Exemple #1
0
 /**
  * Adds the registering user from a form
  */
 public function actionRegister()
 {
     if (!Pii::guest()) {
         $this->redirect('/');
     }
     /** @var $_config Config */
     if (false === ($_config = Config::getOpenRegistration())) {
         throw new BadRequestException("Open registration for users is not currently enabled for this system.");
     }
     $_model = new RegisterUserForm();
     $_viaEmail = null !== Option::get($_config, 'open_reg_email_service_id');
     $_model->setViaEmail($_viaEmail);
     if (isset($_POST, $_POST['RegisterUserForm'])) {
         $_model->attributes = $_POST['RegisterUserForm'];
         if ($_model->validate()) {
             try {
                 $_result = Register::userRegister($_model->getAttributes(), true, false);
                 if ($_viaEmail) {
                     if (Option::getBool($_result, 'success')) {
                         Yii::app()->user->setFlash('register-user-form', 'A registration confirmation has been sent to this email.');
                     }
                 } else {
                     // result should be true
                     if ($_result) {
                         $this->redirect($this->_getRedirectUrl());
                         return;
                     }
                     $_model->addError(null, 'Registration successful, but failed to automatically login.');
                 }
             } catch (\Exception $_ex) {
                 $_model->addError(null, $_ex->getMessage());
             }
         }
     }
     $this->render('register', array('model' => $_model, 'backUrl' => $this->_getRedirectUrl()));
 }
 /**
  * Adds the registering user from a form
  */
 public function actionRegister()
 {
     if (!Pii::guest()) {
         $this->redirect('/');
     }
     /** @var $_config Config */
     if (false === ($_config = Config::getOpenRegistration())) {
         throw new BadRequestException("Open registration for users is not currently enabled for this system.");
     }
     $_model = new RegisterUserForm();
     $_viaEmail = null !== Option::get($_config, 'open_reg_email_service_id');
     $_model->setViaEmail($_viaEmail);
     $_form = isset($_POST) ? Option::get($_POST, 'RegisterUserForm', array()) : null;
     if (!empty($_form)) {
         $_model->email = filter_var(Option::get($_form, 'email'), FILTER_SANITIZE_EMAIL);
         $_model->password = filter_var(Option::get($_form, 'password'), FILTER_SANITIZE_STRING);
         $_model->password_repeat = filter_var(Option::get($_form, 'password_repeat'), FILTER_SANITIZE_STRING);
         $_model->first_name = filter_var(Option::get($_form, 'first_name'), FILTER_SANITIZE_STRING);
         $_model->last_name = filter_var(Option::get($_form, 'last_name'), FILTER_SANITIZE_STRING);
         $_model->display_name = filter_var(Option::get($_form, 'display_name'), FILTER_SANITIZE_STRING);
         if ($_model->validate()) {
             try {
                 $_result = Register::userRegister($_model->getAttributes(), true, false);
                 if ($_viaEmail) {
                     if (Option::getBool($_result, 'success')) {
                         Yii::app()->user->setFlash('register-user-form', 'A registration confirmation has been sent to this email.');
                     }
                 } else {
                     // result should be true
                     if ($_result) {
                         $this->redirect($this->_getRedirectUrl());
                         return;
                     }
                     $_model->addError(null, 'Registration successful, but failed to automatically login.');
                 }
             } catch (\Exception $_ex) {
                 $_model->addError(null, $_ex->getMessage());
             }
         }
     }
     $this->render('register', array('model' => $_model, 'backUrl' => $this->_getRedirectUrl()));
 }