Blog

Some of my recent posts and ramblings.

Prevent multiple registrations by same email in mura

This was a request from one of the site visitors (my first request :)).

It was easy enough, the code is in the validate() method in userBean.cfc. You just need to add the highlighted lines in. Instead of modifying the core file, you can use method injection to inject the method, the process is similar to this post. This way it won’t break when you update mura.


<cffunction name="validate" access="public" output="false" >
<cfset var extErrors=structNew() />
<cfif len(getSiteID())>
<cfset extErrors=variables.configBean.getClassExtensionManager().validateExtendedData(getAllValues())>
</cfif>
<cfset variables.instance.errors=structnew() />
<cfif not structIsEmpty(extErrors)>
<cfset structAppend(variables.instance.errors,extErrors)>
</cfif>
<cfif trim(variables.instance.siteid) neq "">
<cfif variables.instance.type eq 2 and (variables.instance.username eq "" or not checkUsername())>
<cfsetvariables.instance.errors.username=variables.settingsManager.getSite(getSiteID()).getRBFactory().getResourceBundle().messageFormat(variables.settingsManager.getSite(getSiteID()).getRBFactory().getKey("user.usernamevalidate") , getusername() ) />
</cfif>
<cfif variables.instance.type eq 2 and variables.instance.email eq "">
<cfsetvariables.instance.errors.email=variables.settingsManager.getSite(getSiteID()).getRBFactory().getKey("user.emailrequired")/>
</cfif>
<cfif variables.instance.type eq 2 and not checkEmail()>
<cfsetvariables.instance.errors.email=variables.settingsManager.getSite(getSiteID()).getRBFactory().getKey("user.emailalreadyinuse")/>
</cfif>
<!--- If captcha data has been submitted validate it --->
<cfif not (not len(variables.instance.hKey) or variables.instance.hKey eq hash(variables.instance.uKey))>
<cfsetvariables.instance.errors.SecurityCode=variables.settingsManager.getSite(getSiteID()).getRBFactory().getKey("captcha.error")/>
</cfif>
<!--- If cfformprotect has been submitted validate it --->
<cfif not variables.instance.passedProtect>
<cfsetvariables.instance.errors.Spam=variables.settingsManager.getSite(getSiteID()).getRBFactory().getKey("captcha.spam")/>
</cfif>
<cfelse>
<cfset variables.instance.errors.siteid="The 'SiteID' variable is missing." />
</cfif>
<cfreturn this>
</cffunction>

Add the ‘user.emailalreadyinuse’ key in the properties files in resourcebundles folder in your theme. You can add a message like ‘This email is already in use’ or of you want it to be more verbose, ‘This email already has an account, please go to the login page to login or if you have forgotten your password, reset it using the Forgot Password form on the login page.’

I did not have enough time to test it thoroughly, but it worked on the registration page and it did not seem to break anything else. Please test it out some more before deploying to production.


Leave a Reply

Your email is never published nor shared. Required fields are marked *

You may use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>