LoginController.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | saiadmin [ saiadmin快速开发框架 ]
  4. // +----------------------------------------------------------------------
  5. // | Author: sai <1430792918@qq.com>
  6. // +----------------------------------------------------------------------
  7. namespace plugin\saiadmin\app\controller;
  8. use support\Request;
  9. use support\Response;
  10. use plugin\saiadmin\utils\Captcha;
  11. use plugin\saiadmin\basic\BaseController;
  12. use plugin\saiadmin\app\logic\system\SystemUserLogic;
  13. /**
  14. * 登录控制器
  15. */
  16. class LoginController extends BaseController
  17. {
  18. /**
  19. * 不需要登录的方法
  20. */
  21. protected array $noNeedLogin = ['captcha', 'login'];
  22. /**
  23. * 获取验证码
  24. */
  25. public function captcha() : Response
  26. {
  27. $captcha = new Captcha();
  28. $result = $captcha->imageCaptcha();
  29. if ($result['result'] !== 1) {
  30. return $this->fail($result['message']);
  31. }
  32. return $this->success($result);
  33. }
  34. /**
  35. * 登录
  36. * @param Request $request
  37. * @return Response
  38. */
  39. public function login(Request $request): Response
  40. {
  41. $username = $request->post('username', '');
  42. $password = $request->post('password', '');
  43. $type = $request->post('type', 'pc');
  44. $code = $request->post('code', '');
  45. $uuid = $request->post('uuid', '');
  46. $captcha = new Captcha();
  47. if (!$captcha->checkCaptcha($uuid, $code)) {
  48. return $this->fail('验证码错误');
  49. }
  50. $logic = new SystemUserLogic();
  51. $data = $logic->login($username, $password, $type);
  52. return $this->success($data);
  53. }
  54. }