/var/www/vhosts/nabawater/vendor/dektrium/yii2-user/controllers
Edit: /var/www/vhosts/nabawater/vendor/dektrium/yii2-user/controllers/ProfileController.php (2057B)
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace dektrium\user\controllers;
use dektrium\user\Finder;
use yii\filters\AccessControl;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
/**
* ProfileController shows users profiles.
*
* @property \dektrium\user\Module $module
*
* @author Dmitry Erofeev
*/
class ProfileController extends Controller
{
/** @var Finder */
protected $finder;
/**
* @param string $id
* @param \yii\base\Module $module
* @param Finder $finder
* @param array $config
*/
public function __construct($id, $module, Finder $finder, $config = [])
{
$this->finder = $finder;
parent::__construct($id, $module, $config);
}
/** @inheritdoc */
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'rules' => [
['allow' => true, 'actions' => ['index'], 'roles' => ['@']],
['allow' => true, 'actions' => ['show'], 'roles' => ['?', '@']],
],
],
];
}
/**
* Redirects to current user's profile.
*
* @return \yii\web\Response
*/
public function actionIndex()
{
return $this->redirect(['show', 'id' => \Yii::$app->user->getId()]);
}
/**
* Shows user's profile.
*
* @param int $id
*
* @return \yii\web\Response
* @throws \yii\web\NotFoundHttpException
*/
public function actionShow($id)
{
$profile = $this->finder->findProfileById($id);
if ($profile === null) {
throw new NotFoundHttpException();
}
return $this->render('show', [
'profile' => $profile,
]);
}
}