use super::system_config_string;
use crate::{AppState, GatewayError};
use serde_json::json;
pub(crate) struct AdminEmailTemplateDefinition {
pub(crate) template_type: &'static str,
pub(crate) name: &'static str,
pub(crate) variables: &'static [&'static str],
pub(crate) default_subject: &'static str,
pub(crate) default_html: &'static str,
}
const ADMIN_EMAIL_TEMPLATE_DEFINITIONS: &[AdminEmailTemplateDefinition] = &[
AdminEmailTemplateDefinition {
template_type: "verification",
name: "注册验证码",
variables: &["app_name", "code", "expire_minutes", "email"],
default_subject: "验证码",
default_html: r#"
验证码
|
{{app_name}}
|
验证码
您正在注册账户,请使用以下验证码完成验证。
验证码将在 {{expire_minutes}} 分钟后失效
|
|
|
如果这不是您的操作,请忽略此邮件。
此邮件由系统自动发送,请勿回复
|
|
"#,
},
AdminEmailTemplateDefinition {
template_type: "password_reset",
name: "找回密码",
variables: &["app_name", "reset_link", "expire_minutes", "email"],
default_subject: "密码重置",
default_html: r#"
密码重置
|
{{app_name}}
|
重置密码
您正在重置账户密码,请点击下方按钮完成操作。
链接将在 {{expire_minutes}} 分钟后失效
|
|
|
如果您没有请求重置密码,请忽略此邮件。
此邮件由系统自动发送,请勿回复
|
|
"#,
},
];
pub(crate) fn admin_email_template_definition(
template_type: &str,
) -> Option<&'static AdminEmailTemplateDefinition> {
let normalized = template_type.trim();
ADMIN_EMAIL_TEMPLATE_DEFINITIONS
.iter()
.find(|definition| definition.template_type == normalized)
}
pub(crate) fn admin_email_template_subject_key(template_type: &str) -> String {
format!("email_template_{template_type}_subject")
}
pub(crate) fn admin_email_template_html_key(template_type: &str) -> String {
format!("email_template_{template_type}_html")
}
pub(crate) async fn read_admin_email_template_payload(
state: &AppState,
template_type: &str,
) -> Result