Blame view

frontend/controllers/LoginController.php 1.56 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
10
11
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
  
  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
37
              $model = new Customer;
ffe503d1   Dmytry Fedorchuk   images
38
              if(!empty($_POST['Customer']['username'])){
57e7caa3   Dmytry Fedorchuk   images
39
                  if($user = Customer::find()->where(['username'=>$_POST['Customer']['username']])->one())
462ce364   Dmytry Fedorchuk   restet password mail
40
41
42
43
44
45
                      Mailer::widget(
                          ['type' => 'password',
                              'subject'=> 'Ваш пароль',
                              'email' => $user->email,
                              'params' => $user,
                          ]);
ecf49b1b   Administrator   second
46
47
48
49
                      $user->sendMsg();
                  Yii::$app->getSession()->setFlash('success', 'На указанный Вами эмейл отправленно письмо с паролем!');
                  return $this->refresh();
              }
7ba4acc5   Administrator   after marge
50
  
ecf49b1b   Administrator   second
51
52
              return $this->render('forgot', [
                  'model' => $model,
7ba4acc5   Administrator   after marge
53
              ]);
ecf49b1b   Administrator   second
54
55
      }
  }