views:

269

answers:

2

I have a website built on App Engine(Java) and need user use Google Account to login.

The situation is that:

  1. User Adam has multiple accounts.
  2. User Adam login with account Adam1 and get his Adam1 data in browser page A.
  3. He clicked logout link, but opened it in another tab page B(the same browser of course)
  4. He login with another account Adam2 in browser page B get his Adam2 data shown.
  5. He then returned to browser page A and made some changes to his data and then send to server, at this time my app would recognize the current user is Adam2 , and the changes would be taken on Adam2, it does not match the status with its current page A, our user may be confused.

I thought maybe I can attach a userID parameter while making change request to the server and server side will compare the current user id with this userID parameter to make the change request processed or return a refresh command to make the out-of-date page be refreshed to the current account's if the ids are not same.

What is the best practice to handle this situation?

+1  A: 

Put a hidden field on your forms that is a combined hash of the session ID and the user ID. When your server processes the request, double check that the combined hash sent along with the request matches what you expect. If either the user or the session is wrong, the hash won't match, and you can report an error appropriately.

John Feminella
+1  A: 

Presumably the user would be identified by a Session ID that is send as Cookie information. Adam on site A will have a different Session ID than Adam on site B because of the differing login. Also presumably the form page will be protected such that a user needs to be logged in in order to access it.

When Adam logs out on page B, the old session is destroyed on the server and the login becomes invalid. When Adam submits the form from page A, the browser doesn't know this has happened and will submit the form together with the old Session ID. The server will (should) reject this submit since the session has already expired.

Hence, in a properly coded Session/User management system, this becomes a non-issue. The critical point is to renew/invalidate the Session ID upon logout.

deceze
You may misunderstand my question, there is no Site A and Site B, but just two pages opened by browser for the same site. The session id would not change until user closed browser and tried to get a new session.
virsir
@virsir I do understand your question and I am using the terms "page A" and "page B" the same way you did in your question. What I'm saying is that the session id should change when you log out, which would render this issue moot.
deceze