mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
changes on Rocket Chat authentication
This commit is contained in:
@@ -7,6 +7,7 @@ import { environment } from 'src/environments/environment';
|
||||
import { HttpService } from './http.service';
|
||||
import { BehaviorSubject, Observable } from 'rxjs';
|
||||
import { AuthConnstants } from '../config/auth-constants';
|
||||
import { AlertController } from '@ionic/angular';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -16,13 +17,15 @@ export class AuthService {
|
||||
userId$ = new BehaviorSubject<any>('');
|
||||
headers: HttpHeaders;
|
||||
public ValidatedUser:User;
|
||||
public ValidatedUserChat:any;
|
||||
opts:any;
|
||||
|
||||
constructor(
|
||||
private http: HttpClient,
|
||||
private httpService: HttpService,
|
||||
private storageService:StorageService,
|
||||
private router:Router
|
||||
private router:Router,
|
||||
public alertController: AlertController,
|
||||
) {
|
||||
|
||||
this.headers = new HttpHeaders();
|
||||
@@ -30,6 +33,9 @@ export class AuthService {
|
||||
if (localStorage.getItem("user") != null) {
|
||||
this.ValidatedUser = JSON.parse(localStorage.getItem('user'));
|
||||
}
|
||||
if (localStorage.getItem("userChat") != null) {
|
||||
this.ValidatedUserChat = JSON.parse(localStorage.getItem('userChat'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -75,12 +81,30 @@ export class AuthService {
|
||||
}
|
||||
|
||||
//Login to rocketChat server
|
||||
loginChat(postData: any):Observable<any> {
|
||||
console.log(postData);
|
||||
|
||||
return this.httpService.post('login', postData);
|
||||
async loginChat(user: UserForm): Promise<boolean> {
|
||||
let postData = {
|
||||
"user": user.username,
|
||||
"password": user.password,
|
||||
}
|
||||
|
||||
let responseChat = await this.httpService.post('login', postData).toPromise();
|
||||
if(responseChat){
|
||||
console.log('Login to Rocket chat OK');
|
||||
this.ValidatedUserChat = responseChat;
|
||||
localStorage.setItem('userChat', JSON.stringify(responseChat));
|
||||
this.storageService.store(AuthConnstants.AUTH, responseChat);
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
console.log('Network error');
|
||||
this.presentAlert('Network error');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//Get user data from RocketChat | global object
|
||||
getUserData(){
|
||||
this.storageService.get(AuthConnstants.AUTH).then(res=>{
|
||||
@@ -108,4 +132,14 @@ export class AuthService {
|
||||
}) */
|
||||
|
||||
}
|
||||
async presentAlert(message: string) {
|
||||
const alert = await this.alertController.create({
|
||||
cssClass: 'my-custom-class',
|
||||
header: 'Mensagem do sistema',
|
||||
message: message,
|
||||
buttons: ['OK']
|
||||
});
|
||||
|
||||
await alert.present();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user