2015-12-11 06:30:06 -05:00
|
|
|
UserGetter = require("./UserGetter")
|
2016-10-06 10:49:47 -04:00
|
|
|
UserSessionsManager = require("./UserSessionsManager")
|
2015-12-11 06:30:06 -05:00
|
|
|
ErrorController = require("../Errors/ErrorController")
|
2014-04-09 10:04:47 -04:00
|
|
|
logger = require("logger-sharelatex")
|
|
|
|
Settings = require("settings-sharelatex")
|
|
|
|
fs = require('fs')
|
2016-09-05 10:58:31 -04:00
|
|
|
AuthenticationController = require('../Authentication/AuthenticationController')
|
2014-04-09 07:17:50 -04:00
|
|
|
|
|
|
|
module.exports =
|
|
|
|
|
2014-04-09 07:22:57 -04:00
|
|
|
registerPage : (req, res)->
|
2014-04-09 07:17:50 -04:00
|
|
|
sharedProjectData =
|
|
|
|
project_name:req.query.project_name
|
|
|
|
user_first_name:req.query.user_first_name
|
|
|
|
|
|
|
|
newTemplateData = {}
|
|
|
|
if req.session.templateData?
|
|
|
|
newTemplateData.templateName = req.session.templateData.templateName
|
|
|
|
|
|
|
|
res.render 'user/register',
|
2014-08-01 08:47:14 -04:00
|
|
|
title: 'register'
|
2014-04-09 07:17:50 -04:00
|
|
|
sharedProjectData: sharedProjectData
|
|
|
|
newTemplateData: newTemplateData
|
2014-04-09 07:22:57 -04:00
|
|
|
new_email:req.query.new_email || ""
|
2016-09-05 10:58:31 -04:00
|
|
|
|
2015-12-11 06:30:06 -05:00
|
|
|
activateAccountPage: (req, res) ->
|
|
|
|
# An 'activation' is actually just a password reset on an account that
|
|
|
|
# was set with a random password originally.
|
2016-06-13 08:21:44 -04:00
|
|
|
logger.log query:req.query, "activiate account page called"
|
2015-12-11 06:30:06 -05:00
|
|
|
if !req.query?.user_id? or !req.query?.token?
|
|
|
|
return ErrorController.notFound(req, res)
|
2016-09-05 10:58:31 -04:00
|
|
|
|
2015-12-11 06:30:06 -05:00
|
|
|
UserGetter.getUser req.query.user_id, {email: 1, loginCount: 1}, (error, user) ->
|
|
|
|
return next(error) if error?
|
|
|
|
if !user
|
|
|
|
return ErrorController.notFound(req, res)
|
|
|
|
if user.loginCount > 0
|
2016-06-13 08:21:44 -04:00
|
|
|
logger.log user:user, "user has already logged in so is active, sending them to /login"
|
2015-12-11 06:30:06 -05:00
|
|
|
# Already seen this user, so account must be activate
|
|
|
|
# This lets users keep clicking the 'activate' link in their email
|
|
|
|
# as a way to log in which, if I know our users, they will.
|
|
|
|
res.redirect "/login?email=#{encodeURIComponent(user.email)}"
|
|
|
|
else
|
|
|
|
res.render 'user/activate',
|
|
|
|
title: 'activate_account'
|
|
|
|
email: user.email,
|
|
|
|
token: req.query.token
|
2014-04-09 07:22:57 -04:00
|
|
|
|
|
|
|
loginPage : (req, res)->
|
2016-11-24 06:38:13 -05:00
|
|
|
# if user is being sent to /login with explicit redirect (redir=/foo),
|
|
|
|
# such as being sent from the editor to /login, then set the redirect explicitly
|
|
|
|
if req.query.redir? and !AuthenticationController._getRedirectFromSession(req)?
|
|
|
|
logger.log {redir: req.query.redir}, "setting explicit redirect from login page"
|
2018-11-30 08:03:35 -05:00
|
|
|
AuthenticationController.setRedirectInSession(req, req.query.redir)
|
2014-04-09 07:22:57 -04:00
|
|
|
res.render 'user/login',
|
2014-08-01 08:47:14 -04:00
|
|
|
title: 'login',
|
2015-12-11 06:30:06 -05:00
|
|
|
email: req.query.email
|
2014-04-09 07:22:57 -04:00
|
|
|
|
2015-02-05 13:20:25 -05:00
|
|
|
settingsPage : (req, res, next)->
|
2016-09-05 10:58:31 -04:00
|
|
|
user_id = AuthenticationController.getLoggedInUserId(req)
|
|
|
|
logger.log user: user_id, "loading settings page"
|
2016-11-25 09:38:00 -05:00
|
|
|
shouldAllowEditingDetails = !(Settings?.ldap?.updateUserDetailsOnLogin) and !(Settings?.saml?.updateUserDetailsOnLogin)
|
2018-05-24 09:55:12 -04:00
|
|
|
UserGetter.getUser user_id, (err, user)->
|
2015-02-05 13:20:25 -05:00
|
|
|
return next(err) if err?
|
|
|
|
res.render 'user/settings',
|
|
|
|
title:'account_settings'
|
|
|
|
user: user,
|
2016-11-25 09:38:00 -05:00
|
|
|
shouldAllowEditingDetails: shouldAllowEditingDetails
|
2015-02-05 13:20:25 -05:00
|
|
|
languages: Settings.languages,
|
|
|
|
accountSettingsTabActive: true
|
2016-10-06 10:49:47 -04:00
|
|
|
|
|
|
|
sessionsPage: (req, res, next) ->
|
2016-10-07 05:52:58 -04:00
|
|
|
user = AuthenticationController.getSessionUser(req)
|
|
|
|
logger.log user_id: user._id, "loading sessions page"
|
|
|
|
UserSessionsManager.getAllUserSessions user, [req.sessionID], (err, sessions) ->
|
|
|
|
if err?
|
|
|
|
logger.err {user_id: user._id}, "error getting all user sessions"
|
|
|
|
return next(err)
|
2016-10-06 10:49:47 -04:00
|
|
|
res.render 'user/sessions',
|
|
|
|
title: "sessions"
|
|
|
|
sessions: sessions
|