handler

package
v0.0.0-...-2668dd0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2022 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ActiveEmail = "active" // 用户激活邮件
	ResetEmail  = "reset"  // 用户重置密码邮件
)

Variables

View Source
var (
	// 400
	ErrUserExists     = ex.NewError(http.StatusConflict, 140001, "email exists")                         // 需要注册的用户已经存在了
	ErrUserSignIn     = ex.NewError(http.StatusUnauthorized, 140002, "username or password incorrect")   // 用户名或密码错误
	ErrActivation     = ex.NewError(http.StatusBadRequest, 140003, "invalid or expired activation link") // 无效或已过期的激活链接
	ErrChangePassword = ex.NewError(http.StatusBadRequest, 140004, "change password")                    // 修改密码参数错误
	ErrResetPassword  = ex.NewError(http.StatusBadRequest, 140005, "reset password")                     // 重置密码错误
	ErrOauth2Source   = ex.NewError(http.StatusBadRequest, 140006, "unknown oauth2 source")              // 未知的 oauth2 认证源
	ErrOauth2State    = ex.NewError(http.StatusBadRequest, 140007, "incorrect state")                    //  oauth2 state 校验失败

	// 500
	ErrSendEmail          = ex.NewError(http.StatusConflict, 150001, "send email")                     // ErrSendEmail 发送邮件
	ErrOauth2ExchangeCode = ex.NewError(http.StatusServiceUnavailable, 150002, "oauth2 exchange code") // 获取 access token err
	ErrGetOauth2User      = ex.NewError(http.StatusServiceUnavailable, 150003, "get oauth2 user info") // 获取 oauth2 用户信息
)

Functions

This section is empty.

Types

type Cacher

type Cacher interface {
	GetString(ctx context.Context, key string) (string, error)
	Set(ctx context.Context, key string, val any, ex time.Duration) error
	SetNX(ctx context.Context, key string, val any, ex time.Duration) (bool, error)
	Del(ctx context.Context, key string) (int64, error)
}

type Mailer

type Mailer interface {
	Send(to, subj, body string) error
}

type TokenRepo

type TokenRepo interface {
	SaveToken(ctx context.Context, token *oauth2.Token, source string, sourceID int64) error
	GetToken(ctx context.Context, source string, sourceID int64, fn repo.Refresher) (*oauth2.Token, error)
}

type User

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

func NewUserSrv

func NewUserSrv(ur UserRepo, tr TokenRepo, mailer Mailer, cacher Cacher, aesKey []byte) *User

func (*User) Active

func (u *User) Active(ctx context.Context, token string) error

Active 注册激活

func (*User) ChangePassword

func (u *User) ChangePassword(ctx context.Context, id int64, req *types.ChangePasswordReq) error

ChangePassword 更新密码

func (*User) Info

func (u *User) Info(ctx context.Context, id, sourceID int64, source string) (*types.User, error)

func (*User) ResetPassword

func (u *User) ResetPassword(ctx context.Context, req *types.ResetPasswordReq) error

ResetPassword 重置密码

func (*User) SendEmail

func (u *User) SendEmail(ctx context.Context, email, emailType, redirectURL string) error

SendEmail 发送邮件: 激活邮件, 重置密码邮件

func (*User) SignIn

func (u *User) SignIn(ctx context.Context, req *types.SignInReq) (*types.User, error)

SignIn 用户登录

func (*User) SignInByOauth2

func (u *User) SignInByOauth2(ctx context.Context, source, code string, auth oauth2x.Oauth2x) (*types.User, error)

SignInByOauth2 oauth2 登录

func (*User) SignUp

func (u *User) SignUp(ctx context.Context, req *types.SignUpReq) error

SignUp 用户注册

type UserRepo

type UserRepo interface {
	Create(ctx context.Context, u *model.User) (*model.User, error)
	Get(ctx context.Context, id int64, opt query.Opt) (*model.User, error)
	GetByEmail(ctx context.Context, email string, opt query.Opt) (*model.User, error)
	GetBySource(ctx context.Context, source string, sourceID int64, opt query.Opt) (*model.User, error)
	Update(ctx context.Context, id int64, params *model.UserParam) (int64, error)
	UpdateByEmail(ctx context.Context, email string, params *model.UserParam) (int64, error)
}

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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