mirror of
https://github.com/ditatompel/xmr-remote-nodes.git
synced 2025-01-08 05:52:10 +07:00
Remove admin login logout handler and endpoints #2
This commit is contained in:
parent
30b37b922f
commit
d5f510ae32
4 changed files with 0 additions and 75 deletions
|
@ -14,7 +14,6 @@ import (
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"github.com/gofiber/fiber/v2/middleware/cors"
|
"github.com/gofiber/fiber/v2/middleware/cors"
|
||||||
"github.com/gofiber/fiber/v2/middleware/encryptcookie"
|
|
||||||
"github.com/gofiber/fiber/v2/middleware/filesystem"
|
"github.com/gofiber/fiber/v2/middleware/filesystem"
|
||||||
"github.com/gofiber/fiber/v2/middleware/logger"
|
"github.com/gofiber/fiber/v2/middleware/logger"
|
||||||
"github.com/gofiber/fiber/v2/middleware/recover"
|
"github.com/gofiber/fiber/v2/middleware/recover"
|
||||||
|
@ -62,10 +61,6 @@ func serve() {
|
||||||
AllowCredentials: true,
|
AllowCredentials: true,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
// cookie
|
|
||||||
app.Use(encryptcookie.New(encryptcookie.Config{Key: appCfg.SecretKey}))
|
|
||||||
|
|
||||||
handler.AppRoute(app)
|
|
||||||
handler.V1Api(app)
|
handler.V1Api(app)
|
||||||
app.Use("/", filesystem.New(filesystem.Config{
|
app.Use("/", filesystem.New(filesystem.Config{
|
||||||
Root: frontend.SvelteKitHandler(),
|
Root: frontend.SvelteKitHandler(),
|
||||||
|
|
|
@ -7,19 +7,6 @@ import (
|
||||||
"github.com/gofiber/fiber/v2"
|
"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 {
|
func CheckProber(c *fiber.Ctx) error {
|
||||||
key := c.Get("X-Prober-Api-Key")
|
key := c.Get("X-Prober-Api-Key")
|
||||||
if key == "" {
|
if key == "" {
|
||||||
|
|
|
@ -1,65 +1,13 @@
|
||||||
package handler
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
|
||||||
"xmr-remote-nodes/internal/database"
|
"xmr-remote-nodes/internal/database"
|
||||||
"xmr-remote-nodes/internal/repo"
|
"xmr-remote-nodes/internal/repo"
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Login(c *fiber.Ctx) error {
|
|
||||||
payload := repo.Admin{}
|
|
||||||
if err := c.BodyParser(&payload); err != nil {
|
|
||||||
return c.Status(fiber.StatusUnprocessableEntity).JSON(fiber.Map{
|
|
||||||
"status": "error",
|
|
||||||
"message": err.Error(),
|
|
||||||
"data": nil,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
repo := repo.NewAdminRepo(database.GetDB())
|
|
||||||
res, err := repo.Login(payload.Username, payload.Password)
|
|
||||||
if err != nil {
|
|
||||||
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
|
|
||||||
"status": "error",
|
|
||||||
"message": err.Error(),
|
|
||||||
"data": nil,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
token := fmt.Sprintf("auth_%d_%d", res.Id, time.Now().Unix())
|
|
||||||
c.Cookie(&fiber.Cookie{
|
|
||||||
Name: "xmr-nodes-ui",
|
|
||||||
Value: token,
|
|
||||||
Expires: time.Now().Add(time.Hour * 24),
|
|
||||||
HTTPOnly: true,
|
|
||||||
})
|
|
||||||
|
|
||||||
return c.JSON(fiber.Map{
|
|
||||||
"status": "ok",
|
|
||||||
"message": "Logged in",
|
|
||||||
"data": nil,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func Logout(c *fiber.Ctx) error {
|
|
||||||
c.Cookie(&fiber.Cookie{
|
|
||||||
Name: "xmr-nodes-ui",
|
|
||||||
Value: "",
|
|
||||||
Expires: time.Now(),
|
|
||||||
HTTPOnly: true,
|
|
||||||
})
|
|
||||||
|
|
||||||
return c.JSON(fiber.Map{
|
|
||||||
"status": "ok",
|
|
||||||
"message": "Logged out",
|
|
||||||
"data": nil,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func MoneroNode(c *fiber.Ctx) error {
|
func MoneroNode(c *fiber.Ctx) error {
|
||||||
nodeId, err := c.ParamsInt("id", 0)
|
nodeId, err := c.ParamsInt("id", 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -4,11 +4,6 @@ import (
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func AppRoute(app *fiber.App) {
|
|
||||||
app.Post("/auth/login", Login)
|
|
||||||
app.Post("/auth/logout", Logout)
|
|
||||||
}
|
|
||||||
|
|
||||||
func V1Api(app *fiber.App) {
|
func V1Api(app *fiber.App) {
|
||||||
v1 := app.Group("/api/v1")
|
v1 := app.Group("/api/v1")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue