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.
mohemmionic5/Mohem/src/app/authentication/login/login.component.ts

192 lines
7.4 KiB
TypeScript

7 years ago
import { Component, OnInit, NgZone, OnDestroy } from "@angular/core";
7 years ago
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 { 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';
@Component({
7 years ago
selector: "login",
templateUrl: "./login.component.html",
styleUrls: ["./login.component.scss"]
})
export class LoginComponent implements OnInit, OnDestroy {
7 years ago
appLang: number = 1;
isExpired: boolean = false;
isSupportAr: boolean = false;
isAppleStore: boolean = false;
memberLogin: any = {};
private password: string;
private language: string;
private username: string;
private currentLang: any = 1;
private patientOutSA: boolean;
private loginTokenID: string;
private isMobileFingerPrint: boolean;
private FingerPrintPatientIdentificationID: string;
private loginData = new LoginModel();
6 years ago
7 years ago
constructor(
public cs: CommonService,
public authService: AuthenticationService,
public router: Router,
public alertController: AlertController,
public ts: TranslatorService,
public smsService: SmsReaderService,
private faio: FingerprintAIO,
public ngZone: NgZone,
public device: Device,
public splash: SplashScreen,
public sharedData: SharedDataService
) { }
ngOnInit() { }
ngOnDestroy(): void {
this.backClicked();
}
7 years ago
public changeLanguage() {
this.ts.switchLanguage();
if (TranslatorService.CURRENT_LANGUAGE == TranslatorService.EN) {
this.language = "US";
} else {
this.language = "AR";
7 years ago
}
7 years ago
this.currentLang = TranslatorService.getCurrentLanguageCode();
}
private forgetPasswordPage() {
this.cs.openUserForgot();
}
private hideSplashScreen(stopLoading = false) {
// this.splash.hide();
if (stopLoading) {
this.cs.stopLoading();
7 years ago
}
7 years ago
}
7 years ago
7 years ago
public onLogin() {
this.checkUserAuthentication();
}
7 years ago
7 years ago
private checkUserAuthentication() {
6 years ago
console.log("debug Here!!");
7 years ago
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
6 years ago
.login(request, () => {
console.log("error here");
//console.log(result.MessageStatus);
6 years ago
//this.sharedData.setSharedData(true, Password.IS_EXPIRED_PSW);
//this.userCheck();
}, this.ts.trPK("general", "ok"))
7 years ago
.subscribe((result: CheckUserAuthenticationResponse) => {
console.log("success");
this.cs.stopLoading();
7 years ago
if (this.cs.validResponse(result)) {
this.loginData.LogInTokenID = result.LogInTokenID;
this.loginData.MobileNumber = result.MemberLoginList.P_MOBILE_NUMBER;
6 years ago
this.loginData.P_USER_NAME = this.username;
this.sharedData.setSharedData(this.loginData, AuthenticationService.LOGIN_DATA);
this.cs.sharedService.setSharedData(this.loginData.P_USER_NAME, LoginRequest.SHARED_DATA);
7 years ago
this.cs.openSMSPage();
6 years ago
} else{
console.log("result.IsPasswordExpired");
console.log(result.IsPasswordExpired);
if(result.IsPasswordExpired)
{
this.presentPasswordExpiredDialog();
7 years ago
}
6 years ago
}
7 years ago
});
}
7 years ago
7 years ago
public backClicked() {
this.smsService.stopSMSMonitoring();
}
7 years ago
6 years ago
async presentPasswordExpiredDialog() {
const alert = await this.alertController.create({
6 years ago
header: this.ts.trPK("general", "confirm"),
message: this.ts.trPK("login", "password-expired"),
buttons: [
6 years ago
{
text: this.ts.trPK("general", "ok"),
handler: () => {
console.log('Confirm Okay');
this.sharedData.setSharedData(true, Password.IS_EXPIRED_PSW);
this.userCheck();
}
}
]
6 years ago
});
await alert.present();
}
7 years ago
public openForgotID() {
this.cs.openUserForgot();
}
7 years ago
6 years ago
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();
}
});
6 years ago
}
6 years ago
private checkUserResult: CheckUserAuthenticationResponse;
private sendSMSForForgotPassword() {
6 years ago
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.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();
}
});
}
}