Skip to content
Snippets Groups Projects
Commit ec52547c authored by Hugo SUBTIL's avatar Hugo SUBTIL
Browse files

feat(auth): add email verification page

parent 68a7de9d
No related branches found
No related tags found
3 merge requests!68Recette,!67Dev,!38Feat/auth
...@@ -5,6 +5,7 @@ import { HomeComponent } from './home/home.component'; ...@@ -5,6 +5,7 @@ import { HomeComponent } from './home/home.component';
import { LegalNoticeComponent } from './legal-notice/legal-notice.component'; import { LegalNoticeComponent } from './legal-notice/legal-notice.component';
import { StructureDetailsComponent } from './structure-list/components/structure-details/structure-details.component'; import { StructureDetailsComponent } from './structure-list/components/structure-details/structure-details.component';
import { StructureListComponent } from './structure-list/structure-list.component'; import { StructureListComponent } from './structure-list/structure-list.component';
import { UserVerificationComponent } from './user-verification/user-verification.component';
const routes: Routes = [ const routes: Routes = [
{ path: 'print', outlet: 'print', children: [{ path: 'structure', component: StructureDetailsComponent }] }, { path: 'print', outlet: 'print', children: [{ path: 'structure', component: StructureDetailsComponent }] },
...@@ -36,6 +37,10 @@ const routes: Routes = [ ...@@ -36,6 +37,10 @@ const routes: Routes = [
path: 'about', path: 'about',
component: AboutComponent, component: AboutComponent,
}, },
{
path: 'users/verify/:id',
component: UserVerificationComponent,
},
{ {
path: '**', path: '**',
redirectTo: 'home', redirectTo: 'home',
......
...@@ -22,6 +22,7 @@ import { ModalFilterComponent } from './structure-list/components/modal-filter/m ...@@ -22,6 +22,7 @@ import { ModalFilterComponent } from './structure-list/components/modal-filter/m
import { LegalNoticeComponent } from './legal-notice/legal-notice.component'; import { LegalNoticeComponent } from './legal-notice/legal-notice.component';
import { AboutComponent } from './about/about.component'; import { AboutComponent } from './about/about.component';
import { MenuPhoneComponent } from './menu-phone/menu-phone.component'; import { MenuPhoneComponent } from './menu-phone/menu-phone.component';
import { UserVerificationComponent } from './user-verification/user-verification.component';
@NgModule({ @NgModule({
declarations: [ declarations: [
...@@ -38,6 +39,7 @@ import { MenuPhoneComponent } from './menu-phone/menu-phone.component'; ...@@ -38,6 +39,7 @@ import { MenuPhoneComponent } from './menu-phone/menu-phone.component';
LegalNoticeComponent, LegalNoticeComponent,
AboutComponent, AboutComponent,
MenuPhoneComponent, MenuPhoneComponent,
UserVerificationComponent,
], ],
imports: [ imports: [
BrowserModule, BrowserModule,
......
...@@ -32,4 +32,10 @@ export class AuthService { ...@@ -32,4 +32,10 @@ export class AuthService {
public register(user: User): Observable<any> { public register(user: User): Observable<any> {
return this.http.post('api/users', user); return this.http.post('api/users', user);
} }
public verifyUser(userId: string, token: string): Observable<any> {
return this.http.post(`api/users/verify/${userId}`, null, {
params: { token },
});
}
} }
<div fxLayout="column" class="content-container">
<h1 style="display: none">Vérification du mail utilisateur</h1>
<div class="section-container" fxLayout="colum" fxLayoutAlign="center center">
<p *ngIf="!verificationSuccess && !verificationIssue">Votre email est en cours de vérification ...</p>
<p *ngIf="verificationSuccess">
Vous avez correctement validé l'email associé a votre compte. Vous pouvez dès maintenant vous connecter au site.
</p>
<p *ngIf="verificationIssue">
Une erreur est survenue lors de la validation de votre email... Veuillez envoyer un mail au support.
</p>
<div></div>
</div>
</div>
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { UserVerificationComponent } from './user-verification.component';
describe('UserVerificationComponent', () => {
let component: UserVerificationComponent;
let fixture: ComponentFixture<UserVerificationComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ UserVerificationComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(UserVerificationComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { AuthService } from '../services/auth.service';
@Component({
selector: 'app-user-verification',
templateUrl: './user-verification.component.html',
styleUrls: ['./user-verification.component.scss'],
})
export class UserVerificationComponent implements OnInit {
public userId: string;
public token: string;
public verificationSuccess = false;
public verificationIssue = false;
constructor(private activatedRoute: ActivatedRoute, private authService: AuthService) {
this.activatedRoute.queryParams.subscribe((params) => {
this.token = params['token'];
});
}
ngOnInit(): void {
this.userId = this.activatedRoute.snapshot.paramMap.get('id');
this.sendVerification();
}
private sendVerification(): void {
this.authService.verifyUser(this.userId, this.token).subscribe(
() => {
this.verificationSuccess = true;
},
() => {
this.verificationIssue = true;
}
);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment