File

src/app/auth/reset-password/reset-password.component.ts

Implements

OnInit OnDestroy

Metadata

selector crm-reset-password
styleUrls reset-password.component.scss
templateUrl ./reset-password.component.html

Index

Properties
Methods

Constructor

constructor(formBuilder: FormBuilder, route: ActivatedRoute, authService: AuthService, notificationsService: NotificationsService, router: Router)
Parameters :
Name Type Optional Description
formBuilder FormBuilder
route ActivatedRoute
authService AuthService
notificationsService NotificationsService
router Router

Methods

Private formInit
formInit()
Returns : void
ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()
Returns : void
onSubmit
onSubmit()
Returns : void

Properties

changeValueSubscription
changeValueSubscription: Subscription
Type : Subscription
email
email: string
Type : string
hash
hash: string
Type : string
passIsEqual
passIsEqual: boolean
Type : boolean
Default value : false
querySubscription
querySubscription: Subscription
Type : Subscription
resetForm
resetForm: FormGroup
Type : FormGroup
showNotEqual
showNotEqual: boolean
Type : boolean
Default value : false
import {Component, OnInit, OnDestroy} from '@angular/core';
import {FormGroup, FormBuilder, Validators} from "@angular/forms";
import {ActivatedRoute, Router} from "@angular/router";
import {Subscription} from "rxjs";
import {AuthService} from "../../core/auth/auth.service";
import {NotificationsService} from "../../core/notifications/notifications.service";

@Component({
  selector: 'crm-reset-password',
  templateUrl: './reset-password.component.html',
  styleUrls: ['./reset-password.component.scss']
})
export class ResetPasswordComponent implements OnInit, OnDestroy {

  resetForm: FormGroup;
  querySubscription: Subscription;
  changeValueSubscription: Subscription;

  email: string;
  hash: string;

  passIsEqual: boolean = false;
  showNotEqual: boolean = false;

  constructor(private formBuilder: FormBuilder,
              private route: ActivatedRoute,
              private authService: AuthService,
              private notificationsService: NotificationsService,
              private router: Router) {
  }

  onSubmit() {
    const password = this.resetForm.value['pass'];
    this.authService.resetPassword(this.hash, password).subscribe(
      ok => {
        this.notificationsService.success('Password changed');
        this.router.navigate(['/'])
      },
      error => this.notificationsService.error(error.json())
    );
  }

  ngOnInit() {
    this.formInit();
    this.querySubscription = this.route.queryParams.subscribe(params => {
      this.email = params['email'];
      this.hash = params['hash'];
    });

    this.changeValueSubscription = this.resetForm.valueChanges.subscribe(value => {
      this.passIsEqual = value.pass === value.repeat && value.pass.length > 0;
      this.showNotEqual = !this.passIsEqual && value.repeat.length > 0;
    });
  }

  ngOnDestroy() {
    this.querySubscription.unsubscribe();
    this.changeValueSubscription.unsubscribe();
  }

  private formInit() {
    this.resetForm = this.formBuilder.group({
      pass: ['', [Validators.required, Validators.minLength(6)]],
      repeat: ['', Validators.required]
    });
  }

}
<div class="app flex-row align-items-center">
  <div class="container">
    <div class="row justify-content-center">
      <div class="col-md-6">
        <div class="card mx-2">
          <div class="card-block p-2">
            <h1>Reset password</h1>
            <p class="text-muted">Reset password for email: {{email}}</p>

            <form [formGroup]="resetForm" (ngSubmit)="onSubmit()">
              <small *ngIf="resetForm.controls.pass.dirty && resetForm.controls.pass.errors" class="form-text text-danger">
                Password must be at least 6 characters</small>

              <div class="input-group mb-1">
                            <span class="input-group-addon"><i class="icon-lock"></i>
                            </span>
                <input type="password" class="form-control" placeholder="Password" formControlName="pass">
              </div>

              <small class="form-text text-danger" *ngIf="showNotEqual">Passwords do not match!</small>
              <div class="input-group mb-2">
                            <span class="input-group-addon"><i class="icon-lock"></i>
                            </span>
                <input type="password" class="form-control" placeholder="Repeat password" formControlName="repeat">
              </div>

              <button type="submit" class="btn btn-block btn-success" [disabled]="!resetForm.valid || !passIsEqual">
                Reset password
              </button>
            </form>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""