Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Email bug & Password change fix #118

Merged
merged 1 commit into from
May 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,38 +1,46 @@
<div class="row register-container" data-hook="">
<div id="content" class="col-sm-12" data-hook="">
<div class="col-md-5 col-centered">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Update Password</h3>
</div>
<div id="existing-customer" class="panel-body" data-hook="login">
<form class="register-register-form" novalidate="" [formGroup]="updatePasswordForm" (ngSubmit)="onSubmit()">
<fieldset class="register-input-container">

<div class="register-input-item">
<input type="password" class="register-user-input-password register-user-input" name="password" formControlName="password"
placeholder="Choose New Password" autocomplete="off">
<div *ngIf="updatePasswordForm.get('password').errors && updatePasswordForm.get('password').touched">
<span class="register-error-icon">!</span>
<p class="register-error-message">{{updatePasswordForm.get('password').errors.msg || 'Password must be at least 6 characters'}}</p>
</div>
<div id="content" class="col-sm-12" data-hook="">
<div class="col-md-5 col-centered">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title" *ngIf="passwordReset===false">Update Password</h3>
<h3 class="panel-title" *ngIf="passwordReset===true">Password Changed!</h3>
</div>
<div id="existing-customer" class="panel-body" data-hook="login" *ngIf="passwordReset===false">
<form class="register-register-form" novalidate="" [formGroup]="updatePasswordForm" (ngSubmit)="onSubmit()">
<fieldset class="register-input-container">

<div class="register-input-item">
<input type="password" class="register-user-input-password register-user-input" name="password" formControlName="password"
placeholder="Choose New Password" autocomplete="off">
<div *ngIf="updatePasswordForm.get('password').errors && updatePasswordForm.get('password').touched">
<span class="register-error-icon">!</span>
<p class="register-error-message">{{updatePasswordForm.get('password').errors.msg || 'Password must be at least 6 characters'}}</p>
</div>

<div class="register-input-item">
<input type="password" class="register-user-input-password register-user-input" name="password_confirmation" formControlName="password_confirmation"
placeholder="Confirm Password" autocomplete="off">
<div *ngIf="(updatePasswordForm.get('password_confirmation').errors || updatePasswordForm.hasError('mismatchedPasswords')) && updatePasswordForm.get('password_confirmation').touched">
<span class="register-error-icon">!</span>
<p class="register-error-message">{{ 'Password must match'}}</p>
</div>
</div>

<div class="register-input-item">
<input type="password" class="register-user-input-password register-user-input" name="password_confirmation" formControlName="password_confirmation"
placeholder="Confirm Password" autocomplete="off">
<div *ngIf="(updatePasswordForm.get('password_confirmation').errors || updatePasswordForm.hasError('mismatchedPasswords')) && updatePasswordForm.get('password_confirmation').touched">
<span class="register-error-icon">!</span>
<p class="register-error-message">{{ 'Password must match'}}</p>
</div>
</fieldset>
<fieldset class="register-register-button-container">
<button class="btn btn-success register-register-button">Update Password!</button>
</fieldset>
</form>
</div>
</div>
</fieldset>
<fieldset class="register-register-button-container">
<button class="btn btn-success register-register-button">Update Password!</button>
</fieldset>
</form>
</div>
<div id="existing-customer" class="panel-body" data-hook="login" *ngIf="passwordReset===true">
<span>Password has been changed sucessfully!</span>
<span>
Click
<a [routerLink]="['/auth/login']">here</a>for login.
</span>
</div>
</div>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class UpdatePasswordComponent implements OnInit {
token: string;
email: string;
id: string;
passwordReset = false;

constructor(
private fb: FormBuilder,
Expand All @@ -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);
Expand Down
19 changes: 12 additions & 7 deletions src/app/core/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}))
)
Expand All @@ -71,7 +71,7 @@ export class AuthService {
register(data: User): Observable<User> {
const params = { spree_user: data };
return (
this.http.post<User>('api/account', params)
this.http.post<User>('auth/accounts', params)
.map((user) => {
this.setTokenInLocalStorage(user);
this.store.dispatch(this.actions.loginSuccess());
Expand All @@ -98,8 +98,11 @@ export class AuthService {
forgetPassword(data: User): Observable<any> {
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'
Expand All @@ -117,9 +120,11 @@ export class AuthService {
updatePassword(data: User): Observable<void> {
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'
}))
Expand Down