views:

35

answers:

2

I have something that I thought was a relatively common problem, but after researching the issue, it appears not to be as easy as thought.

I have a CakePHP application (using version 1.2.7) and I am trying to change the standard login procedure using the Auth Component. I would like to use a persistent login screen ( like this Jquery plugin : http://web-kreation.com/demos/Sliding_login_panel_jquery/ ) which my users would use to login.

In Cake terminology, I would like to be able to login to the Auth component from the /pages/home screen but Cakephp keeps redirecting to the /users/login.

In My App Controller :

 function beforeFilter()
 {
  ...
  $this->Auth->loginAction = array( 'controller' => 'users', 'action' => 'login' );
  $this->Auth->loginRedirect = array( 'controller' => 'pages', 'action' => 'home' );
  $this->Auth->logoutRedirect  = array( 'controller' => 'pages', 'action' => 'home' );
  $this->Auth->autoRedirect = false;
  ...
 }

If I change the loginAction to /pages/home. the login does not work, in fact it does not even post to the /users/login method. Not exactly sure what has happened.

My question is this :

How do I make a login form located at www.EXAMPLE.com/ which will return to the same location on successful and unsuccessful login?

I would prefer not to have it redirect to /users/login or have that show up in the URL at all.

+1  A: 

If you set $this->Auth->autoRedirect to false then you must redirect manually in your login() method. Take a look at this also.

bancer
I have tried to do this. It is not a matter of the form not loading. It is a matter of the black magic Cake is doing on the login. I mentioned the details in a comment below but these are related ideas. When I have the form post to the /users/login method, for some reason the actual call is never made to the login function.I can only assume that it is related or protected by Cake's Auth because as soon as I change the loginAction to the /users/login, everything magically connects up and runs without issue.
Todd
So, what is the problem if it runs without issue? If you want to login user you must submit the login form somewhere. `$this->Auth->loginAction` is the method that handles the login logic. It can be named as you want, f.ex. `enter()`. Your form must submit to THAT action - the one you specify in loginAction. Do login logic there and redirect to home on success and failure. It does not work if you set loginAction to one method and submit your form to another.
bancer
A: 

To change where the form submits just changed the submit url in your form, it's that simple.

$form->create('User', array('url'=>array('controller'=>'users','action'=>'login')))

Then you can load your page, and check the action attribute, and you should see your /users/login :)

DavidYell
Thanks for the response. I have tried before and confirmed the form posts to the correct controller but this where the odd behavior begins. The actual method in the controller is never called. I confirm this by commenting out all of the code in the method and only adding a logging call.Any ideas if this is protected by Cake's Auth in any way?
Todd
If you are using Auth component, you dont need any code in your login method. It can be blank, try clearning all the code and using a blank function to eliminate your code as an issue.
DavidYell