title: cakephp 2.x auth component and angular js
body: <p>I have a problem.</p>
  
  <p>I would like to create an app using cakephp (backend) and angular js (frontend).</p>
  
  <p>i don't have any idea about login users from angular js.</p>
  
  <p>My code:</p>
  
  <p>backend - appController</p>
  
  <pre><code>class AppController extends Controller {
  
      public $components = array(
          'Session',
          'RequestHandler',
          'Cookie',
          'Auth' =&gt; array(
              //'loginRedirect'   =&gt; array('controller' =&gt; 'index', 'action' =&gt; 'home'),
              //'logoutRedirect'=&gt; array('controller' =&gt; 'index', 'action' =&gt; 'home'),
                  'authenticate'  =&gt; array(
                  'Form' =&gt; array(
                      'fields'    =&gt; array('username' =&gt; 'username', 'password' =&gt; 'password', 'status' =&gt; 'enabled'),
                      'userModel' =&gt; 'User',
                      'scope'     =&gt; array('User.status' =&gt; 'enabled')
                  )
              )
          )
      );
  
      public $helpers = array ('Html','Session','Js','Form');
  
  }
  </code></pre>
  
  <p>backend - usersController</p>
  
  <pre><code>class UsersController extends AppController {
  
      public function beforeFilter() {
  
          $this-&gt;Auth-&gt;allow('register');
  
          $this-&gt;Auth-&gt;fields = array(
              'username'          =&gt; 'username',
              'password'          =&gt; 'secretword',
          );
      }
  
      public function login() {
  
          if ($this-&gt;request-&gt;is('post')) {
  
              if ($this-&gt;Auth-&gt;login()) {
                  $this-&gt;User-&gt;id = $this-&gt;Auth-&gt;user('id');
                  $this-&gt;User-&gt;saveField('last_login', date('Y-m-d H:i:s') );
                  die("Logged");
              }
          }
          throw new ForbiddenException("You are not authorized to access that location.");
  
      }
  </code></pre>
  
  <p>frontend - userSv</p>
  
  <pre><code>var login = function(data) {
  
      var deferred = $q.defer();
  
      var params = {
          "params":{
              "plugin":null,
              "controller":"users",
              "action":"login",
              "named":[],
              "pass":[],
              "isAjax":false              
          },
          "data":{"User":{"username":data.username,"password":data.password}},
          "query":[],
          "url":"users\/login",
          "base":"",
          "webroot":"\/",
          "here":"\/users\/login"
      };
  
      console.log(params);
  
      $http({method: 'POST', url: '/users/login',data:params}).
      success(function(data, status, headers, config) {
          console.log("success");
          //console.log(data);
          console.log(status);
          console.log(headers);
          console.log(config);
      }).
      error(function(data, status, headers, config) {
          console.log("error");
          //console.log(data);
          console.log(status);
          console.log(headers);
          console.log(config);
      });
  
      return deferred.promise;
  }
  </code></pre>
  
  <p>so, after sent the information, i get:</p>
  
  <p>"You are not authorized to access that location.</p>
  
  <p>Error: The requested address '/users/login' was not found on this server."</p>
  
  <p>do you have any idea?</p>