Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- app.post('/login', routes.dologin);
- exports.dologin = function (req, res) {
- res.locals.session = req.session;
- var user = req.body.user;
- db.authenticateUser(user.email, user.password, function ( err, response) {
- if (err) {
- .......
- .......
- } else {
- .......
- ........
- }
- });
- };
- var mongo = require('mongoskin'),
- crypto = require('crypto');
- module.exports = function (config) {
- var USERS_COLLECTION = 'users',
- ORDERS_COLLECTION = 'orders',
- salt = 'supersecretkey',
- db;
- authenticateUser: function (emailId, password, callback) {
- db.collection(USERS_COLLECTION).count({email : emailId, password: encryptPassword(password)}, function (err, count) {
- if (err) {
- console.log("error authenticating user: " + err);
- callback(new Error(err));
- } else if (count === 0) {
- callback(new Error("emailid/password did not match"));
- } else {
- callback(null);
- }
- });
- },
- }
- var mongo = require('mongoskin'),
- crypto = require('crypto');
- module.exports = function (config) {
- var USERS_COLLECTION = 'users',
- ORDERS_COLLECTION = 'orders',
- salt = 'supersecretkey',
- db = mongo.db('localhost:27017/yourdb');
- authenticateUser: function (emailId, password, callback) {
- db.collection(USERS_COLLECTION).count({
- email: emailId,
- password: encryptPassword(password)
- }, function (err, count) {
- if (err) {
- console.log("error authenticating user: " + err);
- callback(new Error(err));
- } else if (count === 0) {
- callback(new Error("emailid/password did not match"));
- } else {
- callback(null);
- }
- });
- },
- }
Add Comment
Please, Sign In to add comment