Import des sources angular à partir de 'headup_app'

This commit is contained in:
Rampeur
2025-08-11 23:26:29 +02:00
parent 7dcb426ef5
commit 0a6cbc0c00
335 changed files with 64362 additions and 0 deletions
+113
View File
@@ -0,0 +1,113 @@
<div class="container auth-page">
<div class="row">
<div class="col-md-6 offset-md-3 col-xs-12">
<h1 class="text-xs-center">{{ title }}</h1>
<p class="text-xs-center">
@if (authType === 'register') {
<a [routerLink]="['/login']">Vous avez déjà un compte ?</a>
}
@if (authType === 'login') {
<a [routerLink]="['/register']">Vous n'avez pas encore de compte ?</a>
}
</p>
<app-list-errors [errors]="errors"></app-list-errors>
<form [formGroup]="authForm" (ngSubmit)="submitForm()">
<fieldset [disabled]="isSubmitting" class="w-100">
<legend [hidden]="true">Informations personnelles</legend>
<div class="col-12">
<mat-form-field appearance="fill" class="w-100">
<input matInput type="text" placeholder="Votre adresse email" formControlName="email" required>
@if (this.authForm.controls['email'].status === 'INVALID') {
<mat-error>{{getErrorMessage('email')}}</mat-error>
}
</mat-form-field>
</div>
@if (authType === 'register') {
<div class="col-12">
<mat-form-field appearance="fill" class="w-100">
<input matInput type="text" placeholder="Votre nom" formControlName="lastname" required>
@if (this.authForm.controls['lastname'].status === 'INVALID') {
<mat-error>{{getErrorMessage('lastname')}}</mat-error>
}
</mat-form-field>
</div>
}
@if (authType === 'register') {
<div class="col-12">
<mat-form-field appearance="fill" class="w-100">
<input matInput type="text" placeholder="Votre prénom" formControlName="firstname" required>
@if (this.authForm.controls['firstname'].status === 'INVALID') {
<mat-error>{{getErrorMessage('firstname')}}</mat-error>
}
</mat-form-field>
</div>
}
@if (authType === 'register') {
<div class="col-12">
<mat-form-field appearance="fill" class="w-100">
<input matInput type="text" placeholder="Numéro de téléphone" formControlName="phone" required>
@if (this.authForm.controls['phone'].status === 'INVALID') {
<mat-error>{{getErrorMessage('phone')}}</mat-error>
}
</mat-form-field>
</div>
}
@if (authType === 'register') {
<div class="col-12">
<mat-form-field appearance="fill" class="w-100">
<input matInput type="text" placeholder="Pseudo" formControlName="username">
@if (this.authForm.controls['username'].status === 'INVALID') {
<mat-error>{{getErrorMessage('username')}}</mat-error>
}
</mat-form-field>
</div>
}
@if (authType === 'register') {
<div class="col-12">
<mat-form-field appearance="fill" class="w-100">
<input matInput type="text" placeholder="Numéro de licence FFP" formControlName="licence">
@if (this.authForm.controls['licence'].status === 'INVALID') {
<mat-error>{{getErrorMessage('licence')}}</mat-error>
}
</mat-form-field>
</div>
}
@if (authType === 'register') {
<div class="col-12">
<mat-form-field appearance="fill" class="w-100">
<input matInput type="text" placeholder="Indiquez le poids en Kg" formControlName="poids">
@if (this.authForm.controls['poids'].status === 'INVALID') {
<mat-error>{{getErrorMessage('poids')}}</mat-error>
}
</mat-form-field>
</div>
}
</fieldset>
<fieldset [disabled]="isSubmitting" class="w-100">
<legend [hidden]="true">Informations de connexion</legend>
<div class="col-12">
<mat-form-field appearance="fill" class="w-100">
<input matInput type="password" placeholder="Mot de passe" formControlName="password" required>
@if (this.authForm.controls['password'].status === 'INVALID') {
<mat-error>{{getErrorMessage('password')}}</mat-error>
}
</mat-form-field>
</div>
@if (authType === 'register') {
<div class="col-12">
<mat-form-field appearance="fill" class="w-100">
<input matInput type="password" placeholder="Confirmez votre nouveau mot de passe" formControlName="confirmPassword" required>
@if (this.authForm.controls['confirmPassword'].status === 'INVALID') {
<mat-error>{{getErrorMessage('confirmPassword')}}</mat-error>
}
</mat-form-field>
</div>
}
<div class="col-12">
<button mat-raised-button color="primary" [disabled]="!authForm.valid" type="submit" class="float-sm-end">{{ btnTitle }}</button>
</div>
</fieldset>
</form>
</div>
</div>
</div>
@@ -0,0 +1,6 @@
fieldset {
border-style: none;
border-width: 0;
margin: 0;
padding: 0;
}
@@ -0,0 +1,21 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { AuthComponent } from './auth.component';
describe('AuthComponent', () => {
let component: AuthComponent;
let fixture: ComponentFixture<AuthComponent>;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [AuthComponent]
});
fixture = TestBed.createComponent(AuthComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
+168
View File
@@ -0,0 +1,168 @@
import { Component, DestroyRef, inject, OnInit, OnDestroy } from '@angular/core';
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
import { UntypedFormBuilder, UntypedFormGroup, AbstractControl, Validators, ValidatorFn, ValidationErrors, FormsModule, ReactiveFormsModule } from '@angular/forms';
import { Title } from '@angular/platform-browser';
import { ActivatedRoute, Router, RouterLink } from '@angular/router';
import { MatButtonModule } from '@angular/material/button';
import { MatInputModule } from '@angular/material/input';
import { MatFormFieldModule } from '@angular/material/form-field';
import { Subscription } from 'rxjs';
import { take } from 'rxjs/operators';
import { Errors } from 'src/app/core/models';
import { UserService } from 'src/app/core/services';
import { ListErrorsComponent, ShowAuthedDirective } from 'src/app/components/shared';
@Component({
standalone: true,
imports: [
RouterLink,
FormsModule,
ReactiveFormsModule,
MatFormFieldModule,
MatInputModule,
MatButtonModule,
ListErrorsComponent,
ShowAuthedDirective
],
selector: 'app-auth',
templateUrl: './auth.component.html',
styleUrl: './auth.component.scss'
})
export class AuthComponent implements OnInit, OnDestroy {
private _url: Subscription = new Subscription();
private _user: Subscription = new Subscription();
authType = '';
title = '';
btnTitle = '';
errors: Errors = { errors: {} };
isSubmitting = false;
authForm!: UntypedFormGroup;
destroyRef = inject(DestroyRef);
constructor(
private route: ActivatedRoute,
private router: Router,
private titleService: Title,
private userService: UserService,
private fb: UntypedFormBuilder
) {
this._resetErrors();
// use FormBuilder to create a form group
const controlsConfig = {
email: ['', [Validators.required, Validators.email]],
username: '',
firstname: '',
lastname: '',
phone: '',
licence: '',
poids: '',
password: ['', Validators.required],
confirmPassword: ''
};
this.authForm = this.fb.group(controlsConfig, { validators: this.checkPasswords });
}
ngOnInit() {
// you would normally unsubscribe from this observable subscription
// the active route observables are exemptions from unsubribe always rule
// see notes on: https://angular.io/guide/router#observable-parammap-and-component-reuse
this.route.url.pipe(take(1))
.subscribe(data => {
// Get the last piece of the URL (it's either 'login' or 'register')
this.authType = data[data.length - 1].path;
// Set a title for the page accordingly
if (this.authType === 'register') {
this.title = 'Création de compte';
this.btnTitle = 'Créer le compte';
this.titleService.setTitle(`Head Up - Créer un compte`);
} else {
this.title = 'Se connecter';
this.btnTitle = 'Se connecter';
this.titleService.setTitle(`Head Up - Connexion`);
}
// add form control for username if this is the register page
if (this.authType === 'register') {
this.authForm.controls['firstname'].setValidators([Validators.required]);
this.authForm.controls['lastname'].setValidators([Validators.required]);
this.authForm.controls['phone'].setValidators([Validators.required]);
this.authForm.controls['confirmPassword'].setValidators([Validators.minLength(8), Validators.required]);
}
});
}
ngOnDestroy() {
this._user.unsubscribe();
//this._url.unsubscribe();
}
submitForm() {
this.isSubmitting = true;
this.errors = { errors: {} };
if (this.authForm.valid) {
this._resetErrors();
const credentials = this.authForm.value;
const user$ = this.userService.attemptAuth(this.authType, credentials).pipe(takeUntilDestroyed(this.destroyRef));
this._user = user$.subscribe({
next: () => void this.router.navigateByUrl('/'),
error: (err) => {
console.log(err);
this.errors = err;
this.isSubmitting = false;
}
});
}
}
getErrorMessage(name: string) {
switch (name) {
case 'email':
if (this.authForm.controls['email'].errors !== null) {
return 'Indiquez votre adresse email';
}
break;
case 'firstname':
if (this.authForm.controls['firstname'].errors !== null) {
return 'Vous devez indiquer votre prénnom';
}
break;
case 'lastname':
if (this.authForm.controls['lastname'].errors !== null) {
return 'Vous devez indiquer votre nom';
}
break;
case 'phone':
if (this.authForm.controls['phone'].errors !== null) {
return 'Vous devez indiquer votre numéro de téléphone';
}
break;
case 'password':
if (this.authForm.controls['password'].errors !== null) {
return 'Un mot de passe est obligatoire';
}
break;
case 'confirmPassword':
if (this.authForm.controls['confirmPassword'].errors !== null) {
return 'Une confirmation du mot de passe est obligatoire';
}
break;
}
return '';
}
checkPasswords: ValidatorFn = (group: AbstractControl): ValidationErrors | null => {
if (this.authType !== 'register') {
return null;
}
const pass = group.get('password')!.value;
const confirmPass = group.get('confirmPassword')!.value
return (pass === confirmPass && pass !== '') ? null : { notSame: true }
}
private _resetErrors(): void {
this.errors = { errors: {} };
}
}