Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block registration based on email domain #5157

Merged
Prev Previous commit
Next Next commit
update method name
  • Loading branch information
adelowo committed Oct 25, 2018
commit 7115126bc1965267745facd3b3847849d972cb17
4 changes: 2 additions & 2 deletions modules/auth/user_form.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ func (f *RegisterForm) Validate(ctx *macaron.Context, errs binding.Errors) bindi
return validate(errs, ctx.Data, f, ctx.Locale)
}

// IsEmailDomainWhitelisted validates that the email address
// IsEmaildomainwhitelisted validates that the email address
// provided by the user matches what has been configured .
// If the domain whitelist from the config is empty, it marks the
// email as whitelisted
func (f RegisterForm) IsEmailDomainWhitelisted() bool {
func (f RegisterForm) IsEmaildomainwhitelisted() bool {
adelowo marked this conversation as resolved.
Show resolved Hide resolved
if len(setting.Service.EmailDomainWhitelist) == 0 {
return true
}
Expand Down
6 changes: 3 additions & 3 deletions modules/auth/user_form_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestRegisterForm_IsDomainWhiteList_Empty(t *testing.T) {

form := RegisterForm{}

assert.True(t, form.IsEmailDomainWhitelisted())
assert.True(t, form.IsEmaildomainwhitelisted())
}

func TestRegisterForm_IsDomainWhiteList_InvalidEmail(t *testing.T) {
Expand All @@ -37,7 +37,7 @@ func TestRegisterForm_IsDomainWhiteList_InvalidEmail(t *testing.T) {
for _, v := range tt {
form := RegisterForm{Email: v.email}

assert.False(t, form.IsEmailDomainWhitelisted())
assert.False(t, form.IsEmaildomainwhitelisted())
}
}

Expand All @@ -58,6 +58,6 @@ func TestRegisterForm_IsDomainWhiteList_ValidEmail(t *testing.T) {
for _, v := range tt {
form := RegisterForm{Email: v.email}

assert.Equal(t, v.valid, form.IsEmailDomainWhitelisted())
assert.Equal(t, v.valid, form.IsEmaildomainwhitelisted())
}
}
2 changes: 1 addition & 1 deletion routers/user/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ func SignUpPost(ctx *context.Context, cpt *captcha.Captcha, form auth.RegisterFo
}
}

if !form.IsEmailDomainWhitelisted() {
if !form.IsEmaildomainwhitelisted() {
ctx.RenderWithErr(ctx.Tr("auth.email_domain_blacklisted"), tplSignUp, &form)
return
}
Expand Down