Files
SkydiveLogs/Front/skydivelogs-app/src/app/user-profile/user-profile.component.ts
2021-03-18 16:32:10 +01:00

60 lines
1.7 KiB
TypeScript

import { Component, OnInit } from '@angular/core';
import { FormGroup, FormControl, Validators } from '@angular/forms';
import { AuthenticationService } from '../../services/authentication.service';
import { User } from '../../models/user';
@Component({
selector: 'app-user-profile',
templateUrl: './user-profile.component.html',
styleUrls: ['./user-profile.component.css'],
})
export class UserProfileComponent implements OnInit {
public userForm: FormGroup;
constructor(private authenticationService: AuthenticationService) { }
ngOnInit(): void {
const currentUser = this.authenticationService.currentUserValue;
this.userForm = new FormGroup(
{
login: new FormControl(currentUser.login, Validators.required),
firstName: new FormControl(currentUser.firstName, [
Validators.required,
Validators.minLength(3),
]),
lastName: new FormControl(currentUser.lastName, [
Validators.required,
Validators.minLength(3),
]),
email: new FormControl(currentUser.email, [
Validators.required,
Validators.email,
]),
currentPassword: new FormControl(
'',
Validators.pattern('^[A-Za-z0-9_-]{8,15}$')
),
newPassword: new FormControl(
'',
Validators.pattern('^[A-Za-z0-9_-]{8,15}$')
),
},
{ updateOn: 'blur' }
);
}
onSubmit(formData) {
if (this.userForm.invalid) {
return;
}
// const updatedUser = new User();
// updatedUser.firstName = formData.firstName;
// updatedUser.lastName = formData.lastName;
// updatedUser.email = formData.email;
// this.authenticationService.update(updatedUser);
}
}