diff --git a/.env b/.env index 8728934..b848290 100644 --- a/.env +++ b/.env @@ -1,2 +1 @@ -DATABASE_URL=postgres://lyj:1325479Lyj!@47.95.198.7:13207/demo_rs - +DATABASE_URL=postgres://lyj:B3a5kL9z!qQ@47.95.198.7:31000/chuanyue_gm \ No newline at end of file diff --git a/api/src/controller/account.rs b/api/src/controller/account.rs index d9918bf..c17ad7a 100644 --- a/api/src/controller/account.rs +++ b/api/src/controller/account.rs @@ -29,3 +29,8 @@ pub async fn refresh_token( validator::validate_params(&refresh_token, "")?; service::account::refresh_token(context, refresh_token.token).await } + +/// 添加管理员账号 +pub async fn add_account() -> ResResult> { + service::sys_account::add_account().await +} \ No newline at end of file diff --git a/api/src/router.rs b/api/src/router.rs index 2af7486..8851c49 100644 --- a/api/src/router.rs +++ b/api/src/router.rs @@ -15,7 +15,7 @@ pub(crate) fn init() -> Router { ) .route( "/account/sys", - post(controller::account::authenticate_with_password), + post(controller::account::add_account), ) .route( "/account/refresh-token", diff --git a/app.toml b/app.toml index 76f6aa3..610135c 100644 --- a/app.toml +++ b/app.toml @@ -9,7 +9,7 @@ prefix = "tower_defense_server" level = "DEBUG" [database] -url = "postgres://lyj:1325479Lyj!@47.95.198.7:13207/demo_rs" +url = "postgres://lyj:B3a5kL9z!qQ@47.95.198.7:31000/chuanyue_gm" options = { min_conns = 10, max_conns = 20, conn_timeout = 30, idle_timeout = 300, max_lifetime = 60, sql_logging = true } [jwt] diff --git a/domain/src/entities/account.rs b/domain/src/entities/account.rs index ba49974..7b75e6b 100644 --- a/domain/src/entities/account.rs +++ b/domain/src/entities/account.rs @@ -75,9 +75,9 @@ pub struct Account { pub weixin_id: Option, pub douyin_id: Option, pub create_time: DateTime, - pub update_time: DateTime, - pub verify_time: DateTime, - pub disable_time: DateTime, + pub update_time: Option>, + pub verify_time: Option>, + pub disable_time: Option>, } impl Account { @@ -189,7 +189,7 @@ impl Account { select * from account where username = $1 and password = $2 "#, username, - password.as_bytes() + password.as_bytes().to_vec(), ).fetch_one(db_pool).await { Ok(account) => { return Ok(Some(account)); @@ -209,14 +209,16 @@ impl Account { Account, r#" insert into account - (username, password, lang_tag, role) + (username, password, lang_tag, role, wallet, metadata) values - ($1, $2, $3, $4) returning * + ($1, $2, $3, $4, $5, $6) returning * "#, self.username, self.password, self.lang_tag, - self.role.to_string() + self.role.to_string(), + self.wallet, + self.metadata ).fetch_one(db_pool).await { Ok(account) => { return Ok(Some(account)); diff --git a/service/src/account.rs b/service/src/account.rs index f0708f9..c35d2a0 100644 --- a/service/src/account.rs +++ b/service/src/account.rs @@ -45,10 +45,13 @@ pub async fn authenticate_google( } Some(account) => { tracing::info!("账户已存在, {:?}", account); - if account.disable_time > Utc::now() { - tracing::error!("账户已禁用"); - return Err(ResErr::system(message!(context.get_lang_tag(), ACCOUNT_DISABLED))); + if let Some(disable_time) = account.disable_time { + if disable_time > Utc::now() { + tracing::error!("账户已禁用"); + return Err(ResErr::system(message!(context.get_lang_tag(), ACCOUNT_DISABLED))); + } } + account } }; diff --git a/service/src/sys_account.rs b/service/src/sys_account.rs index 03e2c3a..66c3366 100644 --- a/service/src/sys_account.rs +++ b/service/src/sys_account.rs @@ -29,12 +29,14 @@ pub async fn authenticate_with_password( ))); } let account = account.unwrap(); - if account.disable_time > Utc::now() { - tracing::error!("账户已禁用"); - return Err(ResErr::auth(message!( - context.get_lang_tag(), - ACCOUNT_DISABLED - ))); + if let Some(disable_time) = account.disable_time { + if disable_time > Utc::now() { + tracing::error!("账户已禁用"); + return Err(ResErr::auth(message!( + context.get_lang_tag(), + ACCOUNT_DISABLED + ))); + } } if !account.role.is_admin() { tracing::error!("账户不是管理员,无权限");