Little hint:
You can add a $this->set into the AppController::beforeRender to
always read $this->Auth->user() and thus make its content available in
all views.
function beforeRender() {
$this->set('auth', $this->Auth->user());
}
You can also do the same for your controllers, so you have that info
in all actions too
function beforeFilter() {
$this->currentUser = $this->Auth->user();
$this->isAuthed = !empty($this->currentUser);
}
And of course you could then use $this->currentUser for your
$this->set call instead of calling $this->Auth->user() again.
function beforeRender() {
$this->set('auth', $this->currentUser);
$this->set('isAuthed', $this->isAuthed);
}
In your views you can benefit from all that like so:
<?php if ($isAuthed): ?>
<?php pr($auth); ?>
<?php endif; ?>
Happy baking :)
On Wed, Aug 27, 2008 at 9:23 PM, ar2oor <[EMAIL PROTECTED]> wrote:
>
> It's working on functions with $this->Auth->deny();
>
> but its not working on functions with $this->Auth->allow();
>
> ;/
>
> any ideas ?
>
> On 17 Sie, 12:36, francky06l <[EMAIL PROTECTED]> wrote:
>> The Auth login stores the user information in the Session (with Auth
>> key).
>> The Auth->user() is actually a wrapper function to the session
>> Auth.User key.
>> The Auth logout function delete the informations from the session.
>>
>> Knowing this, you can use the Session component in controllers and the
>> session helper in views to detect the login status.
>>
>> in controllers:
>>
>> $this->Session->check('Auth.User.id') will return true if the user is
>> logged, you can also use $this->Auth->user('id').
>>
>> in views
>>
>> $session->check('Auth.User.id') will tell you if a user is logged, and
>> you can user $session->read('Auth.User') to retrieve the user's
>> information.
>>
>> hth
>>
>> On Aug 17, 2:31 am, "Bill Brisky" <[EMAIL PROTECTED]> wrote:
>>
>> > I'm starting off with Cake and enjoying it. As confusing as the entire ACL
>> > world seems, I think I'm getting a grip on it.
>>
>> > One small current problem: How do you determine if someone is currently
>> > logged in?
>>
>> > Here is the situation: I have a simple home page (pages/home.ctp) that
>> > simply that should display a "login" link (users/login) and if no one is
>> > currently logged in, a "logout" link (users/logout). It seems simple
>> > enough
>> > however, I can't seem to find a way to determine whether or not someone is
>> > logged in.
>>
>> > $loggedIn (Auth public variable as stated in docs) seems to always be false
>> > outside of actual Auth code.
>>
>> > $this->Auth->user() : After an initial login, this always seems to return a
>> > User object properly filled out, with the exception that person had
>> > actually
>> > logged out.
>>
>> > So between an always false condition, and an always true condition, what
>> > does one do? I have a feeling I'm missing something fundamental and will
>> > be
>> > smacking my head on my desk after reading the solution.
>>
>> > More detail:
>>
>> > App_controller.php
>>
>> > Acl & Auth components in $components
>>
>> > Auth variables set in beforeFilter
>>
>> > Pages/Home.ctp
>>
>> > Typical Cake home page
>>
>> > Due to the lack of a controller (and thus a lack of access to data), I made
>> > a copy of the cake core pages_controller.php and moved it into my
>> > app/controllers directory.
>>
>> > Controllers/pages_controller.php
>>
>> > This is where I hope to set a variable (inside of display()) with login
>> > status and pass it to home.ctp.
>>
>> > Changes to this file are minimal: Added Auth & Session to $components.
>>
>> > Users_controller.php
>>
>> > Typical Auth login (no code) and logout (taken from examples).
>>
>> > Versions:
>>
>> > - Windows XP
>>
>> > - Xampp v1.6.7
>>
>> > - PHP v.5.2.6
>>
>> > - Cake v1.2.0.7296rc2
>>
>> > Any and all help will be greatly appreciated.
>>
>> > B.
>>
>>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---