]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/login/login.component.ts
Merge branch 'develop' into unused-imports
[github/Chocobozzz/PeerTube.git] / client / src / app / login / login.component.ts
index 8e88225108d3c615fdd8b2d38b7e3a56a972ce70..7553e64564220907cf323ed7c88f1279893d28c5 100644 (file)
@@ -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,10 +71,19 @@ 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(
-        res => {
+        () => {
           const message = this.i18n(
             'An email with the reset password instructions will be sent to {{email}}.',
             { email: this.forgotPasswordEmail }