Login.php 1.9 KB

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