summaryrefslogtreecommitdiff
path: root/node
diff options
context:
space:
mode:
authorPeter 'Pita' Martischka <petermartischka - googlemail - com>2012-01-30 01:58:28 -0800
committerPeter 'Pita' Martischka <petermartischka - googlemail - com>2012-01-30 01:58:28 -0800
commitaeea061f6977c685197ca0fcbec4ff0a3376f899 (patch)
tree9c8451a4c003cba05fa9a86cac6d73a17f392bd1 /node
parent4d714cee94351d8feceeed851721485cc945928b (diff)
parenta300bb6e9268f047f990780edfda37cd9ae1c7c0 (diff)
downloadetherpad-lite-aeea061f6977c685197ca0fcbec4ff0a3376f899.zip
Merge pull request #366 from booo/master
move randomString function into a module
Diffstat (limited to 'node')
-rw-r--r--node/db/AuthorManager.js17
-rw-r--r--node/db/GroupManager.js16
-rw-r--r--node/db/ReadOnlyManager.js17
-rw-r--r--node/db/SecurityManager.js2
-rw-r--r--node/db/SessionManager.js16
-rw-r--r--node/handler/APIHandler.js16
-rw-r--r--node/utils/randomstring.js16
7 files changed, 25 insertions, 75 deletions
diff --git a/node/db/AuthorManager.js b/node/db/AuthorManager.js
index f4f42d11..7c054a56 100644
--- a/node/db/AuthorManager.js
+++ b/node/db/AuthorManager.js
@@ -22,6 +22,8 @@ var ERR = require("async-stacktrace");
var db = require("./DB").db;
var async = require("async");
+var randomString = require("../utils/randomstring");
+
/**
* Checks if the author exists
*/
@@ -177,18 +179,3 @@ exports.setAuthorName = function (author, name, callback)
{
db.setSub("globalAuthor:" + author, ["name"], name, callback);
}
-
-/**
- * Generates a random String with the given length. Is needed to generate the Author Ids
- */
-function randomString(len)
-{
- var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
- var randomstring = '';
- for (var i = 0; i < len; i++)
- {
- var rnum = Math.floor(Math.random() * chars.length);
- randomstring += chars.substring(rnum, rnum + 1);
- }
- return randomstring;
-}
diff --git a/node/db/GroupManager.js b/node/db/GroupManager.js
index 473ea9b7..7e3b7d6d 100644
--- a/node/db/GroupManager.js
+++ b/node/db/GroupManager.js
@@ -20,6 +20,7 @@
var ERR = require("async-stacktrace");
var customError = require("../utils/customError");
+var randomString = require("../utils/randomstring");
var db = require("./DB").db;
var async = require("async");
var padManager = require("./PadManager");
@@ -255,18 +256,3 @@ exports.listPads = function(groupID, callback)
}
});
}
-
-/**
- * Generates a random String with the given length. Is needed to generate the Author Ids
- */
-function randomString(len)
-{
- var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
- var randomstring = '';
- for (var i = 0; i < len; i++)
- {
- var rnum = Math.floor(Math.random() * chars.length);
- randomstring += chars.substring(rnum, rnum + 1);
- }
- return randomstring;
-}
diff --git a/node/db/ReadOnlyManager.js b/node/db/ReadOnlyManager.js
index 73b3be9e..1e5079c5 100644
--- a/node/db/ReadOnlyManager.js
+++ b/node/db/ReadOnlyManager.js
@@ -22,6 +22,8 @@ var ERR = require("async-stacktrace");
var db = require("./DB").db;
var async = require("async");
+var randomString = require("../utils/randomstring");
+
/**
* returns a read only id for a pad
* @param {String} padId the id of the pad
@@ -70,18 +72,3 @@ exports.getPadId = function(readOnlyId, callback)
{
db.get("readonly2pad:" + readOnlyId, callback);
}
-
-/**
- * Generates a random String with the given length. Is needed to generate the read only ids
- */
-function randomString(len)
-{
- var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
- var randomstring = '';
- for (var i = 0; i < len; i++)
- {
- var rnum = Math.floor(Math.random() * chars.length);
- randomstring += chars.substring(rnum, rnum + 1);
- }
- return randomstring;
-}
diff --git a/node/db/SecurityManager.js b/node/db/SecurityManager.js
index 52d5afcb..4b86d868 100644
--- a/node/db/SecurityManager.js
+++ b/node/db/SecurityManager.js
@@ -26,6 +26,8 @@ var padManager = require("./PadManager");
var sessionManager = require("./SessionManager");
var settings = require("../utils/Settings")
+var randomString = require("../utils/randomstring");
+
/**
* This function controlls the access to a pad, it checks if the user can access a pad.
* @param padID the pad the user wants to access
diff --git a/node/db/SessionManager.js b/node/db/SessionManager.js
index a394f544..084d4a69 100644
--- a/node/db/SessionManager.js
+++ b/node/db/SessionManager.js
@@ -20,6 +20,7 @@
var ERR = require("async-stacktrace");
var customError = require("../utils/customError");
+var randomString = require("../utils/randomstring");
var db = require("./DB").db;
var async = require("async");
var groupMangager = require("./GroupManager");
@@ -358,21 +359,6 @@ function listSessionsWithDBKey (dbkey, callback)
});
}
-/**
- * Generates a random String with the given length. Is needed to generate the SessionIDs
- */
-function randomString(len)
-{
- var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
- var randomstring = '';
- for (var i = 0; i < len; i++)
- {
- var rnum = Math.floor(Math.random() * chars.length);
- randomstring += chars.substring(rnum, rnum + 1);
- }
- return randomstring;
-}
-
//checks if a number is an int
function is_int(value)
{
diff --git a/node/handler/APIHandler.js b/node/handler/APIHandler.js
index 0cd9cb58..ca45e1f8 100644
--- a/node/handler/APIHandler.js
+++ b/node/handler/APIHandler.js
@@ -22,6 +22,7 @@ var ERR = require("async-stacktrace");
var fs = require("fs");
var api = require("../db/API");
var padManager = require("../db/PadManager");
+var randomString = require("../utils/randomstring");
//ensure we have an apikey
var apikey = null;
@@ -157,18 +158,3 @@ function callAPI(functionName, fields, req, res)
//call the api function
api[functionName](functionParams[0],functionParams[1],functionParams[2],functionParams[3],functionParams[4]);
}
-
-/**
- * Generates a random String with the given length. Is needed to generate the Author Ids
- */
-function randomString(len)
-{
- var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
- var randomstring = '';
- for (var i = 0; i < len; i++)
- {
- var rnum = Math.floor(Math.random() * chars.length);
- randomstring += chars.substring(rnum, rnum + 1);
- }
- return randomstring;
-}
diff --git a/node/utils/randomstring.js b/node/utils/randomstring.js
new file mode 100644
index 00000000..4c1bba24
--- /dev/null
+++ b/node/utils/randomstring.js
@@ -0,0 +1,16 @@
+/**
+ * Generates a random String with the given length. Is needed to generate the Author, Group, readonly, session Ids
+ */
+var randomString = function randomString(len)
+{
+ var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+ var randomstring = '';
+ for (var i = 0; i < len; i++)
+ {
+ var rnum = Math.floor(Math.random() * chars.length);
+ randomstring += chars.substring(rnum, rnum + 1);
+ }
+ return randomstring;
+};
+
+module.exports = randomString;