Admin mode. Data driven content sections. Bugfixes.
This commit is contained in:
1 parent
bd65455945
commit
266c2451f1
30 files changed
+1733
-13
No files matched your search
@@ -0,0 +1,47 @@
|
||||
import { Component, inject } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { Router } from '@angular/router';
|
||||
import { firstValueFrom } from 'rxjs';
|
||||
|
||||
import { AuthService } from '../services/auth.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-login',
|
||||
standalone: true,
|
||||
imports: [CommonModule, FormsModule],
|
||||
templateUrl: './login.component.html',
|
||||
styleUrl: './login.component.scss',
|
||||
})
|
||||
export class LoginComponent {
|
||||
private auth = inject(AuthService);
|
||||
private router = inject(Router);
|
||||
|
||||
username = '';
|
||||
password = '';
|
||||
error = '';
|
||||
loading = false;
|
||||
|
||||
async onSubmit(): Promise<void> {
|
||||
if (!this.username || !this.password) return;
|
||||
|
||||
this.loading = true;
|
||||
this.error = '';
|
||||
|
||||
try {
|
||||
const resp = await firstValueFrom(this.auth.login(this.username, this.password));
|
||||
// Token stored — fetch user info
|
||||
const user = await this.auth.getCurrentUser();
|
||||
if (user?.is_admin) {
|
||||
this.router.navigate(['/admin']);
|
||||
} else {
|
||||
this.router.navigate(['/']);
|
||||
}
|
||||
} catch (err: any) {
|
||||
const body = err.error?.detail;
|
||||
this.error = typeof body === 'string' ? body : 'Login failed. Please try again.';
|
||||
} finally {
|
||||
this.loading = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user