2023-06-16 14:30:27 +02:00
|
|
|
package web
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
2024-05-04 17:06:01 +02:00
|
|
|
|
|
|
|
"code.lila.network/adoralaura/go-urlsh/internal/constants"
|
|
|
|
"code.lila.network/adoralaura/go-urlsh/internal/db"
|
|
|
|
"code.lila.network/adoralaura/go-urlsh/models"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
2023-06-16 14:30:27 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func HandleAdminAccountGet(c *fiber.Ctx) error {
|
2024-05-04 17:06:01 +02:00
|
|
|
if !db.IsCookieValid(c.Cookies(constants.LoginCookieName, "")) {
|
2023-06-16 14:30:27 +02:00
|
|
|
c.Location("/admin/")
|
|
|
|
c.Status(fiber.StatusSeeOther)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-05-04 17:06:01 +02:00
|
|
|
cookie := c.Cookies(constants.LoginCookieName, "")
|
|
|
|
user, err := db.GetUserFromCookie(cookie)
|
2023-06-16 14:30:27 +02:00
|
|
|
if err != nil {
|
2024-05-04 17:06:01 +02:00
|
|
|
log.Println(err)
|
|
|
|
fiber.NewError(fiber.StatusInternalServerError, "500 Internal Server Error")
|
2023-06-16 14:30:27 +02:00
|
|
|
}
|
2024-05-04 17:06:01 +02:00
|
|
|
var userresponse models.UserResponse
|
|
|
|
userresponse.UserName = user.UserName
|
|
|
|
userresponse.Created = user.Created
|
2023-06-16 14:30:27 +02:00
|
|
|
|
2024-05-04 17:06:01 +02:00
|
|
|
hasmfa, err := db.UserHasMFA(user)
|
2023-06-16 14:30:27 +02:00
|
|
|
if err != nil {
|
2024-05-04 17:06:01 +02:00
|
|
|
log.Println(err)
|
|
|
|
fiber.NewError(fiber.StatusInternalServerError, "500 Internal Server Error")
|
2023-06-16 14:30:27 +02:00
|
|
|
}
|
|
|
|
|
2024-05-04 17:06:01 +02:00
|
|
|
userresponse.MFAEnabled = hasmfa
|
|
|
|
|
|
|
|
return c.Render("account", userresponse)
|
2023-06-16 14:30:27 +02:00
|
|
|
}
|