local db = sqlite("dk")

local username = string.trim(ctx.form.username)
if username == "" or db:exists("users", "username = :u COLLATE NOCASE", {u = username}) then
	return "username required and must be unique"
end

local email = string.trim(ctx.form.email)
if sanitize_email(email) == "" or db:exists("users", "email = :e COLLATE NOCASE", {e = email}) then
	return "email required, must be valid format, and must be unique"
end

if ctx.form.password == "" then
	return "password required"
end

db:insert("users", {
	username = username,
	email = email,
	password = password_hash(ctx.form.password),
	attributes_id = 0
})

return "Account registered!"
