A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.
feat(user): Add a have password flag
LinkinStar62bfb2b3f6d2
diff --git a/internal/controller/connector_controller.go b/internal/controller/connector_controller.goindex 93238379..df67b3f5 100644--- a/internal/controller/connector_controller.go+++ b/internal/controller/connector_controller.go@@ -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 nildiff --git a/internal/schema/user_schema.go b/internal/schema/user_schema.goindex 0cdba3f1..c8089ee6 100644--- a/internal/schema/user_schema.go+++ b/internal/schema/user_schema.go@@ -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// UserModifyPassWordRequesttype 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) {diff --git a/internal/service/user_service.go b/internal/service/user_service.goindex 436ee8d1..c50778df 100644--- a/internal/service/user_service.go+++ b/internal/service/user_service.go@@ -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 stresp.GetFromUserEntity(userInfo)resp.AccessToken = tokenresp.IsAdmin = roleID == role.RoleAdminID+ resp.HavePassword = len(userInfo.Pass) > 0return 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}