PageRenderTime 54ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/application/hooks/precontrollerhook.php

https://bitbucket.org/matyhaty/senses-designertravelv3
PHP | 126 lines | 81 code | 17 blank | 28 comment | 17 complexity | 8a29e185b0dc9ab0f7a30b7dc99a1bf9 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0
  1. <?php
  2. /**
  3. * checkAccess
  4. *
  5. */
  6. define('ADMIN_USER_TYPE', 9);
  7. class preControllerHook extends MX_Controller
  8. {
  9. /**
  10. * Enter description here...
  11. *
  12. */
  13. function __construct()
  14. {
  15. parent::__construct();
  16. }
  17. /**
  18. * should be checked against routes,
  19. *
  20. */
  21. function checkAccess()
  22. {
  23. if ($this -> uri -> segment(1) == 'admin')
  24. {
  25. log_message('info', '--------------- Check Access ------------------');
  26. log_message('info', $_SERVER['PHP_SELF']);
  27. log_message('info', '-----------------------------------------------');
  28. $this -> load -> library('session');
  29. $this -> load -> helper(array(
  30. 'password_helper',
  31. 'url'
  32. ));
  33. $perms = array();
  34. $loggedIn = false;
  35. $myFriends = array();
  36. $this -> user = $user = new User();
  37. if ($session_user = isLoggedIn($this -> session))
  38. {
  39. //print_r( $session_user);
  40. // user is logged in, lets check their state
  41. $user = $this -> tank_auth -> is_logged_in($session_user, 'Active', $this -> cache);
  42. // will return user dm object is they are active
  43. if ($this -> router -> method == 'activate')
  44. return;
  45. elseif (!$user && $this -> router -> method != 'send_again' && $this -> router -> method != 'logout')
  46. {
  47. //echo $this -> router -> method;
  48. //echo '<hr>';
  49. //echo $this -> router -> class;
  50. return redirect('admin/user/auth/send_again');
  51. }
  52. // check the user state against active
  53. elseif ($this -> router -> method == 'send_again' && $user)
  54. {
  55. return redirect('admin/user/profile/index');
  56. }
  57. else
  58. $loggedIn = true;
  59. if ($user)
  60. {
  61. //$subscription = new Subscription();
  62. //$myFriends = $subscription->getFriends( $user );
  63. // friends should be available with in the apps, nice as they will be cahced!
  64. }
  65. }
  66. if (!$user instanceof DataMapper)
  67. $user = $this -> user;
  68. // set the user back to the DM
  69. $CI = &get_instance();
  70. //$CI -> firephp -> error("PRECONTROLLER");
  71. $hasAccess = check_permissions($user);
  72. //$CI -> firephp -> error("PRECONTROLLER END");
  73. // if page was not redirected by fail or success hooks
  74. if ($hasAccess === false)
  75. {
  76. //echo 'N ACCESS';
  77. return redirect('home/noaccess');
  78. }
  79. elseif ($hasAccess === 'must_be_logged_in')
  80. {
  81. $this -> session -> set_flashdata('message', 'You need to be logged in!');
  82. return redirect('admin/login');
  83. }
  84. elseif ($hasAccess === 'must_be_logged_out')
  85. {
  86. $this -> session -> set_flashdata('message', 'You are already logged in');
  87. return redirect('admin/home');
  88. }
  89. else
  90. {
  91. $this -> CI = get_instance();
  92. $this -> CI -> perms = $perms;
  93. //$this->CI->myFriends = $myFriends;
  94. $this -> CI -> loggedIn = $loggedIn;
  95. $this -> CI -> session_user = $session_user;
  96. $this -> CI -> user = $user;
  97. }
  98. if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == "XMLHttpRequest")
  99. {
  100. $this -> CI -> is_ajax = true;
  101. }
  102. else
  103. {
  104. $this -> CI -> is_ajax = false;
  105. }
  106. }
  107. }
  108. }
  109. ?>