From dd11a9a88cf0ad278c68e7911b814d458bf93dee Mon Sep 17 00:00:00 2001 From: andrey Date: Tue, 7 Sep 2021 16:32:57 +0300 Subject: [PATCH] some fix --- .../reports/controllers/ReportsController.php | 1 + common/models/User.php | 5 ++++ .../api/controllers/ProfileController.php | 13 ++++++++- .../api/controllers/ReportsController.php | 29 ++++++++++--------- 4 files changed, 33 insertions(+), 15 deletions(-) diff --git a/backend/modules/reports/controllers/ReportsController.php b/backend/modules/reports/controllers/ReportsController.php index 741d549..8e6a414 100644 --- a/backend/modules/reports/controllers/ReportsController.php +++ b/backend/modules/reports/controllers/ReportsController.php @@ -9,6 +9,7 @@ use common\models\Reports; use backend\modules\reports\models\ReportsSearch; use yii\filters\AccessControl; use yii\web\Controller; +use yii\web\JsonResponseFormatter; use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; diff --git a/common/models/User.php b/common/models/User.php index 0168246..f7a555d 100755 --- a/common/models/User.php +++ b/common/models/User.php @@ -216,4 +216,9 @@ class User extends ActiveRecord implements IdentityInterface return false; } + public function getUserCard() + { + return $this->hasOne(UserCard::class, ['id_user' => 'id']); + } + } diff --git a/frontend/modules/api/controllers/ProfileController.php b/frontend/modules/api/controllers/ProfileController.php index 3e9fac4..6646e57 100644 --- a/frontend/modules/api/controllers/ProfileController.php +++ b/frontend/modules/api/controllers/ProfileController.php @@ -5,6 +5,7 @@ namespace frontend\modules\api\controllers; use common\behaviors\GsCors; use common\classes\Debug; use common\models\InterviewRequest; +use common\models\User; use frontend\modules\api\models\ProfileSearchForm; use yii\filters\auth\CompositeAuth; use yii\filters\auth\HttpBearerAuth; @@ -63,7 +64,7 @@ class ProfileController extends \yii\rest\Controller $model->attributes = \Yii::$app->request->post(); $model->created_at = time(); $model->user_id = \Yii::$app->user->id; - if ($model->save()){ + if ($model->save()) { return ['status' => 'success']; } @@ -72,4 +73,14 @@ class ProfileController extends \yii\rest\Controller } } + public function actionMe() + { + if(isset(\Yii::$app->user->id)){ + $user = User::find()->with('userCard')->where(['id' => \Yii::$app->user->id])->one(); + } + + \Yii::$app->response->statusCode = 401; + return ['status' => 'error', 'errors' => 'No authorized']; + } + } diff --git a/frontend/modules/api/controllers/ReportsController.php b/frontend/modules/api/controllers/ReportsController.php index 40884d1..11333c7 100644 --- a/frontend/modules/api/controllers/ReportsController.php +++ b/frontend/modules/api/controllers/ReportsController.php @@ -3,6 +3,7 @@ namespace frontend\modules\api\controllers; use common\behaviors\GsCors; +use common\classes\Debug; use common\models\Reports; use frontend\modules\api\models\ReportSearchForm; use JsonException; @@ -31,19 +32,19 @@ class ReportsController extends Controller 'application/json' => Response::FORMAT_JSON, ], ], - 'corsFilter' => [ - 'class' => GsCors::class, - 'cors' => [ - 'Origin' => ['*'], - //'Access-Control-Allow-Credentials' => true, - 'Access-Control-Allow-Headers' => [ - 'Content-Type', - 'Access-Control-Allow-Headers', - 'Authorization', - 'X-Requested-With' - ], - ] - ], +// 'corsFilter' => [ +// 'class' => GsCors::class, +// 'cors' => [ +// 'Origin' => ['*'], +// //'Access-Control-Allow-Credentials' => true, +// 'Access-Control-Allow-Headers' => [ +// 'Content-Type', +// 'Access-Control-Allow-Headers', +// 'Authorization', +// 'X-Requested-With' +// ], +// ] +// ], 'authenticator' => [ 'class' => CompositeAuth::class, 'authMethods' => [ @@ -70,7 +71,7 @@ class ReportsController extends Controller { $reportsModel = new Reports(); - $params = Yii::$app->request->get(); + $params = Yii::$app->request->post(); $reportsModel->attributes = $params; if(!$reportsModel->validate()){