Last active
April 27, 2018 19:13
-
-
Save stevewithington/b9d12df946dc8756b6bf to your computer and use it in GitHub Desktop.
Mura CMS : How to set an 'Admin' alert in Mura based on the age of someone's password.
This file contains hidden or 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
<!--- 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