Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-13-2008, 02:04 PM
Junior Member
 
Join Date: Apr 2008
Posts: 7
Question Getting a Session set by Zend Auth

Hello,

I have a login Controller that uses an Zend Auth to authentcate the user.

I have a UserClass that is called in the bootstrap file that I need to look for the Zend Auth Session. If I print the session I can see the data after I am authenticated in the UserClass but I do not want to call it using.

PHP Code:
 $_SESSION 

I might be little simple here but I can not see a way to access that session using Zend_Session without doing

PHP Code:
<?php

$authSesssion 
=  Zend_Session::namespaceGet('Zend_Auth');

?>
This above is DEPRECATED according to the docs so I do nto want to use it.

Please help
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 05-13-2008, 02:42 PM
Junior Member
 
Join Date: Mar 2008
Posts: 26
Default

try this:

PHP Code:
// bootstrap file (usually index.php):
// setup application authentication
$auth Zend_Auth::getInstance();
$auth->setStorage(new Zend_Auth_Storage_Session()); 
everything stays in sessions and recovers every request
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-13-2008, 02:55 PM
Junior Member
 
Join Date: Apr 2008
Posts: 7
Default Found the answer for me!!

Hello,

It is always the way that writing your problem down helps solve it.

If you do the following

PHP Code:
$auth Zend_Auth::getInstance();
$adapter = new Zend_Auth_Adapter_Ldap($options$username$password);

try {
        
$result $auth->authenticate($adapter);
    }
    catch (
Zend_Auth_Adapter_Exception $e)
    {
            print 
$e;
    }

$result->isValid() 
This does the check and if the user is valid creates a Session with the NameSpace of Zend_Auth

All you then need to do is create a new Zend_Session object with the namespace of Zend_Auth.

I used the code below to extract the userid of the authenticated login

PHP Code:

    $auth 
= new Zend_Session_Namespace('Zend_Auth');

    
### CHECK IF USER IS AUTHENTICATED ###
    
if (isset($auth->storage))
    {
        
$User $auth->storage;
    }
    else 
    {
        
$User 'nobody';
    } 
Thanks

Madmaxious
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 05-28-2008, 09:18 AM
Junior Member
 
Join Date: May 2008
Posts: 5
Arrow

I used:
$auth->setStorage(new Zend_Auth_Storage_Session('admin'));
$result = $auth->authenticate($adapter);
...


Than later after success authenticate:
$data = $adapter->getResultRowObject(null, 'password');
$auth->getStorage()->write($data);

Can I use following to access the saved data?

$auth = new Zend_Session_Namespace('admin');
hello, $auth->admin_firstname


admin_firstname is a column in the admin table.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 11:39 AM.