Si la respuesta (Response) va a ser una página (Page) entonces hay que añadir la petición de entrada (HttpRequest) al contexto de renderizado (RenderContext) para que los componentes puedan consultarla durante la preparación de la página. Por ejemplo para consultar la URL de entrada y decidir si se renderiza o no un componente dado.
75 lines
2 KiB
Rust
75 lines
2 KiB
Rust
use pagetop::prelude::*;
|
|
|
|
pub_handle!(MODULE_USER);
|
|
|
|
pub_locale!("src/locales");
|
|
|
|
mod migration;
|
|
|
|
pub struct User;
|
|
|
|
impl ModuleTrait for User {
|
|
fn handle(&self) -> Handle {
|
|
MODULE_USER
|
|
}
|
|
|
|
fn name(&self) -> String {
|
|
l("module_name")
|
|
}
|
|
|
|
fn description(&self) -> Option<String> {
|
|
Some(l("module_description"))
|
|
}
|
|
|
|
fn configure_service(&self, cfg: &mut server::web::ServiceConfig) {
|
|
cfg.route("/user/login", server::web::get().to(login));
|
|
}
|
|
|
|
fn migrations(&self) -> Vec<MigrationItem> {
|
|
vec![
|
|
migration_item!(m20220312_000001_create_table_role),
|
|
migration_item!(m20220312_000002_create_table_role_permission),
|
|
migration_item!(m20220312_000003_create_table_user),
|
|
migration_item!(m20220312_000004_create_table_user_role),
|
|
]
|
|
}
|
|
}
|
|
|
|
async fn login(request: server::HttpRequest) -> ResultPage<Markup, FatalError> {
|
|
Page::new(request)
|
|
.with_title("Identificación del usuario")
|
|
.with_this_in(
|
|
"region-content",
|
|
Container::new()
|
|
.with_id("welcome")
|
|
.with_component(form_login()),
|
|
)
|
|
.render()
|
|
}
|
|
|
|
fn form_login() -> Form {
|
|
Form::new()
|
|
.with_id("user-login")
|
|
.with_element(
|
|
form_element::Input::textfield()
|
|
.with_name("name")
|
|
.with_label(l("username").as_str())
|
|
.with_help_text(
|
|
t(
|
|
"username_help",
|
|
&args![
|
|
"app" => config::SETTINGS.app.name.to_owned()
|
|
],
|
|
)
|
|
.as_str(),
|
|
)
|
|
.with_autofocus(true),
|
|
)
|
|
.with_element(
|
|
form_element::Input::password()
|
|
.with_name("pass")
|
|
.with_label(l("password").as_str())
|
|
.with_help_text(l("password_help").as_str()),
|
|
)
|
|
.with_element(form_element::Button::submit(l("login").as_str()))
|
|
}
|