From ec769c89fdcbcaf2d15de8d211d3ede3b6f69c1a Mon Sep 17 00:00:00 2001 From: BO41 Date: Sun, 23 Sep 2018 16:37:48 +0200 Subject: add redirect after login (#1110) --- client/src/app/login/login.component.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (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 4bae3ae5c..7553e6456 100644 --- a/client/src/app/login/login.component.ts +++ b/client/src/app/login/login.component.ts @@ -8,6 +8,7 @@ import { I18n } from '@ngx-translate/i18n-polyfill' import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' import { LoginValidatorsService } from '@app/shared/forms/form-validators/login-validators.service' import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap' +import { Router } from '@angular/router' @Component({ selector: 'my-login', @@ -26,6 +27,7 @@ export class LoginComponent extends FormReactive implements OnInit { private openedForgotPasswordModal: NgbModalRef constructor ( + public router: Router, protected formValidatorService: FormValidatorService, private modalService: NgbModal, private loginValidatorsService: LoginValidatorsService, @@ -59,7 +61,7 @@ export class LoginComponent extends FormReactive implements OnInit { this.authService.login(username, password) .subscribe( - () => this.redirectService.redirectToHomepage(), + () => this.redirect(), err => { if (err.message.indexOf('credentials are invalid') !== -1) this.error = this.i18n('Incorrect username or password.') @@ -69,6 +71,15 @@ export class LoginComponent extends FormReactive implements OnInit { ) } + redirect () { + const redirect = this.authService.redirectUrl + if (redirect) { + this.router.navigate([ redirect ]) + } else { + this.redirectService.redirectToHomepage() + } + } + askResetPassword () { this.userService.askResetPassword(this.forgotPasswordEmail) .subscribe( -- cgit v1.2.3