Ejemplo n.º 1
0
 /**
  * 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 = GetValue('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();
             unset($Values['Roles']);
             $AuthUserID = $this->UserModel->Register($Values, array('Method' => 'Invitation'));
             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 = GetValue('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();
 }