Implemented working pw changer

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

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

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

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

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

Loading…
Cancel
Save