added profile controller
This commit is contained in:
54
lib/User/Controller/ProfileController.php
Normal file
54
lib/User/Controller/ProfileController.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
namespace Da\User\Controller;
|
||||
|
||||
use Da\User\Query\ProfileQuery;
|
||||
use yii\base\Module;
|
||||
use yii\filters\AccessControl;
|
||||
use yii\web\Controller;
|
||||
use Yii;
|
||||
use yii\web\NotFoundHttpException;
|
||||
|
||||
class ProfileController extends Controller
|
||||
{
|
||||
protected $profileQuery;
|
||||
|
||||
public function __construct($id, Module $module, ProfileQuery $profileQuery, array $config)
|
||||
{
|
||||
$this->profileQuery = $profileQuery;
|
||||
parent::__construct($id, $module, $config);
|
||||
}
|
||||
|
||||
public function behaviors()
|
||||
{
|
||||
return [
|
||||
'access' => [
|
||||
'class' => AccessControl::className(),
|
||||
'rules' => [
|
||||
['allow' => true, 'actions' => ['index'], 'roles' => ['@']],
|
||||
['allow' => true, 'actions' => ['show'], 'roles' => ['?', '@']],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function actionIndex()
|
||||
{
|
||||
return $this->redirect(['show', 'id' => Yii::$app->user->getId()]);
|
||||
}
|
||||
|
||||
public function actionShow($id)
|
||||
{
|
||||
$profile = $this->profileQuery->whereId($id)->one();
|
||||
if ($profile === null) {
|
||||
throw new NotFoundHttpException();
|
||||
}
|
||||
|
||||
return $this->render(
|
||||
'show',
|
||||
[
|
||||
'profile' => $profile,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@ -27,7 +27,6 @@ use yii\web\NotFoundHttpException;
|
||||
|
||||
class RegistrationController extends Controller
|
||||
{
|
||||
use ModuleTrait;
|
||||
use ContainerTrait;
|
||||
|
||||
protected $userQuery;
|
||||
|
||||
@ -2,8 +2,6 @@
|
||||
namespace Da\User\Factory;
|
||||
|
||||
use Da\User\Model\Token;
|
||||
use Da\User\Model\User;
|
||||
use Da\User\Traits\ContainerTrait;
|
||||
use Yii;
|
||||
|
||||
|
||||
|
||||
@ -5,5 +5,8 @@ use yii\db\ActiveQuery;
|
||||
|
||||
class ProfileQuery extends ActiveQuery
|
||||
{
|
||||
|
||||
public function whereId($id)
|
||||
{
|
||||
return $this->andWhere(['id' => $id]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user