Skip to content

Commit

Permalink
新增单条[短信,邮件]发送,同步等待结果
Browse files Browse the repository at this point in the history
  • Loading branch information
shanliu committed Feb 3, 2024
1 parent 5db5708 commit 282ade4
Show file tree
Hide file tree
Showing 38 changed files with 1,155 additions and 417 deletions.
26 changes: 16 additions & 10 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,29 @@ name: Rust

on:
push:
branches: [ "main" ]
branches: ["main"]
pull_request:
branches: [ "main" ]
branches: ["main"]

env:
CARGO_TERM_COLOR: always

jobs:
build:

runs-on: ubuntu-latest

services:
redis:
image: redis
ports:
- 6379:6379
options: --entrypoint redis-server

steps:
- uses: actions/checkout@v3
- name: Build
working-directory: ./server
run: cargo build --verbose
- name: Run tests
working-directory: ./server
run: cargo test --verbose
- uses: actions/checkout@v3
- name: Build
working-directory: ./server
run: cargo build --verbose
- name: Run tests
working-directory: ./server
run: cargo test --verbose
2 changes: 2 additions & 0 deletions server/assets/tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ CREATE TABLE `yaf_sender_mail_body` (
`reply_mail` varchar(254) NOT NULL COMMENT '回复',
`user_ip` varchar(40) NOT NULL DEFAULT '' COMMENT '操作者IP',
`request_id` varchar(32) NOT NULL COMMENT '请求ID',
`reply_host` varchar(255) NOT NULL COMMENT '结果返回主机',
PRIMARY KEY (`id`),
KEY `sender_record_data_IDX` (`expected_time`, `status`, `id`) USING BTREE
) ENGINE = InnoDB CHARSET = utf8mb4 COMMENT = '发送邮件数据';
Expand Down Expand Up @@ -449,6 +450,7 @@ CREATE TABLE `yaf_sender_sms_body` (
`user_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT '用户id',
`user_ip` varchar(40) NOT NULL DEFAULT '' COMMENT '操作者IP',
`request_id` varchar(32) NOT NULL COMMENT '请求ID',
`reply_host` varchar(255) NOT NULL COMMENT '结果返回主机',
PRIMARY KEY (`id`),
KEY `sender_record_data_IDX` (`expected_time`, `status`, `id`) USING BTREE
) ENGINE = InnoDB CHARSET = utf8mb4 COMMENT = '发送短信数据';
Expand Down
5 changes: 5 additions & 0 deletions server/examples/lsys-actix-web/locale/zh_CN/lsys-sender.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ check-email-not-match = = 邮箱[{$mail}]格式错误
smtp-check-error = Smpt服务器异常:{$msg}
sms-config-url-error = 网关地址错误,仅支持http或https.
sms-config-branch-error = 批量发送数量不能超过:{$max}
mail-send-fail = 邮件发送失败:{$msg}
mail-send-wait-fail = 邮件发送中,获取发送结果失败:{$msg}
mail-cancel-status-error = 邮件非待发送状态:{$status}
mail-config-add-error = 邮件配置:字段{$name}校验失败:{$msg}
mail-config-add-max-num-error = 请提交每次最大邮件限制发送数
Expand All @@ -18,6 +21,8 @@ mail-send-ok-cancel = 邮件已发送到邮箱:{$to_mail}[{$msg_id}]
sms-cancel-status-error = 短信非待发送状态:{$status}
sms-config-add-error = 短信配置:字段{$name}校验失败:{$msg}
sms-config-add-max-num-error = 请提交每次最大短信限制发送数
sms-send-fail = 短信发送失败:{$msg}
sms-send-wait-fail = 短信发送中,获取发送结果失败:{$msg}
sms-send-check-miss-error = 接收短信为空
sms-send-check-max-send = 超过每次最大短信发送量:{$max}
sms-send-check-block = 接收号码:{$mobile} 已被屏蔽[{$config_id}]
Expand Down
76 changes: 74 additions & 2 deletions server/examples/lsys-actix-web/locale/zh_CN/lsys-web.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ address-bad-area = 提交的区域编码不存在
mail-bind-other-user = 邮箱已绑定其他账号[{$other_user_id}]
rbac-check-fail = 权限校验失败
system-not-found = 结果不存在
system-not-found = 不存在相关记录
user-old-passwrod-bad= 提交的原密码错误
user-old-passwrod-empty= 请提交原密码
Expand All @@ -45,4 +45,76 @@ app-domain-not-config=请先在后台配置跳转域名
reg-mobile-registered=该手机号已注册过账号
mobile-bind-other-user=邮箱已绑定其他账号:{$id}
mobile-is-bind=邮箱重复绑定
mobile-is-bind=邮箱重复绑定
# 以下是权限资源翻译

res-global-system = 全局权限
res-global-app-appid=应用__管理
res-global-user-user_id=__用户权限管理
res-global-oauth=OAuath授权信息管理
res-global-rbac-res=用户资源管理
res-global-rbac-role=用户角色管理
res-global-user-mobile=用户手机号管理
res-global-user-app=用户应用管理
res-global-user-email=用户邮件管理
res-global-user-info=用户信息管理
res-global-user-name=用户名管理
res-global-user-address=用户地址管理
res-global-user-password=用户密码管理
res-op-app-smtp-config=邮件应用Smtp配置
res-op-app-mail-config=邮件应用配置
res-op-app-mail-manage=邮件应用管理
res-op-main=进入后台
res-op-see-change-log=查看更改日志
res-op-edit-docs=编辑文档配置
res-op-setting=系统设置
res-op-app-sms-config=短信应用管理
res-op-app-sms-manage=短信应用管理
res-op-app-confirm=应用审核
res-op-login=登陆控制
res-op-email-confirm=邮箱确认
res-op-mobile-confirm=手机号确认
res-op-reset-confirm=重置密码
res-op-tpl-view=模板查看
res-op-tpl-edit=模板编辑
res-op-site-setting=站点配置
res-op-app-mail-send=邮件发送
res-op-app-sms-send=短信发送
res-op-access-check=权限校验
res-op-full=系统资源列表
res-op-base=基本资源列表
res-op-user-info=用户资料
res-op-user-email=用户邮箱
res-op-user-mobile=用户手机号
res-op-user-address=用户守候地址
res-op-view=查看
res-op-edit=编辑
res-op-change-all=资源更改
res-op-allow-res=所有资源允许
res-op-deny-res=所有资源禁止
res-op-edit=编辑
res-op-view=查看
res-app-sender = 发送相关管理
res-rbac-res = 权限资源管理
res-rbac-role = 权限角色管理
res-user-mobile = 绑定手机号管理
res-user-app = 应用管理
res-user-email = 绑定邮箱管理
res-user-info = 用户信息管理
res-user-name = 登陆账号管理
res-user-address = 收货地址管理
res-user-external = 关联账号管理
res-user-password = 账号密码管理
4 changes: 3 additions & 1 deletion server/examples/lsys-actix-web/src/handler/api/user/rbac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ pub async fn res<'t>(
"delete" => user_res_delete(json_param.param::<ResDeleteParam>()?, &auth_dao).await,
"list_data" => user_res_list_data(json_param.param::<ResListDataParam>()?, &auth_dao).await,
"tags" => user_res_tags(json_param.param::<ResTagsParam>()?, &auth_dao).await,
"all" => rbac_all_res_list(&res_tpls(), json_param.param::<ResAllParam>()?).await,
"all" => {
rbac_all_res_list(&res_tpls(), json_param.param::<ResAllParam>()?, &auth_dao).await
}
name => handler_not_found!(name),
};
Ok(data?.into())
Expand Down
2 changes: 1 addition & 1 deletion server/examples/lsys-actix-web/src/handler/web/captcha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub(crate) async fn captcha(
CacheDirective::MaxAge(valid_code_data.save_time as u32),
]))
.body(valid_code_data.image_data),
Err(err) => HttpResponse::InternalServerError().body(err.to_string()),
Err(err) => HttpResponse::InternalServerError().body(req_dao.fluent_string(err)),
}
}
Err(_) => HttpResponse::NotFound().body("not find"),
Expand Down
4 changes: 2 additions & 2 deletions server/examples/lsys-actix-web/src/handler/web/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use actix_web::{get, HttpResponse, Responder};
use actix_web::{http::StatusCode, Result};
use lsys_web::dao::WebDao;

#[get("/")]
pub(crate) async fn index<'t>(web_dao: Data<WebDao>) -> Result<HttpResponse, WebHandError> {
#[get("/dome")]
pub(crate) async fn dome(web_dao: Data<WebDao>) -> Result<HttpResponse, WebHandError> {
let mut ctx = tera::Context::new();
ctx.insert("name", &"lsys".to_owned());
ctx.insert("text", &"Welcome!".to_owned());
Expand Down
15 changes: 8 additions & 7 deletions server/examples/lsys-actix-web/src/handler/web/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ pub(crate) fn router<T>(app: App<T>, app_dao: &Arc<WebDao>) -> App<T>
where
T: ServiceFactory<ServiceRequest, Config = (), Error = Error, InitError = ()>,
{
let static_serve_from = app_dao
.app_core
.config
.find(None)
.get_string("static_serve_from")
.unwrap_or_else(|_| String::from("./static"));
let mut app = app
.service(scope("/captcha").service(captcha::captcha))
// .service(actix_files::Files::new("/static", "./static").show_files_listing())
;
if let Ok(tmp) = app_dao.app_core.config.find(None).get_string("ui_path") {
if !tmp.is_empty() && tmp != *"./" && tmp != *"/" {
app = app.service(index::index);
}
}
.service(actix_files::Files::new("/static", static_serve_from).show_files_listing());
app = app.service(index::dome);
app
}
4 changes: 3 additions & 1 deletion server/examples/lsys-actix-web/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use handler::router_main;
use jsonwebtoken::{DecodingKey, Validation};
use lsys_core::{AppCore, AppCoreError};
use lsys_web::dao::WebDao;
use lsys_web::FluentFormat;
use rustls::server::ServerConfig;
use rustls::{Certificate, PrivateKey};
use rustls_pemfile::{certs, read_one, Item};
Expand Down Expand Up @@ -129,13 +130,14 @@ pub async fn create_server(app_dir: &str) -> Result<Server, AppError> {
let apps = app_data.app.app_dao.app.clone();
Box::pin(async move {
apps.find_secret_by_client_id(&app_key)
.map_err(|e| e.to_string())
.map_err(|e| e.fluent_format(&app_data.fluent.locale(None)))
.await
})
}));

let app = App::new()
.wrap(middlewares::Logger::default())
.wrap(middlewares::Compress::default())
.wrap(
middlewares::ErrorHandlers::new()
.handler(http::StatusCode::INTERNAL_SERVER_ERROR, handler::render_500),
Expand Down
3 changes: 1 addition & 2 deletions server/examples/lsys-actix-web/static/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@

<head>
<title>actix - basics</title>
<link rel="shortcut icon" type="image/x-icon" href="/favicon" />
</head>

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

Expand Down
4 changes: 2 additions & 2 deletions server/examples/lsys-actix-web/static/welcome.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

<head>
<title>actix - basics</title>
<link rel="shortcut icon" type="image/x-icon" href="/favicon" />
</head>

<body>
<h1>Welcome <img width="30px" height="30px" src="/logo.png" /></h1>
<h1>Welcome <img width="30px" height="30px" src="/static/logo.png" /></h1>
<a href="/dome">actix-web-dome-page</a>
</body>

</html>
24 changes: 24 additions & 0 deletions server/lsys-app/README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,27 @@
> 接入文档:[README.MD](../../sdk/README.MD)

> 内部模块
1. 使用 RestQuery 获取接口请求
访问需要:app_id sign version timestamp 等参数
由RestQuery完成签名校验
2. 登录使用 OauthAuthQuery 获取完成登录校验[可选]
3. 授权查询: 调用Rbac.check 完成必要权限校验[可选]

> 外部模块校验流程
1. 模块自身client_id 自身KEY 访问者client_id
2. 系统返回访问者 key
3. 检查签名,继续完成操作


> oauth 登录过程
1. [用户授权]请求用户 /oauth/authorize?response_type=code&client_id=app_id&redirect_uri=CALLBACK_URL&scope=read
2. [用户授权]显示登录,完成登录,跳到授权页面 以 scope 作为关系KEY,拉取关系角色可操作权限列表
3. [用户授权]完成授权. 生成code ,存放redis, scope,授权时间 +client_id+授权user_id ,设置5分钟超时,回到用户站点 /callback?code=AUTHORIZATION_CODE
4. [用户授权]请求令牌 /oauth/token?client_id=CLIENT_ID&client_secret=CLIENT_SECRET&grant_type=authorization_code&code=AUTHORIZATION_CODE 读取redis 判断client_id,生成token记录并放入本地缓存,返回token
5. [完成鉴权]通过TOKEN访问 参数:[client_id,code,需访问资源名],检查缓存->检查数据库->有结果->检测授权:
用户授权参数 检查请求资源[yaf_app_token]是否存在 参数: 用户ID[通过APP表可获取] + 关系KEY[yaf_app_token] +(res[请求参数]+授权用户ID[登录TOKEN])
通过 继续完成内置功能操作



6 changes: 5 additions & 1 deletion server/lsys-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ dotenv = "~0.15.*"

tokio = { version = "~1.28.0", features = ["fs", "macros"] }
deadpool-redis = { version = "0.12" }
redis = { version = "~0.23", features = ["aio", "tokio-comp"] }
redis = { version = "~0.23", features = [
"aio",
"tokio-comp",
"connection-manager",
] }


serde = { version = "1.0.*" }
Expand Down
2 changes: 1 addition & 1 deletion server/lsys-core/src/fluents/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ impl FluentBundle {
pub fn format_message(&self, message: &FluentMessage) -> String {
self.find_fluent_bundle(&message.crate_name)
.and_then(|fluent| {
fluent.get_message(message.id).and_then(|msg| {
fluent.get_message(&message.id).and_then(|msg| {
msg.value().map(|pattern| {
let mut args: fluent::FluentArgs = fluent::FluentArgs::new();
for (k, v) in &message.data {
Expand Down
14 changes: 9 additions & 5 deletions server/lsys-core/src/fluents/message.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
#[derive(Debug)]
pub struct FluentMessage {
pub id: &'static str,
pub id: String,
pub crate_name: String,
pub data: Vec<(String, String)>,
}

impl std::fmt::Display for FluentMessage {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}:{}", self.id, serde_json::json!(self.data))
if self.data.is_empty() {
write!(f, "{}", self.id)
} else {
write!(f, "{}:{}", self.id, serde_json::json!(self.data))
}
}
}

Expand All @@ -16,7 +20,7 @@ macro_rules! fluent_message {
($key:literal) => {
{
$crate::FluentMessage {
id: $key,
id: $key.to_owned(),
crate_name:env!("CARGO_PKG_NAME").to_string(),
data:vec![]
}
Expand All @@ -25,7 +29,7 @@ macro_rules! fluent_message {
($key:literal,{$($msg_key:literal:$msg_val:expr),+$(,)*}) => {
{
$crate::FluentMessage {
id: $key,
id: $key.to_owned(),
crate_name:env!("CARGO_PKG_NAME").to_string(),
data:vec![
$( ($msg_key.to_owned(), $msg_val.to_string()) ),*
Expand All @@ -36,7 +40,7 @@ macro_rules! fluent_message {
($key:literal,$msg_val:expr) => {
{
$crate::FluentMessage {
id: $key,
id: $key.to_owned(),
crate_name:env!("CARGO_PKG_NAME").to_string(),
data:vec![("msg".to_owned(),$msg_val.to_string())]
}
Expand Down
2 changes: 2 additions & 0 deletions server/lsys-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub mod cache;
mod config;
mod fluents;

mod listen_notify;
mod macros;
mod remote_notify;
mod task;
Expand All @@ -13,6 +14,7 @@ pub use app_core::*;
pub use config::*;
pub use fluents::*;

pub use listen_notify::*;
pub use remote_notify::*;
pub use task::*;
pub use utils::*;
Expand Down
Loading

0 comments on commit 282ade4

Please sign in to comment.