package handler import ( "youngee_b_api/consts" "youngee_b_api/model/http_model" "youngee_b_api/service" "youngee_b_api/util" "github.com/gin-gonic/gin" log "github.com/sirupsen/logrus" ) func WrapPasswordLoginHandler(ctx *gin.Context) { handler := newPasswordLoginHandler(ctx) baseRun(handler) } func newPasswordLoginHandler(ctx *gin.Context) *PasswordLoginHandler { return &PasswordLoginHandler{ req: http_model.NewPasswordLoginRequest(), resp: http_model.NewPasswordLoginResponse(), ctx: ctx, } } type PasswordLoginHandler struct { req *http_model.PasswordLoginRequest resp *http_model.CommonResponse ctx *gin.Context } func (h *PasswordLoginHandler) getRequest() interface{} { return h.req } func (h *PasswordLoginHandler) getContext() *gin.Context { return h.ctx } func (h *PasswordLoginHandler) getResponse() interface{} { return h.resp } func (h *PasswordLoginHandler) run() { // 登录接口处理流程 // 1. 在redis中查找验证码,判断验证码是否正确,若正确进行下一步,否则返回error // 2. 在user表中查找phone,判断手机号是否存在,若存在进行下一步,否则返回error,message:账号不存在 // 3. 更新user表中登陆时间 // 4. 生成tocken // 5. 将userID和tocken存到redis // 6. 返回tocken data := http_model.PasswordLoginData{} token, err := service.LoginAuth.AuthMSG(h.ctx, h.req.UserPhone, h.req.UserPasswd) if err != nil { util.HandlerPackErrorResp(h.resp, consts.ErrorInternal) log.Info("login fail,req:%+v", h.req) return } data.Token = token h.resp.Data = data } func (h *PasswordLoginHandler) checkParam() error { return nil }