public function actionSignup()
 {
     $model = new ProfileForm();
     $model->setScenario('signup');
     if ($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]);
 }
 public function testNotCorrectSignup()
 {
     $model = new ProfileForm(['username' => 'troy.becker', 'email' => '*****@*****.**', 'password' => 'some_password']);
     expect('username and email are in use, user should not be created', $model->signup())->null();
 }
 /**
  * Страница продукта
  */
 public function actionProductBuy($id)
 {
     $item = Product::find()->with('organization', 'type')->with('agreement')->where(['id' => $id])->asArray()->one();
     $item['price_format'] = Product::priceFormat($item['price']);
     $item['price_discount_format'] = Product::priceFormat($item['price_discount']);
     if (!count($item['agreement'])) {
         $agreement = Agreement::find()->where(["default_flag" => 1])->asArray()->one();
         $item['agreement'] = $agreement;
     }
     // Загружаем в форму данные пользователя
     $user = Yii::$app->user->getIdentity();
     $model_signup = array();
     $page = $user ? 'product_buy' : 'buy_forbidden';
     if ($page == 'buy_forbidden') {
         $model_signup = new ProfileForm();
         $model_signup->setScenario('signup');
         if ($model_signup->load(Yii::$app->request->post())) {
             if ($user = $model_signup->signup()) {
                 if (Yii::$app->getUser()->login($user)) {
                     return $this->redirect(Yii::$app->request->referrer);
                     //return $this->goHome();
                 }
             }
         }
     } else {
         if (Yii::$app->request->post() && $user) {
             // Устанавливаем сценарий валидации
             $form = new OrderForm();
             if ($form->saveOrder($user, $item, Yii::$app->request->post())) {
                 die('true');
             } else {
                 die('false');
             }
         }
     }
     return $this->render($page, ['item' => $item, 'user' => $user, 'model_signup' => $model_signup]);
 }