aboutsummaryrefslogtreecommitdiff
path: root/node_simple.js
diff options
context:
space:
mode:
authornanalelfe <nargiza.nosirova@mail.utoronto.ca>2016-07-22 08:18:26 +0000
committernanalelfe <nargiza.nosirova@mail.utoronto.ca>2016-07-22 08:24:50 +0000
commit0d4151d3e5dfec6da4ce7878682d39a1899c017a (patch)
treece22bfbbf5e9f908d8aa10817549c93bb4a05d30 /node_simple.js
parente0da9feb10efd002f6ebaa99870b4317687a4557 (diff)
Added authentication for signin. Created new signin page. Added validation checks for signup.
Diffstat (limited to 'node_simple.js')
-rw-r--r--node_simple.js30
1 files changed, 29 insertions, 1 deletions
diff --git a/node_simple.js b/node_simple.js
index 5c0666b..fa46447 100644
--- a/node_simple.js
+++ b/node_simple.js
@@ -137,7 +137,7 @@ exports.add_user = function (fields, callbackUser) {
}
else {// user insert successfull
- logins.insertOne( login_data, function (err) {
+ logins.insertOne(login_data, function (err) {
if (err) {
callbackUser(false, true, "Error : User has not been added.");
}
@@ -194,6 +194,34 @@ exports.find_user_name = function (user_name, callbackUser, callback) {
};
/*
+ Retrieves the user object based on the username.
+*/
+
+exports.retrieveUser = function (username, callback) {
+ mongoFactory.getConnection(uri).then(function (db) {
+ var users = db.collection('users');
+
+ users.find({user_name: username}).toArray(function (err, result) {
+ if (err) {
+ // callback(success, error, user, message)
+ callback(false, true, null, "Error : Could not retrieve user.");
+ }
+
+ else if (result.length) {
+ callback(true, false, result, "User retrieved");
+ }
+
+ else {
+ callback(false, false, null, "Username is undefined.");
+ }
+
+ });
+ });
+}
+
+
+
+/*
* This (helper) function returns true IFF email already exists in the database
* */
exports.find_user = function (email, callbackUser, callback) {