Skip to content

Commit

Permalink
Fonctionnement revu + mise en place du login avec Token Jwt
Browse files Browse the repository at this point in the history
  • Loading branch information
Wyveth committed Nov 20, 2023
1 parent 32b2204 commit 71f4880
Show file tree
Hide file tree
Showing 29 changed files with 455 additions and 144 deletions.
171 changes: 90 additions & 81 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@
"@angular/platform-browser": "^16.2.12",
"@angular/platform-browser-dynamic": "^16.2.12",
"@angular/router": "^16.2.12",
"@fortawesome/angular-fontawesome": "^0.14.0",
"@fortawesome/fontawesome-free": "^6.4.2",
"@fortawesome/free-solid-svg-icons": "^6.4.2",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-prettier": "^4.2.1",
"flowbite": "^1.5.3",
"prettier": "^2.8.7",
"primeicons": "^6.0.1",
"primeng": "^15.4.1",
"primeng": "^16.4.2",
"rxjs": "^6.6.0",
"tslib": "^2.3.0",
"zone.js": "~0.13.3"
Expand All @@ -49,4 +52,4 @@
"tailwindcss": "^2.2.19",
"typescript": "^5.1.6"
}
}
}
6 changes: 6 additions & 0 deletions src/app/api/models/concretes/authenticate-user.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface AuthenticateUser {
email: string;
password: string;
userName: string;
token: string;
}
2 changes: 2 additions & 0 deletions src/app/api/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ export class ApiRequest {
responseType: 'json',
};

console.log('Request: ', requestOptions);

return httpClient
.request<T>('POST', path, requestOptions)
.pipe(
Expand Down
19 changes: 19 additions & 0 deletions src/app/api/services/authenticate.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* tslint:disable:no-unused-variable */

import { TestBed, async, inject } from '@angular/core/testing';
import { AuthenticateService } from './authenticate.service';

describe('Service: Authorize', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [AuthenticateService],
});
});

it('should ...', inject(
[AuthenticateService],
(service: AuthenticateService) => {
expect(service).toBeTruthy();
}
));
});
60 changes: 60 additions & 0 deletions src/app/api/services/authenticate.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { Injectable } from '@angular/core';
import { AbstractService } from './abstract/abstract.service';
import { ParametersRequest } from '../models/shared/parametersRequest';
import { AppConfig } from 'src/app/app.config';
import { HttpClient } from '@angular/common/http';
import { AuthenticateUser } from '../models/concretes/authenticate-user';
import { ApiRequest } from '../request';

@Injectable({
providedIn: 'root',
})
export class AuthenticateService extends AbstractService {
parametersRequest!: ParametersRequest;
api_authenticate: string;

constructor(config: AppConfig, httpClient: HttpClient) {
super(config, httpClient);
this.api_authenticate = config.getConfig('authenticate_api');
console.log('API Authenticate: ' + this.api_authenticate);
}

login(authenticateUser: AuthenticateUser) {
this.parametersRequest = {
url: this.api_authenticate + '/login',
parameters: [],
};

const path = this.basePath + this.parametersRequest.url;
console.log(this.api_authenticate, authenticateUser);
return ApiRequest.post<AuthenticateUser>(
this.httpClient,
this.defaultHeaders,
this.configuration,
path,
authenticateUser,
undefined,
'body',
false
);
}

register(authenticateUser: AuthenticateUser) {
this.parametersRequest = {
url: this.api_authenticate + '/register',
parameters: [],
};

const path = this.basePath + this.parametersRequest.url;
return ApiRequest.post<AuthenticateUser>(
this.httpClient,
this.defaultHeaders,
this.configuration,
path,
authenticateUser,
undefined,
'body',
false
);
}
}
Loading

0 comments on commit 71f4880

Please sign in to comment.