Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You might find it easier to just add a check function on the server to check for a valid session. Even if the cookie is there, it doesn't mean they haven't logged out and the session cookie is sent back and forth with every request.</p> <p>That said, if you want to access the cookies from the client, they are attached to the document as a single string value. You can access them at document.cookies. I would look at the documentation and source of the ExtJS cookies utility for some inspiration about how to go about finding your cookie in that string.</p> <p><a href="http://docs.sencha.com/extjs/4.1.3/#!/api/Ext.util.Cookies" rel="nofollow">Ext.util.Cookies Documentation</a></p> <p><a href="http://docs.sencha.com/extjs/4.1.3/source/Cookies.html#Ext-util-Cookies" rel="nofollow">Ext.util.Cookies Source</a></p> <p>Essentially the process is to go through each letter in the cookie string, take a substring out to the length of the session key's name, see if it matches, then pull the data between the next equals sign and semicolon. Then you un-percent-encode the value and you're good to go.</p> <p><strong>Edit</strong> To ping the server, you just make an Ajax request somewhere along the application loading process before the first view is shown. The launch function is a pretty natural place I think:</p> <pre><code>Ext.application({ name: 'App', requires: [], models: [], stores: [], views: [], controllers: [], .... launch: function () { //Check with the server Ext.Ajax.request({ //Proxy Settings url: 'path/to/check/script.php', //Callbacks success: function (response, opts) { // process server response here response = Ext.JSON.decode(response.responseText); if(response &amp;&amp; response.success === true) { //Load the normal first view Ext.Viewport.add(Ext.create('App.view.Main'); } else { //Load the login view Ext.Viewport.add(Ext.create('App.view.LoginForm'); } }, failure: function (response, opts) { //Notify of network failure } }); } }); </code></pre> <p>As far as what to do in the script on the server side, it is dependent on what language you are developing in and what you are authenticating against. If it's just a database of usernames and passwords then when the user first logs in, start a session, and store a session variable for their userID and password. In the check function, make sure they are still valid by first checking if a current session exists, and then re-authenticating against your database (in case you or someone else canceled their account while the session was still valid). Then just send back a json response that says whether or not they are logged in, and includes any relevant user information needed to make your app work.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload