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.
185 lines
5.9 KiB
TypeScript
185 lines
5.9 KiB
TypeScript
import { Component, OnInit } from '@angular/core';
|
|
import { SMSDialogService } from './service/smsdialogservice';
|
|
import { ModalController } from '@ionic/angular';
|
|
import { CommonService } from 'src/app/hmg-common/services/common/common.service';
|
|
import { TranslatorService } from 'src/app/hmg-common/services/translator/translator.service';
|
|
import { Response } from 'src/app/hmg-common/services/models/response';
|
|
import { SmsReaderService } from 'src/app/hmg-common/services/sms/sms-reader.service';
|
|
// import { UserDetailsModel } from 'src/app/h2o/service/models/user-details.model';
|
|
// import { SendValidationResponse } from 'src/app/h2o/service/models/send-activation.response';
|
|
import { SharedDataService } from 'src/app/hmg-common/services/shared-data-service/shared-data.service';
|
|
import { CountryCode } from 'src/app/hmg-common/ui/mobile-number/international-mobile/models/country-code.model';
|
|
import { SmsModalComponent } from './sms-modal/sms-modal.component';
|
|
import { AlertController } from '@ionic/angular';
|
|
|
|
@Component({
|
|
selector: 'app-smsdialog',
|
|
templateUrl: './smsdialog.page.html',
|
|
styleUrls: ['./smsdialog.page.scss'],
|
|
})
|
|
export class SmsdialogPage implements OnInit {
|
|
public timeInSeconds: number;
|
|
public time: number;
|
|
public runTimer: boolean;
|
|
public static SHARED_DATA = 'h2o-login-details';
|
|
public hasStarted: boolean;
|
|
public countryCode: CountryCode;
|
|
public hasFinished: boolean;
|
|
public remainingTime: number;
|
|
public displayTime: string = "";
|
|
// public userData: UserDetailsModel;
|
|
public mobile: string;
|
|
public country_code: string;
|
|
public id: string;
|
|
public MobileNumber: string;
|
|
public token: string;
|
|
public resend: boolean = false;
|
|
public smc_code: any;
|
|
constructor(public cs: CommonService,
|
|
public ts: TranslatorService,
|
|
public alertController: AlertController,
|
|
public smsService: SmsReaderService,
|
|
public sharedData: SharedDataService,
|
|
private modalCtrl: ModalController,
|
|
// private navParams: NavParams,
|
|
public smsservice: SMSDialogService) {
|
|
// this.country_code = this.navParams.get("c_code");
|
|
// this.MobileNumber = this.navParams.get('mobile');
|
|
// this.mobile = this.navParams.get('mobile');
|
|
// this.id = this.navParams.get('id');
|
|
// this.smsservice.sendActivationCode(this.id, this.mobile,
|
|
// this.country_code, () => { },
|
|
// this.ts.trPK('general', 'ok')).subscribe((result: SendValidationResponse) => {
|
|
// if (this.cs.validResponse(result)) {
|
|
// if (result.isSMSSent) {
|
|
// this.token = result.LogInTokenID;
|
|
// this.initTimer();
|
|
// this.startTimer();
|
|
// } else {
|
|
// this.stopSMSMonitoring();
|
|
// }
|
|
// } else {
|
|
// this.stopSMSMonitoring();
|
|
// }
|
|
// });
|
|
}
|
|
|
|
ngOnInit() {
|
|
}
|
|
|
|
closeModal() {
|
|
this.modalCtrl.dismiss();
|
|
}
|
|
|
|
cancelModal() {
|
|
this.modalCtrl.dismiss({ cancelled: true });
|
|
}
|
|
|
|
initTimer() {
|
|
if (!this.timeInSeconds) {
|
|
this.timeInSeconds = 60;
|
|
}
|
|
this.time = this.timeInSeconds;
|
|
this.runTimer = false;
|
|
this.hasStarted = false;
|
|
this.hasFinished = false;
|
|
this.remainingTime = this.timeInSeconds;
|
|
this.displayTime = this.getSecondsAsDigitalClock(this.remainingTime);
|
|
}
|
|
|
|
startTimer() {
|
|
this.runTimer = true;
|
|
this.hasStarted = true;
|
|
this.resend = false;
|
|
this.timerTick();
|
|
}
|
|
|
|
pauseTimer() {
|
|
this.runTimer = false;
|
|
}
|
|
|
|
resumeTimer() {
|
|
this.startTimer();
|
|
}
|
|
|
|
timerTick() {
|
|
setTimeout(() => {
|
|
if (!this.runTimer) { return; }
|
|
this.remainingTime--;
|
|
this.displayTime = this.getSecondsAsDigitalClock(this.remainingTime);
|
|
if (this.remainingTime > 0) {
|
|
this.timerTick();
|
|
}
|
|
else {
|
|
this.hasFinished = true;
|
|
this.resend = true;
|
|
}
|
|
}, 1000);
|
|
}
|
|
|
|
getSecondsAsDigitalClock(inputSeconds: number) {
|
|
var sec_num = parseInt(inputSeconds.toString(), 10); // don't forget the second param
|
|
var hours = Math.floor(sec_num / 3600);
|
|
var minutes = Math.floor((sec_num - (hours * 3600)) / 60);
|
|
var seconds = sec_num - (hours * 3600) - (minutes * 60);
|
|
var hoursString = '';
|
|
var minutesString = '';
|
|
var secondsString = '';
|
|
hoursString = (hours < 10) ? "0" + hours : hours.toString();
|
|
minutesString = (minutes < 10) ? "0" + minutes : minutes.toString();
|
|
secondsString = (seconds < 10) ? "0" + seconds : seconds.toString();
|
|
return minutesString + ':' + secondsString;
|
|
}
|
|
|
|
validate() {
|
|
this.checkSMSActivationCode(this.smc_code);
|
|
}
|
|
|
|
public presentSMSPasswordDialog() {
|
|
|
|
}
|
|
|
|
async presentAlert() {
|
|
const alert = await this.alertController.create({
|
|
header: 'Alert',
|
|
message: 'Incorrect OTP, Please enter correct OTP.',
|
|
buttons: ['OK']
|
|
});
|
|
|
|
await alert.present();
|
|
}
|
|
|
|
private checkSMSActivationCode(smsCode: string) {
|
|
this.smsservice.validateActivationCode(this.token, smsCode,
|
|
() => { }, this.ts.trPK('settings', 'incorrect_otp')).subscribe((result: Response) => {
|
|
if (this.cs.validResponse(result)) {
|
|
//this.stopSMSMonitoring();
|
|
this.modalCtrl.dismiss();
|
|
SMSDialogService.modal_success = true;
|
|
}
|
|
});
|
|
}
|
|
|
|
public stopSMSMonitoring() {
|
|
this.smsService.stopSMSMonitoring();
|
|
}
|
|
|
|
public ResendOTP() {
|
|
// this.smsservice.sendActivationCode(this.id, this.mobile,
|
|
// this.country_code, () => { },
|
|
// this.ts.trPK('general', 'ok')).subscribe((result: SendValidationResponse) => {
|
|
// if (this.cs.validResponse(result)) {
|
|
// if (result.isSMSSent) {
|
|
// this.initTimer();
|
|
// this.startTimer();
|
|
// } else {
|
|
// this.stopSMSMonitoring();
|
|
// }
|
|
// } else {
|
|
// this.stopSMSMonitoring();
|
|
// }
|
|
// });
|
|
}
|
|
|
|
}
|