Advertisement
Guest User

Untitled

a guest
Sep 28th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. exports.login = function (req, res, next) {
  2.     Admin.getUserByLogin(req.user.email, (err, user) => {
  3.         if (err) {
  4.             res.json(err);
  5.         }
  6.         //console.log(user.salt, user.hashedPassword);
  7.         //res.json(user);
  8.         console.log(req.user._id);
  9.    
  10.         if (cryptPassword(user.salt, req.body.password) === user.hashedPassword) {
  11.             var randomstring = Math.random().toString(36).slice(-4);
  12.  
  13.             queues.getQueue('sms').sendMessage('test', {
  14.                 token: randomstring,
  15.                 userId: req.user._id
  16.             });
  17.  
  18.             res.json({"token": randomstring});
  19.         }
  20.  
  21.     })
  22.  
  23.     function cryptPassword(salt, password) {
  24.         if (!password) {
  25.             throw new errors.NotAcceptable('$password must be specified');
  26.         }
  27.  
  28.         return crypto.createHmac('sha1', salt).update(password).digest('hex');
  29.     }
  30.  
  31. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement