mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-09 03:04:20 -04:00
Adding a protected account page and an unauthorized page
This commit is contained in:
parent
b1aae349fd
commit
8507a2a3cd
1
src/app/account/account.component.html
Normal file
1
src/app/account/account.component.html
Normal file
@ -0,0 +1 @@
|
|||||||
|
<p>account works!</p>
|
0
src/app/account/account.component.scss
Normal file
0
src/app/account/account.component.scss
Normal file
15
src/app/account/account.component.ts
Normal file
15
src/app/account/account.component.ts
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-account',
|
||||||
|
templateUrl: './account.component.html',
|
||||||
|
styleUrls: ['./account.component.scss']
|
||||||
|
})
|
||||||
|
export class AccountComponent implements OnInit {
|
||||||
|
|
||||||
|
constructor() { }
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -13,6 +13,9 @@ import { ShowResolverService } from './services/show-resolver.service';
|
|||||||
import { StreamResolverService } from "./services/stream-resolver.service";
|
import { StreamResolverService } from "./services/stream-resolver.service";
|
||||||
import { ShowDetailsComponent } from './show-details/show-details.component';
|
import { ShowDetailsComponent } from './show-details/show-details.component';
|
||||||
import {LoginComponent} from "./login/login.component";
|
import {LoginComponent} from "./login/login.component";
|
||||||
|
import {AccountComponent} from "./account/account.component";
|
||||||
|
import {AuthenticatedGuard} from "./guards/authenticated-guard.service";
|
||||||
|
import {UnauthorizedComponent} from "./unauthorized/unauthorized.component";
|
||||||
|
|
||||||
const routes: Routes = [
|
const routes: Routes = [
|
||||||
{ path: "browse", component: BrowseComponent, pathMatch: "full", resolve: { shows: LibraryResolverService } },
|
{ path: "browse", component: BrowseComponent, pathMatch: "full", resolve: { shows: LibraryResolverService } },
|
||||||
@ -23,6 +26,8 @@ const routes: Routes = [
|
|||||||
{ path: "watch/:item", component: PlayerComponent, resolve: { item: StreamResolverService } },
|
{ path: "watch/:item", component: PlayerComponent, resolve: { item: StreamResolverService } },
|
||||||
{ path: "search/:query", component: SearchComponent, resolve: { items: SearchResolverService } },
|
{ path: "search/:query", component: SearchComponent, resolve: { items: SearchResolverService } },
|
||||||
{ path: "login", component: LoginComponent },
|
{ path: "login", component: LoginComponent },
|
||||||
|
{ path: "account", component: AccountComponent, canActivate: [AuthenticatedGuard], canLoad: [AuthenticatedGuard] },
|
||||||
|
{ path: "unauthorized", component: UnauthorizedComponent },
|
||||||
{ path: "**", component: NotFoundComponent }
|
{ path: "**", component: NotFoundComponent }
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
<mat-menu #accountMenu="matMenu">
|
<mat-menu #accountMenu="matMenu">
|
||||||
<button mat-menu-item>Settings</button>
|
<a class="link" mat-menu-item href="/account" routerLink="/account">Settings</a>
|
||||||
<button mat-menu-item (click)="this.authManager.logout()">Logout</button>
|
<button mat-menu-item (click)="this.authManager.logout()">Logout</button>
|
||||||
</mat-menu>
|
</mat-menu>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
|
@ -18,6 +18,17 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.link
|
||||||
|
{
|
||||||
|
outline: none;
|
||||||
|
color: inherit;
|
||||||
|
|
||||||
|
&:hover
|
||||||
|
{
|
||||||
|
text-decoration: none !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.nav-link
|
.nav-link
|
||||||
{
|
{
|
||||||
padding: 12px;
|
padding: 12px;
|
||||||
|
@ -37,6 +37,9 @@ import {
|
|||||||
OidcSecurityService,
|
OidcSecurityService,
|
||||||
OpenIdConfiguration
|
OpenIdConfiguration
|
||||||
} from "angular-auth-oidc-client";
|
} from "angular-auth-oidc-client";
|
||||||
|
import { AccountComponent } from './account/account.component';
|
||||||
|
import {AuthenticatedGuard} from "./guards/authenticated-guard.service";
|
||||||
|
import { UnauthorizedComponent } from './unauthorized/unauthorized.component';
|
||||||
|
|
||||||
export function loadConfig(oidcConfigService: OidcConfigService)
|
export function loadConfig(oidcConfigService: OidcConfigService)
|
||||||
{
|
{
|
||||||
@ -56,7 +59,9 @@ export function loadConfig(oidcConfigService: OidcConfigService)
|
|||||||
PeopleListComponent,
|
PeopleListComponent,
|
||||||
ShowsListComponent,
|
ShowsListComponent,
|
||||||
LoginComponent,
|
LoginComponent,
|
||||||
PasswordValidator
|
PasswordValidator,
|
||||||
|
AccountComponent,
|
||||||
|
UnauthorizedComponent
|
||||||
],
|
],
|
||||||
imports: [
|
imports: [
|
||||||
BrowserModule,
|
BrowserModule,
|
||||||
@ -88,7 +93,9 @@ export function loadConfig(oidcConfigService: OidcConfigService)
|
|||||||
useFactory: loadConfig,
|
useFactory: loadConfig,
|
||||||
deps: [OidcConfigService],
|
deps: [OidcConfigService],
|
||||||
multi: true
|
multi: true
|
||||||
},],
|
},
|
||||||
|
AuthenticatedGuard
|
||||||
|
],
|
||||||
bootstrap: [AppComponent]
|
bootstrap: [AppComponent]
|
||||||
})
|
})
|
||||||
export class AppModule
|
export class AppModule
|
||||||
|
39
src/app/guards/authenticated-guard.service.ts
Normal file
39
src/app/guards/authenticated-guard.service.ts
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import {
|
||||||
|
CanActivate,
|
||||||
|
CanLoad,
|
||||||
|
Route,
|
||||||
|
UrlSegment,
|
||||||
|
ActivatedRouteSnapshot,
|
||||||
|
RouterStateSnapshot,
|
||||||
|
UrlTree,
|
||||||
|
Router
|
||||||
|
} from '@angular/router';
|
||||||
|
import { Observable } from 'rxjs';
|
||||||
|
import {AuthService} from "../services/auth.service";
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
|
export class AuthenticatedGuard implements CanActivate, CanLoad
|
||||||
|
{
|
||||||
|
constructor(private router: Router, private authManager: AuthService) {}
|
||||||
|
|
||||||
|
canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree
|
||||||
|
{
|
||||||
|
return this.checkPermissions();
|
||||||
|
}
|
||||||
|
|
||||||
|
canLoad(route: Route, segments: UrlSegment[]): Observable<boolean> | Promise<boolean> | boolean
|
||||||
|
{
|
||||||
|
return this.checkPermissions();
|
||||||
|
}
|
||||||
|
|
||||||
|
checkPermissions() : boolean
|
||||||
|
{
|
||||||
|
if (this.authManager.isAuthenticated)
|
||||||
|
return true;
|
||||||
|
this.router.navigate(["/unauthorized"]);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
11
src/app/unauthorized/unauthorized.component.html
Normal file
11
src/app/unauthorized/unauthorized.component.html
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<br/>
|
||||||
|
<br/>
|
||||||
|
<br/>
|
||||||
|
<br/>
|
||||||
|
<br/>
|
||||||
|
<div class="text-center">
|
||||||
|
<h1>Unauthorized</h1>
|
||||||
|
<p>You don't have enough permissions to view this page.
|
||||||
|
<span *ngIf="!this.isLoggedIn()"><br/>Sign in and try again.</span>
|
||||||
|
</p>
|
||||||
|
</div>
|
0
src/app/unauthorized/unauthorized.component.scss
Normal file
0
src/app/unauthorized/unauthorized.component.scss
Normal file
17
src/app/unauthorized/unauthorized.component.ts
Normal file
17
src/app/unauthorized/unauthorized.component.ts
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
import {AuthService} from "../services/auth.service";
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-unauthorized',
|
||||||
|
templateUrl: './unauthorized.component.html',
|
||||||
|
styleUrls: ['./unauthorized.component.scss']
|
||||||
|
})
|
||||||
|
export class UnauthorizedComponent
|
||||||
|
{
|
||||||
|
constructor(private authManager: AuthService) { }
|
||||||
|
|
||||||
|
isLoggedIn() : boolean
|
||||||
|
{
|
||||||
|
return this.authManager.isAuthenticated;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user