forgot-password.component.ts 2.16 KB
Newer Older
Steven Zou's avatar
Steven Zou committed
1
import { Component, ViewChild } from '@angular/core';
kunw's avatar
kunw committed
2
import { Router } from '@angular/router';
Steven Zou's avatar
Steven Zou committed
3 4 5 6
import { NgForm } from '@angular/forms';

import { PasswordSettingService } from './password-setting.service';
import { InlineAlertComponent } from '../../shared/inline-alert/inline-alert.component';
kunw's avatar
kunw committed
7 8 9

@Component({
    selector: 'forgot-password',
Steven Zou's avatar
Steven Zou committed
10 11
    templateUrl: "forgot-password.component.html",
    styleUrls: ['password.component.css']
kunw's avatar
kunw committed
12 13
})
export class ForgotPasswordComponent {
Steven Zou's avatar
Steven Zou committed
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
    opened: boolean = false;
    private onGoing: boolean = false;
    private email: string = "";
    private validationState: boolean = true;
    private forceValid: boolean = true;

    @ViewChild("forgotPasswordFrom") forgotPwdForm: NgForm;
    @ViewChild(InlineAlertComponent)
    private inlineAlert: InlineAlertComponent;

    constructor(private pwdService: PasswordSettingService) { }

    public get showProgress(): boolean {
        return this.onGoing;
    }

    public get isValid(): boolean {
        return this.forgotPwdForm && this.forgotPwdForm.valid && this.forceValid;
    }

    public open(): void {
        this.opened = true;
        this.validationState = true;
        this.forceValid = true;
        this.forgotPwdForm.resetForm();
    }

    public close(): void {
        this.opened = false;
    }

    public send(): void {
        //Double confirm to avoid improper situations
        if (!this.email) {
            return;
        }

        if (!this.isValid) {
            return;
        }

        this.onGoing = true;
        this.pwdService.sendResetPasswordMail(this.email)
            .then(response => {
                this.onGoing = false;
                this.forceValid = false;//diable the send button
                this.inlineAlert.showInlineSuccess({
                    message: "RESET_PWD.SUCCESS"
                });
            })
            .catch(error => {
                this.onGoing = false;
                this.inlineAlert.showInlineError(error);
            })

    }

    public handleValidation(flag: boolean): void {
        if (flag) {
            this.validationState = true;
        } else {
            this.validationState = this.isValid;
        }
    }
kunw's avatar
kunw committed
78
}