login.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package handler
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "github.com/sirupsen/logrus"
  5. "youngee_m_api/consts"
  6. "youngee_m_api/model/http_model"
  7. "youngee_m_api/service"
  8. "youngee_m_api/util"
  9. )
  10. func WrapCodeLoginHandler(ctx *gin.Context) {
  11. handler := newCodeLoginHandler(ctx)
  12. BaseRun(handler)
  13. }
  14. func newCodeLoginHandler(ctx *gin.Context) *CodeLoginHandler {
  15. return &CodeLoginHandler{
  16. req: http_model.NewCodeLoginRequest(),
  17. resp: http_model.NewCodeLoginResponse(),
  18. ctx: ctx,
  19. }
  20. }
  21. type CodeLoginHandler struct {
  22. req *http_model.CodeLoginRequest
  23. resp *http_model.CommonResponse
  24. ctx *gin.Context
  25. }
  26. func (h *CodeLoginHandler) getRequest() interface{} {
  27. return h.req
  28. }
  29. func (h *CodeLoginHandler) getContext() *gin.Context {
  30. return h.ctx
  31. }
  32. func (h *CodeLoginHandler) getResponse() interface{} {
  33. return h.resp
  34. }
  35. func (h *CodeLoginHandler) run() {
  36. err, resdata := service.LoginAuth.AuthCode(h.ctx, h.req.User, h.req.Password)
  37. if err != nil {
  38. logrus.Errorf("[CodeLoginHandler] call AuthCode err:%+v\n", err)
  39. util.HandlerPackErrorResp(h.resp, consts.ErrorInternal, resdata.Token)
  40. logrus.Info("login fail,req:%+v", h.req)
  41. return
  42. }
  43. //data := http_model.CodeLoginData{}
  44. //data.Token = token
  45. //data.Username = username
  46. //data.Role = role
  47. h.resp.Data = resdata
  48. h.resp.Status = consts.ErrorSuccess
  49. }
  50. func (h *CodeLoginHandler) checkParam() error {
  51. return nil
  52. }