GheddoAuth

This commit is contained in:
daru
2022-04-15 01:38:03 +02:00
parent ea49d83475
commit 19f860f418

19
ober.go
View File

@@ -180,7 +180,24 @@ func Register(ctx *fasthttp.RequestCtx) {
}
func WatchPost(ctx *fasthttp.RequestCtx) {
//
auth := ctx.Request.Header.Peek("X-HUSO-AUTH")
if ctx.UserValue("user") == nil || auth == nil || string(auth) == "" {
ctx.SetStatusCode(fasthttp.StatusBadRequest)
return
}
username := fmt.Sprintf("%s", ctx.UserValue("user"))
if !authenticate(username, string(auth)) {
ctx.SetStatusCode(fasthttp.StatusUnauthorized)
return
}
}
func authenticate(username, auth string) bool {
user, err := ReadUser(username)
if err != nil {
return false
}
return user.Secret == auth
}
func addErrorToCtx(ctx *fasthttp.RequestCtx, err error) {