mirror of
https://github.com/ditatompel/xmr-remote-nodes.git
synced 2024-12-23 12:09:47 +00:00
5496692c5d
I hope it will be less discoverable by other users and less likely to be used unintentionally in other projects.
46 lines
932 B
Go
46 lines
932 B
Go
package handler
|
|
|
|
import (
|
|
"xmr-remote-nodes/internal/database"
|
|
"xmr-remote-nodes/internal/repo"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
func CookieProtected(c *fiber.Ctx) error {
|
|
cookie := c.Cookies("xmr-nodes-ui")
|
|
if cookie == "" {
|
|
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
|
|
"status": "error",
|
|
"message": "Unauthorized",
|
|
"data": nil,
|
|
})
|
|
}
|
|
|
|
return c.Next()
|
|
}
|
|
|
|
func CheckProber(c *fiber.Ctx) error {
|
|
key := c.Get("X-Prober-Api-Key")
|
|
if key == "" {
|
|
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
|
|
"status": "error",
|
|
"message": "Unauthorized",
|
|
"data": nil,
|
|
})
|
|
}
|
|
|
|
proberRepo := repo.NewProberRepo(database.GetDB())
|
|
|
|
prober, err := proberRepo.CheckApi(key)
|
|
if err != nil {
|
|
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
|
|
"status": "error",
|
|
"message": "No API key match",
|
|
"data": nil,
|
|
})
|
|
}
|
|
|
|
c.Locals("prober_id", prober.Id)
|
|
return c.Next()
|
|
}
|