Your IP : 216.73.216.90


Current Path : /home/semix18/public_html/optimum-wycena.pl/modules/Auth/
Upload File :
Current File : /home/semix18/public_html/optimum-wycena.pl/modules/Auth/Auth.php

<?php

if (!defined('LOADED_AS_NORMAL_MODULE'))
{ 
	require_once('../../core/Dobi.php');  
	Dobi::exception('dobiExcDirectAccess', FATAL, '', 'direct');
}

class Auth implements DobiModule 
{
	 private $auth_instance_handler;
	 private $auth_current_action_to_run;
	
	 public function __construct($user_current_action_to_run)
	 {
	 	$this->auth_current_action_to_run = $user_current_action_to_run; 
	 	$this->auth_instance_handler['session'] = Registry::getObject('session');
	 	$this->auth_instance_handler['dataRequest'] = Registry::getObject('dataRequest');	 	
	 }
		 
	 public function _executeAction()
	 {
	 	$go = $this->auth_current_action_to_run;
	 	$this->$go();	
	 }
	 
	 public function _defaultAction()
	 {
	    return $this->loginForm();
	 }
	 
 	 public function _getTitle()
	 {
	    return _AUTH_TITLE_;
	 }	
	  
 	 public function _getModuleTitle()
	 {
	    return _AUTH_MTITLE_;
	 }
	 		
	 public function login()
	 {
	 	$login = $this->auth_instance_handler['session']->loginIn(
		 				 $this->auth_instance_handler['dataRequest']->getValue('ulogin'),
						 $this->auth_instance_handler['dataRequest']->getValue('upassword'),
						 $this->auth_instance_handler['dataRequest']->getValue('uremember')); 
        $level = (int)$this->auth_instance_handler['session']->getUserLevel();
     
	    if ($login && ($level & LA_INFORMATION)) 
        {
        	header('Location: admin.php');
        }
        elseif (!$login) 
        {
        	include('modules/Auth/tpl.login_failed.php');
		}
        else 
        {
            header('refresh: 3; url=index.php');
            $username = $this->auth_instance_handler['session']->getUserLogin();
            include('modules/Auth/tpl.login_true.php');		  	 		
        }		
	 }
	  
	 public function logout()
	 {
	 	$this->auth_instance_handler['session']->logout();
	 	include('modules/Auth/tpl.logout.php');
	 }
	 
     public function loginForm($register_error='',$user='')
     {	 
     	if ($this->auth_instance_handler['session']->isLoggedIn())
	 	{
	 	    $level = (int)$this->auth_instance_handler['session']->getUserLevel();
	    	if ($level & LA_INFORMATION) 
        	{
        		header('Location: admin.php');
        	}	
			 	    
	 		header('refresh: 2; url=index.php');
	 		$username = $this->auth_instance_handler['session']->getUserLogin();
	 		include('modules/Auth/tpl.loginForm.php'); 
	 	}
	 	else 
	 	{
      	 	$db = Registry::getObject('db');
    		$content = $db->getTranslation('Auth');
			if ($content != '') {
				include('modules/Auth/tpl.content.php');		
			}
     		include('modules/Auth/tpl.loginForm2.php'); 
			$form = new form('loginForm','index.php?module=Auth');
			$form->fieldset('user');
			$form->legend(_AUTH_LEGEND_);
     		$form->setSeparator('<br />');
     		
     		if (isset($register_error)) echo $register_error;
     		
     		$form->setSize(10);
			$form->text(_AUTH_ULOGIN_, 'ulogin', $user['ulogin']);
			$form->password(_AUTH_PASS_, 'upassword', $user['upassword']);
			$form->checkbox(_AUTH_REMEMBER_, 'uremember', 1, 'checkbox', 'checkbox');
			$form->hidden('action', 'login');
     		$form->submit(_AUTH_LOGIN_, 'inputSubmit');
     		$form->eFieldset();
     		echo $form->getForm();	
	 	}
     }
     
     public function change($register_error='')
     {
        if ($this->auth_instance_handler['session']->isLoggedIn())
        {
            include('modules/Auth/tpl.change.php'); 
			$form = new form('loginForm','index.php?module=Auth');
			$form->fieldset('user');
			$form->legend(_AUTH_CHANGE_LEGEND_);
     		$form->setSeparator('<br />');
      		
     		if (isset($register_error)) echo $register_error;
     		
     		$form->setSize(10);
			$form->password(_AUTH_OLDPASS_, 'oldpass');
			$form->password(_AUTH_NEWPASS_, 'newpass');
			$form->password(_AUTH_NEWREPASS_, 'newrepass');
			$form->hidden('action', 'executeChange');
     		$form->submit(_AUTH_SET_, 'inputSubmit');
     		$form->eFieldset();
     		echo $form->getForm();    		
		 }
		 else $this->loginForm();			 
	 }
     
     public function executeChange()
     {
	 	$uid = $this->auth_instance_handler['session']->getUserID();
		$error = Registry::getObject('error');
	  	$error->addAction('change', 'index.php');
	  	$error->setTrueMessage(_UCHANGE_SUCC_);
	  	$error->setFalseMessage(_UCHANGE_FAIL_ . _ERRORS_OCCURRED_);

    	$dbRC = Registry::getObject('dbRC');			
    	$dbRC->rowCache('user_exists', 'user_id, user_password', 'users', 'user_id = "'.$uid.'"');
    	$dbRC->setName('user_exists');

		if ($dbRC->getRowsAmount() == 0)
        { 
        	include('modules/Auth/tpl.no_user.php');
         	return;
		}
		
		if ($dbRC->getRow('user_password') !== sha1($this->auth_instance_handler['dataRequest']->getValue('oldpass')))
		{
			$error->addError(_UCHANGE_ERR_1_);
		}

		$dbUDECA = Registry::getObject('dbUDECA');
		$dbUDECA->setMapper(true);
		$dbUDECA->mapper(IS_REQUIRED | FILTR_TH, array('oldpass', 'newpass', 'newrepass'));
		
		if ($dbUDECA->getMapped('newpass') !== $dbUDECA->getMapped('newrepass'))
		{
			$error->addError(_UCHANGE_ERR_2_);		
		}

		$dbUDECA->setWhere('user_id="'.$uid.'"');
		$dbUDECA->update('users', array('user_password' => sha1($dbUDECA->getMapped('newpass'))));		
		$dbUDECA->execute();
		$dbUDECA->clear();
		$dbRC->clear();
		$error->getErrors();
	 }          
}

?>