import { ChangeDetectionStrategy, Component, computed, inject, signal } from '@angular/core'; import { FormsModule } from '@angular/forms'; import { Router, RouterLink } from '@angular/router'; import { MatIconModule } from '@angular/material/icon'; import { ApiService } from '../../core/api.service'; import { AuthService } from '../../core/auth.service'; import { errorText } from '../../core/models'; import { AuthFrameComponent } from './auth-frame.component'; const NAME = /^[a-z0-9]([a-z0-9._-]{0,62}[a-z0-9])?$/; @Component({ selector: 'app-register', imports: [FormsModule, RouterLink, MatIconModule, AuthFrameComponent], changeDetection: ChangeDetectionStrategy.OnPush, template: ` @if (!loaded()) { Loading… } @else if (!enabled()) { Registration is closed on this server. Ask the administrator for a mailbox. arrow_back BACK TO LOGIN } @else { Address @ @if (domains().length > 1) { @for (d of domains(); track d) { {{ d }} } } @else { {{ domain() }} } Letters, digits, dot, dash, underscore Your name (shown to recipients) Password (8+ characters) {{ show() ? 'visibility_off' : 'visibility' }} Password again {{ show() ? 'visibility_off' : 'visibility' }} @if (error()) { error{{ error() }} } person_add {{ busy() ? 'CREATING…' : 'CREATE MAILBOX' }} Have a mailbox? Log in } ` }) export class RegisterPage { private auth = inject(AuthService); private router = inject(Router); readonly loaded = signal(false); readonly enabled = signal(false); readonly show = signal(false); readonly domains = signal([]); readonly domain = signal(''); readonly local = signal(''); readonly password = signal(''); readonly password2 = signal(''); displayName = ''; readonly busy = signal(false); readonly error = signal(''); readonly localValid = computed(() => NAME.test(this.local())); constructor() { inject(ApiService).config().subscribe({ next: c => { this.enabled.set(c.registrationEnabled); this.domains.set(c.domains); this.domain.set(c.domains[0] ?? ''); this.loaded.set(true); }, error: e => { this.loaded.set(true); this.error.set(errorText(e)); } }); } submit(): void { const problem = !this.localValid() ? 'The address: letters, digits, dot, dash, underscore' : this.password().length < 8 ? 'The password is shorter than 8 characters' : this.password() !== this.password2() ? 'The passwords do not match' : ''; if (problem) { this.error.set(problem); return; } this.busy.set(true); this.error.set(''); this.auth.register(`${this.local()}@${this.domain()}`, this.password(), this.displayName.trim()).subscribe({ next: () => this.router.navigate(['/']), error: e => { this.busy.set(false); this.error.set(errorText(e)); } }); } }
Loading…
Registration is closed on this server. Ask the administrator for a mailbox.
Letters, digits, dot, dash, underscore
error{{ error() }}
Have a mailbox? Log in