mirror of
https://github.com/ultrasn0w/huso.git
synced 2025-12-13 15:39:53 +01:00
GheddoAuth
This commit is contained in:
19
ober.go
19
ober.go
@@ -180,7 +180,24 @@ func Register(ctx *fasthttp.RequestCtx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func WatchPost(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) {
|
func addErrorToCtx(ctx *fasthttp.RequestCtx, err error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user