Merge pull request 'main' (#12) from main into prod
All checks were successful
Release / Release (push) Successful in 1m46s
All checks were successful
Release / Release (push) Successful in 1m46s
Reviewed-on: #12
This commit is contained in:
commit
f8e14133d0
3 changed files with 102 additions and 69 deletions
|
@ -1,75 +1,35 @@
|
||||||
<div class="flex min-h-full flex-col justify-center px-6 py-12 lg:px-8">
|
<div class="mx-auto pt-3 container">
|
||||||
<div class="sm:mx-auto sm:w-full sm:max-w-sm">
|
<mat-card appearance="outlined">
|
||||||
<img
|
<mat-card-content>
|
||||||
class="mx-auto h-10 w-auto"
|
<h1>Login</h1>
|
||||||
src="https://tailwindui.com/plus/img/logos/mark.svg?color=indigo&shade=600"
|
|
||||||
alt="Your Company"
|
|
||||||
/>
|
|
||||||
<h2
|
|
||||||
class="mt-10 text-center text-2xl/9 font-bold tracking-tight text-gray-900"
|
|
||||||
>
|
|
||||||
Sign in to your account
|
|
||||||
</h2>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="mt-10 sm:mx-auto sm:w-full sm:max-w-sm">
|
<form class="flex flex-col" [formGroup]="loginForm">
|
||||||
<form [formGroup]="loginForm" class="space-y-6" action="#" method="POST">
|
<mat-form-field appearance="outline">
|
||||||
@if (invalidCredentials) {
|
<mat-error>{{ errorMessages["email"] }}</mat-error>
|
||||||
<div class="mt-2">
|
<mat-label>Email</mat-label>
|
||||||
<p
|
|
||||||
class="block w-full rounded-md bg-white px-3 py-1.5 text-base text-red-500 outline outline-red-500 outline-2 -outline-offset-2 sm:text-sm/6"
|
|
||||||
>
|
|
||||||
Invalid Credentials
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
<div>
|
|
||||||
<label for="email" class="block text-sm/6 font-medium text-gray-900"
|
|
||||||
>Email address</label
|
|
||||||
>
|
|
||||||
<div class="mt-2">
|
|
||||||
<input
|
<input
|
||||||
formControlName="email"
|
formControlName="email"
|
||||||
type="email"
|
type="email"
|
||||||
name="email"
|
matInput
|
||||||
id="email"
|
placeholder="banana@banana.com"
|
||||||
autocomplete="email"
|
|
||||||
required
|
|
||||||
class="block w-full rounded-md bg-white px-3 py-1.5 text-base text-gray-900 outline outline-1 -outline-offset-1 outline-gray-300 placeholder:text-gray-400 focus:outline focus:outline-2 focus:-outline-offset-2 focus:outline-indigo-600 sm:text-sm/6"
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</mat-form-field>
|
||||||
</div>
|
<mat-form-field appearance="outline">
|
||||||
|
<mat-error>{{ errorMessages["password"] }}</mat-error>
|
||||||
<div>
|
<mat-label>Password</mat-label>
|
||||||
<div class="flex items-center justify-between">
|
|
||||||
<label
|
|
||||||
for="password"
|
|
||||||
class="block text-sm/6 font-medium text-gray-900"
|
|
||||||
>Password</label
|
|
||||||
>
|
|
||||||
</div>
|
|
||||||
<div class="mt-2">
|
|
||||||
<input
|
<input
|
||||||
formControlName="password"
|
formControlName="password"
|
||||||
|
matInput
|
||||||
type="password"
|
type="password"
|
||||||
name="password"
|
placeholder="Aurelius14"
|
||||||
id="password"
|
|
||||||
autocomplete="current-password"
|
|
||||||
required
|
|
||||||
class="block w-full rounded-md bg-white px-3 py-1.5 text-base text-gray-900 outline outline-1 -outline-offset-1 outline-gray-300 placeholder:text-gray-400 focus:outline focus:outline-2 focus:-outline-offset-2 focus:outline-indigo-600 sm:text-sm/6"
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</mat-form-field>
|
||||||
</div>
|
<button class="mb-3" mat-flat-button type="submit" (click)="submit()">Login</button>
|
||||||
|
<mat-divider></mat-divider>
|
||||||
<div>
|
<button mat-flat-button [style.backgroundColor]="'#FD4B2D'" class="mt-3 mat-authentik" (click)="loginWithAuthentik()">
|
||||||
<button
|
Log in with Authentik
|
||||||
(click)="submit()"
|
|
||||||
type="submit"
|
|
||||||
class="flex w-full justify-center rounded-md bg-indigo-600 px-3 py-1.5 text-sm/6 font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
|
|
||||||
>
|
|
||||||
Sign in
|
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</form>
|
||||||
</form>
|
</mat-card-content>
|
||||||
</div>
|
</mat-card>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,12 +1,31 @@
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms';
|
import {
|
||||||
|
FormControl,
|
||||||
|
FormGroup,
|
||||||
|
ReactiveFormsModule,
|
||||||
|
Validators,
|
||||||
|
} from '@angular/forms';
|
||||||
import PocketBase from 'pocketbase';
|
import PocketBase from 'pocketbase';
|
||||||
import { environment } from '../../environments/environment';
|
import { environment } from '../../environments/environment';
|
||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
|
import { MatCardModule } from '@angular/material/card';
|
||||||
|
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||||
|
import { MatInputModule, MatLabel } from '@angular/material/input';
|
||||||
|
import { MatButton, MatButtonModule } from '@angular/material/button';
|
||||||
|
import { MatSnackBar } from '@angular/material/snack-bar';
|
||||||
|
import {MatDividerModule} from '@angular/material/divider';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-login',
|
selector: 'app-login',
|
||||||
imports: [ReactiveFormsModule],
|
imports: [
|
||||||
|
ReactiveFormsModule,
|
||||||
|
MatCardModule,
|
||||||
|
MatInputModule,
|
||||||
|
MatLabel,
|
||||||
|
MatFormFieldModule,
|
||||||
|
MatButtonModule,
|
||||||
|
MatDividerModule,
|
||||||
|
],
|
||||||
templateUrl: './login.component.html',
|
templateUrl: './login.component.html',
|
||||||
styleUrl: './login.component.css',
|
styleUrl: './login.component.css',
|
||||||
})
|
})
|
||||||
|
@ -14,21 +33,69 @@ export class LoginComponent {
|
||||||
public loginForm!: FormGroup;
|
public loginForm!: FormGroup;
|
||||||
public invalidCredentials = false;
|
public invalidCredentials = false;
|
||||||
private pb = new PocketBase(environment.POCKETBASE);
|
private pb = new PocketBase(environment.POCKETBASE);
|
||||||
|
public errorMessages: Record<string, string> = {};
|
||||||
|
|
||||||
constructor(private router: Router) {}
|
constructor(
|
||||||
|
private router: Router,
|
||||||
|
private snackBar: MatSnackBar,
|
||||||
|
) { }
|
||||||
|
|
||||||
|
private validationErrorMessages: Record<string, string> = {
|
||||||
|
required: 'This field is required',
|
||||||
|
};
|
||||||
|
|
||||||
|
updateErrorMessages(): void {
|
||||||
|
this.errorMessages = {};
|
||||||
|
|
||||||
|
Object.keys(this.loginForm.controls).forEach((field) => {
|
||||||
|
const control = this.loginForm.get(field);
|
||||||
|
|
||||||
|
if (control && control.errors) {
|
||||||
|
this.errorMessages[field] = Object.keys(control.errors)
|
||||||
|
.map(
|
||||||
|
(errorKey) =>
|
||||||
|
this.validationErrorMessages[errorKey] ||
|
||||||
|
`Unknown error: ${errorKey}`,
|
||||||
|
)
|
||||||
|
.join(' ');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.loginForm = new FormGroup({
|
this.loginForm = new FormGroup({
|
||||||
email: new FormControl(''),
|
email: new FormControl('', Validators.required),
|
||||||
password: new FormControl(''),
|
password: new FormControl('', Validators.required),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (this.pb.authStore.isValid) {
|
if (this.pb.authStore.isValid) {
|
||||||
this.router.navigate(['dashboard']);
|
this.router.navigate(['dashboard']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.loginForm.valueChanges.subscribe(() => {
|
||||||
|
this.updateErrorMessages();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
loginWithAuthentik() {
|
||||||
|
this.pb.collection('users').authWithOAuth2({ provider: 'oidc' })
|
||||||
|
.then(() => {
|
||||||
|
this.router.navigate(['dashboard']);
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
this.invalidCredentials = true;
|
||||||
|
const error = this.snackBar.open('Invalid Credentials');
|
||||||
|
setTimeout(() => {
|
||||||
|
error.dismiss();
|
||||||
|
}, 5000);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
submit() {
|
submit() {
|
||||||
|
if (!this.loginForm.valid) {
|
||||||
|
this.updateErrorMessages();
|
||||||
|
}
|
||||||
|
|
||||||
this.pb
|
this.pb
|
||||||
.collection('users')
|
.collection('users')
|
||||||
.authWithPassword(
|
.authWithPassword(
|
||||||
|
@ -40,6 +107,10 @@ export class LoginComponent {
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
this.invalidCredentials = true;
|
this.invalidCredentials = true;
|
||||||
|
const error = this.snackBar.open('Invalid Credentials');
|
||||||
|
setTimeout(() => {
|
||||||
|
error.dismiss();
|
||||||
|
}, 5000);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,8 @@ html {
|
||||||
@apply underline text-blue-500 cursor-pointer;
|
@apply underline text-blue-500 cursor-pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
html,
|
html,
|
||||||
body {
|
body {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
|
Loading…
Add table
Reference in a new issue