Skip to content

Instantly share code, notes, and snippets.

@jzuijlek
Forked from stevewithington/muraPasswordExpired.cfm
Last active August 29, 2015 14:16
Show Gist options
  • Save jzuijlek/14e5a7c9f6e7c83e1a0e to your computer and use it in GitHub Desktop.
Save jzuijlek/14e5a7c9f6e7c83e1a0e to your computer and use it in GitHub Desktop.
<!--- Drop these in the Theme or a Plugin eventHandler.cfc (global events won't work in the Site Handler) --->
<cfset variables.passwordexpired = false />
<!--- Custom method to determine if password is expired --->
<cffunction name="isPasswordExpired" output="false">
<cfargument name="userBean" required="true" />
<cfset var daysUntilExpired = 90 />
<cfset var expires = DateAdd('d', daysUntilExpired, arguments.userBean.getValue('passwordcreated')) />
<cfreturn DateCompare(expires, Now()) eq 1 ? false : true />
</cffunction>
<cffunction name="onGlobalRequestStart" output="false">
<!--- This allows you to do some messaging on the front end based, if needed --->
<cfset request.passwordexpired = variables.passwordexpired />
<cfif variables.passwordexpired>
<cfset arguments.$.setAdminAlert(key='passwordexpired', text='Password is EXPIRED!', type='error') />
</cfif>
</cffunction>
<!--- Global: login/out via back-end --->
<cffunction name="onGlobalLoginSuccess" output="false">
<cfargument name="$" />
<cfset var user = arguments.$.getBean('user').loadBy(username=arguments.$.currentUser('username'), siteid=arguments.$.siteConfig('siteid')) />
<cfset variables.passwordexpired = arguments.$.currentUser().isLoggedIn() and isPasswordExpired(user) />
</cffunction>
<cffunction name="onAfterGlobalLogout" output="false">
<cfargument name="$" />
<cfset variables.passwordexpired = false />
</cffunction>
<!--- Site: login/out via front-end --->
<cffunction name="onSiteLoginSuccess" output="false">
<cfset onGlobalLoginSuccess(argumentCollection=arguments) />
</cffunction>
<cffunction name="onAfterSiteLogout" output="false">
<cfset onAfterGlobalLogout(argumentCollection=arguments) />
</cffunction>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment