Blame view

frontend/controllers/SiteController.php 10.8 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;
5e9f3657   Administrator   VItaliy 21.12.2015
8
  
89d4b5ac   Administrator   VItaliy 25.11.2015
9
  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
  use frontend\models\PasswordResetRequestForm;
  use frontend\models\ResetPasswordForm;
5e9f3657   Administrator   VItaliy 21.12.2015
14
  
a63b5418   Administrator   first_commit
15
16
17
  use yii\base\InvalidParamException;
  use yii\web\BadRequestHttpException;
  use yii\web\Controller;
fa5a99de   Administrator   VItaliy 04.12.2015
18
  
068f769f   Administrator   first commit from...
19
20
  use common\models\Callback;
  use common\components\MailWidget;
5e9f3657   Administrator   VItaliy 21.12.2015
21
22
23
  use frontend\models\SiteSearchForm;
  use yii\db\Query;
  use yii\data\ArrayDataProvider;
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
  
      /**
       * @inheritdoc
       */
      public function actions()
      {
          return [
              'error' => [
                  'class' => 'yii\web\ErrorAction',
              ],
              'captcha' => [
                  'class' => 'yii\captcha\CaptchaAction',
                  'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
              ],
          ];
      }
  
5e9f3657   Administrator   VItaliy 21.12.2015
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
      public function actionSearch()
      {
          $this->layout = '/internal';
          $search = new SiteSearchForm();
          if ($search->load(Yii::$app->request->get()) && $search->validate()) {
  //            $query1 = (new Query())
  //                ->select('name, image, description, translit ')
  //                ->addSelect(["CONCAT('stone/view') AS url"])
  //                ->where(['like','name',$search->string])
  //                ->from('{{%stone}}');
  //
  //            $query2 = (new Query())
  //                ->select('name, image, description, translit ')
  //                ->addSelect(["CONCAT('goods/one-item') AS url"])
  //                ->where(['like','name',$search->string])
  //                ->from('{{%goods}}');
  //
  //            $dataProvider = new ArrayDataProvider([
  //                'allModels' => $query1->union($query2)->all(),
  //                'pagination' => [
  //                    'pageSize' => 6,
  //                ],
  //
  //            ]);
              $dataProvider = array();
  
              return $this->render('search', [
  
                  'dataProvider' => $dataProvider,
              ]);
  
  
          }
      }
  
a63b5418   Administrator   first_commit
83
84
85
86
87
88
89
      /**
       * Displays homepage.
       *
       * @return mixed
       */
      public function actionIndex()
      {
27b0cb06   Administrator   VItaliy 02.12.2015
90
  
394e2db6   Administrator   Importers CRUD
91
          $this->layout = '/outer';
068f769f   Administrator   first commit from...
92
  
1ec3afef   Administrator   VItaliy 27.11.2015
93
          $news_list = News::find()->where(['is_active'=>1])->limit(3)->all();
25545a10   Administrator   VItaliy 30.11.2015
94
          $slider_list = Slider::find()->where(['is_active'=>1])->all();
068f769f   Administrator   first commit from...
95
96
97
98
99
100
101
102
103
          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
104
                  MailWidget::widget(['email' => 'ital-auto@test.com', 'text' => $text, 'subject' => 'Обратный звонок']);
068f769f   Administrator   first commit from...
105
106
107
              }
  
          }
1ec3afef   Administrator   VItaliy 27.11.2015
108
          return $this->render('index',[
25545a10   Administrator   VItaliy 30.11.2015
109
              'slider_list' => $slider_list,
1ec3afef   Administrator   VItaliy 27.11.2015
110
111
              'news_list' => $news_list
          ]);
a63b5418   Administrator   first_commit
112
113
      }
  
394e2db6   Administrator   Importers CRUD
114
115
116
117
118
119
120
121
122
123
      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
124
  
394e2db6   Administrator   Importers CRUD
125
  
25545a10   Administrator   VItaliy 30.11.2015
126
      public function actionTeam()
394e2db6   Administrator   Importers CRUD
127
      {
25545a10   Administrator   VItaliy 30.11.2015
128
129
          $teamGroups = TeamGroup::find()->all();
  
394e2db6   Administrator   Importers CRUD
130
          $this->layout = '/internal';
25545a10   Administrator   VItaliy 30.11.2015
131
132
133
134
          return $this->render('team',[
              'teamGroups' => $teamGroups,
          ]);
  
394e2db6   Administrator   Importers CRUD
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
      }
  
      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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
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
  
      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
215
      public function actionWholesalers()
394e2db6   Administrator   Importers CRUD
216
217
      {
          $this->layout = '/internal';
89d4b5ac   Administrator   VItaliy 25.11.2015
218
          return $this->render('wholesalers');
394e2db6   Administrator   Importers CRUD
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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
      }
  
      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
300
301
302
303
304
305
306
      /**
       * Logs in a user.
       *
       * @return mixed
       */
      public function actionLogin()
      {
27b0cb06   Administrator   VItaliy 02.12.2015
307
308
  
  
a63b5418   Administrator   first_commit
309
          if (!\Yii::$app->user->isGuest) {
27b0cb06   Administrator   VItaliy 02.12.2015
310
  
a63b5418   Administrator   first_commit
311
312
313
              return $this->goHome();
          }
  
27b0cb06   Administrator   VItaliy 02.12.2015
314
315
          $model = new UserLoginForm();
  
a63b5418   Administrator   first_commit
316
317
318
          if ($model->load(Yii::$app->request->post()) && $model->login()) {
              return $this->goBack();
          } else {
27b0cb06   Administrator   VItaliy 02.12.2015
319
              $this->layout = '/internal';
a63b5418   Administrator   first_commit
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
              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
338
339
  
      public function actionContacts()
a63b5418   Administrator   first_commit
340
      {
89d4b5ac   Administrator   VItaliy 25.11.2015
341
342
343
          $this->layout = '/internal';
          return $this->render('contacts');
      }
a63b5418   Administrator   first_commit
344
  
89d4b5ac   Administrator   VItaliy 25.11.2015
345
346
347
348
349
  
      public function actionPaymentDelivery()
      {
          $this->layout = '/internal';
          return $this->render('payment_delivery');
a63b5418   Administrator   first_commit
350
351
352
353
354
355
356
357
358
      }
  
      /**
       * Displays about page.
       *
       * @return mixed
       */
      public function actionAbout()
      {
89d4b5ac   Administrator   VItaliy 25.11.2015
359
360
          $teamGroups = TeamGroup::find()->all();
  
7b407169   Administrator   upload project
361
          $this->layout = '/internal';
89d4b5ac   Administrator   VItaliy 25.11.2015
362
363
364
          return $this->render('about',[
             'teamGroups' => $teamGroups,
          ]);
a63b5418   Administrator   first_commit
365
366
367
368
369
370
371
372
373
      }
  
      /**
       * Signs user up.
       *
       * @return mixed
       */
      public function actionSignup()
      {
27b0cb06   Administrator   VItaliy 02.12.2015
374
375
376
  
          $this->layout = '/internal';
  
2fd0fce6   Administrator   VItaliy 04.12.2015
377
          $model = new AccountsForm();
89d4b5ac   Administrator   VItaliy 25.11.2015
378
  
2fd0fce6   Administrator   VItaliy 04.12.2015
379
          if ($model->load(Yii::$app->request->post()) && $model->validate() ) {
27b0cb06   Administrator   VItaliy 02.12.2015
380
  
89d4b5ac   Administrator   VItaliy 25.11.2015
381
  
27b0cb06   Administrator   VItaliy 02.12.2015
382
  
2fd0fce6   Administrator   VItaliy 04.12.2015
383
384
385
386
387
388
389
390
391
              $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
392
393
  
                  return $this->goHome();
89d4b5ac   Administrator   VItaliy 25.11.2015
394
  
a63b5418   Administrator   first_commit
395
              }
27b0cb06   Administrator   VItaliy 02.12.2015
396
  
a63b5418   Administrator   first_commit
397
398
399
400
401
402
403
404
405
406
407
408
409
410
          }
  
          return $this->render('signup', [
              'model' => $model,
          ]);
      }
  
      /**
       * Requests password reset.
       *
       * @return mixed
       */
      public function actionRequestPasswordReset()
      {
fa5a99de   Administrator   VItaliy 04.12.2015
411
412
          $this->layout = '/internal';
  
a63b5418   Administrator   first_commit
413
          $model = new PasswordResetRequestForm();
2fd0fce6   Administrator   VItaliy 04.12.2015
414
  
a63b5418   Administrator   first_commit
415
          if ($model->load(Yii::$app->request->post()) && $model->validate()) {
fa5a99de   Administrator   VItaliy 04.12.2015
416
  
a63b5418   Administrator   first_commit
417
              if ($model->sendEmail()) {
2fd0fce6   Administrator   VItaliy 04.12.2015
418
  
fa5a99de   Administrator   VItaliy 04.12.2015
419
                  Yii::$app->session->setFlash('success', 'Для того, чтобы изменить пароль, перейдите по ссылке, которая придет Вам на email');
a63b5418   Administrator   first_commit
420
421
422
  
                  return $this->goHome();
              } else {
2fd0fce6   Administrator   VItaliy 04.12.2015
423
                  die('here2');
fa5a99de   Administrator   VItaliy 04.12.2015
424
                  Yii::$app->session->setFlash('error', 'Пользователя с таким e-mail в базе не существует');
a63b5418   Administrator   first_commit
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
              }
          }
  
          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
458
  
a63b5418   Administrator   first_commit
459
  }