mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-22 12:54:53 -05:00
Allow Recaptcha service url to be configured (#6820)
This commit is contained in:
parent
159294f799
commit
ade88a877d
8 changed files with 20 additions and 5 deletions
|
@ -362,6 +362,8 @@ CAPTCHA_TYPE = image
|
||||||
; Go to https://www.google.com/recaptcha/admin to sign up for a key
|
; Go to https://www.google.com/recaptcha/admin to sign up for a key
|
||||||
RECAPTCHA_SECRET =
|
RECAPTCHA_SECRET =
|
||||||
RECAPTCHA_SITEKEY =
|
RECAPTCHA_SITEKEY =
|
||||||
|
; Change this to use recaptcha.net or other recaptcha service
|
||||||
|
RECAPTCHA_URL = https://www.google.com/recaptcha/
|
||||||
; Default value for KeepEmailPrivate
|
; Default value for KeepEmailPrivate
|
||||||
; Each new user will get the value of this setting copied into their profile
|
; Each new user will get the value of this setting copied into their profile
|
||||||
DEFAULT_KEEP_EMAIL_PRIVATE = false
|
DEFAULT_KEEP_EMAIL_PRIVATE = false
|
||||||
|
|
|
@ -214,6 +214,7 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
|
||||||
- `CAPTCHA_TYPE`: **image**: \[image, recaptcha\]
|
- `CAPTCHA_TYPE`: **image**: \[image, recaptcha\]
|
||||||
- `RECAPTCHA_SECRET`: **""**: Go to https://www.google.com/recaptcha/admin to get a secret for recaptcha.
|
- `RECAPTCHA_SECRET`: **""**: Go to https://www.google.com/recaptcha/admin to get a secret for recaptcha.
|
||||||
- `RECAPTCHA_SITEKEY`: **""**: Go to https://www.google.com/recaptcha/admin to get a sitekey for recaptcha.
|
- `RECAPTCHA_SITEKEY`: **""**: Go to https://www.google.com/recaptcha/admin to get a sitekey for recaptcha.
|
||||||
|
- `RECAPTCHA_URL`: **https://www.google.com/recaptcha/**: Set the recaptcha url - allows the use of recaptcha net.
|
||||||
- `DEFAULT_ENABLE_DEPENDENCIES`: **true**: Enable this to have dependencies enabled by default.
|
- `DEFAULT_ENABLE_DEPENDENCIES`: **true**: Enable this to have dependencies enabled by default.
|
||||||
- `ENABLE_USER_HEATMAP`: **true**: Enable this to display the heatmap on users profiles.
|
- `ENABLE_USER_HEATMAP`: **true**: Enable this to display the heatmap on users profiles.
|
||||||
- `EMAIL_DOMAIN_WHITELIST`: **\<empty\>**: If non-empty, list of domain names that can only be used to register
|
- `EMAIL_DOMAIN_WHITELIST`: **\<empty\>**: If non-empty, list of domain names that can only be used to register
|
||||||
|
|
|
@ -13,6 +13,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
"code.gitea.io/gitea/modules/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Response is the structure of JSON returned from API
|
// Response is the structure of JSON returned from API
|
||||||
|
@ -23,11 +24,11 @@ type Response struct {
|
||||||
ErrorCodes []string `json:"error-codes"`
|
ErrorCodes []string `json:"error-codes"`
|
||||||
}
|
}
|
||||||
|
|
||||||
const apiURL = "https://www.google.com/recaptcha/api/siteverify"
|
const apiURL = "/api/siteverify"
|
||||||
|
|
||||||
// Verify calls Google Recaptcha API to verify token
|
// Verify calls Google Recaptcha API to verify token
|
||||||
func Verify(response string) (bool, error) {
|
func Verify(response string) (bool, error) {
|
||||||
resp, err := http.PostForm(apiURL,
|
resp, err := http.PostForm(util.URLJoin(setting.Service.RecaptchaURL, apiURL),
|
||||||
url.Values{"secret": {setting.Service.RecaptchaSecret}, "response": {response}})
|
url.Values{"secret": {setting.Service.RecaptchaSecret}, "response": {response}})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, fmt.Errorf("Failed to send CAPTCHA response: %s", err)
|
return false, fmt.Errorf("Failed to send CAPTCHA response: %s", err)
|
||||||
|
|
|
@ -30,6 +30,7 @@ var Service struct {
|
||||||
CaptchaType string
|
CaptchaType string
|
||||||
RecaptchaSecret string
|
RecaptchaSecret string
|
||||||
RecaptchaSitekey string
|
RecaptchaSitekey string
|
||||||
|
RecaptchaURL string
|
||||||
DefaultKeepEmailPrivate bool
|
DefaultKeepEmailPrivate bool
|
||||||
DefaultAllowCreateOrganization bool
|
DefaultAllowCreateOrganization bool
|
||||||
EnableTimetracking bool
|
EnableTimetracking bool
|
||||||
|
@ -63,6 +64,7 @@ func newService() {
|
||||||
Service.CaptchaType = sec.Key("CAPTCHA_TYPE").MustString(ImageCaptcha)
|
Service.CaptchaType = sec.Key("CAPTCHA_TYPE").MustString(ImageCaptcha)
|
||||||
Service.RecaptchaSecret = sec.Key("RECAPTCHA_SECRET").MustString("")
|
Service.RecaptchaSecret = sec.Key("RECAPTCHA_SECRET").MustString("")
|
||||||
Service.RecaptchaSitekey = sec.Key("RECAPTCHA_SITEKEY").MustString("")
|
Service.RecaptchaSitekey = sec.Key("RECAPTCHA_SITEKEY").MustString("")
|
||||||
|
Service.RecaptchaURL = sec.Key("RECAPTCHA_URL").MustString("https://www.google.com/recaptcha/")
|
||||||
Service.DefaultKeepEmailPrivate = sec.Key("DEFAULT_KEEP_EMAIL_PRIVATE").MustBool()
|
Service.DefaultKeepEmailPrivate = sec.Key("DEFAULT_KEEP_EMAIL_PRIVATE").MustBool()
|
||||||
Service.DefaultAllowCreateOrganization = sec.Key("DEFAULT_ALLOW_CREATE_ORGANIZATION").MustBool(true)
|
Service.DefaultAllowCreateOrganization = sec.Key("DEFAULT_ALLOW_CREATE_ORGANIZATION").MustBool(true)
|
||||||
Service.EnableTimetracking = sec.Key("ENABLE_TIMETRACKING").MustBool(true)
|
Service.EnableTimetracking = sec.Key("ENABLE_TIMETRACKING").MustBool(true)
|
||||||
|
|
|
@ -20,6 +20,8 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"code.gitea.io/gitea/modules/util"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
"code.gitea.io/gitea/modules/base"
|
"code.gitea.io/gitea/modules/base"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
|
@ -115,6 +117,8 @@ func NewFuncMap() []template.FuncMap {
|
||||||
"EscapePound": func(str string) string {
|
"EscapePound": func(str string) string {
|
||||||
return strings.NewReplacer("%", "%25", "#", "%23", " ", "%20", "?", "%3F").Replace(str)
|
return strings.NewReplacer("%", "%25", "#", "%23", " ", "%20", "?", "%3F").Replace(str)
|
||||||
},
|
},
|
||||||
|
"PathEscapeSegments": util.PathEscapeSegments,
|
||||||
|
"URLJoin": util.URLJoin,
|
||||||
"RenderCommitMessage": RenderCommitMessage,
|
"RenderCommitMessage": RenderCommitMessage,
|
||||||
"RenderCommitMessageLink": RenderCommitMessageLink,
|
"RenderCommitMessageLink": RenderCommitMessageLink,
|
||||||
"RenderCommitBody": RenderCommitBody,
|
"RenderCommitBody": RenderCommitBody,
|
||||||
|
|
|
@ -662,6 +662,7 @@ func LinkAccount(ctx *context.Context) {
|
||||||
ctx.Data["LinkAccountMode"] = true
|
ctx.Data["LinkAccountMode"] = true
|
||||||
ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha
|
ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha
|
||||||
ctx.Data["CaptchaType"] = setting.Service.CaptchaType
|
ctx.Data["CaptchaType"] = setting.Service.CaptchaType
|
||||||
|
ctx.Data["RecaptchaURL"] = setting.Service.RecaptchaURL
|
||||||
ctx.Data["RecaptchaSitekey"] = setting.Service.RecaptchaSitekey
|
ctx.Data["RecaptchaSitekey"] = setting.Service.RecaptchaSitekey
|
||||||
ctx.Data["DisableRegistration"] = setting.Service.DisableRegistration
|
ctx.Data["DisableRegistration"] = setting.Service.DisableRegistration
|
||||||
ctx.Data["ShowRegistrationButton"] = false
|
ctx.Data["ShowRegistrationButton"] = false
|
||||||
|
@ -710,6 +711,7 @@ func LinkAccountPostSignIn(ctx *context.Context, signInForm auth.SignInForm) {
|
||||||
ctx.Data["LinkAccountMode"] = true
|
ctx.Data["LinkAccountMode"] = true
|
||||||
ctx.Data["LinkAccountModeSignIn"] = true
|
ctx.Data["LinkAccountModeSignIn"] = true
|
||||||
ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha
|
ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha
|
||||||
|
ctx.Data["RecaptchaURL"] = setting.Service.RecaptchaURL
|
||||||
ctx.Data["CaptchaType"] = setting.Service.CaptchaType
|
ctx.Data["CaptchaType"] = setting.Service.CaptchaType
|
||||||
ctx.Data["RecaptchaSitekey"] = setting.Service.RecaptchaSitekey
|
ctx.Data["RecaptchaSitekey"] = setting.Service.RecaptchaSitekey
|
||||||
ctx.Data["DisableRegistration"] = setting.Service.DisableRegistration
|
ctx.Data["DisableRegistration"] = setting.Service.DisableRegistration
|
||||||
|
@ -778,6 +780,7 @@ func LinkAccountPostRegister(ctx *context.Context, cpt *captcha.Captcha, form au
|
||||||
ctx.Data["LinkAccountMode"] = true
|
ctx.Data["LinkAccountMode"] = true
|
||||||
ctx.Data["LinkAccountModeRegister"] = true
|
ctx.Data["LinkAccountModeRegister"] = true
|
||||||
ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha
|
ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha
|
||||||
|
ctx.Data["RecaptchaURL"] = setting.Service.RecaptchaURL
|
||||||
ctx.Data["CaptchaType"] = setting.Service.CaptchaType
|
ctx.Data["CaptchaType"] = setting.Service.CaptchaType
|
||||||
ctx.Data["RecaptchaSitekey"] = setting.Service.RecaptchaSitekey
|
ctx.Data["RecaptchaSitekey"] = setting.Service.RecaptchaSitekey
|
||||||
ctx.Data["DisableRegistration"] = setting.Service.DisableRegistration
|
ctx.Data["DisableRegistration"] = setting.Service.DisableRegistration
|
||||||
|
@ -918,7 +921,7 @@ func SignUp(ctx *context.Context) {
|
||||||
ctx.Data["SignUpLink"] = setting.AppSubURL + "/user/sign_up"
|
ctx.Data["SignUpLink"] = setting.AppSubURL + "/user/sign_up"
|
||||||
|
|
||||||
ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha
|
ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha
|
||||||
|
ctx.Data["RecaptchaURL"] = setting.Service.RecaptchaURL
|
||||||
ctx.Data["CaptchaType"] = setting.Service.CaptchaType
|
ctx.Data["CaptchaType"] = setting.Service.CaptchaType
|
||||||
ctx.Data["RecaptchaSitekey"] = setting.Service.RecaptchaSitekey
|
ctx.Data["RecaptchaSitekey"] = setting.Service.RecaptchaSitekey
|
||||||
|
|
||||||
|
@ -934,7 +937,7 @@ func SignUpPost(ctx *context.Context, cpt *captcha.Captcha, form auth.RegisterFo
|
||||||
ctx.Data["SignUpLink"] = setting.AppSubURL + "/user/sign_up"
|
ctx.Data["SignUpLink"] = setting.AppSubURL + "/user/sign_up"
|
||||||
|
|
||||||
ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha
|
ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha
|
||||||
|
ctx.Data["RecaptchaURL"] = setting.Service.RecaptchaURL
|
||||||
ctx.Data["CaptchaType"] = setting.Service.CaptchaType
|
ctx.Data["CaptchaType"] = setting.Service.CaptchaType
|
||||||
ctx.Data["RecaptchaSitekey"] = setting.Service.RecaptchaSitekey
|
ctx.Data["RecaptchaSitekey"] = setting.Service.RecaptchaSitekey
|
||||||
|
|
||||||
|
|
|
@ -312,6 +312,7 @@ func RegisterOpenID(ctx *context.Context) {
|
||||||
ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha
|
ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha
|
||||||
ctx.Data["CaptchaType"] = setting.Service.CaptchaType
|
ctx.Data["CaptchaType"] = setting.Service.CaptchaType
|
||||||
ctx.Data["RecaptchaSitekey"] = setting.Service.RecaptchaSitekey
|
ctx.Data["RecaptchaSitekey"] = setting.Service.RecaptchaSitekey
|
||||||
|
ctx.Data["RecaptchaURL"] = setting.Service.RecaptchaURL
|
||||||
ctx.Data["OpenID"] = oid
|
ctx.Data["OpenID"] = oid
|
||||||
userName, _ := ctx.Session.Get("openid_determined_username").(string)
|
userName, _ := ctx.Session.Get("openid_determined_username").(string)
|
||||||
if userName != "" {
|
if userName != "" {
|
||||||
|
@ -337,6 +338,7 @@ func RegisterOpenIDPost(ctx *context.Context, cpt *captcha.Captcha, form auth.Si
|
||||||
ctx.Data["PageIsOpenIDRegister"] = true
|
ctx.Data["PageIsOpenIDRegister"] = true
|
||||||
ctx.Data["EnableOpenIDSignUp"] = setting.Service.EnableOpenIDSignUp
|
ctx.Data["EnableOpenIDSignUp"] = setting.Service.EnableOpenIDSignUp
|
||||||
ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha
|
ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha
|
||||||
|
ctx.Data["RecaptchaURL"] = setting.Service.RecaptchaURL
|
||||||
ctx.Data["CaptchaType"] = setting.Service.CaptchaType
|
ctx.Data["CaptchaType"] = setting.Service.CaptchaType
|
||||||
ctx.Data["RecaptchaSitekey"] = setting.Service.RecaptchaSitekey
|
ctx.Data["RecaptchaSitekey"] = setting.Service.RecaptchaSitekey
|
||||||
ctx.Data["OpenID"] = oid
|
ctx.Data["OpenID"] = oid
|
||||||
|
|
|
@ -46,7 +46,7 @@
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if .EnableCaptcha}}
|
{{if .EnableCaptcha}}
|
||||||
{{if eq .CaptchaType "recaptcha"}}
|
{{if eq .CaptchaType "recaptcha"}}
|
||||||
<script src="https://www.google.com/recaptcha/api.js" async></script>
|
<script src='{{ URLJoin .RecaptchaURL "api.js"}}' async></script>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if .RequireTribute}}
|
{{if .RequireTribute}}
|
||||||
|
|
Loading…
Reference in a new issue