Blame view

frontend/controllers/LoginController.php 1.29 KB
ecf49b1b   Administrator   second
1
2
3
4
5
6
7
8
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
  <?php
  
  namespace frontend\controllers;
  
  use Yii;
  use yii\web\Controller;
  use common\models\LoginForm;
  use common\models\User;
  
  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(){
          
              $model = new User;
              if(!empty($_POST['User']['username'])){
                  if($user = User::find()->where(['username'=>$_POST['User']['username']])->one())
                      $user->sendMsg();
                  Yii::$app->getSession()->setFlash('success', 'На указанный Вами эмейл отправленно письмо с паролем!');
                  return $this->refresh();
              }
          
              return $this->render('forgot', [
                  'model' => $model,
              ]);        
      }
  }