diff --git a/webapp/src/app/modules/app-login/app-login.component.html b/webapp/src/app/modules/app-login/app-login.component.html index e7cb87a6..35a4fc3e 100644 --- a/webapp/src/app/modules/app-login/app-login.component.html +++ b/webapp/src/app/modules/app-login/app-login.component.html @@ -1,68 +1,154 @@ -
-
-

Anmeldung

-

- Um auf den Dienst zuzugreifen, musst Du Deine Anmeldedaten eingeben. -

- - - Login - - @if (loginForm.controls.login.hasError('required')) { - Fehler: Login erforderlich. - } @else if (loginForm.controls.login.hasError('minlength')) { - Fehler: Login ist unvollständig. - } - - - - Passwort - - @if (showPassword) { - visibility - } @else { - visibility_off - } - @if (loginForm.controls.password.hasError('required')) { - Fehler: Passwort erforderlich. - } @else if (loginForm.controls.password.hasError('minlength')) { - Fehler: Passwort ist unvollständig. - } - - - -
- +
+ diff --git a/webapp/src/app/modules/app-login/app-login.component.scss b/webapp/src/app/modules/app-login/app-login.component.scss index 034b92ac..e5cdaf91 100644 --- a/webapp/src/app/modules/app-login/app-login.component.scss +++ b/webapp/src/app/modules/app-login/app-login.component.scss @@ -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; + } +} diff --git a/webapp/src/app/modules/app-login/app-login.component.ts b/webapp/src/app/modules/app-login/app-login.component.ts index 24fd129f..3352060d 100644 --- a/webapp/src/app/modules/app-login/app-login.component.ts +++ b/webapp/src/app/modules/app-login/app-login.component.ts @@ -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('', [ - Validators.required, - Validators.minLength(4), - ]), + credentialsForm = new FormGroup({ + email: new FormControl('', [Validators.required, Validators.email]), password: new FormControl('', [ Validators.required, - Validators.minLength(4), + Validators.minLength(8), ]), }); + otkForm = new FormGroup({ + code: new FormControl('', [ + 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; 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; } } }