Skip to content

Instantly share code, notes, and snippets.

@bphamous
Forked from tdm00/Controller.cfc
Created June 2, 2014 21:34
Show Gist options
  • Select an option

  • Save bphamous/1b313ee3848cd52acfb2 to your computer and use it in GitHub Desktop.

Select an option

Save bphamous/1b313ee3848cd52acfb2 to your computer and use it in GitHub Desktop.
<cfcomponent extends="Wheels">
<cffunction name="init">
<cfset filters(through="checkLogin", except="login,authenticate,logout,resetPassword,forgotPassword")>
</cffunction>
<cffunction name="checkLogin">
<cfif StructKeyExists(session, "user")>
<cfset loggedInUser = model("user").findByKey(session.user.id) />
<cfif isDefined("session.gotoredirectparams")>
<!--- make params what the previous ones before timeout --->
<cfset params = structcopy(session.gotoredirectparams) />
<!--- delete the struct from the session --->
<cfset structDelete(session, "gotoredirectparams") />
</cfif>
<cfelse>
<cfif IsStruct(params)>
<cfset session.redirectparams = params />
<cfset flashInsert(error="Your session timed out. Please login again.")>
</cfif>
<cfset redirectTo(controller="security", action="login")/>
</cfif>
</cffunction>
</cfcomponent>
<cfcomponent extends="Controller" output="false">
<cffunction name="authenticate">
... other code ...
<cfif isDefined("session.redirectparams")>
<!--- make a copy of the struct so the next line doesn't interfere --->
<cfset var args = structcopy(session.redirectparams) />
<cfset session.gotoredirectparams= structcopy(session.redirectparams) />
<!--- delete the struct from the session --->
<cfset structDelete(session, "redirectparams") />
<!--- redirect to the previously expected location --->
<cfset redirectTo(argumentCollection=args) />
<cfelse>
...
</cfif>
</cffunction>
</cfcomponent>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment