diff options
author | zeripath <art27@cantab.net> | 2019-05-02 14:09:39 +0100 |
---|---|---|
committer | Lauris BH <lauris@nix.lv> | 2019-05-02 16:09:39 +0300 |
commit | ade88a877d7f3c1fba466359198b8aa8ce5f28f8 (patch) | |
tree | 05ba56fbd3ac14068ccd1cc7deb713caec725db0 /modules | |
parent | 159294f79991ad50747cb5f14c82aadfdc77f2c8 (diff) | |
download | gitea-ade88a877d7f3c1fba466359198b8aa8ce5f28f8.tar.gz gitea-ade88a877d7f3c1fba466359198b8aa8ce5f28f8.zip |
Allow Recaptcha service url to be configured (#6820)
Diffstat (limited to 'modules')
-rw-r--r-- | modules/recaptcha/recaptcha.go | 5 | ||||
-rw-r--r-- | modules/setting/service.go | 2 | ||||
-rw-r--r-- | modules/templates/helper.go | 4 |
3 files changed, 9 insertions, 2 deletions
diff --git a/modules/recaptcha/recaptcha.go b/modules/recaptcha/recaptcha.go index 1009185961..2d7bb6a5a6 100644 --- a/modules/recaptcha/recaptcha.go +++ b/modules/recaptcha/recaptcha.go @@ -13,6 +13,7 @@ import ( "time" "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/modules/util" ) // Response is the structure of JSON returned from API @@ -23,11 +24,11 @@ type Response struct { 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 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}}) if err != nil { return false, fmt.Errorf("Failed to send CAPTCHA response: %s", err) diff --git a/modules/setting/service.go b/modules/setting/service.go index 08bfb6c414..7e4fb8d7d9 100644 --- a/modules/setting/service.go +++ b/modules/setting/service.go @@ -30,6 +30,7 @@ var Service struct { CaptchaType string RecaptchaSecret string RecaptchaSitekey string + RecaptchaURL string DefaultKeepEmailPrivate bool DefaultAllowCreateOrganization bool EnableTimetracking bool @@ -63,6 +64,7 @@ func newService() { Service.CaptchaType = sec.Key("CAPTCHA_TYPE").MustString(ImageCaptcha) Service.RecaptchaSecret = sec.Key("RECAPTCHA_SECRET").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.DefaultAllowCreateOrganization = sec.Key("DEFAULT_ALLOW_CREATE_ORGANIZATION").MustBool(true) Service.EnableTimetracking = sec.Key("ENABLE_TIMETRACKING").MustBool(true) diff --git a/modules/templates/helper.go b/modules/templates/helper.go index b6c5cc5945..94e0748872 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -20,6 +20,8 @@ import ( "strings" "time" + "code.gitea.io/gitea/modules/util" + "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/log" @@ -115,6 +117,8 @@ func NewFuncMap() []template.FuncMap { "EscapePound": func(str string) string { return strings.NewReplacer("%", "%25", "#", "%23", " ", "%20", "?", "%3F").Replace(str) }, + "PathEscapeSegments": util.PathEscapeSegments, + "URLJoin": util.URLJoin, "RenderCommitMessage": RenderCommitMessage, "RenderCommitMessageLink": RenderCommitMessageLink, "RenderCommitBody": RenderCommitBody, |