forked from TWS/kalkutago
Rename user -> users
This commit is contained in:
parent
cf8380db35
commit
149a936638
|
@ -52,7 +52,7 @@ pub(super) async fn sign_up(
|
|||
user_data: Json<LoginData>,
|
||||
cookies: &CookieJar<'_>,
|
||||
) -> ApiResult<()> {
|
||||
let user_data = user::ActiveModel::new(&user_data.name, &user_data.password)?
|
||||
let user_data = users::ActiveModel::new(&user_data.name, &user_data.password)?
|
||||
.insert(db as &DatabaseConnection)
|
||||
.await
|
||||
.map_err(Error::from)?;
|
||||
|
|
|
@ -31,7 +31,7 @@ pub(super) async fn all_tracks(
|
|||
async fn get_track_check_user(
|
||||
db: &DatabaseConnection,
|
||||
track_id: i32,
|
||||
user: &user::Model,
|
||||
user: &users::Model,
|
||||
) -> Result<Json<tracks::Model>, Either<Status, api::ErrorResponder>> {
|
||||
if let Some(Some(user)) = user
|
||||
.find_related(Tracks)
|
||||
|
|
|
@ -6,5 +6,5 @@ pub mod groups;
|
|||
pub mod ticks;
|
||||
pub mod track2_groups;
|
||||
pub mod tracks;
|
||||
pub mod user;
|
||||
pub mod user_tracks;
|
||||
pub mod users;
|
||||
|
|
|
@ -4,5 +4,5 @@ pub use super::groups::Entity as Groups;
|
|||
pub use super::ticks::Entity as Ticks;
|
||||
pub use super::track2_groups::Entity as Track2Groups;
|
||||
pub use super::tracks::Entity as Tracks;
|
||||
pub use super::user::Entity as User;
|
||||
pub use super::user_tracks::Entity as UserTracks;
|
||||
pub use super::users::Entity as Users;
|
||||
|
|
|
@ -46,9 +46,9 @@ impl Related<super::user_tracks::Entity> for Entity {
|
|||
}
|
||||
}
|
||||
|
||||
impl Related<super::user::Entity> for Entity {
|
||||
impl Related<super::users::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
super::user_tracks::Relation::User.def()
|
||||
super::user_tracks::Relation::Users.def()
|
||||
}
|
||||
fn via() -> Option<RelationDef> {
|
||||
Some(super::user_tracks::Relation::Tracks.def().rev())
|
||||
|
|
|
@ -22,13 +22,13 @@ pub enum Relation {
|
|||
)]
|
||||
Tracks,
|
||||
#[sea_orm(
|
||||
belongs_to = "super::user::Entity",
|
||||
belongs_to = "super::users::Entity",
|
||||
from = "Column::UserId",
|
||||
to = "super::user::Column::Id",
|
||||
to = "super::users::Column::Id",
|
||||
on_update = "NoAction",
|
||||
on_delete = "NoAction"
|
||||
)]
|
||||
User,
|
||||
Users,
|
||||
}
|
||||
|
||||
impl Related<super::tracks::Entity> for Entity {
|
||||
|
@ -37,9 +37,9 @@ impl Related<super::tracks::Entity> for Entity {
|
|||
}
|
||||
}
|
||||
|
||||
impl Related<super::user::Entity> for Entity {
|
||||
impl Related<super::users::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::User.def()
|
||||
Relation::Users.def()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ use std::default::default;
|
|||
use bcrypt::*;
|
||||
// TODO Add option for argon2 https://docs.rs/argon2/latest/argon2/
|
||||
use either::Either::{self, Left, Right};
|
||||
use rocket::response::status::Unauthorized;
|
||||
use rocket::http::Status;
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
@ -17,7 +17,7 @@ use crate::{
|
|||
use super::tracks;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
|
||||
#[sea_orm(table_name = "user")]
|
||||
#[sea_orm(table_name = "users")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key)]
|
||||
#[serde(skip_deserializing)]
|
||||
|
@ -43,7 +43,7 @@ impl Related<super::tracks::Entity> for Entity {
|
|||
}
|
||||
|
||||
fn via() -> Option<RelationDef> {
|
||||
Some(super::user_tracks::Relation::User.def().rev())
|
||||
Some(super::user_tracks::Relation::Users.def().rev())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,11 +65,8 @@ impl ActiveModel {
|
|||
impl Model {
|
||||
pub fn check_password(
|
||||
self,
|
||||
password: String,
|
||||
) -> std::result::Result<Self, Either<Unauthorized<()>, ErrorResponder>> {
|
||||
match verify(password, &self.password_hash) {
|
||||
Ok(true) => Ok(self),
|
||||
Ok(false) => Err(Left(Unauthorized(None))),
|
||||
Err(err) => Err(Right(Error::from(err).into())),
|
||||
}
|
||||
}
|
|
@ -9,17 +9,17 @@ impl MigrationTrait for Migration {
|
|||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(User::Table)
|
||||
.table(Users::Table)
|
||||
.if_not_exists()
|
||||
.col(
|
||||
ColumnDef::new(User::Id)
|
||||
ColumnDef::new(Users::Id)
|
||||
.integer()
|
||||
.not_null()
|
||||
.auto_increment()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(ColumnDef::new(User::Name).string().not_null())
|
||||
.col(ColumnDef::new(User::PasswordHash).string().not_null())
|
||||
.col(ColumnDef::new(Users::Name).string().unique_key().not_null())
|
||||
.col(ColumnDef::new(Users::PasswordHash).string().not_null())
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
|
@ -27,14 +27,14 @@ impl MigrationTrait for Migration {
|
|||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(User::Table).to_owned())
|
||||
.drop_table(Table::drop().table(Users::Table).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
/// Learn more at https://docs.rs/sea-query#iden
|
||||
#[derive(Iden)]
|
||||
pub(crate) enum User {
|
||||
pub(crate) enum Users {
|
||||
Table,
|
||||
Id,
|
||||
Name,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use super::{
|
||||
m20230606_000001_create_tracks_table::Tracks, m20230626_083036_create_users_table::User,
|
||||
m20230606_000001_create_tracks_table::Tracks, m20230626_083036_create_users_table::Users,
|
||||
};
|
||||
use sea_orm_migration::prelude::*;
|
||||
|
||||
|
@ -27,7 +27,7 @@ impl MigrationTrait for Migration {
|
|||
ForeignKey::create()
|
||||
.name("fk-user_tracks-user_id")
|
||||
.from(UserTracks::Table, UserTracks::UserId)
|
||||
.to(User::Table, User::Id),
|
||||
.to(Users::Table, Users::Id),
|
||||
)
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
|
|
Loading…
Reference in a new issue