serverdb

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: May 31, 2023 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const MaxExtendTimes = 31
View Source
const MaxTokenLifeSpan = 24 // in hours

Variables

This section is empty.

Functions

func ActiviateUser

func ActiviateUser(user_id uint) (int64, error)

func DeactivateUser

func DeactivateUser(user_id uint) (int64, error)

func GetDB

func GetDB() *gorm.DB

func GetUserIDByAccessToken

func GetUserIDByAccessToken(token string) (uint, error)

func GetUserIDByActivationToken

func GetUserIDByActivationToken(token string) (uint, error)

func InitServerDB

func InitServerDB(dialector string, connection_str string, verbose bool) (*gorm.DB, error)

Types

type AuthUser

type AuthUser struct {
	gorm.Model

	Username   string `gorm:"type:varchar(64); not null;" json:"username"`
	Hostname   string `gorm:"type:varchar(64); not null;" json:"hostname"`
	Email      string `gorm:"type:varchar(128); not null;uniqueIndex:uniq_user" json:"email"`
	DeviceInfo string `gorm:"type:varchar(255); not null;" json:"device_info"`

	Password   string `gorm:"type:varchar(255); not null;" json:"password"`
	IsActived  uint   `gorm:"not null; default:0;" json:"is_actived"`
	IsVerified uint   `gorm:"not null; default:0;" json:"is_verified"`

	RegisterAt   time.Time `gorm:"autoCreateTime" json:"register_at"`
	ExpiredAt    time.Time `gorm:"index" json:"expired_at"`
	ActivateAt   time.Time `json:"activate_at"`
	DeactivateAt time.Time `json:"deactivate_at"`
}

func GetValidUser

func GetValidUser(user_id uint) (*AuthUser, error)

func RegisterUser

func RegisterUser(user_info *model.UserInfo) (*AuthUser, error)

func (*AuthUser) Logout

func (user *AuthUser) Logout() error

func (*AuthUser) VerifyUser

func (user *AuthUser) VerifyUser() (*AuthUser, error)

type ProxyLog

type ProxyLog struct {
	ID                 uint      `gorm:"primary_key"`
	UserID             uint      `gorm:"not null"`          // user id
	RemoteAddr         string    `gorm:"type:varchar(255)"` // remote ip address
	RequestTime        time.Time `gorm:"not null"`          // 请求时间
	RequestMethod      string    `gorm:"not null"`          // 请求方法
	RequestURL         string    `gorm:"not null"`          // 请求URL
	RequestHeaders     string    `gorm:"type:text"`         // 请求头
	RequestBody        string    `gorm:"type:longtext"`     // 请求体
	ResponseStatusCode int       `gorm:"not null"`          // 响应状态码
	ResponseHeaders    string    `gorm:"type:text"`         // 响应头
	ResponseBody       string    `gorm:"type:longtext"`     // 响应体
	CreatedAt          time.Time `gorm:"autoCreateTime"`    // 创建时间
}

func (*ProxyLog) RecordRequest

func (plog *ProxyLog) RecordRequest() error

type UserToken

type UserToken struct {
	gorm.Model
	TokenType      string    `gorm:"type:varchar(64); not null;" json:"token_type"`
	Token          string    `gorm:"type:char(36); not null;" json:"token"`
	ExpiredAt      time.Time `gorm:"index" json:"expired_at"`
	UserID         uint      `json:"user_id"`
	ConsumeCounter uint      `gorm:"not null; default:0;" json:"consume_counter"`
}

func NewAccessToken

func NewAccessToken(user_id uint) (*UserToken, error)

func NewActiviationToken

func NewActiviationToken(user_id uint) (*UserToken, error)

func RefreshAccessToken

func RefreshAccessToken(token string) (*UserToken, error)

type WhiteList

type WhiteList struct {
	// AvailableUserMap map[string]time.Time
	AvailableUserMap map[string]WhiteListUser
	Mutex            *sync.RWMutex
}

///////////////////////////////////////////////////////////////////////////

func (*WhiteList) GetUserInfoByToken

func (w *WhiteList) GetUserInfoByToken(access_token string) *WhiteListUser

func (*WhiteList) IsAccessTokenValid

func (w *WhiteList) IsAccessTokenValid(access_token string) bool

func (*WhiteList) LoadWhiteList

func (w *WhiteList) LoadWhiteList(interval int64)

func (*WhiteList) RefreshToken

func (w *WhiteList) RefreshToken(old_access_token string) (string, error)

type WhiteListUser

type WhiteListUser struct {
	UserID    uint      `json:"user_id"`
	Token     string    `gorm:"size:512;not null;" json:"token"`
	ExpiredAt time.Time `gorm:"index" json:"expired_at"`
}

Jump to

Keyboard shortcuts

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