filegate/web/ui/profile.go

39 lines
855 B
Go

package ui
import (
"net/http"
"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
"git.jmbit.de/filegate/filegate/db"
"git.jmbit.de/filegate/filegate/utils"
"git.jmbit.de/filegate/filegate/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))
}
}