Note that there are some explanatory texts on larger screens.

plurals
  1. POCakePHP auth/acl not working
    primarykey
    data
    text
    <p>This has been bothering me for DAYS.</p> <p>I followed this tutorial to do the authentication: <a href="http://book.cakephp.org/2.0/en/tutorials-and-examples/simple-acl-controlled-application/simple-acl-controlled-application.html" rel="nofollow">http://book.cakephp.org/2.0/en/tutorials-and-examples/simple-acl-controlled-application/simple-acl-controlled-application.html</a></p> <p>I tested if the hashing was working correctly by running the Security:hash command, and comparing the value to the one in the database (it's the same).</p> <p>$this->Auth->login() always returns false no matter what I do... please shed some light on this situation...</p> <p>This works fine on my localhost wamp server but not on the live server (no php errors that I know of)... I'm able to use ssh to get in if needed.</p> <p>I'm using CakePHP 2.4.2</p> <p>My user login method:</p> <pre><code>public function login() { if ($this-&gt;request-&gt;is('post')) { //echo "&lt;div style=\"padding:10px; border:black 1px solid; margin: 5px;\"&gt;" . Security::hash($_POST['data']['User']['password'], 'sha1', true) ."&lt;/div&gt;"; if ($this-&gt;Auth-&gt;login()) { //if ($this-&gt;Auth-&gt;login($this-&gt;request-&gt;data)) { return $this-&gt;redirect($this-&gt;Auth-&gt;redirect()); echo "logged in"; } else { echo "login failed"; } if ($this-&gt;Session-&gt;read('Auth.User')) { $this-&gt;Session-&gt;setFlash('You are logged in!'); return $this-&gt;redirect('/pages/home'); } else { //echo "not logged in"; } $this-&gt;Session-&gt;setFlash(__('Your username or password was incorrect.')); } } </code></pre> <p>app controller:</p> <pre><code>class AppController extends Controller { public $components = array( 'Acl', 'Auth' =&gt; array( 'authorize' =&gt; array( 'Actions' =&gt; array('actionPath' =&gt; 'controllers') ) ), 'Session' ); public $helpers = array('Html', 'Form', 'Session'); public function beforeFilter() { parent::beforeFilter(); //Configure AuthComponent $this-&gt;Auth-&gt;loginAction = array('controller' =&gt; 'users', 'action' =&gt; 'login'); $this-&gt;Auth-&gt;logoutRedirect = array('controller' =&gt; 'users', 'action' =&gt; 'login'); $this-&gt;Auth-&gt;loginRedirect = array('controller' =&gt; 'applications', 'action' =&gt; 'index'); //$this-&gt;Auth-&gt;loginRedirect = array('controller' =&gt; 'users', 'action' =&gt; 'login'); $this-&gt;Auth-&gt;allow('display'); $this-&gt;set('Auth', $this-&gt;Auth-&gt;user()); } } </code></pre> <p>login view:</p> <pre><code>&lt;?php echo $this-&gt;Form-&gt;create('User', array('url' =&gt; array('controller' =&gt; 'users', 'action' =&gt; 'login'))); echo $this-&gt;Form-&gt;input('User.username'); echo $this-&gt;Form-&gt;input('User.password'); echo $this-&gt;Form-&gt;end('Login'); ?&gt; </code></pre> <p>user model:</p> <pre><code>&lt;?php App::uses('AuthComponent', 'Controller/Component'); class User extends AppModel { // other code. public function beforeSave($options = array()) { $this-&gt;data['User']['password'] = AuthComponent::password($this-&gt;data['User']['password']); return true; } public $belongsTo = array('Group'); public $actsAs = array('Acl' =&gt; array('type' =&gt; 'requester')); public function parentNode() { if (!$this-&gt;id &amp;&amp; empty($this-&gt;data)) { return null; } if (isset($this-&gt;data['User']['group_id'])) { $groupId = $this-&gt;data['User']['group_id']; } else { $groupId = $this-&gt;field('group_id'); } if (!$groupId) { return null; } else { return array('Group' =&gt; array('id' =&gt; $groupId)); } } public function bindNode($user) { return array('model' =&gt; 'Group', 'foreign_key' =&gt; $user['User']['group_id']); } } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload