public function actionRegister() { $model = new RegistrationForm(); $form = Yii::$app->request->post('RegistrationForm'); $user = new User(); $model->attributes = $form; $email = $user->checkEmail($model->email); if ($model->validate()) { if ($email["count"] == 0) { $user->addUser($model); return $this->redirect('http://masterillla.com/web/index.php?r=registration/success'); } else { return $this->redirect('http://masterillla.com/web/index.php?r=registration/error'); } } else { return $this->redirect('http://masterillla.com/web/index.php?r=registration/error'); } }
/** * actionRegister * * the Register action contains most of the logic behind user registration. * When it is called it checks to see if any data can be loaded into the * RegistrationForm model. If not then that means the user has not yet been * taken to the registration page, so it collects the data need to render * the registration page/form (all of the states and counties needed to fill * in the dropdowns, etc.) and renders view/site/registration. If however * data is able to be loaded into the RegistrationForm model, then that * means that the user has already submitted a filled out form, so it calls * model->validate() to make sure that all of the input is good and to make * sure that the entered username and email address have not already been * taken. If that does not return any errors then newUser(), a member * function of SiteController, is called and the RegistrationForm model is * passed in. After that, registration-confirm is rendered. */ public function actionRegister() { /** * check if the user is already logged in * if so, do nothing and return them to the home screen */ if (!\Yii::$app->user->isGuest) { return $this->goHome(); } /** * loads model that will store all data entered into the ActiveForm * on register.php and contains all front-end validation rules */ $model = new RegistrationForm(); /* Used to populate 'select state' dropdown and 'select region' section */ $stateList = State::find()->all(); /* Used to populate the 'select region' multiselects */ $countyList = County::find()->orderBy('name')->all(); /** * if the user has made a 'post' request AND registration form model * is able to succesfully register the user based on the inputted information */ if ($model->load(Yii::$app->request->post()) && $model->validate()) { /* Calls member function newUser() and passes in a populated model */ $this->newUser($model); /* registration was successful, go back to registration-confirm view */ return $this->render('registration-confirm', ['model' => $model]); } else { /** * The user has not yet been taken to the registration form so * render the registration view and pass in an empty RegistrationForm * model that is stored in $model */ return $this->render('register', ['model' => $model, 'stateList' => $stateList, 'countyList' => $countyList]); } }