|
|
|
|
@ -13,7 +13,7 @@ import { Password } from '../models/password';
|
|
|
|
|
import { GetLoginInfoRequest } from 'src/app/hmg-common/services/authentication/models/get-login-info.request';
|
|
|
|
|
import * as moment from 'moment';
|
|
|
|
|
import { NFC } from "@ionic-native/nfc/ngx";
|
|
|
|
|
|
|
|
|
|
import { SmsRetriever } from '@ionic-native/sms-retriever/ngx';
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-sms-page',
|
|
|
|
|
templateUrl: './sms-page.page.html',
|
|
|
|
|
@ -53,7 +53,7 @@ export class SmsPageComponent implements OnInit {
|
|
|
|
|
public showErrorMessage = false;
|
|
|
|
|
public messageValue: string;
|
|
|
|
|
public businessInfo: object;
|
|
|
|
|
|
|
|
|
|
public isAutoRead: boolean = false;
|
|
|
|
|
constructor(
|
|
|
|
|
public navCtrl: NavController,
|
|
|
|
|
public translate: TranslatorService,
|
|
|
|
|
@ -62,15 +62,16 @@ export class SmsPageComponent implements OnInit {
|
|
|
|
|
public authService: AuthenticationService,
|
|
|
|
|
public sharedData: SharedDataService,
|
|
|
|
|
public platform: Platform,
|
|
|
|
|
private nfc: NFC
|
|
|
|
|
) {}
|
|
|
|
|
private nfc: NFC,
|
|
|
|
|
private smsRetriever: SmsRetriever
|
|
|
|
|
) { }
|
|
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
|
this.checkNFCStatus();
|
|
|
|
|
this.activeType=this.common.getActiveTypeLogin();
|
|
|
|
|
console.log("active "+ this.common.sharedService.getSharedData('active-type',true));
|
|
|
|
|
this.activeType = this.common.getActiveTypeLogin();
|
|
|
|
|
console.log("active " + this.common.sharedService.getSharedData('active-type', true));
|
|
|
|
|
|
|
|
|
|
console.log("activeType :"+this.activeType);
|
|
|
|
|
console.log("activeType :" + this.activeType);
|
|
|
|
|
this.count = 0;
|
|
|
|
|
this.initTimer();
|
|
|
|
|
this.startTimer();
|
|
|
|
|
@ -84,16 +85,25 @@ export class SmsPageComponent implements OnInit {
|
|
|
|
|
}
|
|
|
|
|
console.log('deviceToken :' + this.deviceToken);
|
|
|
|
|
this.loginTypeData = this.common.sharedService.getSharedData(SMSCheckRequest.SHARED_DATA, false);
|
|
|
|
|
if( this.loginTypeData){
|
|
|
|
|
this.loginType=this.loginTypeData.loginType;
|
|
|
|
|
|
|
|
|
|
console.log("loginType :"+this.loginTypeData.loginType);
|
|
|
|
|
}else{
|
|
|
|
|
this.loginType=1;
|
|
|
|
|
}
|
|
|
|
|
if (this.loginTypeData) {
|
|
|
|
|
this.loginType = this.loginTypeData.loginType;
|
|
|
|
|
|
|
|
|
|
console.log("loginType :" + this.loginTypeData.loginType);
|
|
|
|
|
} else {
|
|
|
|
|
this.loginType = 1;
|
|
|
|
|
}
|
|
|
|
|
this.smsRetriever.startWatching()
|
|
|
|
|
.then((res: any) => this.checkActivation(res))
|
|
|
|
|
.catch((error: any) => console.error(error));
|
|
|
|
|
}
|
|
|
|
|
checkActivation(res) {
|
|
|
|
|
this.isAutoRead = true;
|
|
|
|
|
var pattern = /\d+/g;
|
|
|
|
|
var code = res.Message.match(pattern)[0];
|
|
|
|
|
this.activationCode = code
|
|
|
|
|
this.smc_code = code.split('');
|
|
|
|
|
this.checkVerificationCode();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
initTimer() {
|
|
|
|
|
if (!this.timeInSeconds) {
|
|
|
|
|
this.timeInSeconds = 120;
|
|
|
|
|
@ -178,7 +188,7 @@ export class SmsPageComponent implements OnInit {
|
|
|
|
|
if (err === "NO_NFC") {
|
|
|
|
|
this.isNFCAvailable = false;
|
|
|
|
|
} else if (err === "NFC_DISABLED") {
|
|
|
|
|
this.isNFCAvailable = true;
|
|
|
|
|
this.isNFCAvailable = true;
|
|
|
|
|
} else {
|
|
|
|
|
this.isNFCAvailable = false;
|
|
|
|
|
}
|
|
|
|
|
@ -186,81 +196,81 @@ export class SmsPageComponent implements OnInit {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public checkSMS() {
|
|
|
|
|
this.showErrorMessage = false;
|
|
|
|
|
const data = this.sharedData.getSharedData(AuthenticationService.LOGIN_DATA, false);
|
|
|
|
|
const request = new SMSCheckRequest();
|
|
|
|
|
request.LogInTokenID = data.LogInTokenID;
|
|
|
|
|
request.activationCode = this.code; // code;this.activationCode;
|
|
|
|
|
request.P_USER_NAME = data.P_USER_NAME;
|
|
|
|
|
request.MobileNumber = data.MobileNumber;
|
|
|
|
|
request.IsDeviceNFC = this.isNFCAvailable;
|
|
|
|
|
this.authService.checkSMS(request, () => {}, this.translate.trPK('general', 'ok'), true).subscribe((result: SMSCheckResponse) => {
|
|
|
|
|
if (this.common.validResponse(result)) {
|
|
|
|
|
this.showErrorMessage = false;
|
|
|
|
|
const data = this.sharedData.getSharedData(AuthenticationService.LOGIN_DATA, false);
|
|
|
|
|
const request = new SMSCheckRequest();
|
|
|
|
|
request.LogInTokenID = data.LogInTokenID;
|
|
|
|
|
request.activationCode = this.code; // code;this.activationCode;
|
|
|
|
|
request.P_USER_NAME = data.P_USER_NAME;
|
|
|
|
|
request.MobileNumber = data.MobileNumber;
|
|
|
|
|
request.IsDeviceNFC = this.isNFCAvailable;
|
|
|
|
|
this.authService.checkSMS(request, () => { }, this.translate.trPK('general', 'ok'), true).subscribe((result: SMSCheckResponse) => {
|
|
|
|
|
if (this.common.validResponse(result)) {
|
|
|
|
|
|
|
|
|
|
//save business card info
|
|
|
|
|
this.businessInfo = {
|
|
|
|
|
show_business: result.BusinessCardPrivilege,
|
|
|
|
|
name_en: result.MemberInformationList[0].EMPLOYEE_NAME_En,
|
|
|
|
|
job_en: result.MemberInformationList[0].JOB_NAME_En,
|
|
|
|
|
name_ar: result.MemberInformationList[0].EMPLOYEE_NAME_Ar,
|
|
|
|
|
job_ar: result.MemberInformationList[0].JOB_NAME_Ar,
|
|
|
|
|
mobile: result.MemberInformationList[0].MobileNumberWithZipCode,
|
|
|
|
|
qr: result.MemberInformationList[0].BusinessCardQR,
|
|
|
|
|
company_logo: result.BC_Logo ? result.BC_Logo: result.CompanyImageURL,
|
|
|
|
|
company_url: result.BC_Domain,
|
|
|
|
|
company_type: result.CompanyMainCompany,
|
|
|
|
|
email: result.MemberInformationList[0].EMPLOYEE_EMAIL_ADDRESS
|
|
|
|
|
}
|
|
|
|
|
//save business card info
|
|
|
|
|
this.businessInfo = {
|
|
|
|
|
show_business: result.BusinessCardPrivilege,
|
|
|
|
|
name_en: result.MemberInformationList[0].EMPLOYEE_NAME_En,
|
|
|
|
|
job_en: result.MemberInformationList[0].JOB_NAME_En,
|
|
|
|
|
name_ar: result.MemberInformationList[0].EMPLOYEE_NAME_Ar,
|
|
|
|
|
job_ar: result.MemberInformationList[0].JOB_NAME_Ar,
|
|
|
|
|
mobile: result.MemberInformationList[0].MobileNumberWithZipCode,
|
|
|
|
|
qr: result.MemberInformationList[0].BusinessCardQR,
|
|
|
|
|
company_logo: result.BC_Logo ? result.BC_Logo : result.CompanyImageURL,
|
|
|
|
|
company_url: result.BC_Domain,
|
|
|
|
|
company_type: result.CompanyMainCompany,
|
|
|
|
|
email: result.MemberInformationList[0].EMPLOYEE_EMAIL_ADDRESS
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Wifi Credientials
|
|
|
|
|
CommonService.MOHEMM_WIFI_SSID = result.Mohemm_Wifi_SSID;
|
|
|
|
|
CommonService.MOHEMM_WIFI_PASSWORD = result.Mohemm_Wifi_Password;
|
|
|
|
|
localStorage.setItem('bussiness-card-info', JSON.stringify(this.businessInfo));
|
|
|
|
|
// this.common.sharedService.setSharedData(this.businessInfo,'bussiness-card-info');
|
|
|
|
|
// Wifi Credientials
|
|
|
|
|
CommonService.MOHEMM_WIFI_SSID = result.Mohemm_Wifi_SSID;
|
|
|
|
|
CommonService.MOHEMM_WIFI_PASSWORD = result.Mohemm_Wifi_Password;
|
|
|
|
|
localStorage.setItem('bussiness-card-info', JSON.stringify(this.businessInfo));
|
|
|
|
|
// this.common.sharedService.setSharedData(this.businessInfo,'bussiness-card-info');
|
|
|
|
|
|
|
|
|
|
AuthenticationService.servicePrivilage = result.Privilege_List;
|
|
|
|
|
this.authService.setAuthenticatedUser(result).subscribe(() => {
|
|
|
|
|
localStorage.setItem('emp-name', result.MemberInformationList[0].EMPLOYEE_NAME);
|
|
|
|
|
this.user_name = result.MemberInformationList[0].EMPLOYEE_NAME;
|
|
|
|
|
const currDateTime = moment().format('MMM DD , YYYY HH:mm');
|
|
|
|
|
localStorage.setItem('login-at', currDateTime);
|
|
|
|
|
if (this.platform.is('cordova')) {
|
|
|
|
|
this.insertMobileLogin();
|
|
|
|
|
}
|
|
|
|
|
this.common.sharedService.setSharedData(result.MemberInformationList[0].PAYROLL_CODE, "projcet-code");
|
|
|
|
|
this.activeType =this.common.setActiveTypeLogin(0);
|
|
|
|
|
this.common.openHome();
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
let errorResult: any;
|
|
|
|
|
errorResult = result;
|
|
|
|
|
this.showErrorMessage = true;
|
|
|
|
|
this.messageValue = errorResult.ErrorEndUserMessage;
|
|
|
|
|
this.smc_code = [];
|
|
|
|
|
(document.activeElement as HTMLElement).blur();
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.showErrorMessage = false;
|
|
|
|
|
}, 5000);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
AuthenticationService.servicePrivilage = result.Privilege_List;
|
|
|
|
|
this.authService.setAuthenticatedUser(result).subscribe(() => {
|
|
|
|
|
localStorage.setItem('emp-name', result.MemberInformationList[0].EMPLOYEE_NAME);
|
|
|
|
|
this.user_name = result.MemberInformationList[0].EMPLOYEE_NAME;
|
|
|
|
|
const currDateTime = moment().format('MMM DD , YYYY HH:mm');
|
|
|
|
|
localStorage.setItem('login-at', currDateTime);
|
|
|
|
|
if (this.platform.is('cordova')) {
|
|
|
|
|
this.insertMobileLogin();
|
|
|
|
|
}
|
|
|
|
|
this.common.sharedService.setSharedData(result.MemberInformationList[0].PAYROLL_CODE, "projcet-code");
|
|
|
|
|
this.activeType = this.common.setActiveTypeLogin(0);
|
|
|
|
|
this.common.openHome();
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
let errorResult: any;
|
|
|
|
|
errorResult = result;
|
|
|
|
|
this.showErrorMessage = true;
|
|
|
|
|
this.messageValue = errorResult.ErrorEndUserMessage;
|
|
|
|
|
this.smc_code = [];
|
|
|
|
|
(document.activeElement as HTMLElement).blur();
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.showErrorMessage = false;
|
|
|
|
|
}, 5000);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public insertMobileLogin() {
|
|
|
|
|
const 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; // "5ca8a69cf1804db55264c349edffb99b9d63acd9fa9b6b18956bcb2ad3f2ba36";//this.deviceToken;
|
|
|
|
|
request.LoginType = this.loginTypeData.loginType;
|
|
|
|
|
request.EmployeeName = this.user_name;
|
|
|
|
|
this.authService.insertMobileLoginInfo(request, () => { }, this.translate.trPK('general', 'ok'), this.isPostNoLoad)
|
|
|
|
|
.subscribe((result: any) => {
|
|
|
|
|
console.log('successful insertMobileLogin' );
|
|
|
|
|
});
|
|
|
|
|
const 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; // "5ca8a69cf1804db55264c349edffb99b9d63acd9fa9b6b18956bcb2ad3f2ba36";//this.deviceToken;
|
|
|
|
|
request.LoginType = this.loginTypeData.loginType;
|
|
|
|
|
request.EmployeeName = this.user_name;
|
|
|
|
|
this.authService.insertMobileLoginInfo(request, () => { }, this.translate.trPK('general', 'ok'), this.isPostNoLoad)
|
|
|
|
|
.subscribe((result: any) => {
|
|
|
|
|
console.log('successful insertMobileLogin');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public checkForgetPwdSMS() {
|
|
|
|
|
@ -269,28 +279,28 @@ export class SmsPageComponent implements OnInit {
|
|
|
|
|
request.LogInTokenID = data.LogInTokenID;
|
|
|
|
|
request.activationCode = this.code; // this.activationCode;
|
|
|
|
|
request.P_USER_NAME = data.P_USER_NAME;
|
|
|
|
|
this.authService.checkForgetSMS(request, () => {}, this.translate.trPK('general', 'ok')).subscribe((result: SMSCheckResponse) => {
|
|
|
|
|
if (this.common.validResponse(result)) {
|
|
|
|
|
this.sharedData.setSharedData(result, 'checkSMSResponse');
|
|
|
|
|
if (this.isForgetPwd) {
|
|
|
|
|
this.common.openForgotPassword();
|
|
|
|
|
}
|
|
|
|
|
if (this.isExpiredPwd) {
|
|
|
|
|
this.sharedData.setSharedData(true, Password.IS_EXPIRED_PSW);
|
|
|
|
|
this.common.openChangePassword();
|
|
|
|
|
}
|
|
|
|
|
this.authService.checkForgetSMS(request, () => { }, this.translate.trPK('general', 'ok')).subscribe((result: SMSCheckResponse) => {
|
|
|
|
|
if (this.common.validResponse(result)) {
|
|
|
|
|
this.sharedData.setSharedData(result, 'checkSMSResponse');
|
|
|
|
|
if (this.isForgetPwd) {
|
|
|
|
|
this.common.openForgotPassword();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if (this.isExpiredPwd) {
|
|
|
|
|
this.sharedData.setSharedData(true, Password.IS_EXPIRED_PSW);
|
|
|
|
|
this.common.openChangePassword();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onChange() {
|
|
|
|
|
// tslint:disable-next-line: only-arrow-functions
|
|
|
|
|
const filtered = this.smc_code.filter(function(el) {
|
|
|
|
|
const filtered = this.smc_code.filter(function (el) {
|
|
|
|
|
if (el) {
|
|
|
|
|
return el;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if (filtered.length === 4) {
|
|
|
|
|
if (filtered.length === 4 && !this.isAutoRead) {
|
|
|
|
|
this.checkVerificationCode();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|