X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Flogin%2Flogin.component.ts;h=7553e64564220907cf323ed7c88f1279893d28c5;hb=791645e620fb98c6e7c32271d91d91ff7e41b892;hp=7c02208859508562344d9911ddbb19a58ea73655;hpb=141b177db088891e84040f68aa95008fb52f1d44;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/login/login.component.ts b/client/src/app/login/login.component.ts index 7c0220885..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', @@ -16,6 +17,7 @@ import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap' }) export class LoginComponent extends FormReactive implements OnInit { + @ViewChild('emailInput') input: ElementRef @ViewChild('forgotPasswordModal') forgotPasswordModal: ElementRef @ViewChild('forgotPasswordEmailInput') forgotPasswordEmailInput: ElementRef @@ -25,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, @@ -47,6 +50,8 @@ export class LoginComponent extends FormReactive implements OnInit { username: this.loginValidatorsService.LOGIN_USERNAME, password: this.loginValidatorsService.LOGIN_PASSWORD }) + + this.input.nativeElement.focus() } login () { @@ -56,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.') @@ -66,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(