user

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const UserKey = "user"

Variables

This section is empty.

Functions

func NewUserService

func NewUserService(params ...interface{}) (interface{}, error)

Types

type Service

type Service interface {

	// Register 注册用户,注意这里只是将用户注册, 并没有激活, 需要调用
	// 参数:user必填,username,password, email
	// 返回值: user 带上token
	Register(ctx context.Context, user *User) (*User, error)
	// SendRegisterMail 发送注册的邮件
	// 参数:user必填: username, password, email, token
	SendRegisterMail(ctx context.Context, user *User) error
	// VerifyRegister 注册用户,验证注册信息, 返回验证是否成功
	VerifyRegister(ctx context.Context, captcha string) error

	// Login 登录相关,使用用户名密码登录,获取完成User信息
	Login(ctx context.Context, user *User) (*User, error)

	// GetUser 获取用户信息
	GetUser(ctx context.Context, userID uint) (*User, error)

	// GetLoginUser 获取登录的用户信息
	GetLoginUser(ctx context.Context) (*User, error)
}

type User

type User struct {
	gorm.Model
	UserName  string    `gorm:"column:username"`
	Password  string    `gorm:"column:password"`
	Email     string    `gorm:"column:email"`
	CreatedAt time.Time `gorm:"column:created_at"`

	Captcha string `gorm:"-"` // 注册验证码
	Token   string `gorm:"-"` // 用户token
}

User 代表一个用户,注意这里的用户信息字段在不同接口和参数可能为空

func (*User) MarshalBinary

func (b *User) MarshalBinary() ([]byte, error)

使用到缓存功能 需要实现BinaryMarshaler接口

func (*User) UnmarshalBinary

func (b *User) UnmarshalBinary(bt []byte) error

使用到缓存功能 需要实现 BinaryUnMarshaler接口

type UserProvider

type UserProvider struct {
	framework.ServiceProvider
}

func (*UserProvider) Boot

func (sp *UserProvider) Boot(c framework.Container) error

func (*UserProvider) IsDefer

func (sp *UserProvider) IsDefer() bool

func (*UserProvider) Name

func (sp *UserProvider) Name() string

func (*UserProvider) Params

func (sp *UserProvider) Params(c framework.Container) []interface{}

func (*UserProvider) Register

type UserService

type UserService struct {
	Service
	// contains filtered or unexported fields
}

func (*UserService) GetLoginUser

func (u *UserService) GetLoginUser(ctx context.Context) (*User, error)

func (*UserService) GetUser

func (u *UserService) GetUser(ctx context.Context, userID uint) (*User, error)

func (*UserService) Login

func (u *UserService) Login(ctx context.Context, user *User) (*User, error)

func (*UserService) Register

func (u *UserService) Register(ctx context.Context, user *User) (*User, error)

func (*UserService) SendRegisterMail

func (u *UserService) SendRegisterMail(ctx context.Context, user *User) error

func (*UserService) VerifyRegister

func (u *UserService) VerifyRegister(ctx context.Context, captcha string) error

Jump to

Keyboard shortcuts

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