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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With