ciyidogan commited on
Commit
8dd0742
·
verified ·
1 Parent(s): 5d67c0c

Update flare-ui/src/app/components/login/login.component.ts

Browse files
flare-ui/src/app/components/login/login.component.ts CHANGED
@@ -1,115 +1,128 @@
1
- import { Component, inject } from '@angular/core';
2
- import { CommonModule } from '@angular/common';
3
- import { FormsModule } from '@angular/forms';
4
- import { Router } from '@angular/router';
5
- import { AuthService } from '../../services/auth.service';
6
-
7
- @Component({
8
- selector: 'app-login',
9
- standalone: true,
10
- imports: [CommonModule, FormsModule],
11
- template: `
12
- <div class="login-container">
13
- <div class="login-card">
14
- <h1>Flare Administration</h1>
15
- <form (ngSubmit)="login()" #loginForm="ngForm">
16
- <div class="form-group">
17
- <label for="username">Username</label>
18
- <input
19
- type="text"
20
- id="username"
21
- name="username"
22
- [(ngModel)]="username"
23
- required
24
- [disabled]="loading"
25
- >
26
- </div>
27
- <div class="form-group">
28
- <label for="password">Password</label>
29
- <input
30
- type="password"
31
- id="password"
32
- name="password"
33
- [(ngModel)]="password"
34
- required
35
- [disabled]="loading"
36
- >
37
- </div>
38
- @if (error) {
39
- <div class="alert alert-danger">{{ error }}</div>
40
- }
41
- <button
42
- type="submit"
43
- class="btn btn-primary w-100"
44
- [disabled]="loading || !loginForm.valid"
45
- >
46
- @if (loading) {
47
- <span class="spinner"></span> Logging in...
48
- } @else {
49
- Login
50
- }
51
- </button>
52
- </form>
53
- </div>
54
- </div>
55
- `,
56
- styles: [`
57
- .login-container {
58
- min-height: 100vh;
59
- display: flex;
60
- align-items: center;
61
- justify-content: center;
62
- background-color: #f5f5f5;
63
- }
64
-
65
- .login-card {
66
- background: white;
67
- padding: 2rem;
68
- border-radius: 8px;
69
- box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
70
- width: 100%;
71
- max-width: 400px;
72
-
73
- h1 {
74
- text-align: center;
75
- margin-bottom: 2rem;
76
- color: #333;
77
- font-size: 1.5rem;
78
- }
79
- }
80
-
81
- .w-100 {
82
- width: 100%;
83
- }
84
-
85
- button {
86
- display: flex;
87
- align-items: center;
88
- justify-content: center;
89
- gap: 0.5rem;
90
- }
91
- `]
92
- })
93
- export class LoginComponent {
94
- private authService = inject(AuthService);
95
- private router = inject(Router);
96
-
97
- username = '';
98
- password = '';
99
- loading = false;
100
- error = '';
101
-
102
- async login() {
103
- this.loading = true;
104
- this.error = '';
105
-
106
- try {
107
- await this.authService.login(this.username, this.password).toPromise();
108
- this.router.navigate(['/']);
109
- } catch (err: any) {
110
- this.error = err.error?.detail || 'Invalid credentials';
111
- } finally {
112
- this.loading = false;
113
- }
114
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  }
 
1
+ import { Component, inject } from '@angular/core';
2
+ import { CommonModule } from '@angular/common';
3
+ import { FormsModule } from '@angular/forms';
4
+ import { Router } from '@angular/router';
5
+ import { MatCardModule } from '@angular/material/card';
6
+ import { MatFormFieldModule } from '@angular/material/form-field';
7
+ import { MatInputModule } from '@angular/material/input';
8
+ import { MatButtonModule } from '@angular/material/button';
9
+ import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
10
+ import { AuthService } from '../../services/auth.service';
11
+
12
+ @Component({
13
+ selector: 'app-login',
14
+ standalone: true,
15
+ imports: [
16
+ CommonModule,
17
+ FormsModule,
18
+ MatCardModule,
19
+ MatFormFieldModule,
20
+ MatInputModule,
21
+ MatButtonModule,
22
+ MatProgressSpinnerModule
23
+ ],
24
+ template: `
25
+ <div class="login-container">
26
+ <div class="login-card">
27
+ <h1>Flare Administration</h1>
28
+ <form (ngSubmit)="login()" #loginForm="ngForm">
29
+ <div class="form-group">
30
+ <label for="username">Username</label>
31
+ <input
32
+ type="text"
33
+ id="username"
34
+ name="username"
35
+ [(ngModel)]="username"
36
+ required
37
+ [disabled]="loading"
38
+ >
39
+ </div>
40
+ <div class="form-group">
41
+ <label for="password">Password</label>
42
+ <input
43
+ type="password"
44
+ id="password"
45
+ name="password"
46
+ [(ngModel)]="password"
47
+ required
48
+ [disabled]="loading"
49
+ >
50
+ </div>
51
+ @if (error) {
52
+ <div class="alert alert-danger">{{ error }}</div>
53
+ }
54
+ <button
55
+ type="submit"
56
+ class="btn btn-primary w-100"
57
+ [disabled]="loading || !loginForm.valid"
58
+ >
59
+ @if (loading) {
60
+ <span class="spinner"></span> Logging in...
61
+ } @else {
62
+ Login
63
+ }
64
+ </button>
65
+ </form>
66
+ </div>
67
+ </div>
68
+ `,
69
+ styles: [`
70
+ .login-container {
71
+ min-height: 100vh;
72
+ display: flex;
73
+ align-items: center;
74
+ justify-content: center;
75
+ background-color: #f5f5f5;
76
+ }
77
+
78
+ .login-card {
79
+ background: white;
80
+ padding: 2rem;
81
+ border-radius: 8px;
82
+ box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
83
+ width: 100%;
84
+ max-width: 400px;
85
+
86
+ h1 {
87
+ text-align: center;
88
+ margin-bottom: 2rem;
89
+ color: #333;
90
+ font-size: 1.5rem;
91
+ }
92
+ }
93
+
94
+ .w-100 {
95
+ width: 100%;
96
+ }
97
+
98
+ button {
99
+ display: flex;
100
+ align-items: center;
101
+ justify-content: center;
102
+ gap: 0.5rem;
103
+ }
104
+ `]
105
+ })
106
+ export class LoginComponent {
107
+ private authService = inject(AuthService);
108
+ private router = inject(Router);
109
+
110
+ username = '';
111
+ password = '';
112
+ loading = false;
113
+ error = '';
114
+
115
+ async login() {
116
+ this.loading = true;
117
+ this.error = '';
118
+
119
+ try {
120
+ await this.authService.login(this.username, this.password).toPromise();
121
+ this.router.navigate(['/']);
122
+ } catch (err: any) {
123
+ this.error = err.error?.detail || 'Invalid credentials';
124
+ } finally {
125
+ this.loading = false;
126
+ }
127
+ }
128
  }