From b9a88bce1c0ef7abd2682994c47d4f91bfd1d1c9 Mon Sep 17 00:00:00 2001 From: donpat1to Date: Thu, 23 Oct 2025 19:17:51 +0200 Subject: [PATCH] added password unveiling on login --- frontend/src/pages/Auth/Login.tsx | 113 +++++++++++++++++++++++++----- 1 file changed, 94 insertions(+), 19 deletions(-) diff --git a/frontend/src/pages/Auth/Login.tsx b/frontend/src/pages/Auth/Login.tsx index 7a76386..50e154b 100644 --- a/frontend/src/pages/Auth/Login.tsx +++ b/frontend/src/pages/Auth/Login.tsx @@ -1,17 +1,20 @@ -// frontend/src/pages/Auth/Login.tsx - KORRIGIERT -import React, { useState, useEffect } from 'react'; +// frontend/src/pages/Auth/Login.tsx - UPDATED PASSWORD SECTION +import React, { useState, useEffect, useRef } from 'react'; import { useNavigate } from 'react-router-dom'; import { useAuth } from '../../contexts/AuthContext'; import { useNotification } from '../../contexts/NotificationContext'; -import { employeeService } from '../../services/employeeService'; const Login: React.FC = () => { const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); + const [showPassword, setShowPassword] = useState(false); const [loading, setLoading] = useState(false); const { login, user } = useAuth(); const { showNotification } = useNotification(); const navigate = useNavigate(); + + const holdTimeoutRef = useRef(null); + const passwordInputRef = useRef(null); useEffect(() => { if (user) { @@ -20,6 +23,47 @@ const Login: React.FC = () => { } }, [user, navigate]); + // Cleanup timeouts on unmount + useEffect(() => { + return () => { + if (holdTimeoutRef.current) { + clearTimeout(holdTimeoutRef.current); + } + }; + }, []); + + const handleMouseDown = () => { + // Start timeout to show password after a brief delay (300ms) + holdTimeoutRef.current = setTimeout(() => { + setShowPassword(true); + }, 300); + }; + + const handleMouseUp = () => { + // Clear the timeout if user releases before delay completes + if (holdTimeoutRef.current) { + clearTimeout(holdTimeoutRef.current); + holdTimeoutRef.current = null; + } + // Always hide password on release + setShowPassword(false); + }; + + const handleTouchStart = (e: React.TouchEvent) => { + e.preventDefault(); // Prevent context menu on mobile + handleMouseDown(); + }; + + const handleTouchEnd = (e: React.TouchEvent) => { + e.preventDefault(); + handleMouseUp(); + }; + + // Prevent context menu on long press + const handleContextMenu = (e: React.MouseEvent) => { + e.preventDefault(); + }; + const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setLoading(true); @@ -35,7 +79,6 @@ const Login: React.FC = () => { message: `Willkommen zurück!` }); - // Navigiere zur Startseite navigate('/'); } catch (error: any) { @@ -50,7 +93,6 @@ const Login: React.FC = () => { } }; - // Wenn bereits eingeloggt, zeige Ladeanzeige if (user) { return (
@@ -101,20 +143,53 @@ const Login: React.FC = () => { - setPassword(e.target.value)} - required - style={{ - width: '94.5%', - padding: '10px', - border: '1px solid #ddd', - borderRadius: '4px', - fontSize: '16px' - }} - placeholder="Ihr Passwort" - /> +
+ setPassword(e.target.value)} + required + style={{ + width: '94.5%', + padding: '10px', + paddingRight: '10px', + border: '1px solid #ddd', + borderRadius: '4px', + fontSize: '16px' + }} + placeholder="Ihr Passwort" + /> + +