Site Tree

Email Users When They are Added to a Site

When users are added to a ShadoCMS site, by default they are not notified that they have been added. However, if you need to notify users by email that they have been added to a ShadoCMS site, you can easily create an event handler that does this. Here is how...

In Object Designer > Manual Configurator (in earlier versions of ShadoCMS and older sites, this might be referred to as IDE), expand the shadomx package, locate the users class, navigate to the "Events" tab, and select "afterCreate". Select the "Add" tab, and paste in the following code in the text box.

<cfmail from="Your Name <you@yourdomain.com>"
to="#arguments.user_firstname# #arguments.user_lastname# <#trim(arguments.user_emailaddress)#>"
subject="Invitation to join a ShadoCMS site">
You have been invited to help with Your Site Name (http://yoursite.com).

To login, visit:
http://yoursite.com/shadomx/

Username: #arguments.user_loginid#
Password: #arguments.user_loginid#_#year(now())#
Site: #request.siteContext.dsn#

Please change your password to protect the security of your account and never share your password or give out your account information.

If you have any questions or comments, please do not hesitate to contact you@yourdomain.com.
</cfmail>

Before you save the code, change the add your own email address, name and site URL.

Add a new user and now they will get this email.

You can customize this code in any way you deem necessary. The code is saved in /yoursite/app_templates/objects/native/users/aftercreate.cfm. Keep in mind that any changes you make require you to clear the variables cache.

One thing to note about this code is that the password for the user is set to the user's logind followed by an underscore and current year. This is done because ShadoCMS generates passwords as hashed strings. Therefore when the user is created, make sure you create the password that matches what is sent in this email.

This shows the how easily you can tap into the ShadoCMS events. Basically we have written an event handler for the afterCreate user event that is dispatched each time a user is added to the system. You can similarly add your own handlers for the different events that are dispatched continuously by ShadoCMS. For example, sticking to the users object, you can write your own onLogin and onLogout handlers.


Comments

There are no comments for this page as yet.

Add a comment