add: some user api and all api desc
This commit is contained in:
@@ -7,7 +7,7 @@ import (
|
||||
"juwan-backend/app/users/rpc/internal/svc"
|
||||
utils2 "juwan-backend/app/users/rpc/internal/utils"
|
||||
"juwan-backend/app/users/rpc/pb"
|
||||
"juwan-backend/common/utils"
|
||||
"juwan-backend/common/utils/pwdUtils"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
@@ -36,7 +36,7 @@ func (l *LoginLogic) Login(in *pb.LoginReq) (*pb.LoginResp, error) {
|
||||
return nil, err
|
||||
}
|
||||
logx.Infof("user:%v", user)
|
||||
if !utils.VerifyPassword(user.PasswordHash, in.Passwd) {
|
||||
if !pwdUtils.VerifyPassword(user.PasswordHash, in.Passwd) {
|
||||
logx.WithContext(l.ctx).Errorf("User %s Login failed", user.Username)
|
||||
return nil, errors.New("incorrect password")
|
||||
}
|
||||
|
||||
@@ -8,9 +8,9 @@ import (
|
||||
"fmt"
|
||||
"juwan-backend/app/snowflake/rpc/snowflake"
|
||||
"juwan-backend/app/users/rpc/internal/svc"
|
||||
"juwan-backend/app/users/rpc/internal/utils"
|
||||
"juwan-backend/app/users/rpc/pb"
|
||||
"juwan-backend/common/redisx"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
@@ -56,8 +56,7 @@ func (l *RegisterLogic) Register(in *pb.RegisterReq) (*pb.RegisterResp, error) {
|
||||
return nil, errors.New("invalid verification code")
|
||||
}
|
||||
|
||||
code, err := strconv.ParseInt(vcode, 10, 32)
|
||||
if err != nil || int32(code) != in.Vcode {
|
||||
if vcode != in.Vcode {
|
||||
logx.Error("invalid verification code")
|
||||
return nil, errors.New("invalid verification code")
|
||||
}
|
||||
@@ -80,7 +79,16 @@ func (l *RegisterLogic) Register(in *pb.RegisterReq) (*pb.RegisterResp, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
token, err := l.svcCtx.JwtManager.New(l.ctx, &utils.TokenPayload{
|
||||
UserId: resp.Id,
|
||||
IsAdmin: false,
|
||||
})
|
||||
if err != nil {
|
||||
logx.Errorf("generate token failed, err:%v", err)
|
||||
return nil, errors.New("generate token failed, but user registered successfully")
|
||||
}
|
||||
|
||||
return &pb.RegisterResp{
|
||||
Res: "user registered successfully",
|
||||
Res: token,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -30,6 +30,14 @@ func NewSearchUsersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Searc
|
||||
var SearUsersErr = errors.New("search users failed")
|
||||
|
||||
func (l *SearchUsersLogic) SearchUsers(in *pb.SearchUsersReq) (out *pb.SearchUsersResp, err error) {
|
||||
if in.Page == nil || *in.Page < 0 {
|
||||
logx.Errorf("Invalid page number: %v", in.Page)
|
||||
return nil, errors.New("invalid page number")
|
||||
}
|
||||
if *in.Limit > 1000 {
|
||||
logx.Errorf("Limit exceeds max limit: %d", in.Limit)
|
||||
return nil, errors.New("limit exceeds max limit")
|
||||
}
|
||||
user, err := l.svcCtx.UsersModelRO.Query().
|
||||
Where(users.Or(
|
||||
users.UsernameContainsFold(*in.Username),
|
||||
@@ -37,6 +45,8 @@ func (l *SearchUsersLogic) SearchUsers(in *pb.SearchUsersReq) (out *pb.SearchUse
|
||||
users.EmailContainsFold(*in.Username),
|
||||
users.CurrentRole(*in.CurrentRole),
|
||||
)).
|
||||
Offset(int(*in.Page * *in.Limit)).
|
||||
Limit(int(*in.Limit)).
|
||||
All(l.ctx)
|
||||
if err != nil {
|
||||
logx.Errorf("search users failed, err:%v.", err)
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
// Users is the model entity for the Users schema.
|
||||
// Users is the models entity for the Users schema.
|
||||
type Users struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.36.11
|
||||
// protoc v3.19.4
|
||||
// protoc v5.29.6
|
||||
// source: users.proto
|
||||
|
||||
package pb
|
||||
@@ -1201,10 +1201,10 @@ func (x *ValidateTokenReq) GetUserId() int64 {
|
||||
|
||||
type ValidateTokenResp struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
Valid bool `protobuf:"varint,1,opt,name=valid,proto3" json:"valid,omitempty"` // token 是否有效(不在黑名单中)
|
||||
Message string `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"` // 验证失败原因
|
||||
UserId int64 `protobuf:"varint,3,opt,name=userId,proto3" json:"userId,omitempty"` // 用户ID
|
||||
RoleType string `protobuf:"varint,4,opt,name=roleType,proto3" json:"roleType,omitempty"` // 用户角色
|
||||
Valid bool `protobuf:"varint,1,opt,name=valid,proto3" json:"valid,omitempty"` // token 是否有效(不在黑名单中)
|
||||
Message string `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"` // 验证失败原因
|
||||
UserId int64 `protobuf:"varint,3,opt,name=userId,proto3" json:"userId,omitempty"` // 用户ID
|
||||
RoleType string `protobuf:"bytes,4,opt,name=roleType,proto3" json:"roleType,omitempty"` // 用户角色
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
@@ -1384,7 +1384,7 @@ type RegisterReq struct {
|
||||
Username string `protobuf:"bytes,1,opt,name=username,proto3" json:"username,omitempty"`
|
||||
Passwd string `protobuf:"bytes,2,opt,name=passwd,proto3" json:"passwd,omitempty"`
|
||||
Phone string `protobuf:"bytes,3,opt,name=phone,proto3" json:"phone,omitempty"`
|
||||
Vcode int32 `protobuf:"varint,4,opt,name=vcode,proto3" json:"vcode,omitempty"`
|
||||
Vcode string `protobuf:"bytes,4,opt,name=vcode,proto3" json:"vcode,omitempty"`
|
||||
Email string `protobuf:"bytes,5,opt,name=email,proto3" json:"email,omitempty"`
|
||||
RequestId string `protobuf:"bytes,6,opt,name=requestId,proto3" json:"requestId,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
@@ -1442,11 +1442,11 @@ func (x *RegisterReq) GetPhone() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *RegisterReq) GetVcode() int32 {
|
||||
func (x *RegisterReq) GetVcode() string {
|
||||
if x != nil {
|
||||
return x.Vcode
|
||||
}
|
||||
return 0
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *RegisterReq) GetEmail() string {
|
||||
@@ -1834,7 +1834,7 @@ const file_users_proto_rawDesc = "" +
|
||||
"\x05valid\x18\x01 \x01(\bR\x05valid\x12\x18\n" +
|
||||
"\amessage\x18\x02 \x01(\tR\amessage\x12\x16\n" +
|
||||
"\x06userId\x18\x03 \x01(\x03R\x06userId\x12\x1a\n" +
|
||||
"\broleType\x18\x04 \x01(\x03R\broleType\"`\n" +
|
||||
"\broleType\x18\x04 \x01(\tR\broleType\"`\n" +
|
||||
"\x12CheckPermissionReq\x12\x16\n" +
|
||||
"\x06userId\x18\x01 \x01(\x03R\x06userId\x12\x1a\n" +
|
||||
"\bresource\x18\x02 \x01(\tR\bresource\x12\x16\n" +
|
||||
@@ -1846,7 +1846,7 @@ const file_users_proto_rawDesc = "" +
|
||||
"\busername\x18\x01 \x01(\tR\busername\x12\x16\n" +
|
||||
"\x06passwd\x18\x02 \x01(\tR\x06passwd\x12\x14\n" +
|
||||
"\x05phone\x18\x03 \x01(\tR\x05phone\x12\x14\n" +
|
||||
"\x05vcode\x18\x04 \x01(\x05R\x05vcode\x12\x14\n" +
|
||||
"\x05vcode\x18\x04 \x01(\tR\x05vcode\x12\x14\n" +
|
||||
"\x05email\x18\x05 \x01(\tR\x05email\x12\x1c\n" +
|
||||
"\trequestId\x18\x06 \x01(\tR\trequestId\" \n" +
|
||||
"\fRegisterResp\x12\x10\n" +
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||
// versions:
|
||||
// - protoc-gen-go-grpc v1.6.1
|
||||
// - protoc v3.19.4
|
||||
// - protoc v5.29.6
|
||||
// source: users.proto
|
||||
|
||||
package pb
|
||||
|
||||
Reference in New Issue
Block a user