aboutsummaryrefslogtreecommitdiff
path: root/js/lib/session.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/session.js')
-rw-r--r--js/lib/session.js43
1 files changed, 25 insertions, 18 deletions
diff --git a/js/lib/session.js b/js/lib/session.js
index a1454aa50..a8d52733c 100644
--- a/js/lib/session.js
+++ b/js/lib/session.js
@@ -1,5 +1,5 @@
/**
- * @todo comment
+ * Provides session methods.
*/
elgg.provide('elgg.session');
@@ -8,14 +8,15 @@ elgg.provide('elgg.session');
* @param {string} name
* @param {string} value
* @param {Object} options
+ *
* {number|Date} options[expires]
* {string} options[path]
* {string} options[domain]
* {boolean} options[secure]
*
- * @return {string} The value of the cookie, if only name is specified
+ * @return {string|undefined} The value of the cookie, if only name is specified. Undefined if no value set
*/
-elgg.session.cookie = function (name, value, options) {
+elgg.session.cookie = function(name, value, options) {
var cookies = [], cookie = [], i = 0, date, valid = true;
//elgg.session.cookie()
@@ -46,21 +47,19 @@ elgg.session.cookie = function (name, value, options) {
}
cookies.push(name + '=' + value);
-
- if (elgg.isNumber(options.expires)) {
- if (elgg.isNumber(options.expires)) {
- date = new Date();
- date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
- } else if (options.expires.toUTCString) {
- date = options.expires;
- } else {
- valid = false;
- }
-
- if (valid) {
- cookies.push('expires=' + date.toUTCString());
- }
- }
+
+ if (options.expires) {
+ if (elgg.isNumber(options.expires)) {
+ date = new Date();
+ date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
+ } else if (options.expires.toUTCString) {
+ date = options.expires;
+ }
+
+ if (date) {
+ cookies.push('expires=' + date.toUTCString());
+ }
+ }
// CAUTION: Needed to parenthesize options.path and options.domain
// in the following expressions, otherwise they evaluate to undefined
@@ -81,6 +80,8 @@ elgg.session.cookie = function (name, value, options) {
};
/**
+ * Returns the object of the user logged in.
+ *
* @return {ElggUser} The logged in user
*/
elgg.get_logged_in_user_entity = function() {
@@ -88,6 +89,8 @@ elgg.get_logged_in_user_entity = function() {
};
/**
+ * Returns the GUID of the logged in user or 0.
+ *
* @return {number} The GUID of the logged in user
*/
elgg.get_logged_in_user_guid = function() {
@@ -96,6 +99,8 @@ elgg.get_logged_in_user_guid = function() {
};
/**
+ * Returns if a user is logged in.
+ *
* @return {boolean} Whether there is a user logged in
*/
elgg.is_logged_in = function() {
@@ -103,6 +108,8 @@ elgg.is_logged_in = function() {
};
/**
+ * Returns if the currently logged in user is an admin.
+ *
* @return {boolean} Whether there is an admin logged in
*/
elgg.is_admin_logged_in = function() {