|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
import { Component, OnInit } from '@angular/core';
|
|
|
|
|
import { FormControl, Validators } from '@angular/forms';
|
|
|
|
|
import { FormBuilder, FormControl, FormGroup, ValidationErrors, ValidatorFn, Validators } from '@angular/forms';
|
|
|
|
|
import { ActivatedRoute, Router } from '@angular/router';
|
|
|
|
|
import { AuthService } from 'src/app/services/auth.service';
|
|
|
|
|
import { BikesService } from '../../services/bikes.service';
|
|
|
|
@ -10,8 +10,13 @@ import { BikesService } from '../../services/bikes.service';
|
|
|
|
|
styleUrls: ['./profile.component.scss'],
|
|
|
|
|
})
|
|
|
|
|
export class ProfileComponent implements OnInit {
|
|
|
|
|
|
|
|
|
|
minPw: number = 8;
|
|
|
|
|
email = new FormControl('', [Validators.required, Validators.email]);
|
|
|
|
|
password = new FormControl('', [Validators.required]);
|
|
|
|
|
passwordNew = new FormControl('', [Validators.required,Validators.minLength(this.minPw)]);
|
|
|
|
|
passwordNew2 = new FormControl('', [Validators.required]);
|
|
|
|
|
pwGroup: FormGroup;
|
|
|
|
|
hide = true;
|
|
|
|
|
loading = false;
|
|
|
|
|
errorOccurred = false;
|
|
|
|
@ -19,10 +24,20 @@ export class ProfileComponent implements OnInit {
|
|
|
|
|
|
|
|
|
|
returnUrl : string;
|
|
|
|
|
|
|
|
|
|
constructor(private authService: AuthService, private router: Router, private route: ActivatedRoute) {}
|
|
|
|
|
constructor(private authService: AuthService, private router: Router, private route: ActivatedRoute, private formBuilder : FormBuilder) {}
|
|
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
|
this.returnUrl = this.route.snapshot.queryParams['returnUrl'] || '/tableOverview';
|
|
|
|
|
this.pwGroup = this.formBuilder.group({
|
|
|
|
|
passwordNew: this.passwordNew,
|
|
|
|
|
passwordNew2: this.passwordNew2
|
|
|
|
|
}, {validator: passwordMatchValidator});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onPasswordInput() {
|
|
|
|
|
if (this.pwGroup.hasError('passwordMismatch'))
|
|
|
|
|
this.passwordNew2.setErrors([{'passwordMismatch': true}]);
|
|
|
|
|
else
|
|
|
|
|
this.passwordNew2.setErrors(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
login() {
|
|
|
|
@ -48,3 +63,10 @@ export class ProfileComponent implements OnInit {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const passwordMatchValidator: ValidatorFn = (formGroup: FormGroup): ValidationErrors | null => {
|
|
|
|
|
if (formGroup.get('passwordNew').value === formGroup.get('passwordNew2').value)
|
|
|
|
|
return null;
|
|
|
|
|
else
|
|
|
|
|
return {passwordMismatch: true};
|
|
|
|
|
};
|
|
|
|
|