From c52227822294b89afc4d20cd42856a6ce540bdec Mon Sep 17 00:00:00 2001 From: andrey Date: Tue, 3 Aug 2021 15:52:25 +0300 Subject: [PATCH] fix login api --- common/models/Reports.php | 1 - common/models/User.php | 9 ++++++++- frontend/modules/api/controllers/UserController.php | 2 +- frontend/modules/api/models/LoginForm.php | 2 +- frontend/modules/api/models/ReportSearchForm.php | 5 +++-- 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/common/models/Reports.php b/common/models/Reports.php index ccde0f8..d2a24d3 100644 --- a/common/models/Reports.php +++ b/common/models/Reports.php @@ -68,7 +68,6 @@ class Reports extends \yii\db\ActiveRecord public function afterFind() { - parent::afterFind(); $this->_task = []; if ($this->task) { diff --git a/common/models/User.php b/common/models/User.php index 1658563..0168246 100755 --- a/common/models/User.php +++ b/common/models/User.php @@ -20,6 +20,7 @@ use yii\web\UnauthorizedHttpException; * @property integer $status * @property integer $created_at * @property integer $updated_at + * @property $access_token_expired_at * @property string $password write-only password */ class User extends ActiveRecord implements IdentityInterface @@ -83,6 +84,12 @@ class User extends ActiveRecord implements IdentityInterface } } + + public function getTokenExpiredAt() + { + return $this->access_token_expired_at; + } + /** * Finds user by username * @@ -124,7 +131,7 @@ class User extends ActiveRecord implements IdentityInterface return false; } - $timestamp = (int) substr($token, strrpos($token, '_') + 1); + $timestamp = (int)substr($token, strrpos($token, '_') + 1); $expire = Yii::$app->params['user.passwordResetTokenExpire']; return $timestamp + $expire >= time(); } diff --git a/frontend/modules/api/controllers/UserController.php b/frontend/modules/api/controllers/UserController.php index 07bf9eb..34cea86 100644 --- a/frontend/modules/api/controllers/UserController.php +++ b/frontend/modules/api/controllers/UserController.php @@ -63,7 +63,7 @@ class UserController extends ActiveController $model = new LoginForm(); if ($model->load(Yii::$app->getRequest()->getBodyParams(), '') && $model->login()) { return [ - 'access_token' => $model->login(), + 'access_token' => $model->login(), 'access_token_expired_at' => $model->getUser()->getTokenExpiredAt() ]; } else { throw new BadRequestHttpException(json_encode($model->errors)); diff --git a/frontend/modules/api/models/LoginForm.php b/frontend/modules/api/models/LoginForm.php index 30a75ec..3e06a42 100644 --- a/frontend/modules/api/models/LoginForm.php +++ b/frontend/modules/api/models/LoginForm.php @@ -59,7 +59,7 @@ class LoginForm extends Model return false; } - protected function getUser() + public function getUser() { if ($this->_user === null) { $this->_user = User::findByUsername($this->username); diff --git a/frontend/modules/api/models/ReportSearchForm.php b/frontend/modules/api/models/ReportSearchForm.php index 40642b9..2a46dee 100644 --- a/frontend/modules/api/models/ReportSearchForm.php +++ b/frontend/modules/api/models/ReportSearchForm.php @@ -38,7 +38,8 @@ class ReportSearchForm extends Model public function byParams() { $queryBuilder = Reports::find() - ->andWhere(['between', 'created_at', $this->fromDate, $this->toDate, $this->user_id]) + ->with('task') + ->andWhere(['between', 'reports.created_at', $this->fromDate, $this->toDate, $this->user_id]) ->limit($this->limit) ->offset($this->offset); @@ -47,7 +48,7 @@ class ReportSearchForm extends Model $queryBuilder->andWhere(['user_card_id' => $userCardId]); } - $data = $queryBuilder->all(); + $data = $queryBuilder->asArray()->all(); return $data; }