feat(user): Add a have password flag

This commit is contained in:
LinkinStar 2023-01-17 17:27:20 +08:00
parent 29aa3f7ef2
commit 62bfb2b3f6
3 changed files with 19 additions and 13 deletions

View File

@ -107,18 +107,18 @@ func (cc *ConnectorController) ConnectorRedirect(connector plugin.Connector) (fn
// @Success 200 {object} handler.RespBody{data=[]schema.ConnectorInfoResp}
// @Router /answer/api/v1/connector/info [get]
func (cc *ConnectorController) ConnectorsInfo(ctx *gin.Context) {
//general, err := cc.siteInfoService.GetSiteGeneral(ctx)
//if err != nil {
// handler.HandleResponse(ctx, err, nil)
// return
//}
general, err := cc.siteInfoService.GetSiteGeneral(ctx)
if err != nil {
handler.HandleResponse(ctx, err, nil)
return
}
resp := make([]*schema.ConnectorInfoResp, 0)
_ = plugin.CallConnector(func(fn plugin.Connector) error {
resp = append(resp, &schema.ConnectorInfoResp{
Name: fn.ConnectorName(),
Icon: fn.ConnectorLogoSVG(),
Link: fmt.Sprintf("%s%s%s%s", "http://10.0.20.88:8080",
Link: fmt.Sprintf("%s%s%s%s", general.SiteUrl,
commonRouterPrefix, ConnectorLoginRouterPrefix, fn.ConnectorSlugName()),
})
return nil

View File

@ -85,7 +85,8 @@ func (r *GetUserResp) GetFromUserEntity(userInfo *entity.User) {
type GetUserToSetShowResp struct {
*GetUserResp
Avatar *AvatarInfo `json:"avatar"`
Avatar *AvatarInfo `json:"avatar"`
HavePassword bool `json:"have_password"`
}
func (r *GetUserToSetShowResp) GetFromUserEntity(userInfo *entity.User) {
@ -254,9 +255,9 @@ func (u *UserRegisterReq) Check() (errFields []*validator.FormErrorField, err er
// UserModifyPassWordRequest
type UserModifyPassWordRequest struct {
UserID string `json:"-" ` // user_id
OldPass string `json:"old_pass" ` // old password
Pass string `json:"pass" ` // password
OldPass string `validate:"omitempty,gte=8,lte=32" json:"old_pass"`
Pass string `validate:"required,gte=8,lte=32" json:"pass"`
UserID string `json:"-"`
}
func (u *UserModifyPassWordRequest) Check() (errFields []*validator.FormErrorField, err error) {

View File

@ -69,7 +69,8 @@ func NewUserService(userRepo usercommon.UserRepo,
}
// GetUserInfoByUserID get user info by user id
func (us *UserService) GetUserInfoByUserID(ctx context.Context, token, userID string) (resp *schema.GetUserToSetShowResp, err error) {
func (us *UserService) GetUserInfoByUserID(ctx context.Context, token, userID string) (
resp *schema.GetUserToSetShowResp, err error) {
userInfo, exist, err := us.userRepo.GetByUserID(ctx, userID)
if err != nil {
return nil, err
@ -85,6 +86,7 @@ func (us *UserService) GetUserInfoByUserID(ctx context.Context, token, userID st
resp.GetFromUserEntity(userInfo)
resp.AccessToken = token
resp.IsAdmin = roleID == role.RoleAdminID
resp.HavePassword = len(userInfo.Pass) > 0
return resp, nil
}
@ -469,8 +471,11 @@ func (us *UserService) UserVerifyEmail(ctx context.Context, req *schema.UserVeri
// verifyPassword
// Compare whether the password is correct
func (us *UserService) verifyPassword(ctx context.Context, LoginPass, UserPass string) bool {
err := bcrypt.CompareHashAndPassword([]byte(UserPass), []byte(LoginPass))
func (us *UserService) verifyPassword(ctx context.Context, loginPass, userPass string) bool {
if len(loginPass) == 0 && len(userPass) == 0 {
return true
}
err := bcrypt.CompareHashAndPassword([]byte(userPass), []byte(loginPass))
return err == nil
}