From 426bfb86cabb6c400b36b7004e48268ba9293571 Mon Sep 17 00:00:00 2001 From: umasoodch Date: Thu, 8 Apr 2021 14:15:51 +0300 Subject: [PATCH] fixed session issue --- .../authentication/authentication.service.ts | 28 ++++++++- .../services/connector/connector.service.ts | 57 +++++++++++++++++-- 2 files changed, 78 insertions(+), 7 deletions(-) diff --git a/Mohem/src/app/hmg-common/services/authentication/authentication.service.ts b/Mohem/src/app/hmg-common/services/authentication/authentication.service.ts index 018cb146..688377e5 100644 --- a/Mohem/src/app/hmg-common/services/authentication/authentication.service.ts +++ b/Mohem/src/app/hmg-common/services/authentication/authentication.service.ts @@ -654,11 +654,37 @@ export class AuthenticationService { this.ts.trPK("general", "idle-relogin"), () => { this.cs.sharedService.clearAll(); - this.cs.openLogin(); + // this.cs.openLogin(); + this.getLastLoginInfo(); } ); } + + public getLastLoginInfo() { + let deviceToken = localStorage.getItem('deviceToken'); + + const requestGetLoginInfo = { + DeviceType: this.cs.getDeviceType(), + DeviceToken: deviceToken + }; + + this.getLoginInfo(requestGetLoginInfo, () => {}, this.ts.trPK('general', 'ok')).subscribe(res => { + if (this.cs.validResponse(res)) { + if (res.Mohemm_GetMobileLoginInfoList.length > 0) { + this.cs.sharedService.setSharedData(res.Mohemm_GetMobileLoginInfoList[0], AuthenticationService.IMEI_USER_DATA); + const user = true; + this.events.publish('user', user); + this.cs.openLogin(); + } else { + const user = false; + this.events.publish('user', user); + this.cs.openLogin(); + } + } else {} + }); + } + /* reset and start idling interval */ diff --git a/Mohem/src/app/hmg-common/services/connector/connector.service.ts b/Mohem/src/app/hmg-common/services/connector/connector.service.ts index 5b221dfc..b18145b3 100644 --- a/Mohem/src/app/hmg-common/services/connector/connector.service.ts +++ b/Mohem/src/app/hmg-common/services/connector/connector.service.ts @@ -9,6 +9,10 @@ import { catchError, retry, tap, timeout } from 'rxjs/operators'; import { CommonService } from '../common/common.service'; // import { Response } from "../models/response"; import { Response } from 'src/app/hmg-common/services/models/response'; +import { Events } from "@ionic/angular"; +import { GetLoginInfoResponse } from "src/app/hmg-common/services/authentication/models/get-login-info.response"; +import { GetLoginInfoRequest } from "src/app/hmg-common/services/authentication/models/get-login-info.request"; +import { TranslatorService } from "../translator/translator.service"; @Injectable({ providedIn: 'root' @@ -26,7 +30,10 @@ export class ConnectorService { // public static host = 'https://uat.hmgwebservices.com/'; public static host = 'https://hmgwebservices.com/'; - constructor(public httpClient: HttpClient, public cs: CommonService) {} + constructor(public httpClient: HttpClient, + public cs: CommonService, + private events: Events, + public ts: TranslatorService) {} public post( service: string, @@ -173,6 +180,44 @@ export class ConnectorService { } } + public getLoginInfo( + request: any, + onError: any, + errorLabel: string + ): Observable { + //this.setPublicFields(request); + return this.post( + 'Services/ERP.svc/REST/Mohemm_GetMobileLoginInfo_NEW', + request, + onError, + errorLabel + ); + } + + public getLastLoginInfo() { + let deviceToken = localStorage.getItem('deviceToken'); + + const requestGetLoginInfo = { + DeviceType: this.cs.getDeviceType(), + DeviceToken: deviceToken + }; + + this.getLoginInfo(requestGetLoginInfo, () => {}, this.ts.trPK('general', 'ok')).subscribe(res => { + if (this.cs.validResponse(res)) { + if (res.Mohemm_GetMobileLoginInfoList.length > 0) { + this.cs.sharedService.setSharedData(res.Mohemm_GetMobileLoginInfoList[0], 'imei-user-data'); + const user = true; + this.events.publish('user', user); + this.cs.openLogin(); + } else { + const user = false; + this.events.publish('user', user); + this.cs.openLogin(); + } + } else {} + }); + } + public handleResponse(result: Response, onError: any, errorLabel: string, isPostNoLoad = false) { if (!isPostNoLoad) { this.cs.stopLoading(); @@ -182,8 +227,8 @@ export class ConnectorService { this.cs.stopLoading(); this.cs.presentAcceptDialog(result.ErrorEndUserMessage, () => { this.cs.sharedService.clearAll(); - this.cs.openLogin(); - + // this.cs.openLogin(); + this.getLastLoginInfo(); }); return false; } else if (result.ErrorType === 2 || result.ErrorType === 4) { @@ -212,9 +257,9 @@ export class ConnectorService { this.cs.stopLoading(); this.cs.presentAcceptDialog(result.ErrorEndUserMessage, () => { console.log("presentAcceptDialog"); - this.cs.sharedService.clearAll(); - this.cs.openLogin(); - + this.cs.sharedService.clearAll(); + // this.cs.openLogin(); + this.getLastLoginInfo(); }); return false; } else if (result.ErrorType === 2 || result.ErrorType === 4) {