code_login.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package handler
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "github.com/sirupsen/logrus"
  5. log "github.com/sirupsen/logrus"
  6. "youngee_b_api/model/http_model"
  7. "youngee_b_api/service"
  8. )
  9. func WrapCodeLoginHandler(ctx *gin.Context) {
  10. handler := newCodeLoginHandler(ctx)
  11. baseRun(handler)
  12. }
  13. func newCodeLoginHandler(ctx *gin.Context) *CodeLoginHandler {
  14. return &CodeLoginHandler{
  15. req: http_model.NewCodeLoginRequest(),
  16. resp: http_model.NewCodeLoginResponse(),
  17. ctx: ctx,
  18. }
  19. }
  20. type CodeLoginHandler struct {
  21. req *http_model.CodeLoginRequest
  22. resp *http_model.CommonResponse
  23. ctx *gin.Context
  24. }
  25. func (h *CodeLoginHandler) getRequest() interface{} {
  26. return h.req
  27. }
  28. func (h *CodeLoginHandler) getContext() *gin.Context {
  29. return h.ctx
  30. }
  31. func (h *CodeLoginHandler) getResponse() interface{} {
  32. return h.resp
  33. }
  34. func (h *CodeLoginHandler) run() {
  35. tag, userData, err := service.LoginAuth.AuthCode(h.ctx, h.req.Phone, h.req.Code)
  36. if err != nil {
  37. logrus.Errorf("[CodeLoginHandler] call AuthCode err:%+v\n", err)
  38. // util.HandlerPackErrorResp(h.resp, consts.ErrorInternal, msg)
  39. log.Info("login fail,req:%+v", h.req)
  40. h.resp.Status = 40000
  41. h.resp.Message = err.Error()
  42. h.resp.Data = nil
  43. return
  44. }
  45. if tag == 1 {
  46. h.resp.Status = 34000
  47. h.resp.Message = "验证码校验错误"
  48. h.resp.Data = nil
  49. return
  50. }
  51. if tag == 2 {
  52. h.resp.Status = 34500
  53. h.resp.Message = "账户已停用"
  54. h.resp.Data = nil
  55. return
  56. }
  57. var data *http_model.CodeLoginData
  58. data = userData
  59. h.resp.Data = data
  60. }
  61. func (h *CodeLoginHandler) checkParam() error {
  62. return nil
  63. }