Re: Login script and posting

Dan Rossi <liveuser-zu2dZaOKXTSc5qR/[email protected]>
Newsgroups gmane.comp.php.pear.liveuser
Message-ID <[email protected]>
On 21/06/2005, at 3:05 AM, Lukas Smith wrote:

> Dan Rossi wrote:
>
>> Here is my event dispatcher class, i may need to try and find the   
>> method which is used  when catching someone has not logged in and   
>> forcing them to login, but before forcelogin, as that is what i used   
>> for the login form :) I could use forcelogin as a method to redirect  
>> to  the actual login form ??
>
> err .. why do you need an event before forceLogin? .. that makes no  
> sense to me. do you just want to have the forceLogin event to be fired  
> twice? if so you can register multiple event handler and they will be  
> called in the order they have been registered.
>

I require an event before forceLogin to do redirects, ie you have one  
for a logout postLogout which can be used for redirects. The login  
redirect is to redirect to a login script. Now what the issue is say my  
index.php page calls the forcelogin which displays a form, I post back  
to index.php to login, my index.php is loading a class which has a  
methods to handle get and post, it will trigger the post method in the  
index.php file too :)


Now say I made a redirect in forceLogin to login.php and my login.php  
also requires the login class its redirecting itself. I am attempting  
to get the login script which is posting to itself to use a different  
events class to the rest of the scripts. However somehow now even using  
the right login details i am getting a forceLogin when it was working  
last night :|


LiveUser class

class Feeds_Admin_LiveUser extends Feeds {

	function Feeds_Admin_LiveUser()
	{
		parent::Feeds();	
		$this->tpl = new HTML_Template_Flexy($this->settings['flexy']);
		
		$options = &PEAR::getStaticProperty('DB_DataObject','options');
		$options = $this->settings['DB_DataObject'];
	
		$this->_db =  
MDB2::connect($this->settings['LiveUser']['dsn'],$this- 
 >settings['DB_DataObject']['MDB2']);
		$this->_db->setFetchMode(MDB2_FETCHMODE_ASSOC);
		
		//HTTP_Session::useCookies(true);
		//HTTP_Session::start();
		//HTTP_Session::setExpire(60*60*24);
		//HTTP_Session::setIdle(300);
		
		$GLOBALS['_LIVEUSER_DEBUG'] = true;
		$this->conf =
			    array(
			        'autoInit' => false,
			        'session'  => array(
			            'name'     => 'PHPSESSION',
			            'varname'  => 'ludata'
			        ),
			        'cache_perm' => true,
			        'cookie'            => array(
				        'name' => 'loginInfo',
				        'path' => null,
				        'domain' => null,
				        'secure' => false,
				        'lifetime' => 30,
				        'secret' => 'mysecretkey',
				        'savedir' => '.',
				    ),
			        'login' => array(
			            'force'    => true,
			        ),
			        'logout' => array(
			            'destroy'  => true,
			        ),
			        'authContainers' => array(
			            'DB_Local' => array(
			                'type' => 'MDB2',
			                'loginTimeout'  => 0,
			                'expireTime'    => 3600,
			                'idleTime'      => 1800,
			                'allowDuplicateHandles' => true,
			                'passwordEncryptionMode' => 'MD5',
			                'storage' => array(
			                    'connection' => $this->_db,
			                    'dsn' => $this->settings['LiveUser']['dsn'],
			                    'prefix' => 'liveuser_',
			                    'tables' => array(
			                        'users' => array(
			                            'fields' => array(
			                                'name' => false,
			                                'email' => false,
			                            ),
			                        ),
			                    ),
			                    'fields' => array(
			                        'name' => 'text',
			                        'email' => 'text',
			                    ),
			                    'alias' => array(
			                        'name' => 'name',
			                        'email' => 'email'
			                    ),
			                    // 'force_seq' => false
			                ),
			            )
			        ),
			        'permContainer' => array(
			            'type'  => 'Complex',
			            'alias' => array(),
			            'storage' => array(
			                'MDB2' => array(
			                    'connection' => $this->_db,
			                    'dsn' => $this->settings['LiveUser']['dsn'],
			                    'prefix' => 'liveuser_',
			                    'tables' => array(),
			                    'fields' => array(),
			                    'alias' => array(),
			                    // 'force_seq' => false
			                ),
			            ),
			        ),
			    );
			
				$this->admin =& LiveUser_Admin::factory($this->conf);
				$logconf = array('mode' => 0666, 'timeFormat' => '%X %x');
				$logger = &Log::factory('file', 'liveuser_test.log', 'ident',  
$logconf);
				$this->admin->addErrorLog($logger);
				$this->admin->setAdminContainers();
	}
}

Login script class

class Feeds_Admin_LiveUser_Login extends Feeds_Admin_LiveUser {

	function Feeds_Admin_LiveUser_Login()
	{
		parent::Feeds_Admin_LiveUser();
		$this->liveuser =& LiveUser::factory($this->conf);



		$this->liveuser->dispatcher- 
 >addObserver(array($this,'get'),null,'LiveUser');

		$username = (isset($_POST['username'])) ? $_POST['username'] : null;
		$password = (isset($_POST['password'])) ? $_POST['password'] : null;
		$remember = (isset($_POST['remember'])) ? $_POST['remember'] : null;
		$logout = (isset($_GET['logout'])) ? $_GET['logout'] : null;
		$this->liveuser->init($username, $password, $logout, $remember);
	}
	
	function get($notification)
	{
		//echo $notification->getNotificationName();
		$this->{$notification->getNotificationName()}($notification);
	}
	
	function onUnfreeze()
	{
		
	}
	
	function postLogout()
	{
		//die("yes");
		HTTP::redirect('login.php');
	}
	
	
	function onIdled()
	{
		die("yes");	
	}
	
	function onLogout()
	{
		//die("logout");	
	}
	
	function onLogin()
	{	


		if (!isset($_SESSION['customerID'])) {
			$this->do = DB_DataObject::factory('users_join');
			$_SESSION['customerID'] =  
$this->do->getCustomerID($_SESSION['ludate']['admin']['authUserId']);
			
		
		}
	}
	
	function onFailedLogin($notification)
	{
		die("yes");
		//$this->liveuser = $notification->getNotificationObject();
	}
	

	
	function forceLogin(&$notification)
     {
		
		
		//$form = new HTML_QuickForm('liveuser','post','logincheck.php');
		$form = new HTML_QuickForm();
		$form->addElement('text','handle','Username');
		$form->addElement('password','passwd','Password');
		$form->addElement('checkbox','remember','Remember Login?');
		$form->addElement('submit','login','Login');
		
		$renderer =& new HTML_QuickForm_Renderer_Object(true);
		$form->accept($renderer);
		
	
		$this->form = $renderer->toObject();
		

		$this->tpl->compile('login_main.html');
		$this->tpl->outputObject($this);
		exit;
		
		
     }

     function messageHandler()
     {
     		return $this->liveuser->statusMessage($this->liveuser->status);
     }

	
}

Other Liveuser events class:

class Feeds_Admin_LiveUser_Events extends Feeds_Admin_LiveUser {

	function Feeds_Admin_LiveUser_Events()
	{
		parent::Feeds_Admin_LiveUser();
		$this->liveuser =& LiveUser::factory($this->conf);



		$this->liveuser->dispatcher- 
 >addObserver(array($this,'get'),null,'LiveUser');

		$username = (isset($_POST['username'])) ? $_POST['username'] : null;
		$password = (isset($_POST['password'])) ? $_POST['password'] : null;
		$remember = (isset($_POST['remember'])) ? $_POST['remember'] : null;
		$logout = (isset($_GET['logout'])) ? $_GET['logout'] : null;
		$this->liveuser->init($username, $password, $logout, $remember);
	}
	
	function get($notification)
	{
		//echo $notification->getNotificationName();
		$this->{$notification->getNotificationName()}($notification);
	}
	
	function onUnfreeze()
	{
		
	}
	
	function postLogout()
	{
		//die("yes");
		HTTP::redirect('login.php');
	}
	
	
	function onIdled()
	{
		die("yes");	
	}
	
	function onLogout()
	{
		//die("logout");	
	}
	
	
	function onFailedLogin($notification)
	{
		die("yes");
		//$this->liveuser = $notification->getNotificationObject();
	}
	

	
	function forceLogin(&$notification)
     {
		HTTP::redirect('login.php');
     }

     function messageHandler()
     {
     		return $this->liveuser->statusMessage($this->liveuser->status);
     }

	
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.