Captcha and design works.

Added captcha generation. As we're working without JS - there is no
possibility to reload image, only if user will reload whole web page.

Some design works - set monospace font for paste textarea (will
use system-defined default monospace font) and lowered font size
in paste views.
This commit is contained in:
2018-05-01 17:45:36 +05:00
parent 6150e3c1fd
commit 850fbb55ab
25 changed files with 11611 additions and 14 deletions

View File

@@ -36,6 +36,7 @@ import (
// local
"github.com/pztrn/fastpastebin/api/http/static"
"github.com/pztrn/fastpastebin/captcha"
"github.com/pztrn/fastpastebin/pagination"
// other
@@ -44,6 +45,7 @@ import (
htmlfmt "github.com/alecthomas/chroma/formatters/html"
"github.com/alecthomas/chroma/lexers"
"github.com/alecthomas/chroma/styles"
//"github.com/dchest/captcha"
"github.com/labstack/echo"
)
@@ -140,6 +142,13 @@ func pastePOST(ec echo.Context) error {
return ec.HTML(http.StatusBadRequest, errhtmlAsString)
}
// Verify captcha.
if !captcha.Verify(params["paste-captcha-id"][0], params["paste-captcha-solution"][0]) {
c.Logger.Debug().Msgf("Invalid captcha solution for captcha ID '%s': %s", params["paste-captcha-id"][0], params["paste-captcha-solution"][0])
errhtmlAsString := strings.Replace(string(errhtml), "{error}", "Invalid captcha solution.", 1)
return ec.HTML(http.StatusBadRequest, errhtmlAsString)
}
paste := &Paste{
Title: params["paste-title"][0],
Data: params["paste-contents"][0],