| @@ -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}} | ||||