register() public méthode

Register a new user.
public register ( array $FormPostValues, array $Options = [] ) : boolean | integer | string
$FormPostValues array
$Options array
Résultat boolean | integer | string
 public static function completeRegister()
 {
     require_once 'User.model.php';
     $data = array();
     if (isset($_POST['createAccount'])) {
         $username = $_POST['username'];
         $password = $_POST['password'];
         $name = $_POST['name'];
         $membership = $_POST['membership'];
         $state = $_POST['state'];
         $email = $_POST['email'];
         $adress = $_POST['adress'];
         $zip_code = $_POST['zip_code'];
         $phone = $_POST['phone'];
         $city = $_POST['city'];
         try {
             $result = UserModel::register($username, $password, $name, $membership, $state, $email, $adress, $zip_code, $phone, $city);
             $data['template'] = 'registerSuccess.html';
         } catch (Exception $e) {
             $data['template'] = 'error.html';
             $data['error'] = $e->getMessage();
         }
     } else {
         $data['redirect'] = '?/User/register';
     }
     return $data;
 }
Exemple #2
0
 public static function register($username, $email, $name, $raw_password)
 {
     global $user;
     if ($user->is_authenticated()) {
         return false;
     }
     // do db stuff here
     $password = $user->hash_password($raw_password);
     $r = UserModel::register($username, $email, $name, $password);
     // finally login user
     self::login($username, $raw_password);
     return true;
 }
 /**
  * Invitation-only registration. Requires code.
  *
  * @param int $InvitationCode
  * @since 2.0.0
  */
 public function registerInvitation($InvitationCode = 0)
 {
     $this->Form->setModel($this->UserModel);
     // Define gender dropdown options
     $this->GenderOptions = array('u' => t('Unspecified'), 'm' => t('Male'), 'f' => t('Female'));
     if (!$this->Form->isPostBack()) {
         $this->Form->setValue('InvitationCode', $InvitationCode);
     }
     $InvitationModel = new InvitationModel();
     // Look for the invitation.
     $Invitation = $InvitationModel->getWhere(array('Code' => $this->Form->getValue('InvitationCode')))->firstRow(DATASET_TYPE_ARRAY);
     if (!$Invitation) {
         $this->Form->addError('Invitation not found.', 'Code');
     } else {
         if ($Expires = val('DateExpires', $Invitation)) {
             $Expires = Gdn_Format::toTimestamp($Expires);
             if ($Expires <= time()) {
             }
         }
     }
     $this->Form->addHidden('ClientHour', date('Y-m-d H:00'));
     // Use the server's current hour as a default
     $this->Form->addHidden('Target', $this->target());
     Gdn::userModel()->addPasswordStrength($this);
     if ($this->Form->isPostBack() === true) {
         $this->InvitationCode = $this->Form->getValue('InvitationCode');
         // Add validation rules that are not enforced by the model
         $this->UserModel->defineSchema();
         $this->UserModel->Validation->applyRule('Name', 'Username', $this->UsernameError);
         $this->UserModel->Validation->applyRule('TermsOfService', 'Required', t('You must agree to the terms of service.'));
         $this->UserModel->Validation->applyRule('Password', 'Required');
         $this->UserModel->Validation->applyRule('Password', 'Strength');
         $this->UserModel->Validation->applyRule('Password', 'Match');
         // $this->UserModel->Validation->applyRule('DateOfBirth', 'MinimumAge');
         $this->fireEvent('RegisterValidation');
         try {
             $Values = $this->Form->formValues();
             $Values = $this->UserModel->filterForm($Values, true);
             unset($Values['Roles']);
             $AuthUserID = $this->UserModel->register($Values, array('Method' => 'Invitation'));
             $this->setData('UserID', $AuthUserID);
             if (!$AuthUserID) {
                 $this->Form->setValidationResults($this->UserModel->validationResults());
             } else {
                 // The user has been created successfully, so sign in now.
                 Gdn::session()->start($AuthUserID);
                 if ($this->Form->getFormValue('RememberMe')) {
                     Gdn::authenticator()->setIdentity($AuthUserID, true);
                 }
                 $this->fireEvent('RegistrationSuccessful');
                 // ... and redirect them appropriately
                 $Route = $this->redirectTo();
                 if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
                     $this->RedirectUrl = url($Route);
                 } else {
                     if ($Route !== false) {
                         redirect($Route);
                     }
                 }
             }
         } catch (Exception $Ex) {
             $this->Form->addError($Ex);
         }
     } else {
         // Set some form defaults.
         if ($Name = val('Name', $Invitation)) {
             $this->Form->setValue('Name', $Name);
         }
         $this->InvitationCode = $InvitationCode;
     }
     // Make sure that the hour offset for new users gets defined when their account is created
     $this->addJsFile('entry.js');
     $this->render();
 }
Exemple #4
0
 protected function register()
 {
     $viewmodel = new UserModel();
     $this->getView($viewmodel->register(), true);
 }