@@ -6,6 +6,7 @@ package user
66
77import (
88 "fmt"
9+ "net/http"
910 "net/url"
1011
1112 "code.gitea.io/gitea/models"
@@ -250,7 +251,7 @@ func signInOpenIDVerify(ctx *context.Context) {
250251 log .Error ("signInOpenIDVerify: Unable to save changes to the session: %v" , err )
251252 }
252253
253- if u != nil || ! setting .Service .EnableOpenIDSignUp {
254+ if u != nil || ! setting .Service .EnableOpenIDSignUp || setting . Service . AllowOnlyInternalRegistration {
254255 ctx .Redirect (setting .AppSubURL + "/user/openid/connect" )
255256 } else {
256257 ctx .Redirect (setting .AppSubURL + "/user/openid/register" )
@@ -268,6 +269,7 @@ func ConnectOpenID(ctx *context.Context) {
268269 ctx .Data ["PageIsSignIn" ] = true
269270 ctx .Data ["PageIsOpenIDConnect" ] = true
270271 ctx .Data ["EnableOpenIDSignUp" ] = setting .Service .EnableOpenIDSignUp
272+ ctx .Data ["AllowOnlyInternalRegistration" ] = setting .Service .AllowOnlyInternalRegistration
271273 ctx .Data ["OpenID" ] = oid
272274 userName , _ := ctx .Session .Get ("openid_determined_username" ).(string )
273275 if userName != "" {
@@ -329,6 +331,7 @@ func RegisterOpenID(ctx *context.Context) {
329331 ctx .Data ["PageIsSignIn" ] = true
330332 ctx .Data ["PageIsOpenIDRegister" ] = true
331333 ctx .Data ["EnableOpenIDSignUp" ] = setting .Service .EnableOpenIDSignUp
334+ ctx .Data ["AllowOnlyInternalRegistration" ] = setting .Service .AllowOnlyInternalRegistration
332335 ctx .Data ["EnableCaptcha" ] = setting .Service .EnableCaptcha
333336 ctx .Data ["Captcha" ] = context .GetImageCaptcha ()
334337 ctx .Data ["CaptchaType" ] = setting .Service .CaptchaType
@@ -368,6 +371,11 @@ func RegisterOpenIDPost(ctx *context.Context) {
368371 ctx .Data ["HcaptchaSitekey" ] = setting .Service .HcaptchaSitekey
369372 ctx .Data ["OpenID" ] = oid
370373
374+ if setting .Service .AllowOnlyInternalRegistration {
375+ ctx .Error (http .StatusForbidden )
376+ return
377+ }
378+
371379 if setting .Service .EnableCaptcha {
372380 var valid bool
373381 var err error
0 commit comments