Note that there are some explanatory texts on larger screens.

plurals
  1. POAuth Component not logging in users
    primarykey
    data
    text
    <p>I am unable to get the Auth component to login once passed credentials in a post method.</p> <p>I am using CakePHP2.* </p> <p>I am trying to write a web service.</p> <p>Please below the code i have written to configure the Auth component in the AppController and below that the UserController for the User model</p> <p>class AppController extends Controller {</p> <pre><code>public $components = array( 'DebugKit.Toolbar', 'Session', 'Auth' =&gt; array( 'loginRedirect' =&gt; array('controller' =&gt; 'user', 'action' =&gt; 'view'), 'logoutRedirect' =&gt; array('controller' =&gt; 'user', 'action' =&gt; 'home'), 'authenticate' =&gt; array('Form' =&gt; array('fields' =&gt; array('username'=&gt;'username','password'=&gt;'password'))), 'userScope'=&gt; array('User.active_yn' =&gt; 1), 'userModel'=&gt;'User', 'loginAction'=&gt;array('controller' =&gt; 'user', 'action' =&gt; 'login'), 'autoRedirect'=&gt;true, 'authError'=&gt;'You dont have access to that area. Please login first.', 'loginError'=&gt;'Username or password entered is incorrect. Please try again.', 'authorize' =&gt; array('Controller') // Added this line ) ); public function isAuthorized($user) { // Admin can access every action if (isset($user['active_yn']) &amp;&amp; $user['active_yn'] === 1) { //admin return true; } // Default deny return false; } public function beforeFilter() { } </code></pre> <p>}</p> <p>class UserController extends AppController {</p> <pre><code>public $helpers = array('Html', 'Form', 'Session'); public $components = array('Session'); public $validate = array( 'email' =&gt; array('rule' =&gt; 'notEmpty') ); public function index() { $this-&gt;set('User', $this-&gt;User-&gt;find('all')); } public function view($id = null) { if (!$id) { throw new NotFoundException(__('Invalid User')); } $User = $this-&gt;User-&gt;findById($id); if (!$User) { throw new NotFoundException(__('Invalid User')); } $this-&gt;set('User', $User); } public function login() { if ($this-&gt;request-&gt;is('post')) { if ($this-&gt;Auth-&gt;login()) { return $this-&gt;redirect($this-&gt;Auth-&gt;redirect()); } $this-&gt;Session-&gt;setFlash(__('Invalid username or password, try again')); } $this-&gt;set('request', $this-&gt;request-&gt;data); } public function logout() { return $this-&gt;redirect($this-&gt;Auth-&gt;logout()); } public function beforeFilter() { parent::beforeFilter(); $this-&gt;Auth-&gt;allow('view','login','logout'); } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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