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.

74 lines
2.4 KiB

  1. /**
  2. * Determines what template and controls that will be
  3. * displayed based on the url such as
  4. * /
  5. * /posts
  6. * /downloads
  7. *
  8. * For each controls it calls that "pages" associated javascript file
  9. * which fetches the template, deals with post data and gathers context
  10. * for the template engine.
  11. */
  12. //file IO
  13. const utils = require('../utils/utils.js');
  14. module.exports=
  15. {
  16. /**
  17. *
  18. * @param request -- used to get post data
  19. * @param clientAddress -- used to see if user is banned for login
  20. * @param templateContext -- used by whiskers for information to plug
  21. * in the template
  22. * @param filename -- specific admin page requested
  23. * @returns {Promise} resolves once everything has been added to the template context
  24. */
  25. main: function(request, clientAddress, templateContext, filename)
  26. {
  27. console.log("admin main called");
  28. return new Promise(function(resolve, reject)
  29. {
  30. //if logged in
  31. if(request.session && request.session.user)
  32. {
  33. console.log(filename);
  34. templateContext.loggedIn = true;
  35. utils.getPostData(request).then(function (postData)
  36. {
  37. console.log("temp 1");
  38. var page = "./adminHome.js";
  39. if(filename.includes('/downloads'))
  40. {
  41. page = "./adminDownloads.js";
  42. console.log("downloads time")
  43. }
  44. else if(filename.includes("/posts"))
  45. {
  46. page = "./posts.js";
  47. }
  48. require(page).main(postData, templateContext).then(function(template)
  49. {
  50. templateContext.adminPage = template;
  51. resolve();
  52. }).catch(function(error)
  53. {
  54. console.log(error);
  55. });
  56. });
  57. }
  58. else
  59. {
  60. require("./login/login.js").main(request, clientAddress, templateContext).then(function()
  61. {
  62. resolve();
  63. }).catch(function(err)
  64. {
  65. console.log(err);
  66. reject(err);
  67. })
  68. }
  69. });
  70. }
  71. };