recaptcha: implement varied recaptcha host
This commit is contained in:
parent
a184b775b3
commit
ba285eb33a
@ -71,7 +71,8 @@ type FileBrowser struct {
|
|||||||
// there will only exist one user, called "admin".
|
// there will only exist one user, called "admin".
|
||||||
NoAuth bool
|
NoAuth bool
|
||||||
|
|
||||||
// ReCaptcha Site key and secret.
|
// ReCaptcha host, key and secret.
|
||||||
|
ReCaptchaHost string
|
||||||
ReCaptchaKey string
|
ReCaptchaKey string
|
||||||
ReCaptchaSecret string
|
ReCaptchaSecret string
|
||||||
|
|
||||||
|
|||||||
@ -12,7 +12,7 @@ import (
|
|||||||
fm "github.com/filebrowser/filebrowser"
|
fm "github.com/filebrowser/filebrowser"
|
||||||
)
|
)
|
||||||
|
|
||||||
const reCaptchaAPI = "https://www.google.com/recaptcha/api/siteverify"
|
const reCaptchaAPI = "/recaptcha/api/siteverify"
|
||||||
|
|
||||||
type cred struct {
|
type cred struct {
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
@ -21,14 +21,14 @@ type cred struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// reCaptcha checks the reCaptcha code.
|
// reCaptcha checks the reCaptcha code.
|
||||||
func reCaptcha(secret string, response string) (bool, error) {
|
func reCaptcha(host, secret, response string) (bool, error) {
|
||||||
body := url.Values{}
|
body := url.Values{}
|
||||||
body.Set("secret", secret)
|
body.Set("secret", secret)
|
||||||
body.Add("response", response)
|
body.Add("response", response)
|
||||||
|
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
|
|
||||||
resp, err := client.Post(reCaptchaAPI, "application/x-www-form-urlencoded", strings.NewReader(body.Encode()))
|
resp, err := client.Post(host+reCaptchaAPI, "application/x-www-form-urlencoded", strings.NewReader(body.Encode()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func authHandler(c *fm.Context, w http.ResponseWriter, r *http.Request) (int, er
|
|||||||
|
|
||||||
// If ReCaptcha is enabled, check the code.
|
// If ReCaptcha is enabled, check the code.
|
||||||
if len(c.ReCaptchaSecret) > 0 {
|
if len(c.ReCaptchaSecret) > 0 {
|
||||||
ok, err := reCaptcha(c.ReCaptchaSecret, cred.ReCaptcha)
|
ok, err := reCaptcha(c.ReCaptchaHost, c.ReCaptchaSecret, cred.ReCaptcha)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return http.StatusForbidden, err
|
return http.StatusForbidden, err
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user