senses-designertravelv3 /application/hooks/precontrollerhook.php

Language PHP Lines 126
MD5 Hash 8a29e185b0dc9ab0f7a30b7dc99a1bf9 Estimated Cost $1,880 (why?)
Repository https://bitbucket.org/matyhaty/senses-designertravelv3 View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
/**
 * checkAccess
 *
 */

define('ADMIN_USER_TYPE', 9);

class preControllerHook extends MX_Controller
{

	/**
	 * Enter description here...
	 *
	 */
	function __construct()
	{
		parent::__construct();
	}

	/**
	 * should be checked against routes,
	 *
	 */
	function checkAccess()
	{
		if ($this -> uri -> segment(1) == 'admin')
		{
			log_message('info', '--------------- Check Access ------------------');
			log_message('info', $_SERVER['PHP_SELF']);
			log_message('info', '-----------------------------------------------');

			$this -> load -> library('session');
			$this -> load -> helper(array(
				'password_helper',
				'url'
			));

			$perms = array();
			$loggedIn = false;
			$myFriends = array();
			$this -> user = $user = new User();

			if ($session_user = isLoggedIn($this -> session))
			{
				//print_r( $session_user);
				// user is logged in, lets check their state
				$user = $this -> tank_auth -> is_logged_in($session_user, 'Active', $this -> cache);

				

				// will return user dm object is they are active
				if ($this -> router -> method == 'activate')
					return;
				elseif (!$user && $this -> router -> method != 'send_again' && $this -> router -> method != 'logout') 
				{
					//echo $this -> router -> method;
					//echo '<hr>';
					//echo $this -> router -> class;
				    return redirect('admin/user/auth/send_again');
				}
				// check the user state against active
				elseif ($this -> router -> method == 'send_again' && $user)
				{
					return redirect('admin/user/profile/index');
				}
				else
					$loggedIn = true;

				if ($user)
				{
					//$subscription		= new Subscription();
					//$myFriends 			= $subscription->getFriends( $user );
					// friends should be available with in the apps, nice as they will be cahced!
				}
			}

			if (!$user instanceof DataMapper)
				$user = $this -> user;
			// set the user back to the DM

			$CI = &get_instance();
			//$CI -> firephp -> error("PRECONTROLLER");
			$hasAccess = check_permissions($user);
			//$CI -> firephp -> error("PRECONTROLLER END");

			// if page was not redirected by fail or success hooks
			if ($hasAccess === false)
			{
				//echo 'N ACCESS';
				return redirect('home/noaccess');
			}
			elseif ($hasAccess === 'must_be_logged_in')
			{
				$this -> session -> set_flashdata('message', 'You need to be logged in!');
				return redirect('admin/login');
			}
			elseif ($hasAccess === 'must_be_logged_out')
			{
				$this -> session -> set_flashdata('message', 'You are already logged in');
				return redirect('admin/home');
			}
			else
			{
				$this -> CI = get_instance();
				$this -> CI -> perms = $perms;
				//$this->CI->myFriends = $myFriends;
				$this -> CI -> loggedIn = $loggedIn;
				$this -> CI -> session_user = $session_user;
				$this -> CI -> user = $user;
			}

			if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == "XMLHttpRequest")
			{
				$this -> CI -> is_ajax = true;
			}
			else
			{
				$this -> CI -> is_ajax = false;
			}
		}

	}

}
?>
Back to Top