password_login.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package handler
  2. import (
  3. "youngee_b_api/consts"
  4. "youngee_b_api/model/http_model"
  5. "youngee_b_api/service"
  6. "youngee_b_api/util"
  7. "github.com/gin-gonic/gin"
  8. log "github.com/sirupsen/logrus"
  9. )
  10. func WrapPasswordLoginHandler(ctx *gin.Context) {
  11. handler := newPasswordLoginHandler(ctx)
  12. baseRun(handler)
  13. }
  14. func newPasswordLoginHandler(ctx *gin.Context) *PasswordLoginHandler {
  15. return &PasswordLoginHandler{
  16. req: http_model.NewPasswordLoginRequest(),
  17. resp: http_model.NewPasswordLoginResponse(),
  18. ctx: ctx,
  19. }
  20. }
  21. type PasswordLoginHandler struct {
  22. req *http_model.PasswordLoginRequest
  23. resp *http_model.CommonResponse
  24. ctx *gin.Context
  25. }
  26. func (h *PasswordLoginHandler) getRequest() interface{} {
  27. return h.req
  28. }
  29. func (h *PasswordLoginHandler) getContext() *gin.Context {
  30. return h.ctx
  31. }
  32. func (h *PasswordLoginHandler) getResponse() interface{} {
  33. return h.resp
  34. }
  35. func (h *PasswordLoginHandler) run() {
  36. // 登录接口处理流程
  37. // 1. 在redis中查找验证码,判断验证码是否正确,若正确进行下一步,否则返回error
  38. // 2. 在user表中查找phone,判断手机号是否存在,若存在进行下一步,否则返回error,message:账号不存在
  39. // 3. 更新user表中登陆时间
  40. // 4. 生成tocken
  41. // 5. 将userID和tocken存到redis
  42. // 6. 返回tocken
  43. data := http_model.PasswordLoginData{}
  44. token, err := service.LoginAuth.AuthMSG(h.ctx, h.req.UserPhone, h.req.UserPasswd)
  45. if err != nil {
  46. util.HandlerPackErrorResp(h.resp, consts.ErrorInternal)
  47. log.Info("login fail,req:%+v", h.req)
  48. return
  49. }
  50. data.Token = token
  51. h.resp.Data = data
  52. }
  53. func (h *PasswordLoginHandler) checkParam() error {
  54. return nil
  55. }