import { Component, inject, signal } from '@angular/core'; import { Router } from '@angular/router'; import { FormsModule } from '@angular/forms'; import { AuthService } from '../../core/services/auth.service'; import { ThemeService } from '../../core/services/theme.service'; import { CardComponent, CardHeaderComponent, CardTitleComponent, CardDescriptionComponent, CardContentComponent, CardFooterComponent, } from '../../ui/card/card.component'; import { ButtonComponent } from '../../ui/button/button.component'; import { InputComponent } from '../../ui/input/input.component'; import { LabelComponent } from '../../ui/label/label.component'; import { AlertComponent, AlertDescriptionComponent } from '../../ui/alert/alert.component'; @Component({ selector: 'app-login', standalone: true, imports: [ FormsModule, CardComponent, CardHeaderComponent, CardTitleComponent, CardDescriptionComponent, CardContentComponent, CardFooterComponent, ButtonComponent, InputComponent, LabelComponent, AlertComponent, AlertDescriptionComponent, ], template: `
Welcome to Onebox Enter your credentials to sign in
@if (error()) { {{ error() }} }

Default credentials: admin / admin

`, }) export class LoginComponent { private auth = inject(AuthService); private router = inject(Router); theme = inject(ThemeService); username = ''; password = ''; loading = signal(false); error = signal(null); async onSubmit(): Promise { if (!this.username || !this.password) { this.error.set('Please enter username and password'); return; } this.loading.set(true); this.error.set(null); const result = await this.auth.login(this.username, this.password); this.loading.set(false); if (result.success) { this.router.navigate(['/dashboard']); } else { this.error.set(result.error || 'Invalid credentials'); } } }