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

178 lines
5.2 KiB
TypeScript

7 years ago
import { Component, OnInit } from '@angular/core';
import { ElementRef } from '@angular/core';
7 years ago
import { NavController } from '@ionic/angular';
import { TranslatorService } from 'src/app/hmg-common/services/translator/translator.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 { SMSCheckRequest } from 'src/app/hmg-common/services/authentication/models/smscheck.request';
import { LoginModel } from '../models/LoginModel';
import { AuthenticationService } from 'src/app/hmg-common/services/authentication/authentication.service';
import { SMSCheckResponse } from 'src/app/hmg-common/services/authentication/models/smscheck.response';
import { Password } from '../models/password';
7 years ago
@Component({
7 years ago
selector: "app-sms-page",
templateUrl: "./sms-page.page.html",
styleUrls: ["./sms-page.page.scss"]
7 years ago
})
export class SmsPagePage implements OnInit {
7 years ago
public static LOGIN_DATA = 'LOGIN_DATA';
Channel: number = 0;
7 years ago
activationCode: string;
P_SESSION_ID: number;
7 years ago
timeInSeconds: any;
time: any;
runTimer: any;
7 years ago
hasStarted: any;
hasFinished: any;
remainingTime: any;
displayTime: any;
loginTokenID: string;
public isForgetPwd: boolean = false;
public isExpiredPwd: boolean = false;
public count: number = 0;
private loginData = new LoginModel();
7 years ago
7 years ago
constructor(
public navCtrl: NavController,
7 years ago
public translate: TranslatorService,
public common: CommonService,
private elementRef: ElementRef,
public authService: AuthenticationService,
7 years ago
public sharedData: SharedDataService
) {}
7 years ago
ngOnInit() {
this.count = 0;
this.initTimer();
this.startTimer();
this.isForgetPwd = this.sharedData.getSharedData(Password.IS_FORGET_PSW) || false;
}
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) {
return;
}
this.remainingTime--;
7 years ago
this.displayTime = this.common.getSecondsAsDigitalClock(
this.remainingTime
);
if (this.remainingTime > 0) {
this.timerTick();
7 years ago
} else {
this.hasFinished = true;
this.pauseTimer();
this.navCtrl.pop();
}
}, 1000);
}
ionViewWillLeave() {
this.pauseTimer();
}
checkVerificationCode() {
if (this.count < 3) {
7 years ago
if (
this.activationCode == undefined ||
this.activationCode == null ||
this.activationCode == ""
) {
// 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.showAlert(msg);
//this.navCtrl.pop(); goBack
this.common.JustAlertDialog(this.translate.trPK("general", "ok"), msg);
}
7 years ago
};
7 years ago
public checkSMS() {
const data = this.sharedData.getSharedData("logindata", false);
const request = new SMSCheckRequest();
7 years ago
(request.LogInTokenID = data.LogInTokenID),
(request.activationCode = this.activationCode);
//request.P_USER_NAME=this.userName,
//request.MobileNumber=this.member.MemberLoginList.P_MOBILE_NUMBER
7 years ago
this.authService
.checkSMS(request, () => {}, this.translate.trPK("general", "ok"))
.subscribe((result: SMSCheckResponse) => {
console.log(result);
7 years ago
if (this.common.validResponse(result)) {
//this.sharedData.setSharedData(this.loginData, SmsPagePage.LOGIN_DATA);
this.authService.setAuthenticatedUser(result).subscribe(() => {
this.common.openHome();
})
}
});
}
public checkForgetPwdSMS()
{
const data = this.sharedData.getSharedData("logindata", false);
const request = new SMSCheckRequest();
request.LogInTokenID= data.LogInTokenID,
request.activationCode =this.activationCode;
//request.P_USER_NAME=this.userName,
//request.MobileNumber=this.member.MemberLoginList.P_MOBILE_NUMBER
console.log(data.LogInTokenID);
this.authService.checkForgetSMS(
request,
() => {
}, this.translate.trPK('general', 'ok')).subscribe((result: SMSCheckResponse) => {
console.log(result);
if (this.common.validResponse(result)) {
console.log(result);
//this.loginData.LogInTokenID = result.LogInTokenID;
//this.sharedData.setSharedData(this.loginData, "logindata");
this.common.openForgotPassword();
}
});
7 years ago
}
}