38 lines
976 B
Go
38 lines
976 B
Go
package web
|
|
|
|
import (
|
|
"log"
|
|
|
|
"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"
|
|
)
|
|
|
|
func HandleAdminAccountGet(c *fiber.Ctx) error {
|
|
if !db.IsCookieValid(c.Cookies(constants.LoginCookieName, "")) {
|
|
c.Location("/admin/")
|
|
c.Status(fiber.StatusSeeOther)
|
|
return nil
|
|
}
|
|
|
|
cookie := c.Cookies(constants.LoginCookieName, "")
|
|
user, err := db.GetUserFromCookie(cookie)
|
|
if err != nil {
|
|
log.Println(err)
|
|
fiber.NewError(fiber.StatusInternalServerError, "500 Internal Server Error")
|
|
}
|
|
var userresponse models.UserResponse
|
|
userresponse.UserName = user.UserName
|
|
userresponse.Created = user.Created
|
|
|
|
hasmfa, err := db.UserHasMFA(user)
|
|
if err != nil {
|
|
log.Println(err)
|
|
fiber.NewError(fiber.StatusInternalServerError, "500 Internal Server Error")
|
|
}
|
|
|
|
userresponse.MFAEnabled = hasmfa
|
|
|
|
return c.Render("account", userresponse)
|
|
}
|