示例#1
0
 /**
  * Logs in a user.
  *
  * @return mixed
  */
 public function actionLogin()
 {
     $model = new Login();
     if ($model->load(Yii::$app->getRequest()->post(), '') && $model->login()) {
         /* @var $user \common\models\User */
         $user = Yii::$app->getUser()->getIdentity();
         return $user->getToken(true);
     }
     return $model;
 }
示例#2
0
 public function actionLogin()
 {
     Yii::$app->getResponse()->format = 'json';
     $model = new Login();
     $model->load(Yii::$app->getRequest()->post(), '');
     if ($model->login()) {
         /* @var $user \common\models\User */
         $user = Yii::$app->getUser()->getIdentity();
         return ['token' => $user->getToken(true)];
     }
     return Yii::createObject('yii\\rest\\Serializer')->serialize($model);
 }