Esempio n. 1
0
 function doRegister($data, $form)
 {
     if (!isset($data["Affiliations"]) || empty($data["Affiliations"])) {
         //Set error message
         $form->AddErrorMessage('Affiliations', "Sorry, You must at least enter one valid Affiliation.", 'bad');
         //Set form data from submitted values
         Session::set("FormInfo.Form_RegistrationForm.data", $data);
         //Return back to form
         return $this->redirectBack();
     }
     $new_affiliations = json_decode($data["Affiliations"]);
     //Check for existing member email address
     if ($member = Member::get()->filter('Email', Convert::raw2sql($data['Email']))->first()) {
         //Set error message
         $form->AddErrorMessage('Email', "Sorry, that email address already exists. Please choose another.", 'bad');
         //Set form data from submitted values
         Session::set("FormInfo.Form_RegistrationForm.data", $data);
         //Return back to form
         return $this->redirectBack();
     }
     //Otherwise create new member and log them in
     $Member = new Member();
     $form->saveInto($Member);
     if (isset($data['Gender'])) {
         $Gender = $data['Gender'];
         if ($Gender != 'Male' && $Gender != 'Female' && $Gender != 'Prefer not to say') {
             $Member->Gender = Convert::raw2sql($data['GenderSpecify']);
         }
     }
     $Member->write();
     if ($data['MembershipType'] == 'foundation') {
         $Member->upgradeToFoundationMember();
     } else {
         $Member->convert2SiteUser();
     }
     //Find or create the 'user' group
     if (!($userGroup = Group::get()->filter('Code', 'users')->first())) {
         $userGroup = new Group();
         $userGroup->Code = "users";
         $userGroup->Title = "Users";
         $userGroup->Write();
         $Member->Groups()->add($userGroup);
     }
     //Add member to user group
     $Member->Groups()->add($userGroup);
     foreach ($new_affiliations as $key => $newAffiliation) {
         $dbAffiliation = new Affiliation();
         $org_name = Convert::raw2sql($newAffiliation->OrgName);
         $org_name = trim($org_name);
         AffiliationController::Save($dbAffiliation, $newAffiliation, $org_name, $Member);
     }
     PublisherSubscriberManager::getInstance()->publish('new_user_registered', array($Member->ID));
     //Get profile page
     if ($ProfilePage = EditProfilePage::get()->first()) {
         //send Thank you email
         $config = SiteConfig::current_site_config();
         if ($config->RegistrationSendMail && !empty($config->RegistrationFromMessage) && !empty($config->RegistrationSubjectMessage) && !empty($config->RegistrationHTMLMessage) && !empty($config->RegistrationPlainTextMessage)) {
             $registration_email = new CustomEmail($config->RegistrationFromMessage, $Member->Email, $data['MembershipType'] == 'foundation' ? 'Thank you for becoming an OpenStack Foundation Member' : 'Thank you for becoming an OpenStack Community Member', $config->RegistrationHTMLMessage, $config->RegistrationPlainTextMessage);
             $registration_email->send();
         }
         //Redirect to profile page with success message
         return OpenStackIdCommon::loginMember($member, $ProfilePage->Link('?success=1'));
     }
 }
Esempio n. 2
0
 * See the License for the specific language governing permissions and
 * limitations under the License.
 **/
PublisherSubscriberManager::getInstance()->subscribe('survey_organization_selected', function ($member, $organization_name) {
    //create the affiliation as current
    $organization_name = Convert::raw2sql(trim($organization_name));
    if (!empty($organization_name)) {
        $org = Org::get()->filter(array('Name' => $organization_name))->first();
        if (!$org) {
            $org = new Org();
            $org->Name = $organization_name;
            $org->IsStandardizedOrg = false;
            $org->write();
            //register new request
            $new_request = new OrganizationRegistrationRequest();
            $new_request->MemberID = $member->getIdentifier();
            $new_request->OrganizationID = $org->ID;
            $new_request->write();
        }
        // If a new org name was provided for the member, find / create the new org and update the member record
        if (!$member->hasCurrentAffiliation($organization_name)) {
            $newAffiliation = new StdClass();
            $newAffiliation->StartDate = date('Y-m-d');
            $newAffiliation->EndDate = null;
            $newAffiliation->Current = 1;
            $newAffiliation->JobTitle = "";
            $newAffiliation->Role = "";
            AffiliationController::Save(new Affiliation(), $newAffiliation, $organization_name, $member);
        }
    }
});
 public function UpdateMember($Organization)
 {
     $Member = Member::currentUser();
     $NewOrg = convert::raw2sql($Organization);
     // If a new org name was provided for the member, find / create the new org and update the member record
     if (!is_null($NewOrg) && !$Member->hasCurrentAffiliation($NewOrg)) {
         $newAffiliation = new StdClass();
         $newAffiliation->StartDate = date('Y-m-d');
         $newAffiliation->EndDate = null;
         $newAffiliation->Current = 1;
         $newAffiliation->JobTitle = "";
         $newAffiliation->Role = "";
         AffiliationController::Save(new Affiliation(), $newAffiliation, $NewOrg, $Member);
     }
 }