password_login.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. data := http_model.PasswordLoginData{}
  37. data.Token = h.req.UserPhone
  38. auth := service.LoginAuth.AuthPassword(h.ctx, h.req.UserPhone, h.req.UserPasswd)
  39. if auth == nil {
  40. util.HandlerPackErrorResp(h.resp, consts.ErrorInternal)
  41. log.Info("login fail,req:%+v", h.req)
  42. return
  43. }
  44. h.resp.Data = data
  45. }
  46. func (h *PasswordLoginHandler) checkParam() error {
  47. return nil
  48. }