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 { 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 { SmsPageModule } from 'src/app/hmg-common/ui/sms/sms.module';
import { SmsPageComponent } from './sms-page/sms-page.page';
import { CheckUserComponent } from './check-user/check-user.component';
import { ChangePasswordComponent } from './change-password/change-password.component';
import {ConfirmLoginComponent} from '../authentication/confirm-login/confirm-login.component'
import {WelcomeComponent} from '../authentication/welcome/welcome.component'
import { ConfirmLoginComponent } from '../authentication/confirm-login/confirm-login.component'
import { WelcomeComponent } from '../authentication/welcome/welcome.component'
import { SmsRetriever } from '@ionic-native/sms-retriever/ngx';
const routes: Routes = [
{
@ -84,11 +85,12 @@ const routes: Routes = [
// ConfirmLoginComponent,
WelcomeComponent,
],
providers:[
providers: [
FingerprintAIO,
Device,
SplashScreen
SplashScreen,
SmsRetriever
],
entryComponents:[]
entryComponents: []
})
export class AuthenticationPageModule { }

@ -22,6 +22,7 @@ import { DigitalIdComponent } from '../digital-id/digital-id.component';
import { AppUpdateComponent } from '../app-update/app-update.component';
import { Password } from '../models/password';
import { CheckUserAuthenticationRequest } from 'src/app/hmg-common/services/authentication/models/check-user-auth.request';
import { SmsRetriever } from '@ionic-native/sms-retriever/ngx';
@Component({
selector: 'app-confirm-login',
@ -57,6 +58,7 @@ export class ConfirmLoginComponent implements OnInit {
userInfo: any;
public businessInfo: object;
private checkUserResult: CheckUserAuthenticationResponse;
private signature: string;
constructor(
public ts: TranslatorService,
public cs: CommonService,
@ -67,7 +69,8 @@ export class ConfirmLoginComponent implements OnInit {
public platform: Platform,
public modalController: ModalController,
public alertController: AlertController,
private nfc: NFC
private nfc: NFC,
private smsRetriever: SmsRetriever
) {
this.loginData = this.sharedData.getSharedData(AuthenticationService.LOGIN_DATA, 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.userInfo = JSON.parse(localStorage.getItem('digitalIDUser'));
this.checkNFCStatus();
this.generateSMSsignature();
// **checkIfAvailable FAIO **//
this.checkIfAvailable();
// **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) {
console.log(this.signature);
const request = new SendActivationByType();
this.authService.setPublicFields(request);
request.OTP_SendType = type;
request.MobileNumber = this.loginData.MobileNumber;
request.MobileNumber = '0593233758';//this.loginData.MobileNumber;
request.smsSignature = this.signature;
request.IsMobileFingerPrint = 0;
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 {
P_USER_NAME: string; // id
UserName:string;
UserName: string;
MobileNumber: string; // phone number
ZipCode: string;
LogInTokenID: string;
OTP_SendType:number;
IsMobileFingerPrint:number;
P_LEGISLATION_CODE:string;
OTP_SendType: number;
IsMobileFingerPrint: number;
P_LEGISLATION_CODE: string;
smsSignature: string;
// VersionID:string;
// Test
//{
// "Channel":31,
// "LanguageID":2,
// "LogInTokenID":"Wfm9uDlWhEi3vFsQMqUz3w==",
// "MobileNumber":"0508079569",
// "P_USER_NAME":"191817",
// "UserName":"191817",
// "VersionID":2.0,
// "P_LEGISLATION_CODE":"SA",
// "IsMobileFingerPrint":0,
// "OTP_SendType":1
// }
// Test
//{
// "Channel":31,
// "LanguageID":2,
// "LogInTokenID":"Wfm9uDlWhEi3vFsQMqUz3w==",
// "MobileNumber":"0508079569",
// "P_USER_NAME":"191817",
// "UserName":"191817",
// "VersionID":2.0,
// "P_LEGISLATION_CODE":"SA",
// "IsMobileFingerPrint":0,
// "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 * 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();
}
}

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

Loading…
Cancel
Save