diff options
author | Zettat123 <zettat123@gmail.com> | 2024-03-11 14:07:36 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-11 06:07:36 +0000 |
commit | 4129e0e79bbf30e4297efd33feb2602c40322d10 (patch) | |
tree | 8b9b9d18835cc3dfd290f204f8802e7df860a0f8 /models/user | |
parent | 8fc1a8f0eb642c574610a346e858d42c433ebe01 (diff) | |
download | gitea-4129e0e79bbf30e4297efd33feb2602c40322d10.tar.gz gitea-4129e0e79bbf30e4297efd33feb2602c40322d10.zip |
Add a warning for disallowed email domains (#29658)
Resolve #29660
Follow #29522 and #29609
Add a warning for disallowed email domains when admins manually add/edit
users.
Thanks @yp05327 for the
[comment](https://github.com/go-gitea/gitea/pull/29605#issuecomment-1980105119)
![image](https://github.com/go-gitea/gitea/assets/15528715/6737b221-a3a2-4180-9ef8-b846c10f96e0)
Diffstat (limited to 'models/user')
-rw-r--r-- | models/user/email_address.go | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/models/user/email_address.go b/models/user/email_address.go index 11700a0129..a9dbb8e891 100644 --- a/models/user/email_address.go +++ b/models/user/email_address.go @@ -539,17 +539,17 @@ func validateEmailBasic(email string) error { // validateEmailDomain checks whether the email domain is allowed or blocked func validateEmailDomain(email string) error { - // if there is no allow list, then check email against block list - if len(setting.Service.EmailDomainAllowList) == 0 && - validation.IsEmailDomainListed(setting.Service.EmailDomainBlockList, email) { + if !IsEmailDomainAllowed(email) { return ErrEmailInvalid{email} } - // if there is an allow list, then check email against allow list - if len(setting.Service.EmailDomainAllowList) > 0 && - !validation.IsEmailDomainListed(setting.Service.EmailDomainAllowList, email) { - return ErrEmailInvalid{email} + return nil +} + +func IsEmailDomainAllowed(email string) bool { + if len(setting.Service.EmailDomainAllowList) == 0 { + return !validation.IsEmailDomainListed(setting.Service.EmailDomainBlockList, email) } - return nil + return validation.IsEmailDomainListed(setting.Service.EmailDomainAllowList, email) } |