reset password
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
</mat-form-field>
|
||||
<app-button-row>
|
||||
<button (click)="onLogin()" mat-button>Anmelden</button>
|
||||
<button mat-button routerLink="/user/password">neues Passwort anfordern</button>
|
||||
<p *ngIf="errorMessage" class="error">{{errorMessage|authMessage}}</p>
|
||||
</app-button-row>
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {Component, OnInit} from '@angular/core';
|
||||
import {FormControl, FormGroup, Validators} from '@angular/forms';
|
||||
import {AngularFireAuth} from '@angular/fire/auth';
|
||||
import {Router} from '@angular/router';
|
||||
import {UserService} from '../../../services/user.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-login',
|
||||
@@ -12,7 +12,7 @@ export class LoginComponent implements OnInit {
|
||||
public form: FormGroup;
|
||||
public errorMessage: string;
|
||||
|
||||
constructor(public afAuth: AngularFireAuth, private router: Router) {
|
||||
constructor(private userService: UserService, private router: Router) {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
@@ -26,7 +26,7 @@ export class LoginComponent implements OnInit {
|
||||
this.form.updateValueAndValidity();
|
||||
if (this.form.valid) {
|
||||
try {
|
||||
await this.afAuth.auth.signInWithEmailAndPassword(this.form.value.user, this.form.value.pass);
|
||||
await this.userService.login(this.form.value.user, this.form.value.pass);
|
||||
await this.router.navigateByUrl('/');
|
||||
} catch (ex) {
|
||||
this.errorMessage = ex.code;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {AfterViewInit, Component} from '@angular/core';
|
||||
import {AngularFireAuth} from '@angular/fire/auth';
|
||||
import {Router} from '@angular/router';
|
||||
import {UserService} from '../../../services/user.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-logout',
|
||||
@@ -8,11 +8,11 @@ import {Router} from '@angular/router';
|
||||
styleUrls: ['./logout.component.less']
|
||||
})
|
||||
export class LogoutComponent implements AfterViewInit {
|
||||
constructor(public afAuth: AngularFireAuth, private router: Router) {
|
||||
constructor(private userService: UserService, private router: Router) {
|
||||
}
|
||||
|
||||
public async ngAfterViewInit() {
|
||||
await this.afAuth.auth.signOut();
|
||||
await this.userService.logout();
|
||||
await this.router.navigateByUrl('/');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
<app-card>
|
||||
Eine E-Mail mit dem neuen Passwort wurde gesendet.
|
||||
Darin ist der link enthalten, über den das neue Passwort eingegeben werden kann.
|
||||
</app-card>
|
||||
@@ -0,0 +1,25 @@
|
||||
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
|
||||
|
||||
import {PasswordSendComponent} from './password-send.component';
|
||||
|
||||
describe('PasswordSendComponent', () => {
|
||||
let component: PasswordSendComponent;
|
||||
let fixture: ComponentFixture<PasswordSendComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [PasswordSendComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(PasswordSendComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,16 @@
|
||||
import {Component, OnInit} from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'app-password-send',
|
||||
templateUrl: './password-send.component.html',
|
||||
styleUrls: ['./password-send.component.less']
|
||||
})
|
||||
export class PasswordSendComponent implements OnInit {
|
||||
|
||||
constructor() {
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
}
|
||||
|
||||
}
|
||||
15
src/app/modules/user/password/password.component.html
Normal file
15
src/app/modules/user/password/password.component.html
Normal 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>
|
||||
8
src/app/modules/user/password/password.component.less
Normal file
8
src/app/modules/user/password/password.component.less
Normal file
@@ -0,0 +1,8 @@
|
||||
.form {
|
||||
display: grid;
|
||||
}
|
||||
|
||||
p.error {
|
||||
margin: 8px 10px;
|
||||
color: darkred;
|
||||
}
|
||||
25
src/app/modules/user/password/password.component.spec.ts
Normal file
25
src/app/modules/user/password/password.component.spec.ts
Normal 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();
|
||||
});
|
||||
});
|
||||
36
src/app/modules/user/password/password.component.ts
Normal file
36
src/app/modules/user/password/password.component.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,6 +4,8 @@ import {LoginComponent} from './login/login.component';
|
||||
import {InfoComponent} from './info/info.component';
|
||||
import {LogoutComponent} from './logout/logout.component';
|
||||
import {AngularFireAuthGuard, redirectUnauthorizedTo} from '@angular/fire/auth-guard';
|
||||
import {PasswordComponent} from './password/password.component';
|
||||
import {PasswordSendComponent} from './password-send/password-send.component';
|
||||
|
||||
|
||||
const routes: Routes = [
|
||||
@@ -20,6 +22,14 @@ const routes: Routes = [
|
||||
path: 'logout',
|
||||
component: LogoutComponent
|
||||
},
|
||||
{
|
||||
path: 'password',
|
||||
component: PasswordComponent
|
||||
},
|
||||
{
|
||||
path: 'password-send',
|
||||
component: PasswordSendComponent
|
||||
},
|
||||
{
|
||||
path: 'info',
|
||||
component: InfoComponent,
|
||||
|
||||
@@ -13,10 +13,12 @@ import {InfoComponent} from './info/info.component';
|
||||
import {LogoutComponent} from './logout/logout.component';
|
||||
import {RolePipe} from './info/role.pipe';
|
||||
import {MatSelectModule} from '@angular/material/select';
|
||||
import {PasswordComponent} from './password/password.component';
|
||||
import {PasswordSendComponent} from './password-send/password-send.component';
|
||||
|
||||
|
||||
@NgModule({
|
||||
declarations: [LoginComponent, AuthMessagePipe, InfoComponent, LogoutComponent, RolePipe],
|
||||
declarations: [LoginComponent, AuthMessagePipe, InfoComponent, LogoutComponent, RolePipe, PasswordComponent, PasswordSendComponent],
|
||||
imports: [
|
||||
CommonModule,
|
||||
UserRoutingModule,
|
||||
|
||||
Reference in New Issue
Block a user