Guest User

Untitled

a guest
Sep 18th, 2017
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. exports.workerLogin = function(req, cb) {
  2. console.log('workerLogin', req);
  3.  
  4. Worklog.find({
  5. where: { username: req.username, isActive: true },
  6. attributes: ['id', 'username', 'fName', 'lName','email','mobile',
  7. 'role', 'password'
  8. ],
  9. raw: true
  10. }).then(function(worker, err) {
  11. if (worker && compare(req.password, worker.password)) {
  12.  
  13. worker.password = undefined;
  14. cb(worker);
  15. } else if (err) {
  16. console.log('workerLogin findOne err:', err);
  17. cb(false);
  18. } else if (!!worker && !compare(req.password, worker.password)) {
  19. cb('Wrong password');
  20. } else {
  21. cb('No account found');
  22. }
  23. });
  24. }
  25.  
  26.  
  27. //////////////////////////
  28.  
  29. Worklog.create({
  30. username: req.body.username,
  31. fName: req.body.fName,
  32. lName: req.body.lName,
  33. password:encrypt(req.body.password),
  34. email: req.body.email,
  35. mobile: req.body.mobile,
  36. address: req.body.address,
  37. role: req.body.role
  38. }).then(function(woker, err) {
  39. if(woker) {
  40. woker.password = undefined;
  41. cb(woker);
  42. } else {
  43. console.log('woker create err.', err);
  44. }
  45. })
  46.  
  47. };
Add Comment
Please, Sign In to add comment