Remove admin login logout handler and endpoints #2

This commit is contained in:
ditatompel 2024-05-18 20:27:30 +07:00
parent 30b37b922f
commit d5f510ae32
No known key found for this signature in database
GPG key ID: 31D3D06D77950979
4 changed files with 0 additions and 75 deletions

View file

@ -14,7 +14,6 @@ import (
"github.com/gofiber/fiber/v2"
"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/logger"
"github.com/gofiber/fiber/v2/middleware/recover"
@ -62,10 +61,6 @@ func serve() {
AllowCredentials: true,
}))
// cookie
app.Use(encryptcookie.New(encryptcookie.Config{Key: appCfg.SecretKey}))
handler.AppRoute(app)
handler.V1Api(app)
app.Use("/", filesystem.New(filesystem.Config{
Root: frontend.SvelteKitHandler(),

View file

@ -7,19 +7,6 @@ import (
"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 == "" {

View file

@ -1,65 +1,13 @@
package handler
import (
"fmt"
"strconv"
"time"
"xmr-remote-nodes/internal/database"
"xmr-remote-nodes/internal/repo"
"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 {
nodeId, err := c.ParamsInt("id", 0)
if err != nil {

View file

@ -4,11 +4,6 @@ import (
"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) {
v1 := app.Group("/api/v1")