-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
89 changed files
with
5,759 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* angular-todo-prototype | ||
* | ||
* app-routing.module.ts | ||
* | ||
* Copyright (c) 2021 ForgeRock. All rights reserved. | ||
* This software may be modified and distributed under the terms | ||
* of the MIT license. See the LICENSE file for details. | ||
*/ | ||
|
||
import { NgModule } from '@angular/core'; | ||
import { RouterModule, Routes } from '@angular/router'; | ||
import { HomeComponent } from './views/home/home.component'; | ||
import { LoginComponent } from './views/login/login.component'; | ||
import { TodosComponent } from './views/todos/todos.component'; | ||
import { AuthGuard } from './auth/auth.guard'; | ||
import { RegisterComponent } from './views/register/register.component'; | ||
import { LogoutComponent } from './features/logout/logout.component'; | ||
|
||
const routes: Routes = [ | ||
{ path: 'home', component: HomeComponent }, | ||
{ path: 'login', component: LoginComponent }, | ||
{ path: 'register', component: RegisterComponent }, | ||
{ path: 'todos', canActivate: [AuthGuard], component: TodosComponent }, | ||
{ path: 'logout', component: LogoutComponent }, | ||
{ path: '', redirectTo: 'home', pathMatch: 'full' }, | ||
]; | ||
|
||
/** | ||
* Defines the routes and auth guards for the application | ||
*/ | ||
@NgModule({ | ||
imports: [RouterModule.forRoot(routes)], | ||
exports: [RouterModule], | ||
}) | ||
export class AppRoutingModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!-- | ||
angular-todo-prototype | ||
app.component.html | ||
Copyright (c) 2021 ForgeRock. All rights reserved. | ||
This software may be modified and distributed under the terms | ||
of the MIT license. See the LICENSE file for details. | ||
--> | ||
|
||
<div id="root" class="cstm_root"> | ||
<router-outlet></router-outlet> | ||
<div *ngIf="loading" class="cstm_container_v-centered container-fluid d-flex align-items-center"> | ||
<div class="w-100"> | ||
<app-loading message="Verifying access ..."></app-loading> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* angular-todo-prototype | ||
* | ||
* app.module.ts | ||
* | ||
* Copyright (c) 2021 ForgeRock. All rights reserved. | ||
* This software may be modified and distributed under the terms | ||
* of the MIT license. See the LICENSE file for details. | ||
*/ | ||
|
||
import { NgModule } from '@angular/core'; | ||
import { BrowserModule } from '@angular/platform-browser'; | ||
|
||
import { AppRoutingModule } from './app-routing.module'; | ||
import { FormsModule } from '@angular/forms'; | ||
|
||
import { AppComponent } from './app.component'; | ||
import { LoginComponent } from './views/login/login.component'; | ||
import { TextComponent } from './features/journey/text/text.component'; | ||
import { PasswordComponent } from './features/journey/password/password.component'; | ||
import { HomeComponent } from './views/home/home.component'; | ||
import { TodosComponent } from './views/todos/todos.component'; | ||
import { LogoutComponent } from './features/logout/logout.component'; | ||
import { TodoComponent } from './features/todo/todo.component'; | ||
import { BackHomeComponent } from './utilities/back-home/back-home.component'; | ||
import { LoadingComponent } from './utilities/loading/loading.component'; | ||
import { HomeIconComponent } from './icons/home-icon/home-icon.component'; | ||
import { LeftArrowIconComponent } from './icons/left-arrow-icon/left-arrow-icon.component'; | ||
import { KeyIconComponent } from './icons/key-icon/key-icon.component'; | ||
import { FormComponent } from './features/journey/form/form.component'; | ||
import { ButtonComponent } from './features/journey/button/button.component'; | ||
import { EyeIconComponent } from './icons/eye-icon/eye-icon.component'; | ||
import { AlertComponent } from './features/journey/alert/alert.component'; | ||
import { AlertIconComponent } from './icons/alert-icon/alert-icon.component'; | ||
import { VerifiedIconComponent } from './icons/verified-icon/verified-icon.component'; | ||
import { RegisterComponent } from './views/register/register.component'; | ||
import { UnknownComponent } from './features/journey/unknown/unknown.component'; | ||
import { BooleanComponent } from './features/journey/boolean/boolean.component'; | ||
import { TermsConditionsComponent } from './features/journey/terms-conditions/terms-conditions.component'; | ||
import { KbaComponent } from './features/journey/kba/kba.component'; | ||
import { LockIconComponent } from './icons/lock-icon/lock-icon.component'; | ||
import { NewUserIconComponent } from './icons/new-user-icon/new-user-icon.component'; | ||
import { HeaderComponent } from './layout/header/header.component'; | ||
import { FooterComponent } from './layout/footer/footer.component'; | ||
import { AngularIconComponent } from './icons/angular-icon/angular-icon.component'; | ||
import { ForgerockIconComponent } from './icons/forgerock-icon/forgerock-icon.component'; | ||
import { TodosIconComponent } from './icons/todos-icon/todos-icon.component'; | ||
import { AccountIconComponent } from './icons/account-icon/account-icon.component'; | ||
import { TodoIconComponent } from './icons/todo-icon/todo-icon.component'; | ||
import { ActionIconComponent } from './icons/action-icon/action-icon.component'; | ||
import { ChoiceComponent } from './features/journey/choice/choice.component'; | ||
|
||
@NgModule({ | ||
declarations: [ | ||
AppComponent, | ||
LoginComponent, | ||
TextComponent, | ||
PasswordComponent, | ||
HomeComponent, | ||
TodosComponent, | ||
LogoutComponent, | ||
TodoComponent, | ||
BackHomeComponent, | ||
LoadingComponent, | ||
HomeIconComponent, | ||
LeftArrowIconComponent, | ||
KeyIconComponent, | ||
FormComponent, | ||
ButtonComponent, | ||
EyeIconComponent, | ||
AlertComponent, | ||
AlertIconComponent, | ||
VerifiedIconComponent, | ||
RegisterComponent, | ||
UnknownComponent, | ||
BooleanComponent, | ||
TermsConditionsComponent, | ||
KbaComponent, | ||
LockIconComponent, | ||
NewUserIconComponent, | ||
HeaderComponent, | ||
FooterComponent, | ||
AngularIconComponent, | ||
ForgerockIconComponent, | ||
TodosIconComponent, | ||
AccountIconComponent, | ||
TodoIconComponent, | ||
ActionIconComponent, | ||
ChoiceComponent, | ||
], | ||
imports: [BrowserModule, AppRoutingModule, FormsModule], | ||
providers: [], | ||
bootstrap: [AppComponent], | ||
}) | ||
export class AppModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* angular-todo-prototype | ||
* | ||
* auth.guard.ts | ||
* | ||
* Copyright (c) 2021 ForgeRock. All rights reserved. | ||
* This software may be modified and distributed under the terms | ||
* of the MIT license. See the LICENSE file for details. | ||
*/ | ||
|
||
import { Injectable } from '@angular/core'; | ||
import { | ||
ActivatedRouteSnapshot, | ||
CanActivate, | ||
RouterStateSnapshot, | ||
UrlTree, | ||
Router, | ||
} from '@angular/router'; | ||
import { UserService } from '../services/user.service'; | ||
import { Tokens, TokenStorage, UserManager } from '@forgerock/javascript-sdk'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class AuthGuard implements CanActivate { | ||
constructor( | ||
public userService: UserService, | ||
private router: Router, | ||
) {} | ||
|
||
/** | ||
* Extends CanActivate to protect selected routes from unauthenticated access | ||
* | ||
* @param next - Route that the user is trying to access | ||
* @param state - Router state | ||
* @returns Promise - Boolean or route to redirect the user to | ||
*/ | ||
async canActivate( | ||
next: ActivatedRouteSnapshot, | ||
state: RouterStateSnapshot, | ||
): Promise<true | UrlTree> { | ||
const loginUrl = this.router.parseUrl('/login'); | ||
try { | ||
// Assume user is likely authenticated if there are tokens | ||
const tokens = await TokenStorage.get(); | ||
const info = await UserManager.getCurrentUser(); | ||
if (tokens === undefined || info === undefined) { | ||
return loginUrl; | ||
} | ||
return true; | ||
} catch (err) { | ||
// User likely not authenticated | ||
console.log(err); | ||
return loginUrl; | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
angular-todo/src/app/features/journey/alert/alert.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<!-- | ||
angular-todo-prototype | ||
alert.component.html | ||
Copyright (c) 2021 ForgeRock. All rights reserved. | ||
This software may be modified and distributed under the terms | ||
of the MIT license. See the LICENSE file for details. | ||
--> | ||
|
||
<!-- | ||
Display the message in a danger or success style alert depending on the type | ||
--> | ||
<container-element [ngSwitch]="type"> | ||
<p *ngSwitchCase="'error'" class="alert alert-danger d-flex align-items-center mt-1" role="alert"> | ||
<app-alert-icon></app-alert-icon> | ||
<span class="ps-2">{{ message }}</span> | ||
</p> | ||
<p | ||
*ngSwitchCase="'success'" | ||
class="alert alert-success d-flex align-items-center mt-5" | ||
role="alert" | ||
> | ||
<app-verified-icon size="36px"></app-verified-icon> | ||
<span class="ps-2">{{ message }}</span> | ||
</p> | ||
<p *ngSwitchDefault class="alert d-flex align-items-center mt-5" role="alert"> | ||
<span class="ps-2">{{ message }}</span> | ||
</p> | ||
</container-element> |
30 changes: 30 additions & 0 deletions
30
angular-todo/src/app/features/journey/alert/alert.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* angular-todo-prototype | ||
* | ||
* alert.component.ts | ||
* | ||
* Copyright (c) 2021 ForgeRock. All rights reserved. | ||
* This software may be modified and distributed under the terms | ||
* of the MIT license. See the LICENSE file for details. | ||
*/ | ||
|
||
import { Component, Input } from '@angular/core'; | ||
|
||
/** | ||
* Used for displaying for errors | ||
*/ | ||
@Component({ | ||
selector: 'app-alert', | ||
templateUrl: './alert.component.html', | ||
}) | ||
export class AlertComponent { | ||
/** | ||
* Determines whether this is an error or success alert | ||
*/ | ||
@Input() type?: string; | ||
|
||
/** | ||
* The message to display | ||
*/ | ||
@Input() message?: string; | ||
} |
Oops, something went wrong.