mirror of
https://github.com/linux-do/new-api.git
synced 2025-09-17 16:06:38 +08:00
Merge remote-tracking branch 'upstream/main'
This commit is contained in:
commit
cd3ed22045
@ -57,7 +57,8 @@ var TurnstileCheckEnabled = false
|
|||||||
var RegisterEnabled = true
|
var RegisterEnabled = true
|
||||||
var UserSelfDeletionEnabled = false
|
var UserSelfDeletionEnabled = false
|
||||||
|
|
||||||
var EmailDomainRestrictionEnabled = false
|
var EmailDomainRestrictionEnabled = false // 是否启用邮箱域名限制
|
||||||
|
var EmailAliasRestrictionEnabled = false // 是否启用邮箱别名限制
|
||||||
var EmailDomainWhitelist = []string{
|
var EmailDomainWhitelist = []string{
|
||||||
"gmail.com",
|
"gmail.com",
|
||||||
"163.com",
|
"163.com",
|
||||||
|
@ -122,12 +122,17 @@ func SendEmailVerification(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
return
|
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 {
|
if common.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 common.EmailDomainWhitelist {
|
for _, domain := range common.EmailDomainWhitelist {
|
||||||
if domainPart == domain {
|
if domainPart == domain {
|
||||||
@ -135,13 +140,7 @@ func SendEmailVerification(c *gin.Context) {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if allowed && !containsSpecialSymbols {
|
if !allowed {
|
||||||
c.JSON(http.StatusOK, gin.H{
|
|
||||||
"success": false,
|
|
||||||
"message": "Your email address is allowed.",
|
|
||||||
})
|
|
||||||
return
|
|
||||||
} else {
|
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"success": false,
|
"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.",
|
"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
|
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) {
|
if model.IsEmailAlreadyTaken(email) {
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"success": false,
|
"success": false,
|
||||||
|
@ -46,6 +46,7 @@ func InitOptionMap() {
|
|||||||
common.OptionMap["DataExportEnabled"] = strconv.FormatBool(common.DataExportEnabled)
|
common.OptionMap["DataExportEnabled"] = strconv.FormatBool(common.DataExportEnabled)
|
||||||
common.OptionMap["ChannelDisableThreshold"] = strconv.FormatFloat(common.ChannelDisableThreshold, 'f', -1, 64)
|
common.OptionMap["ChannelDisableThreshold"] = strconv.FormatFloat(common.ChannelDisableThreshold, 'f', -1, 64)
|
||||||
common.OptionMap["EmailDomainRestrictionEnabled"] = strconv.FormatBool(common.EmailDomainRestrictionEnabled)
|
common.OptionMap["EmailDomainRestrictionEnabled"] = strconv.FormatBool(common.EmailDomainRestrictionEnabled)
|
||||||
|
common.OptionMap["EmailAliasRestrictionEnabled"] = strconv.FormatBool(common.EmailAliasRestrictionEnabled)
|
||||||
common.OptionMap["EmailDomainWhitelist"] = strings.Join(common.EmailDomainWhitelist, ",")
|
common.OptionMap["EmailDomainWhitelist"] = strings.Join(common.EmailDomainWhitelist, ",")
|
||||||
common.OptionMap["SMTPServer"] = ""
|
common.OptionMap["SMTPServer"] = ""
|
||||||
common.OptionMap["SMTPFrom"] = ""
|
common.OptionMap["SMTPFrom"] = ""
|
||||||
@ -183,6 +184,8 @@ func updateOptionMap(key string, value string) (err error) {
|
|||||||
common.UserSelfDeletionEnabled = boolValue
|
common.UserSelfDeletionEnabled = boolValue
|
||||||
case "EmailDomainRestrictionEnabled":
|
case "EmailDomainRestrictionEnabled":
|
||||||
common.EmailDomainRestrictionEnabled = boolValue
|
common.EmailDomainRestrictionEnabled = boolValue
|
||||||
|
case "EmailAliasRestrictionEnabled":
|
||||||
|
common.EmailAliasRestrictionEnabled = boolValue
|
||||||
case "AutomaticDisableChannelEnabled":
|
case "AutomaticDisableChannelEnabled":
|
||||||
common.AutomaticDisableChannelEnabled = boolValue
|
common.AutomaticDisableChannelEnabled = boolValue
|
||||||
case "AutomaticEnableChannelEnabled":
|
case "AutomaticEnableChannelEnabled":
|
||||||
|
@ -47,6 +47,7 @@ const SystemSetting = () => {
|
|||||||
RegisterEnabled: '',
|
RegisterEnabled: '',
|
||||||
UserSelfDeletionEnabled: false,
|
UserSelfDeletionEnabled: false,
|
||||||
EmailDomainRestrictionEnabled: '',
|
EmailDomainRestrictionEnabled: '',
|
||||||
|
EmailAliasRestrictionEnabled: '',
|
||||||
SMTPSSLEnabled: '',
|
SMTPSSLEnabled: '',
|
||||||
EmailDomainWhitelist: [],
|
EmailDomainWhitelist: [],
|
||||||
// telegram login
|
// telegram login
|
||||||
@ -105,6 +106,7 @@ const SystemSetting = () => {
|
|||||||
case 'TelegramOAuthEnabled':
|
case 'TelegramOAuthEnabled':
|
||||||
case 'TurnstileCheckEnabled':
|
case 'TurnstileCheckEnabled':
|
||||||
case 'EmailDomainRestrictionEnabled':
|
case 'EmailDomainRestrictionEnabled':
|
||||||
|
case 'EmailAliasRestrictionEnabled':
|
||||||
case 'SMTPSSLEnabled':
|
case 'SMTPSSLEnabled':
|
||||||
case 'RegisterEnabled':
|
case 'RegisterEnabled':
|
||||||
case 'UserSelfDeletionEnabled':
|
case 'UserSelfDeletionEnabled':
|
||||||
@ -562,6 +564,14 @@ const SystemSetting = () => {
|
|||||||
checked={inputs.EmailDomainRestrictionEnabled === 'true'}
|
checked={inputs.EmailDomainRestrictionEnabled === 'true'}
|
||||||
/>
|
/>
|
||||||
</Form.Group>
|
</Form.Group>
|
||||||
|
<Form.Group widths={3}>
|
||||||
|
<Form.Checkbox
|
||||||
|
label='启用邮箱别名限制(例如:ab.cd@gmail.com)'
|
||||||
|
name='EmailAliasRestrictionEnabled'
|
||||||
|
onChange={handleInputChange}
|
||||||
|
checked={inputs.EmailAliasRestrictionEnabled === 'true'}
|
||||||
|
/>
|
||||||
|
</Form.Group>
|
||||||
<Form.Group widths={2}>
|
<Form.Group widths={2}>
|
||||||
<Form.Dropdown
|
<Form.Dropdown
|
||||||
label='允许的邮箱域名'
|
label='允许的邮箱域名'
|
||||||
|
Loading…
Reference in New Issue
Block a user