opt: add enabled_msg_service config var to system config database

This commit is contained in:
RockYang
2023-08-03 10:04:45 +08:00
parent 18d74f1057
commit d7b278f2f7
5 changed files with 29 additions and 24 deletions

View File

@@ -6,20 +6,19 @@ import (
)
type AppConfig struct {
Path string `toml:"-"`
Listen string
Session Session
ProxyURL string
MysqlDns string // mysql 连接地址
Manager Manager // 后台管理员账户信息
StaticDir string // 静态资源目录
StaticUrl string // 静态资源 URL
Redis RedisConfig // redis 连接信息
ApiConfig ChatPlusApiConfig // ChatPlus API authorization configs
AesEncryptKey string
SmsConfig AliYunSmsConfig // AliYun send message service config
StartWechatBot bool // 是否启动微信机器人
EnabledMsgService bool // 是否启用短信服务
Path string `toml:"-"`
Listen string
Session Session
ProxyURL string
MysqlDns string // mysql 连接地址
Manager Manager // 后台管理员账户信息
StaticDir string // 静态资源目录
StaticUrl string // 静态资源 URL
Redis RedisConfig // redis 连接信息
ApiConfig ChatPlusApiConfig // ChatPlus API authorization configs
AesEncryptKey string
SmsConfig AliYunSmsConfig // AliYun send message service config
StartWechatBot bool // 是否启动微信机器人
}
type ChatPlusApiConfig struct {
@@ -85,9 +84,10 @@ type ChatConfig struct {
}
type SystemConfig struct {
Title string `json:"title"`
AdminTitle string `json:"admin_title"`
Models []string `json:"models"`
UserInitCalls int `json:"user_init_calls"` // 新用户注册默认总送多少次调用
EnabledRegister bool `json:"enabled_register"`
Title string `json:"title"`
AdminTitle string `json:"admin_title"`
Models []string `json:"models"`
UserInitCalls int `json:"user_init_calls"` // 新用户注册默认总送多少次调用
EnabledRegister bool `json:"enabled_register"`
EnabledMsgService bool `json:"enabled_msg_service"`
}

View File

@@ -66,5 +66,5 @@ type statusVo struct {
// Status check if the message service is enabled
func (h *SmsHandler) Status(c *gin.Context) {
resp.SUCCESS(c, statusVo{EnabledMsgService: h.App.Config.EnabledMsgService, EnabledRegister: h.App.SysConfig.EnabledRegister})
resp.SUCCESS(c, statusVo{EnabledMsgService: h.App.SysConfig.EnabledMsgService, EnabledRegister: h.App.SysConfig.EnabledRegister})
}

View File

@@ -58,7 +58,7 @@ func (h *UserHandler) Register(c *gin.Context) {
// 检查验证码
key := CodeStorePrefix + data.Mobile
if h.App.Config.EnabledMsgService {
if h.App.SysConfig.EnabledMsgService {
var code int
err := h.levelDB.Get(key, &code)
if err != nil || code != data.Code {
@@ -117,7 +117,7 @@ func (h *UserHandler) Register(c *gin.Context) {
return
}
if h.App.Config.EnabledMsgService {
if h.App.SysConfig.EnabledMsgService {
_ = h.levelDB.Delete(key) // 注册成功,删除短信验证码
}
resp.SUCCESS(c, user)