40 lines
691 B
Go
40 lines
691 B
Go
package rest_handler
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
|
|
"gitea.elara.ws/Hazel/hangman/internal/game"
|
|
"github.com/labstack/echo/v4"
|
|
)
|
|
|
|
func TestAuth(c echo.Context) error {
|
|
session := game.GetSession(c.Param("session"))
|
|
|
|
type TestResults struct {
|
|
SignatureValid bool
|
|
User *string
|
|
}
|
|
|
|
sig := c.Request().Header.Get("signature")
|
|
body, _ := io.ReadAll(c.Request().Body)
|
|
fmt.Println(sig)
|
|
|
|
u := session.VerifySignature(sig, body)
|
|
var resp TestResults
|
|
if u == nil {
|
|
resp = TestResults{
|
|
SignatureValid: false,
|
|
User: nil,
|
|
}
|
|
} else {
|
|
resp = TestResults{
|
|
SignatureValid: true,
|
|
User: &u.Name,
|
|
}
|
|
}
|
|
|
|
return c.JSON(http.StatusOK, resp)
|
|
}
|