Blame view

frontend/controllers/SiteController.php 9.73 KB
a63b5418   Administrator   first_commit
1
2
3
  <?php
  namespace frontend\controllers;
  
89d4b5ac   Administrator   VItaliy 25.11.2015
4
  use common\models\Accounts;
2fd0fce6   Administrator   VItaliy 04.12.2015
5
  use frontend\models\AccountsForm;
1ec3afef   Administrator   VItaliy 27.11.2015
6
  use common\models\News;
25545a10   Administrator   VItaliy 30.11.2015
7
  use common\models\Slider;
89d4b5ac   Administrator   VItaliy 25.11.2015
8
9
  use common\models\Team;
  use common\models\TeamGroup;
a63b5418   Administrator   first_commit
10
  use Yii;
27b0cb06   Administrator   VItaliy 02.12.2015
11
  use common\models\UserLoginForm;
a63b5418   Administrator   first_commit
12
13
14
15
16
17
18
  use frontend\models\PasswordResetRequestForm;
  use frontend\models\ResetPasswordForm;
  use frontend\models\SignupForm;
  use frontend\models\ContactForm;
  use yii\base\InvalidParamException;
  use yii\web\BadRequestHttpException;
  use yii\web\Controller;
fa5a99de   Administrator   VItaliy 04.12.2015
19
  
a63b5418   Administrator   first_commit
20
21
  use yii\filters\VerbFilter;
  use yii\filters\AccessControl;
068f769f   Administrator   first commit from...
22
23
  use common\models\Callback;
  use common\components\MailWidget;
a63b5418   Administrator   first_commit
24
25
26
27
28
  /**
   * Site controller
   */
  class SiteController extends Controller
  {
7b407169   Administrator   upload project
29
  
89d4b5ac   Administrator   VItaliy 25.11.2015
30
     // public $enableCsrfValidation = false;
a63b5418   Administrator   first_commit
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
  
      /**
       * @inheritdoc
       */
      public function actions()
      {
          return [
              'error' => [
                  'class' => 'yii\web\ErrorAction',
              ],
              'captcha' => [
                  'class' => 'yii\captcha\CaptchaAction',
                  'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
              ],
          ];
      }
  
      /**
       * Displays homepage.
       *
       * @return mixed
       */
      public function actionIndex()
      {
27b0cb06   Administrator   VItaliy 02.12.2015
55
  
394e2db6   Administrator   Importers CRUD
56
          $this->layout = '/outer';
068f769f   Administrator   first commit from...
57
  
1ec3afef   Administrator   VItaliy 27.11.2015
58
          $news_list = News::find()->where(['is_active'=>1])->limit(3)->all();
25545a10   Administrator   VItaliy 30.11.2015
59
          $slider_list = Slider::find()->where(['is_active'=>1])->all();
068f769f   Administrator   first commit from...
60
61
62
63
64
65
66
67
68
          if (Yii::$app->request->post()) {
  
              $post = Yii::$app->request->post();
              if(isset($post['Callback'])){
                  $text = "Имя: ".$post['Callback']['name'].'<br>';
                  $text .= "Телефон: ".$post['Callback']['phone_num'];
                  $model = new Callback();
                  $model->load(Yii::$app->request->post());
                  $model->save();
ad4b55bc   Administrator   VItaliy 26.11.2015
69
                  MailWidget::widget(['email' => 'ital-auto@test.com', 'text' => $text, 'subject' => 'Обратный звонок']);
068f769f   Administrator   first commit from...
70
71
72
              }
  
          }
1ec3afef   Administrator   VItaliy 27.11.2015
73
          return $this->render('index',[
25545a10   Administrator   VItaliy 30.11.2015
74
              'slider_list' => $slider_list,
1ec3afef   Administrator   VItaliy 27.11.2015
75
76
              'news_list' => $news_list
          ]);
a63b5418   Administrator   first_commit
77
78
      }
  
394e2db6   Administrator   Importers CRUD
79
80
81
82
83
84
85
86
87
88
      public function actionNotFound()
      {
          $this->layout = '/internal';
          return $this->render('not-found');
      }
      public function action404()
      {
          $this->layout = '/internal';
          return $this->render('404');
      }
7b407169   Administrator   upload project
89
  
394e2db6   Administrator   Importers CRUD
90
  
25545a10   Administrator   VItaliy 30.11.2015
91
      public function actionTeam()
394e2db6   Administrator   Importers CRUD
92
      {
25545a10   Administrator   VItaliy 30.11.2015
93
94
          $teamGroups = TeamGroup::find()->all();
  
394e2db6   Administrator   Importers CRUD
95
          $this->layout = '/internal';
25545a10   Administrator   VItaliy 30.11.2015
96
97
98
99
          return $this->render('team',[
              'teamGroups' => $teamGroups,
          ]);
  
394e2db6   Administrator   Importers CRUD
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
      }
  
      public function actionBc2Catalog()
      {
          $this->layout = '/internal';
          return $this->render('BC2_catalog');
      }
  
      public function actionBc2CatalogZapchasti()
      {
          $this->layout = '/internal';
          return $this->render('BC2_catalog_zapchasti');
      }
  
      public function actionBrands()
      {
          $this->layout = '/internal';
          return $this->render('brands');
      }
  
      public function actionBusket()
      {
          $this->layout = '/internal';
          return $this->render('busket');
      }
  
      public function actionBusketStep2()
      {
          $this->layout = '/internal';
          return $this->render('busket_step2');
      }
  
394e2db6   Administrator   Importers CRUD
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
  
      public function actionCatalogMarokStep2()
      {
          $this->layout = '/internal';
          return $this->render('catalog_marok_step2');
      }
  
      public function actionCatalogMarokStep3()
      {
          $this->layout = '/internal';
          return $this->render('catalog_marok_step3');
      }
  
      public function actionCatalogMarokStep4()
      {
          $this->layout = '/internal';
          return $this->render('catalog_marok_step4');
      }
  
      public function actionCatalogMarokStep5()
      {
          $this->layout = '/internal';
          return $this->render('catalog_marok_step5');
      }
      public function actionCatalogMarokStep6()
      {
          $this->layout = '/internal';
          return $this->render('catalog_marok_step6');
      }
  
      public function actionCatalogMarok()
      {
          $this->layout = '/internal';
          return $this->render('catalog_marok');
      }
  
      public function actionNewsAll()
      {
          $this->layout = '/internal';
          return $this->render('news_all');
      }
  
      public function actionNotepad()
      {
          $this->layout = '/internal';
          return $this->render('notepad');
      }
  
89d4b5ac   Administrator   VItaliy 25.11.2015
180
      public function actionWholesalers()
394e2db6   Administrator   Importers CRUD
181
182
      {
          $this->layout = '/internal';
89d4b5ac   Administrator   VItaliy 25.11.2015
183
          return $this->render('wholesalers');
394e2db6   Administrator   Importers CRUD
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
      }
  
      public function actionOriginalCatalog()
      {
          $this->layout = '/internal';
          return $this->render('original_catalog');
      }
  
      public function actionOriginalCatalogStep2()
      {
          $this->layout = '/internal';
          return $this->render('original_catalog_step2');
      }
  
      public function actionOriginalCatalogStep3()
      {
          $this->layout = '/internal';
          return $this->render('original_catalog_step3');
      }
  
      public function actionOriginalCatalogStep4()
      {
          $this->layout = '/internal';
          return $this->render('original_catalog_step4');
      }
  
      public function actionOriginalCatalogStep5()
      {
          $this->layout = '/internal';
          return $this->render('original_catalog_step5');
      }
  
      public function actionOriginalCatalogStep6()
      {
          $this->layout = '/internal';
          return $this->render('original_catalog_step6');
      }
  
      public function actionOriginalCatalogStep7()
      {
          $this->layout = '/internal';
          return $this->render('original_catalog_step7');
      }
  
      public function actionProvider()
      {
          $this->layout = '/internal';
          return $this->render('provider');
      }
  
      public function actionRegistrationForm()
      {
          $this->layout = '/internal';
          return $this->render('registration_form');
      }
      public function actionSearchPage()
      {
          $this->layout = '/internal';
          return $this->render('search_page');
      }
  
      public function actionSearchTovarFilters()
      {
          $this->layout = '/internal';
          return $this->render('search_tovar_filters');
      }
  
      public function actionThanks()
      {
          $this->layout = '/internal';
          return $this->render('thanks');
      }
  
      public function actionVinCode()
      {
          $this->layout = '/internal';
          return $this->render('vin_code');
      }
  
  
  
a63b5418   Administrator   first_commit
265
266
267
268
269
270
271
      /**
       * Logs in a user.
       *
       * @return mixed
       */
      public function actionLogin()
      {
27b0cb06   Administrator   VItaliy 02.12.2015
272
273
  
  
a63b5418   Administrator   first_commit
274
          if (!\Yii::$app->user->isGuest) {
27b0cb06   Administrator   VItaliy 02.12.2015
275
  
a63b5418   Administrator   first_commit
276
277
278
              return $this->goHome();
          }
  
27b0cb06   Administrator   VItaliy 02.12.2015
279
280
          $model = new UserLoginForm();
  
a63b5418   Administrator   first_commit
281
282
283
          if ($model->load(Yii::$app->request->post()) && $model->login()) {
              return $this->goBack();
          } else {
27b0cb06   Administrator   VItaliy 02.12.2015
284
              $this->layout = '/internal';
a63b5418   Administrator   first_commit
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
              return $this->render('login', [
                  'model' => $model,
              ]);
          }
      }
  
      /**
       * Logs out the current user.
       *
       * @return mixed
       */
      public function actionLogout()
      {
          Yii::$app->user->logout();
  
          return $this->goHome();
      }
  
89d4b5ac   Administrator   VItaliy 25.11.2015
303
304
  
      public function actionContacts()
a63b5418   Administrator   first_commit
305
      {
89d4b5ac   Administrator   VItaliy 25.11.2015
306
307
308
          $this->layout = '/internal';
          return $this->render('contacts');
      }
a63b5418   Administrator   first_commit
309
  
89d4b5ac   Administrator   VItaliy 25.11.2015
310
311
312
313
314
  
      public function actionPaymentDelivery()
      {
          $this->layout = '/internal';
          return $this->render('payment_delivery');
a63b5418   Administrator   first_commit
315
316
317
318
319
320
321
322
323
      }
  
      /**
       * Displays about page.
       *
       * @return mixed
       */
      public function actionAbout()
      {
89d4b5ac   Administrator   VItaliy 25.11.2015
324
325
          $teamGroups = TeamGroup::find()->all();
  
7b407169   Administrator   upload project
326
          $this->layout = '/internal';
89d4b5ac   Administrator   VItaliy 25.11.2015
327
328
329
          return $this->render('about',[
             'teamGroups' => $teamGroups,
          ]);
a63b5418   Administrator   first_commit
330
331
332
333
334
335
336
337
338
      }
  
      /**
       * Signs user up.
       *
       * @return mixed
       */
      public function actionSignup()
      {
27b0cb06   Administrator   VItaliy 02.12.2015
339
340
341
  
          $this->layout = '/internal';
  
2fd0fce6   Administrator   VItaliy 04.12.2015
342
          $model = new AccountsForm();
89d4b5ac   Administrator   VItaliy 25.11.2015
343
  
2fd0fce6   Administrator   VItaliy 04.12.2015
344
          if ($model->load(Yii::$app->request->post()) && $model->validate() ) {
27b0cb06   Administrator   VItaliy 02.12.2015
345
  
89d4b5ac   Administrator   VItaliy 25.11.2015
346
  
27b0cb06   Administrator   VItaliy 02.12.2015
347
  
2fd0fce6   Administrator   VItaliy 04.12.2015
348
349
350
351
352
353
354
355
356
              $accounts = new Accounts();
  
              $accounts->load(Yii::$app->request->post());
  
              $accounts->generateAuthKey();
  
              $accounts->save();
  
              if (Yii::$app->getUser()->login($accounts)) {
27b0cb06   Administrator   VItaliy 02.12.2015
357
358
  
                  return $this->goHome();
89d4b5ac   Administrator   VItaliy 25.11.2015
359
  
a63b5418   Administrator   first_commit
360
              }
27b0cb06   Administrator   VItaliy 02.12.2015
361
  
a63b5418   Administrator   first_commit
362
363
364
365
366
367
368
369
370
371
372
373
374
375
          }
  
          return $this->render('signup', [
              'model' => $model,
          ]);
      }
  
      /**
       * Requests password reset.
       *
       * @return mixed
       */
      public function actionRequestPasswordReset()
      {
fa5a99de   Administrator   VItaliy 04.12.2015
376
377
          $this->layout = '/internal';
  
a63b5418   Administrator   first_commit
378
          $model = new PasswordResetRequestForm();
2fd0fce6   Administrator   VItaliy 04.12.2015
379
  
a63b5418   Administrator   first_commit
380
          if ($model->load(Yii::$app->request->post()) && $model->validate()) {
fa5a99de   Administrator   VItaliy 04.12.2015
381
  
a63b5418   Administrator   first_commit
382
              if ($model->sendEmail()) {
2fd0fce6   Administrator   VItaliy 04.12.2015
383
  
fa5a99de   Administrator   VItaliy 04.12.2015
384
                  Yii::$app->session->setFlash('success', 'Для того, чтобы изменить пароль, перейдите по ссылке, которая придет Вам на email');
a63b5418   Administrator   first_commit
385
386
387
  
                  return $this->goHome();
              } else {
2fd0fce6   Administrator   VItaliy 04.12.2015
388
                  die('here2');
fa5a99de   Administrator   VItaliy 04.12.2015
389
                  Yii::$app->session->setFlash('error', 'Пользователя с таким e-mail в базе не существует');
a63b5418   Administrator   first_commit
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
              }
          }
  
          return $this->render('requestPasswordResetToken', [
              'model' => $model,
          ]);
      }
  
      /**
       * Resets password.
       *
       * @param string $token
       * @return mixed
       * @throws BadRequestHttpException
       */
      public function actionResetPassword($token)
      {
          try {
              $model = new ResetPasswordForm($token);
          } catch (InvalidParamException $e) {
              throw new BadRequestHttpException($e->getMessage());
          }
  
          if ($model->load(Yii::$app->request->post()) && $model->validate() && $model->resetPassword()) {
              Yii::$app->session->setFlash('success', 'New password was saved.');
  
              return $this->goHome();
          }
  
          return $this->render('resetPassword', [
              'model' => $model,
          ]);
      }
89d4b5ac   Administrator   VItaliy 25.11.2015
423
  
a63b5418   Administrator   first_commit
424
  }