db

package
v0.0.0-...-f123b97 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2021 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBadCredential = errors.New("电子邮箱或密码错误")
View Source
var ErrServiceExists = errors.New("服务已存在")
View Source
var ErrUserNotFound = errors.New("用户不存在")
View Source
var ErrorServiceNotFound = errors.New("服务不存在")

Functions

func ConnDB

func ConnDB() error

func ConnRedis

func ConnRedis() error

func CountServices

func CountServices() int64

CountServices 返回服务的总数。

func CountUsers

func CountUsers() int64

CountUsers 返回用户的总数

func CreateService

func CreateService(s *Service) error

CreateService 新建一个新的服务。

func CreateUser

func CreateUser(u *User) error

CreateUser 新建一个新的用户。

func DeleteService

func DeleteService(id uint) error

DeleteService 根据指定 Service ID 删除对应的服务。

func GetSetting

func GetSetting(key string, defaultValue ...string) (string, error)

func GetUserSalt

func GetUserSalt() string

GetUserSalt 返回随机字符串作为用户的盐。

func IsEmailUsed

func IsEmailUsed(email string) bool

IsEmailUsed 检查邮箱是否重复。

func IsErrEmailAlreadyUsed

func IsErrEmailAlreadyUsed(err error) bool

func IsErrNameNotAllowed

func IsErrNameNotAllowed(err error) bool

func IsErrUserAlreadyExist

func IsErrUserAlreadyExist(err error) bool

func IsServiceExist

func IsServiceExist(name string) bool

IsServiceExist 检查服务名是否重复。

func IsUserExist

func IsUserExist(name string) bool

IsUserExist 检查用户昵称是否重复。

func MustGetSetting

func MustGetSetting(key string, defaultValue ...string) string

func NewServiceTicket

func NewServiceTicket(service *Service, user *User) (string, error)

NewServiceTicket 生成一个 Ticket。

func SetSetting

func SetSetting(key, value string) error

func UpdateService

func UpdateService(s *Service) error

UpdateService 更新一个服务。

func UpdateUserProfile

func UpdateUserProfile(u *User) error

UpdateUserProfile 修改用户信息。

func ValidateTicket

func ValidateTicket(ticket string) (*User, *Service, bool)

ValidateTicket 验证 Ticket 是否正确。

Types

type ErrEmailAlreadyUsed

type ErrEmailAlreadyUsed struct {
	// contains filtered or unexported fields
}

func (ErrEmailAlreadyUsed) Error

func (err ErrEmailAlreadyUsed) Error() string

type ErrNameNotAllowed

type ErrNameNotAllowed struct {
	// contains filtered or unexported fields
}

func (ErrNameNotAllowed) Error

func (err ErrNameNotAllowed) Error() string

type ErrUserAlreadyExist

type ErrUserAlreadyExist struct {
	// contains filtered or unexported fields
}

func (ErrUserAlreadyExist) Error

func (err ErrUserAlreadyExist) Error() string

type Service

type Service struct {
	gorm.Model

	Name   string
	Avatar string // 服务 Logo
	Domain string // 白名单域名
	Ban    bool   // 是否封禁
}

Service 为接入的服务。

func GetServiceByID

func GetServiceByID(id uint) (*Service, error)

GetServiceByID 根据对应的 ServiceID 查找对应的服务。

func GetServices

func GetServices(options ...int) ([]*Service, error)

GetServices 批量获取服务。 options[0] offset options[1] limit

func ServiceByURL

func ServiceByURL(u string) (*Service, error)

ServiceByURL 通过 ServiceURL 查找对应的服务。

type Setting

type Setting struct {
	gorm.Model

	Key   string
	Value string
}

Setting 为应用设置

type User

type User struct {
	gorm.Model

	NickName string
	Email    string
	Password string
	Salt     string
	Avatar   string

	IsActive bool
	IsAdmin  bool
}

User 为用户表。

func GetUserByEmail

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

GetUserByEmail 根据给定的电子邮箱地址查询对应的用户。

func GetUserByNickName

func GetUserByNickName(nickName string) (*User, error)

GetUserByNickName 根据给定的用户昵称查询对应的用户。

func GetUsers

func GetUsers(options ...int) []*User

GetUsers 批量获取用户 options[0] offset options[1] limit

func MustGetUserByID

func MustGetUserByID(uid uint) *User

MustGetUserByID 根据传入的用户 ID 查询对应的用户。

func UserAuthenticate

func UserAuthenticate(email string, password string) (*User, error)

UserAuthenticate 验证用户传入的用户名与密码。

func ValidateServiceTicket

func ValidateServiceTicket(service *Service, ticket string) (*User, bool)

ValidateServiceTicket 验证 Ticket 是否正确。

func VerifyUserActiveCode

func VerifyUserActiveCode(code string) *User

VerifyUserActiveCode 检查用户输入的账号激活码是否有效。

func (*User) EncodePassword

func (u *User) EncodePassword()

EncodePassword 对密码进行加盐处理。

func (*User) GetActivationCode

func (u *User) GetActivationCode() string

GetActivationCode 返回用户账号激活码,有效期两小时。

func (*User) ValidatePassword

func (u *User) ValidatePassword(password string) bool

ValidatePassword 检查输入的密码是否正确。

Jump to

Keyboard shortcuts

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