Created
July 2, 2012 19:55
-
-
Save tdm00/3035318 to your computer and use it in GitHub Desktop.
Restore params after session timeout and re-authentication
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
| <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> |
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
| <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