/**
  * Creates a new User model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new User(['scenario' => 'create']);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 public function __construct($initUserInYiiApp = false)
 {
     $user = User::findByAttributes(['name' => 'Test', 'last_name' => 'Test']);
     if (!$user) {
         $user = new User();
         $user->setAttributes(['name' => 'Test', 'last_name' => 'Test']);
         $user->save();
         $user = User::findByAttributes(['name' => 'Test', 'last_name' => 'Test']);
     }
     $this->user = $user;
     if ($initUserInYiiApp) {
         Yii::$app->user->model = $this->user;
     }
 }
 /**
  * Creates a new User model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  *
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new User(['scenario' => User::SCENARIO_CREATE]);
     if (Yii::$app->request->isPost) {
         // Traitement du formulaire
         if (!($model->load(Yii::$app->request->post()) && $model->save())) {
             // On ré-affiche le formulaire avec ses erreurs
             Yii::$app->session->setFlash('flash-warning', HLib::t('messages', 'There are errors in your form'));
         } else {
             // Retour à la liste ou redirection sur la page d'édition, selon le bouton qui a été cliqué
             Yii::$app->session->setFlash('flash-success', HLib::t('messages', 'Create successful'));
             $requestedRedirection = Yii::$app->request->getBodyParam('action') == 'saveAndKeepEditing' ? Url::toRoute(['/users/users/update', 'id' => $model->id]) : Url::toRoute('/users/users/index');
             return $this->redirect($requestedRedirection);
         }
     }
     // Affichage ou ré-affichage
     return $this->render('create', compact('model'));
 }
 /**
  * Создаём новую запись.
  * В случае успеха, пользователь будет перенаправлен на view метод.
  */
 public function actionSignup()
 {
     $model = new User(['scenario' => 'signup']);
     // Добавляем обработчик события который отправляет сообщение с клюом активации на e-mail адрес что был указан при регистрации.
     if ($this->module->activeAfterRegistration === false) {
         $model->on(User::EVENT_AFTER_INSERT, [$this->module, 'onSignup']);
     }
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         // Сообщаем пользователю что регистрация прошла успешно.
         Yii::$app->session->setFlash('success', 'users', 'Учётная запись была успешно создана! Вам выслано письмо для подтверждения регистрации. Пока вы не подтвердите регистрацию, некоторые функции сайта будут недоступны');
         // Авторизуем сразу пользователя.
         Yii::$app->getUser()->login($model);
         // Возвращаем пользователя на главную.
         return $this->goHome();
     }
     $model->captcha = '';
     // Рендерим представление.
     return $this->render('signup', ['model' => $model]);
 }
 /**
  * Creates a new User model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $user = new User(['scenario' => 'create']);
     $profile = new Profile();
     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)) {
                 $user->link('profile', $profile);
                 Yii::$app->session->setFlash('success', Module::t('users', 'User has been successfully created.'));
                 return $this->redirect(['update', 'id' => $user->id]);
             } else {
                 Yii::$app->session->setFlash('danger', Module::t('users', 'User has not been saved. Please try again!'));
                 return $this->refresh();
             }
         }
     }
     return $this->render('create', ['user' => $user, 'profile' => $profile]);
 }