Auth forms

oxblade-adminlte Alpha Rust

adminlte::auth.form renders the AdminLTE card for six authentication pages. It renders the form only: your application owns the routes, the controllers, validation, rate limiting and CSRF checks.

AuthKindPHP viewFields
SignInauth/loginemail, password, remember me
Registerauth/registername, email, password, confirmation
RequestResetauth/passwords/emailemail
ResetPassword { token }auth/passwords/resetreset token (hidden), email, password, confirmation
ConfirmPasswordauth/passwords/confirmpassword
VerifyEmailauth/verifynone; a button that resends the email

Render a form

use laravel::view::view;
use oxblade_adminlte::{AuthForm, AuthKind, Layout};
use serde_json::json;

let form = AuthForm::new(AuthKind::SignIn, "/login".parse()?, &csrf_token)?;
let html = view(
    "adminlte::auth.form",
    json!({
        "layout": Layout::default().view("en"),
        "auth": form,
        "brand": "Example",
        "stylesheet_url": stylesheet,
    }),
)
.render()
.map_err(|error| std::io::Error::other(format!("{error:?}")))?;

AuthForm::new returns an error when:

  • the action is not a rooted path on your own site (/login works, https://…/login and /login#x don't): AuthFormError::InvalidAction;
  • the CSRF token, or the reset token for ResetPassword, is empty: AuthFormError::MissingToken.

Every form posts to the action you give it, with the token in a hidden _token field.

After a failed submission

let form = AuthForm::new(AuthKind::Register, "/register".parse()?, &csrf_token)?
    .old(&old_name, &old_email, false)
    .with_error("email", "This email address is already registered.");

old refills name, email and the remember-me box. Passwords are never refilled. with_error puts a plain-text message under one visible field and marks it with aria-invalid and aria-describedby. Messages are escaped.

Not included

  • Translated titles and labels. The form text is English for now.
  • The lock screen, the auth page layout options and the PHP auth routes.
  • Links between the forms, such as "Forgot your password?" or "Register".

These are listed as planned in parity.toml.