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/sms-page/sms-page.page.ts

462 lines
7.4 KiB
TypeScript

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