Skip to content

Commit 129b0d6

Browse files
strkappleboy
authored andcommitted
Allow ENABLE_OPENID_SIGNUP to depend on DISABLE_REGISTRATION (#1369)
* Allow ENABLE_OPENID_SIGNUP to depend on DISABLE_REGISTRATION Omit the configuration variable (the default) to be dependent. Fixes #1363 * Move OpenID settings under Service object * Show OpenID SignUp and SignIn status in admin panel / configuration
1 parent 08f7fde commit 129b0d6

File tree

7 files changed

+47
-38
lines changed

7 files changed

+47
-38
lines changed

cmd/web.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ func runWeb(ctx *cli.Context) error {
200200
m.Group("/user", func() {
201201
m.Get("/login", user.SignIn)
202202
m.Post("/login", bindIgnErr(auth.SignInForm{}), user.SignInPost)
203-
if setting.EnableOpenIDSignIn {
203+
if setting.Service.EnableOpenIDSignIn {
204204
m.Combo("/login/openid").
205205
Get(user.SignInOpenID).
206206
Post(bindIgnErr(auth.SignInOpenIDForm{}), user.SignInOpenIDPost)
@@ -243,7 +243,7 @@ func runWeb(ctx *cli.Context) error {
243243
m.Post("/email/delete", user.DeleteEmail)
244244
m.Get("/password", user.SettingsPassword)
245245
m.Post("/password", bindIgnErr(auth.ChangePasswordForm{}), user.SettingsPasswordPost)
246-
if setting.EnableOpenIDSignIn {
246+
if setting.Service.EnableOpenIDSignIn {
247247
m.Group("/openid", func() {
248248
m.Combo("").Get(user.SettingsOpenID).
249249
Post(bindIgnErr(auth.AddOpenIDForm{}), user.SettingsOpenIDPost)

conf/app.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@ IMPORT_LOCAL_PATHS = false
203203
; Whether to allow signin in via OpenID
204204
ENABLE_OPENID_SIGNIN = true
205205
; Whether to allow registering via OpenID
206-
ENABLE_OPENID_SIGNUP = true
206+
; Do not include to rely on DISABLE_REGISTRATION setting
207+
;ENABLE_OPENID_SIGNUP = true
207208
; Allowed URI patterns (POSIX regexp).
208209
; Space separated.
209210
; Only these would be allowed if non-blank.

modules/context/context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ func Contexter() macaron.Handler {
197197
ctx.Data["ShowRegistrationButton"] = setting.Service.ShowRegistrationButton
198198
ctx.Data["ShowFooterBranding"] = setting.ShowFooterBranding
199199
ctx.Data["ShowFooterVersion"] = setting.ShowFooterVersion
200-
ctx.Data["EnableOpenIDSignIn"] = setting.EnableOpenIDSignIn
200+
ctx.Data["EnableOpenIDSignIn"] = setting.Service.EnableOpenIDSignIn
201201

202202
c.Map(ctx)
203203
}

modules/setting/setting.go

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,6 @@ var (
121121
MinPasswordLength int
122122
ImportLocalPaths bool
123123

124-
// OpenID settings
125-
EnableOpenIDSignIn bool
126-
EnableOpenIDSignUp bool
127-
OpenIDWhitelist []*regexp.Regexp
128-
OpenIDBlacklist []*regexp.Regexp
129-
130124
// Database settings
131125
UseSQLite3 bool
132126
UseMySQL bool
@@ -758,24 +752,6 @@ please consider changing to GITEA_CUSTOM`)
758752
MinPasswordLength = sec.Key("MIN_PASSWORD_LENGTH").MustInt(6)
759753
ImportLocalPaths = sec.Key("IMPORT_LOCAL_PATHS").MustBool(false)
760754

761-
sec = Cfg.Section("openid")
762-
EnableOpenIDSignIn = sec.Key("ENABLE_OPENID_SIGNIN").MustBool(true)
763-
EnableOpenIDSignUp = sec.Key("ENABLE_OPENID_SIGNUP").MustBool(true)
764-
pats := sec.Key("WHITELISTED_URIS").Strings(" ")
765-
if len(pats) != 0 {
766-
OpenIDWhitelist = make([]*regexp.Regexp, len(pats))
767-
for i, p := range pats {
768-
OpenIDWhitelist[i] = regexp.MustCompilePOSIX(p)
769-
}
770-
}
771-
pats = sec.Key("BLACKLISTED_URIS").Strings(" ")
772-
if len(pats) != 0 {
773-
OpenIDBlacklist = make([]*regexp.Regexp, len(pats))
774-
for i, p := range pats {
775-
OpenIDBlacklist[i] = regexp.MustCompilePOSIX(p)
776-
}
777-
}
778-
779755
sec = Cfg.Section("attachment")
780756
AttachmentPath = sec.Key("PATH").MustString(path.Join(AppDataPath, "attachments"))
781757
if !filepath.IsAbs(AttachmentPath) {
@@ -939,6 +915,13 @@ var Service struct {
939915
EnableCaptcha bool
940916
DefaultKeepEmailPrivate bool
941917
NoReplyAddress string
918+
919+
// OpenID settings
920+
EnableOpenIDSignIn bool
921+
EnableOpenIDSignUp bool
922+
OpenIDWhitelist []*regexp.Regexp
923+
OpenIDBlacklist []*regexp.Regexp
924+
942925
}
943926

944927
func newService() {
@@ -953,6 +936,25 @@ func newService() {
953936
Service.EnableCaptcha = sec.Key("ENABLE_CAPTCHA").MustBool()
954937
Service.DefaultKeepEmailPrivate = sec.Key("DEFAULT_KEEP_EMAIL_PRIVATE").MustBool()
955938
Service.NoReplyAddress = sec.Key("NO_REPLY_ADDRESS").MustString("noreply.example.org")
939+
940+
sec = Cfg.Section("openid")
941+
Service.EnableOpenIDSignIn = sec.Key("ENABLE_OPENID_SIGNIN").MustBool(true)
942+
Service.EnableOpenIDSignUp = sec.Key("ENABLE_OPENID_SIGNUP").MustBool(!Service.DisableRegistration)
943+
pats := sec.Key("WHITELISTED_URIS").Strings(" ")
944+
if len(pats) != 0 {
945+
Service.OpenIDWhitelist = make([]*regexp.Regexp, len(pats))
946+
for i, p := range pats {
947+
Service.OpenIDWhitelist[i] = regexp.MustCompilePOSIX(p)
948+
}
949+
}
950+
pats = sec.Key("BLACKLISTED_URIS").Strings(" ")
951+
if len(pats) != 0 {
952+
Service.OpenIDBlacklist = make([]*regexp.Regexp, len(pats))
953+
for i, p := range pats {
954+
Service.OpenIDBlacklist[i] = regexp.MustCompilePOSIX(p)
955+
}
956+
}
957+
956958
}
957959

958960
var logLevels = map[string]string{

options/locale/locale_en-US.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,8 @@ config.db_path_helper = (for "sqlite3" and "tidb")
12111211
config.service_config = Service Configuration
12121212
config.register_email_confirm = Require Email Confirmation
12131213
config.disable_register = Disable Registration
1214+
config.enable_openid_signup = Enable Registration via OpenID
1215+
config.enable_openid_signin = Enable OpenID Sign In
12141216
config.show_registration_button = Show Register Button
12151217
config.require_sign_in_view = Require Sign In View
12161218
config.mail_notify = Mail Notification

routers/user/auth_openid.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ func allowedOpenIDURI(uri string) (err error) {
6868

6969
// In case a Whitelist is present, URI must be in it
7070
// in order to be accepted
71-
if len(setting.OpenIDWhitelist) != 0 {
72-
for _, pat := range setting.OpenIDWhitelist {
71+
if len(setting.Service.OpenIDWhitelist) != 0 {
72+
for _, pat := range setting.Service.OpenIDWhitelist {
7373
if pat.MatchString(uri) {
7474
return nil // pass
7575
}
@@ -79,7 +79,7 @@ func allowedOpenIDURI(uri string) (err error) {
7979
}
8080

8181
// A blacklist match expliclty forbids
82-
for _, pat := range setting.OpenIDBlacklist {
82+
for _, pat := range setting.Service.OpenIDBlacklist {
8383
if pat.MatchString(uri) {
8484
return fmt.Errorf("URI forbidden by blacklist")
8585
}
@@ -231,7 +231,7 @@ func signInOpenIDVerify(ctx *context.Context) {
231231

232232
ctx.Session.Set("openid_determined_username", nickname)
233233

234-
if u != nil || !setting.EnableOpenIDSignUp {
234+
if u != nil || !setting.Service.EnableOpenIDSignUp {
235235
ctx.Redirect(setting.AppSubURL + "/user/openid/connect")
236236
} else {
237237
ctx.Redirect(setting.AppSubURL + "/user/openid/register")
@@ -248,7 +248,7 @@ func ConnectOpenID(ctx *context.Context) {
248248
ctx.Data["Title"] = "OpenID connect"
249249
ctx.Data["PageIsSignIn"] = true
250250
ctx.Data["PageIsOpenIDConnect"] = true
251-
ctx.Data["EnableOpenIDSignUp"] = setting.EnableOpenIDSignUp
251+
ctx.Data["EnableOpenIDSignUp"] = setting.Service.EnableOpenIDSignUp
252252
ctx.Data["OpenID"] = oid
253253
userName, _ := ctx.Session.Get("openid_determined_username").(string)
254254
if userName != "" {
@@ -267,7 +267,7 @@ func ConnectOpenIDPost(ctx *context.Context, form auth.ConnectOpenIDForm) {
267267
ctx.Data["Title"] = "OpenID connect"
268268
ctx.Data["PageIsSignIn"] = true
269269
ctx.Data["PageIsOpenIDConnect"] = true
270-
ctx.Data["EnableOpenIDSignUp"] = setting.EnableOpenIDSignUp
270+
ctx.Data["EnableOpenIDSignUp"] = setting.Service.EnableOpenIDSignUp
271271
ctx.Data["OpenID"] = oid
272272

273273
u, err := models.UserSignIn(form.UserName, form.Password)
@@ -300,7 +300,7 @@ func ConnectOpenIDPost(ctx *context.Context, form auth.ConnectOpenIDForm) {
300300

301301
// RegisterOpenID shows a form to create a new user authenticated via an OpenID URI
302302
func RegisterOpenID(ctx *context.Context) {
303-
if !setting.EnableOpenIDSignUp {
303+
if !setting.Service.EnableOpenIDSignUp {
304304
ctx.Error(403)
305305
return
306306
}
@@ -312,7 +312,7 @@ func RegisterOpenID(ctx *context.Context) {
312312
ctx.Data["Title"] = "OpenID signup"
313313
ctx.Data["PageIsSignIn"] = true
314314
ctx.Data["PageIsOpenIDRegister"] = true
315-
ctx.Data["EnableOpenIDSignUp"] = setting.EnableOpenIDSignUp
315+
ctx.Data["EnableOpenIDSignUp"] = setting.Service.EnableOpenIDSignUp
316316
ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha
317317
ctx.Data["OpenID"] = oid
318318
userName, _ := ctx.Session.Get("openid_determined_username").(string)
@@ -328,7 +328,7 @@ func RegisterOpenID(ctx *context.Context) {
328328

329329
// RegisterOpenIDPost handles submission of a form to create a new user authenticated via an OpenID URI
330330
func RegisterOpenIDPost(ctx *context.Context, cpt *captcha.Captcha, form auth.SignUpOpenIDForm) {
331-
if !setting.EnableOpenIDSignUp {
331+
if !setting.Service.EnableOpenIDSignUp {
332332
ctx.Error(403)
333333
return
334334
}
@@ -341,7 +341,7 @@ func RegisterOpenIDPost(ctx *context.Context, cpt *captcha.Captcha, form auth.Si
341341
ctx.Data["Title"] = "OpenID signup"
342342
ctx.Data["PageIsSignIn"] = true
343343
ctx.Data["PageIsOpenIDRegister"] = true
344-
ctx.Data["EnableOpenIDSignUp"] = setting.EnableOpenIDSignUp
344+
ctx.Data["EnableOpenIDSignUp"] = setting.Service.EnableOpenIDSignUp
345345
ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha
346346
ctx.Data["OpenID"] = oid
347347

templates/admin/config.tmpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@
114114
<dd><i class="fa fa{{if .Service.DisableRegistration}}-check{{end}}-square-o"></i></dd>
115115
<dt>{{.i18n.Tr "admin.config.show_registration_button"}}</dt>
116116
<dd><i class="fa fa{{if .Service.ShowRegistrationButton}}-check{{end}}-square-o"></i></dd>
117+
<dt>{{.i18n.Tr "admin.config.enable_openid_signup"}}</dt>
118+
<dd><i class="fa fa{{if .Service.EnableOpenIDSignUp}}-check{{end}}-square-o"></i></dd>
119+
<dt>{{.i18n.Tr "admin.config.enable_openid_signin"}}</dt>
120+
<dd><i class="fa fa{{if .Service.EnableOpenIDSignIn}}-check{{end}}-square-o"></i></dd>
117121
<dt>{{.i18n.Tr "admin.config.require_sign_in_view"}}</dt>
118122
<dd><i class="fa fa{{if .Service.RequireSignInView}}-check{{end}}-square-o"></i></dd>
119123
<dt>{{.i18n.Tr "admin.config.mail_notify"}}</dt>

0 commit comments

Comments
 (0)