Documentation ¶
Index ¶
- func NewVerifyCode(n int) string
- type AuthHandler
- func (a *AuthHandler) EncryptPassword(s string) string
- func (a *AuthHandler) LoginWithPassword(ctx context.Context, option auth.LoginOption) (*auth.TokenPair, error)
- func (a *AuthHandler) RegisterNewUser(ctx context.Context, option auth.RegisterOption) (*ent.User, error)
- func (a *AuthHandler) ResetPassword(ctx context.Context, option auth.ResetPasswordOption) error
- type TokenHandler
- func (t *TokenHandler) Issue(ctx context.Context, payload auth.TokenPayload, refresh bool) (auth.TokenPair, error)
- func (t *TokenHandler) Refresh(ctx context.Context, accessToken string, refreshToken string) (auth.TokenPair, error)
- func (t *TokenHandler) VerifyAccess(ctx context.Context, token string, now time.Time) (auth.Token, error)
- func (t *TokenHandler) VerifyRefresh(ctx context.Context, token string) (auth.Token, error)
- type VerifyCodeHandler
- func (v *VerifyCodeHandler) CheckVerifyCode(ctx context.Context, to, code string, usage auth.Usage) error
- func (v *VerifyCodeHandler) RemoveVerifyCode(ctx context.Context, code string, usage auth.Usage) error
- func (v *VerifyCodeHandler) SendVerifyCodeEmail(ctx context.Context, to string, usage auth.Usage) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewVerifyCode ¶
NewVerifyCode returns a verification code with specified length. the bigger n is, the conflicts will be less, the recommended n is 8.
Types ¶
type AuthHandler ¶
type AuthHandler struct {
// contains filtered or unexported fields
}
AuthHandler is responsible for user authentication
func NewAuthHandler ¶
func NewAuthHandler(userRepo *repo.UserRepo, tokenHandler *TokenHandler, verify *VerifyCodeHandler) *AuthHandler
func (*AuthHandler) EncryptPassword ¶
func (a *AuthHandler) EncryptPassword(s string) string
EncryptPassword encrypts password with sha512
func (*AuthHandler) LoginWithPassword ¶
func (a *AuthHandler) LoginWithPassword(ctx context.Context, option auth.LoginOption) (*auth.TokenPair, error)
LoginWithPassword user login by password
func (*AuthHandler) RegisterNewUser ¶
func (a *AuthHandler) RegisterNewUser(ctx context.Context, option auth.RegisterOption) (*ent.User, error)
RegisterNewUser registers new user and returns it
func (*AuthHandler) ResetPassword ¶
func (a *AuthHandler) ResetPassword(ctx context.Context, option auth.ResetPasswordOption) error
ResetPassword resets specified user password and returns uid
type TokenHandler ¶
TokenHandler is responsible for maintaining authentication tokens
func NewTokenHandler ¶
func NewTokenHandler(jwtConf conf.Jwt, client *redis.Client) *TokenHandler
func (*TokenHandler) Issue ¶
func (t *TokenHandler) Issue(ctx context.Context, payload auth.TokenPayload, refresh bool) (auth.TokenPair, error)
func (*TokenHandler) Refresh ¶
func (t *TokenHandler) Refresh(ctx context.Context, accessToken string, refreshToken string) (auth.TokenPair, error)
Refresh refreshes the access token lifetime with the given refresh token
func (*TokenHandler) VerifyAccess ¶
func (t *TokenHandler) VerifyAccess(ctx context.Context, token string, now time.Time) (auth.Token, error)
VerifyAccess verifies the access token if is valid and parses the payload in the token.
func (*TokenHandler) VerifyRefresh ¶
VerifyRefresh verifies the refresh token if is valid.
type VerifyCodeHandler ¶
type VerifyCodeHandler struct {
// contains filtered or unexported fields
}
func NewVerifyCodeHandler ¶
func NewVerifyCodeHandler(codeCache cache.VerifyCodeCache, sender *email.Handler) *VerifyCodeHandler
func (*VerifyCodeHandler) CheckVerifyCode ¶
func (v *VerifyCodeHandler) CheckVerifyCode(ctx context.Context, to, code string, usage auth.Usage) error
CheckVerifyCode check verify code if is valid
func (*VerifyCodeHandler) RemoveVerifyCode ¶
func (*VerifyCodeHandler) SendVerifyCodeEmail ¶
func (v *VerifyCodeHandler) SendVerifyCodeEmail(ctx context.Context, to string, usage auth.Usage) error
SendVerifyCodeEmail send a verify code email to the specified address