Location: PHPKode > projects > Anahita Social Engine > dependencies/plg_system_socialengine/socialengine/uikit/controller/authenticate.php
<?php

class AnUikitControllerAuthenticate extends KMixinAbstract
{
	/**
	 * Login page url
	 * 
	 * @var string
	 */
	static protected $_auth_url = 'index.php?option=com_user&view=login';
	
	/**
	 * Set the redirect url to login. It defaults to the Joomla login page
	 * @return 
	 * @param $url Object
	 */	
	static public function setAuthendicationUrl($url)
	{
		self::$_auth_url = $url;
	}
			
	/**
	 * Register authenticate filter for the actions passed in. If ther are no actions passed in
	 * then the filter will run for all the actions
	 * @return 
	 * @param $actions Object[optional]
	 */
	public function registerAuthentication($actions=array(), $message = null)
	{
		settype($actions, 'array');

		if ( !count($actions) )
			$actions = $this->_mixer->getActions();
		
		$this->_mixer->registerFunctionBefore($actions, 'authenticate', array($message));
	}
	
	/**
	 * Authenticate the user and depending the type of requet it renders a message. If the request is 
	 * ajax , it opens a modal with a message otherwise it would redirect the user to the login page
	 * @return 
	 * @param $message Object[optional]
	 */
	public function authenticate()
	{							
		if ( $this->_mixer->getViewer()->isGuest() ) {
			
			$url    = self::$_auth_url;
			
			if ( KRequest::referrer() )
				$url .= '&return='.base64_encode(KRequest::referrer());
							
			if ( KRequest::type() == 'AJAX' ) 
			{				
				$message = KFactory::get('lib.anahita.uikit.prompt.message')->setBody(JTExt::_('AN-SE-PLEASE-LOGIN-TO-SEE'));
				KFactory::get('lib.anahita.uikit.modal')
				->setBody( $message )
				->addButton(JText::_('AN-SE-LOGIN'), array('onclick'=>'document.location=\''.$url.'\''))
				->setCancelButtonLabel(false)
				->open()
				;
				
			} else 
			{							
				$message = !$message ? JText::_('AN-SE-PLEASE-LOGIN-TO-SEE') : $message;				
				$this->_mixer->setRedirect($url, $message);
			}
			
			return false;
		}
		
		return true;
	}	
}
Return current item: Anahita Social Engine