|
|
|
|
import { Component, OnInit, NgZone, 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, Platform, Events } 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 { FingerprintAIO } from '@ionic-native/fingerprint-aio/ngx';
|
|
|
|
|
import { Device } from '@ionic-native/device/ngx';
|
|
|
|
|
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
|
|
|
|
|
import { SharedDataService } from 'src/app/hmg-common/services/shared-data-service/shared-data.service';
|
|
|
|
|
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';
|
|
|
|
|
import { CheckAppVersionResponse } from 'src/app/hmg-common/services/authentication/models/check-app-version.response';
|
|
|
|
|
import { PushService } from 'src/app/hmg-common/services/push/push.service';
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'login',
|
|
|
|
|
templateUrl: './login.component.html',
|
|
|
|
|
styleUrls: ['./login.component.scss']
|
|
|
|
|
})
|
|
|
|
|
export class LoginComponent implements OnInit, OnDestroy {
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
public cs: CommonService,
|
|
|
|
|
public authService: AuthenticationService,
|
|
|
|
|
public router: Router,
|
|
|
|
|
public alertController: AlertController,
|
|
|
|
|
public ts: TranslatorService,
|
|
|
|
|
public smsService: SmsReaderService,
|
|
|
|
|
private faio: FingerprintAIO,
|
|
|
|
|
public events: Events,
|
|
|
|
|
public ngZone: NgZone,
|
|
|
|
|
public device: Device,
|
|
|
|
|
public splash: SplashScreen,
|
|
|
|
|
public sharedData: SharedDataService,
|
|
|
|
|
public plt: Platform,
|
|
|
|
|
public pushService: PushService
|
|
|
|
|
) {
|
|
|
|
|
this.events.subscribe('logoutFlage', logoutFlage => {
|
|
|
|
|
console.log('login compont logoutFlage: ' + logoutFlage);
|
|
|
|
|
// tslint:disable-next-line: triple-equals
|
|
|
|
|
if (logoutFlage == true) {
|
|
|
|
|
console.log(' subscribe check logoutFlage: ' + logoutFlage);
|
|
|
|
|
this.logoutFlage = logoutFlage;
|
|
|
|
|
localStorage.setItem('logoutFlage', logoutFlage);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.getuser = this.cs.sharedService.getSharedData(
|
|
|
|
|
AuthenticationService.IMEI_USER_DATA,
|
|
|
|
|
false
|
|
|
|
|
);
|
|
|
|
|
// alert(" this.getuser "+this.getuser);
|
|
|
|
|
if (this.getuser) {
|
|
|
|
|
this.user = true;
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
this.user = false;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
appLang = 1;
|
|
|
|
|
isExpired = false;
|
|
|
|
|
isSupportAr = false;
|
|
|
|
|
isAppleStore = false;
|
|
|
|
|
memberLogin: any = {};
|
|
|
|
|
public password: string;
|
|
|
|
|
private language: string;
|
|
|
|
|
public username: string;
|
|
|
|
|
public remeberMe: boolean;
|
|
|
|
|
private iosLink: string;
|
|
|
|
|
private androidLink: string;
|
|
|
|
|
public currentLang: any = 1;
|
|
|
|
|
private patientOutSA: boolean;
|
|
|
|
|
private loginTokenID: string;
|
|
|
|
|
private isMobileFingerPrint: boolean;
|
|
|
|
|
private FingerPrintPatientIdentificationID: string;
|
|
|
|
|
private loginData = new LoginModel();
|
|
|
|
|
private empname: any;
|
|
|
|
|
private logintype: any;
|
|
|
|
|
public loginDiv = true;
|
|
|
|
|
public welcomeBack = false;
|
|
|
|
|
public logo = 'assets/icon/login/password.png';
|
|
|
|
|
deviceToken: any = '';
|
|
|
|
|
user = false;
|
|
|
|
|
DeviceType: string;
|
|
|
|
|
requestGetLoginInfo: any;
|
|
|
|
|
logoutFlage: boolean ;
|
|
|
|
|
getuser: any = '';
|
|
|
|
|
|
|
|
|
|
private checkUserResult: CheckUserAuthenticationResponse;
|
|
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
|
console.log("ENAD TEST!!!")
|
|
|
|
|
if (TranslatorService.CURRENT_LANGUAGE == TranslatorService.EN) {
|
|
|
|
|
this.language = "US";
|
|
|
|
|
} else {
|
|
|
|
|
this.language = "AR";
|
|
|
|
|
}
|
|
|
|
|
this.ts.switchLanguage();
|
|
|
|
|
this.currentLang = TranslatorService.getCurrentLanguageCode();
|
|
|
|
|
// this.deviceToken= this.cs.sharedService.getSharedData(AuthenticationService.DEVICE_TOKEN, false);
|
|
|
|
|
// console.log("get deviceToken login"+ this.deviceToken)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// this.getuser = this.cs.sharedService.getSharedData(
|
|
|
|
|
// AuthenticationService.IMEI_USER_DATA,
|
|
|
|
|
// false
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
|
|
// if(this.getuser){
|
|
|
|
|
// console.log("this.getuser"+this.getuser);
|
|
|
|
|
// this.logoutFlage = true;
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
this.events.subscribe('user', user => {
|
|
|
|
|
console.log('login compont: ' + user);
|
|
|
|
|
this.user = user;
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.deviceToken = localStorage.getItem('devicyeToken');
|
|
|
|
|
console.log('let deviceToken' + this.deviceToken);
|
|
|
|
|
|
|
|
|
|
if (this.deviceToken) {
|
|
|
|
|
console.log('login enabled first time: ' + this.deviceToken);
|
|
|
|
|
} else {
|
|
|
|
|
console.log('no deviceToken' );
|
|
|
|
|
|
|
|
|
|
this.pushService.startReceiving();
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
// alert('login enabled second time: ' + this.deviceToken);
|
|
|
|
|
|
|
|
|
|
}, 1000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// setTimeout(() => {
|
|
|
|
|
// alert("this.logoutFlage in setTime" +localStorage.getItem('logoutFlage'));
|
|
|
|
|
// alert("this.this.user in setTime" + this.user);
|
|
|
|
|
|
|
|
|
|
// if(localStorage.getItem('logoutFlage')== "true"){
|
|
|
|
|
// this.getLastLoginInfo();
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
// },1000);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// here will delete below part and depdding on user (response from getMobileInfo)
|
|
|
|
|
this.username = localStorage.getItem('user');
|
|
|
|
|
this.password = localStorage.getItem('password'); // ****//
|
|
|
|
|
const remember = localStorage.getItem('remember'); // ****//
|
|
|
|
|
this.empname = localStorage.getItem('emp-name');
|
|
|
|
|
this.logintype = localStorage.getItem('login-type');
|
|
|
|
|
// tslint:disable-next-line: triple-equals
|
|
|
|
|
if (remember == 'true') { this.remeberMe = true; } else { this.remeberMe = false; }
|
|
|
|
|
|
|
|
|
|
// here will be check on user if exite then s part and depdding on user (response from getMobileInfo)
|
|
|
|
|
|
|
|
|
|
if (this.user) {
|
|
|
|
|
|
|
|
|
|
// this.loginDiv=false;
|
|
|
|
|
// this.welcomeBack=true;
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
// this.user=true;
|
|
|
|
|
// this.welcomeBack=false;
|
|
|
|
|
}
|
|
|
|
|
// alert("user>>" + this.username);
|
|
|
|
|
// alert("pass>>>" + this.password);
|
|
|
|
|
// alert("remember>>>" + this.remeberMe);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// call getLoginInfo
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnDestroy(): void {
|
|
|
|
|
this.backClicked();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public changeLanguage(langNumber) {
|
|
|
|
|
if(this.currentLang == langNumber){
|
|
|
|
|
return;
|
|
|
|
|
}else{
|
|
|
|
|
this.ts.switchLanguage();
|
|
|
|
|
if (TranslatorService.CURRENT_LANGUAGE == TranslatorService.EN) {
|
|
|
|
|
this.language = "US";
|
|
|
|
|
} else {
|
|
|
|
|
this.language = "AR";
|
|
|
|
|
}
|
|
|
|
|
this.currentLang = TranslatorService.getCurrentLanguageCode();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public forgetPasswordPage() {
|
|
|
|
|
this.cs.openUserForgot();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private hideSplashScreen(stopLoading = false) {
|
|
|
|
|
// this.splash.hide();
|
|
|
|
|
if (stopLoading) {
|
|
|
|
|
this.cs.stopLoading();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public addValue(e): void {
|
|
|
|
|
// console.log(e.currentTarget.checked);
|
|
|
|
|
this.remeberMe = true; // e.currentTarget.checked;
|
|
|
|
|
this.remeberMyInfo();
|
|
|
|
|
}
|
|
|
|
|
public remeberMyInfo() {
|
|
|
|
|
// if (this.remeberMe) {
|
|
|
|
|
if (this.username) {localStorage.setItem('user', this.username); }
|
|
|
|
|
if (this.password) {localStorage.setItem('password', this.password); }
|
|
|
|
|
localStorage.setItem('remember', 'true');
|
|
|
|
|
// } else {
|
|
|
|
|
// localStorage.setItem("user", "");
|
|
|
|
|
// localStorage.setItem("password", "");
|
|
|
|
|
// localStorage.setItem("remember", "false");
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public onLogin() {
|
|
|
|
|
console.log('onLogin');
|
|
|
|
|
// this.checkAppUpdated();
|
|
|
|
|
// this.checkUserAuthentication();
|
|
|
|
|
|
|
|
|
|
this.deviceToken = localStorage.getItem('deviceToken');
|
|
|
|
|
console.log('let deviceToken' + this.deviceToken);
|
|
|
|
|
|
|
|
|
|
if (this.deviceToken) {
|
|
|
|
|
console.log('login enabled first time: ' + this.deviceToken);
|
|
|
|
|
this.checkAppUpdated();
|
|
|
|
|
} else {
|
|
|
|
|
console.log('no deviceToken' );
|
|
|
|
|
|
|
|
|
|
this.pushService.startReceiving();
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.deviceToken = localStorage.getItem('deviceToken');
|
|
|
|
|
this.checkAppUpdated();
|
|
|
|
|
console.log('login enabled second time: ' + this.deviceToken);
|
|
|
|
|
}, 1000);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public checkAppUpdated() {
|
|
|
|
|
this.authService.checkApplicationVersion(
|
|
|
|
|
() => {
|
|
|
|
|
/* Write code for error */
|
|
|
|
|
}).subscribe((result: CheckAppVersionResponse) => {
|
|
|
|
|
// tslint:disable-next-line: triple-equals
|
|
|
|
|
if (result.MessageStatus == 2 && result.ErrorType == 4) {
|
|
|
|
|
this.cs.presentAcceptDialog(result.ErrorEndUserMessage, () => {
|
|
|
|
|
this.handleAppUpdate(result);
|
|
|
|
|
});
|
|
|
|
|
// tslint:disable-next-line: triple-equals
|
|
|
|
|
} else if (result.MessageStatus == 1) {
|
|
|
|
|
this.checkUserAuthentication();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private handleAppUpdate(result) {
|
|
|
|
|
this.iosLink = result.IOSLink;
|
|
|
|
|
this.androidLink = result.AndroidLink;
|
|
|
|
|
if (this.plt.is('android')) {
|
|
|
|
|
if (this.androidLink) {
|
|
|
|
|
window.open(this.androidLink, '_system');
|
|
|
|
|
}
|
|
|
|
|
} else if (this.plt.is('ios')) {
|
|
|
|
|
if (this.iosLink) {
|
|
|
|
|
window.open(this.iosLink, '_system');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private checkUserAuthentication() {
|
|
|
|
|
console.log('debug Here!!');
|
|
|
|
|
console.log(this.username);
|
|
|
|
|
console.log(this.language);
|
|
|
|
|
console.log(this.password);
|
|
|
|
|
|
|
|
|
|
this.cs.startLoading();
|
|
|
|
|
const request = new LoginRequest();
|
|
|
|
|
request.P_USER_NAME = this.username;
|
|
|
|
|
request.P_LANGUAGE = this.language;
|
|
|
|
|
request.P_PASSWORD = this.password;
|
|
|
|
|
console.log(request);
|
|
|
|
|
this.authService
|
|
|
|
|
.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)) {
|
|
|
|
|
// alert("result.MemberLoginList.EMPLOYEE_NAME :" + result.MemberLoginList[0].EMPLOYEE_NAME);
|
|
|
|
|
|
|
|
|
|
this.loginData.LogInTokenID = result.LogInTokenID;
|
|
|
|
|
this.loginData.MobileNumber = result.MemberLoginList.P_MOBILE_NUMBER;
|
|
|
|
|
this.loginData.P_USER_NAME = this.username;
|
|
|
|
|
// this.loginData.EMPLOYEE_NAME =result.MemberLoginList[0].EMPLOYEE_NAME;
|
|
|
|
|
this.sharedData.setSharedData(this.loginData, AuthenticationService.LOGIN_DATA);
|
|
|
|
|
this.cs.sharedService.setSharedData(this.loginData.P_USER_NAME, LoginRequest.SHARED_DATA);
|
|
|
|
|
this.remeberMyInfo();
|
|
|
|
|
// this.cs.openSMSPage(); phase#1 one type of OTP
|
|
|
|
|
// if(!this.welcomeBack){
|
|
|
|
|
this.cs.openConfirmLoginPage(); // phase#2 add 4 types for OTP
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
console.log('result.IsPasswordExpired');
|
|
|
|
|
console.log(result.IsPasswordExpired);
|
|
|
|
|
if (result.IsPasswordExpired) {
|
|
|
|
|
this.presentPasswordExpiredDialog();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public backClicked() {
|
|
|
|
|
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 sendSMSForForgotPassword() {
|
|
|
|
|
this.cs.startLoading();
|
|
|
|
|
const 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.loginData.EmployeeName =result.MemberLoginList[0].EMPLOYEE_NAME;
|
|
|
|
|
|
|
|
|
|
this.cs.sharedService.setSharedData(this.loginData.P_USER_NAME, LoginRequest.SHARED_DATA);
|
|
|
|
|
this.sharedData.setSharedData(this.loginData, AuthenticationService.LOGIN_DATA);
|
|
|
|
|
this.sharedData.setSharedData(true, Password.IS_FORGET_PSW);
|
|
|
|
|
this.cs.stopLoading();
|
|
|
|
|
this.cs.openSMSPage();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
login() {
|
|
|
|
|
console.log('login emit');
|
|
|
|
|
console.log('login');
|
|
|
|
|
// this.checkUserAuthentication();
|
|
|
|
|
// this.loginDiv=true;
|
|
|
|
|
this.user = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
loginWithUser() {
|
|
|
|
|
console.log('loginWithUser');
|
|
|
|
|
this.cs.openConfirmLoginPage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
|
|
getLastLoginInfo() {
|
|
|
|
|
this.requestGetLoginInfo = {
|
|
|
|
|
DeviceType: this.cs.getDeviceType(), // "Android",//this.cs.getDeviceType(),
|
|
|
|
|
DeviceToken: this.deviceToken// "5ca8a69cf1804db55264c349edffb99b9d63acd9fa9b6b18956bcb2ad3f2ba36"//this.deviceToken
|
|
|
|
|
};
|
|
|
|
|
this.authService.getLoginInfo(this.requestGetLoginInfo, () => {}, this.ts.trPK('general', 'ok')).subscribe(res => {
|
|
|
|
|
if (this.cs.validResponse(res)) {
|
|
|
|
|
|
|
|
|
|
if (res.Mohemm_GetMobileLoginInfoList.length > 0) {
|
|
|
|
|
|
|
|
|
|
this.cs.sharedService.setSharedData(
|
|
|
|
|
// res.Patient_SELECTDeviceIMEIbyIMEIList[0],
|
|
|
|
|
res.Mohemm_GetMobileLoginInfoList[0],
|
|
|
|
|
AuthenticationService.IMEI_USER_DATA
|
|
|
|
|
);
|
|
|
|
|
this.user = true;
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
this.user = false;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|