From d96e93e81f98d18aa84f701b578f4239020652c3 Mon Sep 17 00:00:00 2001 From: nanalelfe Date: Wed, 24 Aug 2016 04:52:06 -0400 Subject: Implemented the password reset function --- node_simple.js | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) (limited to 'node_simple.js') diff --git a/node_simple.js b/node_simple.js index 7ed1f74..360125e 100644 --- a/node_simple.js +++ b/node_simple.js @@ -620,6 +620,32 @@ exports.findUserByID = function (id, callback) { }); }; +exports.updatePassword = function (email, password, callback) { + var logins = db.collection('logins'); + logins.updateOne({email: email}, {$set: {password: password}}, function(err, docs) { + if (err) callback(true, "Error: Failed to update password."); + + else { + callback(false, "Success"); + } + }); +} + +/*exports.findUserByEmail = function (email, callback) { + var users = db.collection('users'); + users.find({email: email}).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."); + } + }); + +}*/ + /************************* COURSES / EXAMS **********************************/ /** @@ -1213,6 +1239,7 @@ exports.addAdmin = function (admin_data, callback) { }); }; + /** * This function checks if the admin username already exists in the ADMINS collection. If it does, then callback * returns success, and the admin object is passed through the callback. @@ -1292,3 +1319,49 @@ exports.checkMailbox = function (username, callback) { }; +exports.addToken = function (email, userToken, token, callback) { + + var tokens = db.collection('tokens'); + + var userToken = { + userToken: userToken, + email: email, + token: token + }; + + tokens.insertOne(userToken, function (err) { + if (err) { + //callback(error, message) + callback(true, "Error : Token has not been added."); + } + + else { + callback(false, "Token has been added"); + } + }); + + +}; + +exports.getToken = function(token, callback) { + var tokens = db.collection('tokens'); + tokens.find({token: token}).toArray(function(err, result) { + if (err) { + callback(true, null); + } else { + callback(false, result); + } + }); +}; + +exports.removeToken = function(token, callback) { + var tokens = db.collection('tokens'); + tokens.removeOne({token: token}, function(err, docs) { + if (err) { + callback(true, "There was an error."); + } else if (docs.deletedCount) { + callback(false, "Token removed"); + } + }); +}; + -- cgit v1.2.3