diff --git a/src/app/models/user.model.ts b/src/app/models/user.model.ts index a2ee351ba..c62516027 100644 --- a/src/app/models/user.model.ts +++ b/src/app/models/user.model.ts @@ -1,7 +1,31 @@ +export class UserForm { + username: string; + password: string; + domainName: string; + BasicAuthKey: string; +} + + export class User { - username: string; - password: string; - domainName: string; - BasicAuthKey: string; - UserId?: number; - } \ No newline at end of file + username: string; + password: string; + domainName: string; + BasicAuthKey: string; + UserId?: number; + Authorization: string; + Email: string + FullName: string + OwnerCalendars: { + CalendarId: string + CalendarName: "Oficial" | "Pessoal" + Id: 1 + }[] + RoleDescription: string + RoleID: number + SharedCalendars: { + CalendarId: string + CalendarName: "Oficial" | "Pessoal" + Id: 1 + }[] + UserName: string +} \ No newline at end of file diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts index 010d31514..108cfab54 100644 --- a/src/app/services/auth.service.ts +++ b/src/app/services/auth.service.ts @@ -2,7 +2,7 @@ import { Injectable } from '@angular/core'; import { StorageService } from './storage.service'; import { Router } from '@angular/router'; import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; -import { User } from '../models/user.model'; +import { User, UserForm } from '../models/user.model'; import { environment } from 'src/environments/environment'; import { HttpService } from './http.service'; import { BehaviorSubject, Observable } from 'rxjs'; @@ -15,25 +15,26 @@ export class AuthService { userData$ = new BehaviorSubject(''); userId$ = new BehaviorSubject(''); headers: HttpHeaders; + public ValidatedUser:User; opts:any; + constructor( private http: HttpClient, private httpService: HttpService, private storageService:StorageService, private router:Router ) { + this.headers = new HttpHeaders(); - //if(!environment.production){ - if (localStorage.getItem("user") != null) { - this.ValidatedUser = JSON.parse(localStorage.getItem('user')); - } - //} + if (localStorage.getItem("user") != null) { + this.ValidatedUser = JSON.parse(localStorage.getItem('user')); + } } - public ValidatedUser:User; + - async login(user: User): Promise { + async login(user: UserForm): Promise { user.BasicAuthKey = 'Basic ' + btoa(user.username + '@' + user.domainName + ':' + user.password); //conversão em base64 das credenciais inseridas @@ -48,20 +49,17 @@ export class AuthService { let response: any; result = await this.http.get(service, options).toPromise(); - response = await this.http.post(environment.apiURL + "UserAuthentication/Login", '', this.opts).toPromise(); + response = await this.http.post(environment.apiURL + "UserAuthentication/Login", '', this.opts).toPromise(); - if (result) - { - this.ValidatedUser = user; - console.log(user); - + console.log(response) - //if(!environment.production){ - localStorage.setItem('user', JSON.stringify(Object.assign(user, response))); - //} + if (result) { + this.ValidatedUser = response; - this.storageService.store(AuthConnstants.USER, response); - } + localStorage.setItem('user', JSON.stringify(response)); + + this.storageService.store(AuthConnstants.USER, response); + } return result; }