public function onAfterWrite() { $changed = $this->owner->getChangedFields(); if (array_key_exists('NeedsApproval', $changed)) { $before = $changed['NeedsApproval']['before']; $after = $changed['NeedsApproval']['after']; $page = $this->owner->ProfilePage(); $email = $page->EmailType; if ($before == true && $after == false && $email != 'None') { $email = new MemberConfirmationEmail($page, $this->owner); $email->send(); } } }
/** * @covers MemberConfirmationEmail::get_parsed_string */ public function testGetParsedString() { $page = new MemberProfilePage(); $member = new Member(); $member->Email = 'Test Email'; $member->FirstName = 'Test'; $member->LastName = 'User'; $member->write(); $raw = '<ul> <li>Cost: $10</li> <li>Site Name: $SiteName</li> <li>Login Link: $LoginLink</li> <li>Member: <ul> <li>Since: $Member.Created</li> <li>Email: $Member.Email</li> <li>Name: $Member.Name</li> <li>Surname: $Member.Surname</li> </ul> </li> </ul>'; $expected = "<ul>\n\t\t\t<li>Cost: \$10</li>\n\t\t\t<li>Site Name: " . SiteConfig::current_site_config()->Title . "</li>\n\t\t\t<li>Login Link: " . Director::absoluteURL(Security::Link('login')) . "</li>\n\t\t\t<li>Member:\n\t\t\t\t<ul>\n\t\t\t\t\t<li>Since: " . $member->obj('Created')->Nice() . "</li>\n\t\t\t\t\t<li>Email: {$member->Email}</li>\n\t\t\t\t\t<li>Name: {$member->Name}</li>\n\t\t\t\t\t<li>Surname: {$member->Surname}</li>\n\t\t\t\t</ul>\n\t\t\t</li>\n\t\t</ul>"; $this->assertEquals($expected, MemberConfirmationEmail::get_parsed_string($raw, $member, $page), 'All allowed variables are parsed into the string.'); }
/** * Attempts to save either a registration or add member form submission * into a new member object, returning NULL on validation failure. * * @return Member|null */ protected function addMember($form) { $member = new Member(); $groupIds = $this->getSettableGroupIdsFrom($form); $form->saveInto($member); $member->ProfilePageID = $this->ID; $member->NeedsValidation = $this->EmailType == 'Validation'; $member->NeedsApproval = $this->RequireApproval; try { $member->write(); } catch (ValidationException $e) { $form->sessionMessage($e->getResult()->message(), 'bad'); return; } // set after member is created otherwise the member object does not exist $member->Groups()->setByIDList($groupIds); // If we require admin approval, send an email to the admin and delay // sending an email to the member. if ($this->RequireApproval) { $groups = $this->ApprovalGroups(); $emails = array(); if ($groups) { foreach ($groups as $group) { foreach ($group->Members() as $_member) { if ($member->Email) { $emails[] = $_member->Email; } } } } if ($emails) { $email = new Email(); $config = SiteConfig::current_site_config(); $approve = Controller::join_links(Director::baseURL(), 'member-approval', $member->ID, '?token=' . $member->ValidationKey); $email->setSubject("Registration Approval Requested for {$config->Title}"); $email->setBcc(implode(',', array_unique($emails))); $email->setTemplate('MemberRequiresApprovalEmail'); $email->populateTemplate(array('SiteConfig' => $config, 'Member' => $member, 'ApproveLink' => Director::absoluteURL($approve))); $email->send(); } } elseif ($this->EmailType != 'None') { $email = new MemberConfirmationEmail($this, $member); $email->send(); } $this->extend('onAddMember', $member); return $member; }
function SaveNewProfile($data, $form) { $groupIds = array(); $member = new Member(); //Check for another member with the same email address if ($existingMember = Member::get_one("Member", "Email = '" . Convert::raw2sql($data['Email']) . "'")) { $form->sessionMessage('Die Emailadresse ist schon in Verwendung.', 'bad'); return $this->redirectBack(); } else { $form->saveInto($member); } $member->NeedsValidation = true; try { $member->write(); } catch (ValidationException $e) { $form->sessionMessage($e->getResult()->message(), 'bad'); return; } foreach ($this->Groups()->column('ID') as $mustId) { $groupIds[] = $mustId; } $member->Groups()->setByIDList($groupIds); $member->write(); $email = new MemberConfirmationEmail($this, $member); $email->send(); if ($this->PostRegistrationTargetID) { $this->redirect($this->PostRegistrationTarget()->Link()); return; } die("no success page set"); }
/** * Updates an existing Member's profile. */ public function save(array $data, Form $form) { $member = Member::currentUser(); if ($member->MembershipStatus === 'Expired' || $member->MembershipStatus === 'Not applied') { $member->MembershipStatus = 'Applied'; $email = new MemberConfirmationEmail($this, $member); $email->send(); $this->sendAdminEmail($member); } $groupIds = $this->getSettableGroupIdsFrom($form, $member); $member->Groups()->setByIDList($groupIds); $form->saveInto($member); try { $member->write(); } catch (ValidationException $e) { $form->sessionMessage($e->getResult()->message(), 'bad'); return $this->redirectBack(); } $form->sessionMessage('Your details have been updated.', 'good'); return $this->redirectBack(); }
/** * Adds new member * * @param array member data. * @return boolean true/false */ public function addMember($data) { if (is_array($data)) { $member = new Member(); $member->Email = $data['ccustemail']; $member->FirstName = ucwords(strtolower($data['ccustfirstname'])); $member->Surname = ucwords(strtolower($data['ccustlastname'])); $member->ClickBankAccountType = 'Paid'; $password = Member::create_new_password(); $member->Password = "******"; /* link to memberprofilepage module */ $profilePage = DataObject::get_one('MemberProfilePage'); $member->ProfilePageID = $profilePage->ID; if ($profilePage->EmailType == 'Validation') { $email = new MemberConfirmationEmail($member->ProfilePage(), $member); $email->send(); $member->NeedsValidation = true; } elseif ($profilePage->EmailType == 'Confirmation') { $email = new MemberConfirmationEmail($member->ProfilePage(), $member); $email->send(); } /* populate new member profile */ $clickBankProfile = new ClickBankMemberProfile(); if ($clickBankProfile) { self::populateFields($clickBankProfile, $data); } $clickBankProfile->write(); $member->ClickBankProfileID = $clickBankProfile->ID; // save new member $member->write(); // assign & update new member to a ClickBank user group $clickBankGroupIds = $profilePage->getClickBankMemberGroups(); if ($clickBankGroupIds) { $member->Groups()->setByIDList($clickBankGroupIds); $member->write(); } // assign & update new member to a regular memberprofile user group $memberGroupIds = $profilePage->getMemberProfileGroups(); if ($memberGroupIds) { $member->Groups()->setByIDList($memberGroupIds); $member->write(); } /* Populate log */ $clickBankIpnLog = new ClickBankIpnLog(); $clickBankIpnLog->MemberID = $member->ID; foreach ($data as $key => $val) { if (isset($clickBankIpnLog->{$key})) { $clickBankIpnLog->{$key} = $val; } } $clickBankIpnLog->write(); return true; } return false; }