Login.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\system\SystemAdmin;
  4. use crmeb\services\UtilService;
  5. use think\facade\Session;
  6. use think\facade\Route as Url;
  7. /**
  8. * 登录验证控制器
  9. * Class Login
  10. * @package app\admin\controller
  11. */
  12. class Login extends SystemBasic
  13. {
  14. public function index()
  15. {
  16. return $this->fetch();
  17. }
  18. /**
  19. * 登录验证 + 验证码验证
  20. */
  21. public function verify()
  22. {
  23. if (!request()->isPost()) return $this->failed('请登陆!');
  24. list($account, $pwd, $verify) = UtilService::postMore([
  25. 'account', 'pwd', 'verify'
  26. ], null, true);
  27. //检验验证码
  28. if (!captcha_check($verify)) return $this->failed('验证码错误,请重新输入');
  29. $error = Session::get('login_error') ?: ['num' => 0, 'time' => time()];
  30. $error['num'] = 0;
  31. if ($error['num'] >= 5 && $error['time'] > strtotime('- 5 minutes'))
  32. return $this->failed('错误次数过多,请稍候再试!');
  33. //检验帐号密码
  34. $res = SystemAdmin::login($account, $pwd);
  35. if ($res) {
  36. Session::set('login_error', null);
  37. Session::save();
  38. return $this->successful(['url' => Url::buildUrl('Index/index')->build()]);
  39. } else {
  40. $error['num'] += 1;
  41. $error['time'] = time();
  42. Session::set('login_error', $error);
  43. Session::save();
  44. return $this->failed(SystemAdmin::getErrorInfo('用户名错误,请重新输入'));
  45. }
  46. }
  47. public function captcha()
  48. {
  49. ob_clean();
  50. return captcha();
  51. }
  52. /**
  53. * 退出登陆
  54. */
  55. public function logout()
  56. {
  57. SystemAdmin::clearLoginInfo();
  58. $this->redirect(Url::buildUrl('index')->build());
  59. }
  60. }