Added login UI
- Added empty adminui component - Added authStore
This commit is contained in:
60
frontend/src/app/login/login.component.ts
Normal file
60
frontend/src/app/login/login.component.ts
Normal file
@ -0,0 +1,60 @@
|
||||
import { Component } from '@angular/core';
|
||||
import {DevelopmentStore} from "../../store/DevelopmentStore";
|
||||
import {FormsModule} from "@angular/forms";
|
||||
import axios from "axios";
|
||||
import {NgClass, NgIf} from "@angular/common";
|
||||
import {AuthStore} from "../../store/authStore";
|
||||
import {firstValueFrom} from "rxjs";
|
||||
|
||||
@Component({
|
||||
selector: 'app-login',
|
||||
standalone: true,
|
||||
imports: [
|
||||
FormsModule,
|
||||
NgClass,
|
||||
NgIf
|
||||
],
|
||||
templateUrl: './login.component.html',
|
||||
styleUrl: './login.component.scss'
|
||||
})
|
||||
export class LoginComponent {
|
||||
inputUsername: string = "";
|
||||
inputPassword: string = "";
|
||||
loginFailed: boolean = false;
|
||||
loginSuccessful: boolean = false;
|
||||
|
||||
constructor(private developmentStore: DevelopmentStore, private authStore: AuthStore) {
|
||||
}
|
||||
|
||||
tryToLogin() {
|
||||
console.log("Trying to login with username: " + this.inputUsername + " and password: " + this.inputPassword);
|
||||
|
||||
axios({
|
||||
method: 'post',
|
||||
url: this.developmentStore.getBaseUrl() + 'api/v1/auth/login',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
data: {
|
||||
username: this.inputUsername,
|
||||
password: this.inputPassword
|
||||
}
|
||||
})
|
||||
.then(async response => {
|
||||
console.log(response);
|
||||
console.log(response.data);
|
||||
if(response.data.token) {
|
||||
this.loginSuccessful = true;
|
||||
this.authStore.setToken(response.data.token);
|
||||
this.authStore.setUsername(this.inputUsername);
|
||||
|
||||
console.log("Login successful");
|
||||
console.log("Token: " + await firstValueFrom(this.authStore.token$));
|
||||
console.log("Username: " + await firstValueFrom(this.authStore.username$));
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
this.loginFailed = true;
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user