From f6dcb21205c9d8d61a07d567dd82970de4b5242b Mon Sep 17 00:00:00 2001 From: Antonio Ramirez Date: Fri, 9 Dec 2016 09:43:46 +0100 Subject: [PATCH] added profile controller --- lib/User/Controller/ProfileController.php | 54 +++++++++++++++++++ .../Controller/RegistrationController.php | 1 - lib/User/Factory/TokenFactory.php | 2 - lib/User/Query/ProfileQuery.php | 5 +- 4 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 lib/User/Controller/ProfileController.php diff --git a/lib/User/Controller/ProfileController.php b/lib/User/Controller/ProfileController.php new file mode 100644 index 0000000..9170cb1 --- /dev/null +++ b/lib/User/Controller/ProfileController.php @@ -0,0 +1,54 @@ +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, + ] + ); + } + +} diff --git a/lib/User/Controller/RegistrationController.php b/lib/User/Controller/RegistrationController.php index 8f54106..40a6c6d 100644 --- a/lib/User/Controller/RegistrationController.php +++ b/lib/User/Controller/RegistrationController.php @@ -27,7 +27,6 @@ use yii\web\NotFoundHttpException; class RegistrationController extends Controller { - use ModuleTrait; use ContainerTrait; protected $userQuery; diff --git a/lib/User/Factory/TokenFactory.php b/lib/User/Factory/TokenFactory.php index bc71bab..8d3255d 100644 --- a/lib/User/Factory/TokenFactory.php +++ b/lib/User/Factory/TokenFactory.php @@ -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; diff --git a/lib/User/Query/ProfileQuery.php b/lib/User/Query/ProfileQuery.php index 13a28a9..8f835b8 100644 --- a/lib/User/Query/ProfileQuery.php +++ b/lib/User/Query/ProfileQuery.php @@ -5,5 +5,8 @@ use yii\db\ActiveQuery; class ProfileQuery extends ActiveQuery { - + public function whereId($id) + { + return $this->andWhere(['id' => $id]); + } }