add status to login method

This commit is contained in:
iIronside 2023-02-21 23:08:46 +03:00
parent 06cfa93adf
commit f5e69511fb
2 changed files with 7 additions and 3 deletions

View File

@ -23,6 +23,8 @@ use yii\web\UnauthorizedHttpException;
* @property integer $updated_at
* @property $access_token_expired_at
* @property string $password write-only password
*
* @property UserCard $userCard
*/
class User extends ActiveRecord implements IdentityInterface, UserRbacInterface
{

View File

@ -62,12 +62,14 @@ class UserController extends ActiveController
{
$model = new LoginForm();
if ($model->load(Yii::$app->getRequest()->getBodyParams(), '') && $model->login()) {
/** @var User $user */
$user = $model->getUser();
return [
'access_token' => $model->login(),
'access_token_expired_at' => $model->getUser()->getTokenExpiredAt(),
'id' => $model->getUser()->id,
'status' => $model->getUser()->status,
'card_id' => $model->getUser()->userCard->id ?? null,
'id' => $user->id,
'status' => $user->userCard->status,
'card_id' => $user->userCard->id ?? null,
];
} else {
throw new BadRequestHttpException(json_encode($model->errors));