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.

47 lines
1.3 KiB

  1. const utils = require('../utils/utils.js');
  2. const Promise = require('promise');
  3. const sql = require('../utils/sql');
  4. var processLogin = function(result, 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. result.write("<meta http-equiv=\"refresh\" content=\"0\">");
  17. }
  18. resolve();
  19. }).catch(function(err)
  20. {
  21. console.log(err);
  22. resolve();
  23. })
  24. });
  25. };
  26. module.exports=
  27. {
  28. main: function(result, request)
  29. {
  30. result.write("<div class=\"w3-col l8 s12\">");
  31. return new Promise(function(resolve, reject)
  32. {
  33. utils.include(result, './admin/login.html').then(function()
  34. {
  35. return require("../sidebar/sidebar.js").main(result);
  36. }).then(function()
  37. {
  38. return processLogin(result, request);
  39. }).then(function()
  40. {
  41. resolve();
  42. })
  43. });
  44. },
  45. };