MCPcopy Index your code
hub / github.com/apache/answer / UserEmailLogin

Method UserEmailLogin

internal/controller/user_controller.go:134–172  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

132// @Success 200 {object} handler.RespBody{data=schema.UserLoginResp}
133// @Router /answer/api/v1/user/login/email [post]
134func (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

Callers

nothing calls this directly

Calls 10

setVisitCookiesMethod · 0.95
BindAndCheckFunction · 0.92
GetUserIsAdminModeratorFunction · 0.92
TrFunction · 0.92
GetLangByCtxFunction · 0.92
HandleResponseFunction · 0.92
EmailLoginMethod · 0.80
ActionRecordAddMethod · 0.80
ActionRecordDelMethod · 0.80

Tested by

no test coverage detected