UserEmailLogin godoc @Summary UserEmailLogin @Description UserEmailLogin @Tags User @Accept json @Produce json @Param data body schema.UserEmailLoginReq true "UserEmailLogin" @Success 200 {object} handler.RespBody{data=schema.UserLoginResp} @Router /answer/api/v1/user/login/email [post]
(ctx *gin.Context)
| 132 | // @Success 200 {object} handler.RespBody{data=schema.UserLoginResp} |
| 133 | // @Router /answer/api/v1/user/login/email [post] |
| 134 | func (uc *UserController) UserEmailLogin(ctx *gin.Context) { |
| 135 | req := &schema.UserEmailLoginReq{} |
| 136 | if handler.BindAndCheck(ctx, req) { |
| 137 | return |
| 138 | } |
| 139 | isAdmin := middleware.GetUserIsAdminModerator(ctx) |
| 140 | if !isAdmin { |
| 141 | captchaPass := uc.actionService.ActionRecordVerifyCaptcha(ctx, entity.CaptchaActionPassword, ctx.ClientIP(), req.CaptchaID, req.CaptchaCode) |
| 142 | if !captchaPass { |
| 143 | errFields := append([]*validator.FormErrorField{}, &validator.FormErrorField{ |
| 144 | ErrorField: "captcha_code", |
| 145 | ErrorMsg: translator.Tr(handler.GetLangByCtx(ctx), reason.CaptchaVerificationFailed), |
| 146 | }) |
| 147 | handler.HandleResponse(ctx, errors.BadRequest(reason.CaptchaVerificationFailed), errFields) |
| 148 | return |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | resp, err := uc.userService.EmailLogin(ctx, req) |
| 153 | if err != nil { |
| 154 | uc.actionService.ActionRecordAdd(ctx, entity.CaptchaActionPassword, ctx.ClientIP()) |
| 155 | errFields := append([]*validator.FormErrorField{}, &validator.FormErrorField{ |
| 156 | ErrorField: "e_mail", |
| 157 | ErrorMsg: translator.Tr(handler.GetLangByCtx(ctx), reason.EmailOrPasswordWrong), |
| 158 | }) |
| 159 | handler.HandleResponse(ctx, errors.BadRequest(reason.EmailOrPasswordWrong), errFields) |
| 160 | return |
| 161 | } |
| 162 | if !isAdmin { |
| 163 | uc.actionService.ActionRecordDel(ctx, entity.CaptchaActionPassword, ctx.ClientIP()) |
| 164 | } |
| 165 | if resp.Status == constant.UserSuspended { |
| 166 | handler.HandleResponse(ctx, errors.Forbidden(reason.UserSuspended), |
| 167 | &schema.ForbiddenResp{Type: schema.ForbiddenReasonTypeUserSuspended}) |
| 168 | return |
| 169 | } |
| 170 | uc.setVisitCookies(ctx, resp.VisitToken, true) |
| 171 | handler.HandleResponse(ctx, nil, resp) |
| 172 | } |
| 173 | |
| 174 | // RetrievePassWord godoc |
| 175 | // @Summary RetrievePassWord |
nothing calls this directly
no test coverage detected