Implemented working pw changer

pull/8/head
FlayInAHook 4 years ago
parent 12643851c3
commit a93639b9dc

@ -1,21 +1,15 @@
export class AuthUser {
request_token: string;
refresh_token: string;
user: {
id: number;
name: string;
email: string;
attributes : {
profile_url: string;
}
}
user: User;
}
export class User {
id: number;
name: string;
email: string;
own_password: string;
password: string;
attributes : {
profile_url: string;
}

@ -1,7 +1,7 @@
<div id="login-form">
<h1>Profil aktualisieren</h1>
<mat-form-field class="currentPW" (keyup.enter)="login()">
<mat-form-field class="currentPW" >
<mat-label>Aktuelles Passwort</mat-label>
<input
matInput
@ -32,8 +32,7 @@
Bitte geben Sie eine valide E-Mail-Adresse ein.
</mat-error>
</mat-form-field>-->
<mat-form-field (keyup.enter)="login()" (input)="onPasswordInput()">
<mat-form-field *ngIf="show()" (input)="onPasswordInput()">
<mat-label>Neues Passwort</mat-label>
<input
matInput
@ -56,7 +55,7 @@
<mat-icon>{{ hide ? "visibility_off" : "visibility" }}</mat-icon>
</button>
</mat-form-field>
<mat-form-field (keyup.enter)="login()" (input)="onPasswordInput()">
<mat-form-field *ngIf="show()" (input)="onPasswordInput()">
<mat-label>Passwort wiederholen</mat-label>
<input
matInput
@ -80,8 +79,8 @@
</button>
</mat-form-field>
<mat-progress-bar mode="indeterminate" id="loading-bar" *ngIf="loading"></mat-progress-bar>
<button mat-stroked-button color="primary" (click)="login()">
Profil aktualisieren
<button *ngIf="show()" mat-stroked-button color="primary" (click)="updatePassword()">
Passwort aktualisieren
</button>
<mat-error class="login-error-message" *ngIf="errorOccurred">
{{errorMessage}}

@ -1,8 +1,11 @@
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormControl, FormGroup, ValidationErrors, ValidatorFn, Validators } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
import { User } from 'src/app/models/user';
import { AuthService } from 'src/app/services/auth.service';
import { SnackBarService } from 'src/app/services/snackbar.service';
import { BikesService } from '../../services/bikes.service';
import {UserService} from '../../services/user.service';
@Component({
selector: 'app-profile',
@ -13,7 +16,7 @@ export class ProfileComponent implements OnInit {
minPw: number = 8;
email = new FormControl('', [Validators.required, Validators.email]);
password = new FormControl('', [Validators.required]);
password = new FormControl('', [Validators.required, Validators.minLength(this.minPw)]);
passwordNew = new FormControl('', [Validators.required,Validators.minLength(this.minPw)]);
passwordNew2 = new FormControl('', [Validators.required]);
pwGroup: FormGroup;
@ -24,7 +27,9 @@ export class ProfileComponent implements OnInit {
returnUrl : string;
constructor(private authService: AuthService, private router: Router, private route: ActivatedRoute, private formBuilder : FormBuilder) {}
constructor(private authService: AuthService, private snackBar: SnackBarService,
private userService: UserService, private router: Router,
private route: ActivatedRoute, private formBuilder : FormBuilder) {}
ngOnInit(): void {
this.pwGroup = this.formBuilder.group({
@ -40,22 +45,34 @@ export class ProfileComponent implements OnInit {
this.passwordNew2.setErrors(null);
}
login() {
show() : boolean {
return !this.password.hasError('required') && !this.password.hasError('minlength');
}
updatePassword() {
this.errorMessage = '';
this.errorOccurred = false;
if (this.email.invalid || this.password.invalid) {
if (this.password.invalid || this.pwGroup.invalid) {
return;
}
let user : User = this.authService.getCurrentUserValue.user;
user.own_password = this.password.value;
user.password = this.passwordNew.value;
this.loading = true;
this.authService
.login(this.email.value, this.password.value)
this.userService
.updateUser(user)
.subscribe(
() => this.router.navigateByUrl(this.returnUrl),
data => {
this.snackBar.openSnackBar("Das Passwort wurde erfolgreich aktualisiert");
console.log(JSON.stringify(data));
},
(error) => {
this.errorOccurred = true;
this.errorMessage =
error.error.message ||
'Ein Fehler bei Einloggen ist aufgetreten. Überprüfen Sie Ihre Internetverbindung oder versuchen Sie es später erneut.';
'Ein Fehler ist aufgetreten. Bitte melden sie dies ihrem Administrator.';
}
)
.add(() => {
@ -64,6 +81,7 @@ export class ProfileComponent implements OnInit {
}
}
export const passwordMatchValidator: ValidatorFn = (formGroup: FormGroup): ValidationErrors | null => {
if (formGroup.get('passwordNew').value === formGroup.get('passwordNew2').value)
return null;

@ -9,7 +9,7 @@ export class SnackBarService {
constructor(private snackBar : MatSnackBar) { }
openSnackBar(message: string, action: string) {
openSnackBar(message: string, action: string = "") {
this.snackBar.open(message, action, {
duration: 5000,
panelClass: ['mat-toolbar', 'mat-primary']

Loading…
Cancel
Save