theme v1
This commit is contained in:
+38
-24
@@ -40,6 +40,7 @@ type UsersStore interface {
|
||||
// UpdateModerationStrictness 更新内容审核严格度(lax / standard / strict,空值表示跟随站点默认)。
|
||||
// 只写 moderation_strictness 列,不影响防骚扰与屏蔽词。
|
||||
UpdateModerationStrictness(ctx context.Context, id uint, strictness string) error
|
||||
UpdateTheme(ctx context.Context, id uint, theme string) error
|
||||
Authenticate(ctx context.Context, email, password string) (*User, error)
|
||||
ChangePassword(ctx context.Context, id uint, oldPassword, newPassword string) error
|
||||
UpdatePassword(ctx context.Context, id uint, newPassword string) error
|
||||
@@ -85,30 +86,33 @@ type users struct {
|
||||
|
||||
type User struct {
|
||||
gorm.Model `json:"-"`
|
||||
UID string `json:"-"`
|
||||
Name string `json:"name"`
|
||||
Password string `json:"-"`
|
||||
Email string `json:"-" gorm:"uniqueIndex:idx_users_email_unique"`
|
||||
Avatar string `json:"avatar"`
|
||||
Domain string `json:"domain" gorm:"uniqueIndex:idx_users_domain_unique"`
|
||||
Background string `json:"background"`
|
||||
Intro string `json:"intro"`
|
||||
Introcolor string `json:"introcolor"`
|
||||
Usernamecolor string `json:"usernamecolor"`
|
||||
Qrcodebackcolor string `json:"qrcodebackcolor"`
|
||||
Qrcodecolor string `json:"qrcodecolor"`
|
||||
BackgroundImage string `json:"backgroundimage"`
|
||||
Dotscale string `json:"dotscale"`
|
||||
Acfunlink string `json:"acfunlink"`
|
||||
Bililink string `json:"bililink"`
|
||||
Weibolink string `json:"weibolink"`
|
||||
Bloglink string `json:"bloglink"`
|
||||
Xiaohongshulink string `json:"xiaohongshulink"`
|
||||
Qrcodepdpcolor string `json:"qrcodepdpcolor"`
|
||||
Backgroundimagealpha string `json:"Backgroundimagealpha"`
|
||||
Notify NotifyType `json:"notify"`
|
||||
HarassmentSetting HarassmentSettingType `json:"harassment_setting" gorm:"default:'none'"`
|
||||
BlockWords string `json:"-"`
|
||||
UID string `json:"-"`
|
||||
Name string `json:"name"`
|
||||
Password string `json:"-"`
|
||||
Email string `json:"-" gorm:"uniqueIndex:idx_users_email_unique"`
|
||||
Avatar string `json:"avatar"`
|
||||
Domain string `json:"domain" gorm:"uniqueIndex:idx_users_domain_unique"`
|
||||
Background string `json:"background"`
|
||||
Intro string `json:"intro"`
|
||||
Introcolor string `json:"introcolor"`
|
||||
Usernamecolor string `json:"usernamecolor"`
|
||||
Qrcodebackcolor string `json:"qrcodebackcolor"`
|
||||
Qrcodecolor string `json:"qrcodecolor"`
|
||||
BackgroundImage string `json:"backgroundimage"`
|
||||
Dotscale string `json:"dotscale"`
|
||||
Acfunlink string `json:"acfunlink"`
|
||||
Bililink string `json:"bililink"`
|
||||
Weibolink string `json:"weibolink"`
|
||||
Bloglink string `json:"bloglink"`
|
||||
Xiaohongshulink string `json:"xiaohongshulink"`
|
||||
Qrcodepdpcolor string `json:"qrcodepdpcolor"`
|
||||
Backgroundimagealpha string `json:"Backgroundimagealpha"`
|
||||
// Theme 箱主选择的主题 slug(空串=跟随站点默认,default=基础外观)。
|
||||
// 取值合法性由 route/user 在写入前校验,读取侧由 internal/theme 回退。
|
||||
Theme string `json:"theme" gorm:"column:theme;type:varchar(32);default:''"`
|
||||
Notify NotifyType `json:"notify"`
|
||||
HarassmentSetting HarassmentSettingType `json:"harassment_setting" gorm:"default:'none'"`
|
||||
BlockWords string `json:"-"`
|
||||
// 防骚扰设置取值 none / register_only(见下方常量)。历史账号此列为空串(建表时无默认值),
|
||||
// 与 none 语义等价但取值不同,会导致「按 == none 判断」的隐性漏判 → 已补 schema 默认值、
|
||||
// Create 显式写入、启动期归一历史空值(见 db.Init 的 normalizeHarassmentSetting)。
|
||||
@@ -445,6 +449,16 @@ func (db *users) UpdateModerationStrictness(ctx context.Context, id uint, strict
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateTheme 仅更新主题 slug,不动其它个性化字段(背景/颜色各自独立保存)。
|
||||
func (db *users) UpdateTheme(ctx context.Context, id uint, theme string) error {
|
||||
if err := db.WithContext(ctx).Model(&User{}).Where("id = ?", id).Updates(map[string]interface{}{
|
||||
"Theme": theme,
|
||||
}).Error; err != nil {
|
||||
return errors.Wrap(err, "update user")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (db *users) Authenticate(ctx context.Context, email, password string) (*User, error) {
|
||||
u, err := db.GetByEmail(ctx, email)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user