Blame view

backend/controllers/SiteController.php 2.93 KB
3a00e6d1   Yarik   Files added
1
2
  <?php
      namespace backend\controllers;
c2b847bb   Yarik   Import completed
3
4
  
      use artbox\core\models\LoginForm;
3a00e6d1   Yarik   Files added
5
6
7
8
9
      use common\models\Settings;
      use Yii;
      use yii\web\Controller;
      use yii\filters\VerbFilter;
      use yii\filters\AccessControl;
c2b847bb   Yarik   Import completed
10
  
3a00e6d1   Yarik   Files added
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
      /**
       * Site controller
       */
      class SiteController extends Controller
      {
          /**
           * @inheritdoc
           */
          public function behaviors()
          {
              return [
                  'access' => [
                      'class' => AccessControl::className(),
                      'rules' => [
                          [
                              'actions' => [
                                  'login',
                                  'error',
                              ],
                              'allow'   => true,
                          ],
                          [
                              'actions' => [
                                  'logout',
                                  'index',
                                  'analytics',
                              ],
                              'allow'   => true,
                              'roles'   => [ '@' ],
                          ],
                      ],
                  ],
                  'verbs'  => [
                      'class'   => VerbFilter::className(),
                      'actions' => [
                          'logout'    => [ 'post' ],
                          'analytics' => [ 'post' ],
                      ],
                  ],
              ];
          }
c2b847bb   Yarik   Import completed
52
      
3a00e6d1   Yarik   Files added
53
54
55
56
57
58
59
60
61
62
63
          /**
           * @inheritdoc
           */
          public function actions()
          {
              return [
                  'error' => [
                      'class' => 'yii\web\ErrorAction',
                  ],
              ];
          }
c2b847bb   Yarik   Import completed
64
      
3a00e6d1   Yarik   Files added
65
66
67
68
69
70
71
72
          /**
           * Displays homepage.
           *
           * @return string
           */
          public function actionIndex()
          {
              $settings = Settings::getInstance();
c2b847bb   Yarik   Import completed
73
          
3a00e6d1   Yarik   Files added
74
75
76
77
78
79
              if (empty( $settings->analytics_key )) {
                  return $this->render('instruction');
              } else {
                  return $this->render('index');
              }
          }
c2b847bb   Yarik   Import completed
80
      
3a00e6d1   Yarik   Files added
81
82
83
84
85
86
87
88
89
90
          /**
           * Login action.
           *
           * @return string
           */
          public function actionLogin()
          {
              if (!Yii::$app->user->isGuest) {
                  return $this->goHome();
              }
c2b847bb   Yarik   Import completed
91
          
3a00e6d1   Yarik   Files added
92
93
94
95
96
97
98
99
100
101
102
103
              $model = new LoginForm();
              if ($model->load(Yii::$app->request->post()) && $model->login()) {
                  return $this->goBack();
              } else {
                  return $this->renderPartial(
                      'login',
                      [
                          'model' => $model,
                      ]
                  );
              }
          }
c2b847bb   Yarik   Import completed
104
      
3a00e6d1   Yarik   Files added
105
106
107
108
109
110
111
112
          /**
           * Logout action.
           *
           * @return string
           */
          public function actionLogout()
          {
              Yii::$app->user->logout();
c2b847bb   Yarik   Import completed
113
          
3a00e6d1   Yarik   Files added
114
115
116
              return $this->goHome();
          }
      }