From 372452955908dfda536a9773b138e23e53e7963f Mon Sep 17 00:00:00 2001 From: umih874 Date: Wed, 7 Mar 2018 21:21:42 +1300 Subject: [PATCH 1/2] Added current password checker on the password reset page. --- .../account/password/password.component.html | 19 +++++-- .../account/password/password.component.ts | 50 +++++++++++++------ .../webapp/app/shared/login/login.service.ts | 14 +++++- 3 files changed, 63 insertions(+), 20 deletions(-) diff --git a/src/main/webapp/app/account/password/password.component.html b/src/main/webapp/app/account/password/password.component.html index e547d65..d6818fe 100644 --- a/src/main/webapp/app/account/password/password.component.html +++ b/src/main/webapp/app/account/password/password.component.html @@ -13,11 +13,24 @@

Password for [{{account.login}}]

The password and its confirmation do not match!
- +
+ Incorrect Password Entered! +
- +
+ + +
+ + Your password is required. + +
+
- + diff --git a/src/main/webapp/app/account/password/password.component.ts b/src/main/webapp/app/account/password/password.component.ts index 7e333a5..e196480 100644 --- a/src/main/webapp/app/account/password/password.component.ts +++ b/src/main/webapp/app/account/password/password.component.ts @@ -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' @@ -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 ) { @@ -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; + }); + } + } diff --git a/src/main/webapp/app/shared/login/login.service.ts b/src/main/webapp/app/shared/login/login.service.ts index 7ebd131..d0752fb 100644 --- a/src/main/webapp/app/shared/login/login.service.ts +++ b/src/main/webapp/app/shared/login/login.service.ts @@ -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() {}; @@ -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); From c08e4bdf55f220f1145da2b5cb6c1b40eebf2148 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 8 Mar 2018 23:07:55 +1300 Subject: [PATCH 2/2] Added ignored files (package.json) --- .gitignore | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.gitignore b/.gitignore index 1b22cca..e00e1aa 100644 --- a/.gitignore +++ b/.gitignore @@ -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