0.2.5 initial commit

Makefile incomplete
This commit is contained in:
Aiden McClelland
2020-11-23 13:44:28 -07:00
commit 95d3845906
503 changed files with 53448 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
import { Injectable } from '@angular/core'
import { CanActivate, Router, CanActivateChild } from '@angular/router'
import { AuthState, AuthService } from '../services/auth.service'
@Injectable({
providedIn: 'root',
})
export class AuthGuard implements CanActivate, CanActivateChild {
constructor (
private readonly authService: AuthService,
private readonly router: Router,
) { }
canActivate (): boolean {
return this.runCheck()
}
canActivateChild (): boolean {
return this.runCheck()
}
private runCheck (): boolean {
const state = this.authService.peek()
switch (state){
case AuthState.VERIFIED: return true
case AuthState.UNVERIFIED: return this.toAuthenticate()
case AuthState.INITIALIZING: return this.toAuthenticate()
}
}
private toAuthenticate () {
this.router.navigate(['/authenticate'], { replaceUrl: true })
return false
}
}

View File

@@ -0,0 +1,26 @@
import { Injectable, Directive } from '@angular/core'
import { CanDeactivate } from '@angular/router'
import { HostListener } from '@angular/core'
@Directive()
export abstract class PageCanDeactivate {
abstract canDeactivate (): boolean
@HostListener('window:beforeunload', ['$event'])
unloadNotification (e: any) {
console.log(e)
if (!this.canDeactivate()) {
e.returnValue = true
}
}
}
@Injectable({
providedIn: 'root',
})
export class CanDeactivateGuard implements CanDeactivate<PageCanDeactivate> {
canDeactivate (page: PageCanDeactivate): boolean {
return page.canDeactivate() || confirm('You have unsaved changes. Are you sure you want to leave the page?')
}
}

View File

@@ -0,0 +1,26 @@
import { Injectable } from '@angular/core'
import { CanActivate, Router } from '@angular/router'
import { AuthService, AuthState } from '../services/auth.service'
@Injectable({
providedIn: 'root',
})
export class UnauthGuard implements CanActivate {
constructor (
private readonly authService: AuthService,
private readonly router: Router,
) { }
canActivate (): boolean {
const state = this.authService.peek()
switch (state){
case AuthState.VERIFIED: {
this.router.navigateByUrl('')
return false
}
case AuthState.UNVERIFIED: return true
case AuthState.INITIALIZING: return true
}
}
}