]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
add redirect after login (#1110)
authorBO41 <lukasw41@gmail.com>
Sun, 23 Sep 2018 14:37:48 +0000 (16:37 +0200)
committerRigel Kent <par@rigelk.eu>
Sun, 23 Sep 2018 14:37:48 +0000 (16:37 +0200)
client/src/app/core/auth/auth.service.ts
client/src/app/core/routing/login-guard.service.ts
client/src/app/login/login.component.ts

index 88ea8963936017e3f14f4287ce3b2e334ac136f1..8ff5713a11805370047335b1024786c42a7afcf5 100644 (file)
@@ -38,6 +38,7 @@ export class AuthService {
   loginChangedSource: Observable<AuthStatus>
   userInformationLoaded = new ReplaySubject<boolean>(1)
   hotkeys: Hotkey[]
+  redirectUrl: string
 
   private clientId: string = peertubeLocalStorage.getItem(AuthService.LOCAL_STORAGE_OAUTH_CLIENT_KEYS.CLIENT_ID)
   private clientSecret: string = peertubeLocalStorage.getItem(AuthService.LOCAL_STORAGE_OAUTH_CLIENT_KEYS.CLIENT_SECRET)
@@ -177,6 +178,8 @@ export class AuthService {
     this.setStatus(AuthStatus.LoggedOut)
 
     this.hotkeysService.remove(this.hotkeys)
+
+    this.redirectUrl = null
   }
 
   refreshAccessToken () {
index 18bc41ca6301e9e8811f851dbd3c7cf256b33356..40ff8f5059491177fd9695e01ec22c675aed81cc 100644 (file)
@@ -20,6 +20,8 @@ export class LoginGuard implements CanActivate, CanActivateChild {
   canActivate (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
     if (this.auth.isLoggedIn() === true) return true
 
+    this.auth.redirectUrl = state.url
+
     this.router.navigate([ '/login' ])
     return false
   }
index 4bae3ae5c950b9347c9584ad406c401d13ec8a36..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',
@@ -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(