diff options
author | Dave Arter <davea@mysociety.org> | 2017-06-13 16:42:52 +0100 |
---|---|---|
committer | Dave Arter <davea@mysociety.org> | 2018-04-08 14:44:31 +0100 |
commit | 64cc9c6c2c1b5ada438fd6e874e812739c259b1a (patch) | |
tree | aa4b271c3bdd6a59985949f8882db936f3e4309c /www/js/app.js | |
parent | c3214d95c633d63a93c67bba4879396bee465a99 (diff) |
Enforce LOGIN_REQUIRED setting
If LOGIN_REQUIRED is true, the app won't let you do anything until
you've logged in.
Diffstat (limited to 'www/js/app.js')
-rw-r--r-- | www/js/app.js | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/www/js/app.js b/www/js/app.js index 61ee590..71a4f97 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -118,21 +118,28 @@ var tpl = { }, checkLoggedInStatus: function() { + var p = $.Deferred(); + if ( FMS.isOffline ) { + p.resolve(); } else { $.ajax( { url: CONFIG.FMS_URL + '/auth/ajax/check_auth', type: 'GET', dataType: 'json', timeout: 30000, - success: function( data, status ) { - FMS.isLoggedIn = 1; - }, - error: function() { - FMS.isLoggedIn = 0; - } - } ); + }) + .done(function() { + FMS.isLoggedIn = 1; + p.resolve(); + }) + .fail(function() { + FMS.isLoggedIn = 0; + p.resolve(); + }) } + + return p; }, saveCurrentDraft: function(force) { @@ -339,20 +346,21 @@ var tpl = { FMS.allDrafts.fetch(); FMS.checkOnlineStatus(); FMS.loadCurrentDraft(); - FMS.checkLoggedInStatus(); - if (!CONFIG.HELP_DISABLED) { - FMS.setupHelp(); - } + FMS.checkLoggedInStatus().done(function() { + if (!CONFIG.HELP_DISABLED) { + FMS.setupHelp(); + } - Backbone.history.start(); - if ( navigator && navigator.splashscreen ) { - navigator.splashscreen.hide(); - } else { - $('#load-screen').hide(); - } - if (!CONFIG.HELP_DISABLED) { - $('#display-help').show(); - } + Backbone.history.start(); + if ( navigator && navigator.splashscreen ) { + navigator.splashscreen.hide(); + } else { + $('#load-screen').hide(); + } + if (!CONFIG.HELP_DISABLED) { + $('#display-help').show(); + } + }); }); } }); |