|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- <?php
-
-
-
- namespace backend\controllers;
-
- use common\logic\User\User\Model\User;
- use Yii;
- use yii\filters\AccessControl;
- use common\forms\LoginForm;
- use yii\filters\VerbFilter;
-
-
- class SiteController extends BackendController
- {
-
-
- public function behaviors()
- {
- return [
- 'access' => [
- 'class' => AccessControl::class,
- 'rules' => [
- [
- 'actions' => ['login', 'error', 'maintenance'],
- 'allow' => true,
- ],
- [
- 'actions' => ['logout'],
- 'allow' => true,
- 'roles' => ['@'],
- 'matchCallback' => function ($rule, $action) {
- return $this->getUserModule()
- ->getAuthorizationChecker()
- ->isGrantedAsProducer($this->getUserCurrent());
- }
- ],
- [
- 'actions' => ['switch-producer'],
- 'allow' => true,
- 'roles' => ['@'],
- 'matchCallback' => function ($rule, $action) {
- return $this->getUserModule()
- ->getAuthorizationChecker()
- ->isGrantedAsAdministrator($this->getUserCurrent());
- }
- ],
- ],
- ],
- 'verbs' => [
- 'class' => VerbFilter::class,
- 'actions' => [
- ],
- ],
- ];
- }
-
-
-
- public function actions()
- {
- return [
- 'error' => [
- 'class' => 'yii\web\ErrorAction',
- ],
- ];
- }
-
-
-
- public function actionLogin()
- {
- if (!\Yii::$app->user->isGuest) {
- return $this->goHome();
- }
-
- $model = new LoginForm();
- if ($model->load(\Yii::$app->request->post()) && $model->login()) {
- return $this->goBack();
- } else {
- return $this->render('login', [
- 'model' => $model,
- ]);
- }
- }
-
-
-
- public function actionLogout()
- {
- Yii::$app->user->logout();
-
- return $this->goHome();
- }
-
-
-
- public function actionSwitchProducer(int $id)
- {
- $user = $this->getUserCurrent();
- $producer = $this->getProducerModule()->getRepository()->findOneProducerById($id);
-
- if($producer) {
- $this->getUserModule()->getBuilder()->switchProducer($user, $producer);
- }
- else {
- $this->addFlash('error', 'Producteur introuvable.');
- }
-
- return $this->redirectReferer();
- }
- }
|