Skip to content

Commit 9a7846d

Browse files
committed
Send old and new password to PUT login
1 parent fe65dba commit 9a7846d

2 files changed

Lines changed: 20 additions & 42 deletions

File tree

src/ChangePassword/changePassword.js

Lines changed: 19 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -11,48 +11,26 @@ export default function ChangePassword(props) {
1111
const handleChangePasswordClick = e => {
1212
e.preventDefault();
1313

14-
const userEmail = localStorage.getItem("email");
15-
16-
const verifyCurrentPassword = () =>
17-
fetch("https://api.borumtech.com/api/login", {
18-
method: "POST",
19-
headers: {
20-
"content-type": "application/x-www-form-urlencoded",
21-
},
22-
body: `email=${userEmail}&password=${currentPassword}`,
23-
}).then(response => {
24-
if (response.ok) return response.json();
25-
throw new Error(response.json());
26-
});
27-
28-
const requestPasswordChange = () =>
29-
fetch("https://api.borumtech.com/api/login", {
30-
method: "PUT",
31-
headers: {
32-
"content-type": "application/x-www-form-urlencoded",
33-
authorization: "Basic " + localStorage.getItem("apiKey"),
34-
},
35-
body: `password=${newPassword}`,
14+
fetch("https://api.borumtech.com/api/login", {
15+
method: "PUT",
16+
headers: {
17+
"content-type": "application/x-www-form-urlencoded",
18+
authorization: "Basic " + localStorage.getItem("apiKey"),
19+
},
20+
body: `old_password=${currentPassword}&new_password=${newPassword}`,
21+
})
22+
.then(response => response.json()).then(response => {
23+
if (response.statusCode >= 200 && response.statusCode < 300)
24+
return response;
25+
26+
throw new Error(response.error.message);
3627
})
37-
.then(response => {
38-
if (response.ok) {
39-
return response.json();
40-
}
41-
})
42-
.then(response => {
43-
if (!response.ok) {
44-
alert(
45-
"An error occurred and the password could not be changed."
46-
);
47-
}
48-
});
49-
50-
verifyCurrentPassword()
51-
.then(requestPasswordChange)
52-
.catch(() => {
53-
alert(
54-
"The current password is not correct. If you do not remember your current password, log out and click 'Forgot Password'"
55-
);
28+
.then(response => {
29+
alert("Password changed successfully");
30+
})
31+
.catch(e => {
32+
console.error(e);
33+
alert(e);
5634
});
5735
};
5836

src/ForgotPassword/forgotPassword.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default function ForgotPassword(props) {
99
const [email, setEmail] = useState("");
1010

1111
const handleEmailSubmit = (e, setConfirmed) => {
12-
fetch(`https://api.borumtech.com/api/v1/register`, {
12+
fetch(`https://api.borumtech.com/api/v1/login`, {
1313
method: "put",
1414
headers: {
1515
"Content-Type": "application/x-www-form-urlencoded",

0 commit comments

Comments
 (0)