Plume/templates/users/new.rs.html
Ana Gelez 8ab690001d Replace the input! macro with an Input builder (#646)
* Replace the input! macro with an Input builder

* Use a BTreeMap instead of an HashMap

Followinf @fdb-hiroshima's advice

* Rename Input::to_html to Input::html

To make clippy happy

* Wrap error messages in red paragraphs
2019-08-27 16:50:24 +02:00

46 lines
1.8 KiB
HTML

@use templates::base;
@use template_utils::*;
@use routes::user::NewUserForm;
@use validator::{ValidationErrors, ValidationErrorsKind};
@use routes::*;
@use std::borrow::Cow;
@(ctx: BaseContext, enabled: bool, form: &NewUserForm, errors: ValidationErrors)
@:base(ctx, i18n!(ctx.1, "Create your account"), {}, {}, {
@if enabled {
<h1>@i18n!(ctx.1, "Create an account")</h1>
<form method="post" action="@uri!(user::create)">
@if let Some(ValidationErrorsKind::Field(errs)) = errors.clone().errors().get("__all__") {
<p class="error">@errs[0].message.as_ref().unwrap_or(&Cow::from("Unknown error"))</p>
}
@(Input::new("username", i18n!(ctx.1, ""))
.default(&form.username)
.error(&errors)
.set_prop("minlength", 1)
.html(ctx.1))
@(Input::new("email", i18n!(ctx.1, ""))
.default(&form.email)
.error(&errors)
.set_prop("minlength", 1)
.html(ctx.1))
@(Input::new("password", i18n!(ctx.1, ""))
.default(&form.password)
.error(&errors)
.set_prop("minlength", 8)
.input_type("password")
.html(ctx.1))
@(Input::new("password_confirmation", i18n!(ctx.1, ""))
.default(&form.password_confirmation)
.error(&errors)
.set_prop("minlength", 8)
.input_type("password")
.html(ctx.1))
<input type="submit" value="@i18n!(ctx.1, "Create your account")" />
</form>
} else {
<p class="center">@i18n!(ctx.1, "Apologies, but registrations are closed on this particular instance. You can, however, find a different one.")</p>
}
})