implement UI Frontend
LocationBasedServices/smartguide/pipeline/head This commit looks good

This commit is contained in:
2026-06-24 13:14:26 +02:00
parent 81441dc588
commit 40fcdba595
3 changed files with 436 additions and 118 deletions
@@ -1,68 +1,154 @@
<div class="container">
<form class="form" [formGroup]="loginForm">
<h3>Anmeldung</h3>
<p class="field">
Um auf den Dienst zuzugreifen, musst Du Deine Anmeldedaten eingeben.
</p>
<mat-form-field class="field">
<mat-label>Login</mat-label>
<input id="dp-login" matInput formControlName="login" />
@if (loginForm.controls.login.hasError('required')) {
<mat-error>Fehler: <b>Login</b> erforderlich.</mat-error>
} @else if (loginForm.controls.login.hasError('minlength')) {
<mat-error>Fehler: <b>Login</b> ist unvollständig.</mat-error>
}
</mat-form-field>
<mat-form-field class="field">
<mat-label>Passwort</mat-label>
<input
id="dp-password"
matInput
[type]="showPassword ? 'text' : 'password'"
formControlName="password" />
@if (showPassword) {
<mat-icon matSuffix (click)="showPassword = false">visibility</mat-icon>
} @else {
<mat-icon matSuffix (click)="showPassword = true"
>visibility_off</mat-icon
>
}
@if (loginForm.controls.password.hasError('required')) {
<mat-error>Fehler: <b>Passwort</b> erforderlich.</mat-error>
} @else if (loginForm.controls.password.hasError('minlength')) {
<mat-error>Fehler: <b>Passwort</b> ist unvollständig.</mat-error>
}
</mat-form-field>
<button
mat-raised-button
class="button"
(click)="login()"
[disabled]="!loginForm.valid || (credentialService.validating | async)">
Anmelden
</button>
<div class="field" style="text-align: center; margin-top: -10px">
<button mat-button type="button" routerLink="/register">
Noch kein Konto? <b>Registrieren</b>
</button>
<section class="login-page">
<div class="login-panel">
<div class="brand-block">
<span class="eyebrow">SmartGuide Account Portal</span>
<h1>Login</h1>
<p>
Melde Dich mit Deiner Organisation an. Nach den Zugangsdaten erhältst Du
einen einmaligen Code per E-Mail.
</p>
</div>
</form>
<p class="progress">
@if (credentialService.validating | async) {
<span><i>Anmeldung läuft,</i> bitte warte einen Moment.</span>
<div class="stepper" aria-label="Login-Fortschritt">
<div class="step" [class.step--active]="currentStep === 'credentials'">
<span>1</span>
<strong>Zugangsdaten</strong>
</div>
<div class="step-line"></div>
<div class="step" [class.step--active]="currentStep === 'otk'">
<span>2</span>
<strong>OTK-Code</strong>
</div>
</div>
@if (currentStep === 'credentials') {
<form
class="login-form"
[formGroup]="credentialsForm"
(ngSubmit)="requestOtk()">
<mat-form-field class="field" appearance="outline">
<mat-label>E-Mail-Adresse</mat-label>
<input
id="login-email"
matInput
type="email"
autocomplete="email"
formControlName="email" />
@if (credentialsForm.controls.email.hasError('required')) {
<mat-error>E-Mail-Adresse ist erforderlich.</mat-error>
} @else if (credentialsForm.controls.email.hasError('email')) {
<mat-error>Bitte gib eine gültige E-Mail-Adresse ein.</mat-error>
}
</mat-form-field>
<mat-form-field class="field" appearance="outline">
<mat-label>Passwort</mat-label>
<input
id="login-password"
matInput
[type]="showPassword ? 'text' : 'password'"
autocomplete="current-password"
formControlName="password" />
<button
mat-icon-button
matSuffix
type="button"
[attr.aria-label]="showPassword ? 'Passwort verbergen' : 'Passwort anzeigen'"
(click)="showPassword = !showPassword">
<mat-icon>{{ showPassword ? 'visibility' : 'visibility_off' }}</mat-icon>
</button>
@if (credentialsForm.controls.password.hasError('required')) {
<mat-error>Passwort ist erforderlich.</mat-error>
} @else if (credentialsForm.controls.password.hasError('minlength')) {
<mat-error>Passwort muss mindestens 8 Zeichen haben.</mat-error>
}
</mat-form-field>
<button
mat-flat-button
color="primary"
class="submit-button"
type="submit"
[disabled]="credentialsForm.invalid || isSubmitting">
@if (isSubmitting) {
Code wird gesendet...
} @else {
Code per E-Mail senden
}
</button>
<div class="form-actions">
<a routerLink="/login">Passwort vergessen?</a>
<a routerLink="/register">Konto erstellen</a>
</div>
</form>
} @else {
@if (
(credentialService.authenticated | async) &&
!(credentialService.superadmin | async) &&
!(credentialService.universityadmin | async)
) {
<span class="error"
>Fehler: <b>{{ credentialService.login.value }}</b> ist nicht
berechtigt.</span
>
}
<form class="login-form" [formGroup]="otkForm" (ngSubmit)="login()">
<div class="code-intro">
<mat-icon>mark_email_unread</mat-icon>
<div>
<strong>Code eingeben</strong>
<span>
Wir haben den Code an
{{ credentialsForm.controls.email.value || 'Deine E-Mail-Adresse' }}
gesendet.
</span>
</div>
</div>
<mat-form-field class="field" appearance="outline">
<mat-label>OTK-Code</mat-label>
<input
id="login-otk"
matInput
inputmode="text"
autocomplete="one-time-code"
formControlName="code" />
@if (otkForm.controls.code.hasError('required')) {
<mat-error>OTK-Code ist erforderlich.</mat-error>
} @else if (otkForm.controls.code.hasError('pattern')) {
<mat-error>Bitte gib den Code aus der E-Mail ein.</mat-error>
}
</mat-form-field>
<div
class="expiry"
[class.expiry--expired]="codeExpiresIn === 0"
aria-live="polite">
<mat-icon>timer</mat-icon>
@if (codeExpiresIn > 0) {
<span>Code läuft in {{ formatCountdown() }} ab.</span>
} @else {
<span>Code ist abgelaufen. Bitte neuen Code anfordern.</span>
}
</div>
<button
mat-flat-button
color="primary"
class="submit-button"
type="submit"
[disabled]="otkForm.invalid || isSubmitting || codeExpiresIn === 0">
@if (isSubmitting) {
Anmeldung wird geprüft...
} @else {
Anmelden
}
</button>
<div class="form-actions">
<button
mat-button
type="button"
(click)="resendCode()"
[disabled]="isSubmitting">
Code erneut senden
</button>
<button mat-button type="button" (click)="editCredentials()">
E-Mail ändern
</button>
</div>
</form>
}
</p>
</div>
</div>
</section>
@@ -1,54 +1,187 @@
.container {
display: flex;
flex-direction: column;
.login-page {
display: grid;
min-height: calc(100svh - 41px);
place-items: center;
padding: 48px 20px;
background:
radial-gradient(circle at top left, rgba(61, 124, 255, 0.12), transparent 34%),
linear-gradient(160deg, #f7f9ff 0%, #ffffff 64%);
}
.login-panel {
width: min(100%, 480px);
padding: 34px;
background: var(--sg-surface);
border: 1px solid var(--sg-border);
border-radius: var(--sg-radius-sm);
box-shadow: var(--sg-shadow-md);
}
.brand-block {
display: grid;
gap: 10px;
margin-bottom: 28px;
}
.eyebrow {
color: var(--sg-blue-highlight);
font-size: 12px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: 32px;
line-height: 1.15;
}
p {
margin: 0;
color: var(--sg-text-muted);
}
.stepper {
display: grid;
grid-template-columns: auto 1fr auto;
align-items: center;
justify-content: center;
gap: 12px;
margin-bottom: 28px;
}
.step {
display: inline-flex;
align-items: center;
gap: 8px;
color: var(--sg-text-muted);
font-size: 13px;
}
.step span {
display: grid;
width: 28px;
height: 28px;
place-items: center;
border: 1px solid var(--sg-border-strong);
border-radius: 50%;
background: var(--sg-surface);
font-weight: 700;
}
.step--active {
color: var(--sg-text);
}
.step--active span {
background: var(--sg-primary);
border-color: var(--sg-primary);
color: #ffffff;
}
.step-line {
height: 1px;
background: var(--sg-border);
}
.login-form {
display: grid;
gap: 18px;
}
.field,
.submit-button {
width: 100%;
height: 100%;
background: linear-gradient(160deg, #f4f6fb 0%, #e8ecf7 100%);
}
.form {
display: flex;
flex-direction: column;
align-items: center;
background: white;
border: none;
border-radius: 12px;
box-shadow:
0 2px 12px rgba(26, 58, 110, 0.1),
0 1px 4px rgba(0, 0, 0, 0.06);
gap: 20px;
padding: 36px 32px 28px;
}
.form h3 {
margin: 0 0 4px;
font-weight: 600;
color: #1a3a6e;
}
.button {
.submit-button {
min-height: 48px;
min-width: 140px;
border-radius: 8px;
font-weight: 500;
letter-spacing: 0.02em;
border-radius: var(--sg-radius-sm);
font-weight: 700;
}
.field {
width: 400px;
.form-actions {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
min-height: 40px;
}
.progress {
padding-top: 5px;
width: 300px;
height: 2em;
text-align: center;
font-size: small;
color: #585f71;
.form-actions a,
.form-actions button {
color: var(--sg-text-muted);
font-size: 13px;
}
.error {
.code-intro {
display: grid;
grid-template-columns: auto 1fr;
gap: 14px;
padding: 14px;
background: var(--sg-surface-soft);
border: 1px solid var(--sg-border);
border-radius: var(--sg-radius-sm);
}
.code-intro mat-icon {
color: var(--sg-blue-highlight);
}
.code-intro div {
display: grid;
gap: 3px;
}
.code-intro span {
color: var(--sg-text-muted);
font-size: 13px;
overflow-wrap: anywhere;
}
.expiry {
display: inline-flex;
align-items: center;
gap: 8px;
color: var(--sg-success);
font-size: 13px;
}
.expiry mat-icon {
width: 18px;
height: 18px;
font-size: 18px;
}
.expiry--expired {
color: #ba1a1a;
}
@media (max-width: 560px) {
.login-page {
padding: 28px 14px;
place-items: start center;
}
.login-panel {
padding: 24px 18px;
}
h1 {
font-size: 28px;
}
.stepper {
grid-template-columns: 1fr;
align-items: start;
}
.step-line {
display: none;
}
.form-actions {
align-items: stretch;
flex-direction: column;
}
}
@@ -15,6 +15,8 @@ import { Subscription } from 'rxjs';
import { MatSnackBar, MatSnackBarModule } from '@angular/material/snack-bar';
import { Router, RouterLink } from '@angular/router';
type LoginStep = 'credentials' | 'otk';
@Component({
selector: 'app-app-login',
imports: [
@@ -32,20 +34,29 @@ import { Router, RouterLink } from '@angular/router';
standalone: true,
})
export class AppLoginComponent implements OnInit, OnDestroy {
loginForm = new FormGroup({
login: new FormControl<string>('', [
Validators.required,
Validators.minLength(4),
]),
credentialsForm = new FormGroup({
email: new FormControl<string>('', [Validators.required, Validators.email]),
password: new FormControl<string>('', [
Validators.required,
Validators.minLength(4),
Validators.minLength(8),
]),
});
otkForm = new FormGroup({
code: new FormControl<string>('', [
Validators.required,
Validators.pattern(/^[0-9A-Za-z]{6,10}$/),
]),
});
currentStep: LoginStep = 'credentials';
showPassword = false;
isSubmitting = false;
codeExpiresIn = 0;
readonly codeLifetimeSeconds = 300;
subscription?: Subscription;
private countdownInterval?: ReturnType<typeof setInterval>;
constructor(
protected credentialService: CredentialService,
@@ -57,9 +68,11 @@ export class AppLoginComponent implements OnInit, OnDestroy {
this.subscription = this.credentialService.validating.subscribe(
(validating) => {
if (validating) {
this.loginForm.disable();
this.credentialsForm.disable();
this.otkForm.disable();
} else {
this.loginForm.enable();
this.credentialsForm.enable();
this.otkForm.enable();
this.checkEnter();
}
},
@@ -80,13 +93,99 @@ export class AppLoginComponent implements OnInit, OnDestroy {
this.subscription.unsubscribe();
this.subscription = undefined;
}
this.stopCountdown();
}
requestOtk() {
if (this.credentialsForm.invalid || this.isSubmitting) {
this.credentialsForm.markAllAsTouched();
return;
}
this.isSubmitting = true;
this.credentialsForm.disable();
setTimeout(() => {
this.isSubmitting = false;
this.credentialsForm.enable();
this.currentStep = 'otk';
this.otkForm.reset();
this.startCountdown();
this.snackBar.open('OTK-Code wurde an die E-Mail-Adresse gesendet.', 'OK', {
duration: 4000,
});
}, 450);
}
resendCode() {
if (this.isSubmitting) {
return;
}
this.requestOtk();
}
login() {
let user = this.loginForm.controls.login.value;
let pass = this.loginForm.controls.password.value;
if (user && pass) {
this.credentialService.loginAccount(user, pass);
if (this.otkForm.invalid || this.isSubmitting) {
this.otkForm.markAllAsTouched();
return;
}
if (this.codeExpiresIn <= 0) {
this.snackBar.open(
'Der Code ist abgelaufen. Bitte fordere einen neuen Code an.',
'OK',
{ duration: 5000 },
);
return;
}
this.isSubmitting = true;
this.otkForm.disable();
setTimeout(() => {
this.isSubmitting = false;
this.otkForm.enable();
this.snackBar.open(
'Backend-Anbindung folgt: login(emailCode) wird hier ausgeführt.',
'OK',
{ duration: 5000 },
);
}, 450);
}
editCredentials() {
this.currentStep = 'credentials';
this.stopCountdown();
this.otkForm.reset();
}
formatCountdown(): string {
const minutes = Math.floor(this.codeExpiresIn / 60);
const seconds = this.codeExpiresIn % 60;
return `${minutes}:${seconds.toString().padStart(2, '0')}`;
}
private startCountdown(): void {
this.stopCountdown();
this.codeExpiresIn = this.codeLifetimeSeconds;
this.countdownInterval = setInterval(() => {
this.codeExpiresIn = Math.max(this.codeExpiresIn - 1, 0);
if (this.codeExpiresIn === 0) {
this.stopCountdown(false);
}
}, 1000);
}
private stopCountdown(reset = true): void {
if (this.countdownInterval) {
clearInterval(this.countdownInterval);
this.countdownInterval = undefined;
}
if (reset) {
this.codeExpiresIn = 0;
}
}
}