fix reesh api
This commit is contained in:
+15
-12
@@ -584,7 +584,7 @@ const file_proto_admin_proto_rawDesc = "" +
|
||||
"\x11AdminLoginRequest\x12\x1a\n" +
|
||||
"\busername\x18\x01 \x01(\tR\busername\x12\x1a\n" +
|
||||
"\bpassword\x18\x02 \x01(\tR\bpassword\"\x13\n" +
|
||||
"\x11AdminEmptyRequest2\xd7\x05\n" +
|
||||
"\x11AdminEmptyRequest2\xaa\x06\n" +
|
||||
"\x05Admin\x12V\n" +
|
||||
"\tAdminEdit\x12\x17.admin.AdminEditRequest\x1a\x0f.admin.Response\"\x1f\x82\xd3\xe4\x93\x02\x19:\x01*\"\x14/admin/v3/admin/edit\x12W\n" +
|
||||
"\vAdminStatus\x12\x14.admin.StatusRequest\x1a\x0f.admin.Response\"!\x82\xd3\xe4\x93\x02\x1b:\x01*\"\x16/admin/v3/admin/status\x12X\n" +
|
||||
@@ -595,7 +595,8 @@ const file_proto_admin_proto_rawDesc = "" +
|
||||
"AdminItems\x12\x18.admin.AdminItemsRequest\x1a\x0f.admin.Response\" \x82\xd3\xe4\x93\x02\x1a:\x01*\x12\x15/admin/v3/admin/items\x12S\n" +
|
||||
"\n" +
|
||||
"AdminLogin\x12\x18.admin.AdminLoginRequest\x1a\x0f.admin.Response\"\x1a\x82\xd3\xe4\x93\x02\x14:\x01*\"\x0f/admin/v3/login\x12W\n" +
|
||||
"\fAdminRefresh\x12\x18.admin.AdminEmptyRequest\x1a\x0f.admin.Response\"\x1c\x82\xd3\xe4\x93\x02\x16:\x01*\"\x11/admin/v3/refreshB\tZ\a./adminb\x06proto3"
|
||||
"\fAdminRefresh\x12\x18.admin.AdminEmptyRequest\x1a\x0f.admin.Response\"\x1c\x82\xd3\xe4\x93\x02\x16:\x01*\"\x11/admin/v3/refresh\x12Q\n" +
|
||||
"\tLoginInfo\x12\x18.admin.AdminEmptyRequest\x1a\x0f.admin.Response\"\x19\x82\xd3\xe4\x93\x02\x13:\x01*\"\x0e/admin/v3/infoB\tZ\a./adminb\x06proto3"
|
||||
|
||||
var (
|
||||
file_proto_admin_proto_rawDescOnce sync.Once
|
||||
@@ -630,16 +631,18 @@ var file_proto_admin_proto_depIdxs = []int32{
|
||||
6, // 5: admin.Admin.AdminItems:input_type -> admin.AdminItemsRequest
|
||||
7, // 6: admin.Admin.AdminLogin:input_type -> admin.AdminLoginRequest
|
||||
8, // 7: admin.Admin.AdminRefresh:input_type -> admin.AdminEmptyRequest
|
||||
2, // 8: admin.Admin.AdminEdit:output_type -> admin.Response
|
||||
2, // 9: admin.Admin.AdminStatus:output_type -> admin.Response
|
||||
2, // 10: admin.Admin.Password:output_type -> admin.Response
|
||||
2, // 11: admin.Admin.OwnPassword:output_type -> admin.Response
|
||||
2, // 12: admin.Admin.AdminInfo:output_type -> admin.Response
|
||||
2, // 13: admin.Admin.AdminItems:output_type -> admin.Response
|
||||
2, // 14: admin.Admin.AdminLogin:output_type -> admin.Response
|
||||
2, // 15: admin.Admin.AdminRefresh:output_type -> admin.Response
|
||||
8, // [8:16] is the sub-list for method output_type
|
||||
0, // [0:8] is the sub-list for method input_type
|
||||
8, // 8: admin.Admin.LoginInfo:input_type -> admin.AdminEmptyRequest
|
||||
2, // 9: admin.Admin.AdminEdit:output_type -> admin.Response
|
||||
2, // 10: admin.Admin.AdminStatus:output_type -> admin.Response
|
||||
2, // 11: admin.Admin.Password:output_type -> admin.Response
|
||||
2, // 12: admin.Admin.OwnPassword:output_type -> admin.Response
|
||||
2, // 13: admin.Admin.AdminInfo:output_type -> admin.Response
|
||||
2, // 14: admin.Admin.AdminItems:output_type -> admin.Response
|
||||
2, // 15: admin.Admin.AdminLogin:output_type -> admin.Response
|
||||
2, // 16: admin.Admin.AdminRefresh:output_type -> admin.Response
|
||||
2, // 17: admin.Admin.LoginInfo:output_type -> admin.Response
|
||||
9, // [9:18] is the sub-list for method output_type
|
||||
0, // [0:9] is the sub-list for method input_type
|
||||
0, // [0:0] is the sub-list for extension type_name
|
||||
0, // [0:0] is the sub-list for extension extendee
|
||||
0, // [0:0] is the sub-list for field type_name
|
||||
|
||||
@@ -27,6 +27,7 @@ const (
|
||||
Admin_AdminItems_FullMethodName = "/admin.Admin/AdminItems"
|
||||
Admin_AdminLogin_FullMethodName = "/admin.Admin/AdminLogin"
|
||||
Admin_AdminRefresh_FullMethodName = "/admin.Admin/AdminRefresh"
|
||||
Admin_LoginInfo_FullMethodName = "/admin.Admin/LoginInfo"
|
||||
)
|
||||
|
||||
// AdminClient is the client API for Admin service.
|
||||
@@ -41,6 +42,7 @@ type AdminClient interface {
|
||||
AdminItems(ctx context.Context, in *AdminItemsRequest, opts ...grpc.CallOption) (*Response, error)
|
||||
AdminLogin(ctx context.Context, in *AdminLoginRequest, opts ...grpc.CallOption) (*Response, error)
|
||||
AdminRefresh(ctx context.Context, in *AdminEmptyRequest, opts ...grpc.CallOption) (*Response, error)
|
||||
LoginInfo(ctx context.Context, in *AdminEmptyRequest, opts ...grpc.CallOption) (*Response, error)
|
||||
}
|
||||
|
||||
type adminClient struct {
|
||||
@@ -131,6 +133,16 @@ func (c *adminClient) AdminRefresh(ctx context.Context, in *AdminEmptyRequest, o
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *adminClient) LoginInfo(ctx context.Context, in *AdminEmptyRequest, opts ...grpc.CallOption) (*Response, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(Response)
|
||||
err := c.cc.Invoke(ctx, Admin_LoginInfo_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// AdminServer is the server API for Admin service.
|
||||
// All implementations must embed UnimplementedAdminServer
|
||||
// for forward compatibility.
|
||||
@@ -143,6 +155,7 @@ type AdminServer interface {
|
||||
AdminItems(context.Context, *AdminItemsRequest) (*Response, error)
|
||||
AdminLogin(context.Context, *AdminLoginRequest) (*Response, error)
|
||||
AdminRefresh(context.Context, *AdminEmptyRequest) (*Response, error)
|
||||
LoginInfo(context.Context, *AdminEmptyRequest) (*Response, error)
|
||||
mustEmbedUnimplementedAdminServer()
|
||||
}
|
||||
|
||||
@@ -177,6 +190,9 @@ func (UnimplementedAdminServer) AdminLogin(context.Context, *AdminLoginRequest)
|
||||
func (UnimplementedAdminServer) AdminRefresh(context.Context, *AdminEmptyRequest) (*Response, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method AdminRefresh not implemented")
|
||||
}
|
||||
func (UnimplementedAdminServer) LoginInfo(context.Context, *AdminEmptyRequest) (*Response, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method LoginInfo not implemented")
|
||||
}
|
||||
func (UnimplementedAdminServer) mustEmbedUnimplementedAdminServer() {}
|
||||
func (UnimplementedAdminServer) testEmbeddedByValue() {}
|
||||
|
||||
@@ -342,6 +358,24 @@ func _Admin_AdminRefresh_Handler(srv interface{}, ctx context.Context, dec func(
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Admin_LoginInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(AdminEmptyRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(AdminServer).LoginInfo(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: Admin_LoginInfo_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(AdminServer).LoginInfo(ctx, req.(*AdminEmptyRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// Admin_ServiceDesc is the grpc.ServiceDesc for Admin service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
@@ -381,6 +415,10 @@ var Admin_ServiceDesc = grpc.ServiceDesc{
|
||||
MethodName: "AdminRefresh",
|
||||
Handler: _Admin_AdminRefresh_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "LoginInfo",
|
||||
Handler: _Admin_LoginInfo_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "proto/admin.proto",
|
||||
|
||||
@@ -33,6 +33,7 @@ type (
|
||||
AdminItems(ctx context.Context, in *AdminItemsRequest, opts ...grpc.CallOption) (*Response, error)
|
||||
AdminLogin(ctx context.Context, in *AdminLoginRequest, opts ...grpc.CallOption) (*Response, error)
|
||||
AdminRefresh(ctx context.Context, in *AdminEmptyRequest, opts ...grpc.CallOption) (*Response, error)
|
||||
LoginInfo(ctx context.Context, in *AdminEmptyRequest, opts ...grpc.CallOption) (*Response, error)
|
||||
}
|
||||
|
||||
defaultAdmin struct {
|
||||
@@ -85,3 +86,8 @@ func (m *defaultAdmin) AdminRefresh(ctx context.Context, in *AdminEmptyRequest,
|
||||
client := admin.NewAdminClient(m.cli.Conn())
|
||||
return client.AdminRefresh(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultAdmin) LoginInfo(ctx context.Context, in *AdminEmptyRequest, opts ...grpc.CallOption) (*Response, error) {
|
||||
client := admin.NewAdminClient(m.cli.Conn())
|
||||
return client.LoginInfo(ctx, in, opts...)
|
||||
}
|
||||
|
||||
@@ -69,6 +69,8 @@ func (l *AdminRefreshLogic) AdminRefresh(in *admin.AdminEmptyRequest) (*admin.Re
|
||||
Token: utils.MD5Encrypt(id + utils.Now().String()),
|
||||
}
|
||||
retData.Refresh = utils.MD5Encrypt(id + retData.Token)
|
||||
//var info dao.JwtInfo
|
||||
//_ = jsoniter.Unmarshal(LoginInfo.Info, &info)
|
||||
|
||||
redisKey := utils.GetLoginKey(utils.LoginTypeAdmin, retData.Token)
|
||||
redis.Client.Set(ctx, redisKey, LoginInfo.Info, expire).Result()
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"admin/internal/dao"
|
||||
"admin/internal/model"
|
||||
"context"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"admin/admin"
|
||||
"admin/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"pkg.local/modelbase"
|
||||
"pkg.local/utils"
|
||||
)
|
||||
|
||||
type LoginInfoLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
BaseLogic
|
||||
}
|
||||
|
||||
func NewLoginInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LoginInfoLogic {
|
||||
return &LoginInfoLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *LoginInfoLogic) LoginInfo(in *admin.AdminEmptyRequest) (*admin.Response, error) {
|
||||
adminInfo := utils.GetUserFromCtx(l.ctx)
|
||||
if adminInfo.ID < utils.NumberOne {
|
||||
return l.fail(utils.ErrorNoLoginInfo), nil
|
||||
}
|
||||
info := dao.AdminInfo{}
|
||||
modelObj := model.AdminModel{}.Init()
|
||||
w := modelbase.Params{Eq: map[string]string{"id": strconv.Itoa(int(adminInfo.ID))}}
|
||||
err := modelObj.GetOne(w, &info)
|
||||
if err != nil {
|
||||
|
||||
}
|
||||
if info.Id > utils.NumberZero {
|
||||
mobile, dErr := utils.DecryptPhone(info.Phone)
|
||||
if dErr == nil {
|
||||
info.Phone = mobile
|
||||
}
|
||||
}
|
||||
|
||||
var roles []int
|
||||
if len(roles) > utils.NumberZero {
|
||||
for _, role := range strings.Split(info.Roles, utils.DecollatorComma) {
|
||||
r, _ := strconv.Atoi(role)
|
||||
roles = append(roles, r)
|
||||
}
|
||||
}
|
||||
retData := dao.AdminInfoRet{
|
||||
AdminInfo: info,
|
||||
Roles: roles,
|
||||
}
|
||||
|
||||
return l.ok(retData), nil
|
||||
}
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
"admin/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"google.golang.org/grpc/metadata"
|
||||
"pkg.local/modelbase"
|
||||
"pkg.local/utils"
|
||||
)
|
||||
@@ -37,13 +36,10 @@ func (l *OwnPasswordLogic) OwnPassword(in *admin.OwnPasswordRequest) (*admin.Res
|
||||
return fail, nil
|
||||
}
|
||||
var info dao.AdminPassword
|
||||
md, exist := metadata.FromIncomingContext(l.ctx)
|
||||
l.Logger.Info("收到完整metadata", exist, md)
|
||||
adminInfo := utils.GetUserFromCtx(l.ctx)
|
||||
if adminInfo.ID < utils.NumberOne {
|
||||
return l.fail(utils.ErrorNoLoginInfo), nil
|
||||
}
|
||||
l.Logger.Info("解析出用户信息", adminInfo.ID, adminInfo.Name)
|
||||
w := modelbase.Params{Eq: map[string]string{"id": strconv.Itoa(int(adminInfo.ID))}}
|
||||
modelObj := model.AdminModel{}.Init()
|
||||
err := modelObj.GetOne(w, &info)
|
||||
|
||||
@@ -62,3 +62,8 @@ func (s *AdminServer) AdminRefresh(ctx context.Context, in *admin.AdminEmptyRequ
|
||||
l := logic.NewAdminRefreshLogic(ctx, s.svcCtx)
|
||||
return l.AdminRefresh(in)
|
||||
}
|
||||
|
||||
func (s *AdminServer) LoginInfo(ctx context.Context, in *admin.AdminEmptyRequest) (*admin.Response, error) {
|
||||
l := logic.NewLoginInfoLogic(ctx, s.svcCtx)
|
||||
return l.LoginInfo(in)
|
||||
}
|
||||
|
||||
@@ -107,4 +107,10 @@ service Admin {
|
||||
body: "*"
|
||||
};
|
||||
};
|
||||
rpc LoginInfo(AdminEmptyRequest) returns(Response){
|
||||
option (google.api.http) = {
|
||||
post: "/admin/v3/info"
|
||||
body: "*"
|
||||
};
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user