@@ -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
0 commit comments