Index.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\AdminLog;
  4. use app\common\controller\Backend;
  5. use think\Config;
  6. use think\Hook;
  7. use think\Validate;
  8. use think\Db;
  9. /**
  10. * 后台首页
  11. * @internal
  12. */
  13. class Index extends Backend
  14. {
  15. protected $noNeedLogin = ['login'];
  16. protected $noNeedRight = ['index', 'logout'];
  17. protected $layout = '';
  18. public function _initialize()
  19. {
  20. parent::_initialize();
  21. //移除HTML标签
  22. $this->request->filter('trim,strip_tags,htmlspecialchars');
  23. }
  24. /**
  25. * 后台首页
  26. */
  27. public function index()
  28. {
  29. //各项为审核的,待处理的数量
  30. $wait = [
  31. 'wait_report' => Db::name('report')->where('status',0)->count(),
  32. 'wait_dt_report' => Db::name('topic_dongtai_report')->where('status',0)->count(),
  33. 'wait_user_audit' => Db::name('user_audit')->where('type','neq','audio_seconds')->where('status',0)->count(),
  34. 'wait_user_idconfirm' => Db::name('user_idconfirm')->where('status',0)->count(),
  35. 'wait_take_cash' => Db::name('take_cash')->where('status',0)->count(),
  36. 'wait_dongtai' => Db::name('topic_dongtai')->where('auditstatus',0)->count(),
  37. 'wait_greet' => Db::name('user_greet')->where('status',0)->count(),
  38. 'wait_introapply' => Db::name('user_intro_apply')->where('status',0)->count(),
  39. 'wait_withdraw' => Db::name('withdraw')->where('status',0)->count(),
  40. ];
  41. //左侧菜单
  42. list($menulist, $navlist, $fixedmenu, $referermenu) = $this->auth->getSidebar([
  43. // 'dashboard' => 'hot',
  44. // 'addon' => ['new', 'red', 'badge'],
  45. // 'auth/rule' => __('Menu'),
  46. // 'general' => ['new', 'purple'],
  47. // 'anquanxuncha' => 3,
  48. 'report' => $wait['wait_report'],
  49. 'topicdongtaireport' => $wait['wait_dt_report'],
  50. 'useraudit' => $wait['wait_user_audit'],
  51. 'useridconfirm' => $wait['wait_user_idconfirm'],
  52. 'takecash' => $wait['wait_take_cash'],
  53. 'topicdongtai' => $wait['wait_dongtai'],
  54. 'usergreet' => $wait['wait_greet'],
  55. 'userintroapply' => $wait['wait_introapply'],
  56. 'withdraw' => $wait['wait_withdraw'],
  57. ], $this->view->site['fixedpage']);
  58. $action = $this->request->request('action');
  59. if ($this->request->isPost()) {
  60. if ($action == 'refreshmenu') {
  61. $this->success('', null, ['menulist' => $menulist, 'navlist' => $navlist]);
  62. }
  63. }
  64. $this->view->assign('menulist', $menulist);
  65. $this->view->assign('navlist', $navlist);
  66. $this->view->assign('fixedmenu', $fixedmenu);
  67. $this->view->assign('referermenu', $referermenu);
  68. $this->view->assign('title', __('Home'));
  69. return $this->view->fetch();
  70. }
  71. /**
  72. * 管理员登录
  73. */
  74. public function login()
  75. {
  76. $url = $this->request->get('url', 'index/index');
  77. if ($this->auth->isLogin()) {
  78. $this->success(__("You've logged in, do not login again"), $url);
  79. }
  80. if ($this->request->isPost()) {
  81. $username = $this->request->post('username');
  82. $password = $this->request->post('password');
  83. $keeplogin = $this->request->post('keeplogin');
  84. $token = $this->request->post('__token__');
  85. $rule = [
  86. 'username' => 'require|length:3,30',
  87. 'password' => 'require|length:3,30',
  88. '__token__' => 'require|token',
  89. ];
  90. $data = [
  91. 'username' => $username,
  92. 'password' => $password,
  93. '__token__' => $token,
  94. ];
  95. if (Config::get('fastadmin.login_captcha')) {
  96. $rule['captcha'] = 'require|captcha';
  97. $data['captcha'] = $this->request->post('captcha');
  98. }
  99. $validate = new Validate($rule, [], ['username' => __('Username'), 'password' => __('Password'), 'captcha' => __('Captcha')]);
  100. $result = $validate->check($data);
  101. if (!$result) {
  102. $this->error($validate->getError(), $url, ['token' => $this->request->token()]);
  103. }
  104. AdminLog::setTitle(__('Login'));
  105. $result = $this->auth->login($username, $password, $keeplogin ? 86400 : 0);
  106. if ($result === true) {
  107. Hook::listen("admin_login_after", $this->request);
  108. $this->success(__('Login successful'), $url, ['url' => $url, 'id' => $this->auth->id, 'username' => $username, 'avatar' => $this->auth->avatar]);
  109. } else {
  110. $msg = $this->auth->getError();
  111. $msg = $msg ? $msg : __('Username or password is incorrect');
  112. $this->error($msg, $url, ['token' => $this->request->token()]);
  113. }
  114. }
  115. // 根据客户端的cookie,判断是否可以自动登录
  116. if ($this->auth->autologin()) {
  117. $this->redirect($url);
  118. }
  119. $background = Config::get('fastadmin.login_background');
  120. $background = $background ? (stripos($background, 'http') === 0 ? $background : config('site.cdnurl') . $background) : '';
  121. $this->view->assign('background', $background);
  122. $this->view->assign('title', __('Login'));
  123. Hook::listen("admin_login_init", $this->request);
  124. return $this->view->fetch();
  125. }
  126. /**
  127. * 退出登录
  128. */
  129. public function logout()
  130. {
  131. if ($this->request->isPost()) {
  132. $this->auth->logout();
  133. Hook::listen("admin_logout_after", $this->request);
  134. $this->success(__('Logout successful'), 'index/login');
  135. }
  136. $html = "<form id='logout_submit' name='logout_submit' action='' method='post'>" . token() . "<input type='submit' value='ok' style='display:none;'></form>";
  137. $html .= "<script>document.forms['logout_submit'].submit();</script>";
  138. return $html;
  139. }
  140. }