Re: Cake 1.2 Auth - Is someone logged in?
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: 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 cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: Cake 1.2 Auth - Is someone logged in?
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 cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: Cake 1.2 Auth - Is someone logged in?
Thank You! As with everything, this all seems impossible (at least daunting), until you know how. Of course, once you know how you slap your forehead and say: "Duh.". Now on to figuring out the ACL! Thanks again, B. On Aug 17, 3:36 am, francky06l <[EMAIL PROTECTED]> wrote: > TheAuthloginstores the user information in the Session (withAuth > key). > TheAuth->user() is actually a wrapper function to the sessionAuth.User key. > TheAuthlogout 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 theloginstatus. > > 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 (Authpublic variable as stated in docs) seems to always be false > > outside of actualAuthcode. > > > $this->Auth->user() : After an initiallogin, 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 &Authcomponents in $components > > >Authvariables 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()) withlogin > > status and pass it to home.ctp. > > > Changes to this file are minimal: AddedAuth& Session to $components. > > > Users_controller.php > > > TypicalAuthlogin(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 cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---