You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
350 lines
12 KiB
TypeScript
350 lines
12 KiB
TypeScript
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";
|
|
//import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
|
|
|
@Component({
|
|
selector: 'app-change-password',
|
|
templateUrl: './change-password.component.html',
|
|
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;
|
|
public logo = "assets/icon/login/lock.png";
|
|
public testy = 'a123';
|
|
|
|
userData: any = {};
|
|
public isExpiredPwd: boolean = false;
|
|
public NEW_PASSWORD: boolean = false;
|
|
public Confirm_NEW_PASSWORD: boolean = false;
|
|
public OLD_PASSWORD: boolean = false;
|
|
|
|
public recentPasswordNote = {
|
|
yellowImg: '../assets/icon/yellow.svg',
|
|
text: 'Do not user recent password',
|
|
|
|
};
|
|
public isLowerCase = {
|
|
blankImg: '../assets/icon/blank.svg',
|
|
greenImg: '../assets/icon/green.svg',
|
|
redImg: '../assets/imgs/close.svg',
|
|
text: 'At least one lowercase',
|
|
isMatch: false
|
|
};
|
|
public isUpperCase = {
|
|
blankImg: '../assets/icon/blank.svg',
|
|
greenImg: '../assets/icon/green.svg',
|
|
redImg: '../assets/imgs/close.svg',
|
|
text: 'At least one uppdercase',
|
|
isMatch: false
|
|
};
|
|
public isLetterCase = {
|
|
blankImg: '../assets/icon/blank.svg',
|
|
greenImg: '../assets/icon/green.svg',
|
|
redImg: '../assets/imgs/close.svg',
|
|
text: 'At least one Letter',
|
|
isMatch: false
|
|
};
|
|
public isHasDigit = {
|
|
blankImg: '../assets/icon/blank.svg',
|
|
greenImg: '../assets/icon/green.svg',
|
|
redImg: '../assets/imgs/close.svg',
|
|
text: 'At least one nomeric',
|
|
isMatch: false
|
|
};
|
|
public isMinLength = {
|
|
blankImg: '../assets/icon/blank.svg',
|
|
greenImg: '../assets/icon/green.svg',
|
|
redImg: '../assets/imgs/close.svg',
|
|
text: 'Minimum 8 characters',
|
|
isMatch: false
|
|
};
|
|
public isRepeatedLetter = {
|
|
blankImg: '../assets/icon/blank.svg',
|
|
greenImg: '../assets/icon/green.svg',
|
|
redImg: '../assets/imgs/close.svg',
|
|
text: 'Do not add repeating letters',
|
|
isMatch: false
|
|
};
|
|
public isContainSpecialChar = {
|
|
blankImg: '../assets/icon/blank.svg',
|
|
greenImg: '../assets/icon/green.svg',
|
|
redImg: '../assets/imgs/close.svg',
|
|
text: 'It should contain special character',
|
|
isMatch: false
|
|
};
|
|
public confirmMatchNew = {
|
|
blankImg: '../assets/icon/blank.svg',
|
|
greenImg: '../assets/icon/green.svg',
|
|
redImg: '../assets/imgs/close.svg',
|
|
text: 'Confirm Password does not match.',
|
|
isMatch: false
|
|
};
|
|
public userNameMatchNew = {
|
|
blankImg: '../assets/icon/blank.svg',
|
|
greenImg: '../assets/icon/green.svg',
|
|
redImg: '../assets/imgs/close.svg',
|
|
text: 'password should not contain the username.',
|
|
isMatch: false
|
|
};
|
|
public userId: string;
|
|
|
|
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,
|
|
// public formBuilder: FormBuilder,
|
|
) {
|
|
console.log("change password 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.profile_form = this.formBuilder.group({
|
|
// password: ['', Validators.compose([Validators.minLength(8)])]
|
|
// });
|
|
// 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);
|
|
// }
|
|
// });
|
|
}
|
|
|
|
|
|
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();
|
|
}
|
|
});
|
|
}
|
|
onChangeCNP() {
|
|
// in UAT Alow to the length of password less than 8
|
|
// so if we ready to go life change it to >= 8
|
|
if (this.P_Confirm_NEW_PASSWORD.length >= 3) {
|
|
this.Confirm_NEW_PASSWORD = true;
|
|
|
|
|
|
} else {
|
|
this.Confirm_NEW_PASSWORD = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
onChangeNP() {
|
|
// in UAT Alow to the length of password less than 8
|
|
// so if we ready to go life change it to >= 8
|
|
if (this.P_NEW_PASSWORD.length >= 3) {
|
|
this.NEW_PASSWORD = true;
|
|
|
|
} else {
|
|
this.NEW_PASSWORD = false;
|
|
|
|
}
|
|
|
|
}
|
|
onChangeOP() {
|
|
// in UAT Alow to the length of password less than 8
|
|
// so if we ready to go life change it to >= 8
|
|
if (this.P_OLD_PASSWORD.length >= 3) {
|
|
this.OLD_PASSWORD = true;
|
|
|
|
} else {
|
|
this.OLD_PASSWORD = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
checkerFuncation(val) {
|
|
if (this.P_NEW_PASSWORD === '') {
|
|
switch (val) {
|
|
case 1:
|
|
return this.isLetterCase.blankImg;
|
|
case 3:
|
|
return this.isHasDigit.blankImg;
|
|
case 4:
|
|
return this.isMinLength.blankImg;
|
|
case 5:
|
|
return this.isRepeatedLetter.blankImg;
|
|
case 6:
|
|
return this.isContainSpecialChar.blankImg;
|
|
case 7:
|
|
return this.confirmMatchNew.blankImg;
|
|
case 8:
|
|
return this.userNameMatchNew.blankImg;
|
|
}
|
|
} else {
|
|
switch (val) {
|
|
// case 1:
|
|
// if (/[a-z]/.test(this.P_NEW_PASSWORD)) {
|
|
// this.isLowerCase.isMatch = true;
|
|
// return this.isLowerCase.greenImg;
|
|
// } else {
|
|
// this.isLowerCase.isMatch = false;
|
|
// return this.isLowerCase.redImg;
|
|
// }
|
|
// case 2:
|
|
// if (/[A-Z]/.test(this.P_NEW_PASSWORD)) {
|
|
// this.isUpperCase.isMatch = true;
|
|
// return this.isUpperCase.greenImg;
|
|
// } else {
|
|
// this.isUpperCase.isMatch = false;
|
|
// return this.isUpperCase.redImg;
|
|
// }
|
|
case 1:
|
|
if (/[a-zA-Z]/.test(this.P_NEW_PASSWORD)) {
|
|
this.isLetterCase.isMatch = true;
|
|
return this.isLetterCase.greenImg;
|
|
} else {
|
|
this.isLetterCase.isMatch = false;
|
|
return this.isLetterCase.redImg;
|
|
}
|
|
case 3:
|
|
if (/[0-9]/.test(this.P_NEW_PASSWORD)) {
|
|
this.isHasDigit.isMatch = true;
|
|
return this.isHasDigit.greenImg;
|
|
} else {
|
|
this.isHasDigit.isMatch = false;
|
|
return this.isHasDigit.redImg;
|
|
}
|
|
case 4:
|
|
if (this.P_NEW_PASSWORD.length >= 8) {
|
|
this.isMinLength.isMatch = true;
|
|
return this.isMinLength.greenImg;
|
|
} else {
|
|
this.isMinLength.isMatch = false;
|
|
return this.isMinLength.redImg;
|
|
}
|
|
case 5:
|
|
if (/([a-z])\1/i.test(this.P_NEW_PASSWORD)) {
|
|
this.isRepeatedLetter.isMatch = false;
|
|
return this.isRepeatedLetter.redImg;
|
|
} else {
|
|
this.isRepeatedLetter.isMatch = true;
|
|
return this.isRepeatedLetter.greenImg;
|
|
}
|
|
case 6:
|
|
if (/[ `!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?~]/.test(this.P_NEW_PASSWORD)) {
|
|
this.isContainSpecialChar.isMatch = true;
|
|
return this.isContainSpecialChar.greenImg;
|
|
} else {
|
|
this.isContainSpecialChar.isMatch = false;
|
|
return this.isContainSpecialChar.redImg;
|
|
}
|
|
case 7:
|
|
if (this.P_NEW_PASSWORD !== this.P_Confirm_NEW_PASSWORD) {
|
|
this.confirmMatchNew.isMatch = false;
|
|
return this.confirmMatchNew.redImg;
|
|
} else {
|
|
this.confirmMatchNew.isMatch = true;
|
|
return this.confirmMatchNew.greenImg;
|
|
}
|
|
case 8:
|
|
if (!this.P_NEW_PASSWORD.includes(this.P_USER_NAME)) {
|
|
this.userNameMatchNew.isMatch = true;
|
|
return this.userNameMatchNew.greenImg;
|
|
} else {
|
|
this.userNameMatchNew.isMatch = false;
|
|
return this.userNameMatchNew.redImg;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
disabledSubmitBtn() {
|
|
if (this.isLetterCase.isMatch && this.isHasDigit.isMatch && this.isMinLength.isMatch
|
|
&& this.isRepeatedLetter.isMatch && this.P_NEW_PASSWORD !== '' && this.NEW_PASSWORD
|
|
&& this.Confirm_NEW_PASSWORD && this.OLD_PASSWORD && this.isContainSpecialChar.isMatch && this.confirmMatchNew.isMatch) {
|
|
return false;
|
|
} else { return true; }
|
|
}
|
|
|
|
}
|