Guest User

Untitled

a guest
Oct 26th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. export const store = function(req, res) {
  2. const { email, password, passwordRepeat } = req.body;
  3. const currentDate = new Date();
  4.  
  5. if (password !== passwordRepeat) {
  6. console.log('passwords dont match');
  7. return;
  8. }
  9.  
  10. hash(password).then((hash) => {
  11. const user = {
  12. email,
  13. password: hash,
  14. created_at: currentDate,
  15. updated_at: currentDate
  16. };
  17.  
  18. query('insert into users set ?', user, (err, result) => {
  19. if (err) {
  20. throw err;
  21. }
  22.  
  23. console.log('success', result);
  24. });
  25. }).catch((err) => {
  26. console.log(err);
  27. });
  28. };
  29.  
  30. export const hash = (str) => {
  31. const saltRounds = 10;
  32. return new Promise((resolve, reject) => {
  33. bcrypt.hash(str, saltRounds, (err, hash) => {
  34. if (err) {
  35. reject(err);
  36. } else {
  37. resolve(hash);
  38. }
  39. });
  40. });
  41. };
Add Comment
Please, Sign In to add comment