SiteController   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 14
lcom 1
cbo 6
dl 0
loc 88
c 0
b 0
f 0
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A behaviors() 0 22 1
A actions() 0 12 2
A actionIndex() 0 4 1
A actionLogin() 0 14 4
A actionLogout() 0 6 1
A actionContact() 0 17 4
A actionAbout() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the Cjt Terabyte LLC [yii2-extension].
5
 *
6
 * (c) Cjt Terabyte LLC [yii2-extension] <http://github.com/cjtterabytesoft>.
7
 * For the full copyright and license information, please view the LICENSE.md.
8
 * file that was distributed with this source code.
9
 *
10
 * @link http://www.cjtterabyte.com.
11
 * @author Wilmer Arámbula <[email protected]>.
12
 * @copyright (c) 2015 Cjt Terabyte LLC.
13
 * @Extension: [yii2-adminlte-basic].
14
 * @Controllers App [SiteController].
15
 * @since 1.0
16
 */
17
18
namespace cjtterabytesoft\adminlte\basic\controllers;
19
20
use Yii;
21
use yii\filters\AccessControl;
22
use yii\web\Controller;
23
use yii\filters\VerbFilter;
24
use cjtterabytesoft\adminlte\basic\models\LoginForm;
25
use cjtterabytesoft\adminlte\basic\models\ContactForm;
26
27
class SiteController extends Controller
28
{
29
    public function behaviors()
30
    {
31
        return [
32
            'access' => [
33
                'class' => AccessControl::className(),
34
                'only' => ['logout'],
35
                'rules' => [
36
                    [
37
                        'actions' => ['logout'],
38
                        'allow' => true,
39
                        'roles' => ['@'],
40
                    ],
41
                ],
42
            ],
43
            'verbs' => [
44
                'class' => VerbFilter::className(),
45
                'actions' => [
46
                    'logout' => ['post'],
47
                ],
48
            ],
49
        ];
50
    }
51
52
    public function actions()
53
    {
54
        return [
55
            'error' => [
56
                'class' => 'yii\web\ErrorAction',
57
            ],
58
            'captcha' => [
59
                'class' => 'yii\captcha\CaptchaAction',
60
                'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
61
            ],
62
        ];
63
    }
64
65
    public function actionIndex()
66
    {
67
        return $this->render('index');
68
    }
69
70
    public function actionLogin()
71
    {
72
        if (!\Yii::$app->user->isGuest) {
73
            return $this->goHome();
74
        }
75
76
        $model = new LoginForm();
77
        if ($model->load(Yii::$app->request->post()) && $model->login()) {
78
            return $this->goBack();
79
        }
80
        return $this->render('login', [
81
            'model' => $model,
82
        ]);
83
    }
84
85
    public function actionLogout()
86
    {
87
        Yii::$app->user->logout();
88
89
        return $this->goHome();
90
    }
91
92
    public function actionContact()
93
    {
94
        $model = new ContactForm();
95
        if ($model->load(Yii::$app->request->post()) && $model->validate()) {
96
            if ($model->sendEmail(Yii::$app->params['adminEmail'])) {
97
                Yii::$app->session->setFlash('success', yii::t('adminlte', 'Thank you for contacting us. We will respond to you as soon as possible.'));
98
            } else {
99
                Yii::$app->session->setFlash('error', yii::t('adminlte', 'There was an error sending email.'));
100
            }
101
102
            return $this->refresh();
103
        } else {
104
            return $this->render('contact', [
105
                'model' => $model,
106
            ]);
107
        }
108
    }
109
110
    public function actionAbout()
111
    {
112
        return $this->render('about');
113
    }
114
}