Base.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. /**
  3. * 易优CMS
  4. * ============================================================================
  5. * 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
  6. * 网站地址: http://www.eyoucms.com
  7. * ----------------------------------------------------------------------------
  8. * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
  9. * ============================================================================
  10. * Author: 小虎哥 <1105415366@qq.com>
  11. * Date: 2018-4-3
  12. */
  13. namespace app\admin\controller;
  14. use app\admin\logic\UpgradeLogic;
  15. use think\Controller;
  16. use think\Db;
  17. use think\response\Json;
  18. use think\Session;
  19. class Base extends Controller {
  20. public $session_id;
  21. /**
  22. * 析构函数
  23. */
  24. function __construct()
  25. {
  26. if (!session_id()) {
  27. Session::start();
  28. }
  29. header("Cache-control: private"); // history.back返回后输入框值丢失问题
  30. parent::__construct();
  31. $this->global_assign();
  32. }
  33. /*
  34. * 初始化操作
  35. */
  36. public function _initialize()
  37. {
  38. $this->session_id = session_id(); // 当前的 session_id
  39. !defined('SESSION_ID') && define('SESSION_ID', $this->session_id); //将当前的session_id保存为常量,供其它方法调用
  40. parent::_initialize();
  41. //过滤不需要登陆的行为
  42. $ctl_act = CONTROLLER_NAME.'@'.ACTION_NAME;
  43. $ctl_all = CONTROLLER_NAME.'@*';
  44. $filter_login_action = config('filter_login_action');
  45. if (in_array($ctl_act, $filter_login_action) || in_array($ctl_all, $filter_login_action)) {
  46. //return;
  47. }else{
  48. $web_login_expiretime = tpCache('web.web_login_expiretime');
  49. empty($web_login_expiretime) && $web_login_expiretime = config('login_expire');
  50. $admin_login_expire = session('admin_login_expire'); // 登录有效期web_login_expiretime
  51. if (session('?admin_id') && getTime() - intval($admin_login_expire) < $web_login_expiretime) {
  52. session('admin_login_expire', getTime()); // 登录有效期
  53. $this->check_priv();//检查管理员菜单操作权限
  54. }else{
  55. /*自动退出*/
  56. adminLog('自动退出');
  57. session_unset();
  58. session::clear();
  59. cookie('admin-treeClicked', null); // 清除并恢复栏目列表的展开方式
  60. /*--end*/
  61. if (IS_AJAX) {
  62. $this->error('登录超时!');
  63. } else {
  64. $url = request()->baseFile().'?s=Admin/login';
  65. $this->redirect($url);
  66. }
  67. }
  68. }
  69. /* 增、改的跳转提示页,只限制于发布文档的模型和自定义模型 */
  70. $channeltype_list = config('global.channeltype_list');
  71. $controller_name = $this->request->controller();
  72. if (isset($channeltype_list[strtolower($controller_name)]) || 'Custom' == $controller_name) {
  73. if (in_array($this->request->action(), ['add','edit'])) {
  74. \think\Config::set('dispatch_success_tmpl', 'public/dispatch_jump');
  75. $id = input('param.id/d', input('param.aid/d'));
  76. ('GET' == $this->request->method()) && cookie('ENV_IS_UPHTML', 0);
  77. } else if (in_array($this->request->action(), ['index'])) {
  78. cookie('ENV_GOBACK_URL', $this->request->url());
  79. cookie('ENV_LIST_URL', request()->baseFile()."?m=admin&c={$controller_name}&a=index&lang=".$this->admin_lang);
  80. }
  81. }
  82. if ('Archives' == $controller_name && in_array($this->request->action(), ['index_archives'])) {
  83. cookie('ENV_GOBACK_URL', $this->request->url());
  84. cookie('ENV_LIST_URL', request()->baseFile()."?m=admin&c=Archives&a=index_archives&lang=".$this->admin_lang);
  85. }
  86. /* end */
  87. /*会员投稿设置*/
  88. $IsOpenRelease = Db::name('users_menu')->where([
  89. 'mca' => 'user/UsersRelease/release_centre',
  90. 'lang' => $this->admin_lang,
  91. ])->getField('status');
  92. $this->assign('IsOpenRelease',$IsOpenRelease);
  93. /* END */
  94. }
  95. public function check_priv()
  96. {
  97. $ctl = CONTROLLER_NAME;
  98. $act = ACTION_NAME;
  99. $ctl_act = $ctl.'@'.$act;
  100. $ctl_all = $ctl.'@*';
  101. //无需验证的操作
  102. $uneed_check_action = config('uneed_check_action');
  103. if (0 >= intval(session('admin_info.role_id'))) {
  104. //超级管理员无需验证
  105. return true;
  106. } else {
  107. $bool = false;
  108. /*检测是否有该权限*/
  109. if (is_check_access($ctl_act)) {
  110. $bool = true;
  111. }
  112. /*--end*/
  113. /*在列表中的操作不需要验证权限*/
  114. if (IS_AJAX || strpos($act,'ajax') !== false || in_array($ctl_act, $uneed_check_action) || in_array($ctl_all, $uneed_check_action)) {
  115. $bool = true;
  116. }
  117. /*--end*/
  118. //检查是否拥有此操作权限
  119. if (!$bool) {
  120. $this->error('您没有操作权限,请联系超级管理员分配权限');
  121. }
  122. }
  123. }
  124. /**
  125. * 保存系统设置
  126. */
  127. public function global_assign()
  128. {
  129. $this->assign('global', tpCache('global'));
  130. }
  131. /**
  132. * 多语言功能操作权限
  133. */
  134. public function language_access()
  135. {
  136. if (is_language() && $this->main_lang != $this->admin_lang) {
  137. $lang_title = model('Language')->where('mark',$this->main_lang)->value('title');
  138. $this->error('当前语言没有此功能,请切换到【'.$lang_title.'】语言');
  139. }
  140. }
  141. }