|
- <?php
-
-
-
- namespace backend\controllers;
-
- use common\forms\LoginForm;
- use Yii;
- use yii\filters\AccessControl;
- 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, bool $createTicket = false)
- {
- $user = $this->getUserCurrent();
- $producer = $this->getProducerModule()->getRepository()->findOneProducerById($id);
-
- if($producer) {
- $this->getUserModule()->getBuilder()->switchProducer($user, $producer);
- if($createTicket) {
- return $this->redirect($this->getUrlManagerBackend()->createUrl(['support/create']));
- }
- }
- else {
- $this->addFlash('error', 'Producteur introuvable.');
- }
-
- return $this->redirectReferer();
- }
- }
|