This commit is contained in:
tiago.kayaya
2021-05-10 15:06:08 +01:00
3 changed files with 49 additions and 27 deletions
+30 -6
View File
@@ -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;
}
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
}
+2 -2
View File
@@ -1,7 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { AuthService } from 'src/app/services/auth.service';
import { User } from 'src/app/models/user.model';
import { User, UserForm } from 'src/app/models/user.model';
import { ToastService } from 'src/app/services/toast.service';
import { environment } from 'src/environments/environment';
import { AlertController } from '@ionic/angular';
@@ -29,7 +29,7 @@ export class LoginPage implements OnInit {
logstatus: boolean;
username: string = environment.defaultuser;
password: string = environment.defaultuserpwd;
userattempt: User;
userattempt: UserForm;
constructor(
private http: HttpClient,
+17 -19
View File
@@ -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<any>('');
userId$ = new BehaviorSubject<any>('');
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<boolean> {
async login(user: UserForm): Promise<boolean> {
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<boolean>(service, options).toPromise();
response = await this.http.post<any>(environment.apiURL + "UserAuthentication/Login", '', this.opts).toPromise();
response = await this.http.post<User>(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;
}