From 2ff9b567aa1c410cf260f31ac577b53caaf530f5 Mon Sep 17 00:00:00 2001 From: ansariakhtar Date: Mon, 1 Jul 2019 10:25:03 +0300 Subject: [PATCH] Change password, Password Expiry, Forgot Password completion and minor changes --- .../change-password.component.html | 50 +++++++- .../change-password.component.ts | 115 +++++++++++++++++- .../authentication/forgot/forgot.component.ts | 2 - .../authentication/login/login.component.ts | 87 +++++++++++-- .../authentication/sms-page/sms-page.page.ts | 21 +++- .../authentication/authentication.service.ts | 15 +++ .../services/common/common.service.ts | 5 +- .../services/connector/connector.service.ts | 3 +- Mohem/src/app/home/home.page.ts | 4 + Mohem/src/assets/localization/i18n.json | 4 + 10 files changed, 284 insertions(+), 22 deletions(-) diff --git a/Mohem/src/app/authentication/change-password/change-password.component.html b/Mohem/src/app/authentication/change-password/change-password.component.html index b0aa1648..4708cb63 100644 --- a/Mohem/src/app/authentication/change-password/change-password.component.html +++ b/Mohem/src/app/authentication/change-password/change-password.component.html @@ -1,3 +1,47 @@ -

- change-password works! -

+ + + + + + {{'changePassword,changePassword' | translate}} + + + + + + + + + + + {{'changePassword,currentPassword' | translate}} + + + + + + {{'changePassword,newPassword' | translate}} + + + + + + + {{'changePassword,confirmPassword' | translate}} + + + + + + + + + + +
+ {{ts.trPK('login','changepassword')}} +
+
\ No newline at end of file diff --git a/Mohem/src/app/authentication/change-password/change-password.component.ts b/Mohem/src/app/authentication/change-password/change-password.component.ts index fab1531a..ee3ece29 100644 --- a/Mohem/src/app/authentication/change-password/change-password.component.ts +++ b/Mohem/src/app/authentication/change-password/change-password.component.ts @@ -1,4 +1,17 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, OnInit, ViewChild, ChangeDetectorRef, OnDestroy } from '@angular/core'; +import { CommonService } from 'src/app/hmg-common/services/common/common.service'; +import { AuthenticationService } from 'src/app/hmg-common/services/authentication/authentication.service'; +import { Router } from '@angular/router'; +import { AlertController } from '@ionic/angular'; +import { TranslatorService } from 'src/app/hmg-common/services/translator/translator.service'; +import { CheckUserAuthenticationResponse } from 'src/app/hmg-common/services/authentication/models/check-user-auth.response'; +import { SmsReaderService } from 'src/app/hmg-common/services/sms/sms-reader.service'; +import { ForgetPassword } from '../models/forget.password'; +import { LoginModel } from '../models/LoginModel'; +import { SharedDataService } from 'src/app/hmg-common/services/shared-data-service/shared-data.service'; +import {LoginComponent} from "src/app/authentication/login/login.component"; +import { Password } from '../models/password'; +import { AuthenticatedUser } from "src/app/hmg-common/services/authentication/models/authenticated-user"; @Component({ selector: 'app-change-password', @@ -6,9 +19,105 @@ import { Component, OnInit } from '@angular/core'; styleUrls: ['./change-password.component.scss'], }) export class ChangePasswordComponent implements OnInit { + private loginData = new LoginModel(); + public P_NEW_PASSWORD: string; + public P_Confirm_NEW_PASSWORD : string; + public P_OLD_PASSWORD : string; + public P_USER_NAME : string; + + userData: any = {}; + public isExpiredPwd: boolean = false; + constructor( + public cs: CommonService, + public authService: AuthenticationService, + public router: Router, + public alertController: AlertController, + public ts: TranslatorService, + public smsService: SmsReaderService, + public changeDetector: ChangeDetectorRef, + public sharedData: SharedDataService) { + console.log("change password constructor"); + } - constructor() { } + ngOnInit() { + console.log("change password oninit"); + this.isExpiredPwd = + this.sharedData.getSharedData(Password.IS_EXPIRED_PSW) || false; + const data = this.sharedData.getSharedData(AuthenticationService.LOGIN_DATA, false); + this.P_USER_NAME =data.P_USER_NAME; + console.log(this.isExpiredPwd); + console.log(this.P_USER_NAME); + // this.authService + // .loadAuthenticatedUser() + // .subscribe((user: AuthenticatedUser) => { + // if (user) { + // this.userData = user; + // this.P_USER_NAME = user.EMPLOYEE_NUMBER; + // console.log(user); + // } else { + // console.log(user); + // } + // }); + } - ngOnInit() {} + private checkUserResult: CheckUserAuthenticationResponse; + + + submit(){ + console.log(this.isExpiredPwd); + if(this.isExpiredPwd){ + this.expiredPassword(); + }else{ + this.changePassword(); + } + } + + public expiredPassword(){ + const data = this.sharedData.getSharedData(AuthenticationService.LOGIN_DATA, false); + //this.loginData.P_USER_NAME = this.P_USER_NAME; + let request:Password = new Password(); + request.P_OLD_PASSWORD=this.P_OLD_PASSWORD; + request.P_Confirm_NEW_PASSWORD=this.P_NEW_PASSWORD; + request.P_NEW_PASSWORD=this.P_Confirm_NEW_PASSWORD; + request.P_USER_NAME = this.P_USER_NAME; + + this.authService.submitExpiredPassword( + request, + () => { + //this.sendSMSForForgotPassword(); + }, this.ts.trPK('general', 'ok')).subscribe((result: CheckUserAuthenticationResponse) => { + if (this.cs.validResponse(result)) { + this.checkUserResult = result; + console.log(result); + this.cs.toastPK("changePassword","successChange"); + this.sharedData.setSharedData(false,Password.IS_EXPIRED_PSW); + this.cs.openLogin(); + } + }); + } + public changePassword(){ + const data = this.sharedData.getSharedData(AuthenticationService.LOGIN_DATA, false); + //this.loginData.P_USER_NAME = this.P_USER_NAME; + let request:Password = new Password(); + request.P_OLD_PASSWORD=this.P_OLD_PASSWORD; + request.P_Confirm_NEW_PASSWORD=this.P_NEW_PASSWORD; + request.P_NEW_PASSWORD=this.P_Confirm_NEW_PASSWORD; + request.P_USER_NAME = this.P_USER_NAME; + + this.authService.submitChangePassword( + request, + () => { + //this.sendSMSForForgotPassword(); + }, this.ts.trPK('general', 'ok')).subscribe((result: CheckUserAuthenticationResponse) => { + if (this.cs.validResponse(result)) { + this.checkUserResult = result; + console.log(result); + this.cs.toastPK("changePassword","successChange"); + this.cs.openHome(); + } + }); + } + + } diff --git a/Mohem/src/app/authentication/forgot/forgot.component.ts b/Mohem/src/app/authentication/forgot/forgot.component.ts index e2bd4b92..96a05ce2 100644 --- a/Mohem/src/app/authentication/forgot/forgot.component.ts +++ b/Mohem/src/app/authentication/forgot/forgot.component.ts @@ -6,7 +6,6 @@ import { AlertController } from '@ionic/angular'; import { TranslatorService } from 'src/app/hmg-common/services/translator/translator.service'; import { CheckUserAuthenticationResponse } from 'src/app/hmg-common/services/authentication/models/check-user-auth.response'; import { SmsReaderService } from 'src/app/hmg-common/services/sms/sms-reader.service'; -import { InternationalMobileComponent } from 'src/app/hmg-common/ui/mobile-number/international-mobile/international-mobile.component'; import { ForgetPassword } from '../models/forget.password'; import { LoginModel } from '../models/LoginModel'; import { SharedDataService } from 'src/app/hmg-common/services/shared-data-service/shared-data.service'; @@ -22,7 +21,6 @@ export class ForgotComponent implements OnInit { public P_NEW_PASSWORD: string; public P_Confirm_NEW_PASSWORD : string; public P_USER_NAME : string; - @ViewChild(InternationalMobileComponent) internationlMobile: InternationalMobileComponent; constructor( public cs: CommonService, public authService: AuthenticationService, diff --git a/Mohem/src/app/authentication/login/login.component.ts b/Mohem/src/app/authentication/login/login.component.ts index 216556ee..524386c9 100644 --- a/Mohem/src/app/authentication/login/login.component.ts +++ b/Mohem/src/app/authentication/login/login.component.ts @@ -13,6 +13,7 @@ import { SharedDataService } from "src/app/hmg-common/services/shared-data-servi import { LoginModel } from "../models/LoginModel"; import { LoginRequest } from "src/app/hmg-common/services/authentication/models/login.request"; import { Password } from '../models/password'; +import { CheckUserAuthenticationRequest } from 'src/app/hmg-common/services/authentication/models/check-user-auth.request'; @Component({ selector: "login", @@ -87,21 +88,28 @@ export class LoginComponent implements OnInit, OnDestroy { request.P_PASSWORD = this.password; console.log(request); this.authService - .login(request, () => { }, this.ts.trPK("general", "ok")) + .login(request, () => { + console.log("error here"); + //console.log(result.MessageStatus); + this.sharedData.setSharedData(true,Password.IS_EXPIRED_PSW); + this.userCheck(); + }, this.ts.trPK("general", "ok")) .subscribe((result: CheckUserAuthenticationResponse) => { + console.log("success"); + this.cs.stopLoading(); if (this.cs.validResponse(result)) { this.loginData.LogInTokenID = result.LogInTokenID; this.loginData.MobileNumber = result.MemberLoginList.P_MOBILE_NUMBER; this.loginData.P_USER_NAME=this.username; this.sharedData.setSharedData(this.loginData, AuthenticationService.LOGIN_DATA); - this.cs.stopLoading(); - if(result.MessageStatus === 2) - { - this.sharedData.setSharedData(true,Password.IS_EXPIRED_PSW); - } - this.cs.openSMSPage(); } + // console.log("result.IsPasswordExpired"); + // console.log(result.IsPasswordExpired); + // if(result.IsPasswordExpired) + // { + // this.presentPasswordExpiredDialog(); + // } }); } @@ -109,8 +117,73 @@ export class LoginComponent implements OnInit, OnDestroy { this.smsService.stopSMSMonitoring(); } + async presentPasswordExpiredDialog() + { + const alert = await this.alertController.create({ + header: this.ts.trPK("general","confirm"), + message: this.ts.trPK("login","password-expired"), + buttons: [ + { + text: this.ts.trPK("general","ok"), + handler: () => { + console.log('Confirm Okay'); + this.sharedData.setSharedData(true,Password.IS_EXPIRED_PSW); + this.userCheck(); + } + } + ] + }); + await alert.present(); + } + public openForgotID() { this.cs.openUserForgot(); } + public userCheck() + { + this.cs.startLoading(); + const request = new CheckUserAuthenticationRequest(); + request.P_USER_NAME = this.username; + this.authService.checkUserAuthentication( + request, + () => { + /* Write code for error */ + }, this.ts.trPK('general', 'ok')).subscribe((result: CheckUserAuthenticationResponse) => { + if (this.cs.validResponse(result)) { + this.checkUserResult = result; + this.cs.stopLoading(); + this.sendSMSForForgotPassword(); + } + }); + } + + private checkUserResult: CheckUserAuthenticationResponse; + + private sendSMSForForgotPassword() { + this.cs.startLoading(); + let changePwdObj= new LoginRequest(); + changePwdObj.MobileNumber= this.checkUserResult.BasicMemberInformation.P_MOBILE_NUMBER; + changePwdObj.P_USER_NAME=this.username; + changePwdObj.P_MOBILE_NUMBER=this.checkUserResult.BasicMemberInformation.P_MOBILE_NUMBER; + + this.authService.sendPublicSMS( + changePwdObj, + () => { + //this.sendSMSForForgotPassword(); + /* Write code for error */ + }, this.ts.trPK('general', 'ok')).subscribe((result: CheckUserAuthenticationResponse) => { + if (this.cs.validResponse(result)) { + this.checkUserResult = result; + console.log("2"); + console.log(result); + this.loginData.LogInTokenID = result.LogInTokenID; + this.loginData.P_USER_NAME = this.username; + this.sharedData.setSharedData(this.loginData, AuthenticationService.LOGIN_DATA); + this.sharedData.setSharedData(true,Password.IS_FORGET_PSW); + this.cs.stopLoading(); + this.cs.openSMSPage(); + }}); + } + } diff --git a/Mohem/src/app/authentication/sms-page/sms-page.page.ts b/Mohem/src/app/authentication/sms-page/sms-page.page.ts index bbf1acde..c6787c87 100644 --- a/Mohem/src/app/authentication/sms-page/sms-page.page.ts +++ b/Mohem/src/app/authentication/sms-page/sms-page.page.ts @@ -20,6 +20,7 @@ export class SmsPageComponent implements OnInit { Channel: number = 0; activationCode: string; P_SESSION_ID: number; + P_USER_NAME: string; timeInSeconds: any; time: any; runTimer: any; @@ -130,9 +131,11 @@ export class SmsPageComponent implements OnInit { const data = this.sharedData.getSharedData(AuthenticationService.LOGIN_DATA, false); const request = new SMSCheckRequest(); - (request.LogInTokenID = data.LogInTokenID), - (request.activationCode = this.activationCode); + request.LogInTokenID = data.LogInTokenID; + request.activationCode = this.activationCode; + request.P_USER_NAME = data.P_USER_NAME; request.MobileNumber = data.MobileNumber; + this.authService .checkSMS(request, () => {}, this.translate.trPK("general", "ok")) .subscribe((result: SMSCheckResponse) => { @@ -149,9 +152,11 @@ export class SmsPageComponent implements OnInit { const data = this.sharedData.getSharedData(AuthenticationService.LOGIN_DATA, false); const request = new SMSCheckRequest(); - (request.LogInTokenID = data.LogInTokenID), - (request.activationCode = this.activationCode); + request.LogInTokenID = data.LogInTokenID; + request.activationCode = this.activationCode; + request.P_USER_NAME = data.P_USER_NAME; console.log(data.LogInTokenID); + console.log(data.P_USER_NAME); this.authService .checkForgetSMS(request, () => {}, this.translate.trPK("general", "ok")) @@ -159,7 +164,13 @@ export class SmsPageComponent implements OnInit { console.log(result); if (this.common.validResponse(result)) { console.log(result); - this.common.openForgotPassword(); + if (this.isForgetPwd) { + this.common.openForgotPassword(); + } + if(this.isExpiredPwd) { + this.sharedData.setSharedData(true,Password.IS_EXPIRED_PSW); + this.common.openChangePassword(); + } } }); } diff --git a/Mohem/src/app/hmg-common/services/authentication/authentication.service.ts b/Mohem/src/app/hmg-common/services/authentication/authentication.service.ts index 98caa60c..a98dbf06 100644 --- a/Mohem/src/app/hmg-common/services/authentication/authentication.service.ts +++ b/Mohem/src/app/hmg-common/services/authentication/authentication.service.ts @@ -62,6 +62,8 @@ export class AuthenticationService { /*user checking methods */ public static userChecking = 'Services/ERP.svc/REST/Get_BasicUserInformation'; public static changePasswordForget ='Services/ERP.svc/REST/ChangePassword_Forget'; + public static changePassword ='Services/ERP.svc/REST/ChangePassword_FromActiveSession'; + public static expiredPassword = 'Services/ERP.svc/REST/ChangePassword_Expired'; public static LOGIN_EVENT = 'user-login-event'; public static FAMILY_LOGIN_EVENT = 'family-login-event'; @@ -494,6 +496,19 @@ export class AuthenticationService { return this.con.post(AuthenticationService.changePasswordForget, request, onError, errorLabel); } + public submitChangePassword(request: ForgetPassword, onError: any, errorLabel: string) + : Observable { + this.setPublicFields(request); + this.authenticateRequest(request); + return this.con.post(AuthenticationService.changePassword, request, onError, errorLabel); + } + + public submitExpiredPassword(request: ForgetPassword, onError: any, errorLabel: string) + : Observable { + this.setPublicFields(request); + return this.con.post(AuthenticationService.expiredPassword, request, onError, errorLabel); + } + public sendSMSForForgotFileNumber(request: CheckUserAuthenticationRequest, onError: any, errorLabel: string) : Observable { diff --git a/Mohem/src/app/hmg-common/services/common/common.service.ts b/Mohem/src/app/hmg-common/services/common/common.service.ts index c3b17829..37e1a9ac 100644 --- a/Mohem/src/app/hmg-common/services/common/common.service.ts +++ b/Mohem/src/app/hmg-common/services/common/common.service.ts @@ -887,11 +887,14 @@ export class CommonService { */ public openHome() { - this.nav.navigateForward(["/home"]); + this.nav.navigateRoot(["/home"]); } public openForgotPassword() { this.nav.navigateForward(["/authentication/forgot"]); } + public openChangePassword() { + this.nav.navigateForward(["/authentication/changepassowrd"]); + } public openProfile() { this.nav.navigateForward(["/profile/home"]); } diff --git a/Mohem/src/app/hmg-common/services/connector/connector.service.ts b/Mohem/src/app/hmg-common/services/connector/connector.service.ts index c6613abd..4e0c6ddd 100644 --- a/Mohem/src/app/hmg-common/services/connector/connector.service.ts +++ b/Mohem/src/app/hmg-common/services/connector/connector.service.ts @@ -120,8 +120,9 @@ export class ConnectorService { this.cs.stopLoading(); if (!this.cs.validResponse(result)) { // not authorized + console.log(result.MessageStatus); if (result.ErrorType === 2) { - this.cs.userNeedToReLogin(); + //console.log("error expired"); } else { this.cs.showErrorMessageDialog(onError, errorLabel, result.ErrorEndUserMessage); } diff --git a/Mohem/src/app/home/home.page.ts b/Mohem/src/app/home/home.page.ts index be1c6674..f7ea5249 100644 --- a/Mohem/src/app/home/home.page.ts +++ b/Mohem/src/app/home/home.page.ts @@ -64,4 +64,8 @@ export class HomePage implements OnInit { private accrualBalance(){ this.common.openAccuralPage(); } + + private Change_password(){ + this.common.openChangePassword(); + } } diff --git a/Mohem/src/assets/localization/i18n.json b/Mohem/src/assets/localization/i18n.json index 3db8c7ea..5e1b380e 100644 --- a/Mohem/src/assets/localization/i18n.json +++ b/Mohem/src/assets/localization/i18n.json @@ -88,6 +88,10 @@ "sms-page": { "en": "Verify OTP", "ar": "تحقق مرة واحدة كلمة المرور" + }, + "password-expired": { + "en": "Your password has been expired. Kindly change your password to login again.", + "ar": "كلمة المرور الخاصة بك قد انتهت صلاحيتها. يرجى تغيير كلمة المرور لتسجيل الدخول مرة أخرى." } }, "verificationcode": {