added creation of account but bad request (400)

This commit is contained in:
2026-03-24 19:44:26 +01:00
parent ef2afb0b58
commit 6ec656fde1
5 changed files with 65 additions and 18 deletions
+1 -1
View File
@@ -19,7 +19,7 @@
<div class="flex-1 border-b border-gray-400"></div>
</div>
} @else {
<app-sign-on-form></app-sign-on-form>
<app-sign-on-form #userForm></app-sign-on-form>
}
<ion-button class="w-10/12 mt-0" color="secondary" (click)="createAccount()">
+20 -2
View File
@@ -2,8 +2,9 @@ import {Component, inject, signal, viewChild} from '@angular/core';
import {IonicModule} from "@ionic/angular";
import {SignInFormComponent} from "../../components/sign-in-form/sign-in-form.component";
import {SignOnFormComponent} from "../../components/sign-on-form/sign-on-form.component";
import {firstValueFrom} from "rxjs";
import {AuthManageService} from "../../services/auth-manage";
import {firstValueFrom} from "rxjs";
import {UsersService} from "../../services/api";
@Component({
selector: 'app-login',
@@ -18,13 +19,16 @@ import {AuthManageService} from "../../services/auth-manage";
export class LoginComponent {
authState = signal<boolean>(true)
login = viewChild<SignInFormComponent>('loginForm');
user = viewChild<SignOnFormComponent>('userForm');
private authManageService = inject(AuthManageService);
private usersService = inject(UsersService);
createAccount() {
async createAccount() {
if (this.authState()) {
this.authState.set(false);
} else if (this.authState() == false) {
await this.addUser();
this.authState.set(true);
}
}
@@ -34,4 +38,18 @@ export class LoginComponent {
console.log(user);
this.authManageService.connectUser(user.username, user.password);
}
async addUser() {
if (this.user().userForm.invalid) {
console.log('Erreur d\'écriture dans le formulaire');
return;
}
try {
const users = this.user().userForm.getRawValue();
await firstValueFrom(this.usersService.createUserEndpoint(users))
console.log('Utilisateur crée : ' + users);
} catch (e) {
console.log(e);
}
}
}