First try

This commit is contained in:
2026-01-13 11:12:51 +01:00
parent af44e50f54
commit 93485efc5c
16 changed files with 525 additions and 486 deletions

View File

@@ -1,32 +1,34 @@
import { Component, OnInit, ViewChild, AfterViewInit } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { MatInput } from '@angular/material/input';
import { Component, OnInit, ViewChild, AfterViewInit } from "@angular/core";
import { Router, ActivatedRoute } from "@angular/router";
import { FormBuilder, FormGroup, Validators } from "@angular/forms";
import { MatInput } from "@angular/material/input";
import { first } from 'rxjs/operators';
import { first } from "rxjs/operators";
import { AuthenticationService } from '../../services/authentication.service';
import { AuthenticationService } from "../../services/authentication.service";
@Component({
selector: 'app-login-user',
templateUrl: './login-user.component.html',
styleUrls: ['./login-user.component.css'],
standalone: false
selector: "app-login-user",
templateUrl: "./login-user.component.html",
styleUrls: ["./login-user.component.css"],
standalone: false,
})
export class LoginUserComponent implements OnInit, AfterViewInit {
loginForm: FormGroup;
loading = false;
submitted = false;
returnUrl: string;
error = '';
@ViewChild('username') userNameInput: MatInput;
error = "";
@ViewChild("username") userNameInput: MatInput;
constructor(private formBuilder: FormBuilder,
private route: ActivatedRoute,
private router: Router,
private authenticationService: AuthenticationService) {
constructor(
private formBuilder: FormBuilder,
private route: ActivatedRoute,
private router: Router,
private authenticationService: AuthenticationService
) {
if (this.authenticationService.currentUserValue) {
this.router.navigate(['/']);
this.router.navigate(["/"]);
}
}
@@ -37,15 +39,14 @@ export class LoginUserComponent implements OnInit, AfterViewInit {
ngOnInit() {
this.loginForm = this.formBuilder.group(
{
username: ['', [Validators.required, Validators.minLength(3)]],
password: ['', [Validators.required]]
username: ["", [Validators.required, Validators.minLength(3)]],
password: ["", [Validators.required]],
},
{ updateOn: 'submit' }
{ updateOn: "submit" }
);
// get return url from route parameters or default to '/'
this.returnUrl = this.route.snapshot.queryParams['returnUrl'] || '/';
this.returnUrl = this.route.snapshot.queryParams["returnUrl"] || "/";
}
get formCtrls() {
@@ -57,17 +58,21 @@ export class LoginUserComponent implements OnInit, AfterViewInit {
if (this.loginForm.valid) {
this.loading = true;
this.authenticationService.login(this.formCtrls.username.value, this.formCtrls.password.value)
.pipe(first())
.subscribe(
data => {
this.router.navigate([this.returnUrl]);
},
error => {
this.error = error;
this.loading = false;
}
);
this.authenticationService
.login(
this.formCtrls["username"].value,
this.formCtrls["password"].value
)
.pipe(first())
.subscribe(
(data) => {
this.router.navigate([this.returnUrl]);
},
(error) => {
this.error = error;
this.loading = false;
}
);
}
}
}