import m, {MithrilComponent} from '@garage44/mithril' import {Button, Card, FieldText} from '@garage44/mithril/components' import {required, validation, validations} from '@garage44/mithril/validation' import {ProviderChoices} from '@/components/elements/providers/providers' import {bind, local} from '@/lib/reactive' import {playerSignIn} from '@/lib/signup' interface SignInAttrs { /** What signing in leads to, under the title. */ hint: string title: string } /** * A player's sign-in card: the person's own session (`$s.signup`), for the pages * that are the account's rather than the operator's — `/buildings` and `/tokens`. * Lifted out of the buildings page when the tokens page needed the same form. */ export class PlayerSignIn extends MithrilComponent { s = local({busy: false, password: '', username: ''}) v = validations({ password: validation(bind(this.s, 'password'), [required]), username: validation(bind(this.s, 'username'), [required]), }) submit = async (e: Event) => { e.preventDefault() const s = this.s if (s.busy || !this.v.$validate()) { return } s.busy = true const ok = await playerSignIn(s.username, s.password) s.busy = false if (ok) { s.password = '' this.v.password.reset() } } view(vnode: m.Vnode) { const s = this.s return ( // A real
, so the phone keyboard shows a Go key and Enter submits.

{vnode.attrs.hint}

{ e.preventDefault() m.route.set('/forgot') }} > Forgot your password?

) } }