title: Can't store user identity Yii2
body: <p>When my user logs in and passes the validation without errors I have a <code>login</code> function inside my <code>LoginForm.php</code>, which must save the user in the session. My function looks like this:</p>
  
  <pre><code>public function login()
      {
          if ($this-&gt;validate()) {
              $email = $this-&gt;email;
              $user = $this::find()-&gt;where(['email' =&gt; $email])-&gt;asArray()-&gt;one();
              $user['password'] = '_';
              Yii::$app-&gt;getUser()-&gt;login($user);
          }
          return false;
      }
  </code></pre>
  
  <p>And inside of <code>SiteController</code> I have this function:</p>
  
  <pre><code>public function actionLogin()
      {
          if (!Yii::$app-&gt;user-&gt;isGuest) {
              return $this-&gt;goHome();
          }
          $model = new LoginForm();
          if ($model-&gt;load(Yii::$app-&gt;request-&gt;post()) &amp;&amp; $model-&gt;validate() &amp;&amp; $model-&gt;login()) {
              $this-&gt;redirect(['users/profile']);
          }
  
          return $this-&gt;render('login', [
              'model' =&gt; $model
          ]);
      }
  </code></pre>
  
  <p>The problem is in my <code>login</code> function, because when I comment the <code>&amp;&amp; $model-&gt;login()</code> part in my if statement the error goes away.</p>
  
  <p>Here is the error which I'm getting:</p>
  
  <pre><code>Argument 1 passed to yii\web\User::login() must be an instance of yii\web\IdentityInterface, array given, called in C:\xampp\htdocs\yii_grig\models\LoginForm.php on line 72
  </code></pre>
  
  <p>The error is this line in my <code>login</code> function - <code>Yii::$app-&gt;getUser()-&gt;login($user);</code>.</p>
  
  <p>This is how my <code>models/User.php</code> file looks like:</p>
  
  <pre><code>&lt;?
  
  namespace app\models;
  
  class User extends \yii\db\ActiveRecord implements  \yii\web\IdentityInterface
  {
      public static function findIdentity($id)
      {
          return static::findOne($id);
      }
  
      public static function findIdentityByAccessToken($token, $type = null)
      {
          return static::findOne(['access_token' =&gt; $token]);
      }
  
      public function getId()
      {
          return $this-&gt;id;
      }
  
      public function getAuthKey()
      {
          return $this-&gt;authKey;
      }
  
      public function validateAuthKey($authKey)
      {
          return $this-&gt;authKey === $authKey;
      }
  }
  </code></pre>
  
  <p>How can I fix this and save user in the session?</p>