diff options
-rw-r--r-- | js/lib/ajax.js | 2 | ||||
-rw-r--r-- | js/lib/configuration.js | 7 | ||||
-rw-r--r-- | js/lib/security.js | 22 | ||||
-rw-r--r-- | languages/en.php | 7 | ||||
-rw-r--r-- | views/default/js/elgg.php | 1 |
5 files changed, 35 insertions, 4 deletions
diff --git a/js/lib/ajax.js b/js/lib/ajax.js index 36f76b2c3..5e290df6f 100644 --- a/js/lib/ajax.js +++ b/js/lib/ajax.js @@ -193,7 +193,7 @@ elgg.action = function(action, options) { //Always display system messages after actions var custom_success = options.success || elgg.nullFunction; options.success = function(json, two, three, four) { - if (json.system_messages) { + if (json && json.system_messages) { elgg.register_error(json.system_messages.errors); elgg.system_message(json.system_messages.success); } diff --git a/js/lib/configuration.js b/js/lib/configuration.js index d0c852bd0..f724a2f01 100644 --- a/js/lib/configuration.js +++ b/js/lib/configuration.js @@ -1,7 +1,10 @@ elgg.provide('elgg.config'); -elgg.config.wwwroot = '/'; - +/** + * Returns the current site URL + * + * @return {String} The site URL. + */ elgg.get_site_url = function() { return elgg.config.wwwroot; }
\ No newline at end of file diff --git a/js/lib/security.js b/js/lib/security.js index f88c6165d..fa0a6f7ef 100644 --- a/js/lib/security.js +++ b/js/lib/security.js @@ -5,13 +5,15 @@ elgg.provide('elgg.security'); elgg.security.token = {}; +elgg.security.tokenRefreshFailed = false; + /** * Sets the currently active security token and updates all forms and links on the current page. * * @param {Object} json The json representation of a token containing __elgg_ts and __elgg_token * @return {Void} */ -elgg.security.setToken = function(json) { +elgg.security.setToken = function(json) { //update the convenience object elgg.security.token = json; @@ -34,6 +36,24 @@ elgg.security.setToken = function(json) { */ elgg.security.refreshToken = function() { elgg.action('security/refreshtoken', function(data) { + + // @todo might want to move this to setToken() once http://trac.elgg.org/ticket/3127 + // is implemented. It's here right now to avoid soggy code. + if (!data || !(data.output.__elgg_ts && data.output.__elgg_token)) { + elgg.register_error(elgg.echo('js:security:token_refresh_failed', [elgg.get_site_url()])); + elgg.security.tokenRefreshFailed = true; + + // don't setToken because we refresh every 5 minutes and tokens are good for 1 + // hour by default + return; + } + + // if had problems last time, let them know it's working now + if (elgg.security.tokenRefreshFailed) { + elgg.system_message(elgg.echo('js:security:token_refreshed', [elgg.get_site_url()])); + elgg.security.tokenRefreshFailed = false; + } + elgg.security.setToken(data.output); }); }; diff --git a/languages/en.php b/languages/en.php index 32a4cbb3d..375ba6135 100644 --- a/languages/en.php +++ b/languages/en.php @@ -1099,6 +1099,13 @@ You cannot reply to this email.", 'tags:site_cloud' => 'Site Tag Cloud', /** + * Javascript + */ + + 'js:security:token_refresh_failed' => 'Cannot contact %s. You may experience problems saving content.', + 'js:security:token_refreshed' => 'Connection to %s restored!', + +/** * Languages according to ISO 639-1 */ "aa" => "Afar", diff --git a/views/default/js/elgg.php b/views/default/js/elgg.php index 018db7967..a434afc7d 100644 --- a/views/default/js/elgg.php +++ b/views/default/js/elgg.php @@ -34,6 +34,7 @@ $libs = array( 'ajax', 'session', 'pageowner', + 'configuration', //ui 'ui', |