feat(auth): started auth restructure
LocationBasedServices/smartguide/pipeline/head There was a failure building this commit
LocationBasedServices/smartguide/pipeline/head There was a failure building this commit
This commit is contained in:
@@ -145,18 +145,19 @@ export class AccountComponent {
|
||||
if (!oldPassword || !newPassword) {
|
||||
return;
|
||||
}
|
||||
this._credentialService
|
||||
.changePassword(oldPassword, newPassword)
|
||||
.subscribe({
|
||||
error: (error) => {
|
||||
console.error('Error changing password:', error);
|
||||
this._snackBar.open(
|
||||
'Das alte Passwort ist nicht korrekt. Bitte versuchen Sie es erneut.',
|
||||
'OK',
|
||||
{ duration: 7000 },
|
||||
);
|
||||
},
|
||||
});
|
||||
try {
|
||||
await this._credentialService.changePassword(
|
||||
oldPassword,
|
||||
newPassword,
|
||||
);
|
||||
} catch (error) {
|
||||
console.error('Error changing password:', error);
|
||||
this._snackBar.open(
|
||||
'Fehler beim Ändern des Passworts. Bitte versuchen Sie es erneut.',
|
||||
'OK',
|
||||
{ duration: 7000 },
|
||||
);
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -14,133 +14,64 @@
|
||||
</button>
|
||||
</header>
|
||||
|
||||
<form class="filters" [formGroup]="filterForm" (ngSubmit)="applyFilters()">
|
||||
<mat-form-field appearance="outline">
|
||||
<mat-label>Name oder E-Mail</mat-label>
|
||||
<input matInput formControlName="search" />
|
||||
</mat-form-field>
|
||||
|
||||
@if (credentialService.isEffectiveSuperAdmin()) {
|
||||
<mat-form-field appearance="outline">
|
||||
<mat-label>Organisation</mat-label>
|
||||
<mat-select formControlName="organizationId">
|
||||
<mat-option value="">Alle Organisationen</mat-option>
|
||||
@for (organization of organizations; track organization.id) {
|
||||
<mat-option [value]="organization.id">
|
||||
{{ organization.name }}
|
||||
</mat-option>
|
||||
}
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
}
|
||||
|
||||
<div class="filter-actions">
|
||||
<button mat-flat-button color="primary" type="submit">
|
||||
<mat-icon>search</mat-icon>
|
||||
Suchen
|
||||
</button>
|
||||
<button mat-button type="button" (click)="resetFilters()">
|
||||
Zurücksetzen
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<section class="table-panel">
|
||||
<div class="table-header">
|
||||
<strong>{{ total }} Accounts</strong>
|
||||
@if (isLoading) {
|
||||
<span>Wird geladen...</span>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="table-wrap">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>E-Mail</th>
|
||||
<th>Organisation</th>
|
||||
<th>Rolle</th>
|
||||
<th>Status</th>
|
||||
<th>Aktionen</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@for (account of accounts; track account.id) {
|
||||
<tr [class.deleted]="account.deleted">
|
||||
<td>
|
||||
<button
|
||||
class="link-button"
|
||||
type="button"
|
||||
(click)="startEdit(account)">
|
||||
{{ account.name }}
|
||||
</button>
|
||||
</td>
|
||||
<td>{{ account.email }}</td>
|
||||
<td>{{ account.organization_name }}</td>
|
||||
<td>
|
||||
<span class="role">{{ account.role | role }}</span>
|
||||
</td>
|
||||
<td>
|
||||
<span class="status" [class.status--deleted]="account.deleted">
|
||||
{{ account.deleted ? 'deleted' : 'active' }}
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<div class="row-actions">
|
||||
<button
|
||||
mat-icon-button
|
||||
type="button"
|
||||
aria-label="Bearbeiten"
|
||||
(click)="startEdit(account)">
|
||||
<mat-icon>edit</mat-icon>
|
||||
</button>
|
||||
<button
|
||||
mat-icon-button
|
||||
type="button"
|
||||
aria-label="Impersonate"
|
||||
[disabled]="!canImpersonate(account)"
|
||||
(click)="impersonate(account)">
|
||||
<mat-icon>switch_account</mat-icon>
|
||||
</button>
|
||||
<button
|
||||
mat-icon-button
|
||||
type="button"
|
||||
aria-label="Deaktivieren"
|
||||
[disabled]="account.is_current || account.deleted"
|
||||
(click)="deleteAccount(account)">
|
||||
<mat-icon>delete</mat-icon>
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
} @empty {
|
||||
<tr>
|
||||
<td colspan="6" class="empty">Keine Accounts gefunden.</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="pagination">
|
||||
<button
|
||||
mat-button
|
||||
type="button"
|
||||
[disabled]="!canPageBack"
|
||||
(click)="loadAccounts(page - 1)">
|
||||
<mat-icon>chevron_left</mat-icon>
|
||||
Zurück
|
||||
</button>
|
||||
<span>Seite {{ page + 1 }}</span>
|
||||
<button
|
||||
mat-button
|
||||
type="button"
|
||||
[disabled]="!canPageForward"
|
||||
(click)="loadAccounts(page + 1)">
|
||||
Weiter
|
||||
<mat-icon>chevron_right</mat-icon>
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
<div
|
||||
style="
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
">
|
||||
<app-query-param-input
|
||||
queryParamKey="search"
|
||||
label="Nach Name oder E-Mail suchen"
|
||||
style="width: 30%" />
|
||||
<app-query-param-selector
|
||||
queryParamKey="organization_id"
|
||||
[options]="selectorOptions"
|
||||
label="Organisation" />
|
||||
</div>
|
||||
<mat-card appearance="outlined">
|
||||
<mat-card-content>
|
||||
<app-data-table [columns]="accountColumns" [data]="accountPage().items" />
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
<app-query-param-paginator [total]="accountPage().total" />
|
||||
</section>
|
||||
|
||||
<ng-template #accountRoleTmp let-row>
|
||||
<span class="role">{{ row.role | role }}</span>
|
||||
</ng-template>
|
||||
|
||||
<ng-template #accountStatusTmp let-row>
|
||||
<span class="status" [class.status--deleted]="row.deleted">
|
||||
{{ row.deleted ? 'deleted' : 'active' }}
|
||||
</span>
|
||||
</ng-template>
|
||||
|
||||
<ng-template #accountActionsTmp let-row>
|
||||
<div class="row-actions">
|
||||
<button
|
||||
mat-icon-button
|
||||
type="button"
|
||||
aria-label="Bearbeiten"
|
||||
(click)="startEdit(row)">
|
||||
<mat-icon>edit</mat-icon>
|
||||
</button>
|
||||
<button
|
||||
mat-icon-button
|
||||
type="button"
|
||||
aria-label="Impersonate"
|
||||
[disabled]="!canImpersonate(row)"
|
||||
(click)="impersonate(row)">
|
||||
<mat-icon>switch_account</mat-icon>
|
||||
</button>
|
||||
<button
|
||||
mat-icon-button
|
||||
type="button"
|
||||
aria-label="Deaktivieren"
|
||||
[disabled]="row.is_current || row.deleted"
|
||||
(click)="deleteAccount(row)">
|
||||
<mat-icon>delete</mat-icon>
|
||||
</button>
|
||||
</div>
|
||||
</ng-template>
|
||||
|
||||
@@ -145,3 +145,8 @@ tr.deleted {
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
|
||||
mat-card,
|
||||
mat-paginator {
|
||||
background-color: var(--sg-background);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { Component, OnInit, inject } from '@angular/core';
|
||||
import {
|
||||
Component,
|
||||
OnInit,
|
||||
TemplateRef,
|
||||
effect,
|
||||
inject,
|
||||
input,
|
||||
viewChild,
|
||||
} from '@angular/core';
|
||||
import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
@@ -10,9 +18,8 @@ import { MatSnackBar, MatSnackBarModule } from '@angular/material/snack-bar';
|
||||
import { MatDialog, MatDialogModule } from '@angular/material/dialog';
|
||||
import { Router } from '@angular/router';
|
||||
import { finalize } from 'rxjs';
|
||||
import { AccountManagementService } from '../../shared/services/account-management.service';
|
||||
import type {
|
||||
AccountProfile,
|
||||
import {
|
||||
AccountManagementService,
|
||||
AccountRole,
|
||||
OrganizationProfile,
|
||||
} from '../../shared/services/account-management.service';
|
||||
@@ -22,6 +29,18 @@ import type {
|
||||
AccountDialogResult,
|
||||
} from './account-dialog.component';
|
||||
import { RolePipe } from '../../shared/pipes/role.pipe';
|
||||
import {
|
||||
GenericColumn,
|
||||
DataTableComponent,
|
||||
} from '../../shared/ui/data-table/data-table.component';
|
||||
import { QueryParamPaginatorComponent } from '../../shared/ui/query-param-paginator/query-param-paginator.component';
|
||||
import { QueryParamInputComponent } from '../../shared/ui/query-param-input/query-param-input.component';
|
||||
import {
|
||||
QueryParamSelectorComponent,
|
||||
SelectorOption,
|
||||
} from '../../shared/ui/query-param-selector/query-param-selector.component';
|
||||
import { MatCardModule } from '@angular/material/card';
|
||||
import { AccountPage, AccountProfile } from '../../api';
|
||||
|
||||
@Component({
|
||||
selector: 'app-accounts',
|
||||
@@ -36,6 +55,11 @@ import { RolePipe } from '../../shared/pipes/role.pipe';
|
||||
MatSnackBarModule,
|
||||
MatDialogModule,
|
||||
RolePipe,
|
||||
DataTableComponent,
|
||||
QueryParamPaginatorComponent,
|
||||
QueryParamInputComponent,
|
||||
QueryParamSelectorComponent,
|
||||
MatCardModule,
|
||||
],
|
||||
templateUrl: './accounts.component.html',
|
||||
styleUrl: './accounts.component.scss',
|
||||
@@ -67,9 +91,63 @@ export class AccountsComponent implements OnInit {
|
||||
organizationId: new FormControl<string>(''),
|
||||
});
|
||||
|
||||
accountColumns: GenericColumn<AccountProfile>[] = [];
|
||||
accountRoleTmp = viewChild.required<TemplateRef<any>>('accountRoleTmp');
|
||||
accountStatusTmp = viewChild.required<TemplateRef<any>>('accountStatusTmp');
|
||||
accountActionsTmp = viewChild.required<TemplateRef<any>>('accountActionsTmp');
|
||||
|
||||
selectorOptions: SelectorOption[] = [];
|
||||
|
||||
accountPage = input.required<AccountPage>();
|
||||
|
||||
constructor() {
|
||||
effect(() => {
|
||||
console.log('accountPage changed:', this.accountPage());
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.loadOrganizations();
|
||||
this.loadAccounts();
|
||||
this.accountColumns = [
|
||||
{
|
||||
id: 'name',
|
||||
header: 'Name',
|
||||
type: 'accessor',
|
||||
accessorKey: 'name',
|
||||
},
|
||||
{
|
||||
id: 'email',
|
||||
header: 'E-Mail',
|
||||
type: 'accessor',
|
||||
accessorKey: 'email',
|
||||
},
|
||||
{
|
||||
id: 'organization_name',
|
||||
header: 'Organisation',
|
||||
type: 'accessor',
|
||||
accessorKey: 'organization_name',
|
||||
},
|
||||
{
|
||||
id: 'role',
|
||||
header: 'Rolle',
|
||||
type: 'accessor',
|
||||
accessorKey: 'role',
|
||||
cellTemplate: this.accountRoleTmp(),
|
||||
},
|
||||
{
|
||||
id: 'status',
|
||||
header: 'Status',
|
||||
type: 'display',
|
||||
cellTemplate: this.accountStatusTmp(),
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
header: 'Aktionen',
|
||||
type: 'display',
|
||||
cellTemplate: this.accountActionsTmp(),
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
protected loadAccounts(page = this.page): void {
|
||||
@@ -101,6 +179,10 @@ export class AccountsComponent implements OnInit {
|
||||
this.accountService.listOrganizations().subscribe({
|
||||
next: (organizations) => {
|
||||
this.organizations = organizations;
|
||||
this.selectorOptions = organizations.map((org) => ({
|
||||
value: org.id,
|
||||
display_name: org.name,
|
||||
}));
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -199,28 +281,24 @@ export class AccountsComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
protected impersonate(account: AccountProfile): void {
|
||||
protected async impersonate(account: AccountProfile): Promise<void> {
|
||||
if (!this.canImpersonate(account)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.credentialService.impersonateAccount(account.id).subscribe({
|
||||
next: () => {
|
||||
this.snackBar.open(`Impersonation aktiv: ${account.name}`, 'OK', {
|
||||
duration: 4000,
|
||||
});
|
||||
this.router.navigate(['/dashboard']);
|
||||
},
|
||||
error: () => {
|
||||
this.snackBar.open(
|
||||
'Impersonation konnte nicht gestartet werden.',
|
||||
'OK',
|
||||
{
|
||||
duration: 5000,
|
||||
},
|
||||
);
|
||||
},
|
||||
});
|
||||
try {
|
||||
await this.credentialService.impersonateAccount(account.id);
|
||||
this.snackBar.open(`Impersonation aktiv: ${account.name}`, 'OK', {
|
||||
duration: 4000,
|
||||
});
|
||||
this.router.navigate(['/dashboard']);
|
||||
} catch (error) {
|
||||
console.error('Impersonation failed:', error);
|
||||
this.snackBar.open('Impersonation konnte nicht gestartet werden.', 'OK', {
|
||||
duration: 5000,
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
protected get canPageBack(): boolean {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Component, OnDestroy, OnInit } from '@angular/core';
|
||||
import { Component, effect, OnDestroy } from '@angular/core';
|
||||
import {
|
||||
FormControl,
|
||||
FormGroup,
|
||||
@@ -11,7 +11,7 @@ import { MatInputModule } from '@angular/material/input';
|
||||
import { CredentialService } from '../../shared/services/credential.service';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { finalize, Subscription } from 'rxjs';
|
||||
import { Subscription } from 'rxjs';
|
||||
import { MatSnackBar, MatSnackBarModule } from '@angular/material/snack-bar';
|
||||
import { Router, RouterLink } from '@angular/router';
|
||||
import { HttpErrorResponse } from '@angular/common/http';
|
||||
@@ -34,7 +34,7 @@ type LoginStep = 'credentials' | 'otk';
|
||||
styleUrl: './app-login.component.scss',
|
||||
standalone: true,
|
||||
})
|
||||
export class AppLoginComponent implements OnInit, OnDestroy {
|
||||
export class AppLoginComponent implements OnDestroy {
|
||||
credentialsForm = new FormGroup({
|
||||
email: new FormControl<string>('', [Validators.required, Validators.email]),
|
||||
password: new FormControl<string>('', [
|
||||
@@ -64,28 +64,21 @@ export class AppLoginComponent implements OnInit, OnDestroy {
|
||||
protected credentialService: CredentialService,
|
||||
protected router: Router,
|
||||
protected snackBar: MatSnackBar,
|
||||
) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.subscription = this.credentialService.validating.subscribe(
|
||||
(validating) => {
|
||||
if (validating) {
|
||||
this.credentialsForm.disable();
|
||||
this.otkForm.disable();
|
||||
} else {
|
||||
this.credentialsForm.enable();
|
||||
this.otkForm.enable();
|
||||
this.checkEnter();
|
||||
}
|
||||
},
|
||||
);
|
||||
if (!this.credentialService.validating.value) {
|
||||
this.checkEnter();
|
||||
}
|
||||
) {
|
||||
effect(() => {
|
||||
if (this.credentialService.isValidating()) {
|
||||
this.credentialsForm.disable();
|
||||
this.otkForm.disable();
|
||||
} else {
|
||||
this.credentialsForm.enable();
|
||||
this.otkForm.enable();
|
||||
this.checkEnter();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
checkEnter(): void {
|
||||
if (this.credentialService.isAuthenticated.value) {
|
||||
if (this.credentialService.isAuthenticated()) {
|
||||
this.router.navigate(['/dashboard']);
|
||||
}
|
||||
}
|
||||
@@ -98,7 +91,7 @@ export class AppLoginComponent implements OnInit, OnDestroy {
|
||||
this.stopCountdown();
|
||||
}
|
||||
|
||||
requestOtk() {
|
||||
async requestOtk() {
|
||||
if (this.credentialsForm.invalid || this.isSubmitting) {
|
||||
this.credentialsForm.markAllAsTouched();
|
||||
return;
|
||||
@@ -110,39 +103,36 @@ export class AppLoginComponent implements OnInit, OnDestroy {
|
||||
const email = this.credentialsForm.controls.email.value ?? '';
|
||||
const password = this.credentialsForm.controls.password.value ?? '';
|
||||
|
||||
this.credentialService
|
||||
.requestOtk(email, password)
|
||||
.pipe(
|
||||
finalize(() => {
|
||||
this.isSubmitting = false;
|
||||
this.credentialsForm.enable();
|
||||
}),
|
||||
)
|
||||
.subscribe({
|
||||
next: (accountId) => {
|
||||
if (!accountId) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.accountId = accountId;
|
||||
this.currentStep = 'otk';
|
||||
this.otkForm.reset();
|
||||
this.startCountdown();
|
||||
this.snackBar.open(
|
||||
'OTK-Code wurde an die E-Mail-Adresse gesendet.',
|
||||
'OK',
|
||||
{
|
||||
duration: 4000,
|
||||
},
|
||||
);
|
||||
try {
|
||||
const otkResponse = await this.credentialService.requestOtk(
|
||||
email,
|
||||
password,
|
||||
);
|
||||
const accountId = otkResponse.account_id;
|
||||
this.accountId = accountId;
|
||||
this.currentStep = 'otk';
|
||||
this.otkForm.reset();
|
||||
this.startCountdown();
|
||||
this.snackBar.open(
|
||||
'OTK-Code wurde an die E-Mail-Adresse gesendet.',
|
||||
'OK',
|
||||
{
|
||||
duration: 4000,
|
||||
},
|
||||
error: (error: HttpErrorResponse) => {
|
||||
this.credentialService.clearLocalAuthState();
|
||||
this.snackBar.open(this.getLoginErrorMessage(error), 'OK', {
|
||||
duration: 5000,
|
||||
});
|
||||
);
|
||||
} catch (error: unknown) {
|
||||
this.credentialService.clearLocalAuthState();
|
||||
this.snackBar.open(
|
||||
this.getLoginErrorMessage(error as HttpErrorResponse),
|
||||
'OK',
|
||||
{
|
||||
duration: 5000,
|
||||
},
|
||||
});
|
||||
);
|
||||
} finally {
|
||||
this.isSubmitting = false;
|
||||
this.credentialsForm.enable();
|
||||
}
|
||||
}
|
||||
|
||||
resendCode() {
|
||||
@@ -153,7 +143,7 @@ export class AppLoginComponent implements OnInit, OnDestroy {
|
||||
this.requestOtk();
|
||||
}
|
||||
|
||||
login() {
|
||||
async login() {
|
||||
if (this.otkForm.invalid || this.isSubmitting) {
|
||||
this.otkForm.markAllAsTouched();
|
||||
return;
|
||||
@@ -178,29 +168,25 @@ export class AppLoginComponent implements OnInit, OnDestroy {
|
||||
this.isSubmitting = true;
|
||||
this.otkForm.disable();
|
||||
|
||||
const email = this.credentialsForm.controls.email.value ?? '';
|
||||
const code = this.otkForm.controls.code.value ?? '';
|
||||
|
||||
this.credentialService
|
||||
.loginWithOtk(this.accountId, email, code)
|
||||
.pipe(
|
||||
finalize(() => {
|
||||
this.isSubmitting = false;
|
||||
this.otkForm.enable();
|
||||
}),
|
||||
)
|
||||
.subscribe({
|
||||
next: () => {
|
||||
this.stopCountdown();
|
||||
this.router.navigate(['/dashboard']);
|
||||
try {
|
||||
await this.credentialService.loginWithOtk(this.accountId, code);
|
||||
this.stopCountdown();
|
||||
this.router.navigate(['/dashboard']);
|
||||
} catch (error: unknown) {
|
||||
this.credentialService.clearLocalAuthState();
|
||||
this.snackBar.open(
|
||||
this.getLoginErrorMessage(error as HttpErrorResponse),
|
||||
'OK',
|
||||
{
|
||||
duration: 5000,
|
||||
},
|
||||
error: (error: HttpErrorResponse) => {
|
||||
this.credentialService.clearLocalAuthState();
|
||||
this.snackBar.open(this.getLoginErrorMessage(error), 'OK', {
|
||||
duration: 5000,
|
||||
});
|
||||
},
|
||||
});
|
||||
);
|
||||
} finally {
|
||||
this.isSubmitting = false;
|
||||
this.otkForm.enable();
|
||||
}
|
||||
}
|
||||
|
||||
editCredentials() {
|
||||
@@ -240,6 +226,7 @@ export class AppLoginComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
private getLoginErrorMessage(error: HttpErrorResponse): string {
|
||||
console.error('Login error:', error);
|
||||
if (error.status === 401) {
|
||||
return 'E-Mail, Passwort oder OTK-Code ist ungültig.';
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
signal,
|
||||
DestroyRef,
|
||||
OnInit,
|
||||
effect,
|
||||
} from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
||||
@@ -54,7 +55,7 @@ import { InstitutionsService } from '../../api';
|
||||
templateUrl: './app-register.component.html',
|
||||
styleUrl: './app-register.component.scss',
|
||||
})
|
||||
export class AppRegisterComponent implements OnDestroy, OnInit {
|
||||
export class AppRegisterComponent implements OnDestroy {
|
||||
private readonly fb = inject(FormBuilder);
|
||||
protected readonly credentialService = inject(CredentialService);
|
||||
private readonly router = inject(Router);
|
||||
@@ -73,42 +74,37 @@ export class AppRegisterComponent implements OnDestroy, OnInit {
|
||||
showPassword = false;
|
||||
|
||||
constructor() {
|
||||
effect(() => {
|
||||
if (this.credentialService.isValidating()) {
|
||||
this.registerForm.disable();
|
||||
} else {
|
||||
this.registerForm.enable();
|
||||
this.checkEnter();
|
||||
}
|
||||
});
|
||||
|
||||
this.setupInstitutionAutocomplete();
|
||||
}
|
||||
ngOnInit(): void {
|
||||
this.subscription = this.credentialService.validating.subscribe(
|
||||
(validating) => {
|
||||
if (validating) {
|
||||
this.registerForm.disable();
|
||||
} else {
|
||||
this.registerForm.enable();
|
||||
this.checkEnter();
|
||||
}
|
||||
},
|
||||
);
|
||||
if (!this.credentialService.validating) {
|
||||
this.checkEnter();
|
||||
}
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.subscription?.unsubscribe();
|
||||
}
|
||||
|
||||
checkEnter(): void {
|
||||
if (this.credentialService.isAuthenticated.value) {
|
||||
if (this.credentialService.isAuthenticated()) {
|
||||
this.router.navigate(['/dashboard']);
|
||||
}
|
||||
}
|
||||
submit() {
|
||||
if (this.registerForm.valid) {
|
||||
this.credentialService.validating.next(true);
|
||||
this.credentialService.isValidating.set(true);
|
||||
this.registerForm.disable();
|
||||
|
||||
this.subscription = this.credentialService
|
||||
.registerAccount(this.registerForm.value)
|
||||
.subscribe({
|
||||
next: () => {
|
||||
this.credentialService.validating.next(false);
|
||||
this.credentialService.isValidating.set(false);
|
||||
this.snackBar.open(
|
||||
'Konto erfolgreich erstellt! Du kannst Dich jetzt anmelden.',
|
||||
'OK',
|
||||
@@ -117,7 +113,7 @@ export class AppRegisterComponent implements OnDestroy, OnInit {
|
||||
this.router.navigate(['/login']);
|
||||
},
|
||||
error: (err) => {
|
||||
this.credentialService.validating.next(false);
|
||||
this.credentialService.isValidating.set(false);
|
||||
this.registerForm.enable();
|
||||
const message =
|
||||
err.error?.message ||
|
||||
|
||||
Reference in New Issue
Block a user