Skip to content

Commit 1546458

Browse files
FabioFortinilunny
authored andcommitted
issue-2768: added new option allow_only_external_registration (#3910)
1 parent e740558 commit 1546458

File tree

8 files changed

+20
-2
lines changed

8 files changed

+20
-2
lines changed

custom/conf/app.ini.sample

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ RESET_PASSWD_CODE_LIVE_MINUTES = 180
288288
REGISTER_EMAIL_CONFIRM = false
289289
; Disallow registration, only allow admins to create accounts.
290290
DISABLE_REGISTRATION = false
291+
; Allow registration only using third part services, it works only when DISABLE_REGISTRATION is false
292+
ALLOW_ONLY_EXTERNAL_REGISTRATION = false
291293
; User must sign in to view anything.
292294
REQUIRE_SIGNIN_VIEW = false
293295
; Mail notification

modules/auth/user_form.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type InstallForm struct {
4444
EnableOpenIDSignIn bool
4545
EnableOpenIDSignUp bool
4646
DisableRegistration bool
47+
AllowOnlyExternalRegistration bool
4748
EnableCaptcha bool
4849
RequireSignInView bool
4950
DefaultKeepEmailPrivate bool

modules/setting/setting.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1143,6 +1143,7 @@ var Service struct {
11431143
ResetPwdCodeLives int
11441144
RegisterEmailConfirm bool
11451145
DisableRegistration bool
1146+
AllowOnlyExternalRegistration bool
11461147
ShowRegistrationButton bool
11471148
RequireSignInView bool
11481149
EnableNotifyMail bool
@@ -1168,7 +1169,8 @@ func newService() {
11681169
Service.ActiveCodeLives = sec.Key("ACTIVE_CODE_LIVE_MINUTES").MustInt(180)
11691170
Service.ResetPwdCodeLives = sec.Key("RESET_PASSWD_CODE_LIVE_MINUTES").MustInt(180)
11701171
Service.DisableRegistration = sec.Key("DISABLE_REGISTRATION").MustBool()
1171-
Service.ShowRegistrationButton = sec.Key("SHOW_REGISTRATION_BUTTON").MustBool(!Service.DisableRegistration)
1172+
Service.AllowOnlyExternalRegistration = sec.Key("ALLOW_ONLY_EXTERNAL_REGISTRATION").MustBool()
1173+
Service.ShowRegistrationButton = sec.Key("SHOW_REGISTRATION_BUTTON").MustBool(!(Service.DisableRegistration || Service.AllowOnlyExternalRegistration))
11721174
Service.RequireSignInView = sec.Key("REQUIRE_SIGNIN_VIEW").MustBool()
11731175
Service.EnableReverseProxyAuth = sec.Key("ENABLE_REVERSE_PROXY_AUTHENTICATION").MustBool()
11741176
Service.EnableReverseProxyAutoRegister = sec.Key("ENABLE_REVERSE_PROXY_AUTO_REGISTRATION").MustBool()

options/locale/locale_en-US.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ federated_avatar_lookup = Enable Federated Avatars
117117
federated_avatar_lookup_popup = Enable federated avatar lookup using Libravatar.
118118
disable_registration = Disable Self-Registration
119119
disable_registration_popup = Disable user self-registration. Only administrators will be able to create new user accounts.
120+
allow_only_external_registration_popup=Enable the registration only through external services.
120121
openid_signin = Enable OpenID Sign-In
121122
openid_signin_popup = Enable user sign-in via OpenID.
122123
openid_signup = Enable OpenID Self-Registration
@@ -1442,6 +1443,7 @@ config.db_path_helper = (for "sqlite3" and "tidb")
14421443
config.service_config = Service Configuration
14431444
config.register_email_confirm = Require Email Confirmation to Register
14441445
config.disable_register = Disable Self-Registration
1446+
config.allow_only_external_registration = Enable the registration only through external services
14451447
config.enable_openid_signup = Enable OpenID Self-Registration
14461448
config.enable_openid_signin = Enable OpenID Sign-In
14471449
config.show_registration_button = Show Register Button

routers/install.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ func Install(ctx *context.Context) {
112112
form.EnableOpenIDSignIn = setting.Service.EnableOpenIDSignIn
113113
form.EnableOpenIDSignUp = setting.Service.EnableOpenIDSignUp
114114
form.DisableRegistration = setting.Service.DisableRegistration
115+
form.AllowOnlyExternalRegistration = setting.Service.AllowOnlyExternalRegistration
115116
form.EnableCaptcha = setting.Service.EnableCaptcha
116117
form.RequireSignInView = setting.Service.RequireSignInView
117118
form.DefaultKeepEmailPrivate = setting.Service.DefaultKeepEmailPrivate
@@ -304,6 +305,7 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) {
304305
cfg.Section("openid").Key("ENABLE_OPENID_SIGNIN").SetValue(com.ToStr(form.EnableOpenIDSignIn))
305306
cfg.Section("openid").Key("ENABLE_OPENID_SIGNUP").SetValue(com.ToStr(form.EnableOpenIDSignUp))
306307
cfg.Section("service").Key("DISABLE_REGISTRATION").SetValue(com.ToStr(form.DisableRegistration))
308+
cfg.Section("service").Key("ALLOW_ONLY_EXTERNAL_REGISTRATION").SetValue(com.ToStr(form.AllowOnlyExternalRegistration))
307309
cfg.Section("service").Key("ENABLE_CAPTCHA").SetValue(com.ToStr(form.EnableCaptcha))
308310
cfg.Section("service").Key("REQUIRE_SIGNIN_VIEW").SetValue(com.ToStr(form.RequireSignInView))
309311
cfg.Section("service").Key("DEFAULT_KEEP_EMAIL_PRIVATE").SetValue(com.ToStr(form.DefaultKeepEmailPrivate))

routers/user/auth.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,8 @@ func SignUpPost(ctx *context.Context, cpt *captcha.Captcha, form auth.RegisterFo
741741

742742
ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha
743743

744-
if setting.Service.DisableRegistration {
744+
//Permission denied if DisableRegistration or AllowOnlyExternalRegistration options are true
745+
if !setting.Service.ShowRegistrationButton {
745746
ctx.Error(403)
746747
return
747748
}

templates/admin/config.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@
114114
<dd><i class="fa fa{{if .Service.RegisterEmailConfirm}}-check{{end}}-square-o"></i></dd>
115115
<dt>{{.i18n.Tr "admin.config.disable_register"}}</dt>
116116
<dd><i class="fa fa{{if .Service.DisableRegistration}}-check{{end}}-square-o"></i></dd>
117+
<dt>{{.i18n.Tr "admin.config.allow_only_external_registration"}}</dt>
118+
<dd><i class="fa fa{{if .Service.AllowOnlyExternalRegistration}}-check{{end}}-square-o"></i></dd>
117119
<dt>{{.i18n.Tr "admin.config.show_registration_button"}}</dt>
118120
<dd><i class="fa fa{{if .Service.ShowRegistrationButton}}-check{{end}}-square-o"></i></dd>
119121
<dt>{{.i18n.Tr "admin.config.enable_openid_signup"}}</dt>

templates/install.tmpl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,12 @@
200200
<input name="disable_registration" type="checkbox" {{if .disable_registration}}checked{{end}}>
201201
</div>
202202
</div>
203+
<div class="inline field">
204+
<div class="ui checkbox" id="allow-only-external-registration">
205+
<label class="poping up" data-content="{{.i18n.Tr "install.allow_only_external_registration_popup"}}"><strong>{{.i18n.Tr "install.allow_only_external_registration_popup"}}</strong></label>
206+
<input name="allow_only_external_registration" type="checkbox" {{if .allow_only_external_registration}}checked{{end}}>
207+
</div>
208+
</div>
203209
<div class="inline field">
204210
<div class="ui checkbox" id="enable-openid-signup">
205211
<label class="poping up" data-content="{{.i18n.Tr "install.openid_signup_popup"}}"><strong>{{.i18n.Tr "install.openid_signup"}}</strong></label>

0 commit comments

Comments
 (0)