mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
auto login chat
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree, Router } from '@angular/router';
|
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree, Router } from '@angular/router';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
|
import { AuthService } from '../services/auth.service';
|
||||||
import { LocalstoreService } from '../store/localstore.service';
|
import { LocalstoreService } from '../store/localstore.service';
|
||||||
import { SessionStore } from '../store/session.service';
|
import { SessionStore } from '../store/session.service';
|
||||||
|
|
||||||
@@ -10,7 +11,8 @@ import { SessionStore } from '../store/session.service';
|
|||||||
export class AuthGuard implements CanActivate {
|
export class AuthGuard implements CanActivate {
|
||||||
constructor(
|
constructor(
|
||||||
private router:Router,
|
private router:Router,
|
||||||
private localstoreService: LocalstoreService
|
private localstoreService: LocalstoreService,
|
||||||
|
private authService: AuthService,
|
||||||
){}
|
){}
|
||||||
|
|
||||||
canActivate(
|
canActivate(
|
||||||
@@ -25,6 +27,7 @@ export class AuthGuard implements CanActivate {
|
|||||||
this.router.navigate(['/']);
|
this.router.navigate(['/']);
|
||||||
return false
|
return false
|
||||||
} else {
|
} else {
|
||||||
|
this.authService.loginChat(SessionStore.user)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,7 +84,6 @@ export class SetRoomOwnerPage implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.chatService.addGroupOwner(body).subscribe((res)=>{
|
this.chatService.addGroupOwner(body).subscribe((res)=>{
|
||||||
alert('here');
|
|
||||||
console.log(res);
|
console.log(res);
|
||||||
this.close();
|
this.close();
|
||||||
this.toastService._successMessage('Operação realizada com sucesso');
|
this.toastService._successMessage('Operação realizada com sucesso');
|
||||||
|
|||||||
-1
@@ -261,7 +261,6 @@ export class BookMeetingModalPage implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(this.task.FsId == '8') {
|
if(this.task.FsId == '8') {
|
||||||
alert('Chegou')
|
|
||||||
const loader = this.toastService.loading()
|
const loader = this.toastService.loading()
|
||||||
try {
|
try {
|
||||||
switch (this.loggeduser.Profile) {
|
switch (this.loggeduser.Profile) {
|
||||||
|
|||||||
@@ -100,7 +100,6 @@ export class LoginPage implements OnInit {
|
|||||||
|
|
||||||
// login to API successfully
|
// login to API successfully
|
||||||
if (attempt) {
|
if (attempt) {
|
||||||
|
|
||||||
if (attempt.UserId == SessionStore.user.UserId) {
|
if (attempt.UserId == SessionStore.user.UserId) {
|
||||||
await this.authService.SetSession(attempt, this.userattempt);
|
await this.authService.SetSession(attempt, this.userattempt);
|
||||||
await this.authService.loginChat(this.userattempt);
|
await this.authService.loginChat(this.userattempt);
|
||||||
|
|||||||
@@ -103,44 +103,41 @@ export class AuthService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Login to rocketChat server
|
//Login to rocketChat server2
|
||||||
async loginChat(user: UserForm) {
|
//user: UserForm
|
||||||
const expireDate = new Date(new Date().getTime() + 60*1000);
|
async loginChat(user: any) {
|
||||||
|
|
||||||
|
const expirationMinutes = 60;
|
||||||
|
let date = new Date().getTime();
|
||||||
|
let expirationDate = new Date(new Date().getTime() + expirationMinutes*60*1000);
|
||||||
|
|
||||||
let postData = {
|
let postData = {
|
||||||
"user": user.username,
|
"user": user.RochetChatUser,
|
||||||
"password": user.password,
|
"password": user.Password,
|
||||||
}
|
}
|
||||||
|
|
||||||
let responseChat = await this.httpService.post('login', postData).toPromise();
|
let responseChat = await this.httpService.post('login', postData).toPromise();
|
||||||
|
|
||||||
if(responseChat) {
|
if(responseChat) {
|
||||||
|
console.log('Login to Rocket chat OK', responseChat);
|
||||||
setTimeout(()=>{
|
|
||||||
|
|
||||||
this.WsChatService.connect();
|
|
||||||
this.WsChatService.login().then((message) => {
|
|
||||||
console.log('rocket chat login successfully', message)
|
|
||||||
this.WsChatService.setStatus('online')
|
|
||||||
}).catch((message)=>{
|
|
||||||
console.log('rocket chat login failed', message)
|
|
||||||
})
|
|
||||||
}, 1)
|
|
||||||
|
|
||||||
console.log('Login to Rocket chat OK');
|
|
||||||
this.ValidatedUserChat = responseChat;
|
this.ValidatedUserChat = responseChat;
|
||||||
localStorage.setItem('userChat', JSON.stringify(responseChat));
|
localStorage.setItem('userChat', JSON.stringify(responseChat));
|
||||||
this.storageService.store(AuthConnstants.AUTH, responseChat);
|
this.storageService.store(AuthConnstants.AUTH, responseChat);
|
||||||
|
//return true;
|
||||||
this.autologout(10000);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
console.log('Network error');
|
console.log('Network error');
|
||||||
this.presentAlert('Network error');
|
this.presentAlert('Network error');
|
||||||
return false;
|
//return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.autoLoginChat(expirationDate.getTime() - date, user);
|
||||||
|
}
|
||||||
|
|
||||||
|
async autoLoginChat(expirationDate:number, user:any){
|
||||||
|
setTimeout(()=>{
|
||||||
|
this.loginChat(user);
|
||||||
|
}, expirationDate)
|
||||||
}
|
}
|
||||||
|
|
||||||
autologout(expirationDate:number){
|
autologout(expirationDate:number){
|
||||||
|
|||||||
@@ -336,7 +336,7 @@ export class FileService {
|
|||||||
quality: 50,
|
quality: 50,
|
||||||
// allowEditing: true,
|
// allowEditing: true,
|
||||||
resultType: CameraResultType.Uri,
|
resultType: CameraResultType.Uri,
|
||||||
source: CameraSource.Camera
|
source: CameraSource.Photos
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -378,6 +378,8 @@ export class FileService {
|
|||||||
//loader.remove();
|
//loader.remove();
|
||||||
});
|
});
|
||||||
*/ }
|
*/ }
|
||||||
|
|
||||||
|
|
||||||
addPictureToChat(roomId) {
|
addPictureToChat(roomId) {
|
||||||
|
|
||||||
console.log('add picture to chat')
|
console.log('add picture to chat')
|
||||||
|
|||||||
@@ -67,7 +67,6 @@ export class NewGroupPage implements OnInit{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ngOnDestroy(){
|
/* ngOnDestroy(){
|
||||||
alert('Destroy')
|
|
||||||
this.dataService.set("newGroup", false);
|
this.dataService.set("newGroup", false);
|
||||||
this.dataService.set("task", null);
|
this.dataService.set("task", null);
|
||||||
this.dataService.set("newGroupName", '');
|
this.dataService.set("newGroupName", '');
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class SessionService {
|
|||||||
// main data
|
// main data
|
||||||
private _user = new UserSession()
|
private _user = new UserSession()
|
||||||
// local storage keyName
|
// local storage keyName
|
||||||
private keyName: string;
|
private keyName: string;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|
||||||
@@ -73,7 +73,7 @@ class SessionService {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return this._user.PIN.length >= 2
|
return this._user.PIN.length >= 2
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
reset(user) {
|
reset(user) {
|
||||||
@@ -98,4 +98,4 @@ class SessionService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export const SessionStore = new SessionService()
|
export const SessionStore = new SessionService()
|
||||||
|
|||||||
Reference in New Issue
Block a user