Login.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. return $this->redirect(Url::buildUrl('Index/index'));
  38. }else{
  39. $error['num'] += 1;
  40. $error['time'] = time();
  41. Session::set('login_error',$error);
  42. return $this->failed(SystemAdmin::getErrorInfo('用户名错误,请重新输入'));
  43. }
  44. }
  45. public function captcha()
  46. {
  47. ob_clean();
  48. return captcha();
  49. }
  50. /**
  51. * 退出登陆
  52. */
  53. public function logout()
  54. {
  55. SystemAdmin::clearLoginInfo();
  56. $this->redirect('Login/index');
  57. }
  58. }