Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using ColdFusion Model-Glue, how do I redirect the user back to their requested page after logging in?

I have a secured event type, which will check to see if the user is logged in, and the redirect them to the login page if they're not:

<event-types>
    <event-type name="securedPage">
        <before>
            <broadcasts>
                <message name="CheckLogin"/>
            </broadcasts>
        </before>
        <results>
            <result name="NeedLogin" do="page.login" redirect="true"/>
        </results>
    </event-type>
</event-types>

The login page has a form that links to an action.login event handler, which will redirect to the user's homepage if login was successful, and redisplay the login page if it wasn't:

<event-handler name="action.login">
    <broadcasts>
        <message name="Login"/>
    </broadcasts>
    <results>
        <result name="LoggedIn" do="page.user.home" redirect="true"/>
        <result name="NotLoggedIn" do="page.login"/>
    </results>
</event-handler>

This code works great, but the problem I'm running into now is that it will always redirect to the user's homepage, even if they requested another page. Since the form posts to the action.login event, and the result do is hard-coded to page.user.home, how can I modify my code to keep track of which page the user originally requested and redirect them back there?

like image 432
Daniel T. Avatar asked Sep 14 '11 01:09

Daniel T.


1 Answers

In the logic you use to determine if a user needs to be logged in, you can grab the current event and store it in a shared scope (like the session scope).

Then, after a successful login simply call event.forward() and pass in that value.

like image 157
Scott Stroz Avatar answered Sep 23 '22 15:09

Scott Stroz