connexion au back avec la partie 'beforeConnexion'
This commit is contained in:
parent
be318e8c06
commit
be3956818b
12 changed files with 93 additions and 44 deletions
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
|
||||
<!-- Mon profil -->
|
||||
<img [src]=urlImage
|
||||
<img [src]=profilService.profileImageUrl
|
||||
onerror="this.onerror=null; this.src='assets/profil.png'"
|
||||
[routerLink]="routes[3]"
|
||||
alt="">
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
import {Component} from '@angular/core';
|
||||
import {Router} from "@angular/router";
|
||||
import {ProfilService} from "../../../utils/services/profil/profil.service";
|
||||
import {MessageService} from "../../../utils/services/message/message.service";
|
||||
|
||||
|
||||
|
||||
|
|
@ -19,9 +21,20 @@ export class NavbarAdminComponent
|
|||
|
||||
url = this.router.url;
|
||||
|
||||
urlImage: string = "https://www.reference-gaming.com/assets/media/product/41195/figurine-pop-duck-tales-n-309-loulou.jpg?format=product-cover-large&k=1519639530" ;
|
||||
constructor( private router: Router,
|
||||
public profilService: ProfilService,
|
||||
private messageService: MessageService ) { }
|
||||
|
||||
constructor(private router: Router) { }
|
||||
onDeconnexion(): void
|
||||
{
|
||||
this.messageService
|
||||
.delete('user/logout', {})
|
||||
.subscribe(retour => this.onDeconnexionCallback(retour), err => this.onDeconnexionCallback(err));
|
||||
}
|
||||
|
||||
onDeconnexionCallback(retour: any): void
|
||||
{
|
||||
console.log(retour);
|
||||
}
|
||||
|
||||
onDeconnexion(): void {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@
|
|||
|
||||
|
||||
<!-- Mon profil -->
|
||||
<img [src]=urlImage
|
||||
<img [src]=profilService.profileImageUrl
|
||||
onerror="this.onerror=null; this.src='assets/profil.png'"
|
||||
[routerLink]="routes[4]"
|
||||
alt="">
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
import { Component } from '@angular/core';
|
||||
import {Router} from "@angular/router";
|
||||
import {ProfilService} from "../../../utils/services/profil/profil.service";
|
||||
import {MessageService} from "../../../utils/services/message/message.service";
|
||||
|
||||
|
||||
|
||||
|
|
@ -20,9 +22,20 @@ export class NavbarAdvertiserComponent
|
|||
|
||||
url = this.router.url;
|
||||
|
||||
urlImage: string = "https://www.figurines-goodies.com/1188-large_default/dewey-duck-tales-disney-funko-pop.jpg" ;
|
||||
constructor( private router: Router,
|
||||
public profilService: ProfilService,
|
||||
private messageService: MessageService ) { }
|
||||
|
||||
constructor(private router: Router) { }
|
||||
onDeconnexion(): void
|
||||
{
|
||||
this.messageService
|
||||
.delete('user/logout', {})
|
||||
.subscribe(retour => this.onDeconnexionCallback(retour), err => this.onDeconnexionCallback(err));
|
||||
}
|
||||
|
||||
onDeconnexionCallback(retour: any): void
|
||||
{
|
||||
console.log(retour);
|
||||
}
|
||||
|
||||
onDeconnexion(): void {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import {ThemeService} from "../../../utils/services/theme/theme.service";
|
|||
import {MatDialog} from "@angular/material/dialog";
|
||||
import {PopupForgottenPasswordComponent} from "../popup-forgotten-password/popup-forgotten-password.component";
|
||||
import {MatSnackBar} from "@angular/material/snack-bar";
|
||||
import {ProfilService} from "../../../utils/services/profil/profil.service";
|
||||
|
||||
|
||||
|
||||
|
|
@ -25,7 +26,8 @@ export class PageLoginComponent implements OnInit
|
|||
private router: Router,
|
||||
public themeService: ThemeService,
|
||||
public dialog: MatDialog,
|
||||
private snackBar: MatSnackBar ) { }
|
||||
private snackBar: MatSnackBar,
|
||||
private profilService: ProfilService) { }
|
||||
|
||||
|
||||
ngOnInit(): void {}
|
||||
|
|
@ -50,12 +52,16 @@ export class PageLoginComponent implements OnInit
|
|||
|
||||
onSeConnecterCallback(retour): void
|
||||
{
|
||||
console.log(retour);
|
||||
if(retour.status !== "success") {
|
||||
this.errorMessage = retour.error.data.reason;
|
||||
this.hasError = true;
|
||||
}
|
||||
else {
|
||||
this.router.navigateByUrl( '/user/search');
|
||||
this.profilService.profileImageUrl = retour.data.profileImageUrl;
|
||||
if(retour.data.role.name === "user") this.router.navigateByUrl( '/user/search');
|
||||
else if(retour.data.role.name === "advertiser") this.router.navigateByUrl( '/advertiser/adList');
|
||||
else if(retour.data.role.name === "admin") this.router.navigateByUrl( '/admin/userList');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<h4>Oubli mot de passe</h4>
|
||||
<h4>Récupération du mot de passe</h4>
|
||||
|
||||
<mat-divider></mat-divider><br>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { Component, OnInit } from '@angular/core';
|
||||
import { Component } from '@angular/core';
|
||||
import {MessageService} from "../../../utils/services/message/message.service";
|
||||
import {Router} from "@angular/router";
|
||||
import {MatDialog} from "@angular/material/dialog";
|
||||
|
|
@ -55,27 +55,18 @@ export class PageRegisterComponent
|
|||
{
|
||||
if(this.user.role.name === "user") this.user.role.permission = 0;
|
||||
else this.user.role.permission = 5;
|
||||
this.user.hashPass = this.hashage(this.password);
|
||||
|
||||
// FAUX CODE
|
||||
const retour = { status: "succes" };
|
||||
this.myCallback(retour);
|
||||
|
||||
// VRAI CODE
|
||||
/*
|
||||
this.user.hashPass = this.password;
|
||||
this.messageService
|
||||
.sendMessage('register', this.user)
|
||||
.subscribe(retour => this.myCallback(retour));
|
||||
*/
|
||||
.post('user/create', this.user)
|
||||
.subscribe(retour => this.onEnregistrerCallback(retour), err => this.onEnregistrerCallback(err));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Gestion de la réponde du backend
|
||||
myCallback(retour): void
|
||||
{
|
||||
if(retour.status === "error")
|
||||
onEnregistrerCallback(retour): void
|
||||
{
|
||||
if(retour.status !== "success") {
|
||||
console.log(retour);
|
||||
}
|
||||
else
|
||||
|
|
@ -140,17 +131,4 @@ export class PageRegisterComponent
|
|||
this.user.interests = myInterets;
|
||||
}
|
||||
|
||||
|
||||
// Fonction de hashage (faible)
|
||||
hashage(input: string): string
|
||||
{
|
||||
let hash = 0;
|
||||
for (let i = 0; i < input.length; i++) {
|
||||
let ch = input.charCodeAt(i);
|
||||
hash = ((hash << 5) - hash) + ch;
|
||||
hash = hash & hash;
|
||||
}
|
||||
return hash.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
import {Component, Inject} from '@angular/core';
|
||||
import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog";
|
||||
|
||||
|
||||
|
||||
@Component({
|
||||
selector: 'app-popup-confirmation',
|
||||
templateUrl: './popup-confirmation.component.html',
|
||||
|
|
@ -10,5 +12,4 @@ export class PopupConfirmationComponent
|
|||
{
|
||||
constructor( public dialogRef: MatDialogRef<PopupConfirmationComponent>,
|
||||
@Inject(MAT_DIALOG_DATA) public data) {}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@
|
|||
|
||||
|
||||
<!-- Mon profil -->
|
||||
<img [src]=urlImage
|
||||
<img [src]=profilService.profileImageUrl
|
||||
onerror="this.onerror=null; this.src='assets/profil.png'"
|
||||
[routerLink]="routes[4]"
|
||||
alt="">
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
import {Component} from '@angular/core';
|
||||
import {Router} from "@angular/router";
|
||||
import {ProfilService} from "../../../../utils/services/profil/profil.service";
|
||||
import {MessageService} from "../../../../utils/services/message/message.service";
|
||||
|
||||
|
||||
|
||||
|
|
@ -20,9 +22,20 @@ export class NavbarUserComponent
|
|||
|
||||
url = this.router.url;
|
||||
|
||||
urlImage: string = "https://www.figurines-goodies.com/1185-thickbox_default/huey-duck-tales-disney-funko-pop.jpg" ;
|
||||
constructor( private router: Router,
|
||||
public profilService: ProfilService,
|
||||
private messageService: MessageService ) { }
|
||||
|
||||
constructor(private router: Router) { }
|
||||
onDeconnexion(): void
|
||||
{
|
||||
this.messageService
|
||||
.delete('user/logout', {})
|
||||
.subscribe(retour => this.onDeconnexionCallback(retour), err => this.onDeconnexionCallback(err));
|
||||
}
|
||||
|
||||
onDeconnexionCallback(retour: any): void
|
||||
{
|
||||
console.log(retour);
|
||||
}
|
||||
|
||||
onDeconnexion(): void {}
|
||||
}
|
||||
|
|
|
|||
16
src/app/utils/services/profil/profil.service.spec.ts
Normal file
16
src/app/utils/services/profil/profil.service.spec.ts
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { ProfilService } from './profil.service';
|
||||
|
||||
describe('ProfilService', () => {
|
||||
let service: ProfilService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(ProfilService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
9
src/app/utils/services/profil/profil.service.ts
Normal file
9
src/app/utils/services/profil/profil.service.ts
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ProfilService
|
||||
{
|
||||
public profileImageUrl: string = "";
|
||||
}
|
||||
Reference in a new issue