From 8033cebac269cfa13abcec6db414c795fdaef236 Mon Sep 17 00:00:00 2001 From: Chneemann Date: Sat, 3 Aug 2024 10:51:43 +0200 Subject: [PATCH] form for password change created --- .../forgot-password.component.html | 93 +++++++++++++++++-- .../forgot-password.component.ts | 25 ++++- 2 files changed, 105 insertions(+), 13 deletions(-) diff --git a/frontend/src/app/components/auth/forgot-password/forgot-password.component.html b/frontend/src/app/components/auth/forgot-password/forgot-password.component.html index b7bab89..5ab990c 100644 --- a/frontend/src/app/components/auth/forgot-password/forgot-password.component.html +++ b/frontend/src/app/components/auth/forgot-password/forgot-password.component.html @@ -1,15 +1,7 @@
Forgot your password?
- @if (sendSuccess) { -
-

- If the email you entered exists on our server, you will receive a - message with instructions on how to reset your password. -

- To the login -
- } @else { + @if (!queryEmail && !sendSuccess && !queryEmailSuccess) {

We will send you an email with instructions to reset your password.

@@ -48,6 +40,87 @@ [disabled]="!isUserEmailValid(authData.mail)" > - } + } @else { @if (sendSuccess) { +
+

+ If the email you entered exists on our server, you will receive a + message with instructions on how to reset your password. +

+ To the login +
+ } @if (queryEmailSuccess) { +
+

+ Password change successful.
You can now log in with your new + password. +

+ To the login +
+ } @if (queryEmail && !queryEmailSuccess) { +
+

Please enter your new password and confirm it.

+
+
+ +
+ @if (!password.valid && password.touched && authData.password.length < + 1) { +

Please enter a password

+ } @else { @if (authData.password && authData.password.length < 6 && + password.touched) { +

Password is too short, min 6 characters

+ } } +
+ +
+ @if (authData.password !== authData.passwordConfirm && + passwordConfirm.touched) { +

The passwords do not match

+ } +
+ +
+ } }
diff --git a/frontend/src/app/components/auth/forgot-password/forgot-password.component.ts b/frontend/src/app/components/auth/forgot-password/forgot-password.component.ts index be7a144..9811761 100644 --- a/frontend/src/app/components/auth/forgot-password/forgot-password.component.ts +++ b/frontend/src/app/components/auth/forgot-password/forgot-password.component.ts @@ -2,7 +2,7 @@ import { CommonModule } from '@angular/common'; import { Component } from '@angular/core'; import { BtnLargeComponent } from '../../../shared/components/btn-large/btn-large.component'; import { FormsModule, NgForm } from '@angular/forms'; -import { RouterLink } from '@angular/router'; +import { ActivatedRoute, Router, RouterLink } from '@angular/router'; @Component({ selector: 'app-forgot-password', @@ -14,9 +14,22 @@ import { RouterLink } from '@angular/router'; export class ForgotPasswordComponent { authData = { mail: '', + password: '', + passwordConfirm: '', }; sendSuccess: boolean = false; + queryEmail: boolean = false; + queryEmailSuccess: boolean = false; + + constructor(private route: ActivatedRoute, private router: Router) {} + + ngOnInit(): void { + this.route.queryParams.subscribe((params) => { + this.authData.mail = params['mail'] || ''; + this.queryEmailSuccess = params['pw-change'] || ''; + }); + } isUserEmailValid(emailValue: string) { const emailRegex = /^[\w.%+-]+@[\w.-]+\.[a-zA-Z]{2,}$/; @@ -25,9 +38,15 @@ export class ForgotPasswordComponent { onSubmit(ngForm: NgForm, mailInput: any) { if (ngForm.submitted && ngForm.form.valid) { + if (mailInput.name === 'mail') { + ngForm.form.reset(); + this.sendSuccess = true; + } else if (mailInput.name === 'password') { + ngForm.form.reset(); + this.queryEmail = false; + this.queryEmailSuccess = true; + } console.log(this.authData); - ngForm.form.reset(); - this.sendSuccess = true; } else { mailInput.control.markAsTouched(); }