correctifs
continuous-integration/drone/pr Build is failing Details
continuous-integration/drone/push Build is passing Details

pull/14/head
Hugo PRADIER 10 months ago
parent 7de3db7c66
commit 2d5c4f126e

@ -30,8 +30,8 @@
"budgets": [ "budgets": [
{ {
"type": "initial", "type": "initial",
"maximumWarning": "500kb", "maximumWarning": "2mb",
"maximumError": "1mb" "maximumError": "3mb"
}, },
{ {
"type": "anyComponentStyle", "type": "anyComponentStyle",

@ -1,43 +1,33 @@
<div class="form-container"> <form [formGroup]="loginForm" (ngSubmit)="loginAction()">
<h1>Formulaire de connexion :</h1> <mat-form-field>
<mat-label>Login</mat-label>
<mat-form-field class="form-field"> <input matInput formControlName="login" required />
<mat-label>Enter your login</mat-label> <mat-error *ngIf="loginForm.controls.login.invalid">
<input matInput placeholder="pat" [formControl]="login" required /> Login is required
<mat-error *ngIf="login.invalid"></mat-error> </mat-error>
</mat-form-field> </mat-form-field>
<mat-form-field class="form-field"> <mat-form-field>
<mat-label>Enter your password</mat-label> <mat-label>Password</mat-label>
<input <input
matInput matInput
[type]="hide ? 'password' : 'text'" [type]="hide ? 'password' : 'text'"
[formControl]="password" formControlName="password"
required /> required />
<button <button
mat-icon-button mat-icon-button
matSuffix matSuffix
(click)="hide = !hide" (click)="hide = !hide"
[attr.aria-label]="'Hide password'" [attr.aria-label]="'Hide password'">
[attr.aria-pressed]="hide">
<mat-icon>{{ hide ? 'visibility_off' : 'visibility' }}</mat-icon> <mat-icon>{{ hide ? 'visibility_off' : 'visibility' }}</mat-icon>
</button> </button>
<mat-error *ngIf="password.invalid">{{ errorMessage }}</mat-error> <mat-error *ngIf="loginForm.controls.password.invalid">
Password is required
</mat-error>
</mat-form-field> </mat-form-field>
<button <button mat-raised-button type="submit">Login</button>
mat-flat-button
color="primary"
(click)="loginAction()"
[disabled]="login.invalid || password.invalid">
Se connecter
</button>
<!-- Message de retour de l'inscription --> <div *ngIf="errorLogin">{{ errorLogin }}</div>
<div *ngIf="successLogin" class="success-message"> <div *ngIf="successLogin">{{ successLogin }}</div>
{{ successLogin }} </form>
</div>
<div *ngIf="errorLogin" class="error-message">
{{ errorLogin }}
</div>
</div>

@ -6,6 +6,8 @@ import {
FormsModule, FormsModule,
ReactiveFormsModule, ReactiveFormsModule,
NgForm, NgForm,
FormGroup,
FormBuilder,
} from '@angular/forms'; } from '@angular/forms';
import { MatInputModule } from '@angular/material/input'; import { MatInputModule } from '@angular/material/input';
import { MatFormFieldModule } from '@angular/material/form-field'; import { MatFormFieldModule } from '@angular/material/form-field';
@ -34,41 +36,37 @@ import { User } from 'src/app/models/user.model';
export class LoginComponent { export class LoginComponent {
hide = true; hide = true;
email = new FormControl('', [Validators.required, Validators.email]); loginForm = this.formBuilder.group({
login: ['', Validators.required],
login = new FormControl('', [Validators.required]); password: ['', Validators.required],
});
password = new FormControl('', [Validators.required]);
errorMessage = ''; errorMessage = '';
successLogin = ''; successLogin = '';
errorLogin = ''; errorLogin = '';
constructor(private userService: UserService) { constructor(
merge(this.email.statusChanges, this.email.valueChanges).pipe( private userService: UserService,
takeUntilDestroyed() private formBuilder: FormBuilder
); ) {
this.userService = userService;
} }
loginAction() { loginAction() {
console.log('login user :', this.login.value); const formValue = this.loginForm.value;
const form: any = { this.userService
value: { .loginUser(formValue.login!, formValue.password!)
login: this.login.value, .subscribe((response) => {
password: this.password.value, console.log('response :', response);
}, if (response.success) {
}; this.successLogin = 'Vous êtes connecté.';
this.userService.loginUser(form).subscribe((response) => { this.errorLogin = '';
console.log('response :', response); } else {
if ((response as any).success) { this.errorLogin = "L'authentification a échoué.";
this.successLogin = 'Vous êtes connecté.'; this.successLogin = '';
this.errorLogin = ''; }
} else { });
this.errorLogin = "L'authentification a échoué.";
this.successLogin = '';
}
});
} }
} }

@ -1,4 +1,4 @@
<div class="form-container"> <form [formGroup]="registerForm" (ngSubmit)="register()">
<h1>Formulaire d'inscription :</h1> <h1>Formulaire d'inscription :</h1>
<mat-form-field class="form-field"> <mat-form-field class="form-field">
@ -6,21 +6,19 @@
<input <input
matInput matInput
placeholder="pat@example.com" placeholder="pat@example.com"
[formControl]="email" formControlName="email"
(blur)="updateErrorMessage()"
required /> required />
<mat-error *ngIf="email.invalid">{{ errorMessage }}</mat-error> <mat-error *ngIf="registerForm.controls.email.invalid">{{
errorMessage
}}</mat-error>
</mat-form-field> </mat-form-field>
<mat-form-field class="form-field"> <mat-form-field class="form-field">
<mat-label>Enter your login</mat-label> <mat-label>Enter your login</mat-label>
<input <input matInput placeholder="pat" formControlName="login" required />
matInput <mat-error *ngIf="registerForm.controls.login.invalid">{{
placeholder="pat" errorMessage
[formControl]="login" }}</mat-error>
(blur)="updateErrorMessage()"
required />
<mat-error *ngIf="login.invalid">{{ errorMessage }}</mat-error>
</mat-form-field> </mat-form-field>
<mat-form-field class="form-field"> <mat-form-field class="form-field">
@ -28,8 +26,7 @@
<input <input
matInput matInput
[type]="hide ? 'password' : 'text'" [type]="hide ? 'password' : 'text'"
[formControl]="password" formControlName="password"
(blur)="updateErrorMessage()"
required /> required />
<button <button
mat-icon-button mat-icon-button
@ -39,16 +36,12 @@
[attr.aria-pressed]="hide"> [attr.aria-pressed]="hide">
<mat-icon>{{ hide ? 'visibility_off' : 'visibility' }}</mat-icon> <mat-icon>{{ hide ? 'visibility_off' : 'visibility' }}</mat-icon>
</button> </button>
<mat-error *ngIf="password.invalid">{{ errorMessage }}</mat-error> <mat-error *ngIf="registerForm.controls.password.invalid">{{
errorMessage
}}</mat-error>
</mat-form-field> </mat-form-field>
<button <button mat-flat-button color="primary" type="submit">Créer un compte</button>
mat-flat-button
color="primary"
(click)="register()"
[disabled]="email.invalid || login.invalid || password.invalid">
Créer un compte
</button>
<!-- Message de retour de l'inscription --> <!-- Message de retour de l'inscription -->
<div *ngIf="successRegister" class="success-message"> <div *ngIf="successRegister" class="success-message">
@ -57,4 +50,4 @@
<div *ngIf="errorRegister" class="error-message"> <div *ngIf="errorRegister" class="error-message">
{{ errorRegister }} {{ errorRegister }}
</div> </div>
</div> </form>

@ -6,6 +6,7 @@ import {
FormsModule, FormsModule,
ReactiveFormsModule, ReactiveFormsModule,
NgForm, NgForm,
FormBuilder,
} from '@angular/forms'; } from '@angular/forms';
import { MatInputModule } from '@angular/material/input'; import { MatInputModule } from '@angular/material/input';
import { MatFormFieldModule } from '@angular/material/form-field'; import { MatFormFieldModule } from '@angular/material/form-field';
@ -34,54 +35,42 @@ import { User } from 'src/app/models/user.model';
export class RegisterComponent { export class RegisterComponent {
hide = true; hide = true;
email = new FormControl('', [Validators.required, Validators.email]); registerForm = this.formBuilder.group({
email: ['', Validators.required],
login = new FormControl('', [Validators.required]); login: ['', Validators.required],
password: ['', Validators.required],
password = new FormControl('', [Validators.required]); });
errorMessage = ''; errorMessage = '';
successRegister = ''; successRegister = '';
errorRegister = ''; errorRegister = '';
constructor(private userService: UserService) { constructor(
merge(this.email.statusChanges, this.email.valueChanges) private userService: UserService,
.pipe(takeUntilDestroyed()) private formBuilder: FormBuilder
.subscribe(() => this.updateErrorMessage()); ) {
} this.userService = userService;
updateErrorMessage() {
if (this.email.hasError('required')) {
this.errorMessage = 'You must enter a value';
} else if (this.email.hasError('email')) {
this.errorMessage = 'Not a valid email';
} else if (this.login.hasError('required')) {
this.errorMessage = 'You must enter a login';
} else {
this.errorMessage = '';
}
} }
register() { register() {
console.log('registering user :', this.login.value); const formRegisterValue = this.registerForm.value;
const form: any = { this.userService
value: { .postUser(
login: this.login.value, formRegisterValue.email!,
password: this.password.value, formRegisterValue.login!,
}, formRegisterValue.password!
}; )
this.userService.postUser(form).subscribe((response) => { .subscribe((response) => {
console.log('response :', response); console.log('response :', response);
if ((response as any).success) { if (response.success) {
this.successRegister = 'Votre compte a été créé avec succès.'; this.successRegister = 'Votre compte a été créé avec succès.';
this.errorRegister = ''; this.errorRegister = '';
} else { } else {
this.errorRegister = this.errorRegister =
"L'inscription a échoué : un compte avec ce login existe déjà."; "L'inscription a échoué : un compte avec ce login existe déjà.";
this.successRegister = ''; this.successRegister = '';
} }
}); });
} }
} }

@ -12,23 +12,28 @@ export class UserService {
constructor(private http: HttpClient) {} constructor(private http: HttpClient) {}
postUser(form: NgForm): Observable<HttpResponse<Response>> { postUser(
let body = { email: string,
login: form.value.login, login: string,
password: form.value.password, password: string
): Observable<Response> {
const body = {
email: email,
login: login,
password: password,
permissions: 0, permissions: 0,
}; };
return this.http.post<any>(`${this.API_URL}/users`, body); return this.http.post<Response>(`${this.API_URL}/users`, body);
} }
loginUser(form: NgForm): Observable<HttpResponse<Response>> { loginUser(login: string, password: string): Observable<Response> {
let body = { const body = {
login: form.value.login, login: login,
password: form.value.password, password: password,
}; };
return this.http.post<any>(`${this.API_URL}/users/login`, body); return this.http.post<Response>(`${this.API_URL}/users/login`, body);
} }
} }

Loading…
Cancel
Save