<?php
/**
 * $Id: LoginController.php 969 2008-07-29 13:55:14Z pawy $
 * Kontroler autoryzacji
 *
 */
class LoginController  extends MainController implements ControllerInterface {
	/**
	 * domyslna metoda
	 *
	 */
	public function IndexAction($param) {

	}

	/**
	 * Autoryzacja
	 *
	 */
	public function AuthAction($param) {

		if(isset($_REQUEST['eLogin']) && isset($_REQUEST['ePassword'])){
			$result = AuthDAL::Login($_REQUEST['eLogin'], $_REQUEST['ePassword']);
			//Utils::ArrayDisplay($_REQUEST);
			Utils::ArrayDisplay($result);
			if($result == true){
				//$logger = LoggerManager::getLogger(__CLASS__);
				//$logger->info('Zalogowal sie uzytkownik: '.$_REQUEST['eLogin'].', z ip: '.getenv('REMOTE_ADDR').', z domeny: '.getenv('REMOTE_HOST'));
				Header("Location: ". Router::GenerateUrl('indexURL', array('Index' => 'Index')) );
			} else {
				$this->smarty->assign("loginError", "1");
			}
		}
	}

	/**
	 * Wylogowanie
	 *
	 */
	public function LogoutAction($param) {
		SessionProxy::ClearSession();
		AuthDAL::Logout();

		die(Header("Location: login".APPLICATION_FILE_TYPE));
	}

	/**
	 * Wspolna metoda
	 *
	 */
	public function preDispatch($param) {
		$this->smarty->assign('projectName', PROJECT_NAME);
		//session_start();
		$template = 'login.tpl';
		Registry::Remove('smartyTemplate');
		Registry::Set('smartyTemplate', $template);
		$this->smarty->assign("loginError", "");
		
	}

	public function postDispatch($param)
	{
		
	}
}
?>