Passed
Push — master ( 11e598...cbc564 )
by Wilmer
01:40
created

SiteController::actionResetPassword()   B

Complexity

Conditions 8
Paths 5

Size

Total Lines 27
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 16
nc 5
nop 1
dl 0
loc 27
rs 8.4444
c 0
b 0
f 0
1
<?php
2
3
namespace app\basic\controllers;
4
5
use app\basic\forms\ContactForm;
6
use app\basic\models\UserModels;
0 ignored issues
show
Bug introduced by
The type app\basic\models\UserModels was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use yii\captcha\CaptchaAction;
8
use yii\base\Model;
9
use yii\mail\MailerInterface;
10
use yii\web\Controller;
11
use yii\web\ErrorAction;
12
use yii\web\Response;
13
use yii\web\filters\AccessControl;
14
use yii\web\filters\VerbFilter;
15
16
/**
17
 * SiteController is the controller Web Application Basic.
18
 **/
19
class SiteController extends Controller
20
{
21
    private $_User;
0 ignored issues
show
introduced by
The private property $_User is not used, and could be removed.
Loading history...
22
23
	/**
24
     * behaviors
25
     *
26
	 * @return array behaviors config.
27
	 **/
28
	public function behaviors()
29
	{
30
		return [
31
			'access' => [
32
				'__class' => AccessControl::class,
33
				'only' => ['logout'],
34
				'rules' => [
35
					[
36
						'actions' => ['logout'],
37
						'allow' => true,
38
						'roles' => ['@'],
39
					],
40
				],
41
			],
42
			'verbs' => [
43
				'__class' => VerbFilter::class,
44
				'actions' => [
45
					'logout' => ['POST'],
46
				],
47
			],
48
		];
49
	}
50
51
	/**
52
     * actions
53
     *
54
	 * @return array actions config.
55
	 **/
56
	public function actions()
57
	{
58
		return [
59
			'error' => [
60
				'__class' => ErrorAction::class,
61
			],
62
			'captcha' => [
63
				'__class' => CaptchaAction::class,
64
				'fixedVerifyCode' => (YII_ENV === 'test') ? 'testme' : null,
65
			],
66
		];
67
	}
68
69
	/**
70
     * actionIndex
71
	 * Displays homepage.
72
	 *
73
	 * @return string
74
	 **/
75
	public function actionIndex()
76
	{
77
		return $this->render('index');
78
	}
79
80
	/**
81
     * actionAbout
82
	 * Displays about page.
83
	 *
84
	 * @return string
85
	 **/
86
	public function actionAbout()
87
	{
88
		return $this->render('about');
89
	}
90
91
	/**
92
     * actionContact
93
	 * Displays contact page.
94
	 *
95
	 * @return Response|string
96
	 **/
97
	public function actionContact()
98
	{
99
        $model = new ContactForm();
100
101
		if ($model->load($this->app->request->post()) && $model->validate()) {
102
            $this->sendContact($this->app->params['adminEmail'], $model);
103
			$this->app->session->setFlash('contactFormSubmitted');
104
			return $this->refresh();
105
		}
106
107
		return $this->render('contact', [
108
			'model' => $model,
109
		]);
110
	}
111
112
    /**
113
     * sendContactForm
114
	 * Sends an email to the specified email address using the information collected by this model.
115
     *
116
	 * @param string $email the target email address.
117
     * @param Model $model.
118
	 * @return bool whether the model passes validation.
119
	 **/
120
	public function sendContact(string $email, Model $model)
121
	{
122
		$this->app->mailer->compose()
123
		    ->setTo($email)
124
			->setFrom([$model->email => $model->name])
125
			->setSubject($model->subject)
126
			->setTextBody($model->body)
127
			->send();
128
    }    
129
}
130