src/ChickenWire/Controller.php
private function _checkAuth()
		{

			// Not needed?
			if (!isset(static::$requiresAuth) || is_null(static::$requiresAuth) || empty(static::$requiresAuth)) {
				return true;
			}

			// Get auth
			$auth = static::$requiresAuth;

			// Is there an except clause?
			if (is_array($auth) && array_key_exists("except", $auth)) {

				// Is my method in it?
				if (in_array($this->route->action, $auth['except'])) {
					return true;
				}

			}

			// Is there an only clause?
			if (is_array($auth) && array_key_exists("only", $auth)) {

				// Is it an array?
				if (!is_array($auth['only'])) {
					$auth['only'] = array($auth['only']);
				}

				// Is my method in it?
				if (!in_array($this->route->action, $auth['only'])) {
					return true;
				}

			}

			// Get auth name
			$authName = is_array($auth) ? $auth[0] : $auth;

			// Find auth object
			$this->auth = Auth::get($authName);

			// Is it authenticated?
			if ($this->auth->isAuthenticated() !== true) {

				// Store last page :)
				$this->auth->rememberPage($this->request->uri);

				// Redirect to login page
				if (!is_null($this->auth->loginAction)) {
					$this->_invokeAuthLoginAction();
				} else {
					$this->redirect($this->auth->loginUri);
				}
				return false;

			} else {

				// We're in!
				return true;

			}


		}
private function _checkAuth()
		{

			// Not needed?
			if (!isset(static::$requiresAuth) || is_null(static::$requiresAuth) || empty(static::$requiresAuth)) {
				return true;
			}

			// Get auth
			$auth = static::$requiresAuth;

			// Is there an except clause?
			if (is_array($auth) && array_key_exists("except", $auth)) {

				// Is my method in it?
				if (in_array($this->route->action, $auth['except'])) {
					return true;
				}

			}

			// Is there an only clause?
			if (is_array($auth) && array_key_exists("only", $auth)) {

				// Is it an array?
				if (!is_array($auth['only'])) {
					$auth['only'] = array($auth['only']);
				}

				// Is my method in it?
				if (!in_array($this->route->action, $auth['only'])) {
					return true;
				}

			}

			// Get auth name
			$authName = is_array($auth) ? $auth[0] : $auth;

			// Find auth object
			$this->auth = Auth::get($authName);

			// Is it authenticated?
			if ($this->auth->isAuthenticated() !== true) {

				// Store last page :)
				$this->auth->rememberPage($this->request->uri);

				// Redirect to login page
				if (!is_null($this->auth->loginAction)) {
					$this->_invokeAuthLoginAction();
				} else {
					$this->redirect($this->auth->loginUri);
				}
				return false;

			} else {

				// We're in!
				return true;

			}


		}
private function _checkAuth ( ) { // Not needed? if ( ! isset ( static :: $ requiresAuth ) || is_null ( static :: $ requiresAuth ) || empty ( static :: $ requiresAuth ) ) { return true ; } // Get auth $ auth = static :: $ requiresAuth ; // Is there an except clause? if ( is_array ( $ auth ) && array_key_exists ( "except" , $ auth ) ) { // Is my method in it? if ( in_array ( $ this -> route -> action , $ auth [ 'except' ] ) ) { return true ; } } // Is there an only clause? if ( is_array ( $ auth ) && array_key_exists ( "only" , $ auth ) ) { // Is it an array? if ( ! is_array ( $ auth [ 'only' ] ) ) { $ auth [ 'only' ] = array ( $ auth [ 'only' ] ) ; } // Is my method in it? if ( ! in_array ( $ this -> route -> action , $ auth [ 'only' ] ) ) { return true ; } } // Get auth name $ authName = is_array ( $ auth ) ? $ auth [ 0 ] : $ auth ; // Find auth object $ this -> auth = Auth :: get ( $ authName ) ; // Is it authenticated? if ( $ this -> auth -> isAuthenticated ( ) !== true ) { // Store last page :) $ this -> auth -> rememberPage ( $ this -> request -> uri ) ; // Redirect to login page if ( ! is_null ( $ this -> auth -> loginAction ) ) { $ this -> _invokeAuthLoginAction ( ) ; } else { $ this -> redirect ( $ this -> auth -> loginUri ) ; } return false ; } else { // We're in! return true ; } }
Check if current action needs authentication, and if it is validated
@return boolean Whether authentication passed
Check if current action needs authentication and if it is validated