diff --git a/common/constants.go b/common/constants.go index 98e6abd..82a1fa5 100644 --- a/common/constants.go +++ b/common/constants.go @@ -57,7 +57,8 @@ var TurnstileCheckEnabled = false var RegisterEnabled = true var UserSelfDeletionEnabled = false -var EmailDomainRestrictionEnabled = false +var EmailDomainRestrictionEnabled = false // 是否启用邮箱域名限制 +var EmailAliasRestrictionEnabled = false // 是否启用邮箱别名限制 var EmailDomainWhitelist = []string{ "gmail.com", "163.com", diff --git a/controller/misc.go b/controller/misc.go index ecc1f26..8a3e7f6 100644 --- a/controller/misc.go +++ b/controller/misc.go @@ -122,12 +122,17 @@ func SendEmailVerification(c *gin.Context) { }) return } + parts := strings.Split(email, "@") + if len(parts) != 2 { + c.JSON(http.StatusOK, gin.H{ + "success": false, + "message": "无效的邮箱地址", + }) + return + } + localPart := parts[0] + domainPart := parts[1] if common.EmailDomainRestrictionEnabled { - parts := strings.Split(email, "@") - localPart := parts[0] - domainPart := parts[1] - - containsSpecialSymbols := strings.Contains(localPart, "+") || strings.Count(localPart, ".") > 1 allowed := false for _, domain := range common.EmailDomainWhitelist { if domainPart == domain { @@ -135,13 +140,7 @@ func SendEmailVerification(c *gin.Context) { break } } - if allowed && !containsSpecialSymbols { - c.JSON(http.StatusOK, gin.H{ - "success": false, - "message": "Your email address is allowed.", - }) - return - } else { + if !allowed { c.JSON(http.StatusOK, gin.H{ "success": false, "message": "The administrator has enabled the email domain name whitelist, and your email address is not allowed due to special symbols or it's not in the whitelist.", @@ -149,6 +148,17 @@ func SendEmailVerification(c *gin.Context) { return } } + if common.EmailAliasRestrictionEnabled { + containsSpecialSymbols := strings.Contains(localPart, "+") || strings.Count(localPart, ".") > 1 + if containsSpecialSymbols { + c.JSON(http.StatusOK, gin.H{ + "success": false, + "message": "管理员已启用邮箱地址别名限制,您的邮箱地址由于包含特殊符号而被拒绝。", + }) + return + } + } + if model.IsEmailAlreadyTaken(email) { c.JSON(http.StatusOK, gin.H{ "success": false, diff --git a/model/option.go b/model/option.go index 2a32c72..a1b0738 100644 --- a/model/option.go +++ b/model/option.go @@ -46,6 +46,7 @@ func InitOptionMap() { common.OptionMap["DataExportEnabled"] = strconv.FormatBool(common.DataExportEnabled) common.OptionMap["ChannelDisableThreshold"] = strconv.FormatFloat(common.ChannelDisableThreshold, 'f', -1, 64) common.OptionMap["EmailDomainRestrictionEnabled"] = strconv.FormatBool(common.EmailDomainRestrictionEnabled) + common.OptionMap["EmailAliasRestrictionEnabled"] = strconv.FormatBool(common.EmailAliasRestrictionEnabled) common.OptionMap["EmailDomainWhitelist"] = strings.Join(common.EmailDomainWhitelist, ",") common.OptionMap["SMTPServer"] = "" common.OptionMap["SMTPFrom"] = "" @@ -183,6 +184,8 @@ func updateOptionMap(key string, value string) (err error) { common.UserSelfDeletionEnabled = boolValue case "EmailDomainRestrictionEnabled": common.EmailDomainRestrictionEnabled = boolValue + case "EmailAliasRestrictionEnabled": + common.EmailAliasRestrictionEnabled = boolValue case "AutomaticDisableChannelEnabled": common.AutomaticDisableChannelEnabled = boolValue case "AutomaticEnableChannelEnabled": diff --git a/web/src/components/SystemSetting.js b/web/src/components/SystemSetting.js index ddf9615..4d5889d 100644 --- a/web/src/components/SystemSetting.js +++ b/web/src/components/SystemSetting.js @@ -47,6 +47,7 @@ const SystemSetting = () => { RegisterEnabled: '', UserSelfDeletionEnabled: false, EmailDomainRestrictionEnabled: '', + EmailAliasRestrictionEnabled: '', SMTPSSLEnabled: '', EmailDomainWhitelist: [], // telegram login @@ -105,6 +106,7 @@ const SystemSetting = () => { case 'TelegramOAuthEnabled': case 'TurnstileCheckEnabled': case 'EmailDomainRestrictionEnabled': + case 'EmailAliasRestrictionEnabled': case 'SMTPSSLEnabled': case 'RegisterEnabled': case 'UserSelfDeletionEnabled': @@ -562,6 +564,14 @@ const SystemSetting = () => { checked={inputs.EmailDomainRestrictionEnabled === 'true'} /> +