Saving app state in jQuery mobile
I have done a bit of research on how to do this but can't find any.I have an app that has a Home
page.On this homepage, there is a Register
button.I want to implement a system where if the user clicks on this and registers, the app never starts with the Register
button displayed again,but rather, a view Profile
button.How do i implement such a system? My guess is to store some boolean value in localstorage, and check this value when the app starts?
Update: I just thought i'd add that my jquery mobile app communicates with a Google App Engine (Python) web service which already uses Google's User's Service
I believe you are looking for Local Storage Jquery Mobile .
You have to store data when user click on Register
button, and every time when app will open it checks is there is any data in Local Storage
. Then you can use your logic.
You can also use HTML5 Local Storage with Jquery Mobile . But some device browser dose not support Local storage if you want to check this you should go for Modernizer.
This is simple code of checking local storage using modernizer:
if (Modernizr.localstorage) {
// Supported
}
else {
// Not Supported
}
If you only store a boolean after the user is logged-in, yes you know that a user is logged in but you don't know which one.
Te best approach is to store the user's token which you will send as a parameter in all requests so that you can validate them.
When entering the website if there is a token you must validate it by querying the server. If it's not valid then you show the register/login page. If the token is valid you could login the user automatically.
Whatever plugin you decide to use be sure to check that if it is a localStorage plugin it also has fallback for cookies. (Maybe some clients will have browsers that don't support localStorage)
On this page there are 3 functions that I personally use when I need access to cookies.
Here you have some details about token authentication.
I would advise you to store the token using cookies.
This answer describes one of the best ways of managing user sessions based on tokens.
链接地址: http://www.djcxy.com/p/22008.html上一篇: 令牌而不是正常的认证过程?