reset password

This commit is contained in:
2020-04-24 15:37:27 +02:00
committed by smuddy
parent 0e8a493deb
commit 732353f5bd
14 changed files with 161 additions and 7 deletions

View File

@@ -0,0 +1,15 @@
<app-card>
<div [formGroup]="form" class="form">
<mat-form-field appearance="outline">
<mat-label>E-Mail Addresse</mat-label>
<input (keyup.enter)="onResetPassword()" formControlName="user" matInput>
</mat-form-field>
<app-button-row>
<button (click)="onResetPassword()" mat-button>neues Passwort anfordern</button>
<p *ngIf="errorMessage" class="error">{{errorMessage|authMessage}}</p>
</app-button-row>
</div>
</app-card>

View File

@@ -0,0 +1,8 @@
.form {
display: grid;
}
p.error {
margin: 8px 10px;
color: darkred;
}

View File

@@ -0,0 +1,25 @@
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
import {PasswordComponent} from './password.component';
describe('PasswordComponent', () => {
let component: PasswordComponent;
let fixture: ComponentFixture<PasswordComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [PasswordComponent]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(PasswordComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@@ -0,0 +1,36 @@
import {Component, OnInit} from '@angular/core';
import {FormControl, FormGroup, Validators} from '@angular/forms';
import {Router} from '@angular/router';
import {UserService} from '../../../services/user.service';
@Component({
selector: 'app-password',
templateUrl: './password.component.html',
styleUrls: ['./password.component.less']
})
export class PasswordComponent implements OnInit {
public form: FormGroup;
public errorMessage: string;
constructor(public userService: UserService, private router: Router) {
}
public ngOnInit(): void {
this.form = new FormGroup({
user: new FormControl(null, [Validators.required, Validators.email])
});
}
public async onResetPassword() {
this.form.updateValueAndValidity();
if (this.form.valid) {
try {
await this.userService.changePassword(this.form.value.user);
await this.router.navigateByUrl('/user/password-send');
} catch (ex) {
this.errorMessage = ex.code;
}
}
}
}