更新密码找回uniapp

This commit is contained in:
hero920103 committed 2026-11-16 17:22:50 +08:00
1 parent 7f9a66da0f
commit 3fdda89833
1304 files changed
+3503 -26132

No files matched your search

+2 -22
View File
@@ -19,8 +19,6 @@ import (
beego "github.com/beego/beego/v2/server/web"
)
// PlatformTemplateController 官网模板管理(平台端专用)
// 模板文件存磁盘 themes/{code}/,DB 仅登记元信息;租户端只读选用。
type PlatformTemplateController struct {
beego.Controller
}
@@ -31,12 +29,10 @@ func (c *PlatformTemplateController) jsonErr(httpStatus, bizCode int, msg string
_ = c.ServeJSON()
}
// cmsThemesRoot 模板根目录(相对运行目录),渲染与静态路径保持一致
func cmsThemesRoot() string {
return "themes"
}
// cmsTemplateSafePath 校验 code 与相对路径,返回模板文件的绝对安全路径(防目录穿越)
func cmsTemplateSafePath(code, rel string) (string, error) {
if !reThemeCode.MatchString(code) {
return "", fmt.Errorf("模板编码不合法")
@@ -65,7 +61,6 @@ func cmsTemplateSafePath(code, rel string) (string, error) {
return abs, nil
}
// cmsTemplateDirExists 判断模板目录是否存在
func cmsTemplateDirExists(code string) bool {
if !reThemeCode.MatchString(code) {
return false
@@ -88,7 +83,6 @@ func cmsTemplateToMap(row models.CmsFrontendTemplate) map[string]interface{} {
}
}
// Index GET /platform/template/index 模板列表(DB 登记)
func (c *PlatformTemplateController) Index() {
if _, err := requirePlatform(&c.Controller); err != nil {
code := identity.Status(err)
@@ -119,7 +113,6 @@ func (c *PlatformTemplateController) Index() {
_ = c.ServeJSON()
}
// cmsScanThemeDirs 扫描 themes/ 目录,返回磁盘上的模板编码列表
func cmsScanThemeDirs() []string {
entries, err := os.ReadDir(cmsThemesRoot())
if err != nil {
@@ -135,7 +128,6 @@ func cmsScanThemeDirs() []string {
return out
}
// Scan POST /platform/template/scan 扫描 themes/ 目录,新目录自动登记入库
func (c *PlatformTemplateController) Scan() {
if _, err := requirePlatform(&c.Controller); err != nil {
code := identity.Status(err)
@@ -180,7 +172,6 @@ func (c *PlatformTemplateController) Scan() {
_ = c.ServeJSON()
}
// Upload POST /platform/template/upload 上传模板 zip(解压到 themes/{code}/)
func (c *PlatformTemplateController) Upload() {
if _, err := requirePlatform(&c.Controller); err != nil {
code := identity.Status(err)
@@ -197,7 +188,6 @@ func (c *PlatformTemplateController) Upload() {
code := strings.TrimSpace(c.GetString("code"))
if code == "" {
// 未显式指定编码时取上传文件名(去扩展名)
code = strings.TrimSuffix(header.Filename, filepath.Ext(header.Filename))
}
code = strings.ToLower(strings.TrimSpace(code))
@@ -230,7 +220,6 @@ func (c *PlatformTemplateController) Upload() {
return
}
// 解压成功后自动登记/更新 DB
now := time.Now()
cnt, _ := models.Orm.QueryTable(new(models.CmsFrontendTemplate)).
Filter("code", code).
@@ -262,8 +251,6 @@ func (c *PlatformTemplateController) Upload() {
_ = c.ServeJSON()
}
// cmsUnzipTemplate 解压模板 zip 到目标目录;
// 支持 zip 内含单一顶层目录的情况(自动剥离),并拦截 zip-slip。
func cmsUnzipTemplate(zipPath, destDir string) error {
r, err := zip.OpenReader(zipPath)
if err != nil {
@@ -271,7 +258,6 @@ func cmsUnzipTemplate(zipPath, destDir string) error {
}
defer r.Close()
// 探测是否所有文件都在同一顶层目录下
topDir := ""
singleTop := true
for _, f := range r.File {
@@ -306,7 +292,7 @@ func cmsUnzipTemplate(zipPath, destDir string) error {
if singleTop && topDir != "" {
parts := strings.Split(strings.Trim(name, "/"), "/")
if len(parts) == 1 && f.FileInfo().IsDir() {
continue // 顶层目录本身
continue
}
rel = strings.Join(parts[1:], "/")
if rel == "" {
@@ -317,7 +303,7 @@ func cmsUnzipTemplate(zipPath, destDir string) error {
target := filepath.Join(destAbs, filepath.FromSlash(rel))
tabs, _ := filepath.Abs(target)
if !strings.HasPrefix(tabs, destAbs+string(filepath.Separator)) {
continue // 越界条目直接跳过
continue
}
if f.FileInfo().IsDir() {
@@ -349,7 +335,6 @@ func cmsUnzipTemplate(zipPath, destDir string) error {
return nil
}
// Files GET /platform/template/files/:code 列出模板目录下可编辑文件
func (c *PlatformTemplateController) Files() {
if _, err := requirePlatform(&c.Controller); err != nil {
code := identity.Status(err)
@@ -391,7 +376,6 @@ func (c *PlatformTemplateController) Files() {
_ = c.ServeJSON()
}
// ReadFile GET /platform/template/file?code=&path= 读取模板文件内容
func (c *PlatformTemplateController) ReadFile() {
if _, err := requirePlatform(&c.Controller); err != nil {
code := identity.Status(err)
@@ -424,7 +408,6 @@ func (c *PlatformTemplateController) ReadFile() {
_ = c.ServeJSON()
}
// SaveFile POST /platform/template/file/save 保存模板文件(路径校验防穿越)
func (c *PlatformTemplateController) SaveFile() {
if _, err := requirePlatform(&c.Controller); err != nil {
code := identity.Status(err)
@@ -474,7 +457,6 @@ func (c *PlatformTemplateController) SaveFile() {
_ = c.ServeJSON()
}
// Status POST /platform/template/status 启用/停用模板
func (c *PlatformTemplateController) Status() {
if _, err := requirePlatform(&c.Controller); err != nil {
code := identity.Status(err)
@@ -518,7 +500,6 @@ func (c *PlatformTemplateController) Status() {
_ = c.ServeJSON()
}
// Delete POST /platform/template/delete/:id 删除登记(可选同时删除磁盘目录)
func (c *PlatformTemplateController) Delete() {
if _, err := requirePlatform(&c.Controller); err != nil {
code := identity.Status(err)
@@ -569,7 +550,6 @@ func (c *PlatformTemplateController) Delete() {
_ = c.ServeJSON()
}
// Tags GET /platform/template/tags 标签调用说明数据(由引擎注册表元信息生成)
func (c *PlatformTemplateController) Tags() {
if _, err := requirePlatform(&c.Controller); err != nil {
code := identity.Status(err)