mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 21:06:06 +00:00
Revisão: Autenticação, Page Events, Page Expediente.
This commit is contained in:
@@ -2,10 +2,10 @@ import { Injectable } from '@angular/core';
|
||||
import { StorageService } from './storage.service';
|
||||
import { HttpService } from './http.service';
|
||||
import { Router } from '@angular/router';
|
||||
import { Observable } from 'rxjs';
|
||||
import { AuthConnstants } from '../config/auth-constants';
|
||||
import axios from "axios";
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { User } from '../models/user.model';
|
||||
import { environment } from 'src/environments/environment';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -15,70 +15,38 @@ export class AuthService {
|
||||
|
||||
|
||||
constructor(
|
||||
private httpService: HttpService,
|
||||
private storageService: StorageService,
|
||||
private router: Router,
|
||||
private http: HttpClient
|
||||
) { }
|
||||
|
||||
async login(postData: any): Promise<any> {
|
||||
public ValidatedUser:User;
|
||||
|
||||
var session_url = 'https://gpr-dev-08.gabinetedigital.local/api/v2.0/me';
|
||||
var credentials = btoa(postData.domainName + '\\' + postData.username + ':' + postData.password); //conversão em base64 das credenciais inseridas
|
||||
var statusresult = -1;
|
||||
async login(user: User): Promise<boolean> {
|
||||
user.domainName = environment.domain;
|
||||
user.BasicAuthKey = 'Basic ' + btoa(user.domainName + '\\' + user.username + ':' + user.password); //conversão em base64 das credenciais inseridas
|
||||
|
||||
//configuração dos headers para autênticação básica, passando as credenciais convertidas em base64
|
||||
var config = {
|
||||
headers: {
|
||||
'Authorization': 'Basic ' + credentials,
|
||||
},
|
||||
};
|
||||
|
||||
await axios.get(session_url, config)
|
||||
.then(function (response) {
|
||||
statusresult = response.status;
|
||||
})
|
||||
.catch(function (error) {
|
||||
if (error.response) {
|
||||
statusresult = error.response.status;
|
||||
}
|
||||
});
|
||||
|
||||
if (statusresult == 200)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
if (statusresult == 401)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
const options = { headers: {'Authorization': user.BasicAuthKey }};
|
||||
const service = environment.apiURL + "userauthentication/GetValidateAuth";
|
||||
|
||||
let result: boolean | PromiseLike<boolean>;
|
||||
|
||||
try {
|
||||
result = await this.http.get<boolean>(service, options).toPromise();
|
||||
} catch(e) {
|
||||
console.log(e);
|
||||
result = false;
|
||||
}
|
||||
|
||||
if (result)
|
||||
{
|
||||
this.ValidatedUser = user;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/* logout(){
|
||||
this.storageService.removeStorageItem(AuthConnstants.AUTH).then(res =>{
|
||||
this.router.navigate([''])
|
||||
})
|
||||
|
||||
} */
|
||||
validateLogin(){
|
||||
const options = { headers: {'Authorization': 'Basic cGF1bG8ucGludG86dGFidGVzdGVAMDA2'}};
|
||||
const url = 'http://gpr-dev-01.gabinetedigital.local/GabineteDigital.Services/api/calendar/ValidateAuth';
|
||||
/* return this.http.get(`${url}`, options); */
|
||||
axios.get(url, options)
|
||||
.then(resp => {
|
||||
if(resp.data)
|
||||
console.log(resp.data);
|
||||
})
|
||||
.catch(err => {
|
||||
// Handle Error Here
|
||||
console.error(err);
|
||||
});
|
||||
logout(){
|
||||
this.ValidatedUser = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,8 +4,11 @@ import { Event } from '../models/event.model';
|
||||
import axios from 'axios'
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { stringify } from 'querystring';
|
||||
import { AuthService } from '../services/auth.service';
|
||||
import { User } from '../models/user.model';
|
||||
import { CalModalPageRoutingModule } from '../pages/cal-modal/cal-modal-routing.module';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -56,18 +59,31 @@ export class EventsService {
|
||||
Attachments: null,
|
||||
}
|
||||
];
|
||||
options = {};
|
||||
loggeduser: User;
|
||||
|
||||
url = 'http://gpr-dev-01.gabinetedigital.local/GabineteDigital.Services/api/calendar/GetEvents?StartDate=2020-08-14 00:00:00&EndDate=2020-08-19 23:59:00&CalendarName=Pessoal';
|
||||
options = { headers: {'Authorization': 'Basic cGF1bG8ucGludG86dGFidGVzdGVAMDA2'}};
|
||||
|
||||
constructor(private http: HttpClient) { }
|
||||
constructor(private http: HttpClient, private user: AuthService) {
|
||||
this.loggeduser = user.ValidatedUser;
|
||||
this.options = { headers: {'Authorization': this.loggeduser.BasicAuthKey}};
|
||||
}
|
||||
|
||||
allEvents(): Observable<Event[]>{
|
||||
return this.http.get<Event[]>(`${this.url}`, this.options)
|
||||
console.log(this.loggeduser);
|
||||
const geturl = environment.apiURL + 'calendar/GetEvents?StartDate=2020-08-14 00:00:00&EndDate=2020-08-19 23:59:00&CalendarName=Pessoal';
|
||||
|
||||
return this.http.get<Event[]>(`${geturl}`, this.options)
|
||||
}
|
||||
getEvent(ev: string): Observable<Event>{
|
||||
const url = 'http://gpr-dev-01.gabinetedigital.local/GabineteDigital.Services/api/calendar/GetEvent?EventId=';
|
||||
return this.http.get<Event>(`${url + ev}`, this.options)
|
||||
const geturl = environment.apiURL + 'calendar/GetEvent?EventId=';
|
||||
|
||||
return this.http.get<Event>(`${geturl + ev}`, this.options)
|
||||
}
|
||||
|
||||
PutEvent(event: Event): Observable<Event>
|
||||
{
|
||||
const puturl = environment.apiURL +'calendar/PutEvent?conflictResolutionMode=2&sendInvitationsOrCancellationsMode=3';
|
||||
|
||||
return this.http.put<Event>(`${puturl}`, event,this.options)
|
||||
}
|
||||
|
||||
AddEvent(postEvent: any){
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { ProcessesService } from './processes.service';
|
||||
|
||||
describe('ProcessesService', () => {
|
||||
let service: ProcessesService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(ProcessesService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,48 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
import { DailyWorkTask } from '../models/dailyworktask.model';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ProcessesService {
|
||||
|
||||
constructor() { }
|
||||
|
||||
GetDailyWorkCount()
|
||||
{
|
||||
return 100;
|
||||
}
|
||||
|
||||
private tasks: DailyWorkTask[] = [
|
||||
{
|
||||
SerialNumber: "1",
|
||||
Folio: "Teste 1",
|
||||
Senders: "MINEC, MINPLAN, MINFIN",
|
||||
CreateDate: "2020-08-18"
|
||||
},
|
||||
{
|
||||
SerialNumber: "2",
|
||||
Folio: "Teste 2",
|
||||
Senders: "MINFIN",
|
||||
CreateDate: "2020-08-19"
|
||||
},{
|
||||
SerialNumber: "3",
|
||||
Folio: "Teste 3",
|
||||
Senders: "MINEC",
|
||||
CreateDate: "2020-08-20"
|
||||
}
|
||||
];
|
||||
|
||||
GetDailyWorkTasks()
|
||||
{
|
||||
return this.tasks;
|
||||
}
|
||||
|
||||
GetTaskDetail(serialnumber:string)
|
||||
{
|
||||
console.log(serialnumber);
|
||||
return this.tasks.find(t => t.SerialNumber = serialnumber);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user