aboutsummaryrefslogtreecommitdiff
path: root/node_simple.js
diff options
context:
space:
mode:
authornanalelfe <nargiza.nosirova@mail.utoronto.ca>2016-08-14 10:13:55 +0000
committernanalelfe <nargiza.nosirova@mail.utoronto.ca>2016-08-14 10:13:55 +0000
commita532390f81e35f611fd02ad3d543f4d52217ca3c (patch)
tree7bebb4f5614afb82c3103b6e9730a62f0b97a42d /node_simple.js
parentef2674cfe13d2c425c5a3b312244c46f2531979d (diff)
Fixed signin and signup
Diffstat (limited to 'node_simple.js')
-rw-r--r--node_simple.js31
1 files changed, 29 insertions, 2 deletions
diff --git a/node_simple.js b/node_simple.js
index bfb5d43..7ed1f74 100644
--- a/node_simple.js
+++ b/node_simple.js
@@ -270,6 +270,7 @@ exports.retrieve_userComments_history = function (username, callback) {
}
});
+
function doCall() {
callback(true, mylist);
}
@@ -346,7 +347,7 @@ exports.retrieve_userSolutions_count = function (username, callback) {
* IFF both the email and the user_name are not in the database already.
* If either of them exist, the user is NOT added.
*
- * @param {string[]} fields: [email, user_name, f_name, l_name, uni, department, password, phone_num]
+ * @param {string[]} fields: [email, user_name, f_name, l_name, uni, department, password, phone_num, facebook_id]
* @param {function} callbackUser: of the form (<boolean1>, <boolean2>, <string>)
* where, <boolean1> -
* <boolean2> -
@@ -365,7 +366,8 @@ exports.add_user = function (fields, callbackUser) {
messages: 0,
comments: 0,
phone_num: fields[7],
- followers: []
+ followers: [],
+ fb_id: fields[8]
};
var login_data = {
@@ -529,6 +531,31 @@ exports.retrieveUser = function (username, callback) {
};
/**
+ * This function retrieves the user object given their Facebook username.
+ *
+ * @param {string} id: the user's facebook id
+ * @param {function} callback: with args (<bool1>,<bool2>,<string1>,<string2>)
+ * where, <bool1> : success ? true : false
+ * where, <bool2> : error ? true : false
+ * where, <string1> : success ? {Obj} : null
+ * where, <string2> : success ? success_mssg : err_mssg
+ * */
+exports.retrieveUserById = function(id, callback){
+ var users = db.collection('users');
+
+ users.find({fb_id: id}).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[0], "User retrieved");
+ } else {
+ callback(false, false, null, "ID is undefined.");
+ }
+ });
+}
+
+/**
* Returns the hashed password given the username. Assume username exists.
* Used for both admins and users.
*