From f523649f5410438a770e1b9512511cc0be721d40 Mon Sep 17 00:00:00 2001 From: calzoneman Date: Fri, 16 Aug 2013 10:37:26 -0500 Subject: [PATCH] Finish refactoring api --- api.js | 17 +++++++++++++---- utilities.js | 6 +++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/api.js b/api.js index 659b0390..88f8ab01 100644 --- a/api.js +++ b/api.js @@ -499,10 +499,19 @@ module.exports = function (Server) { return; } - var channels = Server.db.listUserChannels(name); - res.jsonp({ - success: true, - channels: channels + db.listUserChannels(name, function (err, res) { + if(err) { + res.jsonp({ + success: false, + channels: [] + }); + return; + } + + res.jsonp({ + success: true, + channels: res + }); }); }); diff --git a/utilities.js b/utilities.js index d0c08596..42d04df5 100644 --- a/utilities.js +++ b/utilities.js @@ -1,6 +1,10 @@ module.exports = { isValidChannelName: function (name) { - return name.match(/^[\w-_]+$/); + return name.match(/^[\w-_]{1,30}$/); + }, + + isValidUserName: function (name) { + return name.match(/^[\w-_]{1,20}$/); }, randomSalt: function (length) {