Files
lone-services/services/analysis/internal/logic/analysisstore/storeAuthLogic.go
T
zzw 46d3f672bf
CI / changes (push) Successful in 1m30s
CI / ad (push) Successful in 31s
CI / admin (push) Successful in 24s
CI / bff (push) Successful in 31s
CI / chore (push) Successful in 27s
CI / equipment (push) Successful in 21s
CI / express (push) Successful in 23s
CI / factory (push) Successful in 21s
CI / message (push) Successful in 21s
CI / order (push) Successful in 22s
CI / payment (push) Successful in 20s
CI / percutaneous (push) Successful in 20s
CI / product (push) Successful in 20s
CI / record (push) Successful in 19s
CI / sale (push) Successful in 19s
CI / support (push) Successful in 20s
CI / task (push) Successful in 19s
CI / user (push) Successful in 21s
CI / wecom (push) Successful in 22s
feat: device info and bind
2026-10-16 15:36:17 +08:00

88 lines
2.5 KiB
Go

package analysisstorelogic
import (
"context"
"lone-services/pkg/utils"
"lone-services/pkg/validate"
analysis "lone-services/rpc/analysis/pb"
userpb "lone-services/rpc/user/pb"
"lone-services/services/analysis/internal/dao"
"lone-services/services/analysis/internal/logic/common"
"lone-services/services/analysis/internal/svc"
"lone-services/services/analysis/validator"
"github.com/zeromicro/go-zero/core/logx"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
type StoreAuthLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewStoreAuthLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StoreAuthLogic {
return &StoreAuthLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *StoreAuthLogic) StoreAuth(in *analysis.StoreAuthReq) (*analysis.Response, error) {
var req validator.StoreAuthValidator
if msg := validate.ValidateFromProto(in, &req); msg != utils.StringEmpty {
return common.OutResponse(utils.ErrorParams, msg), nil
}
storeId, _, fail := common.RequireStoreId(l.ctx)
if fail != nil {
return fail, nil
}
if l.svcCtx.UserSvcName == utils.StringEmpty {
return common.FailResponse(utils.Fail), nil
}
cli, err := svc.GetRpcClient(l.svcCtx.UserSvcName)
if err != nil {
l.Errorf("store auth get user rpc: %v", err)
return common.FailResponse(utils.Fail), nil
}
verified, err := userpb.NewUserClient(cli.Conn()).InternalVerifyPassword(l.ctx, &userpb.InternalVerifyPasswordReq{
Username: req.Username,
Password: req.Password,
SubjectType: "user",
ClientCode: dao.ClientCodeUserSkin,
})
if err != nil {
l.Errorf("store auth verify password: %v", err)
if st, ok := status.FromError(err); ok {
switch st.Code() {
case codes.NotFound:
return common.FailResponse(utils.ErrorNotFund), nil
case codes.InvalidArgument:
return common.FailResponse(utils.ErrorPwdError), nil
case codes.FailedPrecondition:
return common.OutResponse(utils.Fail, st.Message()), nil
}
}
return common.FailResponse(utils.Fail), nil
}
if verified == nil || verified.UserId < utils.NumberOne {
return common.FailResponse(utils.ErrorNotFund), nil
}
if verified.BizId < utils.NumberOne {
return common.OutResponse(utils.ErrorParams, "用户未开通"), nil
}
if err := common.BindStoreAuth(verified.BizId, storeId, req.ValidityTime); err != nil {
l.Errorf("store auth bind: %v", err)
return common.FailResponse(utils.Fail), nil
}
return common.OkResponse(map[string]int64{"user_id": verified.BizId}), nil
}