This commit is contained in:
Lurkars
2021-01-12 19:29:00 +01:00
parent b7b4e2d032
commit 997a512e00
96 changed files with 2711 additions and 304 deletions
+22 -9
View File
@@ -1,7 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { AuthService } from './../../services/auth.service';
import { Router } from '@angular/router';
import { Router, ActivatedRoute } from '@angular/router';
import { environment } from './../../../environments/environment';
@@ -15,27 +15,40 @@ export class LoginComponent implements OnInit {
form: FormGroup;
public loginInvalid: boolean;
public apiUrl = environment.apiUrl;
targetRoute = '/account/info';
loginModel = {};
constructor(private formBuilder: FormBuilder, private authService: AuthService, private router: Router) { }
constructor(private formBuilder: FormBuilder, private authService: AuthService, private router: Router, private route: ActivatedRoute) { }
async ngOnInit() {
this.form = this.formBuilder.group({
username: ['', Validators.required],
password: ['', Validators.required]
password: ['', Validators.required],
keep: ['']
});
this.route.queryParams.subscribe(params => {
if (params['target']) {
this.targetRoute = params['target'];
}
});
}
async login() {
this.loginInvalid = false;
if (this.form.valid) {
const username = this.form.get('username').value;
const password = this.form.get('password').value;
this.authService.login(username, password).subscribe((response: any) => {
this.router.navigate(["/account/info"]);
const loginModel = {
username: this.form.get('username').value,
password: this.form.get('password').value,
keep: this.form.get('keep').value
};
this.authService.login(loginModel).subscribe((response: any) => {
this.router.navigate([this.targetRoute]);
}, error => {
if (error.status == 302) {
console.log(error);
if (error.status == 428) {
this.router.navigate(["/login/totp"], { queryParams: { target: this.targetRoute } });
} else {
this.loginInvalid = true;
}