mirror of
https://github.com/mainnika/a-quest.git
synced 2026-07-03 17:42:33 +00:00
improve first answer validation
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -35,8 +36,8 @@ type Api struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Answer struct {
|
type Answer struct {
|
||||||
Answer json.RawMessage `json:"answer"`
|
Answer string `json:"answer"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Api) GetHandler() fasthttp.RequestHandler {
|
func (a *Api) GetHandler() fasthttp.RequestHandler {
|
||||||
@@ -85,8 +86,12 @@ func (a *Api) checkAnswer(ctx *routing.Context) (err error) {
|
|||||||
return routing.NewHTTPError(http.StatusBadRequest, err.Error())
|
return routing.NewHTTPError(http.StatusBadRequest, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cleaner := regexp.MustCompile("[[:^alnum:]]")
|
||||||
|
pure := cleaner.ReplaceAllLiteralString(answer.Answer, "")
|
||||||
|
pure = strings.ToLower(pure)
|
||||||
|
|
||||||
hash := sha256.New()
|
hash := sha256.New()
|
||||||
hash.Write(answer.Answer)
|
hash.Write([]byte(pure))
|
||||||
|
|
||||||
hexed := make([]byte, hex.EncodedLen(sha256.Size))
|
hexed := make([]byte, hex.EncodedLen(sha256.Size))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user