import { Component, OnInit, ViewChild } from '@angular/core'; import { AuthenticationService } from 'src/app/shared/services/authentication.service'; import { ActivatedRoute } from '@angular/router'; import { FeedbackPanelComponent } from 'src/app/shared/components/feedback-panel/feedback-panel.component'; @Component({ selector: 'app-forgottenpassword', templateUrl: './forgottenpassword.component.html', styleUrls: ['./forgottenpassword.component.css'], providers: [ AuthenticationService ] }) export class ForgottenpasswordComponent implements OnInit { @ViewChild('FeedbackPanel') FeedbackPanel:FeedbackPanelComponent; private _resetCode: string;; isWorking: boolean = false; ValidCode: boolean = false; reset_password: string; reset_password_confirm: string; constructor(private _route: ActivatedRoute, private _authentication: AuthenticationService) { } ngOnInit() { this._route.params.subscribe(params => { this.isWorking = true; this._resetCode = params["resetcode"]; this._authentication.validate_forgotten_password(this._resetCode) .then((result) => { this.ValidCode = result.result; this.isWorking = false; }) .catch((err) => { this.isWorking = false; this.FeedbackPanel.triggerError(err); }); }); }; submit() { if (this.isWorking) { return; } this.isWorking = true; this.FeedbackPanel.reset(); this._authentication.reset_password(this._resetCode, this.reset_password, this.reset_password_confirm) .then(() => { this.isWorking = false; this.FeedbackPanel.triggerSuccess("Your password has been successfully reset. You can now login.", false); }) .catch((err) => { this.isWorking = false; this.FeedbackPanel.triggerError(err); }); } }