diff --git a/src/app/account/account.component.html b/src/app/account/account.component.html new file mode 100644 index 00000000..2d5fa188 --- /dev/null +++ b/src/app/account/account.component.html @@ -0,0 +1 @@ +

account works!

diff --git a/src/app/account/account.component.scss b/src/app/account/account.component.scss new file mode 100644 index 00000000..e69de29b diff --git a/src/app/account/account.component.ts b/src/app/account/account.component.ts new file mode 100644 index 00000000..a7aac8e2 --- /dev/null +++ b/src/app/account/account.component.ts @@ -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() { + } + +} diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index a3dea235..be7a22bc 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -13,6 +13,9 @@ import { ShowResolverService } from './services/show-resolver.service'; import { StreamResolverService } from "./services/stream-resolver.service"; import { ShowDetailsComponent } from './show-details/show-details.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 = [ { 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: "search/:query", component: SearchComponent, resolve: { items: SearchResolverService } }, { path: "login", component: LoginComponent }, + { path: "account", component: AccountComponent, canActivate: [AuthenticatedGuard], canLoad: [AuthenticatedGuard] }, + { path: "unauthorized", component: UnauthorizedComponent }, { path: "**", component: NotFoundComponent } ]; diff --git a/src/app/app.component.html b/src/app/app.component.html index ee8aa790..c63ab6b1 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -31,7 +31,7 @@ - + Settings diff --git a/src/app/app.component.scss b/src/app/app.component.scss index 0b559097..ab3ba9ec 100644 --- a/src/app/app.component.scss +++ b/src/app/app.component.scss @@ -18,6 +18,17 @@ } } +.link +{ + outline: none; + color: inherit; + + &:hover + { + text-decoration: none !important; + } +} + .nav-link { padding: 12px; diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 469080af..07f05077 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -37,6 +37,9 @@ import { OidcSecurityService, OpenIdConfiguration } 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) { @@ -56,7 +59,9 @@ export function loadConfig(oidcConfigService: OidcConfigService) PeopleListComponent, ShowsListComponent, LoginComponent, - PasswordValidator + PasswordValidator, + AccountComponent, + UnauthorizedComponent ], imports: [ BrowserModule, @@ -88,7 +93,9 @@ export function loadConfig(oidcConfigService: OidcConfigService) useFactory: loadConfig, deps: [OidcConfigService], multi: true - },], + }, + AuthenticatedGuard + ], bootstrap: [AppComponent] }) export class AppModule diff --git a/src/app/guards/authenticated-guard.service.ts b/src/app/guards/authenticated-guard.service.ts new file mode 100644 index 00000000..ac2266ef --- /dev/null +++ b/src/app/guards/authenticated-guard.service.ts @@ -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 | Promise | boolean | UrlTree + { + return this.checkPermissions(); + } + + canLoad(route: Route, segments: UrlSegment[]): Observable | Promise | boolean + { + return this.checkPermissions(); + } + + checkPermissions() : boolean + { + if (this.authManager.isAuthenticated) + return true; + this.router.navigate(["/unauthorized"]); + return false; + } +} diff --git a/src/app/unauthorized/unauthorized.component.html b/src/app/unauthorized/unauthorized.component.html new file mode 100644 index 00000000..33b5a854 --- /dev/null +++ b/src/app/unauthorized/unauthorized.component.html @@ -0,0 +1,11 @@ +
+
+
+
+
+
+

Unauthorized

+

You don't have enough permissions to view this page. +
Sign in and try again.
+

+
diff --git a/src/app/unauthorized/unauthorized.component.scss b/src/app/unauthorized/unauthorized.component.scss new file mode 100644 index 00000000..e69de29b diff --git a/src/app/unauthorized/unauthorized.component.ts b/src/app/unauthorized/unauthorized.component.ts new file mode 100644 index 00000000..0464fe46 --- /dev/null +++ b/src/app/unauthorized/unauthorized.component.ts @@ -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; + } +}