Skip to content

Commit

Permalink
Funcionalidade de esqueci minha senha conectada com o backend. O envi…
Browse files Browse the repository at this point in the history
…o de emails está funcionando, porém ainda não possui uma tela para a segunda parte -- recuperar a senha (alterar a senha após inserir o token de verificação).
  • Loading branch information
Faehzin committed Dec 9, 2024
1 parent 9170cbd commit 352bfc2
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 8 deletions.
28 changes: 21 additions & 7 deletions src/app/private/pages/esqueciSenha.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,47 @@
import React, { useState } from "react";
import { Image, Text, View, TextInput, StyleSheet, TouchableOpacity } from "react-native";
import { forgotPassword } from "../../services/user.service";
import { Alert, Text, View, TextInput, StyleSheet, TouchableOpacity } from "react-native";
import axios from 'axios';
//import BackButton from "/components/BackButton.tsx"; Não consigo achar esse caminho, preciso fazer rodar... (é o botão q volta pra outra pag)

export default function EsqueciSenha() {
const API_URL = process.env.EXPO_PUBLIC_API_URL;
const API_PORT = process.env.EXPO_PUBLIC_API_USUARIO_PORT;
const BASE_URL = `${API_URL}:${API_PORT}/api/usuario/esqueci-senha`;
const [email, setEmail] = useState("");

const handleRecuperarSenha = async () => {
if (!email) {
Alert.alert("Erro", "Por favor, insira um email válido.");
return;
}
try {
const response = await forgotPassword(email);
console.log("E-mail de recuperação enviado:", response);
} catch (error) {
console.error("Erro ao solicitar recuperação de senha:", error.message);
}
};
return (

<View style={styles.container}>
{/* Logo */}
{/* Logo deveria estar aqui, mas não consegui encaixá-la */}

{/* Título */}
<Text style={styles.title}>Esqueceu sua senha? </Text>
<Text style={styles.subtitle}>Calma, a GERO te ajuda!! </Text>

{/* Campo de Email */}
<View style={styles.inputContainer}>
<TextInput
style={styles.input}
placeholder="Email"
value={email}
onChangeText={setEmail}
keyboardType="email-address"
placeholderTextColor="black" // Garante que o placeholder tenha cor definida
placeholderTextColor="black"
/>
</View>

{/* Botão de Recuperar Senha */}
<TouchableOpacity style={styles.button}>
<TouchableOpacity style={styles.button} onPress={handleRecuperarSenha}>
<Text style={styles.buttonText}>Recuperar senha</Text>
</TouchableOpacity>
</View>
Expand Down
2 changes: 1 addition & 1 deletion src/app/public/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ export default function Login() {

<View style={styles.EsqueciButton}>
<ForgetButton
title="Esqueci minha senha!!"
title="Esqueci minha senha"
showLoading={showLoading}
/>
</View>
Expand Down
22 changes: 22 additions & 0 deletions src/app/services/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,28 @@ export const postUser = async (
return json;
};

export const forgotPassword = async (
email: string,
): Promise<IResponse<null>> => {
const response = await fetch(`${BASE_URL}/esqueci-senha`, {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
},
body: JSON.stringify({ email }),
});

const json = await response.json();

if (response.status !== 200) {
throw new Error(json.message as string);
}

return json;
};


export const updateUser = async (
id: number,
body: Partial<IUser>,
Expand Down

0 comments on commit 352bfc2

Please sign in to comment.