form for password change created
This commit is contained in:
parent
07800c77c5
commit
8033cebac2
2 changed files with 105 additions and 13 deletions
|
|
@ -1,15 +1,7 @@
|
||||||
<section>
|
<section>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<div class="headline">Forgot your password?</div>
|
<div class="headline">Forgot your password?</div>
|
||||||
@if (sendSuccess) {
|
@if (!queryEmail && !sendSuccess && !queryEmailSuccess) {
|
||||||
<div class="note">
|
|
||||||
<p>
|
|
||||||
If the email you entered exists on our server, you will receive a
|
|
||||||
message with instructions on how to reset your password.
|
|
||||||
</p>
|
|
||||||
<a routerLink="/login">To the login</a>
|
|
||||||
</div>
|
|
||||||
} @else {
|
|
||||||
<div class="note">
|
<div class="note">
|
||||||
<p>We will send you an email with instructions to reset your password.</p>
|
<p>We will send you an email with instructions to reset your password.</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -48,6 +40,87 @@
|
||||||
[disabled]="!isUserEmailValid(authData.mail)"
|
[disabled]="!isUserEmailValid(authData.mail)"
|
||||||
></app-btn-large>
|
></app-btn-large>
|
||||||
</form>
|
</form>
|
||||||
}
|
} @else { @if (sendSuccess) {
|
||||||
|
<div class="note">
|
||||||
|
<p>
|
||||||
|
If the email you entered exists on our server, you will receive a
|
||||||
|
message with instructions on how to reset your password.
|
||||||
|
</p>
|
||||||
|
<a routerLink="/login">To the login</a>
|
||||||
|
</div>
|
||||||
|
} @if (queryEmailSuccess) {
|
||||||
|
<div class="note">
|
||||||
|
<p>
|
||||||
|
Password change successful.<br />You can now log in with your new
|
||||||
|
password.
|
||||||
|
</p>
|
||||||
|
<a routerLink="/login">To the login</a>
|
||||||
|
</div>
|
||||||
|
} @if (queryEmail && !queryEmailSuccess) {
|
||||||
|
<div class="note">
|
||||||
|
<p>Please enter your new password and confirm it.</p>
|
||||||
|
</div>
|
||||||
|
<form
|
||||||
|
#taskForm="ngForm"
|
||||||
|
(ngSubmit)="onSubmit(taskForm, password)"
|
||||||
|
onsubmit="return false"
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
type="password"
|
||||||
|
id="password"
|
||||||
|
name="password"
|
||||||
|
#password="ngModel"
|
||||||
|
placeholder="Enter a password"
|
||||||
|
autocomplete="new-password"
|
||||||
|
[(ngModel)]="authData.password"
|
||||||
|
pattern="[^<>]*"
|
||||||
|
minlength="6"
|
||||||
|
[class.error-border]="
|
||||||
|
password.invalid && password.touched && authData.password.length < 6
|
||||||
|
"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<div class="error-msg">
|
||||||
|
@if (!password.valid && password.touched && authData.password.length <
|
||||||
|
1) {
|
||||||
|
<p>Please enter a password</p>
|
||||||
|
} @else { @if (authData.password && authData.password.length < 6 &&
|
||||||
|
password.touched) {
|
||||||
|
<p>Password is too short, min 6 characters</p>
|
||||||
|
} }
|
||||||
|
</div>
|
||||||
|
<input
|
||||||
|
type="password"
|
||||||
|
id="passwordConfirm"
|
||||||
|
name="passwordConfirm"
|
||||||
|
#passwordConfirm="ngModel"
|
||||||
|
placeholder="Confirm password"
|
||||||
|
autocomplete="new-password"
|
||||||
|
[(ngModel)]="authData.passwordConfirm"
|
||||||
|
pattern="[^<>]*"
|
||||||
|
minlength="6"
|
||||||
|
[class.error-border]="
|
||||||
|
authData.password !== authData.passwordConfirm &&
|
||||||
|
passwordConfirm.touched
|
||||||
|
"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<div class="error-msg">
|
||||||
|
@if (authData.password !== authData.passwordConfirm &&
|
||||||
|
passwordConfirm.touched) {
|
||||||
|
<p>The passwords do not match</p>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
<app-btn-large
|
||||||
|
[value]="'Update Password'"
|
||||||
|
[disabled]="
|
||||||
|
!isUserEmailValid(authData.mail) ||
|
||||||
|
authData.password !== authData.passwordConfirm ||
|
||||||
|
!authData.password ||
|
||||||
|
!authData.passwordConfirm
|
||||||
|
"
|
||||||
|
></app-btn-large>
|
||||||
|
</form>
|
||||||
|
} }
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import { CommonModule } from '@angular/common';
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import { BtnLargeComponent } from '../../../shared/components/btn-large/btn-large.component';
|
import { BtnLargeComponent } from '../../../shared/components/btn-large/btn-large.component';
|
||||||
import { FormsModule, NgForm } from '@angular/forms';
|
import { FormsModule, NgForm } from '@angular/forms';
|
||||||
import { RouterLink } from '@angular/router';
|
import { ActivatedRoute, Router, RouterLink } from '@angular/router';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-forgot-password',
|
selector: 'app-forgot-password',
|
||||||
|
|
@ -14,9 +14,22 @@ import { RouterLink } from '@angular/router';
|
||||||
export class ForgotPasswordComponent {
|
export class ForgotPasswordComponent {
|
||||||
authData = {
|
authData = {
|
||||||
mail: '',
|
mail: '',
|
||||||
|
password: '',
|
||||||
|
passwordConfirm: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
sendSuccess: boolean = false;
|
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) {
|
isUserEmailValid(emailValue: string) {
|
||||||
const emailRegex = /^[\w.%+-]+@[\w.-]+\.[a-zA-Z]{2,}$/;
|
const emailRegex = /^[\w.%+-]+@[\w.-]+\.[a-zA-Z]{2,}$/;
|
||||||
|
|
@ -25,9 +38,15 @@ export class ForgotPasswordComponent {
|
||||||
|
|
||||||
onSubmit(ngForm: NgForm, mailInput: any) {
|
onSubmit(ngForm: NgForm, mailInput: any) {
|
||||||
if (ngForm.submitted && ngForm.form.valid) {
|
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);
|
console.log(this.authData);
|
||||||
ngForm.form.reset();
|
|
||||||
this.sendSuccess = true;
|
|
||||||
} else {
|
} else {
|
||||||
mailInput.control.markAsTouched();
|
mailInput.control.markAsTouched();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue