Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
shanliu committed Jan 28, 2024
1 parent a9f4f4b commit 4aecec7
Show file tree
Hide file tree
Showing 21 changed files with 139 additions and 64 deletions.
2 changes: 1 addition & 1 deletion server/examples/lsys-actix-web/config/app.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ root_user_id = [1]
fluent_dir = "locale/"

#页面模板目录
tpl_dir = "src/template/"
tpl_dir = "static"

#地址库数据文件压缩包
area_code_db = "data/2023-7-area-code.csv.gz"
Expand Down
27 changes: 26 additions & 1 deletion server/examples/lsys-actix-web/locale/en_US/lsys-web.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,29 @@ address-bad-area = The submitted area code does not exist.
mail-bind-other-user = Mailbox is bound to another account [{$other_user_id}].
rbac-check-fail = permission check failed
system-not-found = Result does not exist
system-not-found = Result does not exist
user-old-passwrod-bad= The original password was submitted incorrectly.
user-old-passwrod-empty= Please submit the original password.
mail-is-confirm=The mailbox has been confirmed.
email-bad-status=Mailbox does not exist.
mobile-bad-status=Mobile phone number does not exist.
external-not-support=The login type {$name} is not supported.
username-is-exists=Account already exists: {$id}
password-not-set=The login password is not set.
client-secret-not-match=Secret does not match.
app-redirect-uri-not-match= Jump domain [redirect_uri] not supported
app-domain-not-config=Please configure the domain name in the backend.
reg-mobile-registered=This cell phone number has already been registered.
mobile-bind-other-user=Mobile is bound to another account:{$id}
mobile-is-bind=The mailbox is bound to another account.
24 changes: 24 additions & 0 deletions server/examples/lsys-actix-web/locale/zh_CN/lsys-web.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,27 @@ mail-bind-other-user = 邮箱已绑定其他账号[{$other_user_id}]
rbac-check-fail = 权限校验失败
system-not-found = 结果不存在
user-old-passwrod-bad= 提交的原密码错误
user-old-passwrod-empty= 请提交原密码
mail-is-confirm=邮箱已经确认过了
email-bad-status=邮箱不存在
mobile-bad-status=手机号不存在
external-not-support=登陆类型{$name}不支持
username-is-exists=账号已经存在:{$id}
password-not-set=登陆密码未设置
client-secret-not-match=Secret 不匹配
app-redirect-uri-not-match= 跳转域名[redirect_uri]不支持
app-domain-not-config=请先在后台配置跳转域名
reg-mobile-registered=该手机号已注册过账号
mobile-bind-other-user=邮箱已绑定其他账号:{$id}
mobile-is-bind=邮箱重复绑定
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::common::handler::{
JsonQuery, JwtQuery, ResponseJson, ResponseJsonResult, UserAuthQuery,
};
use actix_web::post;
use lsys_core::fluent_message;
use lsys_user::dao::auth::{SessionData, UserSession};
use lsys_web::{
handler::{
Expand Down Expand Up @@ -104,8 +105,12 @@ pub(crate) async fn external<'t>(
.await
}
name => Ok(
JsonData::message(format!("not support login type:{}", name))
.set_sub_code("type_not_support"),
auth_dao
.fluent_json_data(fluent_message!("external-not-support",{
"name":name
}))
.set_sub_code("type_not_support"), // JsonData::message(format!("not support login type:{}", name))
// .set_sub_code(""),
),
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ pub async fn external_login_callback<'t>(
let login_param = json_param.param::<ExternalCallbackParam>()?;
let res = match login_param.login_type.as_str() {
"qq" => {
Ok(JsonData::message("未实现"))
Ok(JsonData::message("unimplemented"))
// user_external_login_callback::<WechatLogin, WechatLoginParam, _, _>(
// "wechat", &auth_dao, &param,
// )
Expand Down
10 changes: 0 additions & 10 deletions server/examples/lsys-actix-web/src/template/err.html

This file was deleted.

11 changes: 0 additions & 11 deletions server/examples/lsys-actix-web/src/template/index.html

This file was deleted.

2 changes: 1 addition & 1 deletion server/examples/lsys-actix-web/static/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</head>

<body>
<a href="/static/welcome.html">back to home</a>
<a href="/welcome.html">back to home</a>
<h1>404</h1>
</body>

Expand Down
2 changes: 1 addition & 1 deletion server/examples/lsys-actix-web/static/welcome.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</head>

<body>
<h1>Welcome <img width="30px" height="30px" src="/static/logo.png" /></h1>
<h1>Welcome <img width="30px" height="30px" src="/logo.png" /></h1>
</body>

</html>
2 changes: 1 addition & 1 deletion server/lsys-sender/src/dao/sender_smser/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ impl SmsRecord {
if let Some(t) = data.iter().find(|e| e.1 as u64 == id) {
if t.0 >= limit.max_send.into() {
return Err(SenderError::System(
fluent_message!("mail-send-check-limit", // "trigger limit rule :{} on {} [{}]",
fluent_message!("sms-send-check-limit", // "trigger limit rule :{} on {} [{}]",
{
"max_send":limit.max_send,
"area":t.2,
Expand Down
5 changes: 3 additions & 2 deletions server/lsys-web/src/handler/common/sender/mailer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::{
use lsys_core::{fluent_message, str_time};
use lsys_core::{now_time, FluentMessage};
use lsys_sender::{
// dao::SenderError,
dao::SenderError,
model::{SenderConfigStatus, SenderMailConfigType, SenderMailMessageStatus},
};
Expand Down Expand Up @@ -463,9 +464,9 @@ pub async fn mailer_config_del<T: SessionTokenData, D: SessionData, S: UserSessi
.map_err(|e| req_dao.fluent_json_data(e))?;
}
}
Err(err) => match err {
Err(err) => match &err {
SenderError::Sqlx(sqlx::Error::RowNotFound) => {
return Ok(JsonData::message("email not find"));
return Ok(req_dao.fluent_json_data(err));
}
_ => {
return Err(req_dao.fluent_json_data(err));
Expand Down
5 changes: 3 additions & 2 deletions server/lsys-web/src/handler/common/sender/smser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,10 @@ pub async fn smser_config_del<'t, T: SessionTokenData, D: SessionData, S: UserSe
.map_err(|e| req_dao.fluent_json_data(e))?;
}
}
Err(err) => match err {
Err(err) => match &err {
SenderError::Sqlx(sqlx::Error::RowNotFound) => {
return Ok(JsonData::message("email not find"));
return Ok(req_dao.fluent_json_data(err));
// return Ok(JsonData::message("email not find"));
}
_ => {
return Err(req_dao.fluent_json_data(err));
Expand Down
8 changes: 4 additions & 4 deletions server/lsys-web/src/handler/common/sender/tpl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
handler::access::{AccessAdminSenderTplEdit, AccessAdminSenderTplView},
JsonData, JsonResult, PageParam,
};
use lsys_sender::{dao::SenderError, model::SenderType};
use lsys_sender::model::SenderType;
use lsys_user::dao::auth::{SessionData, SessionTokenData, UserSession};
use serde::Deserialize;
use serde_json::json;
Expand Down Expand Up @@ -197,9 +197,9 @@ pub async fn tpl_body_del<'t, T: SessionTokenData, D: SessionData, S: UserSessio
let res = req_dao.web_dao.sender_tpl.find_by_id(&param.id).await;
let data = match res {
Ok(d) => d,
Err(SenderError::Sqlx(sqlx::Error::RowNotFound)) => {
return Ok(JsonData::message("not find"))
}
// Err(SenderError::Sqlx(sqlx::Error::RowNotFound)) => {
// return Ok(JsonData::message("not find"))
// }
Err(e) => return Err(req_dao.fluent_json_data(e)),
};
req_dao
Expand Down
17 changes: 11 additions & 6 deletions server/lsys-web/src/handler/common/user/email.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ pub async fn user_email_send_code<'t, T: SessionTokenData, D: SessionData, S: Us
// JsonData::message(format!("other user bind[{}]",)),
);
} else {
return Ok(JsonData::message("the email is confirm"));
return Ok(
req_dao
.fluent_json_data(fluent_message!("mail-is-confirm"))
.set_code("mail-is-confirm"), // JsonData::message("the email is confirm")
);
}
}
email
Expand All @@ -114,7 +118,7 @@ pub async fn user_email_send_code<'t, T: SessionTokenData, D: SessionData, S: Us
if !err.is_not_found() {
return Err(req_dao.fluent_json_data(err));
} else {
return Ok(JsonData::message("email not find"));
return Ok(req_dao.fluent_json_data(err));
}
}
};
Expand Down Expand Up @@ -158,7 +162,7 @@ pub async fn user_email_send_code<'t, T: SessionTokenData, D: SessionData, S: Us
.send_valid_code(&email.email, &res.0, &res.1, Some(&req_dao.req_env))
.await
.map_err(|e| req_dao.fluent_json_data(e))?;
Ok(JsonData::message("mail is send"))
Ok(JsonData::default())
}

#[derive(Debug, Deserialize)]
Expand All @@ -180,7 +184,7 @@ pub async fn user_email_confirm<'t, T: SessionTokenData, D: SessionData, S: User
.await
.map_err(|e| req_dao.fluent_json_data(e))?;
if UserEmailStatus::Delete.eq(email.status) {
return Ok(JsonData::message("email not find"));
return Ok(req_dao.fluent_json_data(fluent_message!("email-bad-status")));
}
if UserEmailStatus::Init.eq(email.status) {
req_dao
Expand All @@ -200,10 +204,11 @@ pub async fn user_email_confirm<'t, T: SessionTokenData, D: SessionData, S: User
.confirm_email_from_code(&email, &param.code, Some(&req_dao.req_env))
.await
.map_err(|e| req_dao.fluent_json_data(e))?;
Ok(JsonData::message("email confirm success"))
// Ok(JsonData::message("email confirm success"))
} else {
Ok(JsonData::message("email is confirm"))
// Ok(JsonData::message("email is confirm"))
}
Ok(JsonData::default())
}

#[derive(Debug, Deserialize)]
Expand Down
20 changes: 14 additions & 6 deletions server/lsys-web/src/handler/common/user/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::{
handler::access::{AccessUserInfoEdit, AccessUserNameEdit},
{JsonData, JsonResult},
};
use lsys_core::fluent_message;
use lsys_user::dao::auth::{SessionData, SessionTokenData, UserSession};
use lsys_user::{dao::account::UserAccountError, model::UserInfoModelRef};
use serde::Deserialize;
Expand Down Expand Up @@ -103,14 +104,19 @@ pub async fn user_info_check_username<T: SessionTokenData, D: SessionData, S: Us
.find_by_name(param.name)
.await;
match user_res {
Err(UserAccountError::Sqlx(sqlx::Error::RowNotFound)) => Ok(JsonData::message("success")
.set_data(json!({
Err(UserAccountError::Sqlx(sqlx::Error::RowNotFound)) => {
Ok(JsonData::default().set_data(json!({
"pass":"1"
}))),
})))
}
Err(err) => Err(req_dao.fluent_json_data(err)),
Ok(user) => Ok(
JsonData::message(format!("Username already exists [{}]", user.id))
.set_sub_code("username_exists"),
req_dao
.fluent_json_data(fluent_message!("username-is-exists",{
"id":user.id
}))
.set_sub_code("username_exists"), // JsonData::message(format!("Username already exists [{}]", user.id))
// ,
),
}
}
Expand Down Expand Up @@ -241,7 +247,9 @@ pub async fn password_last_modify<'t, T: SessionTokenData, D: SessionData, S: Us
.await
.map_err(|e| req_dao.fluent_json_data(e))?;
if user.password_id == 0 {
return Ok(JsonData::message("not set password").set_sub_code("not_set"));
return Ok(req_dao
.fluent_json_data(fluent_message!("password-not-set"))
.set_sub_code("not_set"));
}
let user = req_dao
.web_dao
Expand Down
2 changes: 1 addition & 1 deletion server/lsys-web/src/handler/common/user/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub async fn user_logout<'t, T: SessionTokenData, D: SessionData, S: UserSession
.clear_session()
.await
.map_err(|e| req_dao.fluent_json_data(e))?;
Ok(JsonData::message("logout ok"))
Ok(JsonData::default())
}

#[derive(Debug, Deserialize)]
Expand Down
17 changes: 11 additions & 6 deletions server/lsys-web/src/handler/common/user/mobile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::{
handler::access::{AccessSystemMobileConfirm, AccessUserMobileEdit, AccessUserMobileView},
{CaptchaParam, JsonData, JsonResult},
};
use lsys_core::fluent_message;
use lsys_user::dao::auth::{SessionData, SessionTokenData, UserSession};
use lsys_user::model::UserMobileStatus;
use serde::Deserialize;
Expand Down Expand Up @@ -116,12 +117,16 @@ pub async fn user_mobile_send_code<T: SessionTokenData, D: SessionData, S: UserS
Ok(mobile) => {
if UserMobileStatus::Valid.eq(mobile.status) {
if mobile.user_id != req_auth.user_data().user_id {
return Ok(JsonData::message(format!(
"other user bind[{}]",
mobile.user_id
)));
return Ok(
req_dao.fluent_json_data(fluent_message!("mobile-bind-other-user",{
"id": mobile.user_id
})), // JsonData::message(format!(
// "other user bind[{}]",

// )
);
} else {
return Ok(JsonData::message("the mobile is bind"));
return Ok(req_dao.fluent_json_data(fluent_message!("mobile-is-bind")));
}
}
}
Expand Down Expand Up @@ -198,7 +203,7 @@ pub async fn user_mobile_confirm<'t, T: SessionTokenData, D: SessionData, S: Use
.await
.map_err(|e| req_dao.fluent_json_data(e))?;
if UserMobileStatus::Delete.eq(mobile.status) {
return Ok(JsonData::message("mobile not find"));
return Ok(req_dao.fluent_json_data(fluent_message!("mobile-bad-status")));
}
if UserMobileStatus::Init.eq(mobile.status) {
req_dao
Expand Down
12 changes: 10 additions & 2 deletions server/lsys-web/src/handler/common/user/password.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use lsys_core::fluent_message;
use serde::Deserialize;
use serde_json::json;

Expand Down Expand Up @@ -54,11 +55,18 @@ pub async fn user_set_password<'t, T: SessionTokenData, D: SessionData, S: UserS
.await
.map_err(|e| req_dao.fluent_json_data(e))?;
if !check {
return Ok(JsonData::message("old password is wrong").set_sub_code("bad_passwrod"));
return Ok(req_dao
.fluent_json_data(fluent_message!("user-old-passwrod-bad"))
.set_sub_code("bad_passwrod"));
// return Ok(JsonData::message("old password is wrong").set_sub_code("bad_passwrod"));
}
} else {
return Ok(JsonData::message("your need submit old password")
return Ok(req_dao
.fluent_json_data(fluent_message!("user-old-passwrod-empty"))
.set_sub_code("need_old_passwrod"));

// return Ok(JsonData::message("your need submit old password")
// .set_sub_code(""));
}
}
let pid = user_password
Expand Down
Loading

0 comments on commit 4aecec7

Please sign in to comment.