2024-04-21 09:30:50 +00:00
|
|
|
package ui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"git.solsynth.dev/hydrogen/passport/pkg/database"
|
|
|
|
"git.solsynth.dev/hydrogen/passport/pkg/models"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
|
|
"github.com/gomarkdown/markdown"
|
|
|
|
"github.com/gomarkdown/markdown/html"
|
|
|
|
"github.com/gomarkdown/markdown/parser"
|
2024-05-18 09:24:14 +00:00
|
|
|
"github.com/spf13/viper"
|
2024-04-21 09:30:50 +00:00
|
|
|
"github.com/sujit-baniya/flash"
|
|
|
|
"html/template"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func otherUserinfoPage(c *fiber.Ctx) error {
|
|
|
|
name := c.Params("account")
|
|
|
|
|
|
|
|
var data models.Account
|
|
|
|
if err := database.C.
|
|
|
|
Where(&models.Account{Name: name}).
|
|
|
|
Preload("Profile").
|
|
|
|
Preload("PersonalPage").
|
|
|
|
Preload("Contacts").
|
|
|
|
First(&data).Error; err != nil {
|
|
|
|
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
var birthday = "Unknown"
|
|
|
|
if data.Profile.Birthday != nil {
|
|
|
|
birthday = data.Profile.Birthday.Format(time.RFC822)
|
|
|
|
}
|
|
|
|
|
|
|
|
doc := parser.
|
|
|
|
NewWithExtensions(parser.CommonExtensions | parser.AutoHeadingIDs | parser.NoEmptyLineBeforeBlock).
|
|
|
|
Parse([]byte(data.PersonalPage.Content))
|
|
|
|
|
|
|
|
renderer := html.NewRenderer(html.RendererOptions{Flags: html.CommonFlags | html.HrefTargetBlank})
|
|
|
|
|
|
|
|
return c.Render("views/users/directory/userinfo", fiber.Map{
|
|
|
|
"info": flash.Get(c)["message"],
|
|
|
|
"uid": fmt.Sprintf("%08d", data.ID),
|
|
|
|
"joined_at": data.CreatedAt.Format(time.RFC822),
|
|
|
|
"birthday_at": birthday,
|
|
|
|
"personal_page": template.HTML(markdown.Render(doc, renderer)),
|
|
|
|
"userinfo": data,
|
2024-05-18 09:24:14 +00:00
|
|
|
"avatar": fmt.Sprintf("%s/api/attachments/%s", viper.GetString("paperclip.endpoint"), data.Avatar),
|
|
|
|
"banner": fmt.Sprintf("%s/api/attachments/%s", viper.GetString("paperclip.endpoint"), data.Banner),
|
2024-04-21 09:30:50 +00:00
|
|
|
}, "views/layouts/user-center")
|
|
|
|
}
|