Documentation ¶
Overview ¶
Package biz ...
- @Author: windealli windealli@tencent.com
- @Date: 2023-03-10 11:37:13
- @LastEditors: windealli windealli@tencent.com
- @LastEditTime: 2023-03-20 15:30:03
- @FilePath: /kratos-layout/internal/biz/greeter.go
- @Description:
Package biz ...
- @file: login.go 实现了登录态相关的业务逻辑
- @Description: 如果系统不需要登录态,可以删除这个文件, 以及相关的依赖,比如biz.go中的相关依赖
- @Author: windealli
Index ¶
Constants ¶
View Source
const SessionInfoKey = "x-ssv-session-info-key"
Variables ¶
View Source
var ( // ErrUserNotFound is user not found. ErrUserNotFound = errors.NotFound(v1.ErrorReason_USER_NOT_FOUND.String(), "user not found") )
View Source
var ProviderSet = wire.NewSet(NewGreeterUsecase, NewLoginUsecase)
ProviderSet is biz providers.
Functions ¶
This section is empty.
Types ¶
type GreeterRepo ¶
type GreeterRepo interface { Save(context.Context, *Greeter) (*Greeter, error) Update(context.Context, *Greeter) (*Greeter, error) FindByID(context.Context, int64) (*Greeter, error) ListByHello(context.Context, string) ([]*Greeter, error) ListAll(context.Context) ([]*Greeter, error) }
GreeterRepo is a Greater repo.
type GreeterUsecase ¶
type GreeterUsecase struct {
// contains filtered or unexported fields
}
GreeterUsecase is a Greeter usecase.
func NewGreeterUsecase ¶
func NewGreeterUsecase(repo GreeterRepo, logger log.Logger) *GreeterUsecase
NewGreeterUsecase new a Greeter usecase.
type LoginRepo ¶ added in v0.1.1
type LoginRepo interface { Save(ctx context.Context, info *SessionInfo) error Find(ctx context.Context, info *SessionInfo) error }
LoginRepo :
type LoginUsecase ¶ added in v0.1.1
type LoginUsecase struct {
// contains filtered or unexported fields
}
LoginUsecase :
func NewLoginUsecase ¶ added in v0.1.1
func NewLoginUsecase(repo LoginRepo, logger log.Logger, bc *conf.BusinessConfig) *LoginUsecase
NewLoginUsecase new a Greeter usecase.
func (*LoginUsecase) BusinessAuthCheck ¶ added in v0.1.1
func (uc *LoginUsecase) BusinessAuthCheck() middleware.Middleware
BusinessAuthCheck : 会话登录态中间件
func (*LoginUsecase) GetSessionInfo ¶ added in v0.1.1
func (uc *LoginUsecase) GetSessionInfo(ctx context.Context) (*SessionInfo, error)
getSessionInfo : 获取登录态信息
func (*LoginUsecase) Login ¶ added in v0.1.1
func (uc *LoginUsecase) Login(ctx context.Context, info *SessionInfo) error
Login 实现了登录态的生成逻辑
- 对于PC端 Web站点,Login一般只需要调用一次, 入参info填充BusinessSessioninfo
- 对于微信生态的小程序或者公众号网页,需要调用两次。 第一次即微信侧的登录,获取微信相关的用户信息,如openid、unionid等,然后调用Login接口,填充info.WxSessionInfo 第二次调用是业务侧的调用,可能是通过手机号或者其他的方式登录,同时,登录态中可能包含业务的信息(比如用户当前切换的租户、村庄等)。 填充info.BusinessSessioninfo
func (*LoginUsecase) WxAuthCheck ¶ added in v0.1.1
func (uc *LoginUsecase) WxAuthCheck() middleware.Middleware
WxAuthCheck : 微信会话登录态中间件
type SessionBase ¶ added in v0.1.1
type SessionBase struct { ID string // 业务登录态标识, biz/login.go中闭环管理,这个标识会在Cookie或者JWT-Token中返回给前端 ExpiresAt time.Time // 业务登录态过期时间,biz/login.go中闭环管理 }
SessionBase : 登录态基础信息,与业务无关,不对外开放, 仅用于内部管理
type SessionInfo ¶ added in v0.1.1
type SessionInfo struct { SessionBase WxSessionInfo *WxSessionInfo // 微信会话态信息,如用户的openid、unionid等, 如果是PC端Web站点,则不需要 BusinessSessionInfo interface{} // 此处填充业务相关的信息,如用户的角色、权限等 }
SessionInfo 描述登录态相关的信息
func GetSessionInfo ¶ added in v0.1.1
func GetSessionInfo(ctx context.Context) (*SessionInfo, error)
GetSessionInfo : 从上下文中获取登录态信息
func (*SessionInfo) GetExpiresAt ¶ added in v0.1.1
func (li *SessionInfo) GetExpiresAt() time.Time
GetExpiresAt : 获取SessionInfo的expiresAt
func (*SessionInfo) GetID ¶ added in v0.1.1
func (li *SessionInfo) GetID() string
GetID : 获取SessionInfo的id
Click to show internal directories.
Click to hide internal directories.