diff options
Diffstat (limited to 'client/src/app/core')
-rw-r--r-- | client/src/app/core/auth/auth.service.ts | 10 | ||||
-rw-r--r-- | client/src/app/core/routing/login-guard.service.ts | 9 | ||||
-rw-r--r-- | client/src/app/core/routing/redirect.service.ts | 9 | ||||
-rw-r--r-- | client/src/app/core/routing/user-right-guard.service.ts | 7 |
4 files changed, 22 insertions, 13 deletions
diff --git a/client/src/app/core/auth/auth.service.ts b/client/src/app/core/auth/auth.service.ts index ed7eabb76..6fe601d8d 100644 --- a/client/src/app/core/auth/auth.service.ts +++ b/client/src/app/core/auth/auth.service.ts | |||
@@ -5,11 +5,11 @@ import { HttpClient, HttpErrorResponse, HttpHeaders, HttpParams } from '@angular | |||
5 | import { Injectable } from '@angular/core' | 5 | import { Injectable } from '@angular/core' |
6 | import { Router } from '@angular/router' | 6 | import { Router } from '@angular/router' |
7 | import { Notifier } from '@app/core/notification/notifier.service' | 7 | import { Notifier } from '@app/core/notification/notifier.service' |
8 | import { logger, OAuthUserTokens, objectToUrlEncoded, peertubeLocalStorage, PluginsManager } from '@root-helpers/index' | 8 | import { logger, OAuthUserTokens, objectToUrlEncoded, peertubeLocalStorage } from '@root-helpers/index' |
9 | import { HttpStatusCode, MyUser as UserServerModel, OAuthClientLocal, User, UserLogin, UserRefreshToken } from '@shared/models' | 9 | import { HttpStatusCode, MyUser as UserServerModel, OAuthClientLocal, User, UserLogin, UserRefreshToken } from '@shared/models' |
10 | import { environment } from '../../../environments/environment' | 10 | import { environment } from '../../../environments/environment' |
11 | import { RestExtractor } from '../rest/rest-extractor.service' | 11 | import { RestExtractor } from '../rest/rest-extractor.service' |
12 | import { ServerService } from '../server' | 12 | import { RedirectService } from '../routing' |
13 | import { AuthStatus } from './auth-status.model' | 13 | import { AuthStatus } from './auth-status.model' |
14 | import { AuthUser } from './auth-user.model' | 14 | import { AuthUser } from './auth-user.model' |
15 | 15 | ||
@@ -45,7 +45,7 @@ export class AuthService { | |||
45 | private refreshingTokenObservable: Observable<any> | 45 | private refreshingTokenObservable: Observable<any> |
46 | 46 | ||
47 | constructor ( | 47 | constructor ( |
48 | private serverService: ServerService, | 48 | private redirectService: RedirectService, |
49 | private http: HttpClient, | 49 | private http: HttpClient, |
50 | private notifier: Notifier, | 50 | private notifier: Notifier, |
51 | private hotkeysService: HotkeysService, | 51 | private hotkeysService: HotkeysService, |
@@ -227,9 +227,7 @@ Ensure you have correctly configured PeerTube (config/ directory), in particular | |||
227 | logger.info('Cannot refresh token -> logout...') | 227 | logger.info('Cannot refresh token -> logout...') |
228 | this.logout() | 228 | this.logout() |
229 | 229 | ||
230 | const externalLoginUrl = PluginsManager.getDefaultLoginHref(environment.apiUrl, this.serverService.getHTMLConfig()) | 230 | this.redirectService.redirectToLogin() |
231 | if (externalLoginUrl) window.location.href = externalLoginUrl | ||
232 | else this.router.navigate([ '/login' ]) | ||
233 | 231 | ||
234 | return observableThrowError(() => ({ | 232 | return observableThrowError(() => ({ |
235 | error: $localize`You need to reconnect.` | 233 | error: $localize`You need to reconnect.` |
diff --git a/client/src/app/core/routing/login-guard.service.ts b/client/src/app/core/routing/login-guard.service.ts index a949be14c..2f5a31e7f 100644 --- a/client/src/app/core/routing/login-guard.service.ts +++ b/client/src/app/core/routing/login-guard.service.ts | |||
@@ -1,19 +1,20 @@ | |||
1 | import { Injectable } from '@angular/core' | 1 | import { Injectable } from '@angular/core' |
2 | import { ActivatedRouteSnapshot, CanActivate, CanActivateChild, Router, RouterStateSnapshot } from '@angular/router' | 2 | import { ActivatedRouteSnapshot, CanActivate, CanActivateChild, RouterStateSnapshot } from '@angular/router' |
3 | import { AuthService } from '../auth/auth.service' | 3 | import { AuthService } from '../auth/auth.service' |
4 | import { RedirectService } from './redirect.service' | ||
4 | 5 | ||
5 | @Injectable() | 6 | @Injectable() |
6 | export class LoginGuard implements CanActivate, CanActivateChild { | 7 | export class LoginGuard implements CanActivate, CanActivateChild { |
7 | 8 | ||
8 | constructor ( | 9 | constructor ( |
9 | private router: Router, | 10 | private auth: AuthService, |
10 | private auth: AuthService | 11 | private redirectService: RedirectService |
11 | ) {} | 12 | ) {} |
12 | 13 | ||
13 | canActivate (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) { | 14 | canActivate (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) { |
14 | if (this.auth.isLoggedIn() === true) return true | 15 | if (this.auth.isLoggedIn() === true) return true |
15 | 16 | ||
16 | this.router.navigate([ '/login' ]) | 17 | this.redirectService.redirectToLogin() |
17 | return false | 18 | return false |
18 | } | 19 | } |
19 | 20 | ||
diff --git a/client/src/app/core/routing/redirect.service.ts b/client/src/app/core/routing/redirect.service.ts index 1344458d5..e239c6210 100644 --- a/client/src/app/core/routing/redirect.service.ts +++ b/client/src/app/core/routing/redirect.service.ts | |||
@@ -4,6 +4,8 @@ import { NavigationCancel, NavigationEnd, Router } from '@angular/router' | |||
4 | import { logger } from '@root-helpers/logger' | 4 | import { logger } from '@root-helpers/logger' |
5 | import { ServerService } from '../server' | 5 | import { ServerService } from '../server' |
6 | import { SessionStorageService } from '../wrappers/storage.service' | 6 | import { SessionStorageService } from '../wrappers/storage.service' |
7 | import { PluginsManager } from '@root-helpers/plugins-manager' | ||
8 | import { environment } from 'src/environments/environment' | ||
7 | 9 | ||
8 | const debugLogger = debug('peertube:router:RedirectService') | 10 | const debugLogger = debug('peertube:router:RedirectService') |
9 | 11 | ||
@@ -100,6 +102,13 @@ export class RedirectService { | |||
100 | 102 | ||
101 | } | 103 | } |
102 | 104 | ||
105 | redirectToLogin () { | ||
106 | const externalLoginUrl = PluginsManager.getDefaultLoginHref(environment.apiUrl, this.serverService.getHTMLConfig()) | ||
107 | |||
108 | if (externalLoginUrl) window.location.href = externalLoginUrl | ||
109 | else this.router.navigate([ '/login' ]) | ||
110 | } | ||
111 | |||
103 | private doRedirect (redirectUrl: string, fallbackRoute?: string) { | 112 | private doRedirect (redirectUrl: string, fallbackRoute?: string) { |
104 | debugLogger('Redirecting on %s', redirectUrl) | 113 | debugLogger('Redirecting on %s', redirectUrl) |
105 | 114 | ||
diff --git a/client/src/app/core/routing/user-right-guard.service.ts b/client/src/app/core/routing/user-right-guard.service.ts index a2ce772db..c6bd05bb6 100644 --- a/client/src/app/core/routing/user-right-guard.service.ts +++ b/client/src/app/core/routing/user-right-guard.service.ts | |||
@@ -1,12 +1,13 @@ | |||
1 | import { Injectable } from '@angular/core' | 1 | import { Injectable } from '@angular/core' |
2 | import { ActivatedRouteSnapshot, CanActivate, CanActivateChild, Router, RouterStateSnapshot } from '@angular/router' | 2 | import { ActivatedRouteSnapshot, CanActivate, CanActivateChild, RouterStateSnapshot } from '@angular/router' |
3 | import { AuthService } from '../auth/auth.service' | 3 | import { AuthService } from '../auth/auth.service' |
4 | import { RedirectService } from './redirect.service' | ||
4 | 5 | ||
5 | @Injectable() | 6 | @Injectable() |
6 | export class UserRightGuard implements CanActivate, CanActivateChild { | 7 | export class UserRightGuard implements CanActivate, CanActivateChild { |
7 | 8 | ||
8 | constructor ( | 9 | constructor ( |
9 | private router: Router, | 10 | private redirectService: RedirectService, |
10 | private auth: AuthService | 11 | private auth: AuthService |
11 | ) {} | 12 | ) {} |
12 | 13 | ||
@@ -18,7 +19,7 @@ export class UserRightGuard implements CanActivate, CanActivateChild { | |||
18 | if (user.hasRight(neededUserRight)) return true | 19 | if (user.hasRight(neededUserRight)) return true |
19 | } | 20 | } |
20 | 21 | ||
21 | this.router.navigate([ '/login' ]) | 22 | this.redirectService.redirectToLogin() |
22 | return false | 23 | return false |
23 | } | 24 | } |
24 | 25 | ||