2014-02-12 05:23:40 -05:00
|
|
|
logger = require('logger-sharelatex')
|
2017-11-17 06:55:49 -05:00
|
|
|
Settings = require('settings-sharelatex')
|
2014-02-12 05:23:40 -05:00
|
|
|
_ = require('underscore')
|
2017-11-22 05:44:13 -05:00
|
|
|
Features = require "../../infrastructure/Features"
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2014-04-03 06:43:04 -04:00
|
|
|
Path = require "path"
|
|
|
|
fs = require "fs"
|
2014-04-07 05:55:07 -04:00
|
|
|
|
2014-06-20 12:17:24 -04:00
|
|
|
ErrorController = require "../Errors/ErrorController"
|
2016-09-05 10:58:31 -04:00
|
|
|
AuthenticationController = require('../Authentication/AuthenticationController')
|
2014-06-20 12:17:24 -04:00
|
|
|
|
2018-09-17 19:08:34 -04:00
|
|
|
slHomepageExists = fs.existsSync Path.resolve(__dirname + "/../../../views/external/home/sl.pug")
|
|
|
|
v2HomepageExists = fs.existsSync Path.resolve(__dirname + "/../../../views/external/home/v2.pug")
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2014-04-03 06:43:04 -04:00
|
|
|
module.exports = HomeController =
|
2014-02-12 05:23:40 -05:00
|
|
|
index : (req,res)->
|
2016-09-07 11:40:49 -04:00
|
|
|
if AuthenticationController.isUserLoggedIn(req)
|
2014-02-12 05:23:40 -05:00
|
|
|
if req.query.scribtex_path?
|
|
|
|
res.redirect "/project?scribtex_path=#{req.query.scribtex_path}"
|
|
|
|
else
|
|
|
|
res.redirect '/project'
|
|
|
|
else
|
2014-08-05 12:08:38 -04:00
|
|
|
HomeController.home(req, res)
|
2014-04-03 06:43:04 -04:00
|
|
|
|
2018-09-17 19:08:34 -04:00
|
|
|
home: (req, res, next)->
|
|
|
|
if Features.hasFeature('homepage') and !Settings.overleaf and slHomepageExists
|
|
|
|
res.render 'external/home/sl'
|
|
|
|
else if Features.hasFeature('homepage') and Settings.overleaf and v2HomepageExists
|
|
|
|
res.render 'external/home/v2'
|
2014-07-28 12:04:17 -04:00
|
|
|
else
|
2018-09-17 19:08:34 -04:00
|
|
|
res.redirect '/login'
|
2014-07-28 12:04:17 -04:00
|
|
|
|
2014-04-03 06:43:04 -04:00
|
|
|
externalPage: (page, title) ->
|
|
|
|
return (req, res, next = (error) ->) ->
|
2017-01-20 07:03:02 -05:00
|
|
|
path = Path.resolve(__dirname + "/../../../views/external/#{page}.pug")
|
2014-04-03 06:43:04 -04:00
|
|
|
fs.exists path, (exists) -> # No error in this callback - old method in Node.js!
|
|
|
|
if exists
|
2017-01-20 07:03:02 -05:00
|
|
|
res.render "external/#{page}.pug",
|
2014-04-03 06:43:04 -04:00
|
|
|
title: title
|
|
|
|
else
|
2016-09-05 10:58:31 -04:00
|
|
|
ErrorController.notFound(req, res, next)
|