mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-21 13:55:51 +00:00
change login v1 to v2
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { Injectable, ErrorHandler } from '@angular/core';
|
||||
import { StorageService } from './storage.service';
|
||||
import { HttpClient, HttpHeaders, HttpEventType } from '@angular/common/http';
|
||||
import { LoginUserRespose, UserForm, UserSession } from '../models/user.model';
|
||||
import { UserForm, UserSession } from '../models/user.model';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { BehaviorSubject, of } from 'rxjs';
|
||||
import { AlertController, Platform } from '@ionic/angular';
|
||||
@@ -15,6 +15,7 @@ import { PermissionService } from './permission.service';
|
||||
import { HttpErrorHandle } from 'src/app/services/http-error-handle.service';
|
||||
import { captureException } from '@sentry/angular';
|
||||
import { catchError, tap } from 'rxjs/operators';
|
||||
import { UserLoginOutput } from '../core/user/use-case/user-login-use-case.service';
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
@@ -42,12 +43,6 @@ export class AuthService {
|
||||
private errorHandler: ErrorHandler,
|
||||
private platform: Platform,) {
|
||||
|
||||
if (SessionStore.exist) {
|
||||
if (this.p.userPermission(this.p.permissionList.Chat.access) == true) {
|
||||
this.loginToChatWs()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
window.addEventListener('focus', (event) => {
|
||||
if (!this.tabIsActive) {
|
||||
@@ -70,7 +65,7 @@ export class AuthService {
|
||||
|
||||
}
|
||||
|
||||
async login(user: UserForm, { saveSession = true }): Promise<LoginUserRespose> {
|
||||
async login(user: UserForm, { saveSession = true }): Promise<UserSession> {
|
||||
user.BasicAuthKey = btoa(user.username + ':' + this.aesencrypt.encrypt(user.password, user.username));
|
||||
|
||||
this.headers = this.headers.set('Authorization', user.BasicAuthKey);
|
||||
@@ -95,11 +90,11 @@ export class AuthService {
|
||||
let response: any;
|
||||
|
||||
try {
|
||||
response = await this.http.post<LoginUserRespose>(environment.apiURL + "UserAuthentication/Login", body, this.opts).toPromise();
|
||||
response = await this.http.post<UserSession>(environment.apiURL + "UserAuthentication/Login", body, this.opts).toPromise();
|
||||
|
||||
|
||||
if (saveSession) {
|
||||
this.SetSession(response, user)
|
||||
// this.SetSession(response, user)
|
||||
}
|
||||
} catch (error) {
|
||||
this.errorHandler.handleError(error);
|
||||
@@ -116,7 +111,7 @@ export class AuthService {
|
||||
|
||||
}
|
||||
|
||||
async loginContenteProduction(user: UserForm, { saveSession = true }): Promise<LoginUserRespose> {
|
||||
async loginContenteProduction(user: UserForm, { saveSession = true }): Promise<UserSession> {
|
||||
user.BasicAuthKey = 'Basic ' + btoa(user.username + ':' + this.aesencrypt.encrypt(user.password, user.username));
|
||||
|
||||
this.headers = this.headers.set('Authorization', user.BasicAuthKey);
|
||||
@@ -127,7 +122,7 @@ export class AuthService {
|
||||
let response: any;
|
||||
|
||||
try {
|
||||
response = await this.http.post<LoginUserRespose>(environment.apiURL + "UserAuthentication/Login", '', this.opts).toPromise();
|
||||
response = await this.http.post<UserSession>(environment.apiURL + "UserAuthentication/Login", '', this.opts).toPromise();
|
||||
console.log('JWT', response)
|
||||
|
||||
if (saveSession) {
|
||||
@@ -147,96 +142,6 @@ export class AuthService {
|
||||
|
||||
// async UpdateLogin() {}
|
||||
|
||||
SetSession(response: LoginUserRespose, user: UserForm) {
|
||||
const session: UserSession = Object.assign(SessionStore.user, response)
|
||||
|
||||
if (response) {
|
||||
if (session.RoleID == 100000014) {
|
||||
session.Profile = 'PR'
|
||||
} else if (session.RoleID == 100000011) {
|
||||
session.Profile = 'MDGPR'
|
||||
} else if (session.RoleID == 99999872) {
|
||||
session.Profile = 'Consultant'
|
||||
} else if (session.RoleID == 99999886) {
|
||||
session.Profile = 'SGGPR'
|
||||
} else {
|
||||
session.Profile = 'Unknown'
|
||||
}
|
||||
|
||||
session.Password = user.password
|
||||
SessionStore.reset(session)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
this.initialsService.getInitials(session.FullName);
|
||||
}
|
||||
|
||||
loginToChatWs() {
|
||||
setTimeout(() => {
|
||||
|
||||
//if (SessionStore.user.ChatData?.data) {
|
||||
// this.RochetChatConnectorService.logout();
|
||||
// this.RochetChatConnectorService.connect();
|
||||
// this.RochetChatConnectorService.login().then((message: any) => {
|
||||
// console.log('Chat login', message)
|
||||
|
||||
// SessionStore.user.RochetChatUserId = message.result.id
|
||||
// SessionStore.save()
|
||||
|
||||
// this.ChatSystemService.loadChat()
|
||||
// this.RochetChatConnectorService.setStatus('online')
|
||||
// window['RochetChatConnectorService'] = this.RochetChatConnectorService
|
||||
// setTimeout(() => {
|
||||
// this.ChatSystemService.getAllRooms();
|
||||
// this.RochetChatConnectorService.setStatus('online')
|
||||
// }, 200);
|
||||
|
||||
|
||||
// }).catch((error) => {
|
||||
// console.error(SessionStore.user.ChatData, 'web socket login', error)
|
||||
|
||||
// if(window.location.pathname.includes('/home/')) {
|
||||
// setTimeout(() => {
|
||||
// this.loginToChatWs();
|
||||
// }, 4000)
|
||||
// }
|
||||
|
||||
// })
|
||||
//}
|
||||
|
||||
|
||||
|
||||
// before sending a message with a attachment
|
||||
8
|
||||
// this.NfService.downloadFileMsg = async (message: MessageService, room?: RoomService) => {
|
||||
|
||||
// //
|
||||
// let downloadFile = "";
|
||||
// if (message.file.type == "application/img") {
|
||||
// const event: any = await this.AttachmentsService.downloadFile(message.file.guid).toPromise();
|
||||
|
||||
// if (event.type === HttpEventType.DownloadProgress) {
|
||||
// //this.downloadProgess = Math.round((100 * event.loaded) / event.total);
|
||||
// return true
|
||||
// } else if (event.type === HttpEventType.Response) {
|
||||
// downloadFile = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), ''));
|
||||
|
||||
// message.file = {
|
||||
// guid: message.file.guid,
|
||||
// image_url: downloadFile,
|
||||
// type: message.file.type
|
||||
// }
|
||||
|
||||
// return true
|
||||
// }
|
||||
// return false
|
||||
// }
|
||||
// };
|
||||
|
||||
}, 1)
|
||||
}
|
||||
|
||||
autologout(expirationDate: number) {
|
||||
setTimeout(() => {
|
||||
this.logout();
|
||||
@@ -277,7 +182,7 @@ export class AuthService {
|
||||
|
||||
let response: any;
|
||||
try {
|
||||
response = await this.http.delete<LoginUserRespose>(environment.apiURL + "userauthentication/Logout", this.opts).toPromise();
|
||||
response = await this.http.delete<UserSession>(environment.apiURL + "userauthentication/Logout", this.opts).toPromise();
|
||||
SessionStore.user.Authorization = "";
|
||||
SessionStore.user.RefreshToken = "";
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user