Login.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 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 basic\SystemBasic;
  14. use service\CacheService;
  15. use service\UtilService;
  16. use think\Request;
  17. use think\Response;
  18. use think\Session;
  19. use think\Url;
  20. /**
  21. * 登录验证控制器
  22. * Class Login
  23. * @package app\admin\controller
  24. */
  25. class Login extends SystemBasic
  26. {
  27. public function index()
  28. {
  29. return $this->fetch();
  30. }
  31. /**
  32. * 登录验证 + 验证码验证
  33. */
  34. public function verify(Request $request)
  35. {
  36. if (!$request->isPost()) return ['code'=>4];
  37. list($account, $pwd, $verify) = UtilService::postMore([
  38. 'account', 'pwd', 'verify'
  39. ], $request, true);
  40. //检验验证码
  41. if (!captcha_check($verify)) return ['code'=>2];
  42. $error = Session::get('login_error') ?: ['num' => 0, 'time' => time()];
  43. if ($error['num'] >= 5 && $error['time'] < strtotime('+ 5 minutes')){
  44. return ['code'=>3];
  45. }
  46. //检验帐号密码
  47. $res = SystemAdmin::login($account, $pwd);
  48. if ($res) {
  49. Session::set('login_error', null);
  50. return ['code'=>1];
  51. } else {
  52. $error['num'] += 1;
  53. $error['time'] = time();
  54. Session::set('login_error', $error);
  55. return ['code'=>0];
  56. }
  57. }
  58. public function captcha()
  59. {
  60. ob_clean();
  61. $captcha = new \think\captcha\Captcha([
  62. 'codeSet' => '0123456789',
  63. 'length' => 4,
  64. 'fontSize' => 30
  65. ]);
  66. return $captcha->entry();
  67. }
  68. /**
  69. * 退出登陆
  70. */
  71. public function logout()
  72. {
  73. SystemAdmin::clearLoginInfo();
  74. $this->redirect('Login/index');
  75. }
  76. }