Exemple #1
0
 /**
  * Create user page.
  */
 public function actionCreate()
 {
     $user = new User(['scenario' => 'admin-create']);
     $profile = new Profile();
     $statusArray = User::getStatusArray();
     $roleArray = User::getRoleArray();
     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)) {
                 return $this->redirect(['update', 'id' => $user->id]);
             } else {
                 Yii::$app->session->setFlash('danger', Module::t('users', 'BACKEND_FLASH_FAIL_ADMIN_CREATE'));
                 return $this->refresh();
             }
         } elseif (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return array_merge(ActiveForm::validate($user), ActiveForm::validate($profile));
         }
     }
     return $this->render('create', ['user' => $user, 'profile' => $profile, 'roleArray' => $roleArray, 'statusArray' => $statusArray]);
 }
Exemple #2
-1
 /**
  * Sign Up page.
  * If record will be successful created, user will be redirected to home page.
  */
 public function actionSignup()
 {
     $user = new User(['scenario' => 'signup']);
     $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)) {
                 if ($this->module->requireEmailConfirmation === true) {
                     Yii::$app->session->setFlash('success', Module::t('users', 'FRONTEND_FLASH_SUCCESS_SIGNUP_WITHOUT_LOGIN', ['url' => Url::toRoute('resend')]));
                 } else {
                     Yii::$app->user->login($user);
                     Yii::$app->session->setFlash('success', Module::t('users', 'FRONTEND_FLASH_SUCCESS_SIGNUP_WITH_LOGIN'));
                 }
                 return $this->goHome();
             } else {
                 Yii::$app->session->setFlash('danger', Module::t('users', 'FRONTEND_FLASH_FAIL_SIGNUP'));
                 return $this->refresh();
             }
         } elseif (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ActiveForm::validate($user);
         }
     }
     return $this->render('signup', ['user' => $user, 'profile' => $profile]);
 }