On Tue, Dec 28, 2010 at 11:58 PM, John Maxim <[email protected]> wrote:
> Users_controllers.php:
> ~~~~
>
> var $name = 'Users';
>
> /*some codes in between*/
>
> function login()
> {
> if(!empty($this->data))
> {
> // If the username/password match
> if($this->Auth->login($this->data))
> {
> $this->redirect(array('action' => 'index'), null,
> true);
> } else {
> $this->User->invalidate('username', 'Username and password
> combination is incorrect!');
> }
> }
> }
>
The code in your login method does basically what Auth would do if
left to its own devices. You could get the same functionality as above
by setting the following in AppController's beforeFilter method:
// this tells Auth to handle redirects
$this->Auth->autoRedirect = true;
// this tells Auth where to send the user
$this->Auth->loginRedirect = array(
'controller' => 'posts',
'action' => 'index'
);
$this->Auth->loginError = 'Username and password combination is incorrect!';
if (!$this->Session->read('Auth.User'))
{
$this->Auth->authError = 'Please log in';
}
You set the first one to false when you need to do some routines
during login--like record the login time, set a session var, etc.
Otherwise, you can leave login() empty and allow Auth to sort it all
out.
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