Broker System for Supercredit
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.7KB

  1. import {Component, Input, OnInit, ViewChild} from '@angular/core';
  2. import {FormControl, FormGroup} from '@angular/forms';
  3. import {AuthService} from '../../service/auth.service';
  4. import {PeopleService} from '../../service/people.service';
  5. import {MessageBoxComponent} from '../../message-box/message-box.component';
  6. @Component({
  7. selector: 'app-change-password',
  8. templateUrl: './change-password.component.html',
  9. styleUrls: ['./change-password.component.scss']
  10. })
  11. export class ChangePasswordComponent implements OnInit {
  12. @Input() PeopleId = '';
  13. @ViewChild('messageBox', {static: true}) msgBox: MessageBoxComponent;
  14. public changePassword = false;
  15. public ChangePassForm: FormGroup = new FormGroup({
  16. OldPassword: new FormControl(),
  17. NewPass: new FormControl(),
  18. NewPass1: new FormControl(),
  19. });
  20. constructor(private auth: AuthService, private ps: PeopleService) { }
  21. ngOnInit(): void {
  22. }
  23. public hidePass(): void{
  24. if ( this.changePassword ) {
  25. this.ChangePassForm.reset();
  26. }
  27. }
  28. public savePassword(): void{
  29. this.ps.savePassword('0', this.ChangePassForm.value).subscribe(
  30. () => {
  31. this.changePassword = false;
  32. this.msgBox.Show('Password Changed');
  33. }, err => {
  34. this.msgBox.Show('Failed to Change Password :' + err.toString());
  35. }
  36. );
  37. }
  38. public passwordEqual(): boolean{
  39. const v = this.ChangePassForm.value;
  40. if ( this.ChangePassForm.valid && v.NewPass === v.NewPass1 && this.ChangePassForm.touched && v.NewPass1 !== '') {
  41. return true;
  42. }else{
  43. this.ChangePassForm.get('NewPass1').setErrors({incorrect: true});
  44. }
  45. return false;
  46. }
  47. public canChangePassword(): boolean {
  48. return this.auth.isBroker() || this.auth.isAdmin();
  49. }
  50. }