Guest User

Untitled

a guest
Apr 3rd, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. app.post('/login', routes.dologin);
  2.  
  3. exports.dologin = function (req, res) {
  4. res.locals.session = req.session;
  5.  
  6. var user = req.body.user;
  7. db.authenticateUser(user.email, user.password, function ( err, response) {
  8. if (err) {
  9. .......
  10.  
  11. .......
  12. } else {
  13. .......
  14.  
  15. ........
  16. }
  17. });
  18. };
  19.  
  20. var mongo = require('mongoskin'),
  21. crypto = require('crypto');
  22.  
  23. module.exports = function (config) {
  24.  
  25. var USERS_COLLECTION = 'users',
  26. ORDERS_COLLECTION = 'orders',
  27. salt = 'supersecretkey',
  28. db;
  29.  
  30. authenticateUser: function (emailId, password, callback) {
  31. db.collection(USERS_COLLECTION).count({email : emailId, password: encryptPassword(password)}, function (err, count) {
  32. if (err) {
  33. console.log("error authenticating user: " + err);
  34. callback(new Error(err));
  35. } else if (count === 0) {
  36. callback(new Error("emailid/password did not match"));
  37. } else {
  38. callback(null);
  39. }
  40. });
  41. },
  42. }
  43.  
  44. var mongo = require('mongoskin'),
  45. crypto = require('crypto');
  46.  
  47. module.exports = function (config) {
  48.  
  49. var USERS_COLLECTION = 'users',
  50. ORDERS_COLLECTION = 'orders',
  51. salt = 'supersecretkey',
  52. db = mongo.db('localhost:27017/yourdb');
  53.  
  54. authenticateUser: function (emailId, password, callback) {
  55.  
  56. db.collection(USERS_COLLECTION).count({
  57. email: emailId,
  58. password: encryptPassword(password)
  59. }, function (err, count) {
  60. if (err) {
  61. console.log("error authenticating user: " + err);
  62. callback(new Error(err));
  63. } else if (count === 0) {
  64. callback(new Error("emailid/password did not match"));
  65. } else {
  66. callback(null);
  67. }
  68. });
  69. },
  70. }
Add Comment
Please, Sign In to add comment