4 elgg.provide(
'elgg.security.token');
6 elgg.security.tokenRefreshFailed =
false;
8 elgg.security.tokenRefreshTimer = null;
16 elgg.security.setToken =
function(json) {
18 elgg.security.token = json;
21 $(
'[name=__elgg_ts]').val(json.__elgg_ts);
22 $(
'[name=__elgg_token]').val(json.__elgg_token);
25 $(
'[href*="__elgg_ts"][href*="__elgg_token"]').each(
function() {
27 .replace(/__elgg_ts=\d*/,
'__elgg_ts=' + json.__elgg_ts)
28 .replace(/__elgg_token=[0-9
a-f]*/,
'__elgg_token=' + json.__elgg_token);
37 elgg.security.refreshToken =
function() {
38 elgg.getJSON(
'refresh_token',
function(data) {
39 if (data && data.__elgg_ts && data.__elgg_token) {
40 elgg.security.setToken(data);
41 if (elgg.is_logged_in() && data.logged_in === false) {
42 elgg.session.user = null;
43 elgg.register_error(elgg.echo(
'session_expired'));
57 elgg.security.addToken =
function(data) {
60 if (
elgg.isString(data)) {
62 var parts =
elgg.parse_url(data),
66 if (parts[
'host'] === undefined) {
67 if (data.indexOf(
'?') === 0) {
70 args =
elgg.parse_str(parts[
'query']);
75 if (parts[
'query'] !== undefined) {
77 args =
elgg.parse_str(parts[
'query']);
79 var split = data.split(
'?');
80 base = split[0] +
'?';
82 args[
"__elgg_ts"] =
elgg.security.token.__elgg_ts;
83 args[
"__elgg_token"] =
elgg.security.token.__elgg_token;
85 return base + jQuery.param(args);
89 if (
elgg.isUndefined(data)) {
90 return elgg.security.token;
94 if (
elgg.isPlainObject(data)) {
95 return elgg.extend(data,
elgg.security.token);
99 throw new TypeError(
"elgg.security.addToken not implemented for " + (typeof data) +
"s");
102 elgg.security.init =
function() {
104 elgg.security.tokenRefreshTimer = setInterval(
elgg.security.refreshToken,
elgg.security.interval);
107 elgg.register_hook_handler(
'boot',
'system',
elgg.security.init);