user.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package controller
  2. import (
  3. "context"
  4. "github.com/gogf/gf/v2/errors/gerror"
  5. "github.com/gogf/gf/v2/os/genv"
  6. "github.com/tiger1103/gfast/v3/apiv1/system"
  7. commonService "github.com/tiger1103/gfast/v3/internal/app/common/service"
  8. "github.com/tiger1103/gfast/v3/internal/app/system/model"
  9. "github.com/tiger1103/gfast/v3/internal/app/system/service"
  10. )
  11. var (
  12. User = UserController{}
  13. )
  14. type UserController struct {
  15. baseController
  16. }
  17. func (c *UserController) Login(ctx context.Context, req *system.UserLoginReq) (res *system.UserLoginRes, err error) {
  18. var user *model.LoginUserRes
  19. //判断验证码是否正确
  20. debug := genv.GetWithCmd("gf.debug")
  21. if debug.Int() != 1 {
  22. if !commonService.Captcha().VerifyString(req.VerifyKey, req.VerifyCode) {
  23. err = gerror.New("验证码输入错误")
  24. return
  25. }
  26. }
  27. //ip := libUtils.GetClientIp(ctx)
  28. //userAgent := libUtils.GetUserAgent(ctx)
  29. user, err = service.User().GetAdminUserByUsernamePassword(ctx, req)
  30. if err != nil {
  31. return
  32. }
  33. res = &system.UserLoginRes{
  34. UserInfo: user,
  35. }
  36. return
  37. }