Change password, Password Expiry, Forgot Password completion and minor changes

master
ansariakhtar 7 years ago
parent 40679c2509
commit 2ff9b567aa

@ -1,3 +1,47 @@
<p>
change-password works!
</p>
<ion-header>
<ion-toolbar class="header-toolbar">
<ion-buttons slot="start">
<ion-back-button color="light" class="btnBack" ></ion-back-button>
</ion-buttons>
<ion-title color="light" > {{'changePassword,changePassword' | translate}}</ion-title>
</ion-toolbar>
</ion-header>
<ion-content padding>
<ion-grid>
<ion-item>
<img class="item-icon" src="assets/imgs/password.png" item-start />
<ion-label>{{'changePassword,currentPassword' | translate}}</ion-label>
<ion-input required type="password"
[(ngModel)]="P_OLD_PASSWORD">
</ion-input>
</ion-item>
<ion-item>
<img class="item-icon" src="assets/imgs/password.png" item-start />
<ion-label>{{'changePassword,newPassword' | translate}}</ion-label>
<ion-input required type="password"
[(ngModel)]="P_NEW_PASSWORD">
</ion-input>
</ion-item>
<ion-item>
<img class="item-icon" src="assets/imgs/password.png" item-start />
<ion-label>{{'changePassword,confirmPassword' | translate}}</ion-label>
<ion-input required type="password"
[(ngModel)]="P_Confirm_NEW_PASSWORD">
</ion-input>
</ion-item>
</ion-grid>
<page-trailer [small]="true"></page-trailer>
</ion-content>
<ion-footer>
<div class="centerDiv">
<ion-button color="customnavy" ion-button (click)="submit()">{{ts.trPK('login','changepassword')}}</ion-button>
</div>
</ion-footer>

@ -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();
}
});
}
}

@ -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,

@ -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();
}});
}
}

@ -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();
}
}
});
}

@ -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<CheckUserAuthenticationResponse> {
this.setPublicFields(request);
this.authenticateRequest(request);
return this.con.post(AuthenticationService.changePassword, request, onError, errorLabel);
}
public submitExpiredPassword(request: ForgetPassword, onError: any, errorLabel: string)
: Observable<CheckUserAuthenticationResponse> {
this.setPublicFields(request);
return this.con.post(AuthenticationService.expiredPassword, request, onError, errorLabel);
}
public sendSMSForForgotFileNumber(request: CheckUserAuthenticationRequest, onError: any, errorLabel: string)
: Observable<CheckUserAuthenticationResponse> {

@ -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"]);
}

@ -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);
}

@ -64,4 +64,8 @@ export class HomePage implements OnInit {
private accrualBalance(){
this.common.openAccuralPage();
}
private Change_password(){
this.common.openChangePassword();
}
}

@ -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": {

Loading…
Cancel
Save