import m, {MithrilComponent} from '@garage44/mithril' import {Alert, Button, Card, FieldText} from '@garage44/mithril/components' import {validation, validations} from '@garage44/mithril/validation' import {$s} from '@/app' import {ProviderChoices} from '@/components/elements/providers/providers' import {ADMIN} from '@/lib/base' import {bind, local} from '@/lib/reactive' import {register, whatIsMissing} from '@/lib/signup' /** * Make an account. * * Everything about this screen is arranged around one fact: the account is not * usable when the form is submitted. So there is no "you're in" and no redirect * to a signed-in page — it swaps itself for the "check your inbox" panel, which * is the actual state of the world and the only place the re-send button makes * sense. */ export class Register extends MithrilComponent { s = local({busy: false, email: '', password: '', sent: false, username: ''}) /* * The per-field half of `whatIsMissing`, with its sentences, so each problem * shows under the field it is about. `whatIsMissing` stays the submit gate * (it is the tested copy of the server's rules); these only decide where the * sentence goes. The limits are read from `$s.registration` when a rule runs, * not when it is built, because the rules arrive after this component may * have been constructed. */ v = validations({ email: validation(bind(this.s, 'email')) .required('That does not look like an email address.') .check((value) => { // Deliberately shallow — see `whatIsMissing`. const address = value.trim() const at = address.lastIndexOf('@') return at >= 1 && address.slice(at + 1).includes('.') }, 'That does not look like an email address.'), password: validation(bind(this.s, 'password')) .required() .rule((value) => { const min = $s.registration?.min_password_length ?? 0 return value.length >= min ? null : `The password needs at least ${min} characters.` }), username: validation(bind(this.s, 'username')) .required('Pick a username.') .rule((value) => { const max = $s.registration?.max_username_length ?? Infinity return value.trim().length <= max ? null : `That username is longer than ${max} characters.` }), }) view() { const s = this.s const rules = $s.registration if (rules === undefined) { return (
Asking the server whether it takes registrations…
Nothing arrived? It may be in a spam folder.{' '} Send another.