Actualiza formato del código aplicando cargo fmt
This commit is contained in:
parent
4b5caf06a7
commit
e6ea59785e
75 changed files with 1069 additions and 1160 deletions
|
|
@ -37,12 +37,12 @@ impl ModuleTrait for User {
|
|||
|
||||
async fn login() -> app::Result<Markup> {
|
||||
Page::new()
|
||||
.with_title(
|
||||
"Identificación del usuario"
|
||||
)
|
||||
.add_to("content", Container::new()
|
||||
.with_id("welcome")
|
||||
.with_component(form_login())
|
||||
.with_title("Identificación del usuario")
|
||||
.add_to(
|
||||
"content",
|
||||
Container::new()
|
||||
.with_id("welcome")
|
||||
.with_component(form_login()),
|
||||
)
|
||||
.render()
|
||||
}
|
||||
|
|
@ -50,18 +50,26 @@ async fn login() -> app::Result<Markup> {
|
|||
fn form_login() -> Form {
|
||||
Form::new()
|
||||
.with_id("user-login")
|
||||
.with_element(form::Input::textfield()
|
||||
.with_name("name")
|
||||
.with_label(l("username").as_str())
|
||||
.with_help_text(t("username_help", &args![
|
||||
"app" => SETTINGS.app.name.to_owned()
|
||||
]).as_str())
|
||||
.with_autofocus(true)
|
||||
.with_element(
|
||||
form::Input::textfield()
|
||||
.with_name("name")
|
||||
.with_label(l("username").as_str())
|
||||
.with_help_text(
|
||||
t(
|
||||
"username_help",
|
||||
&args![
|
||||
"app" => SETTINGS.app.name.to_owned()
|
||||
],
|
||||
)
|
||||
.as_str(),
|
||||
)
|
||||
.with_autofocus(true),
|
||||
)
|
||||
.with_element(form::Input::password()
|
||||
.with_name("pass")
|
||||
.with_label(l("password").as_str())
|
||||
.with_help_text(l("password_help").as_str())
|
||||
.with_element(
|
||||
form::Input::password()
|
||||
.with_name("pass")
|
||||
.with_label(l("password").as_str())
|
||||
.with_help_text(l("password_help").as_str()),
|
||||
)
|
||||
.with_element(form::Button::submit(l("login").as_str()))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,51 +14,57 @@ pub_migration!(Migration);
|
|||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager.create_table(Table::create()
|
||||
.table(Role::Table)
|
||||
.if_not_exists()
|
||||
.col(ColumnDef::new(Role::Rid)
|
||||
.unsigned()
|
||||
.not_null()
|
||||
.auto_increment()
|
||||
.primary_key()
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(Role::Table)
|
||||
.if_not_exists()
|
||||
.col(
|
||||
ColumnDef::new(Role::Rid)
|
||||
.unsigned()
|
||||
.not_null()
|
||||
.auto_increment()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(Role::Name)
|
||||
.string_len(64)
|
||||
.not_null()
|
||||
.unique_key(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(Role::Weight)
|
||||
.integer()
|
||||
.not_null()
|
||||
.default(10),
|
||||
)
|
||||
// INDEXES.
|
||||
.index(
|
||||
Index::create()
|
||||
.name("weight-name")
|
||||
.col(Role::Weight)
|
||||
.col(Role::Name),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.col(ColumnDef::new(Role::Name)
|
||||
.string_len(64)
|
||||
.not_null()
|
||||
.unique_key()
|
||||
)
|
||||
.col(ColumnDef::new(Role::Weight)
|
||||
.integer()
|
||||
.not_null()
|
||||
.default(10)
|
||||
)
|
||||
// INDEXES.
|
||||
.index(Index::create()
|
||||
.name("weight-name")
|
||||
.col(Role::Weight)
|
||||
.col(Role::Name)
|
||||
)
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
.await?;
|
||||
|
||||
// Built-in roles.
|
||||
app::db::exec::<InsertStatement>(Query::insert()
|
||||
.into_table(Role::Table)
|
||||
.columns(vec![Role::Name, Role::Weight])
|
||||
.values_panic(vec!["anonymous".into(), "1".into()])
|
||||
.values_panic(vec!["authenticated".into(), "2".into()])
|
||||
.values_panic(vec!["administrator".into(), "3".into()])
|
||||
app::db::exec::<InsertStatement>(
|
||||
Query::insert()
|
||||
.into_table(Role::Table)
|
||||
.columns(vec![Role::Name, Role::Weight])
|
||||
.values_panic(vec!["anonymous".into(), "1".into()])
|
||||
.values_panic(vec!["authenticated".into(), "2".into()])
|
||||
.values_panic(vec!["administrator".into(), "3".into()]),
|
||||
)
|
||||
.await.map(|_| ())
|
||||
.await
|
||||
.map(|_| ())
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager.drop_table(Table::drop()
|
||||
.table(Role::Table)
|
||||
.to_owned()
|
||||
)
|
||||
.await
|
||||
manager
|
||||
.drop_table(Table::drop().table(Role::Table).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,50 +9,55 @@ enum RolePermission {
|
|||
}
|
||||
|
||||
#[derive(Iden)]
|
||||
enum Role { Table, Rid, /* ... */ }
|
||||
enum Role {
|
||||
Table,
|
||||
Rid,
|
||||
/* ... */
|
||||
}
|
||||
|
||||
pub_migration!(Migration);
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager.create_table(Table::create()
|
||||
.table(RolePermission::Table)
|
||||
.if_not_exists()
|
||||
.col(ColumnDef::new(RolePermission::Rid)
|
||||
.unsigned()
|
||||
.not_null()
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(RolePermission::Table)
|
||||
.if_not_exists()
|
||||
.col(ColumnDef::new(RolePermission::Rid).unsigned().not_null())
|
||||
.col(
|
||||
ColumnDef::new(RolePermission::Permission)
|
||||
.string_len(128)
|
||||
.not_null(),
|
||||
)
|
||||
// INDEXES.
|
||||
.primary_key(
|
||||
Index::create()
|
||||
.col(RolePermission::Rid)
|
||||
.col(RolePermission::Permission),
|
||||
)
|
||||
.index(
|
||||
Index::create()
|
||||
.name("permission")
|
||||
.col(RolePermission::Permission),
|
||||
)
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk_role_permission-rid")
|
||||
.from(RolePermission::Table, RolePermission::Rid)
|
||||
.to(Role::Table, Role::Rid)
|
||||
.on_delete(ForeignKeyAction::Restrict)
|
||||
.on_update(ForeignKeyAction::Restrict),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.col(ColumnDef::new(RolePermission::Permission)
|
||||
.string_len(128)
|
||||
.not_null()
|
||||
)
|
||||
// INDEXES.
|
||||
.primary_key(Index::create()
|
||||
.col(RolePermission::Rid)
|
||||
.col(RolePermission::Permission)
|
||||
)
|
||||
.index(Index::create()
|
||||
.name("permission")
|
||||
.col(RolePermission::Permission)
|
||||
)
|
||||
.foreign_key(ForeignKey::create()
|
||||
.name("fk_role_permission-rid")
|
||||
.from(RolePermission::Table, RolePermission::Rid)
|
||||
.to(Role::Table, Role::Rid)
|
||||
.on_delete(ForeignKeyAction::Restrict)
|
||||
.on_update(ForeignKeyAction::Restrict)
|
||||
)
|
||||
.to_owned()
|
||||
)
|
||||
.await
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager.drop_table(Table::drop()
|
||||
.table(RolePermission::Table)
|
||||
.to_owned()
|
||||
)
|
||||
.await
|
||||
manager
|
||||
.drop_table(Table::drop().table(RolePermission::Table).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,59 +21,39 @@ pub_migration!(Migration);
|
|||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager.create_table(Table::create()
|
||||
.table(User::Table)
|
||||
.if_not_exists()
|
||||
.col(ColumnDef::new(User::Uid)
|
||||
.unsigned()
|
||||
.not_null()
|
||||
.primary_key()
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(User::Table)
|
||||
.if_not_exists()
|
||||
.col(
|
||||
ColumnDef::new(User::Uid)
|
||||
.unsigned()
|
||||
.not_null()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(User::Name)
|
||||
.string_len(60)
|
||||
.not_null()
|
||||
.unique_key(),
|
||||
)
|
||||
.col(ColumnDef::new(User::Pass).string_len(128).not_null())
|
||||
.col(ColumnDef::new(User::Mail).string_len(255))
|
||||
.col(ColumnDef::new(User::Created).timestamp().not_null())
|
||||
.col(ColumnDef::new(User::Changed).timestamp().not_null())
|
||||
.col(ColumnDef::new(User::Access).timestamp().not_null())
|
||||
.col(ColumnDef::new(User::Login).timestamp().not_null())
|
||||
.col(ColumnDef::new(User::Status).boolean().not_null())
|
||||
.col(ColumnDef::new(User::Timezone).string_len(32))
|
||||
.to_owned(),
|
||||
)
|
||||
.col(ColumnDef::new(User::Name)
|
||||
.string_len(60)
|
||||
.not_null()
|
||||
.unique_key()
|
||||
)
|
||||
.col(ColumnDef::new(User::Pass)
|
||||
.string_len(128)
|
||||
.not_null()
|
||||
)
|
||||
.col(ColumnDef::new(User::Mail)
|
||||
.string_len(255)
|
||||
)
|
||||
.col(ColumnDef::new(User::Created)
|
||||
.timestamp()
|
||||
.not_null()
|
||||
)
|
||||
.col(ColumnDef::new(User::Changed)
|
||||
.timestamp()
|
||||
.not_null()
|
||||
)
|
||||
.col(ColumnDef::new(User::Access)
|
||||
.timestamp()
|
||||
.not_null()
|
||||
)
|
||||
.col(ColumnDef::new(User::Login)
|
||||
.timestamp()
|
||||
.not_null()
|
||||
)
|
||||
.col(ColumnDef::new(User::Status)
|
||||
.boolean()
|
||||
.not_null()
|
||||
)
|
||||
.col(ColumnDef::new(User::Timezone)
|
||||
.string_len(32)
|
||||
)
|
||||
.to_owned()
|
||||
)
|
||||
.await
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager.drop_table(Table::drop()
|
||||
.table(User::Table)
|
||||
.to_owned()
|
||||
)
|
||||
.await
|
||||
manager
|
||||
.drop_table(Table::drop().table(User::Table).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,56 +9,57 @@ enum UserRole {
|
|||
}
|
||||
|
||||
#[derive(Iden)]
|
||||
enum User { Table, Uid, /* ... */ }
|
||||
enum User {
|
||||
Table,
|
||||
Uid,
|
||||
/* ... */
|
||||
}
|
||||
|
||||
#[derive(Iden)]
|
||||
enum Role { Table, Rid, /* ... */ }
|
||||
enum Role {
|
||||
Table,
|
||||
Rid,
|
||||
/* ... */
|
||||
}
|
||||
|
||||
pub_migration!(Migration);
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager.create_table(Table::create()
|
||||
.table(UserRole::Table)
|
||||
.if_not_exists()
|
||||
.col(ColumnDef::new(UserRole::Uid)
|
||||
.unsigned()
|
||||
.not_null()
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(UserRole::Table)
|
||||
.if_not_exists()
|
||||
.col(ColumnDef::new(UserRole::Uid).unsigned().not_null())
|
||||
.col(ColumnDef::new(UserRole::Rid).unsigned().not_null())
|
||||
// INDEXES.
|
||||
.primary_key(Index::create().col(UserRole::Uid).col(UserRole::Rid))
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk_user_role-uid")
|
||||
.from(UserRole::Table, UserRole::Uid)
|
||||
.to(User::Table, User::Uid)
|
||||
.on_delete(ForeignKeyAction::Restrict)
|
||||
.on_update(ForeignKeyAction::Restrict),
|
||||
)
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk_user_role-rid")
|
||||
.from(UserRole::Table, UserRole::Rid)
|
||||
.to(Role::Table, Role::Rid)
|
||||
.on_delete(ForeignKeyAction::Restrict)
|
||||
.on_update(ForeignKeyAction::Restrict),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.col(ColumnDef::new(UserRole::Rid)
|
||||
.unsigned()
|
||||
.not_null()
|
||||
)
|
||||
// INDEXES.
|
||||
.primary_key(Index::create()
|
||||
.col(UserRole::Uid)
|
||||
.col(UserRole::Rid)
|
||||
)
|
||||
.foreign_key(ForeignKey::create()
|
||||
.name("fk_user_role-uid")
|
||||
.from(UserRole::Table, UserRole::Uid)
|
||||
.to(User::Table, User::Uid)
|
||||
.on_delete(ForeignKeyAction::Restrict)
|
||||
.on_update(ForeignKeyAction::Restrict)
|
||||
)
|
||||
.foreign_key(ForeignKey::create()
|
||||
.name("fk_user_role-rid")
|
||||
.from(UserRole::Table, UserRole::Rid)
|
||||
.to(Role::Table, Role::Rid)
|
||||
.on_delete(ForeignKeyAction::Restrict)
|
||||
.on_update(ForeignKeyAction::Restrict)
|
||||
)
|
||||
.to_owned()
|
||||
)
|
||||
.await
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager.drop_table(Table::drop()
|
||||
.table(UserRole::Table)
|
||||
.to_owned()
|
||||
)
|
||||
.await
|
||||
manager
|
||||
.drop_table(Table::drop().table(UserRole::Table).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue