Blame view

frontend/controllers/LoginController.php 1.58 KB
ecf49b1b   Administrator   second
1
2
3
4
5
6
  <?php
  
  namespace frontend\controllers;
  
  use Yii;
  use yii\web\Controller;
7ba4acc5   Administrator   after marge
7
8
  use frontend\models\LoginForm;
  use common\models\Customer;
ecf49b1b   Administrator   second
9
  
2561bc74   Dmytry Fedorchuk   restet password mail
10
11
  use common\widgets\Mailer;
  
ecf49b1b   Administrator   second
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
  class LoginController extends Controller
  {
  	//public $layout='layout';
      public function actionIndex()
      {
          if (!\Yii::$app->user->isGuest) {
              return $this->goHome();
          }
  
          $model = new LoginForm();
          if ($model->load(Yii::$app->request->post()) && $model->login()) {
              return $this->goBack();
          } else {
              return $this->render('index', [
                  'model' => $model,
              ]);
          }
      }
  	
      public function actionLogout()
      {
          Yii::$app->user->logout();
  
          return $this->goHome();
      }
      
      public function actionForgot(){
7ba4acc5   Administrator   after marge
39
              $model = new Customer;
ffe503d1   Dmytry Fedorchuk   images
40
              if(!empty($_POST['Customer']['username'])){
57e7caa3   Dmytry Fedorchuk   images
41
                  if($user = Customer::find()->where(['username'=>$_POST['Customer']['username']])->one())
462ce364   Dmytry Fedorchuk   restet password mail
42
43
44
45
46
47
                      Mailer::widget(
                          ['type' => 'password',
                              'subject'=> 'Ваш пароль',
                              'email' => $user->email,
                              'params' => $user,
                          ]);
ecf49b1b   Administrator   second
48
49
50
51
                      $user->sendMsg();
                  Yii::$app->getSession()->setFlash('success', 'На указанный Вами эмейл отправленно письмо с паролем!');
                  return $this->refresh();
              }
7ba4acc5   Administrator   after marge
52
  
ecf49b1b   Administrator   second
53
54
              return $this->render('forgot', [
                  'model' => $model,
7ba4acc5   Administrator   after marge
55
              ]);
ecf49b1b   Administrator   second
56
57
      }
  }