Skip to content

Instantly share code, notes, and snippets.

@petrichor8
Forked from jsieber/dsp_login.cfm
Last active January 10, 2020 19:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petrichor8/1cbc7669440fc662cee7f40e96ed6cd5 to your computer and use it in GitHub Desktop.
Save petrichor8/1cbc7669440fc662cee7f40e96ed6cd5 to your computer and use it in GitHub Desktop.
custom returnLoginCheck
<cfif variables.$.event('expired') eq true>
<div class="alert alert-danger">#variables.$.rbKey('user.forgotexpired')#</div>
</cfif>
user.forgotexpired=The temporary login link that you requested has expired. Please request a new link.
//these go inside of a _tagFunction.cfm file
<cffunction name="returnLoginCheckCustom" output="false">
<cfargument name="$">
<cfset var rs="">
<cfif not arguments.$.currentUser().isLoggedIn() and len(arguments.$.event('returnID')) and len(arguments.$.event('returnUserID'))>
<cfquery name="rs" datasource="#variables.configBean.getReadOnlyDatasource()#" username="#variables.configBean.getReadOnlyDbUsername()#" password="#variables.configBean.getReadOnlyDbPassword()#">
select created from tredirects
where redirectID=<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.$.event('returnID')#" >
</cfquery>
<cfif rs.recordcount and rs.created gte dateAdd("d",-2,now())>
<cfset loginByUserID($.event('returnUserID'),arguments.$.event('siteID'))>
<cfset structDelete(session,"siteArray")>
<cfelse>
<cflocation url="?display=login&expired=true##reminder" addtoken="false">
</cfif>
</cfif>
</cffunction>
OR
<cffunction name="returnLoginCheckCustom" output="false">
<cfargument name="$">
<cfargument name="minutesGoodFor" required="false" default="30" >
<cfset var rs="">
<cfif not arguments.$.currentUser().isLoggedIn() and len(arguments.$.event('returnID')) and len(arguments.$.event('returnUserID'))>
<cfset var redirect=getBean('userRedirect').loadBy(redirectid=arguments.$.event('returnID'))>
<cfif redirect.exists()
and redirect.getCreated() gte dateAdd("n",-arguments.minutesGoodFor,now())
and $.event('returnUserID') eq redirect.getUserID()>
<cfset var user=redirect.getUser()>
<cfif user.exists()>
<cfset user.login()>
</cfif>
<cfset structDelete(session,"siteArray")>
<cfelse>
<cflocation url="/forgot-login/?display=login&expired=true&showmore=forgotlogin" addtoken="false" />
</cfif>
</cfif>
</cffunction>
//override login check method to enableto only be used for 30 minutes
$.getBean("userUtility").injectMethod( "returnLoginCheck", returnLoginCheckcustom );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment