开发者

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>
    <resul开发者_JAVA技巧ts>
        <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?


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.


here's the general idea:

  1. in whatever method/code runs to 'secure' your page, if a user is not logged in, grab the url they were trying to reach and set it back to the viewstate as a variable before you forward them. the CGI scope will be your friend here, particularly CGI.query_string.

  2. on your sign/log in form, check for this 'returnEvent' variable in the viewstate and set it as a hidden value on your form if it exists.

  3. someplace in your sign up/in process after success, check for this 'returnEvent' variable and if it exists, forward the user on.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜