auto sms read feature

sultan-q3
Sultan Khan 4 years ago
parent 985103bdb5
commit e765d81711

@ -14,14 +14,15 @@ import { Device } from '@ionic-native/device/ngx';
import { SplashScreen } from '@ionic-native/splash-screen/ngx'; import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { SearchableOptionsModule } from '../hmg-common/ui/searchable-select/searchable-options.module'; import { SearchableOptionsModule } from '../hmg-common/ui/searchable-select/searchable-options.module';
import { MobileNumberModule } from 'src/app/hmg-common/ui/mobile-number/mobile-number.module'; import { MobileNumberModule } from 'src/app/hmg-common/ui/mobile-number/mobile-number.module';
import { SmsdialogPageModule } from 'src/app/hmg-common/ui/smsdialog/smsdialog.module'; import { SmsdialogPageModule } from 'src/app/hmg-common/ui/smsdialog/smsdialog.module';
import { SmsPageModule } from 'src/app/hmg-common/ui/sms/sms.module'; import { SmsPageModule } from 'src/app/hmg-common/ui/sms/sms.module';
import { SmsPageComponent } from './sms-page/sms-page.page'; import { SmsPageComponent } from './sms-page/sms-page.page';
import { CheckUserComponent } from './check-user/check-user.component'; import { CheckUserComponent } from './check-user/check-user.component';
import { ChangePasswordComponent } from './change-password/change-password.component'; import { ChangePasswordComponent } from './change-password/change-password.component';
import {ConfirmLoginComponent} from '../authentication/confirm-login/confirm-login.component' import { ConfirmLoginComponent } from '../authentication/confirm-login/confirm-login.component'
import {WelcomeComponent} from '../authentication/welcome/welcome.component' import { WelcomeComponent } from '../authentication/welcome/welcome.component'
import { SmsRetriever } from '@ionic-native/sms-retriever/ngx';
const routes: Routes = [ const routes: Routes = [
{ {
@ -84,11 +85,12 @@ const routes: Routes = [
// ConfirmLoginComponent, // ConfirmLoginComponent,
WelcomeComponent, WelcomeComponent,
], ],
providers:[ providers: [
FingerprintAIO, FingerprintAIO,
Device, Device,
SplashScreen SplashScreen,
SmsRetriever
], ],
entryComponents:[] entryComponents: []
}) })
export class AuthenticationPageModule { } export class AuthenticationPageModule { }

@ -22,6 +22,7 @@ import { DigitalIdComponent } from '../digital-id/digital-id.component';
import { AppUpdateComponent } from '../app-update/app-update.component'; import { AppUpdateComponent } from '../app-update/app-update.component';
import { Password } from '../models/password'; import { Password } from '../models/password';
import { CheckUserAuthenticationRequest } from 'src/app/hmg-common/services/authentication/models/check-user-auth.request'; import { CheckUserAuthenticationRequest } from 'src/app/hmg-common/services/authentication/models/check-user-auth.request';
import { SmsRetriever } from '@ionic-native/sms-retriever/ngx';
@Component({ @Component({
selector: 'app-confirm-login', selector: 'app-confirm-login',
@ -57,6 +58,7 @@ export class ConfirmLoginComponent implements OnInit {
userInfo: any; userInfo: any;
public businessInfo: object; public businessInfo: object;
private checkUserResult: CheckUserAuthenticationResponse; private checkUserResult: CheckUserAuthenticationResponse;
private signature: string;
constructor( constructor(
public ts: TranslatorService, public ts: TranslatorService,
public cs: CommonService, public cs: CommonService,
@ -67,7 +69,8 @@ export class ConfirmLoginComponent implements OnInit {
public platform: Platform, public platform: Platform,
public modalController: ModalController, public modalController: ModalController,
public alertController: AlertController, public alertController: AlertController,
private nfc: NFC private nfc: NFC,
private smsRetriever: SmsRetriever
) { ) {
this.loginData = this.sharedData.getSharedData(AuthenticationService.LOGIN_DATA, false); this.loginData = this.sharedData.getSharedData(AuthenticationService.LOGIN_DATA, false);
this.deviceToken = this.cs.sharedService.getSharedData(AuthenticationService.DEVICE_TOKEN, false); this.deviceToken = this.cs.sharedService.getSharedData(AuthenticationService.DEVICE_TOKEN, false);
@ -87,6 +90,7 @@ export class ConfirmLoginComponent implements OnInit {
this.direction = TranslatorService.getCurrentLanguageName(); this.direction = TranslatorService.getCurrentLanguageName();
this.userInfo = JSON.parse(localStorage.getItem('digitalIDUser')); this.userInfo = JSON.parse(localStorage.getItem('digitalIDUser'));
this.checkNFCStatus(); this.checkNFCStatus();
this.generateSMSsignature();
// **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 **//
@ -228,13 +232,18 @@ export class ConfirmLoginComponent implements OnInit {
} }
public generateSMSsignature() {
this.smsRetriever.getAppHash()
.then((res: any) => this.signature = res)
.catch((error: any) => console.error(error));
}
public sendActivationCode(type: number) { public sendActivationCode(type: number) {
console.log(this.signature);
const request = new SendActivationByType(); const 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 = '0593233758';//this.loginData.MobileNumber;
request.smsSignature = this.signature;
request.IsMobileFingerPrint = 0; request.IsMobileFingerPrint = 0;
request.P_USER_NAME = this.loginData.P_USER_NAME; request.P_USER_NAME = this.loginData.P_USER_NAME;

@ -2,30 +2,31 @@ import { Request } from 'src/app/hmg-common/services/models/request';
export class SendActivationByType extends Request { export class SendActivationByType extends Request {
P_USER_NAME: string; // id P_USER_NAME: string; // id
UserName:string; UserName: string;
MobileNumber: string; // phone number MobileNumber: string; // phone number
ZipCode: string; ZipCode: string;
LogInTokenID: string; LogInTokenID: string;
OTP_SendType:number; OTP_SendType: number;
IsMobileFingerPrint:number; IsMobileFingerPrint: number;
P_LEGISLATION_CODE:string; P_LEGISLATION_CODE: string;
smsSignature: string;
// VersionID:string; // VersionID:string;
// Test // Test
//{ //{
// "Channel":31, // "Channel":31,
// "LanguageID":2, // "LanguageID":2,
// "LogInTokenID":"Wfm9uDlWhEi3vFsQMqUz3w==", // "LogInTokenID":"Wfm9uDlWhEi3vFsQMqUz3w==",
// "MobileNumber":"0508079569", // "MobileNumber":"0508079569",
// "P_USER_NAME":"191817", // "P_USER_NAME":"191817",
// "UserName":"191817", // "UserName":"191817",
// "VersionID":2.0, // "VersionID":2.0,
// "P_LEGISLATION_CODE":"SA", // "P_LEGISLATION_CODE":"SA",
// "IsMobileFingerPrint":0, // "IsMobileFingerPrint":0,
// "OTP_SendType":1 // "OTP_SendType":1
// } // }

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

@ -27,8 +27,8 @@ export class ConnectorService {
public static retryTimes = 0; public static retryTimes = 0;
public static timeOut = 120 * 1000; public static timeOut = 120 * 1000;
// public static host = 'https://uat.hmgwebservices.com/'; public static host = 'https://uat.hmgwebservices.com/';
public static host = 'https://hmgwebservices.com/'; //public static host = 'https://hmgwebservices.com/';
constructor(public httpClient: HttpClient, constructor(public httpClient: HttpClient,
public cs: CommonService, public cs: CommonService,

Loading…
Cancel
Save