Add download captcha UI

This commit is contained in:
Wim Brand
2019-03-28 10:47:27 +01:00
parent 16d3bb118f
commit 52345de733
6 changed files with 67 additions and 27 deletions

View File

@@ -54,7 +54,7 @@ func (wc *WebController) serveFileViewer(w http.ResponseWriter, r *http.Request,
templateData.Title = fmt.Sprintf("%d files in Pixeldrain", len(finfo))
templateData.Other = viewerData{
Type: "list",
CaptchaKey: wc.captchaSiteKey,
CaptchaKey: wc.captchaKey(),
APIResponse: map[string]interface{}{
"data": finfo,
"date_created": "now",
@@ -67,7 +67,7 @@ func (wc *WebController) serveFileViewer(w http.ResponseWriter, r *http.Request,
templateData.Title = fmt.Sprintf("%s ~ Pixeldrain file", finfo[0].Name)
templateData.Other = viewerData{
Type: "file",
CaptchaKey: wc.captchaSiteKey,
CaptchaKey: wc.captchaKey(),
APIResponse: finfo[0],
}
}

View File

@@ -14,24 +14,7 @@ func (wc *WebController) serveRegister(
p httprouter.Params,
) {
var tpld = wc.newTemplateData(w, r)
// This only runs on the first request
if wc.captchaSiteKey == "" {
var api = pixelapi.New(wc.conf.APIURLInternal, "")
capt, err := api.GetRecaptcha()
if err != nil {
log.Error("Error getting recaptcha key: %s", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
if capt.SiteKey == "" {
wc.captchaSiteKey = "none"
} else {
wc.captchaSiteKey = capt.SiteKey
}
}
tpld.Other = wc.captchaSiteKey
tpld.Other = wc.captchaKey()
err := wc.templates.Get().ExecuteTemplate(w, "register", tpld)
if err != nil {

View File

@@ -7,6 +7,7 @@ import (
"github.com/google/uuid"
"fornaxian.com/pixeldrain-web/init/conf"
"fornaxian.com/pixeldrain-web/pixelapi"
"github.com/Fornaxian/log"
"github.com/julienschmidt/httprouter"
)
@@ -118,3 +119,22 @@ func (wc *WebController) getAPIKey(r *http.Request) (key string, err error) {
}
return "", errors.New("not a valid pixeldrain authentication cookie")
}
func (wc *WebController) captchaKey() string {
// This only runs on the first request
if wc.captchaSiteKey == "" {
var api = pixelapi.New(wc.conf.APIURLInternal, "")
capt, err := api.GetRecaptcha()
if err != nil {
log.Error("Error getting recaptcha key: %s", err)
return ""
}
if capt.SiteKey == "" {
wc.captchaSiteKey = "none"
} else {
wc.captchaSiteKey = capt.SiteKey
}
}
return wc.captchaSiteKey
}