diff --git a/app/_layout.tsx b/app/_layout.tsx index 75c57c5..9168b67 100644 --- a/app/_layout.tsx +++ b/app/_layout.tsx @@ -20,6 +20,7 @@ export default function AppLayout() { + diff --git a/app/forgot-password.tsx b/app/forgot-password.tsx new file mode 100644 index 0000000..4c951cb --- /dev/null +++ b/app/forgot-password.tsx @@ -0,0 +1,119 @@ +import { useAlert } from '@/components/AlertComponent'; +import api from '@/utils/api'; +import { ArrowLeft, Mail, Send } from 'lucide-react-native'; +import { useState } from 'react'; +import { Image, Platform, Text, TextInput, TouchableOpacity, View } from 'react-native'; +import { KeyboardAwareScrollView } from 'react-native-keyboard-controller'; +import { useRouter } from 'expo-router'; + +export default function ForgotPasswordScreen() { + const alert = useAlert(); + const router = useRouter(); + const [identifier, setIdentifier] = useState(''); + const [isLoading, setIsLoading] = useState(false); + + const handleSubmit = async () => { + if (!identifier.trim()) { + alert.showAlert('error', 'Attenzione', 'Inserisci email o username'); + return; + } + setIsLoading(true); + + try { + await api.post('/user/forgot-password', { identifier: identifier.trim() }); + alert.showAlert( + 'success', + 'Richiesta Inviata', + 'Se l\'account esiste, riceverai un\'email con il link per reimpostare la password.' + ); + router.back(); + } catch (error: any) { + let message = 'Si è verificato un errore. Riprova più tardi.'; + + if (error.request && !error.response) { + message = 'Impossibile contattare il server. Controlla la connessione.'; + } else if (error.response) { + message = `Errore Server: ${error.response.data?.message || error.response.status}`; + } + + alert.showAlert('error', 'Errore', message); + } finally { + setIsLoading(false); + } + }; + + return ( + + {/* Header with Logo */} + + + + + {/* Form Container */} + + + + {/* Title */} + + Recupero Password + + Inserisci la tua email o username. Ti invieremo un link per reimpostare la password. + + + + {/* Input Email / Username */} + + Email o Username + + + + + + + {/* Submit Button */} + + + {isLoading ? 'Invio in corso...' : 'Invia Link'} + + {!isLoading && } + + + {/* Back to Login */} + router.back()} + className="flex-row justify-center items-center mt-2" + activeOpacity={0.7} + > + + Torna al Login + + + + + + ); +} diff --git a/app/login.tsx b/app/login.tsx index 46d11a5..abf9e22 100644 --- a/app/login.tsx +++ b/app/login.tsx @@ -5,10 +5,12 @@ import { Eye, EyeOff, Lock, LogIn, Mail } from 'lucide-react-native'; import React, { useContext, useState } from 'react'; import { Image, Platform, Text, TextInput, TouchableOpacity, View } from 'react-native'; import { KeyboardAwareScrollView } from 'react-native-keyboard-controller'; +import { useRouter } from 'expo-router'; export default function LoginScreen() { const alert = useAlert(); const authContext = useContext(AuthContext); + const router = useRouter(); const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); const [showPassword, setShowPassword] = useState(false); @@ -122,10 +124,14 @@ export default function LoginScreen() { )} - {/* TODO: Implement password recovery functionality */} - {/* + router.push('/forgot-password')} + activeOpacity={0.7} + > Password dimenticata? - */} + {/* Login Button */}