/**
  * Регистрация
  * @return array|string|Response
  */
 public function actionSignup()
 {
     $user = new models\User(['scenario' => 'signup']);
     $profile = new models\Profile(['scenario' => 'signup']);
     if ($user->load(Yii::$app->request->post()) && $profile->load(Yii::$app->request->post())) {
         if ($user->validate() && $profile->validate()) {
             $user->populateRelation('profile', $profile);
             if ($user->save(false)) {
                 if ($this->module->requireEmailConfirmation === true) {
                     Yii::$app->consoleRunner->run('users/control/send-email ' . $user->email . ' signup "' . Yii::t('users', 'SUBJECT_SIGNUP') . '"');
                     Yii::$app->session->setFlash('success', Yii::t('users', 'SUCCESS_SIGNUP_WITHOUT_LOGIN', ['url' => Url::toRoute('resend')]));
                 } else {
                     Yii::$app->user->login($user);
                     Yii::$app->session->setFlash('success', Yii::t('users', 'SUCCESS_SIGNUP_WITH_LOGIN'));
                 }
                 return $this->redirect(['login']);
             } else {
                 Yii::$app->session->setFlash('danger', Yii::t('users', 'FAIL_SIGNUP'));
                 return $this->refresh();
             }
         } else {
             if (Yii::$app->request->isAjax) {
                 Yii::$app->response->format = Response::FORMAT_JSON;
                 return ActiveForm::validate($user);
             }
         }
     }
     return $this->render('signup', ['user' => $user, 'profile' => $profile]);
 }
 /**
  * Профиль
  * @return array|string|Response
  */
 public function actionProfile()
 {
     $model = models\Profile::findByUserId(Yii::$app->user->id);
     $model->setScenario('signup');
     if ($model->load(Yii::$app->request->post())) {
         if ($model->validate()) {
             if ($model->save(false)) {
                 Yii::$app->session->setFlash('success', Yii::t('users', 'SUCCESS_UPDATE'));
             } else {
                 Yii::$app->session->setFlash('danger', Yii::t('users', 'FAIL_UPDATE'));
             }
             return $this->refresh();
         } elseif (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ActiveForm::validate($model);
         }
     }
     return $this->render('profile', ['model' => $model]);
 }
示例#3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getProfile()
 {
     return $this->hasOne(Profile::className(), ['user_id' => 'id']);
 }