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())>
<cfset variables.instance.errors=structnew() />
<cfif not structIsEmpty(extErrors)>
<cfset structAppend(variables.instance.errors,extErrors)>
<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 variables.instance.type eq 2 and eq "">
<cfif variables.instance.type eq 2 and not checkEmail()>
<!--- If captcha data has been submitted validate it --->
<cfif not (not len(variables.instance.hKey) or variables.instance.hKey eq hash(variables.instance.uKey))>
<!--- If cfformprotect has been submitted validate it --->
<cfif not variables.instance.passedProtect>
<cfset variables.instance.errors.siteid="The 'SiteID' variable is missing." />
<cfreturn this>

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>