Compare commits
5 Commits
5b1030570f
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 26b680e3ee | |||
| b2aa7bdfdb | |||
| f2a9f24bd5 | |||
| 3bc368ecb3 | |||
| 0be745dc61 |
@@ -8,7 +8,8 @@ import { fr_FR, provideNzI18n } from 'ng-zorro-antd/i18n';
|
|||||||
import { registerLocaleData } from '@angular/common';
|
import { registerLocaleData } from '@angular/common';
|
||||||
import fr from '@angular/common/locales/fr';
|
import fr from '@angular/common/locales/fr';
|
||||||
import { provideAnimationsAsync } from '@angular/platform-browser/animations/async';
|
import { provideAnimationsAsync } from '@angular/platform-browser/animations/async';
|
||||||
import { provideHttpClient } from '@angular/common/http';
|
import {provideHttpClient, withInterceptors} from '@angular/common/http';
|
||||||
|
import {authInterceptor} from "./interceptors/auth-interceptor";
|
||||||
|
|
||||||
registerLocaleData(fr);
|
registerLocaleData(fr);
|
||||||
|
|
||||||
@@ -16,6 +17,7 @@ export const appConfig: ApplicationConfig = {
|
|||||||
providers: [
|
providers: [
|
||||||
provideBrowserGlobalErrorListeners(),
|
provideBrowserGlobalErrorListeners(),
|
||||||
provideZoneChangeDetection({ eventCoalescing: true }),
|
provideZoneChangeDetection({ eventCoalescing: true }),
|
||||||
provideRouter(routes), provideNzIcons(icons), provideNzI18n(fr_FR), provideAnimationsAsync(), provideHttpClient()
|
provideRouter(routes), provideNzIcons(icons), provideNzI18n(fr_FR), provideAnimationsAsync(),
|
||||||
|
provideHttpClient(withInterceptors([authInterceptor]))
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<form nz-form nzLayout="horizontal" [formGroup]="loginForm" (ngSubmit)="submitForm()">
|
<form nz-form nzLayout="horizontal" [formGroup]="loginForm">
|
||||||
<nz-form-item>
|
<nz-form-item>
|
||||||
<nz-form-label nzSpan="8" nzRequired>
|
<nz-form-label nzSpan="8" nzRequired>
|
||||||
Identifiant
|
Identifiant
|
||||||
@@ -19,5 +19,5 @@
|
|||||||
</nz-form-control>
|
</nz-form-control>
|
||||||
</nz-form-item>
|
</nz-form-item>
|
||||||
|
|
||||||
<button class="ml-26 mt-4" nz-button [nzType]="'primary'" (click)="submitForm()">Connexion</button>
|
<button class="ml-26 mt-4" nz-button [nzType]="'primary'" (click)="connectUser()">Connexion</button>
|
||||||
</form>
|
</form>
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
import { Component } from '@angular/core';
|
import {Component, inject} from '@angular/core';
|
||||||
import {FormControl, FormGroup, ReactiveFormsModule, Validators} from "@angular/forms";
|
import {FormControl, FormGroup, ReactiveFormsModule, Validators} from "@angular/forms";
|
||||||
import {NzColDirective, NzRowDirective} from "ng-zorro-antd/grid";
|
import {NzColDirective, NzRowDirective} from "ng-zorro-antd/grid";
|
||||||
import {NzFormControlComponent, NzFormDirective, NzFormItemComponent, NzFormLabelComponent} from "ng-zorro-antd/form";
|
import {NzFormControlComponent, NzFormDirective, NzFormItemComponent, NzFormLabelComponent} from "ng-zorro-antd/form";
|
||||||
import {NzInputDirective} from "ng-zorro-antd/input";
|
import {NzInputDirective} from "ng-zorro-antd/input";
|
||||||
import {NzButtonComponent} from "ng-zorro-antd/button";
|
import {NzButtonComponent} from "ng-zorro-antd/button";
|
||||||
|
import {AuthService} from "../../services/auth.service";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-login',
|
selector: 'app-login',
|
||||||
@@ -22,18 +23,14 @@ import {NzButtonComponent} from "ng-zorro-antd/button";
|
|||||||
styleUrl: './login.css',
|
styleUrl: './login.css',
|
||||||
})
|
})
|
||||||
export class Login {
|
export class Login {
|
||||||
|
private authService = inject(AuthService);
|
||||||
|
|
||||||
loginForm = new FormGroup({
|
loginForm = new FormGroup({
|
||||||
name: new FormControl<string>(null, [Validators.required]),
|
name: new FormControl<string>(null, [Validators.required]),
|
||||||
password: new FormControl<string>(null, [Validators.required]),
|
password: new FormControl<string>(null, [Validators.required]),
|
||||||
})
|
})
|
||||||
|
|
||||||
submitForm() {
|
async connectUser() {
|
||||||
// Pour annuler si le formulaire est invalide
|
await this.authService.connectUser(this.loginForm.value.name, this.loginForm.value.password);
|
||||||
if (this.loginForm.invalid) return;
|
}
|
||||||
|
}
|
||||||
// Pour obtenir la valeur du formulaire
|
|
||||||
console.log(this.loginForm.getRawValue())
|
|
||||||
|
|
||||||
// Pour vider le formulaire
|
|
||||||
this.loginForm.reset()
|
|
||||||
}}
|
|
||||||
|
|||||||
48
src/app/interceptors/auth-interceptor.ts
Normal file
48
src/app/interceptors/auth-interceptor.ts
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
import { HttpInterceptorFn, HttpErrorResponse, HttpRequest, HttpHandlerFn } from '@angular/common/http';
|
||||||
|
import { inject } from '@angular/core';
|
||||||
|
import { AuthService } from '../services/auth.service';
|
||||||
|
import { RefreshService } from '../services/api';
|
||||||
|
import { NzNotificationService } from 'ng-zorro-antd/notification';
|
||||||
|
import { catchError, switchMap, throwError } from 'rxjs';
|
||||||
|
|
||||||
|
export const authInterceptor: HttpInterceptorFn = (req: HttpRequest<any>, next: HttpHandlerFn) => {
|
||||||
|
const authService = inject(AuthService);
|
||||||
|
const refreshService = inject(RefreshService);
|
||||||
|
const notification = inject(NzNotificationService);
|
||||||
|
const token = authService.getToken();
|
||||||
|
|
||||||
|
let authReq = req;
|
||||||
|
if (token) {
|
||||||
|
authReq = req.clone({
|
||||||
|
setHeaders: { Authorization: `Bearer ${token}` }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return next(authReq).pipe(
|
||||||
|
catchError((error: HttpErrorResponse) => {
|
||||||
|
if (error.status === 401 && token) {
|
||||||
|
return refreshService.refreshTokenEndpoint({ token })
|
||||||
|
.pipe(
|
||||||
|
switchMap((res: any) => {
|
||||||
|
authService.setToken(res.token);
|
||||||
|
const newReq = req.clone({
|
||||||
|
setHeaders: { Authorization: `Bearer ${res.token}` }
|
||||||
|
});
|
||||||
|
return next(newReq);
|
||||||
|
}),
|
||||||
|
catchError((refreshErr) => {
|
||||||
|
authService.logout();
|
||||||
|
notification.error('Session expirée', 'Veuillez vous reconnecter.');
|
||||||
|
return throwError(() => refreshErr);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error.status === 403) {
|
||||||
|
notification.error('Accès refusé', 'Vous n’avez pas les droits pour cette action.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return throwError(() => error);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -8,6 +8,7 @@ api/books.service.ts
|
|||||||
api/loans.service.ts
|
api/loans.service.ts
|
||||||
api/login.service.ts
|
api/login.service.ts
|
||||||
api/logins.service.ts
|
api/logins.service.ts
|
||||||
|
api/refresh.service.ts
|
||||||
api/users.service.ts
|
api/users.service.ts
|
||||||
configuration.ts
|
configuration.ts
|
||||||
encoder.ts
|
encoder.ts
|
||||||
@@ -24,9 +25,11 @@ model/get-book-dto.ts
|
|||||||
model/get-loan-dto.ts
|
model/get-loan-dto.ts
|
||||||
model/get-login-connect-dto.ts
|
model/get-login-connect-dto.ts
|
||||||
model/get-login-dto.ts
|
model/get-login-dto.ts
|
||||||
|
model/get-refresh-dto.ts
|
||||||
model/get-user-dto.ts
|
model/get-user-dto.ts
|
||||||
model/models.ts
|
model/models.ts
|
||||||
model/patch-loan-dto.ts
|
model/patch-loan-dto.ts
|
||||||
|
model/refresh-token-dto.ts
|
||||||
model/update-author-dto.ts
|
model/update-author-dto.ts
|
||||||
model/update-book-dto.ts
|
model/update-book-dto.ts
|
||||||
model/update-loan-dto.ts
|
model/update-loan-dto.ts
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ export * from './login.service';
|
|||||||
import { LoginService } from './login.service';
|
import { LoginService } from './login.service';
|
||||||
export * from './logins.service';
|
export * from './logins.service';
|
||||||
import { LoginsService } from './logins.service';
|
import { LoginsService } from './logins.service';
|
||||||
|
export * from './refresh.service';
|
||||||
|
import { RefreshService } from './refresh.service';
|
||||||
export * from './users.service';
|
export * from './users.service';
|
||||||
import { UsersService } from './users.service';
|
import { UsersService } from './users.service';
|
||||||
export const APIS = [AuthorsService, BooksService, LoansService, LoginService, LoginsService, UsersService];
|
export const APIS = [AuthorsService, BooksService, LoansService, LoginService, LoginsService, RefreshService, UsersService];
|
||||||
|
|||||||
@@ -55,6 +55,9 @@ export class AuthorsService extends BaseService {
|
|||||||
|
|
||||||
let localVarHeaders = this.defaultHeaders;
|
let localVarHeaders = this.defaultHeaders;
|
||||||
|
|
||||||
|
// authentication (JWTBearerAuth) required
|
||||||
|
localVarHeaders = this.configuration.addCredentialToHeaders('JWTBearerAuth', 'Authorization', localVarHeaders, 'Bearer ');
|
||||||
|
|
||||||
const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([
|
const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([
|
||||||
'application/json'
|
'application/json'
|
||||||
]);
|
]);
|
||||||
@@ -119,6 +122,9 @@ export class AuthorsService extends BaseService {
|
|||||||
|
|
||||||
let localVarHeaders = this.defaultHeaders;
|
let localVarHeaders = this.defaultHeaders;
|
||||||
|
|
||||||
|
// authentication (JWTBearerAuth) required
|
||||||
|
localVarHeaders = this.configuration.addCredentialToHeaders('JWTBearerAuth', 'Authorization', localVarHeaders, 'Bearer ');
|
||||||
|
|
||||||
const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([
|
const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([
|
||||||
]);
|
]);
|
||||||
if (localVarHttpHeaderAcceptSelected !== undefined) {
|
if (localVarHttpHeaderAcceptSelected !== undefined) {
|
||||||
@@ -168,6 +174,9 @@ export class AuthorsService extends BaseService {
|
|||||||
|
|
||||||
let localVarHeaders = this.defaultHeaders;
|
let localVarHeaders = this.defaultHeaders;
|
||||||
|
|
||||||
|
// authentication (JWTBearerAuth) required
|
||||||
|
localVarHeaders = this.configuration.addCredentialToHeaders('JWTBearerAuth', 'Authorization', localVarHeaders, 'Bearer ');
|
||||||
|
|
||||||
const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([
|
const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([
|
||||||
'application/json'
|
'application/json'
|
||||||
]);
|
]);
|
||||||
@@ -222,6 +231,9 @@ export class AuthorsService extends BaseService {
|
|||||||
|
|
||||||
let localVarHeaders = this.defaultHeaders;
|
let localVarHeaders = this.defaultHeaders;
|
||||||
|
|
||||||
|
// authentication (JWTBearerAuth) required
|
||||||
|
localVarHeaders = this.configuration.addCredentialToHeaders('JWTBearerAuth', 'Authorization', localVarHeaders, 'Bearer ');
|
||||||
|
|
||||||
const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([
|
const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([
|
||||||
'application/json'
|
'application/json'
|
||||||
]);
|
]);
|
||||||
@@ -280,6 +292,9 @@ export class AuthorsService extends BaseService {
|
|||||||
|
|
||||||
let localVarHeaders = this.defaultHeaders;
|
let localVarHeaders = this.defaultHeaders;
|
||||||
|
|
||||||
|
// authentication (JWTBearerAuth) required
|
||||||
|
localVarHeaders = this.configuration.addCredentialToHeaders('JWTBearerAuth', 'Authorization', localVarHeaders, 'Bearer ');
|
||||||
|
|
||||||
const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([
|
const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([
|
||||||
'application/json'
|
'application/json'
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -55,6 +55,9 @@ export class BooksService extends BaseService {
|
|||||||
|
|
||||||
let localVarHeaders = this.defaultHeaders;
|
let localVarHeaders = this.defaultHeaders;
|
||||||
|
|
||||||
|
// authentication (JWTBearerAuth) required
|
||||||
|
localVarHeaders = this.configuration.addCredentialToHeaders('JWTBearerAuth', 'Authorization', localVarHeaders, 'Bearer ');
|
||||||
|
|
||||||
const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([
|
const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([
|
||||||
'application/json'
|
'application/json'
|
||||||
]);
|
]);
|
||||||
@@ -119,6 +122,9 @@ export class BooksService extends BaseService {
|
|||||||
|
|
||||||
let localVarHeaders = this.defaultHeaders;
|
let localVarHeaders = this.defaultHeaders;
|
||||||
|
|
||||||
|
// authentication (JWTBearerAuth) required
|
||||||
|
localVarHeaders = this.configuration.addCredentialToHeaders('JWTBearerAuth', 'Authorization', localVarHeaders, 'Bearer ');
|
||||||
|
|
||||||
const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([
|
const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([
|
||||||
]);
|
]);
|
||||||
if (localVarHttpHeaderAcceptSelected !== undefined) {
|
if (localVarHttpHeaderAcceptSelected !== undefined) {
|
||||||
@@ -168,6 +174,9 @@ export class BooksService extends BaseService {
|
|||||||
|
|
||||||
let localVarHeaders = this.defaultHeaders;
|
let localVarHeaders = this.defaultHeaders;
|
||||||
|
|
||||||
|
// authentication (JWTBearerAuth) required
|
||||||
|
localVarHeaders = this.configuration.addCredentialToHeaders('JWTBearerAuth', 'Authorization', localVarHeaders, 'Bearer ');
|
||||||
|
|
||||||
const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([
|
const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([
|
||||||
'application/json'
|
'application/json'
|
||||||
]);
|
]);
|
||||||
@@ -222,6 +231,9 @@ export class BooksService extends BaseService {
|
|||||||
|
|
||||||
let localVarHeaders = this.defaultHeaders;
|
let localVarHeaders = this.defaultHeaders;
|
||||||
|
|
||||||
|
// authentication (JWTBearerAuth) required
|
||||||
|
localVarHeaders = this.configuration.addCredentialToHeaders('JWTBearerAuth', 'Authorization', localVarHeaders, 'Bearer ');
|
||||||
|
|
||||||
const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([
|
const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([
|
||||||
'application/json'
|
'application/json'
|
||||||
]);
|
]);
|
||||||
@@ -280,6 +292,9 @@ export class BooksService extends BaseService {
|
|||||||
|
|
||||||
let localVarHeaders = this.defaultHeaders;
|
let localVarHeaders = this.defaultHeaders;
|
||||||
|
|
||||||
|
// authentication (JWTBearerAuth) required
|
||||||
|
localVarHeaders = this.configuration.addCredentialToHeaders('JWTBearerAuth', 'Authorization', localVarHeaders, 'Bearer ');
|
||||||
|
|
||||||
const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([
|
const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([
|
||||||
'application/json'
|
'application/json'
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -57,6 +57,9 @@ export class LoansService extends BaseService {
|
|||||||
|
|
||||||
let localVarHeaders = this.defaultHeaders;
|
let localVarHeaders = this.defaultHeaders;
|
||||||
|
|
||||||
|
// authentication (JWTBearerAuth) required
|
||||||
|
localVarHeaders = this.configuration.addCredentialToHeaders('JWTBearerAuth', 'Authorization', localVarHeaders, 'Bearer ');
|
||||||
|
|
||||||
const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([
|
const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([
|
||||||
'application/json'
|
'application/json'
|
||||||
]);
|
]);
|
||||||
@@ -121,6 +124,9 @@ export class LoansService extends BaseService {
|
|||||||
|
|
||||||
let localVarHeaders = this.defaultHeaders;
|
let localVarHeaders = this.defaultHeaders;
|
||||||
|
|
||||||
|
// authentication (JWTBearerAuth) required
|
||||||
|
localVarHeaders = this.configuration.addCredentialToHeaders('JWTBearerAuth', 'Authorization', localVarHeaders, 'Bearer ');
|
||||||
|
|
||||||
const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([
|
const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([
|
||||||
]);
|
]);
|
||||||
if (localVarHttpHeaderAcceptSelected !== undefined) {
|
if (localVarHttpHeaderAcceptSelected !== undefined) {
|
||||||
@@ -170,6 +176,9 @@ export class LoansService extends BaseService {
|
|||||||
|
|
||||||
let localVarHeaders = this.defaultHeaders;
|
let localVarHeaders = this.defaultHeaders;
|
||||||
|
|
||||||
|
// authentication (JWTBearerAuth) required
|
||||||
|
localVarHeaders = this.configuration.addCredentialToHeaders('JWTBearerAuth', 'Authorization', localVarHeaders, 'Bearer ');
|
||||||
|
|
||||||
const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([
|
const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([
|
||||||
'application/json'
|
'application/json'
|
||||||
]);
|
]);
|
||||||
@@ -224,6 +233,9 @@ export class LoansService extends BaseService {
|
|||||||
|
|
||||||
let localVarHeaders = this.defaultHeaders;
|
let localVarHeaders = this.defaultHeaders;
|
||||||
|
|
||||||
|
// authentication (JWTBearerAuth) required
|
||||||
|
localVarHeaders = this.configuration.addCredentialToHeaders('JWTBearerAuth', 'Authorization', localVarHeaders, 'Bearer ');
|
||||||
|
|
||||||
const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([
|
const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([
|
||||||
'application/json'
|
'application/json'
|
||||||
]);
|
]);
|
||||||
@@ -282,6 +294,9 @@ export class LoansService extends BaseService {
|
|||||||
|
|
||||||
let localVarHeaders = this.defaultHeaders;
|
let localVarHeaders = this.defaultHeaders;
|
||||||
|
|
||||||
|
// authentication (JWTBearerAuth) required
|
||||||
|
localVarHeaders = this.configuration.addCredentialToHeaders('JWTBearerAuth', 'Authorization', localVarHeaders, 'Bearer ');
|
||||||
|
|
||||||
const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([
|
const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([
|
||||||
'application/json'
|
'application/json'
|
||||||
]);
|
]);
|
||||||
@@ -350,6 +365,9 @@ export class LoansService extends BaseService {
|
|||||||
|
|
||||||
let localVarHeaders = this.defaultHeaders;
|
let localVarHeaders = this.defaultHeaders;
|
||||||
|
|
||||||
|
// authentication (JWTBearerAuth) required
|
||||||
|
localVarHeaders = this.configuration.addCredentialToHeaders('JWTBearerAuth', 'Authorization', localVarHeaders, 'Bearer ');
|
||||||
|
|
||||||
const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([
|
const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([
|
||||||
'application/json'
|
'application/json'
|
||||||
]);
|
]);
|
||||||
|
|||||||
104
src/app/services/api/api/refresh.service.ts
Normal file
104
src/app/services/api/api/refresh.service.ts
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
/**
|
||||||
|
* ApiEfCoreLibrary
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
|
* https://openapi-generator.tech
|
||||||
|
* Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
/* tslint:disable:no-unused-variable member-ordering */
|
||||||
|
|
||||||
|
import { Inject, Injectable, Optional } from '@angular/core';
|
||||||
|
import { HttpClient, HttpHeaders, HttpParams,
|
||||||
|
HttpResponse, HttpEvent, HttpParameterCodec, HttpContext
|
||||||
|
} from '@angular/common/http';
|
||||||
|
import { CustomHttpParameterCodec } from '../encoder';
|
||||||
|
import { Observable } from 'rxjs';
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
import { GetRefreshDto } from '../model/get-refresh-dto';
|
||||||
|
// @ts-ignore
|
||||||
|
import { RefreshTokenDto } from '../model/refresh-token-dto';
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
import { BASE_PATH, COLLECTION_FORMATS } from '../variables';
|
||||||
|
import { Configuration } from '../configuration';
|
||||||
|
import { BaseService } from '../api.base.service';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
|
export class RefreshService extends BaseService {
|
||||||
|
|
||||||
|
constructor(protected httpClient: HttpClient, @Optional() @Inject(BASE_PATH) basePath: string|string[], @Optional() configuration?: Configuration) {
|
||||||
|
super(basePath, configuration);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @endpoint post /API/refresh
|
||||||
|
* @param refreshTokenDto
|
||||||
|
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
|
||||||
|
* @param reportProgress flag to report request and response progress.
|
||||||
|
*/
|
||||||
|
public refreshTokenEndpoint(refreshTokenDto: RefreshTokenDto, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable<GetRefreshDto>;
|
||||||
|
public refreshTokenEndpoint(refreshTokenDto: RefreshTokenDto, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable<HttpResponse<GetRefreshDto>>;
|
||||||
|
public refreshTokenEndpoint(refreshTokenDto: RefreshTokenDto, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable<HttpEvent<GetRefreshDto>>;
|
||||||
|
public refreshTokenEndpoint(refreshTokenDto: RefreshTokenDto, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable<any> {
|
||||||
|
if (refreshTokenDto === null || refreshTokenDto === undefined) {
|
||||||
|
throw new Error('Required parameter refreshTokenDto was null or undefined when calling refreshTokenEndpoint.');
|
||||||
|
}
|
||||||
|
|
||||||
|
let localVarHeaders = this.defaultHeaders;
|
||||||
|
|
||||||
|
const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([
|
||||||
|
'application/json'
|
||||||
|
]);
|
||||||
|
if (localVarHttpHeaderAcceptSelected !== undefined) {
|
||||||
|
localVarHeaders = localVarHeaders.set('Accept', localVarHttpHeaderAcceptSelected);
|
||||||
|
}
|
||||||
|
|
||||||
|
const localVarHttpContext: HttpContext = options?.context ?? new HttpContext();
|
||||||
|
|
||||||
|
const localVarTransferCache: boolean = options?.transferCache ?? true;
|
||||||
|
|
||||||
|
|
||||||
|
// to determine the Content-Type header
|
||||||
|
const consumes: string[] = [
|
||||||
|
'application/json'
|
||||||
|
];
|
||||||
|
const httpContentTypeSelected: string | undefined = this.configuration.selectHeaderContentType(consumes);
|
||||||
|
if (httpContentTypeSelected !== undefined) {
|
||||||
|
localVarHeaders = localVarHeaders.set('Content-Type', httpContentTypeSelected);
|
||||||
|
}
|
||||||
|
|
||||||
|
let responseType_: 'text' | 'json' | 'blob' = 'json';
|
||||||
|
if (localVarHttpHeaderAcceptSelected) {
|
||||||
|
if (localVarHttpHeaderAcceptSelected.startsWith('text')) {
|
||||||
|
responseType_ = 'text';
|
||||||
|
} else if (this.configuration.isJsonMime(localVarHttpHeaderAcceptSelected)) {
|
||||||
|
responseType_ = 'json';
|
||||||
|
} else {
|
||||||
|
responseType_ = 'blob';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let localVarPath = `/API/refresh`;
|
||||||
|
const { basePath, withCredentials } = this.configuration;
|
||||||
|
return this.httpClient.request<GetRefreshDto>('post', `${basePath}${localVarPath}`,
|
||||||
|
{
|
||||||
|
context: localVarHttpContext,
|
||||||
|
body: refreshTokenDto,
|
||||||
|
responseType: <any>responseType_,
|
||||||
|
...(withCredentials ? { withCredentials } : {}),
|
||||||
|
headers: localVarHeaders,
|
||||||
|
observe: observe,
|
||||||
|
...(localVarTransferCache !== undefined ? { transferCache: localVarTransferCache } : {}),
|
||||||
|
reportProgress: reportProgress
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -55,6 +55,9 @@ export class UsersService extends BaseService {
|
|||||||
|
|
||||||
let localVarHeaders = this.defaultHeaders;
|
let localVarHeaders = this.defaultHeaders;
|
||||||
|
|
||||||
|
// authentication (JWTBearerAuth) required
|
||||||
|
localVarHeaders = this.configuration.addCredentialToHeaders('JWTBearerAuth', 'Authorization', localVarHeaders, 'Bearer ');
|
||||||
|
|
||||||
const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([
|
const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([
|
||||||
'application/json'
|
'application/json'
|
||||||
]);
|
]);
|
||||||
@@ -119,6 +122,9 @@ export class UsersService extends BaseService {
|
|||||||
|
|
||||||
let localVarHeaders = this.defaultHeaders;
|
let localVarHeaders = this.defaultHeaders;
|
||||||
|
|
||||||
|
// authentication (JWTBearerAuth) required
|
||||||
|
localVarHeaders = this.configuration.addCredentialToHeaders('JWTBearerAuth', 'Authorization', localVarHeaders, 'Bearer ');
|
||||||
|
|
||||||
const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([
|
const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([
|
||||||
]);
|
]);
|
||||||
if (localVarHttpHeaderAcceptSelected !== undefined) {
|
if (localVarHttpHeaderAcceptSelected !== undefined) {
|
||||||
@@ -168,6 +174,9 @@ export class UsersService extends BaseService {
|
|||||||
|
|
||||||
let localVarHeaders = this.defaultHeaders;
|
let localVarHeaders = this.defaultHeaders;
|
||||||
|
|
||||||
|
// authentication (JWTBearerAuth) required
|
||||||
|
localVarHeaders = this.configuration.addCredentialToHeaders('JWTBearerAuth', 'Authorization', localVarHeaders, 'Bearer ');
|
||||||
|
|
||||||
const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([
|
const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([
|
||||||
'application/json'
|
'application/json'
|
||||||
]);
|
]);
|
||||||
@@ -222,6 +231,9 @@ export class UsersService extends BaseService {
|
|||||||
|
|
||||||
let localVarHeaders = this.defaultHeaders;
|
let localVarHeaders = this.defaultHeaders;
|
||||||
|
|
||||||
|
// authentication (JWTBearerAuth) required
|
||||||
|
localVarHeaders = this.configuration.addCredentialToHeaders('JWTBearerAuth', 'Authorization', localVarHeaders, 'Bearer ');
|
||||||
|
|
||||||
const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([
|
const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([
|
||||||
'application/json'
|
'application/json'
|
||||||
]);
|
]);
|
||||||
@@ -280,6 +292,9 @@ export class UsersService extends BaseService {
|
|||||||
|
|
||||||
let localVarHeaders = this.defaultHeaders;
|
let localVarHeaders = this.defaultHeaders;
|
||||||
|
|
||||||
|
// authentication (JWTBearerAuth) required
|
||||||
|
localVarHeaders = this.configuration.addCredentialToHeaders('JWTBearerAuth', 'Authorization', localVarHeaders, 'Bearer ');
|
||||||
|
|
||||||
const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([
|
const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([
|
||||||
'application/json'
|
'application/json'
|
||||||
]);
|
]);
|
||||||
|
|||||||
15
src/app/services/api/model/get-refresh-dto.ts
Normal file
15
src/app/services/api/model/get-refresh-dto.ts
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
/**
|
||||||
|
* ApiEfCoreLibrary
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
|
* https://openapi-generator.tech
|
||||||
|
* Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
export interface GetRefreshDto {
|
||||||
|
token?: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -9,8 +9,10 @@ export * from './get-book-dto';
|
|||||||
export * from './get-loan-dto';
|
export * from './get-loan-dto';
|
||||||
export * from './get-login-connect-dto';
|
export * from './get-login-connect-dto';
|
||||||
export * from './get-login-dto';
|
export * from './get-login-dto';
|
||||||
|
export * from './get-refresh-dto';
|
||||||
export * from './get-user-dto';
|
export * from './get-user-dto';
|
||||||
export * from './patch-loan-dto';
|
export * from './patch-loan-dto';
|
||||||
|
export * from './refresh-token-dto';
|
||||||
export * from './update-author-dto';
|
export * from './update-author-dto';
|
||||||
export * from './update-book-dto';
|
export * from './update-book-dto';
|
||||||
export * from './update-loan-dto';
|
export * from './update-loan-dto';
|
||||||
|
|||||||
15
src/app/services/api/model/refresh-token-dto.ts
Normal file
15
src/app/services/api/model/refresh-token-dto.ts
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
/**
|
||||||
|
* ApiEfCoreLibrary
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
|
* https://openapi-generator.tech
|
||||||
|
* Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
export interface RefreshTokenDto {
|
||||||
|
token?: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
38
src/app/services/auth.service.ts
Normal file
38
src/app/services/auth.service.ts
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import { inject, Injectable } from '@angular/core';
|
||||||
|
import { LoginService } from './api';
|
||||||
|
import { firstValueFrom } from 'rxjs';
|
||||||
|
import { NzNotificationService } from 'ng-zorro-antd/notification';
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root',
|
||||||
|
})
|
||||||
|
export class AuthService {
|
||||||
|
private loginService = inject(LoginService);
|
||||||
|
private notificationService = inject(NzNotificationService);
|
||||||
|
|
||||||
|
async connectUser(username: string, password: string){
|
||||||
|
try {
|
||||||
|
const loginDto = { username, password };
|
||||||
|
const res = await firstValueFrom(this.loginService.userLoginEndpoint(loginDto));
|
||||||
|
localStorage.setItem('jwt', res.token);
|
||||||
|
} catch (e) {
|
||||||
|
this.notificationService.error(
|
||||||
|
'Erreur',
|
||||||
|
'Identifiant invalide'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getToken(): string | null {
|
||||||
|
return localStorage.getItem('jwt');
|
||||||
|
}
|
||||||
|
|
||||||
|
setToken(token: string) {
|
||||||
|
localStorage.setItem('jwt', token);
|
||||||
|
}
|
||||||
|
|
||||||
|
logout() {
|
||||||
|
localStorage.removeItem('jwt');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user