修改数据库链接信息和表结构

This commit is contained in:
李运家 2024-09-21 16:09:41 +08:00
parent c219922f22
commit c34cc356f3
7 changed files with 31 additions and 20 deletions

3
.env
View File

@ -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

View File

@ -29,3 +29,8 @@ pub async fn refresh_token(
validator::validate_params(&refresh_token, "")?; validator::validate_params(&refresh_token, "")?;
service::account::refresh_token(context, refresh_token.token).await service::account::refresh_token(context, refresh_token.token).await
} }
/// 添加管理员账号
pub async fn add_account() -> ResResult<ResData<()>> {
service::sys_account::add_account().await
}

View File

@ -15,7 +15,7 @@ pub(crate) fn init() -> Router {
) )
.route( .route(
"/account/sys", "/account/sys",
post(controller::account::authenticate_with_password), post(controller::account::add_account),
) )
.route( .route(
"/account/refresh-token", "/account/refresh-token",

View File

@ -9,7 +9,7 @@ prefix = "tower_defense_server"
level = "DEBUG" level = "DEBUG"
[database] [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 } options = { min_conns = 10, max_conns = 20, conn_timeout = 30, idle_timeout = 300, max_lifetime = 60, sql_logging = true }
[jwt] [jwt]

View File

@ -75,9 +75,9 @@ pub struct Account {
pub weixin_id: Option<String>, pub weixin_id: Option<String>,
pub douyin_id: Option<String>, pub douyin_id: Option<String>,
pub create_time: DateTime<Utc>, pub create_time: DateTime<Utc>,
pub update_time: DateTime<Utc>, pub update_time: Option<DateTime<Utc>>,
pub verify_time: DateTime<Utc>, pub verify_time: Option<DateTime<Utc>>,
pub disable_time: DateTime<Utc>, pub disable_time: Option<DateTime<Utc>>,
} }
impl Account { impl Account {
@ -189,7 +189,7 @@ impl Account {
select * from account where username = $1 and password = $2 select * from account where username = $1 and password = $2
"#, "#,
username, username,
password.as_bytes() password.as_bytes().to_vec(),
).fetch_one(db_pool).await { ).fetch_one(db_pool).await {
Ok(account) => { Ok(account) => {
return Ok(Some(account)); return Ok(Some(account));
@ -209,14 +209,16 @@ impl Account {
Account, Account,
r#" r#"
insert into account insert into account
(username, password, lang_tag, role) (username, password, lang_tag, role, wallet, metadata)
values values
($1, $2, $3, $4) returning * ($1, $2, $3, $4, $5, $6) returning *
"#, "#,
self.username, self.username,
self.password, self.password,
self.lang_tag, self.lang_tag,
self.role.to_string() self.role.to_string(),
self.wallet,
self.metadata
).fetch_one(db_pool).await { ).fetch_one(db_pool).await {
Ok(account) => { Ok(account) => {
return Ok(Some(account)); return Ok(Some(account));

View File

@ -45,10 +45,13 @@ pub async fn authenticate_google(
} }
Some(account) => { Some(account) => {
tracing::info!("账户已存在, {:?}", account); tracing::info!("账户已存在, {:?}", account);
if account.disable_time > Utc::now() { if let Some(disable_time) = account.disable_time {
if disable_time > Utc::now() {
tracing::error!("账户已禁用"); tracing::error!("账户已禁用");
return Err(ResErr::system(message!(context.get_lang_tag(), ACCOUNT_DISABLED))); return Err(ResErr::system(message!(context.get_lang_tag(), ACCOUNT_DISABLED)));
} }
}
account account
} }
}; };

View File

@ -29,13 +29,15 @@ pub async fn authenticate_with_password(
))); )));
} }
let account = account.unwrap(); let account = account.unwrap();
if account.disable_time > Utc::now() { if let Some(disable_time) = account.disable_time {
if disable_time > Utc::now() {
tracing::error!("账户已禁用"); tracing::error!("账户已禁用");
return Err(ResErr::auth(message!( return Err(ResErr::auth(message!(
context.get_lang_tag(), context.get_lang_tag(),
ACCOUNT_DISABLED ACCOUNT_DISABLED
))); )));
} }
}
if !account.role.is_admin() { if !account.role.is_admin() {
tracing::error!("账户不是管理员,无权限"); tracing::error!("账户不是管理员,无权限");
return Err(ResErr::perm(message!( return Err(ResErr::perm(message!(