diff --git a/src/app/components/password-form/password-form.component.html b/src/app/components/password-form/password-form.component.html new file mode 100644 index 0000000..43c3a17 --- /dev/null +++ b/src/app/components/password-form/password-form.component.html @@ -0,0 +1,35 @@ +
+
+ + + Mot de passe + * + + + + + + + + + Modifier + + +
+

Consignes du mot de passe :

+
    +
  • 12 caractères
  • +
  • Au moins une majuscule
  • +
  • Au moins une minuscule
  • +
  • Au moins un chiffre
  • +
  • Au moins un caractère spécial
  • +
+
+
+
\ No newline at end of file diff --git a/src/app/components/password-form/password-form.component.scss b/src/app/components/password-form/password-form.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/app/components/password-form/password-form.component.ts b/src/app/components/password-form/password-form.component.ts new file mode 100644 index 0000000..5f7efa6 --- /dev/null +++ b/src/app/components/password-form/password-form.component.ts @@ -0,0 +1,79 @@ +import {Component, inject, input, OnInit, output} from '@angular/core'; +import {AlertController, IonicModule, LoadingController, ToastController} from "@ionic/angular"; +import {FormControl, FormGroup, ReactiveFormsModule, Validators} from "@angular/forms"; +import {GetUserDetailsDto, UsersService} from "../../services/api"; +import {firstValueFrom} from "rxjs"; + +@Component({ + selector: 'app-password-form', + templateUrl: './password-form.component.html', + styleUrls: ['./password-form.component.scss'], + imports: [ + IonicModule, + ReactiveFormsModule + ] +}) +export class PasswordFormComponent { + private toastCtrl = inject(ToastController); + private loadCtrl = inject(LoadingController); + private usersServices = inject(UsersService); + + passwordForm: FormGroup = new FormGroup({ + password: new FormControl(null, [Validators.required, + Validators.minLength(12), + Validators.pattern(/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*?[#?!_@$%^&*-])/)]) + }); + + async updatePassword() { + const loading = await this.loadCtrl.create({ + message: 'Vérification...', + spinner: 'lines-sharp-small' + }); + await loading.present(); + + if (this.passwordForm.invalid) { + const toast = await this.toastCtrl.create({ + message: 'Mot de passe incorrect', + duration: 2000, + color: 'danger' + }); + this.passwordForm.reset(); + await loading.dismiss(); + await toast.present(); + + return; + } + await loading.dismiss(); + + const loading2 = await this.loadCtrl.create({ + message: 'Modification...', + spinner: 'lines-sharp-small' + }); + await loading2.present(); + + try { + await firstValueFrom(this.usersServices.patchUserPasswordEndpoint(this.passwordForm.getRawValue())); + + const toast = await this.toastCtrl.create({ + message: 'Modification réussie', + duration: 2000, + color: 'success' + }); + + this.passwordForm.reset(); + + await loading2.dismiss(); + await toast.present(); + } catch (error) { + const toast = await this.toastCtrl.create({ + message: 'Modification impossible', + duration: 2000, + color: 'danger' + }); + await loading2.dismiss(); + await toast.present(); + + console.log(error.message); + } + } +} diff --git a/src/app/components/profil-form/profil-form.component.html b/src/app/components/profil-form/profil-form.component.html index 3269849..5e1de49 100644 --- a/src/app/components/profil-form/profil-form.component.html +++ b/src/app/components/profil-form/profil-form.component.html @@ -5,7 +5,7 @@ Prénom * - + * - + * - + * - +
-

Formulaire password

+
} diff --git a/src/app/pages/home/home.component.ts b/src/app/pages/home/home.component.ts index 1762a81..854e483 100644 --- a/src/app/pages/home/home.component.ts +++ b/src/app/pages/home/home.component.ts @@ -22,6 +22,7 @@ import { import {UserAchievementsComponent} from "../../components/user-achievements/user-achievements.component"; import {ModalComponent} from "../../components/modal/modal.component"; import {ProfilFormComponent} from "../../components/profil-form/profil-form.component"; +import {PasswordFormComponent} from "../../components/password-form/password-form.component"; addIcons({ 'profile': personOutline, @@ -44,7 +45,9 @@ type View = 'menu' | 'profile' | 'password' | 'designation' | 'gallery'; ChallengesAccomplishedComponent, UserAchievementsComponent, ModalComponent, - ProfilFormComponent + ProfilFormComponent, + PasswordFormComponent, + PasswordFormComponent ] }) export class HomeComponent implements OnInit {