Skip to content

Commit 2c3a229

Browse files
strkbkcsoft
authored andcommitted
Add OpenID configuration in install page (#2276)
1 parent e7653a6 commit 2c3a229

File tree

7 files changed

+67
-26
lines changed

7 files changed

+67
-26
lines changed

modules/auth/user_form.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ type InstallForm struct {
4141
OfflineMode bool
4242
DisableGravatar bool
4343
EnableFederatedAvatar bool
44+
EnableOpenIDSignIn bool
45+
EnableOpenIDSignUp bool
4446
DisableRegistration bool
4547
EnableCaptcha bool
4648
RequireSignInView bool

options/locale/locale_en-US.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ federated_avatar_lookup = Enable Federated Avatars Lookup
116116
federated_avatar_lookup_popup = Enable federated avatar lookup using Libravatar.
117117
disable_registration = Disable Self-registration
118118
disable_registration_popup = Disable user self-registration, only admin can create accounts.
119+
openid_signin = Enable OpenID Sign-In
120+
openid_signin_popup = Enable user login via OpenID
121+
openid_signup = Enable OpenID Self-registration
122+
openid_signup_popup = Enable OpenID based Self-registration
119123
enable_captcha = Enable Captcha
120124
enable_captcha_popup = Require a CAPTCHA for user self-registration.
121125
require_sign_in_view = Enable Require Sign In to View Pages

public/js/index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,22 @@ function initInstall() {
311311
$('#offline-mode').checkbox('uncheck');
312312
}
313313
});
314+
$('#enable-openid-signin input').change(function () {
315+
if ($(this).is(':checked')) {
316+
if ( $('#disable-registration input').is(':checked') ) {
317+
} else {
318+
$('#enable-openid-signup').checkbox('check');
319+
}
320+
} else {
321+
$('#enable-openid-signup').checkbox('uncheck');
322+
}
323+
});
314324
$('#disable-registration input').change(function () {
315325
if ($(this).is(':checked')) {
316326
$('#enable-captcha').checkbox('uncheck');
327+
$('#enable-openid-signup').checkbox('uncheck');
328+
} else {
329+
$('#enable-openid-signup').checkbox('check');
317330
}
318331
});
319332
$('#enable-captcha input').change(function () {

routers/install.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ func Install(ctx *context.Context) {
108108
form.OfflineMode = setting.OfflineMode
109109
form.DisableGravatar = setting.DisableGravatar
110110
form.EnableFederatedAvatar = setting.EnableFederatedAvatar
111+
form.EnableOpenIDSignIn = true
112+
form.EnableOpenIDSignUp = true
111113
form.DisableRegistration = setting.Service.DisableRegistration
112114
form.EnableCaptcha = setting.Service.EnableCaptcha
113115
form.RequireSignInView = setting.Service.RequireSignInView
@@ -292,6 +294,8 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) {
292294
cfg.Section("server").Key("OFFLINE_MODE").SetValue(com.ToStr(form.OfflineMode))
293295
cfg.Section("picture").Key("DISABLE_GRAVATAR").SetValue(com.ToStr(form.DisableGravatar))
294296
cfg.Section("picture").Key("ENABLE_FEDERATED_AVATAR").SetValue(com.ToStr(form.EnableFederatedAvatar))
297+
cfg.Section("openid").Key("ENABLE_OPENID_SIGNIN").SetValue(com.ToStr(form.EnableOpenIDSignIn))
298+
cfg.Section("openid").Key("ENABLE_OPENID_SIGNUP").SetValue(com.ToStr(form.EnableOpenIDSignUp))
295299
cfg.Section("service").Key("DISABLE_REGISTRATION").SetValue(com.ToStr(form.DisableRegistration))
296300
cfg.Section("service").Key("ENABLE_CAPTCHA").SetValue(com.ToStr(form.EnableCaptcha))
297301
cfg.Section("service").Key("REQUIRE_SIGNIN_VIEW").SetValue(com.ToStr(form.RequireSignInView))

routers/routes/routes.go

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,20 @@ func RegisterRoutes(m *macaron.Macaron) {
136136
bindIgnErr := binding.BindIgnErr
137137
validation.AddBindingRules()
138138

139+
openIDSignInEnabled := func(ctx *context.Context) {
140+
if !setting.Service.EnableOpenIDSignIn {
141+
ctx.Error(403)
142+
return
143+
}
144+
}
145+
146+
openIDSignUpEnabled := func(ctx *context.Context) {
147+
if !setting.Service.EnableOpenIDSignUp {
148+
ctx.Error(403)
149+
return
150+
}
151+
}
152+
139153
m.Use(user.GetNotificationCount)
140154

141155
// FIXME: not all routes need go through same middlewares.
@@ -163,19 +177,21 @@ func RegisterRoutes(m *macaron.Macaron) {
163177
m.Group("/user", func() {
164178
m.Get("/login", user.SignIn)
165179
m.Post("/login", bindIgnErr(auth.SignInForm{}), user.SignInPost)
166-
if setting.Service.EnableOpenIDSignIn {
180+
m.Group("", func() {
167181
m.Combo("/login/openid").
168182
Get(user.SignInOpenID).
169183
Post(bindIgnErr(auth.SignInOpenIDForm{}), user.SignInOpenIDPost)
170-
m.Group("/openid", func() {
171-
m.Combo("/connect").
172-
Get(user.ConnectOpenID).
173-
Post(bindIgnErr(auth.ConnectOpenIDForm{}), user.ConnectOpenIDPost)
174-
m.Combo("/register").
175-
Get(user.RegisterOpenID).
184+
}, openIDSignInEnabled)
185+
m.Group("/openid", func() {
186+
m.Combo("/connect").
187+
Get(user.ConnectOpenID).
188+
Post(bindIgnErr(auth.ConnectOpenIDForm{}), user.ConnectOpenIDPost)
189+
m.Group("/register", func() {
190+
m.Combo("").
191+
Get(user.RegisterOpenID, openIDSignUpEnabled).
176192
Post(bindIgnErr(auth.SignUpOpenIDForm{}), user.RegisterOpenIDPost)
177-
})
178-
}
193+
}, openIDSignUpEnabled)
194+
}, openIDSignInEnabled)
179195
m.Get("/sign_up", user.SignUp)
180196
m.Post("/sign_up", bindIgnErr(auth.RegisterForm{}), user.SignUpPost)
181197
m.Get("/reset_password", user.ResetPasswd)
@@ -206,15 +222,12 @@ func RegisterRoutes(m *macaron.Macaron) {
206222
m.Post("/email/delete", user.DeleteEmail)
207223
m.Get("/password", user.SettingsPassword)
208224
m.Post("/password", bindIgnErr(auth.ChangePasswordForm{}), user.SettingsPasswordPost)
209-
if setting.Service.EnableOpenIDSignIn {
210-
m.Group("/openid", func() {
211-
m.Combo("").Get(user.SettingsOpenID).
212-
Post(bindIgnErr(auth.AddOpenIDForm{}), user.SettingsOpenIDPost)
213-
m.Post("/delete", user.DeleteOpenID)
214-
m.Post("/toggle_visibility", user.ToggleOpenIDVisibility)
215-
})
216-
}
217-
225+
m.Group("/openid", func() {
226+
m.Combo("").Get(user.SettingsOpenID).
227+
Post(bindIgnErr(auth.AddOpenIDForm{}), user.SettingsOpenIDPost)
228+
m.Post("/delete", user.DeleteOpenID)
229+
m.Post("/toggle_visibility", user.ToggleOpenIDVisibility)
230+
}, openIDSignInEnabled)
218231
m.Combo("/keys").Get(user.SettingsKeys).
219232
Post(bindIgnErr(auth.AddKeyForm{}), user.SettingsKeysPost)
220233
m.Post("/keys/delete", user.DeleteKey)

routers/user/auth_openid.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ func ConnectOpenID(ctx *context.Context) {
259259

260260
// ConnectOpenIDPost handles submission of a form to connect an OpenID URI to an existing account
261261
func ConnectOpenIDPost(ctx *context.Context, form auth.ConnectOpenIDForm) {
262+
262263
oid, _ := ctx.Session.Get("openid_verified_uri").(string)
263264
if oid == "" {
264265
ctx.Redirect(setting.AppSubURL + "/user/login/openid")
@@ -300,10 +301,6 @@ func ConnectOpenIDPost(ctx *context.Context, form auth.ConnectOpenIDForm) {
300301

301302
// RegisterOpenID shows a form to create a new user authenticated via an OpenID URI
302303
func RegisterOpenID(ctx *context.Context) {
303-
if !setting.Service.EnableOpenIDSignUp {
304-
ctx.Error(403)
305-
return
306-
}
307304
oid, _ := ctx.Session.Get("openid_verified_uri").(string)
308305
if oid == "" {
309306
ctx.Redirect(setting.AppSubURL + "/user/login/openid")
@@ -328,10 +325,6 @@ func RegisterOpenID(ctx *context.Context) {
328325

329326
// RegisterOpenIDPost handles submission of a form to create a new user authenticated via an OpenID URI
330327
func RegisterOpenIDPost(ctx *context.Context, cpt *captcha.Captcha, form auth.SignUpOpenIDForm) {
331-
if !setting.Service.EnableOpenIDSignUp {
332-
ctx.Error(403)
333-
return
334-
}
335328
oid, _ := ctx.Session.Get("openid_verified_uri").(string)
336329
if oid == "" {
337330
ctx.Redirect(setting.AppSubURL + "/user/login/openid")

templates/install.tmpl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,24 @@
188188
<input name="enable_federated_avatar" type="checkbox" {{if .enable_federated_avatar}}checked{{end}}>
189189
</div>
190190
</div>
191+
<div class="inline field">
192+
<div class="ui checkbox" id="enable-openid-signin">
193+
<label class="poping up" data-content="{{.i18n.Tr "install.openid_signin_popup"}}"><strong>{{.i18n.Tr "install.openid_signin"}}</strong></label>
194+
<input name="enable_open_id_sign_in" type="checkbox" {{if .enable_open_id_sign_in}}checked{{end}}>
195+
</div>
196+
</div>
191197
<div class="inline field">
192198
<div class="ui checkbox" id="disable-registration">
193199
<label class="poping up" data-content="{{.i18n.Tr "install.disable_registration_popup"}}"><strong>{{.i18n.Tr "install.disable_registration"}}</strong></label>
194200
<input name="disable_registration" type="checkbox" {{if .disable_registration}}checked{{end}}>
195201
</div>
196202
</div>
203+
<div class="inline field">
204+
<div class="ui checkbox" id="enable-openid-signup">
205+
<label class="poping up" data-content="{{.i18n.Tr "install.openid_signup_popup"}}"><strong>{{.i18n.Tr "install.openid_signup"}}</strong></label>
206+
<input name="enable_open_id_sign_up" type="checkbox" {{if .enable_open_id_sign_up}}checked{{end}}>
207+
</div>
208+
</div>
197209
<div class="inline field">
198210
<div class="ui checkbox" id="enable-captcha">
199211
<label class="poping up" data-content="{{.i18n.Tr "install.enable_captcha_popup"}}"><strong>{{.i18n.Tr "install.enable_captcha"}}</strong></label>

0 commit comments

Comments
 (0)