[Solar-talk] Verifying Login Status
Sean Montague
scene at themountainscene.com
Thu Feb 7 16:08:55 CST 2008
Thanks, I am now really look forward this. To bring it full circle, and
for any future reference for someone new to this, my logout script looks
like:
public function actionIndex() {
// Register a Solar_User object if not already.
// This will trigger the authentication process.
if (! Solar_Registry::exists('user')) {
Solar_Registry::set('user', Solar::factory('Solar_User'));
}
$user = Solar_Registry::get('user');
$user->auth->processLogout();
// For testing, I check anyway
if ($user->auth->isValid()) {
// user is logged in
} else {
$this->output = "You have successfully signed out!";
}
}
Sean
Paul M Jones wrote:
>
> On Feb 7, 2008, at 09:30 , Sean Montague wrote:
>
>> Just as a follow up, I modified my Vendor_App_Base to look like this:
>>
>> function _setup() {
>> // Register a Solar_Sql object if not already
>> if (! Solar_Registry::exists('sql')) {
>> Solar_Registry::set('sql', Solar::factory('Solar_Sql'));
>> }
>> // Register a Solar_User object if not already.
>> // This will trigger the authentication process.
>> if (! Solar_Registry::exists('user')) {
>> Solar_Registry::set('user', Solar::factory('Solar_User'));
>> }
>> $auth = Solar::factory('Solar_Auth');
>> $auth->start();
>> Solar_Registry::set('auth', $auth);
>> if (Solar_Registry::get('auth')->isValid()) {
>> // user is logged in
>> } else {
>> // user is *not* logged in
>> $uri = Solar::factory('Solar_Uri');
>> if($uri->path[0] != 'Login') {
>> ob_start();
>> header("Location: http://solartutorial/Login");
>> ob_end_flush();
>> exit;
>> }
>> }
>> }
>>
>> and it works great. Thanks!
>
> I think we can do better even than that. Instead of ...
>
> $auth = Solar::factory('Solar_Auth');
> $auth->start();
> Solar_Registry::set('auth', $auth);
> if (Solar_Registry::get('auth')->isValid()) {
> // user is logged in
> } else {
> // user is *not* logged in
>
> ... you should be able to do this:
>
> $user = Solar_Registry::get('user');
> if ($user->auth->isValid()) {
> // user is logged in
> } else {
> // user is not logged in
>
> First, the Solar_User class keeps a Solar_Auth object as a public
> property. Second, when Solar_User is instantiated (e.g., via
> Solar::factory()), it calls $this->auth->start() for you
> automatically. Take a look at the Solar_User::__construct() method
> for more information.
>
> Welcome aboard! :-)
>
>
> -- pmj
> _______________________________________________
> Solar-talk mailing list
> Solar-talk at lists.solarphp.com
> http://mailman-mail3.webfaction.com/listinfo/solar-talk
>
More information about the Solar-talk
mailing list