Last active
August 29, 2015 14:21
-
-
Save pauldenato/394ae7e48862698b8e65 to your computer and use it in GitHub Desktop.
User subType Creation Fuzzy Match - Using an Extended Attribute to match and prevent user creation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!---styles for edit links (these are not necessary) | |
I've placed min in the onAdminHTMLFootRender() | |
function in the theme eventhandler.cfc---> | |
<!---<style> | |
.alert-error span.potentialMatches { | |
display:inline-block; | |
color:#333; | |
} | |
.alert-error span.potentialMatches a { | |
color:#b90e0e; | |
text-decoration:underline; | |
padding-left:5px | |
} | |
</style> | |
---> | |
<!---Placed in site eventhandler.cfc ---> | |
<cffunction name="onBeforeUserStudentCreate" output="false" access="public"> | |
<!---load possible member ---> | |
<cfset user=$.event('userBean') /> | |
<cfset var fuzzyCheck=""/> | |
<!---Create list to add matches to---> | |
<cfset var fuzzyListing = ""/> | |
<!---query tusers and extended attributes to look for possible matches ---> | |
<cfquery name="fuzzyCheck" datasource="#application.configBean.getDatasource()#"> | |
select tu.Fname, tu.Lname, tu.UserName,tu.email, tu.UserID, CONVERT(nvarchar(max),CAST(replace(replace(tca.attributeValue,'{ts ''',''),'''}','') as datetime),101) as dob | |
from tusers tu LEFT OUTER JOIN | |
tclassextenddatauseractivity tca ON tu.UserID = tca.baseID AND | |
<!--- This attribute id is for my DOB EA ---> | |
tca.attributeID = 13 | |
where (tu.Type = 2) AND | |
(tu.SiteID = <cfqueryparam cfsqltype="cf_sql_varchar" value="#session.siteID#">) AND | |
<!--- This attribute id is for my DOB EA ---> | |
(tu.Fname = <cfqueryparam cfsqltype="cf_sql_varchar" value="#trim(user.getValue('fname'))#">) AND | |
(tu.Lname = <cfqueryparam cfsqltype="cf_sql_varchar" value="#trim(user.getValue('lname'))#">) AND | |
(CONVERT(nvarchar(max),CAST(replace(replace(tca.attributeValue,'{ts ''',''),'''}','') as datetime),101) in (<cfqueryparam cfsqltype="cf_sql_varchar" value="#trim(user.getValue('userDob'))#">)) | |
</cfquery> | |
<cfif not fuzzyCheck.recordcount> | |
<cfreturn true /> | |
<cfelse> | |
<cfloop query="fuzzyCheck"> | |
<!---add the matches to a list to return in the key, also provide a link to edit and some additional information---> | |
<cfset fuzzyListing = listAppend(fuzzyListing, "<span class='potentialMatches'><a href='?muraAction=cusers.edituser&userid=#fuzzyCheck.userid#&siteid=#session.siteID#'>"&fuzzyCheck.fname & ' ' & fuzzyCheck.lname & '</a> - ' & fuzzyCheck.email & ' :: ' &fuzzyCheck.dob &"</span>", ';') /> | |
</cfloop> | |
<!---Returnt the custom error ---> | |
<cfset user.getErrors().customErrorKey = "Potential Matches: " & fuzzyListing /> | |
<cfreturn false /> | |
</cfif> | |
</cffunction> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment