Files
we_bstly-web/src/app/pages/login-totp/login-totp.component.ts
T
2025-05-11 18:05:06 +02:00

55 lines
1.4 KiB
TypeScript

import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
import { Auth2FAService } from '../../services/auth.2fa.service';
import { environment } from '../../../environments/environment';
@Component({
standalone: false,
selector: 'app-login-totp',
templateUrl: './login-totp.component.html',
styleUrls: ['./login-totp.component.scss']
})
export class LoginTotpComponent implements OnInit {
form: FormGroup;
public loginInvalid: boolean;
public apiUrl = environment.apiUrl;
targetRoute = '/account/info';
constructor(private formBuilder: FormBuilder, private auth2FAService: Auth2FAService, private router: Router, private route: ActivatedRoute) { }
ngOnInit() {
this.form = this.formBuilder.group({
code: ['', Validators.required],
keep: ['']
});
this.route.queryParams.subscribe({
next: (params) => {
if (params['target']) {
this.targetRoute = params['target'];
}
}
});
}
async loginTotp() {
this.loginInvalid = false;
if (this.form.valid) {
this.auth2FAService.login('totp', this.form.get('code').value, this.form.get('keep').value).subscribe({
next: (response: any) => {
this.router.navigate([this.targetRoute]);
},
error: (error) => {
this.loginInvalid = true;
}
});
}
}
}