Browse Source

Implementing change password

master
GabrielTrettel 3 years ago
parent
commit
d21bd8b11b
  1. 14
      src/app/api/auth.js
  2. 33
      src/app/screens/PasswordRecoveryChangePswdScreen.js
  3. 1
      src/app/screens/PasswordRecoveryScreen.js

14
src/app/api/auth.js

@ -95,6 +95,19 @@ function loginByUsernamAnswers(username, secQuestionId, secQuestionAnswer) {
);
}
function updatePassword(authToken, username, password) {
const localClient = create({
baseURL: "http://wpd.brazilsouth.cloudapp.azure.com:8080/forgotpasswords",
});
localClient.setHeader("Authorization", `Bearer ${authToken}`);
return localClient.post(
`/passwordupdatebyusername?username=${username}&newPassword=${password}`
);
}
export {
login,
signup,
@ -103,4 +116,5 @@ export {
existNickname,
existUsername,
loginByUsernamAnswers,
updatePassword,
};

33
src/app/screens/PasswordRecoveryChangePswdScreen.js

@ -7,6 +7,7 @@ import colors from "../config/colors";
import { dimensions } from "../config/dimensions";
import PasswordFormField from "../components/forms/PasswordFormField";
import ConfirmationModal from "../components/ConfirmationModal";
import { updatePassword } from "../api/auth";
const validationSchema = Yup.object().shape({
password: Yup.string()
@ -19,26 +20,31 @@ const validationSchema = Yup.object().shape({
.matches(/[a-zA-Z]/, "A senha só pode conter letras"),
});
export default function PasswordRecoveryChangePswd({ route }) {
export default function PasswordRecoveryChangePswd({ navigation, route }) {
const authToken = route.params.authToken;
console.log(authToken);
const username = route.params.username;
const [confirmatioModalData, setConfirmatioModalData] = useState({
show: false,
message: "",
onConfirmAction: () => {},
});
const comparePassword = (password, confirmPassword) => {
return password !== confirmPassword;
};
const handleApiReturn = (apiReturn) => {
console.log(apiReturn);
switch (apiReturn) {
const handleSubmit = async (password) => {
const apiReturn = await updatePassword(authToken, username, password);
switch (apiReturn.status) {
case 200:
setConfirmatioModalData({
message: "Senha alterada com sucesso",
show: true,
onConfirmAction: () => {
navigation.navigate("Login");
},
});
break;
case 404:
@ -49,7 +55,10 @@ export default function PasswordRecoveryChangePswd({ route }) {
break;
case 500:
case 403:
console.log("EXPIRED TOKEN");
setConfirmatioModalData({
message: "Algo deu errado, tente novamente mais tarde",
show: true,
});
break;
default:
setConfirmatioModalData({
@ -66,9 +75,10 @@ export default function PasswordRecoveryChangePswd({ route }) {
show={confirmatioModalData.show}
description={confirmatioModalData.message}
confirmationLabel="OK"
onConfirm={() =>
setConfirmatioModalData({ ...confirmatioModalData, show: false })
}
onConfirm={() => {
setConfirmatioModalData({ ...confirmatioModalData, show: false });
confirmatioModalData?.onConfirmAction();
}}
/>
<Form
@ -88,10 +98,7 @@ export default function PasswordRecoveryChangePswd({ route }) {
"As senhas não correspondem"
);
} else {
// FIXME: This should be replaced by the proper api call in future
const apiReturnTest = 403;
handleApiReturn(apiReturnTest);
handleSubmit(form.password);
}
}}
>

1
src/app/screens/PasswordRecoveryScreen.js

@ -79,6 +79,7 @@ export default function PasswordRecovery({ navigation }) {
console.log("ir pra proxima tela....");
navigation.navigate("PasswordRecoveryChangePswd", {
authToken: apiResponse.data,
username: number
});
break;
case 404:

Loading…
Cancel
Save