Login.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\admin\controller;
  12. use app\admin\model\system\SystemAdmin;
  13. use app\admin\model\system\SystemConfig;
  14. use basic\SystemBasic;
  15. use service\CacheService;
  16. use service\UtilService;
  17. use service\JsonService;
  18. use basic\AuthBasic;
  19. use think\Request;
  20. use think\Response;
  21. use think\Session;
  22. use think\Url;
  23. /**
  24. * 登录验证控制器
  25. * Class Login
  26. * @package app\admin\controller
  27. */
  28. class Login extends AuthBasic
  29. {
  30. public function index()
  31. {
  32. $this->assign([
  33. 'login_logo' => SystemConfig::getValue('login_logo'),
  34. 'Auth_site_name' => SystemConfig::getValue('site_name'),
  35. ]);
  36. return $this->fetch();
  37. }
  38. /**
  39. * 读取版权信息
  40. */
  41. public function get_copyright()
  42. {
  43. // return JsonService::successful('ok', $this->__z6uxyJQ4xYa5ee1mx5());
  44. }
  45. /**
  46. * 登录验证 + 验证码验证
  47. */
  48. public function verify(Request $request)
  49. {
  50. if (!$request->isPost()) return ['code' => 4];
  51. $array = $request->Post();
  52. $account = $array['account'];
  53. $pwd = $array['pwd'];
  54. $verify = $array['verify'];
  55. //检验验证码
  56. if (!captcha_check($verify)) return ['code' => 2];
  57. $error = Session::get('login_error', 'admin') ?: ['num' => 0, 'time' => time()];
  58. if ($error['num'] >= 5 && $error['time'] < strtotime('+ 5 minutes')) {
  59. return ['code' => 3];
  60. }
  61. //检验帐号密码
  62. $res = SystemAdmin::login($account, $pwd);
  63. if ($res) {
  64. Session::set('login_error', null, 'admin');
  65. return ['code' => 1];
  66. } else {
  67. $error['num'] += 1;
  68. $error['time'] = time();
  69. Session::set('login_error', $error, 'admin');
  70. return ['code' => 0, 'msg' => SystemAdmin::getErrorInfo()];
  71. }
  72. }
  73. public function captcha()
  74. {
  75. ob_clean();
  76. $captcha = new \think\captcha\Captcha([
  77. 'codeSet' => '0123456789',
  78. 'length' => 4,
  79. 'fontSize' => 30
  80. ]);
  81. return $captcha->entry();
  82. }
  83. /**
  84. * 退出登陆
  85. */
  86. public function logout()
  87. {
  88. SystemAdmin::clearLoginInfo();
  89. $this->redirect('Login/index');
  90. }
  91. }