[Solar-talk] Verifying Login Status

Rodrigo Moraes rodrigo.moraes at gmail.com
Wed Feb 6 07:41:48 CST 2008


On Feb 1, 2008 9:07 PM, Sean Montague wrote:
> I've worked through the tutorial on http://blog.phpdeveloper.org/?p=65
> using Solar_Auth_Adapter_Sql, and I've set a session like:
>
> $session = Solar::factory('Solar_Session',
>     array('class' => 'Vendor_App_Login')
> );
> $session->store['uid'] = $auth->uid;
>
> Should I check the session in the bootstrap?

Not really, and, well, I prefer to keep the bootstrap cleaner as
possible (just setting include ptah and making a Solar front
controller call).

You can initialize the auth proccess when initializing any app, with only this:

    $auth = Solar::factory('Solar_Auth');
    $auth->start();
    Solar_Registry::set('auth', $auth);

Note that it would be better to set the auth adapter configuration in
the config file, not in the factory call as in that tutorial. This way
you can change the configuration more easily.

Then to check if the use is logged in, you can call this anywhere:
Solar_Registry::get('auth')->isValid(), like in:

if (Solar_Registry::get('auth')->isValid()) {
    // user is logged in
} else {
    // user is *not* logged in
}

Also you could use Solar_User, which wraps an auth object, plus role
and access objects. But, for a simple authentication, just registering
a start()'ed auth object as above would do the job.

-- rodrigo


More information about the Solar-talk mailing list