From 5979fd5b2c01b8c162e98e2cc66bd71faac5a7d1 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sun, 2 Mar 2025 12:00:29 +0800 Subject: [PATCH] :sparkles: Enchance user profile :boom: Move description from account to profile --- pkg/authkit/models/accounts.go | 4 +++- pkg/authkit/models/auth.go | 3 ++- pkg/authkit/models/profiles.go | 27 +++++++++++++++++++++------ pkg/internal/web/api/accounts_api.go | 27 +++++++++++++++++++++------ 4 files changed, 47 insertions(+), 14 deletions(-) diff --git a/pkg/authkit/models/accounts.go b/pkg/authkit/models/accounts.go index 4944675..420fbc9 100644 --- a/pkg/authkit/models/accounts.go +++ b/pkg/authkit/models/accounts.go @@ -17,7 +17,6 @@ type Account struct { Name string `json:"name" gorm:"uniqueIndex"` Nick string `json:"nick"` - Description string `json:"description"` Avatar *string `json:"avatar"` Banner *string `json:"banner"` ConfirmedAt *time.Time `json:"confirmed_at"` @@ -39,6 +38,9 @@ type Account struct { Factors []AuthFactor `json:"factors,omitempty"` Relations []AccountRelationship `json:"relations,omitempty" gorm:"foreignKey:AccountID"` + + // Keep this for backward compability + Description string `json:"description" gorm:"-"` } func (v Account) GetAvatar() *string { diff --git a/pkg/authkit/models/auth.go b/pkg/authkit/models/auth.go index 916abd8..b7a2c4f 100644 --- a/pkg/authkit/models/auth.go +++ b/pkg/authkit/models/auth.go @@ -8,7 +8,8 @@ import ( ) type AuthConfig struct { - MaximumAuthSteps int `json:"maximum_auth_steps" validate:"required,min=1,max=99"` + AlwaysRisky bool `json:"always_risky"` + MaximumAuthSteps int `json:"maximum_auth_steps" validate:"required,min=1,max=99"` } type AuthFactorType = int8 diff --git a/pkg/authkit/models/profiles.go b/pkg/authkit/models/profiles.go index 8c873a8..908e9a7 100644 --- a/pkg/authkit/models/profiles.go +++ b/pkg/authkit/models/profiles.go @@ -2,15 +2,30 @@ package models import ( "time" + + "gorm.io/datatypes" ) type AccountProfile struct { BaseModel - FirstName string `json:"first_name"` - LastName string `json:"last_name"` - Experience uint64 `json:"experience"` - LastSeenAt *time.Time `json:"last_seen_at"` - Birthday *time.Time `json:"birthday"` - AccountID uint `json:"account_id"` + FirstName string `json:"first_name"` + LastName string `json:"last_name"` + Description string `json:"description"` + TimeZone string `json:"time_zone"` + Location string `json:"location"` + Pronouns string `json:"pronouns"` + Gender string `json:"gender"` + Links datatypes.JSONMap `json:"links"` + Experience uint64 `json:"experience"` + LastSeenAt *time.Time `json:"last_seen_at"` + Birthday *time.Time `json:"birthday"` + AccountID uint `json:"account_id"` +} + +type AccountPage struct { + BaseModel + + Content string `json:"content"` + AccountID uint `json:"account_id"` } diff --git a/pkg/internal/web/api/accounts_api.go b/pkg/internal/web/api/accounts_api.go index 366923f..c69747d 100644 --- a/pkg/internal/web/api/accounts_api.go +++ b/pkg/internal/web/api/accounts_api.go @@ -119,11 +119,16 @@ func updateUserinfo(c *fiber.Ctx) error { user := c.Locals("user").(models.Account) var data struct { - Nick string `json:"nick" validate:"required"` - Description string `json:"description"` - FirstName string `json:"first_name"` - LastName string `json:"last_name"` - Birthday time.Time `json:"birthday"` + Nick string `json:"nick" validate:"required"` + Description string `json:"description"` + FirstName string `json:"first_name"` + LastName string `json:"last_name"` + Location string `json:"location"` + TimeZone string `json:"time_zone"` + Gender string `json:"gender"` + Pronouns string `json:"pronouns"` + Links map[string]string `json:"links"` + Birthday time.Time `json:"birthday"` } if err := exts.BindAndValidate(c, &data); err != nil { @@ -143,8 +148,18 @@ func updateUserinfo(c *fiber.Ctx) error { return fiber.NewError(fiber.StatusInternalServerError, err.Error()) } + var links = make(map[string]any) + for k, v := range data.Links { + links[k] = v + } + account.Nick = data.Nick - account.Description = data.Description + account.Profile.Gender = data.Gender + account.Profile.Pronouns = data.Pronouns + account.Profile.Location = data.Location + account.Profile.TimeZone = data.TimeZone + account.Profile.Links = links + account.Profile.Description = data.Description account.Profile.FirstName = data.FirstName account.Profile.LastName = data.LastName account.Profile.Birthday = &data.Birthday