Personal blog written from scratch using Node.js, Bootstrap, and MySQL. https://jrtechs.net
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.3 KiB

  1. const utils = require('../utils/utils.js');
  2. const Promise = require('promise');
  3. const sql = require('../utils/sql');
  4. const processLogin = function(request)
  5. {
  6. return new Promise(function(resolve, reject)
  7. {
  8. utils.getPostData(request).then(function(postData)
  9. {
  10. return sql.checkLogin(postData);
  11. }).then(function(loginResult)
  12. {
  13. if(loginResult.pass)
  14. {
  15. request.session.user = loginResult.user;
  16. console.log("user has logged in");
  17. resolve("<meta http-equiv=\"refresh\" content=\"0\">");
  18. }
  19. else
  20. {
  21. resolve("");
  22. }
  23. }).catch(function(err)
  24. {
  25. reject(err);
  26. })
  27. });
  28. };
  29. module.exports=
  30. {
  31. main: function(request)
  32. {
  33. return new Promise(function(resolve, reject)
  34. {
  35. Promise.all([utils.include('./admin/login.html'),
  36. require("../sidebar/sidebar.js").main(),
  37. processLogin(request)]).then(function(html)
  38. {
  39. resolve(html.join('') + "</div>");
  40. }).catch(function(err)
  41. {
  42. reject(err);
  43. })
  44. });
  45. },
  46. };