File

src/app/userModule/password/password.component.ts

Metadata

selector pnx-user-password
styleUrls password.component.scss
templateUrl password.component.html

Constructor

constructor(fb: any, router: any, userService: UserDataService, _toasterService: any)

Methods

initForm
initForm()
Returns: void
save
save()
Returns: void

Properties

form
form: any
import { Component, OnInit } from '@angular/core';
import {
  UntypedFormGroup,
  UntypedFormBuilder,
  Validators,
  ValidatorFn,
  AbstractControl,
} from '@angular/forms';
import { Router } from '@angular/router';
import { UserDataService } from '../services/user-data.service';
import { ToastrService, ToastrConfig } from 'ngx-toastr';
import { similarValidator } from '@geonature/services/validators';

@Component({
  selector: 'pnx-user-password',
  templateUrl: './password.component.html',
  styleUrls: ['./password.component.scss'],
})
export class PasswordComponent implements OnInit {
  form: UntypedFormGroup;

  constructor(
    private fb: UntypedFormBuilder,
    private router: Router,
    private userService: UserDataService,
    private _toasterService: ToastrService
  ) {}

  ngOnInit() {
    this.initForm();
  }

  initForm() {
    this.form = this.fb.group({
      init_password: ['', Validators.required],
      password: ['', Validators.required],
      password_confirmation: ['', Validators.required],
    });
    this.form.setValidators([similarValidator('password', 'password_confirmation')]);
  }

  save() {
    if (this.form.valid) {
      this.userService.putPassword(this.form.value).subscribe(
        (res) => {
          this._toasterService.info(res.msg, '', {
            positionClass: 'toast-top-center',
            tapToDismiss: true,
            timeOut: 5000,
          });
          this.router.navigate(['/user']);
        },
        (error) => {
          this._toasterService.error(error.error.msg, '');
        }
      );
    }
  }
}

results matching ""

    No results matching ""