service

package
v0.0.0-...-2c6e621 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2021 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUserExists 需要注册的用户已经存在了
	ErrUserExists = gm.NewError(http.StatusConflict, 40101, "email exists")
	// ErrUserSignIn 用户名或密码错误
	ErrUserSignIn = gm.NewError(http.StatusBadRequest, 40102, "username or password incorrect")
	// ErrOauth2Source 未知的 oauth2 认证源
	ErrOauth2Source = gm.NewError(http.StatusBadRequest, 40103, "unknown oauth2 source")
	// ErrOauth2State oauth2 state 校验失败
	ErrOauth2State = gm.NewError(http.StatusBadRequest, 40104, "incorrect state")
	// ErrActive 无效或已过期的激活链接
	ErrActive = gm.NewError(http.StatusBadRequest, 40105, "invalid or expired active link")
	// ErrOldPassword 老密码错误
	ErrOldPassword = gm.NewError(http.StatusBadRequest, 40106, "invalid password")
	// ErrResetPassword 重置密码错误
	ErrResetPassword = gm.NewError(http.StatusBadRequest, 40107, "reset password")
	// ErrOauth2ExchangeCode 获取 access token err
	ErrOauth2ExchangeCode = gm.NewError(http.StatusServiceUnavailable, 60101, "oauth2 exchange code")
	// ErrGetOauth2User 获取 oauth2 用户信息
	ErrGetOauth2User = gm.NewError(http.StatusServiceUnavailable, 60102, "get oauth2 user info")
)

Functions

This section is empty.

Types

type Token

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

Token srv

func (*Token) GetToken

func (t *Token) GetToken(source string, id int64, conf *oauth2.Config) (*oauth2.Token, error)

GetToken 获取 access token,自动刷新

func (*Token) SaveToken

func (t *Token) SaveToken(token *oauth2.Token, source string, id int64) error

SaveToken 保存到redis

type User

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

User 用户数据服务

func NewUser

func NewUser(opt *UserOption) *User

NewUser 返回数据服务实例

func (*User) Active

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

Active 注册激活

func (*User) ChangePassword

func (u *User) ChangePassword(_ context.Context, email, oldPass, newPass string) *gm.Error

ChangePassword 更新密码

func (*User) ResetPassword

func (u *User) ResetPassword(ctx context.Context, password, token string) *gm.Error

ResetPassword 重置密码

func (*User) SendMail

func (u *User) SendMail(ctx context.Context, email, emailType, url string) error

SendMail 发送注册激活、重置密码邮件

func (*User) SignIn

func (u *User) SignIn(_ context.Context, user *model.User) (*model.User, *gm.Error)

SignIn 用户登录

func (*User) SignInByOauth2

func (u *User) SignInByOauth2(ctx context.Context, source, code string) (*model.User, *gm.Error)

SignInByOauth2 oauth2 登录

func (*User) SignUp

func (u *User) SignUp(ctx context.Context, url string, user *model.User) *gm.Error

SignUp 注册用户 oauth2 登录的用户如果没有注册过会自动生成一个没有密码用户,用户后面可通过应用内重置密码的方式设置密码

type UserOption

type UserOption struct {
	DB         *gorm.DB
	RDB        *redis.Client
	Oauth2Conf map[string]*oauth2.Config
	Ma         *mailer.Mailer
	AesKey     string
}

UserOption config for user

Jump to

Keyboard shortcuts

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