4 elgg.provide(
'elgg.security.token');
6 elgg.security.tokenRefreshTimer = null;
18 elgg.security.setToken =
function(token_object, valid_tokens) {
20 elgg.security.token = token_object;
23 $(
'[name=__elgg_ts]').val(token_object.__elgg_ts);
24 $(
'[name=__elgg_token]').each(
function () {
25 if (valid_tokens[$(
this).val()]) {
26 $(
this).val(token_object.__elgg_token);
31 $(
'[href*="__elgg_ts"][href*="__elgg_token"]').each(
function() {
32 var token = this.href.match(/__elgg_token=([0-9
a-z_-]+)/
i)[1];
33 if (valid_tokens[token]) {
35 .replace(/__elgg_ts=\d+/
i,
'__elgg_ts=' + token_object.__elgg_ts)
36 .replace(/__elgg_token=[0-9
a-z_-]+/
i,
'__elgg_token=' + token_object.__elgg_token);
49 elgg.security.refreshToken =
function() {
53 pairs[
elgg.security.token.__elgg_ts +
',' +
elgg.security.token.__elgg_token] = 1;
55 $(
'form').each(
function () {
57 var ts = $(
'[name=__elgg_ts]:last',
this).val();
58 var token = $(
'[name=__elgg_token]:last',
this).val();
61 pairs[ts +
',' + token] = 1;
65 $(
'[href*="__elgg_ts"][href*="__elgg_token"]').each(
function() {
66 var ts = this.href.match(/__elgg_ts=(\d+)/
i)[1];
67 var token = this.href.match(/__elgg_token=([0-9
a-z_-]+)/
i)[1];
68 pairs[ts +
',' + token] = 1;
71 pairs = $.map(pairs,
function(val, key) {
75 elgg.ajax(
'refresh_token', {
78 session_token:
elgg.session.token
84 elgg.session.token = data.session_token;
85 elgg.security.setToken(data.token, data.valid_tokens);
87 if (
elgg.get_logged_in_user_guid() != data.user_guid) {
88 elgg.session.user = null;
90 elgg.register_error(
elgg.echo(
'session_changed_user'));
92 elgg.register_error(
elgg.echo(
'session_expired'));
108 elgg.security.addToken =
function(data) {
111 if (
elgg.isString(data)) {
113 var parts =
elgg.parse_url(data),
117 if (parts[
'host'] === undefined) {
118 if (data.indexOf(
'?') === 0) {
121 args =
elgg.parse_str(parts[
'query']);
126 if (parts[
'query'] !== undefined) {
128 args =
elgg.parse_str(parts[
'query']);
130 var split = data.split(
'?');
131 base = split[0] +
'?';
133 args[
"__elgg_ts"] =
elgg.security.token.__elgg_ts;
134 args[
"__elgg_token"] =
elgg.security.token.__elgg_token;
136 return base +
jQuery.param(args);
140 if (
elgg.isUndefined(data)) {
141 return elgg.security.token;
145 if (
elgg.isPlainObject(data)) {
146 return elgg.extend(data,
elgg.security.token);
150 throw new TypeError(
"elgg.security.addToken not implemented for " + (typeof data) +
"s");
156 elgg.security.init =
function() {
158 elgg.security.tokenRefreshTimer = setInterval(
elgg.security.refreshToken,
elgg.security.interval);
161 elgg.register_hook_handler(
'boot',
'system',
elgg.security.init);
elgg message elgg state error
elgg message elgg state success