Check blocklist for emails when adding them to account (#26812)
This commit is contained in:
parent
1bb9b1c4d9
commit
45976a1bde
3 changed files with 40 additions and 27 deletions
|
@ -10,6 +10,8 @@ import (
|
|||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
||||
"github.com/gobwas/glob"
|
||||
)
|
||||
|
||||
var externalTrackerRegex = regexp.MustCompile(`({?)(?:user|repo|index)+?(}?)`)
|
||||
|
@ -48,6 +50,29 @@ func IsValidSiteURL(uri string) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
// IsEmailDomainListed checks whether the domain of an email address
|
||||
// matches a list of domains
|
||||
func IsEmailDomainListed(globs []glob.Glob, email string) bool {
|
||||
if len(globs) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
n := strings.LastIndex(email, "@")
|
||||
if n <= 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
domain := strings.ToLower(email[n+1:])
|
||||
|
||||
for _, g := range globs {
|
||||
if g.Match(domain) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// IsAPIURL checks if URL is current Gitea instance API URL
|
||||
func IsAPIURL(uri string) bool {
|
||||
return strings.HasPrefix(strings.ToLower(uri), strings.ToLower(setting.AppURL+"api"))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue