]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Client: check user is logged in for some pages
authorChocobozzz <florian.bigard@gmail.com>
Tue, 10 Oct 2017 08:18:25 +0000 (10:18 +0200)
committerChocobozzz <florian.bigard@gmail.com>
Tue, 10 Oct 2017 08:24:02 +0000 (10:24 +0200)
client/src/app/+admin/admin-guard.service.ts
client/src/app/account/account-routing.module.ts
client/src/app/core/auth/index.ts
client/src/app/core/auth/login-guard.service.ts [new file with mode: 0644]
client/src/app/core/core.module.ts
client/src/app/core/menu/menu.component.html
client/src/app/videos/+video-edit/video-add-routing.module.ts
client/src/app/videos/+video-edit/video-update-routing.module.ts
client/src/app/videos/+video-watch/video-watch-routing.module.ts
client/src/app/videos/videos-routing.module.ts

index a0ad4817562bdbfa9e6d5f1be5964576eb8a593e..429dc032db78c9bf2febe5cdcd2b75fc3158af64 100644 (file)
@@ -3,7 +3,8 @@ import {
   ActivatedRouteSnapshot,
   CanActivateChild,
   RouterStateSnapshot,
-  CanActivate
+  CanActivate,
+  Router
 } from '@angular/router'
 
 import { AuthService } from '../core'
@@ -11,10 +12,16 @@ import { AuthService } from '../core'
 @Injectable()
 export class AdminGuard implements CanActivate, CanActivateChild {
 
-  constructor (private auth: AuthService) {}
+  constructor (
+    private router: Router,
+    private auth: AuthService
+  ) {}
 
   canActivate (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
-    return this.auth.isAdmin()
+    if (this.auth.isAdmin() === true) return true
+
+    this.router.navigate([ '/login' ])
+    return false
   }
 
   canActivateChild (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
index 029d9778882907b92a2bb2abab033ca950a16f2e..74d9aa03e6abb0e21a3786a83888b0a82142a709 100644 (file)
@@ -3,13 +3,14 @@ import { RouterModule, Routes } from '@angular/router'
 
 import { MetaGuard } from '@ngx-meta/core'
 
+import { LoginGuard } from '../core'
 import { AccountComponent } from './account.component'
 
 const accountRoutes: Routes = [
   {
     path: 'account',
     component: AccountComponent,
-    canActivate: [ MetaGuard ],
+    canActivate: [ MetaGuard, LoginGuard ],
     data: {
       meta: {
         title: 'My account'
index 8e5caa7ed23d00a8127b7ed886e6561cc8766463..a81f2c0021b6836c28937cd64249eeeb904dbe3d 100644 (file)
@@ -1,3 +1,4 @@
 export * from './auth-status.model'
 export * from './auth-user.model'
 export * from './auth.service'
+export * from './login-guard.service'
diff --git a/client/src/app/core/auth/login-guard.service.ts b/client/src/app/core/auth/login-guard.service.ts
new file mode 100644 (file)
index 0000000..c09e8fe
--- /dev/null
@@ -0,0 +1,30 @@
+import { Injectable } from '@angular/core'
+import {
+  ActivatedRouteSnapshot,
+  CanActivateChild,
+  RouterStateSnapshot,
+  CanActivate,
+  Router
+} from '@angular/router'
+
+import { AuthService } from './auth.service'
+
+@Injectable()
+export class LoginGuard implements CanActivate, CanActivateChild {
+
+  constructor (
+    private router: Router,
+    private auth: AuthService
+  ) {}
+
+  canActivate (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
+    if (this.auth.isLoggedIn() === true) return true
+
+    this.router.navigate([ '/login' ])
+    return false
+  }
+
+  canActivateChild (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
+    return this.canActivate(route, state)
+  }
+}
index fd1586f8e48e6153ccef44cfc2dcee68b8fb37c8..163a6bbde9e5299084733057bc7d5103ab8364af 100644 (file)
@@ -7,7 +7,7 @@ import { BrowserAnimationsModule } from '@angular/platform-browser/animations'
 import { SimpleNotificationsModule } from 'angular2-notifications'
 import { ModalModule } from 'ngx-bootstrap/modal'
 
-import { AuthService } from './auth'
+import { AuthService, LoginGuard } from './auth'
 import { ServerService } from './server'
 import { ConfirmComponent, ConfirmService } from './confirm'
 import { MenuComponent, MenuAdminComponent } from './menu'
@@ -41,7 +41,8 @@ import { throwIfAlreadyLoaded } from './module-import-guard'
   providers: [
     AuthService,
     ConfirmService,
-    ServerService
+    ServerService,
+    LoginGuard
   ]
 })
 export class CoreModule {
index fb4c4a6a9a5b7a97e1f437321cf4905320dcd0ae..ca341a0fd193bcb6075f0b04159719d334236de5 100644 (file)
@@ -33,7 +33,7 @@
       See videos
     </a>
 
-    <a *ngIf="isLoggedIn" routerLink="/videos/add" routerLinkActive="active">
+    <a *ngIf="isLoggedIn" routerLink="/videos/upload" routerLinkActive="active">
       <span class="hidden-xs glyphicon glyphicon-cloud-upload"></span>
       Upload a video
     </a>
index 9e8fa4acc1eafc0c3da1974888ef404f50ddaf9c..e7a32627c50dd350ea55e223cbc4b6a65c9eab56 100644 (file)
@@ -3,13 +3,14 @@ import { RouterModule, Routes } from '@angular/router'
 
 import { MetaGuard } from '@ngx-meta/core'
 
+import { LoginGuard } from '../../core'
 import { VideoAddComponent } from './video-add.component'
 
 const videoAddRoutes: Routes = [
   {
     path: '',
     component: VideoAddComponent,
-    canActivateChild: [ MetaGuard ]
+    canActivate: [ MetaGuard, LoginGuard ]
   }
 ]
 
index 1d06a7ac3243ade492a3e6616477caa7730184d9..22c27a072938b93dd7341589ef7a9398f80b481f 100644 (file)
@@ -3,13 +3,14 @@ import { RouterModule, Routes } from '@angular/router'
 
 import { MetaGuard } from '@ngx-meta/core'
 
+import { LoginGuard } from '../../core'
 import { VideoUpdateComponent } from './video-update.component'
 
 const videoUpdateRoutes: Routes = [
   {
     path: '',
     component: VideoUpdateComponent,
-    canActivateChild: [ MetaGuard ]
+    canActivate: [ MetaGuard, LoginGuard ]
   }
 ]
 
index 97fa5c72512f58da12d247ccd87e840168312cc1..bdd4f945e86798baab1434bcc0b6b8aa6386ebe9 100644 (file)
@@ -9,7 +9,7 @@ const videoWatchRoutes: Routes = [
   {
     path: '',
     component: VideoWatchComponent,
-    canActivateChild: [ MetaGuard ]
+    canActivate: [ MetaGuard ]
   }
 ]
 
index 225b6b018abc02bfb50dbf627b2d9f7069846cfe..d3869748bb42554ceedd0ab75f86a59f00473fa6 100644 (file)
@@ -22,11 +22,11 @@ const videosRoutes: Routes = [
         }
       },
       {
-        path: 'add',
+        path: 'upload',
         loadChildren: 'app/videos/+video-edit#VideoAddModule',
         data: {
           meta: {
-            title: 'Add a video'
+            title: 'Upload a video'
           }
         }
       },