Keeping track of the action before a login?
I'm trying to do the following:
- User can vote for an item (controlle开发者_如何转开发r: item, action: vote)
2a. If the user is logged in, then vote action goes through.
2b. If user is not logged in, then user needs to log in/creates an account (handled by user controller), then vote action goes through.
How do I do 2b such that once the user logs in/creates account, the vote action automatically goes through without having the user vote for the item again?
Store the users vote in the session object. When the user logs in check the session object for an existing vote. Something like the following sudo code. vote action
if (isLoggedIn==false)
{
session['vote']=voteObject
}
And from the action executed when a user successfully logs in.
if(session['vote']!=null) {
//read the 'vote' object from your session and put the users vote in
}
store vote url and param into params, and pass to login action.
see also shiro plugins
Similar to earlier suggestions, you could store the params from one or more action prior to login, but store them as an array of arrays in the session variable. The array key value could be the action attempted with any applicable params stored within that array data. Then post login you could check that session variable and easily process each request.
精彩评论