更新密码找回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

-22
View File
@@ -9,35 +9,26 @@ import (
beego "github.com/beego/beego/v2/server/web"
)
// hostnameRe 合法主机名:多段标签,每段字母数字或连字符,末段为字母(顶级域)
var hostnameRe = regexp.MustCompile(`^([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,}$`)
// NormalizeHost 归一化用户输入的域名:去协议、去路径、去端口、去尾点、转小写。
// 返回空字符串表示输入不是合法主机名。
func NormalizeHost(raw string) string {
h := strings.TrimSpace(strings.ToLower(raw))
if h == "" {
return ""
}
// 去掉协议前缀
if idx := strings.Index(h, "://"); idx >= 0 {
h = h[idx+3:]
}
// 去掉路径与查询
if idx := strings.IndexAny(h, "/?#"); idx >= 0 {
h = h[:idx]
}
// 去掉可能的 user@ 前缀
if idx := strings.LastIndex(h, "@"); idx >= 0 {
h = h[idx+1:]
}
// 去掉端口
if idx := strings.Index(h, ":"); idx >= 0 {
h = h[:idx]
}
// 去掉 FQDN 末尾的点
h = strings.TrimSuffix(h, ".")
// 去掉通配符写法
h = strings.TrimPrefix(h, "*.")
if len(h) > 253 || !hostnameRe.MatchString(h) {
@@ -46,13 +37,11 @@ func NormalizeHost(raw string) string {
return h
}
// CustomDomainGuide 自有域名的解析配置指引,供前端展示。
type CustomDomainGuide struct {
CnameTarget string `json:"cname_target"`
AIPs []string `json:"a_ips"`
}
// GetCustomDomainGuide 读取配置中的 CNAME 目标与 A 记录 IP。
func GetCustomDomainGuide() CustomDomainGuide {
target, _ := beego.AppConfig.String("customdomain_cname_target")
target = NormalizeHost(target)
@@ -72,13 +61,6 @@ func GetCustomDomainGuide() CustomDomainGuide {
return CustomDomainGuide{CnameTarget: target, AIPs: ips}
}
// VerifyCustomDomainDNS 检测域名是否已解析到本平台。
// 命中任一条件即通过:
// 1. CNAME 链最终指向配置的 cname_target(或其本身);
// 2. A/AAAA 记录中出现配置的任一 IP;
// 3. cname_target 自身解析出的 IP 与域名解析出的 IP 有交集(兼容 CNAME 被 DNS 服务商拍平的情况)。
//
// 返回 (是否通过, 说明文案)。说明文案会写入 verify_msg 展示给租户。
func VerifyCustomDomainDNS(host string) (bool, string) {
host = NormalizeHost(host)
if host == "" {
@@ -90,7 +72,6 @@ func VerifyCustomDomainDNS(host string) (bool, string) {
return false, "平台尚未配置解析目标(customdomain_cname_target / customdomain_a_ips),请联系平台管理员"
}
// 1. CNAME 校验
if guide.CnameTarget != "" {
if cname, err := net.LookupCNAME(host); err == nil {
actual := NormalizeHost(cname)
@@ -100,7 +81,6 @@ func VerifyCustomDomainDNS(host string) (bool, string) {
}
}
// 2/3. 解析出的 IP 与允许列表或 cname_target 的 IP 比对
addrs, err := net.LookupHost(host)
if err != nil {
return false, "域名无法解析,请确认解析记录已添加并等待生效:" + trimDNSError(err)
@@ -134,7 +114,6 @@ func VerifyCustomDomainDNS(host string) (bool, string) {
return false, fmt.Sprintf("当前解析到 %s,与平台地址不一致。%s", strings.Join(addrs, ", "), expect)
}
// describeExpectedTarget 生成「应该怎么配」的提示文案
func describeExpectedTarget(guide CustomDomainGuide) string {
parts := make([]string, 0, 2)
if guide.CnameTarget != "" {
@@ -149,7 +128,6 @@ func describeExpectedTarget(guide CustomDomainGuide) string {
return strings.Join(parts, ";") + "。"
}
// trimDNSError 精简 DNS 错误信息,避免把内部解析器地址写进给租户看的文案
func trimDNSError(err error) string {
msg := err.Error()
if idx := strings.LastIndex(msg, ": "); idx >= 0 && idx+2 < len(msg) {