Questions regarding Auth component/login box as an element
Hello, I am trying to check out different php frameworks. As a first test I want to create a login box that should appear on every page of the website (that has the standard layout). If a user is not logged in, the login form should appear. If he is logged in, an appropriate message and a logout link or button should appear. I baked the Users model and controller, that worked fine. The I created an element loginbox that I refer to in my default.ctp by echo $this-element('loginbox');. For a start, loginbox.ctp simply created a login form. The password field in the database table is hashed with md5, so in the app_controller.php's beforeFIlter I execute Security::setHash ('md5');. I work on the very same database and table with a similar Zend test project, and login works fine there. But in CakePHP I have problems. First: I am not logged in. Instead I land on a page with a login box in the main content area (plus of course the login box that I constructed myself as an element). In the users_controller.php's beforeFilter I placed: $this-Auth-loginError = 'Invalid e-mail / password combination. Please try again'; But this error appears nowhere (although I places $session-flash ('auth'); in loginbox.ctp) For testing purposes I places $this-Auth-autoRedirect = false; in the users_controller.php's beforeFilter and then placed code in the login function of that controller (from here: http://www.littlehart.net/atthekeyboard/2007/09/11/a-hopefully-useful-tutorial-for-using-cakephps-auth-component/) I modified that code a little to redirect to http://www.yahoo.de when the login failed. That worked. So at least I think that the controller is used at all. But then the question is: Why does the login not work? I modified the security's hashing algorithm to MD5, so it should work. The other question is: how could I access the Auth component from a layout or an element? The loginbox.ctp should only show the login form if the user is not logged in. So I need an conditional clause in the loginbox.ctp and need to determine whether the user is logged in or not. Or alternatively I need a loginbox.ctp and a logoutbox.ctp and then in the default.ctp I place an conditional clause that either places the loginbox or the logoutbox in the header section. A third question: As I mentioned above, if I keep the autoRedirect switched on and the login fails, a login form is displayed in the main area. Though this can be a wanted behavior for some websites, just out of curiosity: How would it be done to keep the user on the actual page and let the loginbox handle the display of the error? I found this as a description of how to store the referrer into a session (http:// bin.cakephp.org/view/316159681). But then how would I tell the users_controller.php to jump to the actual page in case of a failed login attempt? Does it have to be done by switching of autoRedirect and doing it by myself in the login function? Any help or a hint would be very appreciated. Christian --~--~-~--~~~---~--~~ 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 cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Login box in layout
Thank you very much for advices, Dave! I think I'll try AJAX - it will be good practice for me ;) Cheers, Nick Dave J wrote: Hey Nick, You're right about that. I guess you can tackle it either two ways. 1) Submit the form using AJAX, so if there's any errors, you get them back without a page refresh. And on successful login, you could either hide the login form and replace it with a 'logged-in' message. Or send back a JS command to refresh the page, so the page would reflect the new logged-in status 2) Or use the flash feature of the Session Component/Helper to return any errors as soon as the page refreshes. (Just make sure you have $session-flash() somewhere in your layout) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP 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: Login box in layout
Hey Nick, You're right about that. I guess you can tackle it either two ways. 1) Submit the form using AJAX, so if there's any errors, you get them back without a page refresh. And on successful login, you could either hide the login form and replace it with a 'logged-in' message. Or send back a JS command to refresh the page, so the page would reflect the new logged-in status 2) Or use the flash feature of the Session Component/Helper to return any errors as soon as the page refreshes. (Just make sure you have $session-flash() somewhere in your layout) On Mar 23, 8:00 pm, Nick Timchenko [EMAIL PROTECTED] wrote: Yeah, I was trying it, but that way I lose any data according to validation/authentication errors. Is there any solution? Regards, Nick Dave J wrote: How about in the action which processes the form data, you pick up the referer URL ($this-referer() ) and at the end - after the user successfully authenticates - you just redirect to that URL basically leaving him on the same page. Dave --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP 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: Login box in layout
Store referer in session (if referer is different from actual action) and redirect to it when login is successful. Storing referer in session is an idea of AD7six (http://bin.cakephp.org/view/316159681) and it let you do some interesting tricks. On Sun, Mar 23, 2008 at 7:20 PM, Dave J [EMAIL PROTECTED] wrote: Hey Nick, You're right about that. I guess you can tackle it either two ways. 1) Submit the form using AJAX, so if there's any errors, you get them back without a page refresh. And on successful login, you could either hide the login form and replace it with a 'logged-in' message. Or send back a JS command to refresh the page, so the page would reflect the new logged-in status 2) Or use the flash feature of the Session Component/Helper to return any errors as soon as the page refreshes. (Just make sure you have $session-flash() somewhere in your layout) On Mar 23, 8:00 pm, Nick Timchenko [EMAIL PROTECTED] wrote: Yeah, I was trying it, but that way I lose any data according to validation/authentication errors. Is there any solution? Regards, Nick Dave J wrote: How about in the action which processes the form data, you pick up the referer URL ($this-referer() ) and at the end - after the user successfully authenticates - you just redirect to that URL basically leaving him on the same page. Dave --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP 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: Login box
Elements are the way to go, just create the loginbox element and optionbox element and switch them depending on user presence. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP 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 -~--~~~~--~~--~--~---
Login box
I have a 3 columns layout, I'm thinking on putting a login box on the right side. I want to know what is the best way to put this box there. I want to switch it to a an option box when the user logins. What do you think of this? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP 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: Login box
$this-element and requestAction On Dec 6, 2007 5:47 PM, Miguel XT [EMAIL PROTECTED] wrote: I have a 3 columns layout, I'm thinking on putting a login box on the right side. I want to know what is the best way to put this box there. I want to switch it to a an option box when the user logins. What do you think of this? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP 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 -~--~~~~--~~--~--~---