修改数据库链接信息和表结构
This commit is contained in:
parent
c219922f22
commit
c34cc356f3
3
.env
3
.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
|
@ -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<ResData<()>> {
|
||||
service::sys_account::add_account().await
|
||||
}
|
@ -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",
|
||||
|
2
app.toml
2
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]
|
||||
|
@ -75,9 +75,9 @@ pub struct Account {
|
||||
pub weixin_id: Option<String>,
|
||||
pub douyin_id: Option<String>,
|
||||
pub create_time: DateTime<Utc>,
|
||||
pub update_time: DateTime<Utc>,
|
||||
pub verify_time: DateTime<Utc>,
|
||||
pub disable_time: DateTime<Utc>,
|
||||
pub update_time: Option<DateTime<Utc>>,
|
||||
pub verify_time: Option<DateTime<Utc>>,
|
||||
pub disable_time: Option<DateTime<Utc>>,
|
||||
}
|
||||
|
||||
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));
|
||||
|
@ -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
|
||||
}
|
||||
};
|
||||
|
@ -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!("账户不是管理员,无权限");
|
||||
|
Loading…
Reference in New Issue
Block a user