title: How to login user using rest api in yii2
body: <p>I new in yii2, I want login user using rest api but unable to do this.I have setup basic REST API From This blog: </p>
  
  <blockquote>
    <p>budiirawan.com/setup-restful-api-yii2/</p>
  </blockquote>
  
  <p>After that I have created :</p>
  
  <blockquote>
    <p>api\modules\v1\controllers\SiteController.php</p>
  </blockquote>
  
  <pre><code>&lt;?php
  namespace api\modules\v1\controllers;
  
  use Yii;
  use yii\filters\AccessControl;
  use yii\web\Controller;
  use common\models\LoginForm;
  use yii\filters\VerbFilter;
  use yii\rest\ActiveController;
  /**
   * Site controller
   */
  class SiteController extends ActiveController
  {
      /**
       * @inheritdoc
       */
      public $modelClass = 'api\modules\v1\models\user';    
  
  
      public function actionIndex()
      {
              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;login()) {
              return $this-&gt;goBack();
          } else {
              return $this-&gt;render('login', [
                  'model' =&gt; $model,
              ]);
          }
      }
  
      public function actionLogout()
      {
          Yii::$app-&gt;user-&gt;logout();
  
          return $this-&gt;goHome();
      }
  }
  </code></pre>
  
  <p>And Created Model</p>
  
  <blockquote>
    <p>RtWorkForce\api\modules\v1\models\User.php</p>
  </blockquote>
  
  <pre><code>&lt;?php
  namespace api\modules\v1\models;
  use \yii\db\ActiveRecord;
  
  /**
   * User Model
   *
   */
  class User extends ActiveRecord
  {
      /**
       * @inheritdoc
       */
      public static function tableName()
      {
          return '{{%user}}';
  
      }
  
  
  }
  </code></pre>
  
  <p>Here Is my main.php</p>
  
  <pre><code>&lt;?php
  
  $params = array_merge(
      require(__DIR__ . '/../../common/config/params.php'),
      require(__DIR__ . '/../../common/config/params-local.php'),
      require(__DIR__ . '/params.php'),
      require(__DIR__ . '/params-local.php')
  );
  
  return [
      'id' =&gt; 'app-api',
      'basePath' =&gt; dirname(__DIR__),    
      'bootstrap' =&gt; ['log'],
      'modules' =&gt; [
          'v1' =&gt; [
              'basePath' =&gt; '@app/modules/v1',
              'class' =&gt; 'api\modules\v1\Module'
          ]
      ],
      'components' =&gt; [ 
                  'request' =&gt; [
                      'parsers' =&gt; [
                          'application/json' =&gt; 'yii\web\JsonParser',
                      ]
                  ],  
          'user' =&gt; [
              'identityClass' =&gt; 'common\models\User',
              'enableAutoLogin' =&gt; false,
          ],
          'log' =&gt; [
              'traceLevel' =&gt; YII_DEBUG ? 3 : 0,
              'targets' =&gt; [
                  [
                      'class' =&gt; 'yii\log\FileTarget',
                      'levels' =&gt; ['error', 'warning'],
                  ],
              ],
          ],
          'urlManager' =&gt; [
              'enablePrettyUrl' =&gt; true,
              'enableStrictParsing' =&gt; true,
              'showScriptName' =&gt; false,
              'rules' =&gt; [
                  [
                      'class' =&gt; 'yii\rest\UrlRule', 
                      'controller' =&gt; ['v1/country','v1/user','v1/site'],
                      'tokens' =&gt; [
                          '{id}' =&gt; '&lt;id:\\w+&gt;'
                      ]
  
                  ]
              ],        
          ]
      ],
      'params' =&gt; $params,
  ];
  </code></pre>
  
  <p>But IT's not working i don't know where i am wrong ??</p>