Exemple #1
0
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = User::findByEmail($this->email);
     }
     return $this->_user;
 }
Exemple #2
0
 public function actionIndex()
 {
     $model = new RegForm();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         // данные в $model удачно проверены
         $user = new User();
         $user->username = $model->username;
         $user->email = $model->email;
         $user->generatePassword($model->password);
         $user->created_at = time();
         $user->updated_at = time();
         $user->status = 0;
         $user->getAuthKey();
         $user->save();
         $user->cash_id = md5($user->id);
         $user->save();
         $authManager = \Yii::$app->authManager;
         $role = $authManager->getRole(User::TYPE_USER);
         $authManager->assign($role, $user->id);
         Email::sendActivateMail($user);
         $this->layout = "no_login";
         return $this->render('index', ['model' => $model]);
     } else {
         // либо страница отображается первый раз, либо есть ошибка в данных
         $this->layout = "login";
         return $this->render('form', ['model' => $model]);
     }
 }