Saving app state in jQuery mobile - javascript

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.

Related

How to save and fetch user search history on web apl

am working on a navigation web app. And I want to save user search history and display them on the search page. Can I do that without the user logged in.
Apart from cookies that #Alex mentioned, there is something called localStorage in javascript that enables you to store some data on the computer of your user. These would be the most convenient way to implement search history without involving any login or server-side stuff.

Where to store settings in chrome extension app

I am new to web development. I am writing google chrome extension that connects to some API. I have one page for user's settings with fields like API key, and more stuff that user want's to configure.
My question as a developer where and how should I save this settings, I thought creating a json file that it would be possible to export the file and import settings file.
Should the server save this settings? should I save it on user's machine? any suggestions?
I think it will be better if you allow user to save on their machine, it's safer and your users have to take all responsibility to keep it safe.
You can use Extension Options to provide a UI for your users to save their credentials. And in that option page, you should use chrome.storage API to store the credentials so that whenever user access to option page, their credentials still there. Later on, when you want to use user credentials to send API, just use chrome.storage API to query the credential.

How to call a function only on the user's first login on React Native?

I want to put an alert with an information that should only appear in the first login of each user in my app, how do I call this function only on the first access?
Well, this depends on your policy. If you want to set it for after first login ever(don't care if she will login for first time on another devices) you should use a server call to set such flag on db. However, if you want to make it local to the device, yo may use storage i.e. asyncstorage
good luck!
In response to my comment on using cookies or local storage.
Step 1: User visit's website.
Step 2: App checks if a cookie, database, or local storage (non-mobile) is present.
Step 3: If the special cookie name is not present we now set the cookie, and show the first time page. If it is present, we show the visited page.
Android
You can possibly used a shared setting in the shared preferences. This is the same basic concept as checking for a document or item, it the preference isn't there it is the firs time.
All
Generate a hash for a IP Address and store it in a database for a said user. Setup an API endpoint for when user installs app it checks against this.
Generally when I would set a last_login field for User table.
If that's null, it would be safe to assume that it's the first time the user logs in.

How to maintain login session across multiple tabs?

I am developing a website and i am having a problem in finding the best solution to maintain user login session.
Currently i am using Html5 web storage "session storage" to store whether user is logged in or not. But problem in this is that this only works in a single tab not across multiple tabs of a browser.
What should i use either Cookies or LocalStorage or i should maintain server side session and check every times a page loads on server whether the user is logged in or not ?
What is the best solution? please guide me.
I am using Node.js and mongodb in the backend and Angular and jquery in frontend.
First thing you must know is that sessions are made only for server-side not for client side. Second thing, if you want your user to not load everytime, try to save the data in user's cookies also don't think about it will require more time to load on server. Because sessions are only made for security purpose and i guess by storing them on client side you are not using that purpose. Also now major question is how to store them on the server side. Suppose your server goes down now all of your sessions will get deleted. Now to avoid that use some external data store like connect-mongo/connect-redis. redis is faster than mongo but if you want to use only memory store then search for memcached/cookie-sessions/jWT hope this answer helps :)

Chrome extension / web app session control

I am creating a chrome extension, rather a chrome webapp. This application just contains the html, js, image and css files. The application connects to a server to fetch data. I chose to do this as it would reduce the amount of files downloaded by the user. Using Backbone.js I have an MVC architecture in my application. Thus the application just sends json.
Now having said this, I need a session management. I plan to use Google authentication as the organization has Google Apps. I need a method that once the user has logged in using google auth the server get the user name every time the application makes a request.
Is it a good idea to add the user name in request header, if possible. Or should I use cookies? Can any one tell me how I could go about using cookies in this case?
This might be a late response but I want to present a more elegant solution to you given that the user has cookies enabled in their browser.
First read my answer on another question.
Now that you can send cross origin xhr from your content scripts all you need to do is store all your authentication and session management at server only. That is right, you just need to display whether the user is logged in or not and a logout button at client based on server response.
Just follow these steps.
At client Whenever user accesses your chrome web app, blindly make XmlHttpRequests to your server without worrying about authentication, just keep a tab on response from server which I describe below.
At server whenever you receive a request check for valid sessions or session cookie. If session is valid send proper response, if not send error, 401 or any other response to communicate to your client that session is not valid. It is better if you send an error code like 401 since then you can put a generic script at client to inform them that they are not logged in.
At Client If response from server is proper, display it, else display login link to your website.
IMPORTANT: Display logout button if user is logged in.
Check out my implementation of this in my extension
For help using Google authentication in your app take a look at Google's OAuth tutorial which comes with all you need (took me no time to set it up using this).
As for session management. The implementation of OAuth used by Google stores the tokens in localStorage. Also, as briefly mentioned in the extensions overview we are expected to use localStorage to store data. Thus, I suggest you store the users name here as it will be accessible throughout the app's lifetime (until it is uninstalled). However, you may need to manage the name stored here and consider what should happen when users log in and out. That said; I'm not sure if sessionStorage would be a better option as I've never used it before, let alone in an extension.
Note
localStorage and its counterparts only store strings so I suggest using a wrapper which uses JSON to parse and stringify to get and set your values respectively.

Categories

Resources