HomeController.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* eslint-disable
  2. handle-callback-err,
  3. max-len,
  4. no-path-concat,
  5. no-unused-vars,
  6. node/no-deprecated-api,
  7. */
  8. // TODO: This file was created by bulk-decaffeinate.
  9. // Fix any style issues and re-enable lint.
  10. /*
  11. * decaffeinate suggestions:
  12. * DS102: Remove unnecessary code created because of implicit returns
  13. * DS207: Consider shorter variations of null checks
  14. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  15. */
  16. let HomeController
  17. const Features = require('../../infrastructure/Features')
  18. const Path = require('path')
  19. const fs = require('fs')
  20. const ErrorController = require('../Errors/ErrorController')
  21. const AuthenticationController = require('../Authentication/AuthenticationController')
  22. const homepageExists = fs.existsSync(
  23. Path.resolve(__dirname + '/../../../views/external/home/v2.pug')
  24. )
  25. module.exports = HomeController = {
  26. index(req, res) {
  27. if (AuthenticationController.isUserLoggedIn(req)) {
  28. if (req.query.scribtex_path != null) {
  29. return res.redirect(`/project?scribtex_path=${req.query.scribtex_path}`)
  30. } else {
  31. return res.redirect('/project')
  32. }
  33. } else {
  34. return HomeController.home(req, res)
  35. }
  36. },
  37. home(req, res, next) {
  38. if (Features.hasFeature('homepage') && homepageExists) {
  39. return res.render('external/home/v2')
  40. } else {
  41. return res.redirect('/login')
  42. }
  43. },
  44. externalPage(page, title) {
  45. return function(req, res, next) {
  46. if (next == null) {
  47. next = function(error) {}
  48. }
  49. const path = Path.resolve(
  50. __dirname + `/../../../views/external/${page}.pug`
  51. )
  52. return fs.exists(path, function(exists) {
  53. // No error in this callback - old method in Node.js!
  54. if (exists) {
  55. return res.render(`external/${page}.pug`, { title })
  56. } else {
  57. return ErrorController.notFound(req, res, next)
  58. }
  59. })
  60. }
  61. }
  62. }