mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-15 09:10:24 +08:00
[用户节点]可以管理用户节点
This commit is contained in:
@@ -3,6 +3,8 @@ package services
|
||||
import (
|
||||
"context"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
rpcutils "github.com/TeaOSLab/EdgeAPI/internal/rpc/utils"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/utils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
|
||||
@@ -137,3 +139,38 @@ func (this *UserService) CheckUsername(ctx context.Context, req *pb.CheckUsernam
|
||||
}
|
||||
return &pb.CheckUsernameResponse{Exists: b}, nil
|
||||
}
|
||||
|
||||
// 登录
|
||||
func (this *UserService) LoginUser(ctx context.Context, req *pb.LoginUserRequest) (*pb.LoginUserResponse, error) {
|
||||
_, _, err := rpcutils.ValidateRequest(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(req.Username) == 0 || len(req.Password) == 0 {
|
||||
return &pb.LoginUserResponse{
|
||||
UserId: 0,
|
||||
IsOk: false,
|
||||
Message: "请输入正确的用户名密码",
|
||||
}, nil
|
||||
}
|
||||
|
||||
userId, err := models.SharedUserDAO.CheckUserPassword(req.Username, req.Password)
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if userId <= 0 {
|
||||
return &pb.LoginUserResponse{
|
||||
UserId: 0,
|
||||
IsOk: false,
|
||||
Message: "请输入正确的用户名密码",
|
||||
}, nil
|
||||
}
|
||||
|
||||
return &pb.LoginUserResponse{
|
||||
UserId: userId,
|
||||
IsOk: true,
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user