
var LoginHelper = {
  loggedIn : function() {
    var cookie = Ti.App.Properties.getString('auth_cookie');
    if (!cookie)
      return false;
    return true;
  },

  logout : function() {
    var createConfirmDialog = function() {
      var confirmDialog = Ti.UI.createAlertDialog({
        title : "Logout",
        cancel : 1,
        buttonNames : ['Confirm', 'Cancel'],
        message : "This will clear your surveys.\n Are you sure?"
      });
      return confirmDialog;
    }
    var confirmDialog = createConfirmDialog();
    confirmDialog.addEventListener('click', function(e) {
      if (e.index === e.source.cancel) {
        Ti.API.info('The logout was cancelled');
      } else {
        Ti.App.Properties.setString('auth_cookie', null);
        var DatabaseHelper = require("helpers/DatabaseHelper");
        DatabaseHelper.clearDownloadedData();
        Ti.App.fireEvent('settings.refreshSurveys');

      }
    });
    confirmDialog.show();
  }
}

module.exports = LoginHelper;

@@ -109,40 +109,391 @@
     
-if (!cookie)%0A      return false;
+var cookieCreatedAt = Ti.App.Properties.getString('auth_cookie_created_at');%0A    %0A    if (!cookie)%0A      return false;%0A      %0A    if(new Date() - new Date(cookieCreatedAt) %3E 3600000) %7B //Expire the cookie after 1 hour.%0A      alert(%22Your session has expired. You need to login again to fetch or sync any data.%22);%0A      LoginHelper.expireSession();%0A      return false;  %0A    %7D%0A        
 %0A   
@@ -524,32 +524,39 @@
 gout : function(
+clearDB
 ) %7B%0A    var crea
@@ -1061,55 +1061,34 @@
     
-Ti.App.Properties.setString('auth_cookie', null
+LoginHelper.expireSession(
 );%0A 
@@ -1295,16 +1295,178 @@
 w();%0A  %7D
+,%0A  %0A  expireSession : function() %7B%0A    Ti.App.Properties.setString('auth_cookie', null);%0A    Ti.App.Properties.setString('auth_cookie_created_at', null); %0A  %7D%0A  
 %0A%7D%0A%0Amodu

Expire the session (cookie) in one hour after login.