goipam/web/ui/profile.go

39 lines
834 B
Go
Raw Normal View History

2024-02-22 10:18:59 +01:00
package ui
import (
"net/http"
2024-02-22 20:52:37 +01:00
"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
"git.jmbit.de/jmb/goipam/db"
"git.jmbit.de/jmb/goipam/utils"
"git.jmbit.de/jmb/goipam/web/templates"
2024-02-22 10:18:59 +01:00
)
func getProfile(c *gin.Context) {
2024-02-22 20:52:37 +01:00
session := sessions.Default(c)
sessionUserName := session.Get("username")
var user db.User
if username, ok := sessionUserName.(string); ok {
user, err := db.GetUserByName(username)
if err != nil {
c.HTML(
http.StatusInternalServerError,
"",
templates.ProfilePage(utils.GenMetaContent(c), "User Profile", &user, nil),
)
}
c.HTML(
http.StatusOK,
"",
templates.ProfilePage(utils.GenMetaContent(c), "User Profile", &user, nil),
)
} else {
c.HTML(http.StatusNotFound, "", templates.ProfilePage(utils.GenMetaContent(c), "User Profile", &user, nil))
}
2024-02-22 10:18:59 +01:00
}