- add method get user from room in ws api

- Modified logout method
This commit is contained in:
tiago.kayaya
2022-02-02 11:57:11 +01:00
parent 49146e61da
commit 7237d90653
4 changed files with 69 additions and 15 deletions
+27 -8
View File
@@ -11,6 +11,7 @@ import { SessionStore } from '../store/session.service';
import { AESEncrypt } from '../services/aesencrypt.service';
import { CookieService } from 'ngx-cookie-service';
import { WsChatService } from 'src/app/services/chat/ws-chat.service';
import { Router } from '@angular/router';
@Injectable({
providedIn: 'root'
})
@@ -31,7 +32,8 @@ export class AuthService {
public alertController: AlertController,
private aesencrypt: AESEncrypt,
private cookieService: CookieService,
private WsChatService: WsChatService) {
private WsChatService: WsChatService,
private router: Router,) {
this.headers = new HttpHeaders();
@@ -101,12 +103,9 @@ export class AuthService {
}
}
logout() {
this.ValidatedUser = null;
}
//Login to rocketChat server
async loginChat(user: UserForm) {
const expireDate = new Date(new Date().getTime() + 60*1000);
let postData = {
"user": user.username,
"password": user.password,
@@ -128,13 +127,14 @@ export class AuthService {
}, 1)
console.log('Login to Rocket chat OK');
this.ValidatedUserChat = responseChat;
localStorage.setItem('userChat', JSON.stringify(responseChat));
this.storageService.store(AuthConnstants.AUTH, responseChat);
this.autologout(10000);
return true;
}
else{
console.log('Network error');
@@ -143,6 +143,25 @@ export class AuthService {
}
}
autologout(expirationDate:number){
setTimeout(()=>{
this.logout();
}, expirationDate)
}
logout() {
this.ValidatedUser = null;
localStorage.removeItem('userChat');
SessionStore.setInativity(false)
SessionStore.setUrlBeforeInactivity(this.router.url)
setTimeout(() => {
this.router.navigateByUrl('/', { replaceUrl: true });
}, 100)
}
//Get user data from RocketChat | global object
getUserData(){
this.storageService.get(AuthConnstants.AUTH).then(res=>{