add redirect after login (#1110)
This commit is contained in:
parent
9234069903
commit
ec769c89fd
|
@ -38,6 +38,7 @@ export class AuthService {
|
||||||
loginChangedSource: Observable<AuthStatus>
|
loginChangedSource: Observable<AuthStatus>
|
||||||
userInformationLoaded = new ReplaySubject<boolean>(1)
|
userInformationLoaded = new ReplaySubject<boolean>(1)
|
||||||
hotkeys: Hotkey[]
|
hotkeys: Hotkey[]
|
||||||
|
redirectUrl: string
|
||||||
|
|
||||||
private clientId: string = peertubeLocalStorage.getItem(AuthService.LOCAL_STORAGE_OAUTH_CLIENT_KEYS.CLIENT_ID)
|
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)
|
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.setStatus(AuthStatus.LoggedOut)
|
||||||
|
|
||||||
this.hotkeysService.remove(this.hotkeys)
|
this.hotkeysService.remove(this.hotkeys)
|
||||||
|
|
||||||
|
this.redirectUrl = null
|
||||||
}
|
}
|
||||||
|
|
||||||
refreshAccessToken () {
|
refreshAccessToken () {
|
||||||
|
|
|
@ -20,6 +20,8 @@ export class LoginGuard implements CanActivate, CanActivateChild {
|
||||||
canActivate (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
|
canActivate (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
|
||||||
if (this.auth.isLoggedIn() === true) return true
|
if (this.auth.isLoggedIn() === true) return true
|
||||||
|
|
||||||
|
this.auth.redirectUrl = state.url
|
||||||
|
|
||||||
this.router.navigate([ '/login' ])
|
this.router.navigate([ '/login' ])
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import { I18n } from '@ngx-translate/i18n-polyfill'
|
||||||
import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
|
import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
|
||||||
import { LoginValidatorsService } from '@app/shared/forms/form-validators/login-validators.service'
|
import { LoginValidatorsService } from '@app/shared/forms/form-validators/login-validators.service'
|
||||||
import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'
|
import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'
|
||||||
|
import { Router } from '@angular/router'
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'my-login',
|
selector: 'my-login',
|
||||||
|
@ -26,6 +27,7 @@ export class LoginComponent extends FormReactive implements OnInit {
|
||||||
private openedForgotPasswordModal: NgbModalRef
|
private openedForgotPasswordModal: NgbModalRef
|
||||||
|
|
||||||
constructor (
|
constructor (
|
||||||
|
public router: Router,
|
||||||
protected formValidatorService: FormValidatorService,
|
protected formValidatorService: FormValidatorService,
|
||||||
private modalService: NgbModal,
|
private modalService: NgbModal,
|
||||||
private loginValidatorsService: LoginValidatorsService,
|
private loginValidatorsService: LoginValidatorsService,
|
||||||
|
@ -59,7 +61,7 @@ export class LoginComponent extends FormReactive implements OnInit {
|
||||||
|
|
||||||
this.authService.login(username, password)
|
this.authService.login(username, password)
|
||||||
.subscribe(
|
.subscribe(
|
||||||
() => this.redirectService.redirectToHomepage(),
|
() => this.redirect(),
|
||||||
|
|
||||||
err => {
|
err => {
|
||||||
if (err.message.indexOf('credentials are invalid') !== -1) this.error = this.i18n('Incorrect username or password.')
|
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 () {
|
askResetPassword () {
|
||||||
this.userService.askResetPassword(this.forgotPasswordEmail)
|
this.userService.askResetPassword(this.forgotPasswordEmail)
|
||||||
.subscribe(
|
.subscribe(
|
||||||
|
|
Loading…
Reference in New Issue