书籍列表接口新增参数
This commit is contained in:
@ -90,12 +90,26 @@ func (s *sUser) Info(ctx context.Context, in *model.UserInfoIn) (out *model.User
|
||||
if err = user.Struct(&entityUser); err != nil {
|
||||
return nil, ecode.Fail.Sub("data_conversion_failed")
|
||||
}
|
||||
// 查询作者信息
|
||||
var authorStatus int
|
||||
isAuthor := false
|
||||
author, err := dao.Authors.Ctx(ctx).Where(do.Authors{UserId: entityUser.Id}).One()
|
||||
if err == nil && !author.IsEmpty() {
|
||||
authorStatus = author[dao.Authors.Columns().Status].Int()
|
||||
if authorStatus == 1 {
|
||||
isAuthor = true
|
||||
}
|
||||
}
|
||||
return &model.UserInfoOut{
|
||||
UserId: entityUser.Id,
|
||||
Username: entityUser.Username,
|
||||
Email: entityUser.Email,
|
||||
Avatar: entityUser.Avatar,
|
||||
Points: entityUser.Points, // 如有积分表可补充
|
||||
Id: entityUser.Id,
|
||||
Username: entityUser.Username,
|
||||
Email: entityUser.Email,
|
||||
Avatar: entityUser.Avatar,
|
||||
Points: entityUser.Points, // 如有积分表可补充
|
||||
BackgroundUrl: entityUser.BackgroundUrl,
|
||||
AttentionCount: entityUser.AttentionCount,
|
||||
IsAuthor: isAuthor,
|
||||
AuthorStatus: authorStatus,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@ -246,3 +260,33 @@ func (s *sUser) EditPass(ctx context.Context, in *model.UserEditPassIn) (out *mo
|
||||
Success: true,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *sUser) AuthorLogin(ctx context.Context, in *model.UserLoginIn) (out *model.UserLoginOut, err error) {
|
||||
user, err := dao.Users.Ctx(ctx).Where(do.Users{Email: in.Email}).One()
|
||||
if err != nil {
|
||||
return nil, ecode.Fail.Sub("database_query_failed")
|
||||
}
|
||||
if user == nil {
|
||||
return nil, ecode.Auth // 账户名或密码不正确
|
||||
}
|
||||
var entityUser entity.Users
|
||||
if err = user.Struct(&entityUser); err != nil {
|
||||
return nil, ecode.Fail.Sub("data_conversion_failed")
|
||||
}
|
||||
if !encrypt.ComparePassword(entityUser.PasswordHash, in.Password) {
|
||||
return nil, ecode.Password // 密码不正确
|
||||
}
|
||||
// 验证是否为作者
|
||||
author, err := dao.Authors.Ctx(ctx).Where(do.Authors{UserId: entityUser.Id, Status: 1}).One()
|
||||
if err != nil {
|
||||
return nil, ecode.Fail.Sub("author_query_failed")
|
||||
}
|
||||
if author == nil || author.IsEmpty() {
|
||||
return nil, ecode.Auth.Sub("not_author") // 不是作者
|
||||
}
|
||||
token, err := jwt.GenerateToken(&jwt.TokenIn{UserId: entityUser.Id, Role: "author"})
|
||||
if err != nil {
|
||||
return nil, ecode.Fail.Sub("token_generation_failed")
|
||||
}
|
||||
return &model.UserLoginOut{Token: token}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user