PDA

View Full Version : Live state restore



KJedi
19 Jun 2010, 2:58 AM
I need the following functionality. User logs in to the app, starts going something, opens windows, works with grids etc.
Then another user comes TO THE SAME PC and asks him to give a PC for a a few mins. This new user clicks "switch user" button, logs in with his info, interface is rebuilt for him - new menu options etc (he may be an admin or a viewer). He opens a few grids, modifies them and finishes.
The first one clicks "switch user", puts his password, restores his session and should see all the interface in the state when he left it. I need to save:
- windows opened and their positions, sizes
- pages of the grids (when we use paging)
Ideally, I'd also like to save:
- scroll position
- data entered in the form, but not yet submitted
If this is too hard or not possible - then it's not a problem.
Also, the same session restore should occur when user finished his session and logs in from other PC.

Previously, I solved this partly in another app like this:
- used HttpStateProvider from Saki
- kept all session data in DB, in user's profile
- when user logged in, I sent all state data and all panels were restored
- when user changes something, state is saved to the server

The only question here is how to perform LIVE state restore - without refreshing the page:
- I should close the windows of the previous user
- I should open windows for the new user
Then switch it back.

I know about the permissions issue - educated user can use firebug to find all info from the previous user. I think, that simply clearing all stores and loading them back on refresh should solve the problem.

Thanks beforehand!

KJedi
19 Jun 2010, 3:20 AM
I think I should do the following:

for all my windows I:

set stateful:true
define getState method that returns all data from all child items that is needed for state restoring
override applyState method in order to restore state from the data I pass to the state manager in getState

create WindowManager object, extended from Ext.Component (in order to be stateful), which will store the information which windows are opened. In applyState method, it will jsut create these windows, which will attempt to restore their state and will get info from the StateManager
on successful "switch user", I:

save all info to the StateManager, which updates data in user session
destroy all windows, stores, data entered (because I have all data to restore in the session state)
load data for the new user with StateManager (how to do it, is there any built-in even/method for this?)
trigger state restore in WindowManager (how to do it, is there any built-in even/method for this?)

This way, restoring session will take quite long because it will have to re-fetch all datafrom the server, but it should be secure enough since all data from the previous user is destroyed.


Regarding restoring the scroll position and values entered in forms:

I can make all forms and fields stateful and they will restore their state when they are constructed. This way I don't need to redefine applyState in Window or any other component, they will be restored automatically (if they save the info I need).
I can manually go through the child items of each window in order to collect all the data for restoring. This way, I'll have to override applyState and apply states for all child items. This also violates low coupling design pattern and may cause problems in refactoring later.

So I think I will go with the first variant - let every component/window/field save and restore it's state itself.

Any ideas/suggestions/critics on this?

darthwes
19 Jun 2010, 8:14 AM
1.) Why don't we just reload the page?

2.) I think you can set user id in the state of the components being saved. Its not secure at all, but that's not your concern, so just pass it around?

KJedi
20 Jun 2010, 2:37 AM
1) I want to avoid this - lots of script loading and basic rendering. It will save some time. Also, client does not want it to reload page...
2) Why do I need this? I've already solved a problem with switching and restoring sessions from the same PC. After user submits his password from "switch user" dialog, his session on the server is restored together with his state.