✨ User center page
This commit is contained in:
		| @@ -1,7 +1,48 @@ | ||||
| package ui | ||||
|  | ||||
| import "github.com/gofiber/fiber/v2" | ||||
| 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" | ||||
| 	"github.com/sujit-baniya/flash" | ||||
| 	"html/template" | ||||
| 	"time" | ||||
| ) | ||||
|  | ||||
| func selfUserinfoPage(c *fiber.Ctx) error { | ||||
| 	return c.Render("views/users/me/index", fiber.Map{}) | ||||
| 	user := c.Locals("principal").(models.Account) | ||||
|  | ||||
| 	var data models.Account | ||||
| 	if err := database.C. | ||||
| 		Where(&models.Account{BaseModel: models.BaseModel{ID: user.ID}}). | ||||
| 		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/me", 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, | ||||
| 	}, "views/layouts/user-center") | ||||
| } | ||||
|   | ||||
| @@ -12,12 +12,10 @@ func MapUserInterface(A *fiber.App, authFunc func(c *fiber.Ctx, overrides ...str | ||||
| 		if cookie := c.Cookies(services.CookieAccessKey); len(cookie) > 0 { | ||||
| 			token = cookie | ||||
| 		} | ||||
| 		fmt.Println(token) | ||||
|  | ||||
| 		c.Locals("token", token) | ||||
|  | ||||
| 		if err := authFunc(c); err != nil { | ||||
| 			fmt.Println(err) | ||||
| 			uri := c.Request().URI().FullURI() | ||||
| 			return c.Redirect(fmt.Sprintf("/sign-in?redirect_uri=%s", string(uri))) | ||||
| 		} else { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user