update home

production
Sultan Khan 7 years ago
parent eea8947dc7
commit 947fbda4da

@ -32,73 +32,72 @@ import { ForgetPassword } from 'src/app/authentication/models/forget.password';
providedIn: "root" providedIn: "root"
}) })
export class AuthenticationService { export class AuthenticationService {
public static MOBILE_USER = 102;
/* login methods */ public static MOBILE_USER = 102;
public static loginURL =
"Services/Authentication.svc/REST/CheckPatientAuthentication"; /* login methods */
public static checkUserAuthURL = public static loginURL = 'Services/Authentication.svc/REST/CheckPatientAuthentication';
"Services/Authentication.svc/REST/CheckPatientAuthentication"; public static checkUserAuthURL = 'Services/Authentication.svc/REST/CheckPatientAuthentication';
public static login = "Services/ERP.svc/REST/MemberLogin"; public static login = 'Services/ERP.svc/REST/MemberLogin';
public static activationCodeURL = public static activationCodeURL = 'Services/Authentication.svc/REST/CheckActivationCode';
"Services/Authentication.svc/REST/CheckActivationCode"; public static getLoginInfoURL = 'Services/Authentication.svc/REST/GetMobileLoginInfo';
public static getLoginInfoURL =
"Services/Authentication.svc/REST/GetMobileLoginInfo"; public static smsCheck='Services/ERP.svc/REST/CheckActivationCode';
public static smsCheckForget='Services/ERP.svc/REST/CheckPublicActivationCode';
public static smsCheck = "Services/ERP.svc/REST/CheckActivationCode"; public static smsSendCode='Services/ERP.svc/REST/SendPublicActivationCode';
public static smsCheckForget =
"Services/ERP.svc/REST/CheckPublicActivationCode"; /* register methods */
public static smsSendCode = "Services/ERP.svc/REST/SendPublicActivationCode";
public static checkPatientForRegisterationURL = 'Services/Authentication.svc/REST/CheckPatientForRegisteration';
/* register methods */ public static sendSmsForRegisterURL = 'Services/Authentication.svc/REST/SendSMSForPatientRegisteration';
public static registerTempUserURL = 'Services/Authentication.svc/REST/RegisterTempPatientWithoutSMS';
public static checkPatientForRegisterationURL =
"Services/Authentication.svc/REST/CheckPatientForRegisteration"; public static sendSMSForgotFileNoURL = 'Services/Authentication.svc/REST/SendPatientIDSMSByMobileNumber';
public static sendSmsForRegisterURL = public static forgotFileIDURL = 'Services/Authentication.svc/REST/CheckActivationCodeForSendFileNo';
"Services/Authentication.svc/REST/SendSMSForPatientRegisteration"; public static user: AuthenticatedUser;
public static registerTempUserURL =
"Services/Authentication.svc/REST/RegisterTempPatientWithoutSMS"; /*user checking methods */
public static userChecking = 'Services/ERP.svc/REST/Get_BasicUserInformation';
public static sendSMSForgotFileNoURL = public static changePasswordForget ='Services/ERP.svc/REST/ChangePassword_Forget';
"Services/Authentication.svc/REST/SendPatientIDSMSByMobileNumber";
public static forgotFileIDURL = public static LOGIN_EVENT = 'user-login-event';
"Services/Authentication.svc/REST/CheckActivationCodeForSendFileNo"; public static FAMILY_LOGIN_EVENT = 'family-login-event';
public static user: AuthenticatedUser; public static AUTHENTICATED_USER_KEY = 'save-authenticated-user';
public static LOGIN_EVENT = "user-login-event";
public static FAMILY_LOGIN_EVENT = "family-login-event";
public static AUTHENTICATED_USER_KEY = "save-authenticated-user";
// private static user: AuthenticatedUser;
// private static user: AuthenticatedUser; constructor(
constructor( public con: ConnectorService,
public con: ConnectorService, public cs: CommonService,
public cs: CommonService, public ts: TranslatorService,
public ts: TranslatorService, public nativeStorage: NativeStorage,
public nativeStorage: NativeStorage, public localNotifications: UserLocalNotificationService,
public localNotifications: UserLocalNotificationService, private events: Events
private events: Events ) { }
) {}
public authenticateRequest(request: Request, automaticLogin = true): Request {
public authenticateRequest(request: Request, automaticLogin = true): Request {
this.setPublicFields(request); this.setPublicFields(request);
const user = this.getAuthenticatedUser(); const user = this.getAuthenticatedUser();
if (user) { if (user) {
/*user with eye prescriptions*/ request.P_SESSION_ID = user.P_SESSION_ID;
request.P_SESSION_ID = user.P_SESSION_ID; request.MobileNumber = user.EMPLOYEE_MOBILE_NUMBER;
request.MobileNumber = user.EMPLOYEE_MOBILE_NUMBER; request.LogInTokenID = user.LogInTokenID;
request.LogInTokenID = user.LogInTokenID; request.TokenID = user.TokenID;
request.TokenID = user.TokenID; request.P_USER_NAME = user.EMPLOYEE_NUMBER;
request.P_USER_NAME = user.EMPLOYEE_NUMBER; request.UserName = user.EMPLOYEE_NUMBER;
request.UserName = user.EMPLOYEE_NUMBER; if (AuthenticationService.requireRelogin) {
if (AuthenticationService.requireRelogin) { this.sessionTimeOutDialog();
this.sessionTimeOutDialog(); }
} } else {
} else { this.cs.userNeedToReLogin();
this.cs.userNeedToReLogin(); }
} /*
/*
else { else {
if (automaticLogin) { if (automaticLogin) {
this.cs.openUserLogin(); this.cs.openUserLogin();
@ -118,7 +117,6 @@ export class AuthenticationService {
//request.isDentalAllowedBackend = false; //request.isDentalAllowedBackend = false;
return request; return request;
} }
public authenticateAndSetPersonalInformation( public authenticateAndSetPersonalInformation(
request: EmailRequest, request: EmailRequest,
examinationInfo?: any examinationInfo?: any
@ -164,71 +162,67 @@ export class AuthenticationService {
return request; return request;
} }
public getAuthenticatedRequest(login = true): Request { public getAuthenticatedRequest(login = true): Request {
const request = new Request(); const request = new Request();
this.authenticateRequest(request, login); this.authenticateRequest(request, login);
return request; return request;
} }
public getPublicRequest(): Request {
const request = new Request();
this.setPublicFields(request);
return request;
}
public login(
request: LoginRequest,
onError: any,
errorLabel: string
): Observable<Response> {
request.PatientID = 0;
request.TokenID = "";
request.isDentalAllowedBackend = false;
request.isRegister = false;
return this.con.post(
AuthenticationService.loginURL,
request,
onError,
errorLabel
);
}
public isAuthenticated(): boolean { public getPublicRequest(): Request {
return AuthenticationService.user != null; const request = new Request();
} this.setPublicFields(request);
return request;
}
/**
* this fucntion load from user information if he logged in before
* and save user into memory and local storage
* disable notifications for previous user if new user logged in with different user
*
*
* info:
* 1- user stored in local storage without token
* @param result check activation code result
*/
public setAuthenticatedUser(
result: CheckActivationCodeResponse
): Observable<boolean> {
return Observable.create(observer => {
this.loadAuthenticatedUser().subscribe(
(loadedUser: AuthenticatedUser) => {
AuthenticationService.requireRelogin = false;
this.startIdleMonitoring();
const user = this.updateAuthenticatedUser(result, loadedUser);
/* we store in hd without token but with token in memory*/
this.saveUserInStorage(user).subscribe((success: boolean) => {
AuthenticationService.user = user;
this.publishUserChangeEvent();
observer.next(true);
observer.complete();
});
}
);
});
}
public login(request: LoginRequest, onError: any, errorLabel: string): Observable<Response> {
this.setPublicFields(request);
return this.con.post(AuthenticationService.login, request, onError, errorLabel);
}
public isAuthenticated(): boolean {
return AuthenticationService.user != null;
}
/**
* this fucntion load from user information if he logged in before
* and save user into memory and local storage
* disable notifications for previous user if new user logged in with different user
*
*
* info:
* 1- user stored in local storage without token
* @param result check activation code result
*/
public setAuthenticatedUser(
result: CheckActivationCodeResponse
): Observable<boolean> {
return Observable.create(observer => {
this.loadAuthenticatedUser().subscribe(
(loadedUser: AuthenticatedUser) => {
AuthenticationService.requireRelogin = false;
this.startIdleMonitoring();
const user = this.updateAuthenticatedUser(result, loadedUser);
/* we store in hd without token but with token in memory*/
this.saveUserInStorage(user).subscribe((success: boolean) => {
AuthenticationService.user = user;
this.publishUserChangeEvent();
observer.next(true);
observer.complete();
});
}
);
});
}
public resetAuthenticatedUser(user: AuthenticatedUser) { public resetAuthenticatedUser(user: AuthenticatedUser) {
AuthenticationService.user = user; AuthenticationService.user = user;
AuthenticationService.requireRelogin = false; AuthenticationService.requireRelogin = false;
@ -260,7 +254,6 @@ export class AuthenticationService {
}); });
}); });
} }
public setDeviceToken(token: string) { public setDeviceToken(token: string) {
const user = this.getAuthenticatedUser(); const user = this.getAuthenticatedUser();
if (user) { if (user) {
@ -355,7 +348,6 @@ export class AuthenticationService {
} }
}); });
} }
/** /**
* signout * signout
*clear user session and storage information *clear user session and storage information
@ -428,52 +420,41 @@ export class AuthenticationService {
return AuthenticationService.user; return AuthenticationService.user;
} }
*/ */
return AuthenticationService.user; return AuthenticationService.user;
} }
public checkUserAuthentication(
request: CheckUserAuthenticationRequest,
onError: any,
errorLabel: string
): Observable<CheckUserAuthenticationResponse> {
this.setPublicFields(request);
return this.con.post(
AuthenticationService.login,
request,
onError,
errorLabel
);
}
public checkActivationCode( public checkUserAuthentication(request: CheckUserAuthenticationRequest, onError: any, errorLabel: string)
request: CheckActivationCodeRequest, : Observable<CheckUserAuthenticationResponse> {
onError: any, this.setPublicFields(request);
errorLabel: string return this.con.post(AuthenticationService.userChecking, request, onError, errorLabel);
): Observable<CheckActivationCodeResponse> { }
this.setPublicFields(request);
return this.con.post(
AuthenticationService.activationCodeURL,
request,
onError,
errorLabel
);
}
public checkSMS( public checkActivationCode(request: CheckActivationCodeRequest, onError: any, errorLabel: string)
request: SMSCheckRequest, : Observable<CheckActivationCodeResponse> {
onError: any, this.setPublicFields(request);
errorLabel: string return this.con.post(AuthenticationService.activationCodeURL, request, onError, errorLabel);
): Observable<SMSCheckResponse> { }
//this.setPublicFields(request);
return this.con.post(
AuthenticationService.smsCheck,
request,
onError,
errorLabel
);
}
/* public checkSMS(request: SMSCheckRequest, onError: any, errorLabel: string)
: Observable<SMSCheckResponse> {
this.setPublicFields(request);
return this.con.post(AuthenticationService.smsCheck, request, onError, errorLabel);
}
public checkForgetSMS(request: SMSCheckRequest, onError: any, errorLabel: string)
: Observable<SMSCheckResponse> {
this.setPublicFields(request);
return this.con.post(AuthenticationService.smsCheckForget, request, onError, errorLabel);
}
public sendPublicSMS(request: SMSCheckRequest, onError: any, errorLabel: string)
: Observable<CheckUserAuthenticationResponse> {
this.setPublicFields(request);
return this.con.post(AuthenticationService.smsSendCode, request, onError, errorLabel);
}
/*
client side: client side:
id no , mobile no , zip code id no , mobile no , zip code
*/ */
@ -482,112 +463,90 @@ export class AuthenticationService {
client side: client side:
id no , mobile no , zip code id no , mobile no , zip code
*/ */
public sendSmsForPatientRegisteration( public sendSmsForPatientRegisteration(request: CheckPatientRegisterationRequest, onError: any, errorLabel: string)
request: CheckPatientRegisterationRequest, : Observable<CheckUserAuthenticationResponse> {
onError: any, this.setPublicFields(request);
errorLabel: string request.TokenID = '';
): Observable<CheckUserAuthenticationResponse> { request.isRegister = false;
this.setPublicFields(request); return this.con.post(AuthenticationService.sendSmsForRegisterURL, request, onError, errorLabel);
request.TokenID = ""; }
request.isRegister = false;
return this.con.post(
AuthenticationService.sendSmsForRegisterURL,
request,
onError,
errorLabel
);
}
public checkRegisterationActivationCode( public checkRegisterationActivationCode(request: CheckRegisterationCodeRequest, onError: any, errorLabel: string)
request: CheckRegisterationCodeRequest, : Observable<Response> {
onError: any, this.setPublicFields(request);
errorLabel: string return this.con.post(AuthenticationService.activationCodeURL, request, onError, errorLabel);
): Observable<Response> { }
this.setPublicFields(request);
return this.con.post(
AuthenticationService.activationCodeURL,
request,
onError,
errorLabel
);
}
public sendSMSForForgotFileNumber( public sendForgetPassword(request: ForgetPassword, onError: any, errorLabel: string)
request: CheckUserAuthenticationRequest, : Observable<CheckUserAuthenticationResponse> {
onError: any, this.setPublicFields(request);
errorLabel: string return this.con.post(AuthenticationService.smsSendCode, request, onError, errorLabel);
): Observable<CheckUserAuthenticationResponse> { }
this.setPublicFields(request);
request.TokenID = "";
// request.PatientIdentificationID = '';
// request.PatientID = 0;
//request.SearchType = 2;
//request.isRegister = false;
return this.con.post(
AuthenticationService.sendSMSForgotFileNoURL,
request,
onError,
errorLabel
);
}
public forgotFileIdActivation( public submitForgetPassword(request: ForgetPassword, onError: any, errorLabel: string)
request: CheckActivationCodeRequest, : Observable<CheckUserAuthenticationResponse> {
onError: any, this.setPublicFields(request);
errorLabel: string return this.con.post(AuthenticationService.changePasswordForget, request, onError, errorLabel);
): Observable<ForgotFileIDResponse> { }
this.setPublicFields(request);
request.TokenID = "";
request.PatientIdentificationID = "";
// request.PatientID = 0;
request.SearchType = 2;
request.isRegister = false;
return this.con.post(
AuthenticationService.forgotFileIDURL,
request,
onError,
errorLabel
);
}
public isSAUDIIDValid(id: string): boolean {
if (!id) { public sendSMSForForgotFileNumber(request: CheckUserAuthenticationRequest, onError: any, errorLabel: string)
return false; : Observable<CheckUserAuthenticationResponse> {
this.setPublicFields(request);
request.TokenID = '';
//request.SearchType = 2;
//request.isRegister = false;
return this.con.post(AuthenticationService.sendSMSForgotFileNoURL, request, onError, errorLabel);
} }
try {
id = id.toString(); public forgotFileIdActivation(request: CheckActivationCodeRequest, onError: any, errorLabel: string)
id = id.trim(); : Observable<ForgotFileIDResponse> {
const returnValue = Number(id); this.setPublicFields(request);
let sum = 0; request.TokenID = '';
if (returnValue > 0) { request.SearchType = 2;
const type = Number(id.charAt(0)); request.isRegister = false;
return this.con.post(AuthenticationService.forgotFileIDURL, request, onError, errorLabel);
if (id.length !== 10) { }
return false;
}
if (type !== 2 && type !== 1) { public isSAUDIIDValid(id: string): boolean {
if (!id) {
return false; return false;
} }
try {
for (let i = 0; i < 10; i++) { id = id.toString();
if (i % 2 === 0) { id = id.trim();
const a = id.charAt(i); const returnValue = Number(id);
const x = Number(a) * 2; let sum = 0;
let b = x.toString(); if (returnValue > 0) {
if (b.length === 1) { const type = Number(id.charAt(0));
b = "0" + b;
if (id.length !== 10) {
return false;
}
if (type !== 2 && type !== 1) {
return false;
} }
sum += Number(b.charAt(0)) + Number(b.charAt(1));
} else { for (let i = 0; i < 10; i++) {
sum += Number(id.charAt(i)); if (i % 2 === 0) {
const a = id.charAt(i);
const x = Number(a) * 2;
let b = x.toString();
if (b.length === 1) {
b = "0" + b;
}
sum += Number(b.charAt(0)) + Number(b.charAt(1));
} else {
sum += Number(id.charAt(i));
}
}
return sum % 10 === 0;
} }
} } catch (err) {}
return sum % 10 === 0; return false;
} }
} catch (err) {}
return false;
}
public checkUserHasEmailDialog(): Observable<void> { public checkUserHasEmailDialog(): Observable<void> {
return Observable.create(observer => { return Observable.create(observer => {
if (this.isAuthenticatedUserHasRealEmail()) { if (this.isAuthenticatedUserHasRealEmail()) {

Loading…
Cancel
Save