auth.go 813 B

12345678910111213141516171819202122232425262728293031323334
  1. package controller
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "github.com/go-playground/validator/v10"
  5. "hongze/fms_api/controller/resp"
  6. "hongze/fms_api/global"
  7. "hongze/fms_api/models/system"
  8. systemService "hongze/fms_api/services/system"
  9. )
  10. type AuthController struct {
  11. }
  12. func (a *AuthController) Login(c *gin.Context) {
  13. req := new(system.LoginReq)
  14. err := c.ShouldBind(&req)
  15. if err != nil {
  16. errs, ok := err.(validator.ValidationErrors)
  17. if !ok {
  18. resp.FailData("参数解析失败", "Err:"+err.Error(), c)
  19. return
  20. }
  21. resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
  22. return
  23. }
  24. ret, err, errMsg := systemService.Login(req.AdminName, req.Password, req.IsRemember)
  25. if err != nil {
  26. resp.FailMsg(errMsg, err.Error(), c)
  27. return
  28. }
  29. resp.OkData("登录成功", ret, c)
  30. return
  31. }