39 lines
834 B
Go
39 lines
834 B
Go
package ui
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"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"
|
|
)
|
|
|
|
func getProfile(c *gin.Context) {
|
|
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))
|
|
}
|
|
|
|
}
|