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.

65 lines
1.7KB

  1. import { Component, OnInit } from '@angular/core';
  2. import {AuthService} from '../service/auth.service';
  3. import {PeopleService} from '../service/people.service';
  4. import {FormControl, FormGroup} from '@angular/forms';
  5. @Component({
  6. selector: 'app-settings',
  7. templateUrl: './settings.component.html',
  8. styleUrls: ['./settings.component.scss']
  9. })
  10. export class SettingsComponent implements OnInit {
  11. public changeAdminPassword = false;
  12. public opened = false; // dialog box
  13. public Message = ''; // dialog message
  14. public ChangeAdminPassForm: FormGroup = new FormGroup({
  15. OldPassword: new FormControl(),
  16. NewPass: new FormControl(),
  17. NewPass1: new FormControl(),
  18. });
  19. constructor(private auth: AuthService, private ps: PeopleService) { }
  20. ngOnInit(): void {
  21. setTimeout(() => {
  22. this.changeAdminPassword = true;
  23. }, 1000);
  24. }
  25. public hideAdminPass(): void{
  26. if ( this.changeAdminPassword ) {
  27. this.ChangeAdminPassForm.reset();
  28. }
  29. }
  30. public saveAdminPassword(): void{
  31. this.ps.savePassword('0', this.ChangeAdminPassForm.value).subscribe(
  32. () => {
  33. this.showDialog('Password Changed');
  34. }, err => {
  35. this.showDialog('Failed to Change Password :' + err.toString());
  36. }
  37. );
  38. }
  39. public adminPasswordEqual(): boolean{
  40. const v = this.ChangeAdminPassForm.value;
  41. if ( this.ChangeAdminPassForm.valid && v.NewPass === v.NewPass1 && this.ChangeAdminPassForm.touched && v.NewPass1 !== '') {
  42. return true;
  43. }else{
  44. this.ChangeAdminPassForm.controls['NewPass1'].setErrors({'incorrect': true});
  45. }
  46. return false;
  47. }
  48. public showDialog(msg: string): void {
  49. this.Message = msg;
  50. this.opened = true; // open dialog
  51. }
  52. public close(status): void {
  53. this.opened = false;
  54. }
  55. }