title: CakePHP 2 - manual login not adding to session
body: <p>I am new to CakePHP and trying to get my head round register / login, Im using cakephp 2.0</p>
  
  <p>If i create a user using a register controller function and then login seperately the session (<em>$this-Auth-user()</em>) contains all the Model values i expect.</p>
  
  <p>If i follow the cakephp 2.0 book example and manually login during the register then I <em>do</em> get logged in but <em>$this->Auth->user()</em> only contains the fields from the register form not the User Model. (ie. its missing my Model fields "created", "full name" etc but includes "password" and "passwordconfirm" both unencrypted)</p>
  
  <p>Am i missing something here?</p>
  
  <p>Login Action:</p>
  
  <pre><code>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());
      } else {
          $this-&gt;Session-&gt;setFlash(__('Invalid Username or Password.'), 'default', array(), 'auth');
      }
  }
  }
  </code></pre>
  
  <p>Register Action (with auto login):</p>
  
  <pre><code>public function register(){
      if($this-&gt;request-&gt;is('post')){
          $this-&gt;User-&gt;create();
          if($this-&gt;User-&gt;save($this-&gt;request-&gt;data)){
  
              //Login automatically
              if($this-&gt;Auth-&gt;login($this-&gt;data['User'])){
  
                  $this-&gt;Session-&gt;setFlash(__('Welcome to Test Site.'), 'default', array(), 'auth');
                  return $this-&gt;redirect($this-&gt;Auth-&gt;redirect());
  
              } else {
                  $this-&gt;Session-&gt;setFlash(__('Failed to login with new account.'), 'default', array(), 'auth');
                  $this-&gt;redirect(array('action' =&gt; 'login'));
              }
          } else {
              $this-&gt;Session-&gt;setFlash(__('The user could not be saved. Please, try again.'));
          }
      }
  }
  </code></pre>
  
  <p>Register.ctp View</p>
  
  <pre><code>&lt;?php
  echo $this-&gt;Form-&gt;create('User', array('action' =&gt; 'register'));
  echo $this-&gt;Form-&gt;input('username');
  echo $this-&gt;Form-&gt;input('password', array('label' =&gt; 'Password'));
  echo $this-&gt;Form-&gt;input('passwordconfirm', array('label' =&gt; 'Confirm Password', 'type' =&gt; 'password'));
  echo $this-&gt;Form-&gt;input('email', array('label' =&gt; 'Email (optional)'));
  echo $this-&gt;Form-&gt;end('Join');
  ?&gt;
  </code></pre>
  
  <p>Cheers for any help guys apologies this is a bit long!</p>
  
  <hr>
  
  <p>EDIT:</p>
  
  <p>Found a workaround! 
  Looks like $this->Auth->login($this->data['User']) was failing to AuthComponent::identify() my User so i changed it for the following 3 lines:</p>
  
  <pre><code>$LoggedInID = $this-&gt;User-&gt;field('id', array('username' =&gt; $this-&gt;Auth-&gt;user('username')));
  $user = $this-&gt;User-&gt;read(null, $LoggedInID);
  $this-&gt;Auth-&gt;login($user);
  </code></pre>
  
  <p>and this works a treat.</p>
  
  <p>Edit: You can also just use the return value of save():</p>
  
  <pre><code>        if($user = $this-&gt;User-&gt;save($this-&gt;request-&gt;data)){
  
              //Login automatically
              if($this-&gt;Auth-&gt;login($user)){
  </code></pre>