Move auth component files.
This commit is contained in:
@@ -1,51 +1,89 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import {AfterViewInit, Component, OnInit} from '@angular/core';
|
||||
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
|
||||
import {CustomValidator} from '../_helpers';
|
||||
import {CustomErrorStateMatcher, CustomValidator} from '../_helpers';
|
||||
import {AuthService} from '../_services';
|
||||
|
||||
@Component({
|
||||
selector: 'app-auth',
|
||||
templateUrl: './auth.component.html',
|
||||
styleUrls: ['./auth.component.scss']
|
||||
})
|
||||
export class AuthComponent implements OnInit {
|
||||
registerForm: FormGroup;
|
||||
export class AuthComponent implements OnInit, AfterViewInit {
|
||||
keyForm: FormGroup;
|
||||
passphraseForm: FormGroup;
|
||||
submitted: boolean = false;
|
||||
loading: boolean = false;
|
||||
error: any;
|
||||
matcher = new CustomErrorStateMatcher();
|
||||
|
||||
constructor(
|
||||
private authService: AuthService,
|
||||
private formBuilder: FormBuilder,
|
||||
) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
this.registerForm = this.formBuilder.group({
|
||||
email: ['', Validators.required],
|
||||
password: ['', [
|
||||
// 1. Password Field is Required
|
||||
Validators.required,
|
||||
// 2. check whether the entered password has a number
|
||||
CustomValidator.patternValidator(/\d/, { hasNumber: true }),
|
||||
// 3. check whether the entered password has upper case letter
|
||||
CustomValidator.patternValidator(/[A-Z]/, { hasCapitalCase: true }),
|
||||
// 4. check whether the entered password has a lower-case letter
|
||||
CustomValidator.patternValidator(/[a-z]/, { hasSmallCase: true }),
|
||||
// 6. Has a minimum length of 8 characters
|
||||
Validators.minLength(8)]],
|
||||
confirmPassword: ['', Validators.required],
|
||||
terms: ['', Validators.required]
|
||||
}, {
|
||||
// validator for the form group
|
||||
validator: CustomValidator.passwordMatchValidator
|
||||
this.keyForm = this.formBuilder.group({
|
||||
key: ['', Validators.required],
|
||||
});
|
||||
this.passphraseForm = this.formBuilder.group({
|
||||
passphrase: ['', Validators.required],
|
||||
});
|
||||
if (this.authService.privateKey !== undefined ) {
|
||||
this.authService.setKey(this.authService.privateKey).then(r => {
|
||||
if (this.authService.sessionToken !== undefined) {
|
||||
this.authService.setState(
|
||||
'click to perform login ' + this.authService.sessionLoginCount + ' with token ' + this.authService.sessionToken);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
get form(): any { return this.registerForm.controls; }
|
||||
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;
|
||||
|
||||
if (this.registerForm.invalid) { return; }
|
||||
if (this.keyForm.invalid) { return; }
|
||||
|
||||
this.loading = true;
|
||||
this.authService.setKey(this.keyFormStub.key.value).then();
|
||||
this.loading = false;
|
||||
}
|
||||
|
||||
login(): void {
|
||||
// if (this.passphraseForm.invalid) { return; }
|
||||
this.authService.login();
|
||||
}
|
||||
|
||||
switchWindows(): void {
|
||||
this.authService.sessionToken = undefined;
|
||||
const divOne = document.getElementById('one');
|
||||
const divTwo = document.getElementById('two');
|
||||
this.toggleDisplay(divOne);
|
||||
this.toggleDisplay(divTwo);
|
||||
}
|
||||
|
||||
toggleDisplay(element: any): void {
|
||||
const style = window.getComputedStyle(element).display;
|
||||
if (style === 'block') {
|
||||
element.style.display = 'none';
|
||||
} else {
|
||||
element.style.display = 'block';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user