CommonController.class.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. * ==========================================================================
  6. * @link http://www.liofis.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license http://www.liofis.com/license.html License
  9. * ==========================================================================
  10. *
  11. * @author fish
  12. *
  13. */
  14. namespace Admin\Controller;
  15. use Think\Controller;
  16. class CommonController extends Controller{
  17. /* 初始化,权限控制,菜单显示 */
  18. protected function _initialize(){
  19. // 获取当前用户ID
  20. define('UID',is_login());
  21. if(!UID){// 还没登录 跳转到登录页面
  22. $this->redirect('Public/login');
  23. }
  24. /* 读取数据库中的配置 */
  25. $config = S('DB_CONFIG_DATA');
  26. if(!$config){
  27. $config = api('Config/lists');
  28. S('DB_CONFIG_DATA',$config);
  29. }
  30. C($config); //添加配置
  31. //菜单分配
  32. $notLoginModules = explode(',', C('NOT_LOGIN_MODULES'));
  33. if (!in_array(CONTROLLER_NAME, $notLoginModules)) {
  34. // 权限过滤
  35. $this->filterAccess();
  36. }
  37. }
  38. /**
  39. * 权限过滤
  40. * @return
  41. */
  42. protected function filterAccess() {
  43. if (!C('USER_AUTH_ON')) {
  44. return ;
  45. }
  46. //Admin
  47. //var_dump( \Org\Util\Rbac::AccessDecision(C('GROUP_AUTH_NAME')) );die();
  48. if (\Org\Util\Rbac::AccessDecision(C('GROUP_AUTH_NAME'))) {
  49. return ;
  50. }
  51. if (!$_SESSION [C('USER_AUTH_KEY')]) {
  52. // 登录认证号不存在
  53. return $this->redirect(C('USER_AUTH_GATEWAY'));
  54. }
  55. if ('Index' === CONTROLLER_NAME && 'index' === ACTION_NAME) {
  56. // 首页无法进入,则登出帐号
  57. D('Admin', 'Service')->logout();
  58. }
  59. return $this->error('您没有权限执行该操作!');
  60. }
  61. /* 空操作,用于输出404页面 */
  62. public function _empty(){
  63. // $this->display('Public:404');die();
  64. die('空操作');
  65. }
  66. /**
  67. *跳转控制
  68. */
  69. public function osc_alert($status){
  70. if($status['status']=='back'){
  71. $this->error($status['message']);
  72. die;
  73. }elseif($status['status']=='success'){
  74. $this->success($status['message'],$status['jump']);
  75. die;
  76. }elseif($status['status']=='fail'){
  77. $this->error($status['message'],$status['jump']);
  78. die;
  79. }
  80. }
  81. }
  82. ?>