fix login api
This commit is contained in:
parent
f422a70fc3
commit
c522278222
@ -68,7 +68,6 @@ class Reports extends \yii\db\ActiveRecord
|
|||||||
|
|
||||||
public function afterFind()
|
public function afterFind()
|
||||||
{
|
{
|
||||||
|
|
||||||
parent::afterFind();
|
parent::afterFind();
|
||||||
$this->_task = [];
|
$this->_task = [];
|
||||||
if ($this->task) {
|
if ($this->task) {
|
||||||
|
@ -20,6 +20,7 @@ use yii\web\UnauthorizedHttpException;
|
|||||||
* @property integer $status
|
* @property integer $status
|
||||||
* @property integer $created_at
|
* @property integer $created_at
|
||||||
* @property integer $updated_at
|
* @property integer $updated_at
|
||||||
|
* @property $access_token_expired_at
|
||||||
* @property string $password write-only password
|
* @property string $password write-only password
|
||||||
*/
|
*/
|
||||||
class User extends ActiveRecord implements IdentityInterface
|
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
|
* Finds user by username
|
||||||
*
|
*
|
||||||
@ -124,7 +131,7 @@ class User extends ActiveRecord implements IdentityInterface
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$timestamp = (int) substr($token, strrpos($token, '_') + 1);
|
$timestamp = (int)substr($token, strrpos($token, '_') + 1);
|
||||||
$expire = Yii::$app->params['user.passwordResetTokenExpire'];
|
$expire = Yii::$app->params['user.passwordResetTokenExpire'];
|
||||||
return $timestamp + $expire >= time();
|
return $timestamp + $expire >= time();
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ class UserController extends ActiveController
|
|||||||
$model = new LoginForm();
|
$model = new LoginForm();
|
||||||
if ($model->load(Yii::$app->getRequest()->getBodyParams(), '') && $model->login()) {
|
if ($model->load(Yii::$app->getRequest()->getBodyParams(), '') && $model->login()) {
|
||||||
return [
|
return [
|
||||||
'access_token' => $model->login(),
|
'access_token' => $model->login(), 'access_token_expired_at' => $model->getUser()->getTokenExpiredAt()
|
||||||
];
|
];
|
||||||
} else {
|
} else {
|
||||||
throw new BadRequestHttpException(json_encode($model->errors));
|
throw new BadRequestHttpException(json_encode($model->errors));
|
||||||
|
@ -59,7 +59,7 @@ class LoginForm extends Model
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getUser()
|
public function getUser()
|
||||||
{
|
{
|
||||||
if ($this->_user === null) {
|
if ($this->_user === null) {
|
||||||
$this->_user = User::findByUsername($this->username);
|
$this->_user = User::findByUsername($this->username);
|
||||||
|
@ -38,7 +38,8 @@ class ReportSearchForm extends Model
|
|||||||
public function byParams()
|
public function byParams()
|
||||||
{
|
{
|
||||||
$queryBuilder = Reports::find()
|
$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)
|
->limit($this->limit)
|
||||||
->offset($this->offset);
|
->offset($this->offset);
|
||||||
|
|
||||||
@ -47,7 +48,7 @@ class ReportSearchForm extends Model
|
|||||||
$queryBuilder->andWhere(['user_card_id' => $userCardId]);
|
$queryBuilder->andWhere(['user_card_id' => $userCardId]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = $queryBuilder->all();
|
$data = $queryBuilder->asArray()->all();
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user