mirror of
https://github.com/ultrasn0w/huso.git
synced 2025-12-13 17:29:54 +01:00
Users + Nuts + Sauce
This commit is contained in:
33
ober.go
33
ober.go
@@ -1,9 +1,12 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"crypto/sha512"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/fasthttp/router"
|
||||
"github.com/valyala/fasthttp"
|
||||
@@ -13,7 +16,7 @@ func RunWebserv() {
|
||||
r := router.New()
|
||||
r.GET("/", Start)
|
||||
r.GET("/api/season", Season)
|
||||
r.POST("api/register", Register)
|
||||
r.POST("/api/register", Register)
|
||||
log.Fatal(fasthttp.ListenAndServe(":"+strconv.Itoa(*webServerPort), r.Handler))
|
||||
}
|
||||
|
||||
@@ -60,13 +63,31 @@ func Season(ctx *fasthttp.RequestCtx) {
|
||||
}
|
||||
|
||||
func Register(ctx *fasthttp.RequestCtx) {
|
||||
_, err := ctx.WriteString("AAA")
|
||||
if err != nil {
|
||||
addErrorToCtx(ctx, err)
|
||||
if string(ctx.Request.Header.ContentType()) != "application/json" {
|
||||
ctx.SetStatusCode(fasthttp.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.SetContentType("application/json; charset=utf-8")
|
||||
body := ctx.PostBody()
|
||||
var register RegisterData
|
||||
err := json.Unmarshal(body, ®ister)
|
||||
if err != nil {
|
||||
ctx.WriteString(err.Error())
|
||||
ctx.SetStatusCode(fasthttp.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if register.MalId == 0 || register.Username == "" || register.Sauce == "" {
|
||||
ctx.WriteString("Sprich JSON du Hurensohn")
|
||||
ctx.SetStatusCode(fasthttp.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
calcSauce := fmt.Sprintf("%x", sha512.Sum512([]byte(registerSecret+strconv.Itoa(register.MalId)+register.Username)))
|
||||
if calcSauce != strings.ToLower(register.Sauce) {
|
||||
ctx.WriteString("Möge die Sauce mit dir sein")
|
||||
ctx.SetStatusCode(fasthttp.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
// TODO REGISTER
|
||||
ctx.SetBody(body)
|
||||
ctx.SetStatusCode(fasthttp.StatusOK)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user