import { FormGroup, FormBuilder, Validators, NgForm } from '@angular/forms'; import { Component, OnInit } from '@angular/core'; import { LoginService, LgnGirisPasswordChange } from '@karmed/api'; import { MessageService } from '@karmed/core'; @Component({ selector: 'app-user-settings', templateUrl: './user-settings.component.html', styleUrls: ['./user-settings.component.css'] }) export class UserSettingsComponent implements OnInit { updatePasswordForm: FormGroup; submitted = false; constructor(private formBuilder: FormBuilder, private login: LoginService, private messageService: MessageService) { } ngOnInit() { this.updatePasswordForm = this.formBuilder.group({ eskiParola: ['', Validators.required], yeniParola: ['', Validators.required], yeniParolaTekrar: ['', Validators.required] }, { validator: this.MustMatch('yeniParola', 'yeniParolaTekrar') }); } onSubmit() { if (this.updatePasswordForm.invalid) return; this.submitted = true; let giris = new LgnGirisPasswordChange(); giris.NewPassword = this.updatePasswordForm.value.yeniParola; giris.OldPassword = this.updatePasswordForm.value.eskiParola; this.login.pwdUpdate(giris).subscribe(res => { if (res.Islem) this.messageService.success(res.Aciklama); else this.messageService.error(res.HataMesaji); }) } parolaTekrarKontrol(yeniParola: string, yeniParolaTekrar: string): boolean { return yeniParola !== yeniParolaTekrar; } private MustMatch(controlName: string, matchingControlName: string) { return (formGroup: FormGroup) => { const control = formGroup.controls[controlName]; const matchingControl = formGroup.controls[matchingControlName]; if (matchingControl.errors && !matchingControl.errors.mustMatch) { return; } if (control.value !== matchingControl.value) { matchingControl.setErrors({ mustMatch: true }); } else { matchingControl.setErrors(null); } } } }