fix `Finger/FaceID login

production
Ashwaq Hasan Jaafar 6 years ago
parent 0d05073e71
commit 0b4a7090ae

@ -1,379 +1,789 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import {ButtonSettings} from "src/app/hmg-common/ui/button/models/button-settingsl"; import {ButtonSettings} from "src/app/hmg-common/ui/button/models/button-settingsl";
import {TranslatorService} from "src/app/hmg-common/services/translator/translator.service"; import {TranslatorService} from "src/app/hmg-common/services/translator/translator.service";
import { CommonService } from 'src/app/hmg-common/services/common/common.service'; import { CommonService } from 'src/app/hmg-common/services/common/common.service';
import { LoginRequest } from 'src/app/hmg-common/services/authentication/models/login.request'; import { LoginRequest } from 'src/app/hmg-common/services/authentication/models/login.request';
import { AuthenticationService } from 'src/app/hmg-common/services/authentication/authentication.service'; import { AuthenticationService } from 'src/app/hmg-common/services/authentication/authentication.service';
import { SharedDataService } from 'src/app/hmg-common/services/shared-data-service/shared-data.service'; import { SharedDataService } from 'src/app/hmg-common/services/shared-data-service/shared-data.service';
import { SendActivationByType } from '../models/sendActivationByType'; import { SendActivationByType } from '../models/sendActivationByType';
import { FingerprintAIO } from '@ionic-native/fingerprint-aio/ngx'; import { FingerprintAIO } from '@ionic-native/fingerprint-aio/ngx';
import { GetLoginInfoRequest } from "../../hmg-common/services/authentication/models/get-login-info.request"; import { GetLoginInfoRequest } from "../../hmg-common/services/authentication/models/get-login-info.request";
import { GetLoginInfoResponse } from "../../hmg-common/services/authentication/models/get-login-info.response"; import { GetLoginInfoResponse } from "../../hmg-common/services/authentication/models/get-login-info.response";
import { SMSCheckRequest } from "src/app/hmg-common/services/authentication/models/smscheck.request"; import { SMSCheckRequest } from "src/app/hmg-common/services/authentication/models/smscheck.request";
import { SMSCheckResponse } from "src/app/hmg-common/services/authentication/models/smscheck.response"; import { SMSCheckResponse } from "src/app/hmg-common/services/authentication/models/smscheck.response";
import { PushService } from 'src/app/hmg-common/services/push/push.service'; import { PushService } from 'src/app/hmg-common/services/push/push.service';
import { Platform } from '@ionic/angular';
@Component({ @Component({
selector: 'app-confirm-login', selector: 'app-confirm-login',
templateUrl: './confirm-login.component.html', templateUrl: './confirm-login.component.html',
styleUrls: ['./confirm-login.component.scss'], styleUrls: ['./confirm-login.component.scss'],
}) })
export class ConfirmLoginComponent implements OnInit { export class ConfirmLoginComponent implements OnInit {
public logo = "assets/imgs/CS.png"; public logo = "assets/imgs/CS.png";
public buttons:any=[]; public buttons:any=[];
isFaceorFinger: any; isFaceorFinger: any;
onlySMSBox: any = true; onlySMSBox: any = true;
loginData:any; loginData:any;
selectedOption: any; selectedOption: any;
lastLogin: any; lastLogin: any;
loginTokenID:any loginTokenID:any
deviceToken:any; deviceToken:any;
constructor( constructor(
public ts: TranslatorService, public ts: TranslatorService,
public cs: CommonService, public cs: CommonService,
public authService: AuthenticationService, public authService: AuthenticationService,
public sharedData: SharedDataService, public sharedData: SharedDataService,
private faio: FingerprintAIO, private faio: FingerprintAIO,
public pushService: PushService, public pushService: PushService,
public platform: Platform,
) { ) {
this.loginData= this.sharedData.getSharedData(AuthenticationService.LOGIN_DATA, false); this.loginData= this.sharedData.getSharedData(AuthenticationService.LOGIN_DATA, false);
console.log(this.loginData); console.log(this.loginData);
this.deviceToken= this.cs.sharedService.getSharedData(AuthenticationService.DEVICE_TOKEN, false); this.deviceToken= this.cs.sharedService.getSharedData(AuthenticationService.DEVICE_TOKEN, false);
console.log("deviceToken :"+this.deviceToken); console.log("deviceToken :"+this.deviceToken);
//if device token undefind //if device token undefind
if(this.deviceToken == undefined){ if(this.deviceToken == undefined){
this.deviceToken = localStorage.getItem("deviceToken"); this.deviceToken = localStorage.getItem("deviceToken");
} }
this.lastLogin = this.cs.sharedService.getSharedData(AuthenticationService.LAST_LOGIN, false); this.lastLogin = this.cs.sharedService.getSharedData(AuthenticationService.LAST_LOGIN, false);
} }
ngOnInit() { ngOnInit() {
//**checkIfAvailable FAIO **// //**checkIfAvailable FAIO **//
this.checkIfAvailable(); this.checkIfAvailable();
//**getSharedData of IMEI_USER_DATA and REGISTER_DATA_FOR_LOGIIN to set defult value **// //**getSharedData of IMEI_USER_DATA and REGISTER_DATA_FOR_LOGIIN to set defult value **//
// this.setDefault(); // this.setDefault();
this.button(); this.button();
} }
checkIfAvailable() { checkIfAvailable() {
this.faio.isAvailable().then( this.faio.isAvailable().then(
options => { options => {
this.isFaceorFinger = options; this.isFaceorFinger = options;
if (this.isFaceorFinger === 'finger' && this.lastLogin === 1) {
this.selectedOption = 2; // && this.lastLogin === 1
this.cs.presentConfirmDialog(
this.ts.trPK("login", "biometric-support"), // if (this.isFaceorFinger === 'finger' || this.isFaceorFinger === 'biometric') {
() => {
this.presentBiometricDialog(); // this.selectedOption = 2;
this.cs.sharedService.setSharedData(
this.selectedOption, // this.cs.presentConfirmDialog(
AuthenticationService.LAST_LOGIN
); // this.ts.trPK("login", "biometric-support"),
},
() => { } // () => {
);
} // this.presentBiometricDialog();
// this.cs.sharedService.setSharedData(
// this.selectedOption,
// AuthenticationService.LAST_LOGIN
// );
// },
// () => { }
// );
// }
this.button(); this.button();
}, },
() => { () => {
this.isFaceorFinger = null; this.isFaceorFinger = null;
this.button(); this.button();
} }
); );
} }
button() { button() {
console.log("button"); console.log("button");
this.buttons = [ this.buttons = [
[{ [{
title: "login,verify-with-fingerprint", title: "login,verify-with-fingerprint",
url: null, url: null,
icon: "assets/icon/login/102.png", icon: "assets/icon/login/102.png",
settings: new ButtonSettings(true, true, true, true), settings: new ButtonSettings(true, true, true, true),
value: 2, value: 2,
disabled: this.isFaceorFinger === "finger" ? false : true,
disabled: this.isFaceorFinger === "finger" || this.isFaceorFinger === "biometric" ? false : true,
visible: this.onlySMSBox visible: this.onlySMSBox
}, },
{ {
title: "login,verify-with-faceid", title: "login,verify-with-faceid",
url: null, url: null,
icon: "assets/icon/login/101.png", icon: "assets/icon/login/101.png",
settings: new ButtonSettings(true, true, true, true), settings: new ButtonSettings(true, true, true, true),
value: 3, value: 3,
disabled: this.isFaceorFinger === "face" ? false : true,
disabled: this.isFaceorFinger === "face" ? false : true,
visible: this.onlySMSBox visible: this.onlySMSBox
}, },
{ {
title: "login,verify-with-whatsapp", title: "login,verify-with-whatsapp",
url: null, url: null,
icon: "assets/icon/login/104.png", icon: "assets/icon/login/104.png",
settings: new ButtonSettings(true, true, true, true), settings: new ButtonSettings(true, true, true, true),
value: 4, value: 4,
visible: true visible: true
}, },
{ {
title: "login,verify-with-sms", title: "login,verify-with-sms",
url: null, url: null,
icon: "assets/icon/login/103.png", icon: "assets/icon/login/103.png",
settings: new ButtonSettings(true, true, true, true), settings: new ButtonSettings(true, true, true, true),
value: 1, value: 1,
visible: true visible: true
} }
] ]
]; ];
} }
confirm(el: any) { confirm(el: any) {
console.log("confirm:"+ el ); console.log("confirm:"+ el );
this.selectedOption = this.selectedOption && !this.onlySMSBox ? this.selectedOption : el.value; this.selectedOption = this.selectedOption && !this.onlySMSBox ? this.selectedOption : el.value;
switch (el.value) { switch (el.value) {
case 1: case 1:
console.log(el.value); console.log(el.value);
this.loginWithSMS(el); this.loginWithSMS(el);
break; break;
case 2: case 2:
console.log(el.value); console.log(el.value);
this.loginWithFingurePrint(el); this.loginWithFingurePrint(el);
break; break;
case 3: case 3:
console.log(el.value); console.log(el.value);
this.faceReconization(el); this.faceReconization(el);
break; break;
case 4: case 4:
console.log(el.value); console.log(el.value);
this.loginWithWhatsapp(el); this.loginWithWhatsapp(el);
break; break;
default: default:
break; break;
} }
this.cs.sharedService.setSharedData( this.cs.sharedService.setSharedData(
this.selectedOption, this.selectedOption,
AuthenticationService.LAST_LOGIN AuthenticationService.LAST_LOGIN
); );
} }
loginWithSMS(el) { loginWithSMS(el) {
console.log("loginWithSMS: "+ el); console.log("loginWithSMS: "+ el);
if (!el.disabled) { if (!el.disabled) {
// if (this.user && !this.registerd_data) { // if (this.user && !this.registerd_data) {
//calling because i dont have token id which required to the send activation code //calling because i dont have token id which required to the send activation code
/// this.checkUserAuthentication(1); /// this.checkUserAuthentication(1);
// this.checkUserAuthentication(); *** // this.checkUserAuthentication(); ***
// } else { // } else {
if (this.loginData.LogInTokenID) { if (this.loginData.LogInTokenID) {
this.sendActivationCode(1); this.sendActivationCode(1);
} else { } else {
// this.checkUserAuthentication(1); // this.checkUserAuthentication(1);
// this.checkUserAuthentication();** // this.checkUserAuthentication();**
} }
// } // }
} }
} }
loginWithWhatsapp(el) { loginWithWhatsapp(el) {
if (!el.disabled) { if (!el.disabled) {
// if (this.user && !this.registerd_data) { // if (this.user && !this.registerd_data) {
//calling because i dont have token id which required to the send activation code //calling because i dont have token id which required to the send activation code
// this.checkUserAuthentication(2); // this.checkUserAuthentication(2);
// } else { // } else {
if (this.loginData.LogInTokenID) { if (this.loginData.LogInTokenID) {
this.sendActivationCode(2); this.sendActivationCode(2);
} else { } else {
// this.checkUserAuthentication(2); // this.checkUserAuthentication(2);
} }
// } // }
} }
} }
public sendActivationCode(type: number) { public sendActivationCode(type: number) {
let request = new SendActivationByType(); let request = new SendActivationByType();
this.authService.setPublicFields(request); this.authService.setPublicFields(request);
request.OTP_SendType = type; request.OTP_SendType = type;
request.MobileNumber = this.loginData.MobileNumber; request.MobileNumber = this.loginData.MobileNumber;
request.IsMobileFingerPrint =0; request.IsMobileFingerPrint =0;
request.P_USER_NAME=this.loginData.P_USER_NAME; request.P_USER_NAME=this.loginData.P_USER_NAME;
request.LogInTokenID =this.loginData.LogInTokenID; request.LogInTokenID =this.loginData.LogInTokenID;
request.P_LEGISLATION_CODE ="SA"; request.P_LEGISLATION_CODE ="SA";
// request.VersionID ="2.0"; // request.VersionID ="2.0";
// request.LanguageID = imeiData && imeiData.PreferredLanguage || request.LanguageID; // request.LanguageID = imeiData && imeiData.PreferredLanguage || request.LanguageID;
this.authService this.authService
.sendActivationCodeByType( .sendActivationCodeByType(
request, request,
() => { }, () => { },
this.ts.trPK("general", "ok") this.ts.trPK("general", "ok")
) )
.subscribe((result: any) => { .subscribe((result: any) => {
if (result.isSMSSent) { if (result.isSMSSent) {
this.cs.sharedService.setSharedData({ this.cs.sharedService.setSharedData({
MobileNumber: this.loginData.mobileNumber, MobileNumber: this.loginData.mobileNumber,
loginType: this.selectedOption loginType: this.selectedOption
}, },
SMSCheckRequest.SHARED_DATA SMSCheckRequest.SHARED_DATA
); );
this.cs.openSMSPage(); this.cs.openSMSPage();
} }
}); });
} }
loginWithFingurePrint(el: any) { loginWithFingurePrint(el: any) {
if (!el.disabled) { if (!el.disabled) {
this.startBiometricLoginIfAvailable(); this.startBiometricLoginIfAvailable();
} }
} }
faceReconization(el: any) { faceReconization(el: any) {
if (!el.disabled) { if (!el.disabled) {
this.startBiometricLoginIfAvailable(); this.startBiometricLoginIfAvailable();
} }
} }
private startBiometricLoginIfAvailable() { private startBiometricLoginIfAvailable() {
// this.setting.isBiometricsEnabled().then(result => { // this.setting.isBiometricsEnabled().then(result => {
// console.log(result); // console.log(result);
this.faio.isAvailable().then( this.faio.isAvailable().then(
options => { options => {
// if biometric supported // if biometric supported
//if (result) { //if (result) {
// ask if login with face or finger // ask if login with face or finger
this.presentBiometricDialog(); this.presentBiometricDialog();
// } else { // } else {
// //ask to enable biometric // //ask to enable biometric
// this.getPermissionToActivateBiometric(); // this.getPermissionToActivateBiometric();
// } // }
}, },
() => { () => {
alert("not avaliable ") alert("not avaliable ")
// if biometric not supported do nothing unless // if biometric not supported do nothing unless
// user session time out from last login // user session time out from last login
// if (AuthenticationService.isRequireRelogin()) { // if (AuthenticationService.isRequireRelogin()) {
// this.initializeInputsFromSessionTimeOut(user); // this.initializeInputsFromSessionTimeOut(user);
// } // }
// this.hideSplashScreen(true); // this.hideSplashScreen(true);
} }
); );
//}); //});
} }
private presentBiometricDialog() { private presentBiometricDialog() {
this.faio this.faio
.show({ .show({
clientId: "Fingerprint Authetnciation",
clientSecret: "Ate343_9347lajF", // Only necessary for Android
disableBackup: true, // Only for Android(optional)
localizedFallbackTitle: this.ts.trPK("general", "use-pin"), // Only for iOS
localizedReason: this.ts.trPK("general", "auth-please") // Only for iOS
title: 'Biometric Authetnciation', // (Android Only) | optional | Default: "<APP_NAME> Biometric Sign On"
// subtitle: 'Coolest Plugin ever' ,// (Android Only) | optional | Default: null
// description: this.ts.trPK("general", "auth-please"),// optional | Default: null
fallbackButtonTitle: this.ts.trPK("general", "use-pin"), // optional | When disableBackup is false defaults to "Use Pin".
// When disableBackup is true defaults to "Cancel"
disableBackup:true, // optional | default: false
// clientId: "Fingerprint Authetnciation",
// clientSecret: "Ate343_9347lajF", // Only necessary for Android
// disableBackup: true, // Only for Android(optional)
// localizedFallbackTitle: this.ts.trPK("general", "use-pin"), // Only for iOS
// localizedReason: this.ts.trPK("general", "auth-please") // Only for iOS
}) })
.then((result: any) => { .then((result: any) => {
console.log("1"); console.log("1");
// this.deviceToken= this.cs.sharedService.getSharedData(AuthenticationService.DEVICE_TOKEN, false); // this.deviceToken= this.cs.sharedService.getSharedData(AuthenticationService.DEVICE_TOKEN, false);
let request = new GetLoginInfoRequest(); let request = new GetLoginInfoRequest();
this.authService.setPublicFields(request); this.authService.setPublicFields(request);
request.MobileNumber = this.loginData.MobileNumber; request.MobileNumber = this.loginData.MobileNumber;
request.P_USER_NAME=this.loginData.P_USER_NAME; request.P_USER_NAME=this.loginData.P_USER_NAME;
request.UserName=this.loginData.P_USER_NAME; request.UserName=this.loginData.P_USER_NAME;
request.LogInTokenID =this.loginData.LogInTokenID; request.LogInTokenID =this.loginData.LogInTokenID;
request.CompanyID =1;//cs=1 , HMG=2 request.CompanyID =1;//cs=1 , HMG=2
request.DeviceType= this.cs.getDeviceType(); request.DeviceType= this.cs.getDeviceType();
request.DeviceToken=this.deviceToken; request.DeviceToken=this.deviceToken;
this.getMobileInfo(request); this.getMobileInfo(request);
}) })
.catch((error: any) => { .catch((error: any) => {
console.log(error); console.log(error);
}); });
} }
private getMobileInfo(request: GetLoginInfoRequest) { private getMobileInfo(request: GetLoginInfoRequest) {
console.log("2"); console.log("2");
this.authService.getLoginInfo(request,() => { },this.ts.trPK("general", "ok")).subscribe((result: GetLoginInfoResponse) => { this.authService.getLoginInfo(request,() => { },this.ts.trPK("general", "ok")).subscribe((result: GetLoginInfoResponse) => {
console.log("authService.getLoginInfo"); console.log("authService.getLoginInfo");
if(result.Mohemm_GetPatientID_List.length > 0){ if(result.Mohemm_GetPatientID_List.length > 0){
if ( result.Mohemm_GetPatientID_List[0].LoginType == 2 || result.Mohemm_GetPatientID_List[0].LoginType == 3) { if ( result.Mohemm_GetPatientID_List[0].LoginType == 2 || result.Mohemm_GetPatientID_List[0].LoginType == 3) {
this.loginTokenID = result.LogInTokenID; this.loginTokenID = result.LogInTokenID;
this.checkSMS(); this.checkSMS();
} else { } else {
this.onlySMSBox = false; this.onlySMSBox = false;
this.button(); this.button();
} }
}else { }else {
this.onlySMSBox = false; this.onlySMSBox = false;
this.button(); this.button();
} }
}); });
} }
public checkSMS() { public checkSMS() {
const data = this.sharedData.getSharedData(AuthenticationService.LOGIN_DATA, false); const data = this.sharedData.getSharedData(AuthenticationService.LOGIN_DATA, false);
const request = new SMSCheckRequest(); const request = new SMSCheckRequest();
request.LogInTokenID = data.LogInTokenID; request.LogInTokenID = data.LogInTokenID;
request.activationCode = ""; request.activationCode = "";
request.P_USER_NAME = data.P_USER_NAME; request.P_USER_NAME = data.P_USER_NAME;
request.MobileNumber = data.MobileNumber; request.MobileNumber = data.MobileNumber;
this.authService this.authService
.checkSMS(request, () => {}, this.ts.trPK("general", "ok")) .checkSMS(request, () => {}, this.ts.trPK("general", "ok"))
.subscribe((result: SMSCheckResponse) => { .subscribe((result: SMSCheckResponse) => {
console.log(result); console.log(result);
if (this.cs.validResponse(result)) { if (this.cs.validResponse(result)) {
AuthenticationService.servicePrivilage=result.Privilege_List; AuthenticationService.servicePrivilage=result.Privilege_List;
this.authService.setAuthenticatedUser(result).subscribe(() => { this.authService.setAuthenticatedUser(result).subscribe(() => {
this.insertMobileLogin();
if (this.platform.is("mobile")) {
this.insertMobileLogin();
}
this.cs.openHome(); this.cs.openHome();
}); });
} }
}); });
} }
public insertMobileLogin(){ public insertMobileLogin(){
let request = new GetLoginInfoRequest(); let request = new GetLoginInfoRequest();
this.authService.setPublicFields(request); this.authService.setPublicFields(request);
request.MobileNumber = this.loginData.MobileNumber; request.MobileNumber = this.loginData.MobileNumber;
request.P_USER_NAME=this.loginData.P_USER_NAME; request.P_USER_NAME=this.loginData.P_USER_NAME;
request.UserName=this.loginData.P_USER_NAME; request.UserName=this.loginData.P_USER_NAME;
request.LogInTokenID =this.loginData.LogInTokenID; request.LogInTokenID =this.loginData.LogInTokenID;
request.CompanyID =1;//CompanyID request.CompanyID =1;//CompanyID
request.DeviceType= this.cs.getDeviceType(); request.DeviceType= this.cs.getDeviceType();
request.DeviceToken=this.deviceToken; request.DeviceToken=this.deviceToken;
//request.TokenID= //request.TokenID=
request.LoginType=this.selectedOption; request.LoginType=this.selectedOption;
this.authService this.authService
.insertMobileLoginInfo( .insertMobileLoginInfo(
request, request,
() => { }, () => { },
this.ts.trPK("general", "ok") this.ts.trPK("general", "ok")
) )
.subscribe((result: any) => { .subscribe((result: any) => {
console.log(result); console.log(result);
console.log("succssful insertMobileLoginInfo" ); console.log("succssful insertMobileLoginInfo" );
}); });
}
} }
}

@ -1,226 +1,462 @@
import { Component, OnInit } from "@angular/core"; import { Component, OnInit } from "@angular/core";
import { ElementRef } from "@angular/core"; import { ElementRef } from "@angular/core";
import { NavController } from "@ionic/angular";
import { NavController, Platform } from "@ionic/angular";
import { TranslatorService } from "src/app/hmg-common/services/translator/translator.service"; import { TranslatorService } from "src/app/hmg-common/services/translator/translator.service";
import { CommonService } from "src/app/hmg-common/services/common/common.service"; import { CommonService } from "src/app/hmg-common/services/common/common.service";
import { SharedDataService } from "src/app/hmg-common/services/shared-data-service/shared-data.service"; import { SharedDataService } from "src/app/hmg-common/services/shared-data-service/shared-data.service";
import { SMSCheckRequest } from "src/app/hmg-common/services/authentication/models/smscheck.request"; import { SMSCheckRequest } from "src/app/hmg-common/services/authentication/models/smscheck.request";
import { LoginModel } from "../models/LoginModel"; import { LoginModel } from "../models/LoginModel";
import { AuthenticationService } from "src/app/hmg-common/services/authentication/authentication.service"; import { AuthenticationService } from "src/app/hmg-common/services/authentication/authentication.service";
import { SMSCheckResponse } from "src/app/hmg-common/services/authentication/models/smscheck.response"; import { SMSCheckResponse } from "src/app/hmg-common/services/authentication/models/smscheck.response";
import { Password } from "../models/password"; import { Password } from "../models/password";
import { GetLoginInfoRequest } from 'src/app/hmg-common/services/authentication/models/get-login-info.request'; import { GetLoginInfoRequest } from 'src/app/hmg-common/services/authentication/models/get-login-info.request';
@Component({ @Component({
selector: "app-sms-page", selector: "app-sms-page",
templateUrl: "./sms-page.page.html", templateUrl: "./sms-page.page.html",
styleUrls: ["./sms-page.page.scss"] styleUrls: ["./sms-page.page.scss"]
}) })
export class SmsPageComponent implements OnInit { export class SmsPageComponent implements OnInit {
public static LOGIN_DATA = "LOGIN_DATA"; public static LOGIN_DATA = "LOGIN_DATA";
Channel: number = 0; Channel: number = 0;
activationCode: string; activationCode: string;
P_SESSION_ID: number; P_SESSION_ID: number;
P_USER_NAME: string; P_USER_NAME: string;
timeInSeconds: any; timeInSeconds: any;
time: any; time: any;
runTimer: any; runTimer: any;
hasStarted: any; hasStarted: any;
hasFinished: any; hasFinished: any;
remainingTime: any; remainingTime: any;
displayTime: any; displayTime: any;
loginTokenID: string; loginTokenID: string;
public isForgetPwd: boolean = false; public isForgetPwd: boolean = false;
public isExpiredPwd: boolean = false; public isExpiredPwd: boolean = false;
public count: number = 0; public count: number = 0;
private loginData = new LoginModel(); private loginData = new LoginModel();
public deviceToken:any; public deviceToken:any;
public loginTypeData:any; public loginTypeData:any;
constructor( constructor(
public navCtrl: NavController, public navCtrl: NavController,
public translate: TranslatorService, public translate: TranslatorService,
public common: CommonService, public common: CommonService,
private elementRef: ElementRef, private elementRef: ElementRef,
public authService: AuthenticationService, public authService: AuthenticationService,
public sharedData: SharedDataService
public sharedData: SharedDataService,
public platform: Platform,
) {} ) {}
ngOnInit() { ngOnInit() {
this.count = 0; this.count = 0;
this.initTimer(); this.initTimer();
this.startTimer(); this.startTimer();
this.isForgetPwd = this.isForgetPwd =
this.sharedData.getSharedData(Password.IS_FORGET_PSW) || false; this.sharedData.getSharedData(Password.IS_FORGET_PSW) || false;
this.isExpiredPwd = this.isExpiredPwd =
this.sharedData.getSharedData(Password.IS_EXPIRED_PSW) || false; this.sharedData.getSharedData(Password.IS_EXPIRED_PSW) || false;
this.loginData= this.sharedData.getSharedData(AuthenticationService.LOGIN_DATA, false); this.loginData= this.sharedData.getSharedData(AuthenticationService.LOGIN_DATA, false);
console.log("loginData : "+ this.loginData); console.log("loginData : "+ this.loginData);
this.deviceToken= this.common.sharedService.getSharedData(AuthenticationService.DEVICE_TOKEN, false); this.deviceToken= this.common.sharedService.getSharedData(AuthenticationService.DEVICE_TOKEN, false);
if(this.deviceToken == undefined){ if(this.deviceToken == undefined){
this.deviceToken = localStorage.getItem("deviceToken"); this.deviceToken = localStorage.getItem("deviceToken");
} }
console.log("deviceToken :"+this.deviceToken); console.log("deviceToken :"+this.deviceToken);
this.loginTypeData= this.common.sharedService.getSharedData(SMSCheckRequest.SHARED_DATA, false); this.loginTypeData= this.common.sharedService.getSharedData(SMSCheckRequest.SHARED_DATA, false);
console.log("loginType :"+this.loginTypeData.loginType); console.log("loginType :"+this.loginTypeData.loginType);
} }
initTimer() { initTimer() {
// Pomodoro is usually for 25 minutes // Pomodoro is usually for 25 minutes
if (!this.timeInSeconds) { if (!this.timeInSeconds) {
this.timeInSeconds = 600; this.timeInSeconds = 600;
} }
this.time = this.timeInSeconds; this.time = this.timeInSeconds;
this.runTimer = false; this.runTimer = false;
this.hasStarted = false; this.hasStarted = false;
this.hasFinished = false; this.hasFinished = false;
this.remainingTime = this.timeInSeconds; this.remainingTime = this.timeInSeconds;
this.displayTime = this.common.getSecondsAsDigitalClock(this.remainingTime); this.displayTime = this.common.getSecondsAsDigitalClock(this.remainingTime);
} }
startTimer() { startTimer() {
this.runTimer = true; this.runTimer = true;
this.hasStarted = true; this.hasStarted = true;
this.timerTick(); this.timerTick();
} }
pauseTimer() { pauseTimer() {
this.runTimer = false; this.runTimer = false;
} }
resumeTimer() { resumeTimer() {
this.startTimer(); this.startTimer();
} }
timerTick() { timerTick() {
setTimeout(() => { setTimeout(() => {
if (!this.runTimer) { if (!this.runTimer) {
return; return;
} }
this.remainingTime--; this.remainingTime--;
this.displayTime = this.common.getSecondsAsDigitalClock( this.displayTime = this.common.getSecondsAsDigitalClock(
this.remainingTime this.remainingTime
); );
if (this.remainingTime > 0) { if (this.remainingTime > 0) {
this.timerTick(); this.timerTick();
} else { } else {
this.hasFinished = true; this.hasFinished = true;
this.pauseTimer(); this.pauseTimer();
this.navCtrl.pop(); this.navCtrl.pop();
} }
}, 1000); }, 1000);
} }
ionViewWillLeave() { ionViewWillLeave() {
this.pauseTimer(); this.pauseTimer();
} }
checkOTPLength(){ checkOTPLength(){
console.log(this.activationCode.length); console.log(this.activationCode.length);
if(this.activationCode.length==4){ if(this.activationCode.length==4){
this.checkVerificationCode(); this.checkVerificationCode();
} }
} }
checkVerificationCode() { checkVerificationCode() {
if (this.count < 3) { if (this.count < 3) {
if ( if (
this.activationCode == undefined || this.activationCode == undefined ||
this.activationCode == null || this.activationCode == null ||
this.activationCode == "" this.activationCode == ""
) { ) {
// this.common.showAlert(this.translate.translate('verificationcode.emptyCode')); // this.common.showAlert(this.translate.translate('verificationcode.emptyCode'));
} else { } else {
this.count = this.count + 1; this.count = this.count + 1;
if (this.isForgetPwd || this.isExpiredPwd) { if (this.isForgetPwd || this.isExpiredPwd) {
this.checkForgetPwdSMS(); this.checkForgetPwdSMS();
} else { } else {
this.checkSMS(); this.checkSMS();
} }
} }
} else { } else {
let msg: string = this.translate.trPK("general", "noOfTriesLogin"); let msg: string = this.translate.trPK("general", "noOfTriesLogin");
this.common.JustAlertDialog(this.translate.trPK("general", "ok"), msg); this.common.JustAlertDialog(this.translate.trPK("general", "ok"), msg);
} }
} }
public checkSMS() { public checkSMS() {
// alert("checkSMS in page") // alert("checkSMS in page")
const data = this.sharedData.getSharedData(AuthenticationService.LOGIN_DATA, false); const data = this.sharedData.getSharedData(AuthenticationService.LOGIN_DATA, false);
const request = new SMSCheckRequest(); const request = new SMSCheckRequest();
request.LogInTokenID = data.LogInTokenID; request.LogInTokenID = data.LogInTokenID;
request.activationCode = this.activationCode; request.activationCode = this.activationCode;
request.P_USER_NAME = data.P_USER_NAME; request.P_USER_NAME = data.P_USER_NAME;
request.MobileNumber = data.MobileNumber; request.MobileNumber = data.MobileNumber;
this.authService this.authService
.checkSMS(request, () => {}, this.translate.trPK("general", "ok")) .checkSMS(request, () => {}, this.translate.trPK("general", "ok"))
.subscribe((result: SMSCheckResponse) => { .subscribe((result: SMSCheckResponse) => {
console.log(result); console.log(result);
if (this.common.validResponse(result)) { if (this.common.validResponse(result)) {
AuthenticationService.servicePrivilage=result.Privilege_List; AuthenticationService.servicePrivilage=result.Privilege_List;
this.authService.setAuthenticatedUser(result).subscribe(() => { this.authService.setAuthenticatedUser(result).subscribe(() => {
//call insert Mobile Login //call insert Mobile Login
this.insertMobileLogin();
if (this.platform.is("mobile")) {
this.insertMobileLogin();
}
this.common.openHome(); this.common.openHome();
}); });
} }
}); });
} }
public insertMobileLogin(){ public insertMobileLogin(){
// alert("insertMobileLogin"); // alert("insertMobileLogin");
let request = new GetLoginInfoRequest(); let request = new GetLoginInfoRequest();
this.authService.setPublicFields(request); this.authService.setPublicFields(request);
request.MobileNumber = this.loginData.MobileNumber; request.MobileNumber = this.loginData.MobileNumber;
request.P_USER_NAME=this.loginData.P_USER_NAME; request.P_USER_NAME=this.loginData.P_USER_NAME;
request.UserName=this.loginData.P_USER_NAME; request.UserName=this.loginData.P_USER_NAME;
request.LogInTokenID =this.loginData.LogInTokenID; request.LogInTokenID =this.loginData.LogInTokenID;
request.CompanyID =1;//CompanyID request.CompanyID =1;//CompanyID
request.DeviceType= this.common.getDeviceType(); request.DeviceType= this.common.getDeviceType();
request.DeviceToken=this.deviceToken; request.DeviceToken=this.deviceToken;
request.LoginType=this.loginTypeData.loginType; request.LoginType=this.loginTypeData.loginType;
this.authService this.authService
.insertMobileLoginInfo( .insertMobileLoginInfo(
request, request,
() => { }, () => { },
this.translate.trPK("general", "ok") this.translate.trPK("general", "ok")
) )
.subscribe((result: any) => { .subscribe((result: any) => {
console.log("successful insertMobileLogin" ); console.log("successful insertMobileLogin" );
}); });
} }
public checkForgetPwdSMS() { public checkForgetPwdSMS() {
const data = this.sharedData.getSharedData(AuthenticationService.LOGIN_DATA, false); const data = this.sharedData.getSharedData(AuthenticationService.LOGIN_DATA, false);
const request = new SMSCheckRequest(); const request = new SMSCheckRequest();
request.LogInTokenID = data.LogInTokenID; request.LogInTokenID = data.LogInTokenID;
request.activationCode = this.activationCode; request.activationCode = this.activationCode;
request.P_USER_NAME = data.P_USER_NAME; request.P_USER_NAME = data.P_USER_NAME;
console.log(data.LogInTokenID); console.log(data.LogInTokenID);
console.log(data.P_USER_NAME); console.log(data.P_USER_NAME);
this.authService this.authService
.checkForgetSMS(request, () => {}, this.translate.trPK("general", "ok")) .checkForgetSMS(request, () => {}, this.translate.trPK("general", "ok"))
.subscribe((result: SMSCheckResponse) => { .subscribe((result: SMSCheckResponse) => {
console.log(result); console.log(result);
if (this.common.validResponse(result)) { if (this.common.validResponse(result)) {
console.log(result); console.log(result);
if (this.isForgetPwd) { if (this.isForgetPwd) {
this.common.openForgotPassword(); this.common.openForgotPassword();
} }
if(this.isExpiredPwd) { if(this.isExpiredPwd) {
this.sharedData.setSharedData(true,Password.IS_EXPIRED_PSW); this.sharedData.setSharedData(true,Password.IS_EXPIRED_PSW);
this.common.openChangePassword(); this.common.openChangePassword();
} }
} }
}); });
} }
} }
Loading…
Cancel
Save