From 4aecec7cdc96aa903573992e41cb6dd8f1bd8080 Mon Sep 17 00:00:00 2001 From: liushan Date: Sun, 28 Jan 2024 13:02:57 +0800 Subject: [PATCH] fix bug --- .../examples/lsys-actix-web/config/app.toml | 2 +- .../lsys-actix-web/locale/en_US/lsys-web.ftl | 27 ++++++++++++++++++- .../lsys-actix-web/locale/zh_CN/lsys-web.ftl | 24 +++++++++++++++++ .../src/handler/api/user/external.rs | 9 +++++-- .../src/handler/api/user/login.rs | 2 +- .../lsys-actix-web/src/template/err.html | 10 ------- .../lsys-actix-web/src/template/index.html | 11 -------- .../examples/lsys-actix-web/static/404.html | 2 +- .../lsys-actix-web/static/welcome.html | 2 +- .../src/dao/sender_smser/record.rs | 2 +- .../src/handler/common/sender/mailer.rs | 5 ++-- .../src/handler/common/sender/smser.rs | 5 ++-- .../lsys-web/src/handler/common/sender/tpl.rs | 8 +++--- .../lsys-web/src/handler/common/user/email.rs | 17 +++++++----- .../lsys-web/src/handler/common/user/info.rs | 20 +++++++++----- .../lsys-web/src/handler/common/user/login.rs | 2 +- .../src/handler/common/user/mobile.rs | 17 +++++++----- .../src/handler/common/user/password.rs | 12 +++++++-- .../src/handler/common/user/register.rs | 9 +++++-- server/lsys-web/src/handler/oauth/auth.rs | 15 ++++++++--- server/lsys-web/src/utils/json_result.rs | 2 +- 21 files changed, 139 insertions(+), 64 deletions(-) delete mode 100644 server/examples/lsys-actix-web/src/template/err.html delete mode 100644 server/examples/lsys-actix-web/src/template/index.html diff --git a/server/examples/lsys-actix-web/config/app.toml b/server/examples/lsys-actix-web/config/app.toml index cf98cf2..f62ea00 100644 --- a/server/examples/lsys-actix-web/config/app.toml +++ b/server/examples/lsys-actix-web/config/app.toml @@ -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" diff --git a/server/examples/lsys-actix-web/locale/en_US/lsys-web.ftl b/server/examples/lsys-actix-web/locale/en_US/lsys-web.ftl index bea336a..853644d 100644 --- a/server/examples/lsys-actix-web/locale/en_US/lsys-web.ftl +++ b/server/examples/lsys-actix-web/locale/en_US/lsys-web.ftl @@ -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 \ No newline at end of file +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. + diff --git a/server/examples/lsys-actix-web/locale/zh_CN/lsys-web.ftl b/server/examples/lsys-actix-web/locale/zh_CN/lsys-web.ftl index 2b923ab..cc88f22 100644 --- a/server/examples/lsys-actix-web/locale/zh_CN/lsys-web.ftl +++ b/server/examples/lsys-actix-web/locale/zh_CN/lsys-web.ftl @@ -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=邮箱重复绑定 \ No newline at end of file diff --git a/server/examples/lsys-actix-web/src/handler/api/user/external.rs b/server/examples/lsys-actix-web/src/handler/api/user/external.rs index d880266..91ba16a 100644 --- a/server/examples/lsys-actix-web/src/handler/api/user/external.rs +++ b/server/examples/lsys-actix-web/src/handler/api/user/external.rs @@ -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::{ @@ -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(""), ), } } diff --git a/server/examples/lsys-actix-web/src/handler/api/user/login.rs b/server/examples/lsys-actix-web/src/handler/api/user/login.rs index 680e80f..3f27945 100644 --- a/server/examples/lsys-actix-web/src/handler/api/user/login.rs +++ b/server/examples/lsys-actix-web/src/handler/api/user/login.rs @@ -275,7 +275,7 @@ pub async fn external_login_callback<'t>( let login_param = json_param.param::()?; let res = match login_param.login_type.as_str() { "qq" => { - Ok(JsonData::message("未实现")) + Ok(JsonData::message("unimplemented")) // user_external_login_callback::( // "wechat", &auth_dao, ¶m, // ) diff --git a/server/examples/lsys-actix-web/src/template/err.html b/server/examples/lsys-actix-web/src/template/err.html deleted file mode 100644 index 28c5261..0000000 --- a/server/examples/lsys-actix-web/src/template/err.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - - server error - - -

server error

- - \ No newline at end of file diff --git a/server/examples/lsys-actix-web/src/template/index.html b/server/examples/lsys-actix-web/src/template/index.html deleted file mode 100644 index 59cbe50..0000000 --- a/server/examples/lsys-actix-web/src/template/index.html +++ /dev/null @@ -1,11 +0,0 @@ - - - - - hi,{{ name }} - - -

{{ text }}

-

{{name}}

- - \ No newline at end of file diff --git a/server/examples/lsys-actix-web/static/404.html b/server/examples/lsys-actix-web/static/404.html index e140a1d..32579ff 100644 --- a/server/examples/lsys-actix-web/static/404.html +++ b/server/examples/lsys-actix-web/static/404.html @@ -7,7 +7,7 @@ - back to home + back to home

404

diff --git a/server/examples/lsys-actix-web/static/welcome.html b/server/examples/lsys-actix-web/static/welcome.html index 307ed21..5e02f76 100644 --- a/server/examples/lsys-actix-web/static/welcome.html +++ b/server/examples/lsys-actix-web/static/welcome.html @@ -7,7 +7,7 @@ -

Welcome

+

Welcome

\ No newline at end of file diff --git a/server/lsys-sender/src/dao/sender_smser/record.rs b/server/lsys-sender/src/dao/sender_smser/record.rs index 8f5f2ca..cf383a9 100644 --- a/server/lsys-sender/src/dao/sender_smser/record.rs +++ b/server/lsys-sender/src/dao/sender_smser/record.rs @@ -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, diff --git a/server/lsys-web/src/handler/common/sender/mailer.rs b/server/lsys-web/src/handler/common/sender/mailer.rs index 522a0ca..350c138 100644 --- a/server/lsys-web/src/handler/common/sender/mailer.rs +++ b/server/lsys-web/src/handler/common/sender/mailer.rs @@ -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}, }; @@ -463,9 +464,9 @@ pub async fn mailer_config_del 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)); diff --git a/server/lsys-web/src/handler/common/sender/smser.rs b/server/lsys-web/src/handler/common/sender/smser.rs index 2a1a46b..4f37df1 100644 --- a/server/lsys-web/src/handler/common/sender/smser.rs +++ b/server/lsys-web/src/handler/common/sender/smser.rs @@ -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)); diff --git a/server/lsys-web/src/handler/common/sender/tpl.rs b/server/lsys-web/src/handler/common/sender/tpl.rs index ace31f6..6b786bc 100644 --- a/server/lsys-web/src/handler/common/sender/tpl.rs +++ b/server/lsys-web/src/handler/common/sender/tpl.rs @@ -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; @@ -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(¶m.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 diff --git a/server/lsys-web/src/handler/common/user/email.rs b/server/lsys-web/src/handler/common/user/email.rs index dc2615a..ea2c4ec 100644 --- a/server/lsys-web/src/handler/common/user/email.rs +++ b/server/lsys-web/src/handler/common/user/email.rs @@ -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 @@ -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)); } } }; @@ -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)] @@ -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 @@ -200,10 +204,11 @@ pub async fn user_email_confirm<'t, T: SessionTokenData, D: SessionData, S: User .confirm_email_from_code(&email, ¶m.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)] diff --git a/server/lsys-web/src/handler/common/user/info.rs b/server/lsys-web/src/handler/common/user/info.rs index dc932d1..4e930a2 100644 --- a/server/lsys-web/src/handler/common/user/info.rs +++ b/server/lsys-web/src/handler/common/user/info.rs @@ -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; @@ -103,14 +104,19 @@ pub async fn user_info_check_username 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)) + // , ), } } @@ -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 diff --git a/server/lsys-web/src/handler/common/user/login.rs b/server/lsys-web/src/handler/common/user/login.rs index 9f6280d..75f7066 100644 --- a/server/lsys-web/src/handler/common/user/login.rs +++ b/server/lsys-web/src/handler/common/user/login.rs @@ -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)] diff --git a/server/lsys-web/src/handler/common/user/mobile.rs b/server/lsys-web/src/handler/common/user/mobile.rs index 7c15f8c..d6f0fe1 100644 --- a/server/lsys-web/src/handler/common/user/mobile.rs +++ b/server/lsys-web/src/handler/common/user/mobile.rs @@ -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; @@ -116,12 +117,16 @@ pub async fn user_mobile_send_code { 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"))); } } } @@ -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 diff --git a/server/lsys-web/src/handler/common/user/password.rs b/server/lsys-web/src/handler/common/user/password.rs index 8393c25..52c6929 100644 --- a/server/lsys-web/src/handler/common/user/password.rs +++ b/server/lsys-web/src/handler/common/user/password.rs @@ -1,3 +1,4 @@ +use lsys_core::fluent_message; use serde::Deserialize; use serde_json::json; @@ -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 diff --git a/server/lsys-web/src/handler/common/user/register.rs b/server/lsys-web/src/handler/common/user/register.rs index 4be7e2f..e47b37b 100644 --- a/server/lsys-web/src/handler/common/user/register.rs +++ b/server/lsys-web/src/handler/common/user/register.rs @@ -1,3 +1,4 @@ +use lsys_core::fluent_message; use lsys_user::model::{UserEmailStatus, UserInfoModelRef, UserMobileStatus}; use serde::Deserialize; use serde_json::json; @@ -77,7 +78,9 @@ pub async fn user_reg_send_code_from_mobile< if let Ok(mobile) = mobile_res { if UserMobileStatus::Valid.eq(mobile.status) { return Ok( - JsonData::message("this mobile is registered").set_sub_code("mobile_not_reg") + req_dao + .fluent_json_data(fluent_message!("reg-mobile-registered")) + .set_sub_code("mobile_is_reg"), // JsonData::message("this mobile is registered") ); } } @@ -146,7 +149,9 @@ pub async fn user_reg_send_code_from_email< .await; if let Ok(email) = email_res { if UserEmailStatus::Valid.eq(email.status) { - return Ok(JsonData::message("this email is registered").set_sub_code("email_not_reg")); + return Ok(req_dao + .fluent_json_data(fluent_message!("reg-mobile-registered")) + .set_sub_code("mobile_is_reg")); } } valid_code diff --git a/server/lsys-web/src/handler/oauth/auth.rs b/server/lsys-web/src/handler/oauth/auth.rs index db378a9..bef12f9 100644 --- a/server/lsys-web/src/handler/oauth/auth.rs +++ b/server/lsys-web/src/handler/oauth/auth.rs @@ -6,6 +6,7 @@ use crate::{ {JsonData, JsonResult}, }; use lsys_app::model::AppsModel; +use lsys_core::fluent_message; use lsys_user::dao::auth::{SessionData, SessionTokenData, UserSession}; use serde::{Deserialize, Serialize}; use serde_json::json; @@ -168,7 +169,11 @@ pub async fn oauth_create_code(error: T) -> Self { - JsonData::message_error(format!("err:{}", error)) + JsonData::message_error(format!("error:{}", error)) } pub fn message_error(msg: T) -> Self { JsonData::message(msg).set_code(500).set_sub_code("system")