Skip to content
Snippets Groups Projects
Commit c95e8729 authored by narindra.rajohnso's avatar narindra.rajohnso
Browse files

add token send and verify

parent 79de47f1
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,7 @@ import {Component, ElementRef, OnInit, ViewChild} from '@angular/core'; ...@@ -2,6 +2,7 @@ import {Component, ElementRef, OnInit, ViewChild} from '@angular/core';
import {FormControl, FormGroup, Validators} from "@angular/forms"; import {FormControl, FormGroup, Validators} from "@angular/forms";
import {HttpClient} from "@angular/common/http"; import {HttpClient} from "@angular/common/http";
import {ErrorLogin, LoginService} from "../login.service"; import {ErrorLogin, LoginService} from "../login.service";
import {Router} from "@angular/router";
@Component({ @Component({
selector: 'app-sign-up', selector: 'app-sign-up',
...@@ -12,7 +13,7 @@ export class SignUpComponent{ ...@@ -12,7 +13,7 @@ export class SignUpComponent{
formData!: FormGroup; formData!: FormGroup;
@ViewChild('passwordConfirmation') passwordConfirmation!: ElementRef @ViewChild('passwordConfirmation') passwordConfirmation!: ElementRef
errorOccured!: boolean; errorOccured!: boolean;
constructor(private httpClient: HttpClient, private loginService: LoginService) { } constructor(private router: Router, private httpClient: HttpClient, private loginService: LoginService) { }
ngOnInit() { ngOnInit() {
this.errorOccured=false; this.errorOccured=false;
...@@ -34,8 +35,9 @@ export class SignUpComponent{ ...@@ -34,8 +35,9 @@ export class SignUpComponent{
this.formData.value.accountType=0; this.formData.value.accountType=0;
this.httpClient.post<any>('http://localhost:30992/api/v1/guest/create-account', this.formData.value).subscribe( this.httpClient.post<any>('http://localhost:30992/api/v1/guest/create-account', this.formData.value).subscribe(
response => { response => {
console.log(response); // Affiche la réponse du serveur dans la console console.log(response);
// Effectuer une action en fonction de la réponse du serveur ici this.router.navigate(['/login/sign-in']);
}, },
error => { error => {
this.errorOccured=true; this.errorOccured=true;
......
import { TestBed } from '@angular/core/testing';
import { TokenInterceptorService } from './token-interceptor.service';
describe('TokenInterceptorService', () => {
let service: TokenInterceptorService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(TokenInterceptorService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
import { Injectable } from '@angular/core';
import {SessionService} from "./session.service";
import {HttpEvent, HttpHandler, HttpInterceptor, HttpRequest} from "@angular/common/http";
import {Observable} from "rxjs";
@Injectable({
providedIn: 'root'
})
export class TokenInterceptorService implements HttpInterceptor {
constructor(private sessionService: SessionService) { }
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
if ((req.url.indexOf("127.0.0.1") !== -1 || req.url.indexOf("localhost") !== -1) && req.url.indexOf("assets") === -1) {
req = req.clone({
setHeaders: {
Authorization: "Bearer " + this.sessionService.token
}
})
}
return next.handle(req)
}
}
...@@ -63,13 +63,14 @@ export class ListUsersComponent implements OnInit, OnDestroy { ...@@ -63,13 +63,14 @@ export class ListUsersComponent implements OnInit, OnDestroy {
this.modalUser=false; this.modalUser=false;
this.userEdited=null; this.userEdited=null;
this.alertDelete=false; this.alertDelete=false;
if(value !== "error"){ if(value !== "error" && value !== undefined){
this.alertSuccess=value; this.alertSuccess=value;
this.addSuccess=true; this.addSuccess=true;
setTimeout(() => { setTimeout(() => {
this.addSuccess = false; this.addSuccess = false;
}, 5000); }, 5000);
}else{ }
if(value === "error"){
this.errorOccured=true; this.errorOccured=true;
setTimeout(() => { setTimeout(() => {
this.errorOccured = false; this.errorOccured = false;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment