feat: user logout
CI / changes (push) Successful in 1m30s
CI / ad (push) Successful in 0s
CI / admin (push) Successful in 0s
CI / aiserver (push) Successful in 0s
CI / analysis (push) Successful in 35s
CI / bff (push) Successful in 19s
CI / chore (push) Successful in 1s
CI / equipment (push) Successful in 0s
CI / express (push) Successful in 0s
CI / factory (push) Successful in 0s
CI / message (push) Successful in 0s
CI / order (push) Successful in 0s
CI / payment (push) Successful in 0s
CI / percutaneous (push) Successful in 1s
CI / product (push) Successful in 0s
CI / record (push) Successful in 1s
CI / sale (push) Successful in 0s
CI / store (push) Successful in 0s
CI / support (push) Successful in 0s
CI / task (push) Successful in 0s
CI / user (push) Successful in 24s
CI / water (push) Successful in 0s
CI / wecom (push) Successful in 0s
CI / ws (push) Successful in 0s
CI / changes (push) Successful in 1m30s
CI / ad (push) Successful in 0s
CI / admin (push) Successful in 0s
CI / aiserver (push) Successful in 0s
CI / analysis (push) Successful in 35s
CI / bff (push) Successful in 19s
CI / chore (push) Successful in 1s
CI / equipment (push) Successful in 0s
CI / express (push) Successful in 0s
CI / factory (push) Successful in 0s
CI / message (push) Successful in 0s
CI / order (push) Successful in 0s
CI / payment (push) Successful in 0s
CI / percutaneous (push) Successful in 1s
CI / product (push) Successful in 0s
CI / record (push) Successful in 1s
CI / sale (push) Successful in 0s
CI / store (push) Successful in 0s
CI / support (push) Successful in 0s
CI / task (push) Successful in 0s
CI / user (push) Successful in 24s
CI / water (push) Successful in 0s
CI / wecom (push) Successful in 0s
CI / ws (push) Successful in 0s
This commit is contained in:
@@ -67,9 +67,6 @@ func (l *UserStatusLogic) syncRegisteredFromUser(bizId, userId int64, isRegister
|
||||
if isRegistered != uint8(utils.StatusFail) {
|
||||
return isRegistered
|
||||
}
|
||||
if userId < utils.NumberOne || l.svcCtx.UserSvcName == utils.StringEmpty {
|
||||
return isRegistered
|
||||
}
|
||||
|
||||
cli, err := svc.GetRpcClient(l.svcCtx.UserSvcName)
|
||||
if err != nil {
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"lone-services/pkg/redis"
|
||||
"lone-services/pkg/utils"
|
||||
user "lone-services/rpc/user/pb"
|
||||
"lone-services/services/user/internal/dao"
|
||||
"lone-services/services/user/internal/svc"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type LogoutLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewLogoutLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LogoutLogic {
|
||||
return &LogoutLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *LogoutLogic) Logout(in *user.LogoutReq) (*user.Response, error) {
|
||||
loginUser := utils.GetUserFromCtx(l.ctx)
|
||||
if loginUser.ID < utils.NumberOne {
|
||||
return failResponse(utils.ErrorNoLoginInfo), nil
|
||||
}
|
||||
|
||||
loginType, typeErr := resolveLoginCacheType(loginUser)
|
||||
if typeErr != nil {
|
||||
l.Errorf("logout resolve login type: %v", typeErr)
|
||||
return failResponse(utils.Fail), nil
|
||||
}
|
||||
if loginType == utils.StringEmpty {
|
||||
return outResponse(utils.ErrorParams, "无法识别登录类型"), nil
|
||||
}
|
||||
|
||||
redisKeysKey := utils.GetLoginKeysKey(loginType, strconv.FormatInt(loginUser.ID, utils.NumberTen))
|
||||
oldAuth, oldErr := redis.Client.Get(l.ctx, redisKeysKey).Result()
|
||||
if oldErr != nil {
|
||||
return failResponse(utils.ErrorNoLoginInfo), nil
|
||||
}
|
||||
|
||||
var loginInfo utils.LoginRedis
|
||||
if err := jsoniter.Unmarshal([]byte(oldAuth), &loginInfo); err != nil {
|
||||
return failResponse(utils.ErrorNoLoginInfo), nil
|
||||
}
|
||||
|
||||
if len(loginInfo.Token) > utils.NumberOne {
|
||||
_ = redis.Client.Del(l.ctx, utils.GetLoginKey(loginType, loginInfo.Token)).Err()
|
||||
}
|
||||
if len(loginInfo.Refresh) > utils.NumberOne {
|
||||
_ = redis.Client.Del(l.ctx, utils.GetLoginRefreshKey(loginType, loginInfo.Refresh)).Err()
|
||||
}
|
||||
_ = redis.Client.Del(l.ctx, redisKeysKey).Err()
|
||||
|
||||
return okResponse(utils.NumberOne), nil
|
||||
}
|
||||
|
||||
func resolveLoginCacheType(loginUser utils.UserInfo) (string, error) {
|
||||
if loginUser.ClientCode != utils.StringEmpty {
|
||||
client, err := loadEnabledClient(loginUser.ClientCode)
|
||||
if err != nil {
|
||||
return utils.StringEmpty, err
|
||||
}
|
||||
return loginCacheType(client), nil
|
||||
}
|
||||
|
||||
switch loginUser.Type {
|
||||
case dao.TypeSale:
|
||||
return utils.LoginTypeSale, nil
|
||||
case dao.TypeStore:
|
||||
return utils.LoginTypeStore, nil
|
||||
case dao.TypeUser:
|
||||
return utils.LoginTypeUser, nil
|
||||
default:
|
||||
return utils.StringEmpty, nil
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,11 @@ func (s *UserServer) Login(ctx context.Context, in *user.LoginReq) (*user.Respon
|
||||
return l.Login(in)
|
||||
}
|
||||
|
||||
func (s *UserServer) Logout(ctx context.Context, in *user.LogoutReq) (*user.Response, error) {
|
||||
l := logic.NewLogoutLogic(ctx, s.svcCtx)
|
||||
return l.Logout(in)
|
||||
}
|
||||
|
||||
func (s *UserServer) GenerateQrcode(ctx context.Context, in *user.GenerateQrcodeReq) (*user.Response, error) {
|
||||
l := logic.NewGenerateQrcodeLogic(ctx, s.svcCtx)
|
||||
return l.GenerateQrcode(in)
|
||||
|
||||
@@ -46,6 +46,7 @@ type (
|
||||
InternalVerifyPasswordData = user.InternalVerifyPasswordData
|
||||
InternalVerifyPasswordReq = user.InternalVerifyPasswordReq
|
||||
LoginReq = user.LoginReq
|
||||
LogoutReq = user.LogoutReq
|
||||
PasswordReq = user.PasswordReq
|
||||
QrcodeLoginReq = user.QrcodeLoginReq
|
||||
QrcodeScanReq = user.QrcodeScanReq
|
||||
@@ -58,6 +59,7 @@ type (
|
||||
|
||||
User interface {
|
||||
Login(ctx context.Context, in *LoginReq, opts ...grpc.CallOption) (*Response, error)
|
||||
Logout(ctx context.Context, in *LogoutReq, opts ...grpc.CallOption) (*Response, error)
|
||||
GenerateQrcode(ctx context.Context, in *GenerateQrcodeReq, opts ...grpc.CallOption) (*Response, error)
|
||||
QrcodeScan(ctx context.Context, in *QrcodeScanReq, opts ...grpc.CallOption) (*Response, error)
|
||||
QrcodeLogin(ctx context.Context, in *QrcodeLoginReq, opts ...grpc.CallOption) (*Response, error)
|
||||
@@ -100,6 +102,11 @@ func (m *defaultUser) Login(ctx context.Context, in *LoginReq, opts ...grpc.Call
|
||||
return client.Login(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultUser) Logout(ctx context.Context, in *LogoutReq, opts ...grpc.CallOption) (*Response, error) {
|
||||
client := user.NewUserClient(m.cli.Conn())
|
||||
return client.Logout(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultUser) GenerateQrcode(ctx context.Context, in *GenerateQrcodeReq, opts ...grpc.CallOption) (*Response, error) {
|
||||
client := user.NewUserClient(m.cli.Conn())
|
||||
return client.GenerateQrcode(ctx, in, opts...)
|
||||
|
||||
Reference in New Issue
Block a user