From daf0c280cfa46a4a1a71e4bc85cd0d8c454aed50 Mon Sep 17 00:00:00 2001 From: Gopal Shimpi Date: Wed, 2 May 2018 23:07:34 +0530 Subject: [PATCH] Modified auth service 1. Modified routes 2. Change navigation on successfull password chnage. --- .../update-password.component.html | 70 +++++++++++-------- .../update-password.component.ts | 3 +- src/app/core/services/auth.service.ts | 19 +++-- 3 files changed, 53 insertions(+), 39 deletions(-) diff --git a/src/app/auth/components/update-password/update-password.component.html b/src/app/auth/components/update-password/update-password.component.html index 7885ca09..c4d175cd 100644 --- a/src/app/auth/components/update-password/update-password.component.html +++ b/src/app/auth/components/update-password/update-password.component.html @@ -1,38 +1,46 @@
-
-
-
-
-

Update Password

-
-
-
-
- -
- -
- ! -

{{updatePasswordForm.get('password').errors.msg || 'Password must be at least 6 characters'}}

-
+
+
+
+
+

Update Password

+

Password Changed!

+
+
+ +
+ +
+ +
+ ! +

{{updatePasswordForm.get('password').errors.msg || 'Password must be at least 6 characters'}}

- -
- -
- ! -

{{ 'Password must match'}}

-
+
+ +
+ +
+ ! +

{{ 'Password must match'}}

-
-
- -
- -
+
+
+
+ +
+ +
+
+ Password has been changed sucessfully! + + Click + herefor login. +
+
diff --git a/src/app/auth/components/update-password/update-password.component.ts b/src/app/auth/components/update-password/update-password.component.ts index ac30af3d..2543655d 100644 --- a/src/app/auth/components/update-password/update-password.component.ts +++ b/src/app/auth/components/update-password/update-password.component.ts @@ -19,6 +19,7 @@ export class UpdatePasswordComponent implements OnInit { token: string; email: string; id: string; + passwordReset = false; constructor( private fb: FormBuilder, @@ -45,7 +46,7 @@ export class UpdatePasswordComponent implements OnInit { if (this.updatePasswordForm.valid) { this.updatePasswordSubs = this.authService .updatePassword(values) - .do(_ => _, (user) => { + .do(_ => this.passwordReset = true, (user) => { const errors = user.error.error || 'Something went wrong'; keys.forEach(val => { this.pushErrorFor(val, errors); diff --git a/src/app/core/services/auth.service.ts b/src/app/core/services/auth.service.ts index 3fdd1c70..b81eaea1 100644 --- a/src/app/core/services/auth.service.ts +++ b/src/app/core/services/auth.service.ts @@ -50,7 +50,7 @@ export class AuthService { this.store.dispatch(this.actions.loginSuccess()); return user; }) - .do(_ => _, user => this.toastyService.error({ + .do(_ => this.router.navigate(['/']), user => this.toastyService.error({ title: 'ERROR!!', msg: user.error.error })) ) @@ -71,7 +71,7 @@ export class AuthService { register(data: User): Observable { const params = { spree_user: data }; return ( - this.http.post('api/account', params) + this.http.post('auth/accounts', params) .map((user) => { this.setTokenInLocalStorage(user); this.store.dispatch(this.actions.loginSuccess()); @@ -98,8 +98,11 @@ export class AuthService { forgetPassword(data: User): Observable { return ( this.http - .post('api/passwords', { spree_user: data }) - .map(_ => this.toastyService.success({ title: 'Success', msg: 'Password reset link has be sent to your email.' }), + .post('auth/passwords', { spree_user: data }) + .map(_ => this.toastyService.success({ + title: 'Success', + msg: 'Password reset link has be sent to your email.' + }), ) .do(_ => _, _ => this.toastyService.error({ title: 'ERROR!!', msg: 'Not a valid email/user' @@ -117,9 +120,11 @@ export class AuthService { updatePassword(data: User): Observable { return ( this.http - .put(`api/passwords/${data.id}`, { spree_user: data }) - .map(_ => this.toastyService.success({ title: 'Success', msg: 'Password updated success fully!' }), - this.router.navigate(['/auth/login'])) + .put(`auth/passwords/${data.id}`, { spree_user: data }) + .map(_ => this.toastyService.success({ + title: 'Success', + msg: 'Password updated success fully!' + })) .do(_ => _, _ => this.toastyService.error({ title: 'ERROR!', msg: 'Unable to update password' }))