Please let me know if there is a module or a better method for this.. I've searched for hours, and asked a couple of CMSMS gurus, but hadn't found a solution.
I'm currently working on a website for my daughter's preschool as a straight trade for her education. This website has a 'Parents Only' section which has blog entries, a calendar, and photo galleries that the school doesn't want to be available to the public.
Naturally I turned to the FrontEndUsers module to handle the user login. This was my first time using FEU, and was a bit daunted by the huge control panel for it. Luckily configuring and using it was easy enough.
Obviously we don't want the users to register themselves, but the site owner didn't want to have to manually send out mails to parents each time she created an account. I decided to develop a way to send out 'invitations' to new users once their account was created asking them to click HERE to activate their account. Luckily FEU has an extensive API and I was able to create a UDT to handle this.
The UDT: FEUInvite
Code: Select all
global $gCms;
# Get default page ID.. This is where the 'reset password' will take place
$cntnt = $gCms->GetContentOperations();
$page_id = $cntnt->GetDefaultPageID();
# Tell FEU that this account needs their password reset
$FEU = $gCms->GetModuleInstance('FrontEndUsers');
$code = $FEU->GenerateRandomPrintableString();
$FEU->SetUserTempCode( $params['id'], $code );
# Create activation link
$parms = array( 'input_uid' => $params['id'], 'input_code' => $code );
$activate_link = $FEU->CreateLink('m1_','verifycode',$page_id,'',$parms, '', true, false, '', false);
# Loop through user properties and add them to $user_props
foreach ($FEU->GetUserProperties($params['id']) as $prop) {
$user_props[$prop['title']] = $prop['data'];
}
# Create Smarty variables for user properties, the activation link and user name. These will be used in the invitation templates (GCBs);
$smarty->assign('user_props', $user_props);
$smarty->assign('activate_link', $activate_link);
$smarty->assign('user_name', $params['name']);
# Get email from FEU, subject and body of mail from GCBs
$email = $FEU->GetEmail($params['id']);
$subject = $smarty->fetch('globalcontent:FEUInviteSubject');
$body = $smarty->fetch('globalcontent:FEUInviteBody');
# Send the mail
$cmsmailer = $gCms->GetModuleInstance('CMSMailer');
$cmsmailer->AddAddress($email);
$cmsmailer->SetSubject($subject);
$cmsmailer->SetBody($body);
$cmsmailer->IsHTML(true);
$cmsmailer->Send();
Creating the Event Handler
Now we need to add our UDT as an event handler for when new accounts are created. Go to Extensions -> Event Manager. Locate 'Frontend User Management - OnCreateUser' and add your new UDT to the list.
Creating the Email Template
Now we need to create the templates for the email subject and body.
Email subject: Create a Global Content Block called 'FEUInviteSubject'. Make sure that WYSIWYG is off. Click off 'Use WYSIWYG' not 'Turn WYSIWYG on/off'. This option is only in CMSMS version 1.9+. There is a fine distinction between these two options. The 'Click off' option doesn't use Tiny at all. The 'Turn off' option just disables the WYSIWYG, but all the Tiny filtering rules apply. We don't want Tiny messing with the subject line at all. In the GCB, add the subject line you want. Something like 'You are invited to login to mysite.com'
Email body: Now for the body template. Create another GCB called 'FEUInviteBody'. This time 'Turn Off' the WYSIWYG and enter in something like:
Code: Select all
{* {$user_props.property} is available to access all of your FEU properties. Example: $user_prop.age *}
<p>{$user_name},</p>
<p>An account was created for you. You can use this account to access the VIP area of the website</p>
<p>Username: {$user_name}</p>
<p>Please click <a href="{$activate_link}">HERE</a> to activate your account.</p>