I must be missing something very basic here, because it's still not
working. Loading the home page redirects to users/login, logging in
with invalid credentials returns me to the login page with the
appropriate error, but logging in with valid credentials simply
returns me to the login page. When I login with valid credentials, I
see the /pages/home url flash briefly in the address bar. Here's my
code.
class AppController extends Controller {
var $components = array( 'Auth', 'Session' );
function beforeFilter() {
parent::beforeFilter();
$this->Auth->loginAction = array( 'controller' => 'users',
'action' => 'login' );
$this->Auth->loginRedirect = array( 'controller' => 'pages',
'action' => 'home' );
}
}
class UsersController extends AppController {
var $name = 'Users';
function beforeFilter() {
parent::beforeFilter();
$this->Auth->fields = array( 'username' => 'email', 'password' =>
'password' );
$this->Auth->loginRedirect = array( 'controller' => 'pages',
'action' => 'home' );
$this->Auth->logoutRedirect = array( 'controller' => 'pages',
'action' => 'home' );
}
function login() {
}
...
}
app/views/users/login.ctp:
<h2>Login View</h2>
<div id="login">
<?php echo $this->element( 'users/login_form' ); ?>
</div>
/app/views/elements/users/login_form.ctp:
<?php
echo $session->flash( 'auth' );
echo $form->create( 'User', array( 'action' => 'login' ) );
echo $form->input( 'email', array( 'type' => 'text' ) );
echo $form->input( 'password' );
echo $form->end( 'Login' );
?>
If I want the login and logout redirect to be the home page, are my
lines specifying that correct? I think they are. Shouldn't the auth
system only redirect to the login page if the user isn't logged in,
and since I'm not getting an login error when I login with the correct
credentials, doesn't that indicate that the login is successful? I do
get the error when using known incorrect credentials.
Thanks,
Chuck
Check out the new CakePHP Questions site http://cakeqs.org and help others with
their CakePHP related questions.
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