Add auth guard connection for dashboard routes.
This commit is contained in:
@@ -1,16 +1,17 @@
|
||||
import {AfterViewInit, Component, OnInit} from '@angular/core';
|
||||
import {Component, OnInit} from '@angular/core';
|
||||
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
|
||||
import {CustomErrorStateMatcher} from '@app/_helpers';
|
||||
import {AuthService} from '@app/_services';
|
||||
import {Router} from '@angular/router';
|
||||
|
||||
@Component({
|
||||
selector: 'app-auth',
|
||||
templateUrl: './auth.component.html',
|
||||
styleUrls: ['./auth.component.scss']
|
||||
})
|
||||
export class AuthComponent implements OnInit, AfterViewInit {
|
||||
export class AuthComponent implements OnInit {
|
||||
keyForm: FormGroup;
|
||||
passphraseForm: FormGroup;
|
||||
stateForm: FormGroup;
|
||||
submitted: boolean = false;
|
||||
loading: boolean = false;
|
||||
matcher = new CustomErrorStateMatcher();
|
||||
@@ -18,14 +19,15 @@ export class AuthComponent implements OnInit, AfterViewInit {
|
||||
constructor(
|
||||
private authService: AuthService,
|
||||
private formBuilder: FormBuilder,
|
||||
private router: Router
|
||||
) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
this.keyForm = this.formBuilder.group({
|
||||
key: ['', Validators.required],
|
||||
});
|
||||
this.passphraseForm = this.formBuilder.group({
|
||||
passphrase: ['', Validators.required],
|
||||
this.stateForm = this.formBuilder.group({
|
||||
state: '',
|
||||
});
|
||||
if (this.authService.privateKey !== undefined ) {
|
||||
this.authService.setKey(this.authService.privateKey).then(r => {
|
||||
@@ -37,23 +39,7 @@ export class AuthComponent implements OnInit, AfterViewInit {
|
||||
}
|
||||
}
|
||||
|
||||
ngAfterViewInit(): void {
|
||||
console.log(window.location);
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.responseType = 'text';
|
||||
xhr.open('GET', window.location.origin + '/privatekey.asc');
|
||||
xhr.onload = (e) => {
|
||||
if (xhr.status !== 200) {
|
||||
console.warn('failed to autoload private key ciphertext');
|
||||
return;
|
||||
}
|
||||
(document.getElementById('privateKeyAsc') as HTMLInputElement).value = xhr.responseText;
|
||||
};
|
||||
xhr.send();
|
||||
}
|
||||
|
||||
get keyFormStub(): any { return this.keyForm.controls; }
|
||||
get passphraseFormStub(): any { return this.passphraseForm.controls; }
|
||||
|
||||
onSubmit(): void {
|
||||
this.submitted = true;
|
||||
@@ -66,8 +52,10 @@ export class AuthComponent implements OnInit, AfterViewInit {
|
||||
}
|
||||
|
||||
login(): void {
|
||||
// if (this.passphraseForm.invalid) { return; }
|
||||
this.authService.login();
|
||||
const loginStatus = this.authService.login();
|
||||
if (loginStatus) {
|
||||
this.router.navigate(['/home']);
|
||||
}
|
||||
}
|
||||
|
||||
switchWindows(): void {
|
||||
|
||||
Reference in New Issue
Block a user