This commit is contained in:
Ghostz 2024-04-23 12:46:42 +08:00
commit 719279a599

View File

@ -84,17 +84,27 @@ func SendEmailVerification(c *gin.Context) {
return return
} }
if config.EmailDomainRestrictionEnabled { if config.EmailDomainRestrictionEnabled {
parts := strings.Split(email, "@")
localPart := parts[0]
domainPart := parts[1]
containsSpecialSymbols := strings.Contains(localPart, "+") || strings.Count(localPart, ".") > 1
allowed := false allowed := false
for _, domain := range config.EmailDomainWhitelist { for _, domain := range config.EmailDomainWhitelist {
if strings.HasSuffix(email, "@"+domain) { if domainPart == domain {
allowed = true allowed = true
break break
} }
} }
if !allowed { if allowed && !containsSpecialSymbols {
c.JSON(http.StatusOK, gin.H{
"success": true,
"message": "Your email address is allowed.",
})
} else {
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"success": false, "success": false,
"message": "管理员启用了邮箱域名白名单,您的邮箱地址的域名不在白名单中", "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.",
}) })
return return
} }