Sending Out FEU Invites

A UDT that sends an email to newly registered FEU users asking them to activate their account for "Invitation Only" websites.

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)

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);
//, $prettyurl);

# 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 username. 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:

<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>

Then 'Turn on' WYSIWYG and format as desired. That should be it! When the admin creates the account, they can enter in any password, such as '123456', doesn't matter. When the account is created, the UDT tricks FEU into thinking that the user lost their password and has requested a password reset. The email body template that we created sends the user to the password reset page (home page, but with content replaced with reset stuff). The user enters their new password and their new account is activated!

Comments