re-construct oauth

This commit is contained in:
Tao Chen
2024-11-02 04:01:28 +08:00
parent c5e3482538
commit 485ae54e9e
14 changed files with 491 additions and 491 deletions

View File

@@ -1,8 +1,15 @@
package model
import (
"fmt"
"gorm.io/gorm"
)
type User struct {
IdModel
Username string `json:"username" gorm:"default:'';not null;uniqueIndex"`
Email string `json:"email" gorm:"default:'';not null;uniqueIndex"`
// Email string `json:"email" `
Password string `json:"-" gorm:"default:'';not null;"`
Nickname string `json:"nickname" gorm:"default:'';not null;"`
Avatar string `json:"avatar" gorm:"default:'';not null;"`
@@ -12,6 +19,15 @@ type User struct {
TimeModel
}
// BeforeSave 钩子用于确保 email 字段有合理的默认值
func (u *User) BeforeSave(tx *gorm.DB) (err error) {
// 如果 email 为空,设置为默认值
if u.Email == "" {
u.Email = fmt.Sprintf("%s@example.com", u.Username)
}
return nil
}
type UserList struct {
Users []*User `json:"list,omitempty"`
Pagination