registration and get user info
This commit is contained in:
@ -4,6 +4,7 @@
|
||||
namespace frontend\modules\api\controllers;
|
||||
|
||||
use common\behaviors\GsCors;
|
||||
use common\classes\Debug;
|
||||
use common\models\User;
|
||||
use frontend\modules\api\models\LoginForm;
|
||||
use Yii;
|
||||
@ -13,35 +14,35 @@ use yii\rest\ActiveController;
|
||||
use yii\web\BadRequestHttpException;
|
||||
use yii\web\Response;
|
||||
|
||||
class UserController extends ActiveController
|
||||
class UserController extends ApiController
|
||||
{
|
||||
public $modelClass = User::class;
|
||||
|
||||
public function behaviors()
|
||||
{
|
||||
return ArrayHelper::merge(parent::behaviors(), [
|
||||
[
|
||||
'class' => ContentNegotiator::class,
|
||||
'formats' => [
|
||||
'application/json' => Response::FORMAT_JSON,
|
||||
],
|
||||
],
|
||||
'corsFilter' => [
|
||||
'class' => GsCors::class,
|
||||
'cors' => [
|
||||
'Origin' => ['*'],
|
||||
//'Access-Control-Allow-Credentials' => true,
|
||||
'Access-Control-Allow-Headers' => [
|
||||
'Access-Control-Allow-Origin',
|
||||
'Content-Type',
|
||||
'Access-Control-Allow-Headers',
|
||||
'Authorization',
|
||||
'X-Requested-With'
|
||||
],
|
||||
]
|
||||
],
|
||||
]);
|
||||
}
|
||||
// public function behaviors()
|
||||
// {
|
||||
// return ArrayHelper::merge(parent::behaviors(), [
|
||||
// [
|
||||
// 'class' => ContentNegotiator::class,
|
||||
// 'formats' => [
|
||||
// 'application/json' => Response::FORMAT_JSON,
|
||||
// ],
|
||||
// ],
|
||||
// 'corsFilter' => [
|
||||
// 'class' => GsCors::class,
|
||||
// 'cors' => [
|
||||
// 'Origin' => ['*'],
|
||||
// //'Access-Control-Allow-Credentials' => true,
|
||||
// 'Access-Control-Allow-Headers' => [
|
||||
// 'Access-Control-Allow-Origin',
|
||||
// 'Content-Type',
|
||||
// 'Access-Control-Allow-Headers',
|
||||
// 'Authorization',
|
||||
// 'X-Requested-With'
|
||||
// ],
|
||||
// ]
|
||||
// ],
|
||||
// ]);
|
||||
// }
|
||||
|
||||
public function actions()
|
||||
{
|
||||
@ -75,4 +76,18 @@ class UserController extends ActiveController
|
||||
throw new BadRequestHttpException(json_encode($model->errors));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \frontend\modules\api\models\User
|
||||
* @throws BadRequestHttpException
|
||||
*/
|
||||
public function actionMe(): \frontend\modules\api\models\User
|
||||
{
|
||||
$user = \frontend\modules\api\models\User::findOne(Yii::$app->user->id);
|
||||
if (!$user){
|
||||
throw new BadRequestHttpException("User not found");
|
||||
}
|
||||
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user