diff --git a/pkg/server/admin/index.go b/pkg/server/admin/index.go index e3a15fd..ad11edc 100644 --- a/pkg/server/admin/index.go +++ b/pkg/server/admin/index.go @@ -1,12 +1,11 @@ package admin import ( - "git.solsynth.dev/hydrogen/passport/pkg/utils" "github.com/gofiber/fiber/v2" ) -func MapAdminEndpoints(A *fiber.App, authFunc utils.AuthFunc) { - admin := A.Group("/api/admin").Use(authFunc) +func MapAdminEndpoints(A *fiber.App, authMiddleware fiber.Handler) { + admin := A.Group("/api/admin").Use(authMiddleware) { admin.Post("/badges", grantBadge) admin.Delete("/badges/:badgeId", revokeBadge) diff --git a/pkg/server/startup.go b/pkg/server/startup.go index c2f8453..021ffe8 100644 --- a/pkg/server/startup.go +++ b/pkg/server/startup.go @@ -144,7 +144,7 @@ func NewServer() { URL: "/favicon.png", })) - admin.MapAdminEndpoints(A, authFunc) + admin.MapAdminEndpoints(A, authMiddleware) ui.MapUserInterface(A, authFunc) } diff --git a/pkg/server/ui/directory.go b/pkg/server/ui/directory.go deleted file mode 100644 index dc64950..0000000 --- a/pkg/server/ui/directory.go +++ /dev/null @@ -1,51 +0,0 @@ -package ui - -import ( - "fmt" - "html/template" - "time" - - "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" -) - -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()) - } - - 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, - "avatar": data.GetAvatar(), - "banner": data.GetBanner(), - }, "views/layouts/user-center") -} diff --git a/pkg/server/ui/index.go b/pkg/server/ui/index.go index 7f0fc62..eb8b19f 100644 --- a/pkg/server/ui/index.go +++ b/pkg/server/ui/index.go @@ -43,10 +43,5 @@ func MapUserInterface(A *fiber.App, authFunc utils.AuthFunc) { pages.Post("/mfa/apply", mfaApplyAction) pages.Post("/authorize", authCheckWare, authorizeAction) - pages.Get("/@:account", otherUserinfoPage) - pages.Get("/users/me", authCheckWare, selfUserinfoPage) - pages.Get("/users/me/personalize", authCheckWare, personalizePage) - - pages.Post("/users/me/personalize", authCheckWare, personalizeAction) } diff --git a/pkg/server/ui/personalize.go b/pkg/server/ui/personalize.go deleted file mode 100644 index 12b8797..0000000 --- a/pkg/server/ui/personalize.go +++ /dev/null @@ -1,101 +0,0 @@ -package ui - -import ( - "fmt" - "git.solsynth.dev/hydrogen/passport/pkg/database" - "git.solsynth.dev/hydrogen/passport/pkg/models" - "git.solsynth.dev/hydrogen/passport/pkg/services" - "git.solsynth.dev/hydrogen/passport/pkg/utils" - "github.com/gofiber/fiber/v2" - "github.com/nicksnyder/go-i18n/v2/i18n" - "github.com/samber/lo" - "github.com/sujit-baniya/flash" - "strings" - "time" -) - -func personalizePage(c *fiber.Ctx) error { - user := c.Locals("principal").(models.Account) - localizer := c.Locals("localizer").(*i18n.Localizer) - - 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 any - if data.Profile.Birthday != nil { - birthday = strings.SplitN(data.Profile.Birthday.Format(time.RFC3339), "T", 1)[0] - } - - apply, _ := localizer.LocalizeMessage(&i18n.Message{ID: "apply"}) - back, _ := localizer.LocalizeMessage(&i18n.Message{ID: "back"}) - - return c.Render("views/users/personalize", fiber.Map{ - "info": flash.Get(c)["message"], - "birthday_at": birthday, - "userinfo": data, - "i18n": fiber.Map{ - "apply": apply, - "back": back, - }, - }, "views/layouts/user-center") -} - -func personalizeAction(c *fiber.Ctx) error { - user := c.Locals("principal").(models.Account) - - var data struct { - Nick string `form:"nick" validate:"required,min=4,max=24"` - Description string `form:"description"` - FirstName string `form:"first_name"` - LastName string `form:"last_name"` - Birthday string `form:"birthday"` - } - - if err := utils.BindAndValidate(c, &data); err != nil { - return flash.WithInfo(c, fiber.Map{ - "message": err.Error(), - }).Redirect("/users/me/personalize") - } - - var account models.Account - if err := database.C. - Where(&models.Account{BaseModel: models.BaseModel{ID: user.ID}}). - Preload("Profile"). - First(&account).Error; err != nil { - return flash.WithInfo(c, fiber.Map{ - "message": fmt.Sprintf("unable to get your userinfo: %v", err), - }).Redirect("/users/me/personalize") - } - - account.Nick = data.Nick - account.Description = data.Description - account.Profile.FirstName = data.FirstName - account.Profile.LastName = data.LastName - - if birthday, err := time.Parse(time.DateOnly, data.Birthday); err == nil { - account.Profile.Birthday = lo.ToPtr(birthday) - } - - if err := database.C.Save(&account).Error; err != nil { - return flash.WithInfo(c, fiber.Map{ - "message": fmt.Sprintf("unable to personalize your account: %v", err), - }).Redirect("/users/me/personalize") - } else if err := database.C.Save(&account.Profile).Error; err != nil { - return flash.WithInfo(c, fiber.Map{ - "message": fmt.Sprintf("unable to personalize your profile: %v", err), - }).Redirect("/users/me/personalize") - } - - services.InvalidAuthCacheWithUser(account.ID) - - return flash.WithInfo(c, fiber.Map{ - "message": "your account has been personalized", - }).Redirect("/users/me") -} diff --git a/pkg/views/authorize.gohtml b/pkg/views/authorize.gohtml index 2527308..c98e6a4 100644 --- a/pkg/views/authorize.gohtml +++ b/pkg/views/authorize.gohtml @@ -1,50 +1,56 @@
- + -

{{.i18n.title}} {{.client.Name}}

-

{{.i18n.caption}}

+

{{.i18n.title}} {{.client.Name}}

+

{{.i18n.caption}}

-
+
-
-
-
Description
-
{{.client.Description}}
-
+ +
+
Description
+
{{.client.Description}}
+
-
-
Requested scopes
-
    - {{range $_, $element := .scopes}} -
  • - {{$element}} -
  • - {{end}} -
-
+
+
Requested scopes
+
    + {{range $_, $element := .scopes}} +
  • + {{$element}} +
  • + {{end}} +
+
-
- {{.i18n.decline}} - {{.i18n.approve}} -
-
+
+ + +
+
\ No newline at end of file + $("#decline-button").on("click", () => { + history.back() + window.close() + }) + diff --git a/pkg/views/layouts/auth.gohtml b/pkg/views/layouts/auth.gohtml index b993624..94815ea 100644 --- a/pkg/views/layouts/auth.gohtml +++ b/pkg/views/layouts/auth.gohtml @@ -4,124 +4,112 @@ {{template "views/partials/header"}} -
-
- {{if ne .info nil}} -
-
{{.info}}
-
- {{end}} +
+
+ {{if ne .info nil}} + + {{end}} -
- {{embed}} -
+
+ {{embed}} +
-
+
- \ No newline at end of file + + diff --git a/pkg/views/layouts/user-center.gohtml b/pkg/views/layouts/user-center.gohtml index 30ba1f9..4828bd7 100644 --- a/pkg/views/layouts/user-center.gohtml +++ b/pkg/views/layouts/user-center.gohtml @@ -4,132 +4,125 @@ {{template "views/partials/header"}} -
-
- {{if ne .info nil}} -
-
{{.info}}
-
- {{end}} +
+
+ {{if ne .info nil}} + + {{end}} -
- {{embed}} -
+
+ {{embed}} +
-
+
+ diff --git a/pkg/views/mfa-apply.gohtml b/pkg/views/mfa-apply.gohtml index 9aa7bfb..187ce82 100644 --- a/pkg/views/mfa-apply.gohtml +++ b/pkg/views/mfa-apply.gohtml @@ -1,47 +1,43 @@
- + -

{{.i18n.title}}

-

{{.i18n.caption}}

+

{{.i18n.title}}

+

{{.i18n.caption}}

-
+
-
- - + + + -
{{.label}}
+
{{.label}}
- - +
+ + +
-
- {{.i18n.next}} -
-
+
+ +
+
\ No newline at end of file + } + diff --git a/pkg/views/mfa.gohtml b/pkg/views/mfa.gohtml index f3bcaae..8372c07 100644 --- a/pkg/views/mfa.gohtml +++ b/pkg/views/mfa.gohtml @@ -1,61 +1,59 @@
- + -

{{.i18n.title}}

-

{{.i18n.caption}}

+

{{.i18n.title}}

+

{{.i18n.caption}}

-
+
-
- - {{if ne .redirect_uri nil}} - - {{end}} + + + {{if ne .redirect_uri nil}} + + {{end}} -
- {{range $_, $element := .factors}} -
- - - -
- {{end}} +
+ {{range $_, $element := .factors}} +
+
+ +
+
+ {{end}} +
-
- {{.i18n.next}} -
- +
+ +
+
\ No newline at end of file + .factor-label label { + display: inline-flex; + place-items: center; + gap: 8px; + font-family: Roboto, system-ui; + color: var(--md-sys-color-on-background); + } + diff --git a/pkg/views/partials/header.gohtml b/pkg/views/partials/header.gohtml index 8f6349f..09202f3 100644 --- a/pkg/views/partials/header.gohtml +++ b/pkg/views/partials/header.gohtml @@ -1,89 +1,56 @@ - - - + + + - + - - - - + - + + + - + + + + + - Solarpass + Solarpass - + .alert .bi { + aspect-ratio: 1; + width: 16px; + fill: var(--bs-alert-color); + } + + .alert .content { + flex-grow: 1; + text-transform: capitalize; + } + diff --git a/pkg/views/signin.gohtml b/pkg/views/signin.gohtml index 143a825..beef18e 100644 --- a/pkg/views/signin.gohtml +++ b/pkg/views/signin.gohtml @@ -1,35 +1,27 @@
- + -

{{.i18n.title}}

-

{{.i18n.caption}}

+

{{.i18n.title}}

+

{{.i18n.caption}}

-
+
-
- - + +
+ + +
- - +
+ + +
-
- {{.i18n.signup}} - {{.i18n.next}} -
-
-
\ No newline at end of file +
+ {{.i18n.signup}} + +
+ +
diff --git a/pkg/views/signup.gohtml b/pkg/views/signup.gohtml index 22a2973..2f88f97 100644 --- a/pkg/views/signup.gohtml +++ b/pkg/views/signup.gohtml @@ -1,67 +1,47 @@
- + -

{{.i18n.title}}

-

{{.i18n.caption}}

+

{{.i18n.title}}

+

{{.i18n.caption}}

-
+
-
-
- - + +
+
+ + +
- - -
+
+ + +
+
- - +
+ + +
- - +
+ + +
- {{if eq .use_magic_token true}} - - - {{end}} + {{if eq .use_magic_token true}} +
+ + +
+ {{end}} -
- {{.i18n.signin}} - {{.i18n.next}} -
-
-
\ No newline at end of file +
+ {{.i18n.signin}} + +
+ +
diff --git a/pkg/views/users/directory/userinfo.gohtml b/pkg/views/users/directory/userinfo.gohtml deleted file mode 100644 index 4e0b7fb..0000000 --- a/pkg/views/users/directory/userinfo.gohtml +++ /dev/null @@ -1,165 +0,0 @@ - - - - - - - -
- {{if ne .userinfo.Avatar nil}} - Avatar - {{else}} -
- account_circle -
- {{end}} - -
-

{{.userinfo.Nick}}

-
@{{.userinfo.Name}}
-
- {{if gt (len .userinfo.Description) 0}} -
{{.userinfo.Description}}
- {{else}} -
No description yet.
- {{end}} -
#{{.uid}}
- - - -
- - Add as friend - group_add - -
-
- -
-
- {{.personal_page}} -
-
- - \ No newline at end of file diff --git a/pkg/views/users/me.gohtml b/pkg/views/users/me.gohtml index 1c61f36..63c8be1 100644 --- a/pkg/views/users/me.gohtml +++ b/pkg/views/users/me.gohtml @@ -4,166 +4,150 @@
- {{if ne .userinfo.Avatar nil}} - Avatar - {{else}} -
- account_circle -
- {{end}} + {{if ne .userinfo.Avatar nil}} + Avatar + {{else}} +
+ account_circle +
+ {{end}} -
-

{{.userinfo.Nick}}

-
@{{.userinfo.Name}}
-
- {{if gt (len .userinfo.Description) 0}} -
{{.userinfo.Description}}
- {{else}} -
No description yet.
- {{end}} -
#{{.uid}}
- - - -
- - Personalize - palette - - - Security - security - -
+
+

{{.userinfo.Nick}}

+
@{{.userinfo.Name}}
+
+ {{if gt (len .userinfo.Description) 0}} +
{{.userinfo.Description}}
+ {{else}} +
No description yet.
+ {{end}} +
#{{.uid}}
-
- {{.personal_page}} -
+
+ {{.personal_page}} +
\ No newline at end of file + .left-part .prose { + min-width: 0; + max-width: unset; + } + diff --git a/pkg/views/users/personalize.gohtml b/pkg/views/users/personalize.gohtml deleted file mode 100644 index 34fd4b2..0000000 --- a/pkg/views/users/personalize.gohtml +++ /dev/null @@ -1,110 +0,0 @@ -
- - -

Personalize

-

Personalize your account, and make us provide better service for you.

-
- -
-
- -
- We doesn't support edit avatar / banner through Hydrogen.Passport web yet. Go try our Solian App! -
- -
-
- - - - - -
- -
- - - - - -
- - - - - - - -
- {{.i18n.back}} - {{.i18n.apply}} -
-
-
- - \ No newline at end of file