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 5:53 PM, Lukas Smith wrote:
>
> thats why i dont like event based programming.
> anyways you can get the liveuser instance inside your event handler.
> so you should be able to modify the observers inside any event. at the
> same time you could store some property inside your observers to
> handle this.
>
> here are the docs for the event dispatcher
> http://pear.php.net/manual/en/package.event.event-dispatcher.php
>
>
Yeh i get how it works, I have two differen classes, maybe the way I do
it is bending the rules as always ! I have run into issues now, I got
my login script which is used for posting, it executess the onLogin
method which then does a redirect to index.php. However my index.php is
running a different events class, the login is expiring somehow so is
forcing a login there. And then on the login events class its calling
onUnfreeze coz i've already logged in !
Maybe the init function is not for me and I should use a login method
instead to post the login details then redirect somewhere ? Coz its
limitation is that its posting to PHP_SELF.
Here are the classes again.
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($notification)
{
//HTTP::redirect('index.php');
}
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']);
}
HTTP::redirect('index.php');
}
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','username','Username');
$form->addElement('password','password','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);
}
}
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(null, null, $logout, null);
}
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);
}
}