yiisoft /
yii2-app-basic
| 1 | <?php |
||||||||||
| 2 | |||||||||||
| 3 | namespace app\controllers; |
||||||||||
| 4 | |||||||||||
| 5 | use Yii; |
||||||||||
| 6 | use yii\filters\AccessControl; |
||||||||||
| 7 | use yii\web\Controller; |
||||||||||
| 8 | use yii\web\Response; |
||||||||||
| 9 | use yii\filters\VerbFilter; |
||||||||||
| 10 | use app\models\LoginForm; |
||||||||||
| 11 | use app\models\ContactForm; |
||||||||||
| 12 | |||||||||||
| 13 | class SiteController extends Controller |
||||||||||
| 14 | { |
||||||||||
| 15 | /** |
||||||||||
| 16 | * {@inheritdoc} |
||||||||||
| 17 | */ |
||||||||||
| 18 | public function behaviors() |
||||||||||
| 19 | { |
||||||||||
| 20 | return [ |
||||||||||
| 21 | 'access' => [ |
||||||||||
| 22 | 'class' => AccessControl::class, |
||||||||||
| 23 | 'only' => ['logout'], |
||||||||||
| 24 | 'rules' => [ |
||||||||||
| 25 | [ |
||||||||||
| 26 | 'actions' => ['logout'], |
||||||||||
| 27 | 'allow' => true, |
||||||||||
| 28 | 'roles' => ['@'], |
||||||||||
| 29 | ], |
||||||||||
| 30 | ], |
||||||||||
| 31 | ], |
||||||||||
| 32 | 'verbs' => [ |
||||||||||
| 33 | 'class' => VerbFilter::class, |
||||||||||
| 34 | 'actions' => [ |
||||||||||
| 35 | 'logout' => ['post'], |
||||||||||
| 36 | ], |
||||||||||
| 37 | ], |
||||||||||
| 38 | ]; |
||||||||||
| 39 | } |
||||||||||
| 40 | |||||||||||
| 41 | /** |
||||||||||
| 42 | * {@inheritdoc} |
||||||||||
| 43 | */ |
||||||||||
| 44 | public function actions() |
||||||||||
| 45 | { |
||||||||||
| 46 | return [ |
||||||||||
| 47 | 'error' => [ |
||||||||||
| 48 | 'class' => 'yii\web\ErrorAction', |
||||||||||
| 49 | ], |
||||||||||
| 50 | 'captcha' => [ |
||||||||||
| 51 | 'class' => 'yii\captcha\CaptchaAction', |
||||||||||
| 52 | 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null, |
||||||||||
| 53 | ], |
||||||||||
| 54 | ]; |
||||||||||
| 55 | } |
||||||||||
| 56 | |||||||||||
| 57 | /** |
||||||||||
| 58 | * Displays homepage. |
||||||||||
| 59 | * |
||||||||||
| 60 | * @return string |
||||||||||
| 61 | */ |
||||||||||
| 62 | public function actionIndex() |
||||||||||
| 63 | { |
||||||||||
| 64 | return $this->render('index'); |
||||||||||
| 65 | } |
||||||||||
| 66 | |||||||||||
| 67 | /** |
||||||||||
| 68 | * Login action. |
||||||||||
| 69 | * |
||||||||||
| 70 | * @return Response|string |
||||||||||
| 71 | */ |
||||||||||
| 72 | public function actionLogin() |
||||||||||
| 73 | { |
||||||||||
| 74 | if (!Yii::$app->user->isGuest) { |
||||||||||
| 75 | return $this->goHome(); |
||||||||||
| 76 | } |
||||||||||
| 77 | |||||||||||
| 78 | $model = new LoginForm(); |
||||||||||
| 79 | if ($model->load(Yii::$app->request->post()) && $model->login()) { |
||||||||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
It seems like
Yii::app->request->post() can also be of type object; however, parameter $data of yii\base\Model::load() does only seem to accept array, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||||||
| 80 | return $this->goBack(); |
||||||||||
| 81 | } |
||||||||||
| 82 | |||||||||||
| 83 | $model->password = ''; |
||||||||||
| 84 | return $this->render('login', [ |
||||||||||
| 85 | 'model' => $model, |
||||||||||
| 86 | ]); |
||||||||||
| 87 | } |
||||||||||
| 88 | |||||||||||
| 89 | /** |
||||||||||
| 90 | * Logout action. |
||||||||||
| 91 | * |
||||||||||
| 92 | * @return Response |
||||||||||
| 93 | */ |
||||||||||
| 94 | public function actionLogout() |
||||||||||
| 95 | { |
||||||||||
| 96 | Yii::$app->user->logout(); |
||||||||||
|
0 ignored issues
–
show
The method
logout() does not exist on null.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
The method
logout() does not exist on __WebUser.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||||||||
| 97 | |||||||||||
| 98 | return $this->goHome(); |
||||||||||
| 99 | } |
||||||||||
| 100 | |||||||||||
| 101 | /** |
||||||||||
| 102 | * Displays contact page. |
||||||||||
| 103 | * |
||||||||||
| 104 | * @return Response|string |
||||||||||
| 105 | */ |
||||||||||
| 106 | public function actionContact() |
||||||||||
| 107 | { |
||||||||||
| 108 | $model = new ContactForm(); |
||||||||||
| 109 | if ($model->load(Yii::$app->request->post()) && $model->contact(Yii::$app->params['adminEmail'])) { |
||||||||||
|
0 ignored issues
–
show
It seems like
Yii::app->request->post() can also be of type object; however, parameter $data of yii\base\Model::load() does only seem to accept array, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||||||
| 110 | Yii::$app->session->setFlash('contactFormSubmitted'); |
||||||||||
|
0 ignored issues
–
show
The method
setFlash() does not exist on null.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||||||||
| 111 | |||||||||||
| 112 | return $this->refresh(); |
||||||||||
| 113 | } |
||||||||||
| 114 | return $this->render('contact', [ |
||||||||||
| 115 | 'model' => $model, |
||||||||||
| 116 | ]); |
||||||||||
| 117 | } |
||||||||||
| 118 | |||||||||||
| 119 | /** |
||||||||||
| 120 | * Displays about page. |
||||||||||
| 121 | * |
||||||||||
| 122 | * @return string |
||||||||||
| 123 | */ |
||||||||||
| 124 | public function actionAbout() |
||||||||||
| 125 | { |
||||||||||
| 126 | return $this->render('about'); |
||||||||||
| 127 | } |
||||||||||
| 128 | } |
||||||||||
| 129 |