users

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 12, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusNormal = 0
	StatusFrozen = 1
)
View Source
const (
	ActivationPending = 0
	ActivationSuccess = 1
)

Variables

This section is empty.

Functions

func Create

func Create(entity *EntityComplete) error

func ExistEmail

func ExistEmail(email string) bool

ExistEmail 检查邮箱是否已存在

func ExistUsername

func ExistUsername(username string) bool

ExistUsername 检查用户名是否已存在

func GetCountGroupByDay added in v0.1.1

func GetCountGroupByDay() ([]map[string]any, error)

GetCountGroupByDay 按天统计注册人数

func GetMapByIds

func GetMapByIds(userIds []uint64) map[uint64]*EntityComplete

func GetMaxId

func GetMaxId() uint64

func GetRoleId added in v0.1.1

func GetRoleId(userId uint64) (roleId uint64, err error)

func IncrementPrestige

func IncrementPrestige(addNumber int64, userId uint64) int64

func Page

func Page(q PageQuery) struct {
	Page     int
	PageSize int
	Total    int64
	Data     []EntityComplete
}

func RandAvatarUrl added in v0.0.6

func RandAvatarUrl() string

func Save

func Save(entity *EntityComplete) error

Types

type EntityComplete added in v0.0.7

type EntityComplete struct {
	// base
	Id          uint64     `gorm:"primaryKey;column:id;autoIncrement;not null;" json:"id"`                      //
	Username    string     `gorm:"column:username;index;type:varchar(64);not null;default:'';" json:"username"` //
	Email       string     `gorm:"column:email;index;type:varchar(128);not null;default:'';" json:"email"`      //
	Password    string     `gorm:"column:password;type:varchar(128);not null;default:'';" json:"-"`             //
	IsFrozen    int8       `gorm:"column:is_frozen;type:tinyint;not null;default:0;" json:"isFrozen"`           // 状态:0正常 1冻结
	IsActivated int8       `gorm:"column:is_activated;type:tinyint;not null;default:0;" json:"isActivated"`     // 是否验证通过: 0未激活 1 已激活
	ActivatedAt *time.Time `gorm:"column:activated_at;type:datetime;" json:"activatedAt"`                       // 激活时间

	// info
	Nickname            string              `gorm:"column:nickname;type:varchar(64);not null;default:'';" json:"nickname"`                                  //
	RoleId              uint64              `gorm:"column:role_id;type:bigint unsigned;not null;default:0;" json:"roleId"`                                  //
	Prestige            int64               `gorm:"column:prestige;type:bigint;not null;default:0;" json:"prestige"`                                        // 声望
	AvatarUrl           string              `gorm:"column:avatar_url;type:varchar(255);" json:"avatarUrl"`                                                  // 头像URL
	Bio                 string              `gorm:"column:bio;type:varchar(500);not null;default:'';" json:"bio"`                                           // 个人简介
	Signature           string              `gorm:"column:signature;type:varchar(255);not null;default:'';" json:"signature"`                               // 署名
	WebsiteName         string              `gorm:"column:website_name;type:varchar(64);not null;default:'';" json:"websiteName"`                           // 个人网站名
	Website             string              `gorm:"column:website;type:varchar(255);not null;default:'';" json:"website"`                                   // 个人网站
	ExternalInformation ExternalInformation `gorm:"column:external_information;type:varchar(2048);default:'{}';serializer:json" json:"externalInformation"` // 外部信息

	// status
	CreatedAt time.Time      `gorm:"column:created_at;index;autoCreateTime;<-:create;" json:"createdAt"` //
	UpdatedAt time.Time      `gorm:"column:updated_at;autoUpdateTime;" json:"updatedAt"`
	DeletedAt gorm.DeletedAt //
}

func All

func All() (entities []*EntityComplete)

func Get

func Get(id any) (entity EntityComplete, err error)

func GetAll added in v0.1.1

func GetAll(offset, limit int) ([]*EntityComplete, error)

GetAll 用于全量导出/修复数据,支持分页查询

func GetByEmail added in v0.0.3

func GetByEmail(email string) (entity EntityComplete, err error)

GetByEmail 通过邮箱获取用户

func GetByIds

func GetByIds(userIds []uint64) (entities []*EntityComplete)

func MakeUser

func MakeUser(name string, password string, email string) *EntityComplete

func QueryById added in v0.0.3

func QueryById(startId uint64, limit int) (entities []*EntityComplete)

func Verify

func Verify(usernameOrEmail string, password string) (*EntityComplete, error)

func (*EntityComplete) Activate added in v0.0.7

func (itself *EntityComplete) Activate() error

func (*EntityComplete) GetWebAvatarUrl added in v0.0.7

func (itself *EntityComplete) GetWebAvatarUrl() string

func (*EntityComplete) SetPassword added in v0.0.7

func (itself *EntityComplete) SetPassword(password string) *EntityComplete

func (*EntityComplete) TableName added in v0.0.7

func (itself *EntityComplete) TableName() string

type ExternalInformation added in v0.0.3

type ExternalInformation struct {
	Github   ExternalInformationItem `json:"github"`
	Weibo    ExternalInformationItem `json:"weibo"`
	Bilibili ExternalInformationItem `json:"bilibili"`
	Twitter  ExternalInformationItem `json:"twitter"`
	LinkedIn ExternalInformationItem `json:"linkedIn"`
	Zhihu    ExternalInformationItem `json:"zhihu"`
}

type ExternalInformationItem added in v0.0.3

type ExternalInformationItem struct {
	Link string `json:"link"`
}

type PageQuery

type PageQuery struct {
	Page, PageSize int
	Username       string
	UserId         uint64
	Email          string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL