Forms
Thanks to the Deno's builtin Request which contains formData function, handling and working with forms is rather easy.
/**@jsx h */
/**@jsxFrag Fragment */
import { Props, h, Fragment, redirect } from 'https://deno.land/x/atlet@1.2.0/mod.ts'
import { login } from 'legit-auth'
export default function Login(props: Props) {
let message = null
if (props.request.method === 'POST') {
const form = await props.request.formData()
const username = form.get('username')?.toString() ?? null
const password = form.get('password')?.toString() ?? null
if (login(username, password)) {
return redirect('/homepage')
}
message = <p>Wrong username or password.</p>
}
return (
<>
<h1>Login</h1>
{message}
<form method="POST">
<input name="username" type="text" />
<input name="password" type="password" />
<button type="submit">Login</button>
</form>
</>
)
}Result: