mirror of https://gitee.com/answerdev/answer.git
fix: resolve conflict
This commit is contained in:
commit
7c94bdc2a0
|
@ -0,0 +1,27 @@
|
|||
package constant
|
||||
|
||||
const (
|
||||
UserNormal = "normal"
|
||||
UserSuspended = "suspended"
|
||||
UserDeleted = "deleted"
|
||||
UserInactive = "inactive"
|
||||
)
|
||||
const (
|
||||
EmailStatusAvailable = 1
|
||||
EmailStatusToBeVerified = 2
|
||||
)
|
||||
|
||||
func ConvertUserStatus(status, mailStatus int) string {
|
||||
switch status {
|
||||
case 1:
|
||||
if mailStatus == EmailStatusToBeVerified {
|
||||
return UserInactive
|
||||
}
|
||||
return UserNormal
|
||||
case 9:
|
||||
return UserSuspended
|
||||
case 10:
|
||||
return UserDeleted
|
||||
}
|
||||
return UserNormal
|
||||
}
|
|
@ -168,6 +168,20 @@ func GetValidatorByLang(lang i18n.Language) *MyValidator {
|
|||
|
||||
// Check /
|
||||
func (m *MyValidator) Check(value interface{}) (errFields []*FormErrorField, err error) {
|
||||
defer func() {
|
||||
if len(errFields) == 0 {
|
||||
return
|
||||
}
|
||||
for _, field := range errFields {
|
||||
if len(field.ErrorField) == 0 {
|
||||
continue
|
||||
}
|
||||
if !strings.HasSuffix(field.ErrorMsg, ".") {
|
||||
field.ErrorMsg += "."
|
||||
}
|
||||
field.ErrorMsg = fmt.Sprintf("%s%s", strings.ToUpper(string(field.ErrorMsg[0])), field.ErrorMsg[1:])
|
||||
}
|
||||
}()
|
||||
err = m.Validate.Struct(value)
|
||||
if err != nil {
|
||||
var valErrors validator.ValidationErrors
|
||||
|
|
|
@ -98,11 +98,11 @@ func (uc *UserController) GetOtherUserInfoByUsername(ctx *gin.Context) {
|
|||
// @Tags User
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param data body schema.UserEmailLogin true "UserEmailLogin"
|
||||
// @Param data body schema.UserEmailLoginReq true "UserEmailLogin"
|
||||
// @Success 200 {object} handler.RespBody{data=schema.UserLoginResp}
|
||||
// @Router /answer/api/v1/user/login/email [post]
|
||||
func (uc *UserController) UserEmailLogin(ctx *gin.Context) {
|
||||
req := &schema.UserEmailLogin{}
|
||||
req := &schema.UserEmailLoginReq{}
|
||||
if handler.BindAndCheck(ctx, req) {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -7,13 +7,10 @@ import (
|
|||
|
||||
// RemoveAnswerReq delete answer request
|
||||
type RemoveAnswerReq struct {
|
||||
// answer id
|
||||
ID string `validate:"required" json:"id"`
|
||||
// user id
|
||||
UserID string `json:"-"`
|
||||
// whether user can delete it
|
||||
CanDelete bool `json:"-"`
|
||||
CaptchaID string `json:"captcha_id"` // captcha_id
|
||||
CaptchaID string `json:"captcha_id"`
|
||||
CaptchaCode string `json:"captcha_code"`
|
||||
}
|
||||
|
||||
|
@ -29,7 +26,7 @@ type AnswerAddReq struct {
|
|||
UserID string `json:"-"`
|
||||
CanEdit bool `json:"-"`
|
||||
CanDelete bool `json:"-"`
|
||||
CaptchaID string `json:"captcha_id"` // captcha_id
|
||||
CaptchaID string `json:"captcha_id"`
|
||||
CaptchaCode string `json:"captcha_code"`
|
||||
}
|
||||
|
||||
|
@ -47,9 +44,8 @@ type AnswerUpdateReq struct {
|
|||
HTML string `json:"-"`
|
||||
UserID string `json:"-"`
|
||||
NoNeedReview bool `json:"-"`
|
||||
// whether user can edit it
|
||||
CanEdit bool `json:"-"`
|
||||
CaptchaID string `json:"captcha_id"` // captcha_id
|
||||
CaptchaID string `json:"captcha_id"`
|
||||
CaptchaCode string `json:"captcha_code"`
|
||||
}
|
||||
|
||||
|
@ -64,26 +60,24 @@ type AnswerUpdateResp struct {
|
|||
}
|
||||
|
||||
type AnswerListReq struct {
|
||||
QuestionID string `json:"question_id" form:"question_id"` // question_id
|
||||
Order string `json:"order" form:"order"` // 1 Default 2 time
|
||||
Page int `json:"page" form:"page"` // Query number of pages
|
||||
PageSize int `json:"page_size" form:"page_size"` // Search page size
|
||||
QuestionID string `json:"question_id" form:"question_id"`
|
||||
Order string `json:"order" form:"order"`
|
||||
Page int `json:"page" form:"page"`
|
||||
PageSize int `json:"page_size" form:"page_size"`
|
||||
UserID string `json:"-"`
|
||||
IsAdmin bool `json:"-"`
|
||||
// whether user can edit it
|
||||
CanEdit bool `json:"-"`
|
||||
// whether user can delete it
|
||||
CanDelete bool `json:"-"`
|
||||
}
|
||||
|
||||
type AnswerInfo struct {
|
||||
ID string `json:"id" xorm:"id"` // id
|
||||
QuestionID string `json:"question_id" xorm:"question_id"` // question_id
|
||||
Content string `json:"content" xorm:"content"` // content
|
||||
HTML string `json:"html" xorm:"html"` // html
|
||||
CreateTime int64 `json:"create_time" xorm:"created"` // create_time
|
||||
UpdateTime int64 `json:"update_time" xorm:"updated"` // update_time
|
||||
Accepted int `json:"accepted"` // 1 Failed 2 accepted
|
||||
ID string `json:"id" xorm:"id"`
|
||||
QuestionID string `json:"question_id" xorm:"question_id"`
|
||||
Content string `json:"content" xorm:"content"`
|
||||
HTML string `json:"html" xorm:"html"`
|
||||
CreateTime int64 `json:"create_time" xorm:"created"`
|
||||
UpdateTime int64 `json:"update_time" xorm:"updated"`
|
||||
Accepted int `json:"accepted"`
|
||||
UserID string `json:"-"`
|
||||
UpdateUserID string `json:"-"`
|
||||
UserInfo *UserBasicInfo `json:"user_info,omitempty"`
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package schema
|
||||
|
||||
import "github.com/answerdev/answer/internal/base/constant"
|
||||
|
||||
// UpdateUserStatusReq update user request
|
||||
type UpdateUserStatusReq struct {
|
||||
UserID string `validate:"required" json:"user_id"`
|
||||
|
@ -7,17 +9,10 @@ type UpdateUserStatusReq struct {
|
|||
LoginUserID string `json:"-"`
|
||||
}
|
||||
|
||||
const (
|
||||
UserNormal = "normal"
|
||||
UserSuspended = "suspended"
|
||||
UserDeleted = "deleted"
|
||||
UserInactive = "inactive"
|
||||
)
|
||||
|
||||
func (r *UpdateUserStatusReq) IsNormal() bool { return r.Status == UserNormal }
|
||||
func (r *UpdateUserStatusReq) IsSuspended() bool { return r.Status == UserSuspended }
|
||||
func (r *UpdateUserStatusReq) IsDeleted() bool { return r.Status == UserDeleted }
|
||||
func (r *UpdateUserStatusReq) IsInactive() bool { return r.Status == UserInactive }
|
||||
func (r *UpdateUserStatusReq) IsNormal() bool { return r.Status == constant.UserNormal }
|
||||
func (r *UpdateUserStatusReq) IsSuspended() bool { return r.Status == constant.UserSuspended }
|
||||
func (r *UpdateUserStatusReq) IsDeleted() bool { return r.Status == constant.UserDeleted }
|
||||
func (r *UpdateUserStatusReq) IsInactive() bool { return r.Status == constant.UserInactive }
|
||||
|
||||
// GetUserPageReq get user list page request
|
||||
type GetUserPageReq struct {
|
||||
|
@ -33,9 +28,9 @@ type GetUserPageReq struct {
|
|||
Staff bool `validate:"omitempty" form:"staff"`
|
||||
}
|
||||
|
||||
func (r *GetUserPageReq) IsSuspended() bool { return r.Status == UserSuspended }
|
||||
func (r *GetUserPageReq) IsDeleted() bool { return r.Status == UserDeleted }
|
||||
func (r *GetUserPageReq) IsInactive() bool { return r.Status == UserInactive }
|
||||
func (r *GetUserPageReq) IsSuspended() bool { return r.Status == constant.UserSuspended }
|
||||
func (r *GetUserPageReq) IsDeleted() bool { return r.Status == constant.UserDeleted }
|
||||
func (r *GetUserPageReq) IsInactive() bool { return r.Status == constant.UserInactive }
|
||||
|
||||
// GetUserPageResp get user response
|
||||
type GetUserPageResp struct {
|
||||
|
|
|
@ -77,27 +77,20 @@ func (r *UserLoginResp) ConvertFromUserEntity(userInfo *entity.User) {
|
|||
_ = copier.Copy(r, userInfo)
|
||||
r.CreatedAt = userInfo.CreatedAt.Unix()
|
||||
r.LastLoginDate = userInfo.LastLoginDate.Unix()
|
||||
r.Status = UserStatusShow[userInfo.Status]
|
||||
r.Status = constant.ConvertUserStatus(userInfo.Status, userInfo.MailStatus)
|
||||
r.HavePassword = len(userInfo.Pass) > 0
|
||||
}
|
||||
|
||||
type GetCurrentLoginUserInfoResp struct {
|
||||
*UserLoginResp
|
||||
Avatar *AvatarInfo `json:"avatar"`
|
||||
HavePassword bool `json:"have_password"`
|
||||
}
|
||||
|
||||
func (r *GetCurrentLoginUserInfoResp) ConvertFromUserEntity(userInfo *entity.User) {
|
||||
_ = copier.Copy(r, userInfo)
|
||||
r.CreatedAt = userInfo.CreatedAt.Unix()
|
||||
r.LastLoginDate = userInfo.LastLoginDate.Unix()
|
||||
r.Status = UserStatusShow[userInfo.Status]
|
||||
}
|
||||
|
||||
// GetUserStatusResp get user status info
|
||||
type GetUserStatusResp struct {
|
||||
// user status
|
||||
Status string `json:"status"`
|
||||
r.Status = constant.ConvertUserStatus(userInfo.Status, userInfo.MailStatus)
|
||||
}
|
||||
|
||||
// GetOtherUserInfoByUsernameResp get user response
|
||||
|
@ -141,10 +134,7 @@ func (r *GetOtherUserInfoByUsernameResp) ConvertFromUserEntity(userInfo *entity.
|
|||
_ = copier.Copy(r, userInfo)
|
||||
r.CreatedAt = userInfo.CreatedAt.Unix()
|
||||
r.LastLoginDate = userInfo.LastLoginDate.Unix()
|
||||
statusShow, ok := UserStatusShow[userInfo.Status]
|
||||
if ok {
|
||||
r.Status = statusShow
|
||||
}
|
||||
r.Status = constant.ConvertUserStatus(userInfo.Status, userInfo.MailStatus)
|
||||
if userInfo.MailStatus == entity.EmailStatusToBeVerified {
|
||||
statusMsgShow, ok := UserStatusShowMsg[11]
|
||||
if ok {
|
||||
|
@ -159,19 +149,10 @@ func (r *GetOtherUserInfoByUsernameResp) ConvertFromUserEntity(userInfo *entity.
|
|||
}
|
||||
|
||||
const (
|
||||
MailStatePass = 1
|
||||
MailStateVerifi = 2
|
||||
|
||||
NoticeStatusOn = 1
|
||||
NoticeStatusOff = 2
|
||||
)
|
||||
|
||||
var UserStatusShow = map[int]string{
|
||||
1: "normal",
|
||||
9: "forbidden",
|
||||
10: "deleted",
|
||||
}
|
||||
|
||||
var UserStatusShowMsg = map[int]string{
|
||||
1: "",
|
||||
9: "<strong>This user was suspended forever.</strong> This user doesn’t meet a community guideline.",
|
||||
|
@ -179,25 +160,22 @@ var UserStatusShowMsg = map[int]string{
|
|||
11: "This user is inactive.",
|
||||
}
|
||||
|
||||
// EmailLogin
|
||||
type UserEmailLogin struct {
|
||||
Email string `validate:"required,email,gt=0,lte=500" json:"e_mail"` // e_mail
|
||||
Pass string `validate:"required,gte=8,lte=32" json:"pass"` // password
|
||||
CaptchaID string `json:"captcha_id"` // captcha_id
|
||||
CaptchaCode string `json:"captcha_code"` // captcha_code
|
||||
// UserEmailLoginReq user email login request
|
||||
type UserEmailLoginReq struct {
|
||||
Email string `validate:"required,email,gt=0,lte=500" json:"e_mail"`
|
||||
Pass string `validate:"required,gte=8,lte=32" json:"pass"`
|
||||
CaptchaID string `json:"captcha_id"`
|
||||
CaptchaCode string `json:"captcha_code"`
|
||||
}
|
||||
|
||||
// UserRegisterReq user register request
|
||||
type UserRegisterReq struct {
|
||||
// name
|
||||
Name string `validate:"required,gt=3,lte=30" json:"name"`
|
||||
// email
|
||||
Email string `validate:"required,email,gt=0,lte=500" json:"e_mail" `
|
||||
// password
|
||||
Pass string `validate:"required,gte=8,lte=32" json:"pass"`
|
||||
CaptchaID string `json:"captcha_id"`
|
||||
CaptchaCode string `json:"captcha_code"`
|
||||
IP string `json:"-" `
|
||||
CaptchaID string `json:"captcha_id"` // captcha_id
|
||||
CaptchaCode string `json:"captcha_code"` // captcha_code
|
||||
}
|
||||
|
||||
func (u *UserRegisterReq) Check() (errFields []*validator.FormErrorField, err error) {
|
||||
|
@ -214,10 +192,10 @@ func (u *UserRegisterReq) Check() (errFields []*validator.FormErrorField, err er
|
|||
type UserModifyPasswordReq struct {
|
||||
OldPass string `validate:"omitempty,gte=8,lte=32" json:"old_pass"`
|
||||
Pass string `validate:"required,gte=8,lte=32" json:"pass"`
|
||||
UserID string `json:"-"`
|
||||
AccessToken string `json:"-"`
|
||||
CaptchaID string `validate:"omitempty,gt=0,lte=500" json:"captcha_id"`
|
||||
CaptchaCode string `validate:"omitempty,gt=0,lte=500" json:"captcha_code"`
|
||||
UserID string `json:"-"`
|
||||
AccessToken string `json:"-"`
|
||||
}
|
||||
|
||||
func (u *UserModifyPasswordReq) Check() (errFields []*validator.FormErrorField, err error) {
|
||||
|
@ -293,14 +271,14 @@ type UpdateUserInterfaceRequest struct {
|
|||
}
|
||||
|
||||
type UserRetrievePassWordRequest struct {
|
||||
Email string `validate:"required,email,gt=0,lte=500" json:"e_mail" ` // e_mail
|
||||
CaptchaID string `json:"captcha_id" ` // captcha_id
|
||||
CaptchaCode string `json:"captcha_code" ` // captcha_code
|
||||
Email string `validate:"required,email,gt=0,lte=500" json:"e_mail"`
|
||||
CaptchaID string `json:"captcha_id"`
|
||||
CaptchaCode string `json:"captcha_code"`
|
||||
}
|
||||
|
||||
type UserRePassWordRequest struct {
|
||||
Code string `validate:"required,gt=0,lte=100" json:"code" ` // code
|
||||
Pass string `validate:"required,gt=0,lte=32" json:"pass" ` // Password
|
||||
Code string `validate:"required,gt=0,lte=100" json:"code"`
|
||||
Pass string `validate:"required,gt=0,lte=32" json:"pass"`
|
||||
Content string `json:"-"`
|
||||
}
|
||||
|
||||
|
@ -325,7 +303,6 @@ type UserNoticeSetResp struct {
|
|||
}
|
||||
|
||||
type ActionRecordReq struct {
|
||||
// action
|
||||
Action string `validate:"required,oneof=email password edit_userinfo question answer comment edit invitation_answer search report delete vote" form:"action"`
|
||||
IP string `json:"-"`
|
||||
UserID string `json:"-"`
|
||||
|
@ -338,15 +315,15 @@ type ActionRecordResp struct {
|
|||
}
|
||||
|
||||
type UserBasicInfo struct {
|
||||
ID string `json:"id"` // user_id
|
||||
Username string `json:"username" ` // name
|
||||
Rank int `json:"rank" ` // rank
|
||||
DisplayName string `json:"display_name"` // display_name
|
||||
Avatar string `json:"avatar" ` // avatar
|
||||
Website string `json:"website" ` // website
|
||||
Location string `json:"location" ` // location
|
||||
IPInfo string `json:"ip_info"` // ip info
|
||||
Status string `json:"status"` // status
|
||||
ID string `json:"id"`
|
||||
Username string `json:"username"`
|
||||
Rank int `json:"rank"`
|
||||
DisplayName string `json:"display_name"`
|
||||
Avatar string `json:"avatar"`
|
||||
Website string `json:"website"`
|
||||
Location string `json:"location"`
|
||||
IPInfo string `json:"ip_info"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
type GetOtherUserInfoByUsernameReq struct {
|
||||
|
|
|
@ -3,6 +3,7 @@ package user_admin
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/answerdev/answer/internal/base/constant"
|
||||
"github.com/answerdev/answer/internal/service/export"
|
||||
"github.com/google/uuid"
|
||||
"net/mail"
|
||||
|
@ -261,15 +262,15 @@ func (us *UserAdminService) GetUserPage(ctx context.Context, req *schema.GetUser
|
|||
Avatar: avatarMapping[u.ID].GetURL(),
|
||||
}
|
||||
if u.Status == entity.UserStatusDeleted {
|
||||
t.Status = schema.UserDeleted
|
||||
t.Status = constant.UserDeleted
|
||||
t.DeletedAt = u.DeletedAt.Unix()
|
||||
} else if u.Status == entity.UserStatusSuspended {
|
||||
t.Status = schema.UserSuspended
|
||||
t.Status = constant.UserSuspended
|
||||
t.SuspendedAt = u.SuspendedAt.Unix()
|
||||
} else if u.MailStatus == entity.EmailStatusToBeVerified {
|
||||
t.Status = schema.UserInactive
|
||||
t.Status = constant.UserInactive
|
||||
} else {
|
||||
t.Status = schema.UserNormal
|
||||
t.Status = constant.UserNormal
|
||||
}
|
||||
resp = append(resp, t)
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package usercommon
|
|||
|
||||
import (
|
||||
"context"
|
||||
"github.com/answerdev/answer/internal/base/constant"
|
||||
"strings"
|
||||
|
||||
"github.com/Chain-Zhang/pinyin"
|
||||
|
@ -130,8 +131,8 @@ func (us *UserCommon) FormatUserBasicInfo(ctx context.Context, userInfo *entity.
|
|||
userBasicInfo.Website = userInfo.Website
|
||||
userBasicInfo.Location = userInfo.Location
|
||||
userBasicInfo.IPInfo = userInfo.IPInfo
|
||||
userBasicInfo.Status = schema.UserStatusShow[userInfo.Status]
|
||||
if userBasicInfo.Status == schema.UserDeleted {
|
||||
userBasicInfo.Status = constant.ConvertUserStatus(userInfo.Status, userInfo.MailStatus)
|
||||
if userBasicInfo.Status == constant.UserDeleted {
|
||||
userBasicInfo.Avatar = ""
|
||||
userBasicInfo.DisplayName = "Anonymous"
|
||||
}
|
||||
|
|
|
@ -109,7 +109,7 @@ func (us *UserService) GetOtherUserInfoByUsername(ctx context.Context, username
|
|||
}
|
||||
|
||||
// EmailLogin email login
|
||||
func (us *UserService) EmailLogin(ctx context.Context, req *schema.UserEmailLogin) (resp *schema.UserLoginResp, err error) {
|
||||
func (us *UserService) EmailLogin(ctx context.Context, req *schema.UserEmailLoginReq) (resp *schema.UserLoginResp, err error) {
|
||||
userInfo, exist, err := us.userRepo.GetByEmail(ctx, req.Email)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
Loading…
Reference in New Issue