update modify pass

This commit is contained in:
aichy126 2023-05-17 17:27:29 +08:00
parent 7603578f31
commit 3e17559623
6 changed files with 51 additions and 6 deletions

View File

@ -1,5 +1,6 @@
{ {
"eslint.workingDirectories": [ "eslint.workingDirectories": [
"ui" "ui"
] ],
"commentTranslate.multiLineMerge": true
} }

View File

@ -8925,6 +8925,14 @@ const docTemplate = `{
"pass" "pass"
], ],
"properties": { "properties": {
"captcha_code": {
"type": "string",
"maxLength": 500
},
"captcha_id": {
"type": "string",
"maxLength": 500
},
"old_pass": { "old_pass": {
"type": "string", "type": "string",
"maxLength": 32, "maxLength": 32,

View File

@ -8913,6 +8913,14 @@
"pass" "pass"
], ],
"properties": { "properties": {
"captcha_code": {
"type": "string",
"maxLength": 500
},
"captcha_id": {
"type": "string",
"maxLength": 500
},
"old_pass": { "old_pass": {
"type": "string", "type": "string",
"maxLength": 32, "maxLength": 32,

View File

@ -2134,6 +2134,12 @@ definitions:
type: object type: object
schema.UserModifyPasswordReq: schema.UserModifyPasswordReq:
properties: properties:
captcha_code:
maxLength: 500
type: string
captcha_id:
maxLength: 500
type: string
old_pass: old_pass:
maxLength: 32 maxLength: 32
minLength: 8 minLength: 8

View File

@ -350,6 +350,21 @@ func (uc *UserController) UserModifyPassWord(ctx *gin.Context) {
req.UserID = middleware.GetLoginUserIDFromContext(ctx) req.UserID = middleware.GetLoginUserIDFromContext(ctx)
req.AccessToken = middleware.ExtractToken(ctx) req.AccessToken = middleware.ExtractToken(ctx)
captchaPass := uc.actionService.ActionRecordVerifyCaptcha(ctx, schema.ActionRecordTypeModifyPass, ctx.ClientIP(),
req.CaptchaID, req.CaptchaCode)
if !captchaPass {
errFields := append([]*validator.FormErrorField{}, &validator.FormErrorField{
ErrorField: "captcha_code",
ErrorMsg: translator.Tr(handler.GetLang(ctx), reason.CaptchaVerificationFailed),
})
handler.HandleResponse(ctx, errors.BadRequest(reason.CaptchaVerificationFailed), errFields)
return
}
_, err := uc.actionService.ActionRecordAdd(ctx, schema.ActionRecordTypeModifyPass, ctx.ClientIP())
if err != nil {
log.Error(err)
}
oldPassVerification, err := uc.userService.UserModifyPassWordVerification(ctx, req) oldPassVerification, err := uc.userService.UserModifyPassWordVerification(ctx, req)
if err != nil { if err != nil {
handler.HandleResponse(ctx, err, nil) handler.HandleResponse(ctx, err, nil)
@ -363,6 +378,7 @@ func (uc *UserController) UserModifyPassWord(ctx *gin.Context) {
handler.HandleResponse(ctx, errors.BadRequest(reason.OldPasswordVerificationFailed), errFields) handler.HandleResponse(ctx, errors.BadRequest(reason.OldPasswordVerificationFailed), errFields)
return return
} }
if req.OldPass == req.Pass { if req.OldPass == req.Pass {
errFields := append([]*validator.FormErrorField{}, &validator.FormErrorField{ errFields := append([]*validator.FormErrorField{}, &validator.FormErrorField{
ErrorField: "pass", ErrorField: "pass",
@ -372,6 +388,9 @@ func (uc *UserController) UserModifyPassWord(ctx *gin.Context) {
return return
} }
err = uc.userService.UserModifyPassword(ctx, req) err = uc.userService.UserModifyPassword(ctx, req)
if err == nil {
uc.actionService.ActionRecordDel(ctx, schema.ActionRecordTypeLogin, ctx.ClientIP())
}
handler.HandleResponse(ctx, err, nil) handler.HandleResponse(ctx, err, nil)
} }

View File

@ -225,6 +225,7 @@ const (
ActionRecordTypeLogin = "login" ActionRecordTypeLogin = "login"
ActionRecordTypeEmail = "e_mail" ActionRecordTypeEmail = "e_mail"
ActionRecordTypeFindPass = "find_pass" ActionRecordTypeFindPass = "find_pass"
ActionRecordTypeModifyPass = "modify_pass"
) )
var UserStatusShow = map[int]string{ var UserStatusShow = map[int]string{
@ -280,6 +281,8 @@ type UserModifyPasswordReq struct {
Pass string `validate:"required,gte=8,lte=32" json:"pass"` Pass string `validate:"required,gte=8,lte=32" json:"pass"`
UserID string `json:"-"` UserID string `json:"-"`
AccessToken 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"`
} }
func (u *UserModifyPasswordReq) Check() (errFields []*validator.FormErrorField, err error) { func (u *UserModifyPasswordReq) Check() (errFields []*validator.FormErrorField, err error) {