Blame view

frontend/controllers/SiteController.php 3.58 KB
4253cbec   root   first commit
1
2
3
4
  <?php
  
  namespace frontend\controllers;
  
a1a60fa5   Administrator   big commti
5
  use common\components\Mailer;
4253cbec   root   first commit
6
  use Yii;
a1a60fa5   Administrator   big commti
7
8
9
10
11
12
13
  use common\models\LoginForm;
  use frontend\models\PasswordResetRequestForm;
  use frontend\models\ResetPasswordForm;
  use frontend\models\SignupForm;
  use frontend\models\ContactForm;
  use yii\base\InvalidParamException;
  use yii\web\BadRequestHttpException;
4253cbec   root   first commit
14
  use yii\web\Controller;
a1a60fa5   Administrator   big commti
15
16
17
18
  use yii\filters\VerbFilter;
  use yii\filters\AccessControl;
  use yii\web\Response;
  use yii\widgets\ActiveForm;
4253cbec   root   first commit
19
20
  class SiteController extends Controller
  {
e337d04a   Administrator   liniya first commit
21
  
4253cbec   root   first commit
22
  
076b9c96   Administrator   big commti
23
      public function actionMain()
4253cbec   root   first commit
24
25
      {
  
4253cbec   root   first commit
26
27
  
          return $this->render('index', [
4253cbec   root   first commit
28
29
  
  
4253cbec   root   first commit
30
31
32
          ]);
      }
  
c93ce871   Administrator   big commti
33
34
35
36
37
38
39
40
      /**
       * Logs out the current user.
       *
       * @return mixed
       */
      public function actionLogout()
      {
          Yii::$app->user->logout();
4253cbec   root   first commit
41
  
c93ce871   Administrator   big commti
42
43
          return $this->goHome();
      }
a1a60fa5   Administrator   big commti
44
45
46
47
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
83
84
85
86
87
88
89
90
91
92
93
94
      /**
       * Logs in a user.
       *
       * @return mixed
       */
      public function actionLogin()
      {
          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,
              ]);
          }
      }
  
  
      /**
       * Signs user up.
       *
       * @return mixed
       */
      public function actionSignup()
      {
  
          if(Yii::$app->request->post()){
              if (Yii::$app->request->isAjax) {
                  Yii::$app->response->format = Response::FORMAT_JSON;
                  $model = new SignupForm();
                  $model->load(Yii::$app->request->post());
                  return ActiveForm::validate($model);
              } else {
                  $model = new SignupForm();
                  $model->load(Yii::$app->request->post());
                  if ($user = $model->signup()) {
                      if (Yii::$app->getUser()->login($user)) {
                          return $this->goHome();
                      }
                  }
              }
          }
          return $this->render('signup', [
              'model' => $model,
          ]);
      }
  
37415bee   Administrator   big commti
95
      public function actionError(){
37415bee   Administrator   big commti
96
97
          return $this->render('error', [
              'code'=>'404',
37415bee   Administrator   big commti
98
99
          ]);
      }
fe0fcefc   Administrator   big commti
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
      /**
       * Requests password reset.
       *
       * @return mixed
       */
      public function actionRequestPasswordReset()
      {
          $model = new PasswordResetRequestForm();
          if ($model->load(Yii::$app->request->post()) && $model->validate()) {
              if ($model->sendEmail()) {
                  Yii::$app->session->setFlash('success', 'Check your email for further instructions.');
  
                  return $this->goHome();
              } else {
                  Yii::$app->session->setFlash('error', 'Sorry, we are unable to reset password for email provided.');
              }
          }
  
          return $this->render('requestPasswordResetToken', [
              'model' => $model,
          ]);
      }
01cfd880   Administrator   big commti
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
  
  
      /**
       * 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,
          ]);
      }
4253cbec   root   first commit
149
  }