model

package
v0.0.0-...-900783e Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type OAuthCredential

type OAuthCredential struct {
	gorm.Model
	UserID     uint   `gorm:"index;not null"`
	User       User   `gorm:"foreignKey:UserID;references:ID"`
	Provider   string `gorm:"not null"` // local, google, facebook, twitter, wechat
	ProviderID string `gorm:"index"`
}

type RegisterParams

type RegisterParams struct {
	Username string `json:"username"`
	Email    string `json:"email"`
	Password string `json:"password"`
}

RegisterParams 定义注册参数结构体

type Repo

type Repo struct {
	DB *gorm.DB
}

Repo 提供用户注册的服务

func NewRepo

func NewRepo(db *gorm.DB) *Repo

NewRepo 创建一个新的RegisterService实例

func (*Repo) FindUserByName

func (repo *Repo) FindUserByName(username string) (*User, error)

FindUserByName 用过名字找到一个新用户

func (*Repo) Register

func (repo *Repo) Register(ctx context.Context, params RegisterParams) (*User, error)

Register 创建一个新用户

type TwoFactorSetting

type TwoFactorSetting struct {
	gorm.Model
	IsEnabled      bool
	Phone          string
	SecondaryEmail string
	BackupCodes    string // JSON array of backup codes
}

type User

type User struct {
	gorm.Model          // Includes ID, CreatedAt, UpdatedAt, DeletedAt fields
	Username     string `gorm:"uniqueIndex;not null"`
	Email        string `gorm:"uniqueIndex;not null"`
	PasswordHash string `gorm:"not null"`
	TwoFactorID  uint   `gorm:"column:two_factor_setting_id"` // Reference to two-factor settings
}

User 定义了用户账号管理模块的模型

func (*User) BeforeCreate

func (u *User) BeforeCreate(tx *gorm.DB) (err error)

BeforeCreate 是Gorm的hook,在创建记录前调用

func (*User) BeforeUpdate

func (u *User) BeforeUpdate(tx *gorm.DB) (err error)

BeforeUpdate 是Gorm的hook,在更新记录前调用

Jump to

Keyboard shortcuts

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