The beforeSave function defined in both tutorials are same. In the ACL tutorial, since the model name is User, so they have used data['User']['password'].
However, in the auth tutorial, they have used in as a generalised function, " $this->alias " it will work with any model name.
About session_destroy, I am not sure. I never had to use this thing. And you should trying logging via different browser. I hope its not destroying other user's session. It might just be a browser issue. Did you trying clearing sessions and cookies of your browser before using $this->Session->destroy() ?
On Mon, May 13, 2013 at 10:00 PM, McScreech <mcscreech@inbox.com> wrote:
OK, I now seem to have success by destroying all session data in login function _before_ logging in (shown below).
Am I violating any cakePHP conventions in doing so?
Or perhaps simply clearing some default setting that I have been overlooking so far?
Thanx, McSUsersController.php:
Server Software Apache/2.2.22 (Win32) PHP/5.4.14
CAKE_VERSION 2.3.4
public function login() {
$this->Session->destroy(); // attempt to clear session data before loginreturn $this->redirect($this->Auth->redirectUrl()); // from Auth tutorial
if ($this->request->is('post')) {
if ($this->Auth->login()) {
} else {
$this->Session->setFlash('Your username or password was incorrect.');
}
}
} // end login()
On Wednesday, May 8, 2013 12:27:14 PM UTC-4, McScreech wrote:--
Been following the acl and auth tutorials and appear to be near working except for AuthComponent loginRedirect and logoutRedirect properties. Very bare-bones setup as listed below.
Watching the DebugKit.Toolbar output I note the following:
1) on the users/login page Session > Auth > redirect is /pages/home, no user defined
2) form accepts username and password provided and redirects to /pages/home, Session > Auth > user and activeUser are defined correctly
3) also clicking the users/logout link on that page redirects to /users/login page with same conditions as 1)
But I expected my setup below to assign the loginRedirect to /lots/index and logoutRedirect to /pages/home? What did I miss?
MTIA, McS
Server Software Apache/2.2.22 (Win32) PHP/5.4.14
CAKE_VERSION 2.3.4
<?php
Controller/AppController.php:
public $components = array('DebugKit.Toolbar', 'Session', 'Acl',
'Auth' => array(
'authorize' => array('Actions' => array('actionPath' => 'controllers'),
'Controller' => array('actionPath' => 'controllers')),
'loginAction' => array('controller' => 'users', 'action' => 'login'),
'loginRedirect' => array('controller' => 'lots', 'action' => 'index'),
'logoutRedirect' => array('controller' => 'pages', 'action' => 'home')
)
);
public $helpers = array('Html', 'Form', 'Session');
public function beforeFilter() {
// Configure AuthComponent
$this->Auth->allow('login', 'logout', 'display', 'search');
// Remember user who is logged in,
$this->set('activeUser', $this->Auth->user());
} // end beforeFilter()
Controller/UsersController.php:
public function login() {
if ($this->request->is('post')) {
if ($this->Auth->login()) {
$this->redirect($this->Auth->redirect());
} else {
$this->Session->setFlash('Your username or password was incorrect.');
}
}
} // end login()
public function logout() {
$this->Session->setFlash('Good-Bye');
$this->redirect($this->Auth->logout()); // from auth tutorial
} // end logout()
/View/Users/login.ctp:
<div class="users form">
<?php echo $this->Form->create('User', array('action' => 'login')); ?>
<fieldset>
<legend>Login</legend>
<?php
echo $this->Form->input('username', array( 'style' => 'width: 15em; padding: 2px;' ));
echo $this->Form->input('password', array( 'style' => 'width: 15em; padding: 2px;' ));
?>
</fieldset>
<?php
echo $this->Form->submit('Login');
echo $this->Form->end();
?>
</div> <!-- class="users form" -->
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to a topic in the Google Groups "CakePHP" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cake-php/Gmj20G8Qq3U/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
Regards
Divyanshu Das,
AlphaBeta Labs,
Bangalore, India
Contact# 9591999094
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment