aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/login/login.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/login/login.component.ts')
-rw-r--r--client/src/app/login/login.component.ts29
1 files changed, 9 insertions, 20 deletions
diff --git a/client/src/app/login/login.component.ts b/client/src/app/login/login.component.ts
index 7553e6456..fc2442c0e 100644
--- a/client/src/app/login/login.component.ts
+++ b/client/src/app/login/login.component.ts
@@ -1,7 +1,6 @@
1import { Component, ElementRef, OnInit, ViewChild } from '@angular/core' 1import { Component, ElementRef, OnInit, ViewChild } from '@angular/core'
2import { RedirectService, ServerService } from '@app/core' 2import { Notifier, RedirectService, ServerService } from '@app/core'
3import { UserService } from '@app/shared' 3import { UserService } from '@app/shared'
4import { NotificationsService } from 'angular2-notifications'
5import { AuthService } from '../core' 4import { AuthService } from '../core'
6import { FormReactive } from '../shared' 5import { FormReactive } from '../shared'
7import { I18n } from '@ngx-translate/i18n-polyfill' 6import { I18n } from '@ngx-translate/i18n-polyfill'
@@ -19,7 +18,6 @@ import { Router } from '@angular/router'
19export class LoginComponent extends FormReactive implements OnInit { 18export class LoginComponent extends FormReactive implements OnInit {
20 @ViewChild('emailInput') input: ElementRef 19 @ViewChild('emailInput') input: ElementRef
21 @ViewChild('forgotPasswordModal') forgotPasswordModal: ElementRef 20 @ViewChild('forgotPasswordModal') forgotPasswordModal: ElementRef
22 @ViewChild('forgotPasswordEmailInput') forgotPasswordEmailInput: ElementRef
23 21
24 error: string = null 22 error: string = null
25 forgotPasswordEmail = '' 23 forgotPasswordEmail = ''
@@ -35,7 +33,7 @@ export class LoginComponent extends FormReactive implements OnInit {
35 private userService: UserService, 33 private userService: UserService,
36 private serverService: ServerService, 34 private serverService: ServerService,
37 private redirectService: RedirectService, 35 private redirectService: RedirectService,
38 private notificationsService: NotificationsService, 36 private notifier: Notifier,
39 private i18n: I18n 37 private i18n: I18n
40 ) { 38 ) {
41 super() 39 super()
@@ -45,6 +43,10 @@ export class LoginComponent extends FormReactive implements OnInit {
45 return this.serverService.getConfig().signup.allowed === true 43 return this.serverService.getConfig().signup.allowed === true
46 } 44 }
47 45
46 isEmailDisabled () {
47 return this.serverService.getConfig().email.enabled === false
48 }
49
48 ngOnInit () { 50 ngOnInit () {
49 this.buildForm({ 51 this.buildForm({
50 username: this.loginValidatorsService.LOGIN_USERNAME, 52 username: this.loginValidatorsService.LOGIN_USERNAME,
@@ -61,7 +63,7 @@ export class LoginComponent extends FormReactive implements OnInit {
61 63
62 this.authService.login(username, password) 64 this.authService.login(username, password)
63 .subscribe( 65 .subscribe(
64 () => this.redirect(), 66 () => this.redirectService.redirectToPreviousRoute(),
65 67
66 err => { 68 err => {
67 if (err.message.indexOf('credentials are invalid') !== -1) this.error = this.i18n('Incorrect username or password.') 69 if (err.message.indexOf('credentials are invalid') !== -1) this.error = this.i18n('Incorrect username or password.')
@@ -71,15 +73,6 @@ export class LoginComponent extends FormReactive implements OnInit {
71 ) 73 )
72 } 74 }
73 75
74 redirect () {
75 const redirect = this.authService.redirectUrl
76 if (redirect) {
77 this.router.navigate([ redirect ])
78 } else {
79 this.redirectService.redirectToHomepage()
80 }
81 }
82
83 askResetPassword () { 76 askResetPassword () {
84 this.userService.askResetPassword(this.forgotPasswordEmail) 77 this.userService.askResetPassword(this.forgotPasswordEmail)
85 .subscribe( 78 .subscribe(
@@ -88,18 +81,14 @@ export class LoginComponent extends FormReactive implements OnInit {
88 'An email with the reset password instructions will be sent to {{email}}.', 81 'An email with the reset password instructions will be sent to {{email}}.',
89 { email: this.forgotPasswordEmail } 82 { email: this.forgotPasswordEmail }
90 ) 83 )
91 this.notificationsService.success(this.i18n('Success'), message) 84 this.notifier.success(message)
92 this.hideForgotPasswordModal() 85 this.hideForgotPasswordModal()
93 }, 86 },
94 87
95 err => this.notificationsService.error(this.i18n('Error'), err.message) 88 err => this.notifier.error(err.message)
96 ) 89 )
97 } 90 }
98 91
99 onForgotPasswordModalShown () {
100 this.forgotPasswordEmailInput.nativeElement.focus()
101 }
102
103 openForgotPasswordModal () { 92 openForgotPasswordModal () {
104 this.openedForgotPasswordModal = this.modalService.open(this.forgotPasswordModal) 93 this.openedForgotPasswordModal = this.modalService.open(this.forgotPasswordModal)
105 } 94 }