model

package
v0.0.0-...-63192da Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	REGISTER_TICKET_EXP = time.Minute * 5
	RESETPWD_TICKET_EXP = time.Minute * 6
	VERIFY_CODE_EXP     = time.Minute * 3
	// This is not login token expire time, this is login ticket expire time
	LOGIN_TICKET_EXP = time.Minute * 5
	// This is login token expire time
	LOGIN_TOKEN_EXP = time.Hour * 24 * 7
	// Login token key in redis
	LOGIN_TOKEN_IN_REDIS = "LOGIN"

	// For JWT
	LOGIN_TOKEN_SUB     = "loginToken"
	LOGIN_TICKET_SUB    = "loginTicket"
	REGIST_TICKET_SUB   = "registerTicket"
	RESETPWD_TICKET_SUB = "resetPwdTicket"
)
View Source
const VerifyCodeTemplate = `` /* 3238-byte string literal not displayed */

Variables

View Source
var (
	Db  *gorm.DB
	Rdb *redis.Client

	RedisCtx = context.Background()
)
View Source
var (
	VERIFY_STATUS = map[string]string{
		"VERIFY_ACCOUNT": "0",
		"SEND_EMAIL":     "1",
		"VERIFY_CAPTCHA": "2",
		"SUCCESS":        "3",
	}
)

Functions

func ChangePassword

func ChangePassword(uid string, password string) error

func CheckAuth

func CheckAuth(username, password string) bool

func CheckPassword

func CheckPassword(username string, password string) (string, error)

func CreateUserAndProfile

func CreateUserAndProfile(user *User, profile *Profile) error

func GenerateVerifyCode

func GenerateVerifyCode() string

func GetDepAndOrgByOrgId

func GetDepAndOrgByOrgId(orgId int) (string, string, error)

func InsertCode

func InsertCode(code string) string

func LoginJWTSubKey

func LoginJWTSubKey(username string) string

func LoginTicketJWTSubKey

func LoginTicketJWTSubKey(username string) string

func LoginTicketKey

func LoginTicketKey(username string) string

func LoginTokenKey

func LoginTokenKey(username string) string

func RegisterJWTSubKey

func RegisterJWTSubKey(username string) string

func RegisterTicketKey

func RegisterTicketKey(ticket string) string

func ResetPwdJWTSubKey

func ResetPwdJWTSubKey(username string) string

func SendEmail

func SendEmail(recipient, content, title string) error

func UpdateAvatar

func UpdateAvatar(avatar string, userId uint) error

func UpdateGithubId

func UpdateGithubId(username string, githubId string) error

Add github id to user

func UpdateProfile

func UpdateProfile(oldProfile, newProfile *Profile) error

func VerifyCodeKey

func VerifyCodeKey(username string) string

Types

type Auth

type Auth struct {
	ID       int    `gorm:"primary_key" json:"id"`
	Username string `json:"username"`
	Password string `json:"password"`
}

type CheckRes

type CheckRes struct {
	Code int `json:"code"`
	Data struct {
		ForbiddenStatus int    `json:"forbidden_status"`
		Event           string `json:"event"`
		Result          int    `json:"result"`
		TraceId         string `json:"trace_id"`
		Url             string `json:"url"`
	}
	Message string `json:"message"`
}

type Organize

type Organize struct {
	Id  uint   `json:"id" gorm:"primaryKey"`
	Dep string `json:"dep" gorm:"not null"`
	Org string `json:"org"`
}

type PostgresConf

type PostgresConf struct {
	Host     string
	Port     int
	Username string
	Password string
	Dbname   string
}

Postgres config

func GetPostgresConf

func GetPostgresConf() *PostgresConf

Get postgres config

type Profile

type Profile struct {
	ID        uint           `json:"id" gorm:"primaryKey"`
	UserID    *uint          `json:"user_id" gorm:"not null"`
	Nickname  *string        `json:"nickname" gorm:"not null"`
	Email     *string        `json:"email" gorm:"not null"`
	IsDeleted bool           `json:"is_deleted" gorm:"not null"`
	Avatar    *string        `json:"avatar" gorm:"not null"`
	OrgId     int            `json:"org_id"`
	Bio       *string        `json:"bio"`
	Link      pq.StringArray `json:"link" gorm:"type:varchar[]"`
	Badge     *badge         `json:"badge,omitempty" gorm:"type:json"`
	Hide      pq.StringArray `json:"hide,omitempty" gorm:"type:varchar(30)[]"`
}

func SelectProfileByUid

func SelectProfileByUid(uid string) (*Profile, error)

type RedisConf

type RedisConf struct {
	Host     string
	Port     int
	Addr     string
	Password string
	Db       int
	MaxIdle  int
}

Redis config

func GetRedisConf

func GetRedisConf() *RedisConf

Get redis config

type User

type User struct {
	ID        uint      `json:"id,omitempty" gorm:"primaryKey"`
	Uid       *string   `json:"uid,omitempty" gorm:"not null"`
	Email     *string   `json:"email,omitempty" gorm:"not null"`
	Password  *string   `json:"password,omitempty" gorm:"not null"`
	QQId      *string   `json:"qq_id,omitempty"`
	LarkId    *string   `json:"lark_id,omitempty"`
	GithubId  *string   `json:"github_id,omitempty"`
	WechatId  *string   `json:"wechat_id,omitempty"`
	CreatedAt time.Time `json:"created_at,omitempty" gorm:"not null"`
	IsDeleted bool      `json:"is_deleted,omitempty" gorm:"not null"`
}

func FindUserByGithubId

func FindUserByGithubId(githubId string) (*User, error)

Find user by github id Use it need to check if the user is nil Since the RecordNotFound error is nil

func GetUserByEmail

func GetUserByEmail(email string) (*User, error)

GetUserByEmail find user by email

func GetUserByUid

func GetUserByUid(uid string) (*User, error)

CheckUserByUid find user by uid return true if user exist

func UserInfo

func UserInfo(username string) (*User, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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