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

Added current password checker on the password reset page. #66

Merged
merged 2 commits into from
Mar 13, 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
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,11 @@ bin/
.cache-main
.scala_dependencies
.worksheet

package-lock\.json

package\.json

src/main/webapp/app/account/password-reset/init/password-reset-init\.component\.html

src/main/webapp/app/account/register/register\.component\.html
19 changes: 16 additions & 3 deletions src/main/webapp/app/account/password/password.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,24 @@ <h2 *ngIf="account">Password for [<b>{{account.login}}</b>]</h2>
<div class="alert alert-danger" *ngIf="doNotMatch">
The password and its confirmation do not match!
</div>

<div class="alert alert-danger" *ngIf="wrongPassword">
Incorrect Password Entered!
</div>
<form name="form" role="form" (ngSubmit)="changePassword()" #passwordForm="ngForm">

<div class="form-group">
<label class="form-control-label" for="password">Current password</label>
<input type="password" class="form-control" id="currentPassword" name="password" #passwordInput="ngModel"
placeholder="Current password"
[(ngModel)]="currentPassword" minlength=4 maxlength=50 required>
<div *ngIf="passwordInput.dirty && passwordInput.invalid">
<small class="form-text text-danger"
*ngIf="passwordInput.errors.required">
Your password is required.
</small>
</div>
</div>
<div class="form-group">
<label class="form-control-label" for="password">New password</label>
<label class="form-control-label" for="password"> New password</label>
<input type="password" class="form-control" id="password" name="password" #passwordInput="ngModel"
placeholder="New password"
[(ngModel)]="password" minlength=4 maxlength=50 required>
Expand Down
50 changes: 35 additions & 15 deletions src/main/webapp/app/account/password/password.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { Component, OnInit } from '@angular/core';

import { Principal } from '../../shared';
import { PasswordService } from './password.service';

import { Account } from '../../shared';
import { LoginService } from "../../shared/login/login.service";
@Component({
selector: 'jhi-password',
templateUrl: './password.component.html'
Expand All @@ -11,11 +12,13 @@ export class PasswordComponent implements OnInit {
doNotMatch: string;
error: string;
success: string;
account: any;
account: Account;
password: string;
currentPassword: string;
confirmPassword: string;

wrongPassword : boolean;
constructor(
private loginService: LoginService,
private passwordService: PasswordService,
private principal: Principal
) {
Expand All @@ -28,19 +31,36 @@ export class PasswordComponent implements OnInit {
}

changePassword() {
if (this.password !== this.confirmPassword) {
this.error = null;
this.success = null;
this.doNotMatch = 'ERROR';
} else {
this.doNotMatch = null;
this.passwordService.save(this.password).subscribe(() => {
// Check if we can vaidate the entered password.
this.loginService.login({
username: this.account.login,
password: this.currentPassword,
rememberMe: this.loginService.getRememberMe()
}).then(() => {
// check if new passwords match
if (this.password !== this.confirmPassword) {
this.error = null;
this.success = 'OK';
}, () => {
this.success = null;
this.error = 'ERROR';
});
}
this.doNotMatch = 'ERROR';
}
//update password
else{
this.wrongPassword = false;
this.doNotMatch = null;
this.passwordService.save(this.password).subscribe(() => {
this.error = null;
this.success = 'OK';
}, () => {
this.success = null;
this.error = 'ERROR';
});
}
// if password is invalid then throw error message
}).catch(() => {
this.success = null;
this.wrongPassword = true;
});

}

}
14 changes: 12 additions & 2 deletions src/main/webapp/app/shared/login/login.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import { AuthServerProvider } from '../auth/auth-session.service';

@Injectable()
export class LoginService {

private rememberMe;
private username;
constructor(
private principal: Principal,
private authServerProvider: AuthServerProvider
) {}


login(credentials, callback?) {
const cb = callback || function() {};

Expand All @@ -19,15 +21,23 @@ export class LoginService {
this.principal.identity(true).then((account) => {
resolve(data);
});
this.setRememberMe(credentials.rememberMe);
return cb();
}, (err) => {
this.logout();
reject(err);
reject(err);reject(err);
return cb(err);
});
});
}

setRememberMe(rememberMe){
this.rememberMe = rememberMe;
}

getRememberMe() : boolean {
return this.rememberMe;
}
logout() {
this.authServerProvider.logout().subscribe();
this.principal.authenticate(null);
Expand Down