From ecb4e35f4e6c7304cb274593c13cb47fd5078b75 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 30 Jan 2018 13:27:07 +0100 Subject: Add ability to reset our password --- client/src/app/login/login.component.ts | 37 +++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'client/src/app/login/login.component.ts') diff --git a/client/src/app/login/login.component.ts b/client/src/app/login/login.component.ts index e7c9c7226..22e8c77dd 100644 --- a/client/src/app/login/login.component.ts +++ b/client/src/app/login/login.component.ts @@ -1,7 +1,9 @@ -import { Component, OnInit } from '@angular/core' +import { Component, ElementRef, OnInit, ViewChild } from '@angular/core' import { FormBuilder, FormGroup, Validators } from '@angular/forms' import { Router } from '@angular/router' - +import { UserService } from '@app/shared' +import { NotificationsService } from 'angular2-notifications' +import { ModalDirective } from 'ngx-bootstrap/modal' import { AuthService } from '../core' import { FormReactive } from '../shared' @@ -12,6 +14,9 @@ import { FormReactive } from '../shared' }) export class LoginComponent extends FormReactive implements OnInit { + @ViewChild('forgotPasswordModal') forgotPasswordModal: ModalDirective + @ViewChild('forgotPasswordEmailInput') forgotPasswordEmailInput: ElementRef + error: string = null form: FormGroup @@ -27,9 +32,12 @@ export class LoginComponent extends FormReactive implements OnInit { 'required': 'Password is required.' } } + forgotPasswordEmail = '' constructor ( private authService: AuthService, + private userService: UserService, + private notificationsService: NotificationsService, private formBuilder: FormBuilder, private router: Router ) { @@ -60,4 +68,29 @@ export class LoginComponent extends FormReactive implements OnInit { err => this.error = err.message ) } + + askResetPassword () { + this.userService.askResetPassword(this.forgotPasswordEmail) + .subscribe( + res => { + const message = `An email with the reset password instructions will be sent to ${this.forgotPasswordEmail}.` + this.notificationsService.success('Success', message) + this.hideForgotPasswordModal() + }, + + err => this.notificationsService.error('Error', err.message) + ) + } + + onForgotPasswordModalShown () { + this.forgotPasswordEmailInput.nativeElement.focus() + } + + openForgotPasswordModal () { + this.forgotPasswordModal.show() + } + + hideForgotPasswordModal () { + this.forgotPasswordModal.hide() + } } -- cgit v1.2.3