2019-05-29 05:21:06 -04:00
|
|
|
const UserGetter = require('./UserGetter')
|
2020-08-19 05:11:32 -04:00
|
|
|
const OError = require('@overleaf/o-error')
|
2019-05-29 05:21:06 -04:00
|
|
|
const UserSessionsManager = require('./UserSessionsManager')
|
2021-11-01 11:05:16 -04:00
|
|
|
const logger = require('@overleaf/logger')
|
2021-07-07 05:38:56 -04:00
|
|
|
const Settings = require('@overleaf/settings')
|
2019-05-29 05:21:06 -04:00
|
|
|
const AuthenticationController = require('../Authentication/AuthenticationController')
|
2021-07-28 04:51:20 -04:00
|
|
|
const SessionManager = require('../Authentication/SessionManager')
|
2019-09-30 09:21:31 -04:00
|
|
|
const _ = require('lodash')
|
2019-05-29 05:21:06 -04:00
|
|
|
|
2019-07-18 10:19:10 -04:00
|
|
|
const UserPagesController = {
|
2019-05-29 05:21:06 -04:00
|
|
|
registerPage(req, res) {
|
|
|
|
const sharedProjectData = {
|
|
|
|
project_name: req.query.project_name,
|
2021-04-27 03:52:58 -04:00
|
|
|
user_first_name: req.query.user_first_name,
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
const newTemplateData = {}
|
|
|
|
if (req.session.templateData != null) {
|
|
|
|
newTemplateData.templateName = req.session.templateData.templateName
|
|
|
|
}
|
|
|
|
|
2019-07-18 10:19:10 -04:00
|
|
|
res.render('user/register', {
|
2019-05-29 05:21:06 -04:00
|
|
|
title: 'register',
|
|
|
|
sharedProjectData,
|
|
|
|
newTemplateData,
|
2021-04-27 03:52:58 -04:00
|
|
|
samlBeta: req.session.samlBeta,
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
loginPage(req, res) {
|
|
|
|
// 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 != null &&
|
|
|
|
AuthenticationController._getRedirectFromSession(req) == null
|
|
|
|
) {
|
|
|
|
AuthenticationController.setRedirectInSession(req, req.query.redir)
|
|
|
|
}
|
2019-07-18 10:19:10 -04:00
|
|
|
res.render('user/login', {
|
2021-04-27 03:52:58 -04:00
|
|
|
title: 'login',
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2019-07-18 10:19:10 -04:00
|
|
|
/**
|
|
|
|
* Landing page for users who may have received one-time login
|
|
|
|
* tokens from the read-only maintenance site.
|
|
|
|
*
|
|
|
|
* We tell them that Overleaf is back up and that they can login normally.
|
|
|
|
*/
|
|
|
|
oneTimeLoginPage(req, res, next) {
|
|
|
|
res.render('user/one_time_login')
|
|
|
|
},
|
|
|
|
|
2019-05-29 05:21:06 -04:00
|
|
|
logoutPage(req, res) {
|
2019-07-18 10:19:10 -04:00
|
|
|
res.render('user/logout')
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
renderReconfirmAccountPage(req, res) {
|
2019-07-18 10:19:10 -04:00
|
|
|
const pageData = {
|
2021-04-27 03:52:58 -04:00
|
|
|
reconfirm_email: req.session.reconfirm_email,
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
// when a user must reconfirm their account
|
2019-07-18 10:19:10 -04:00
|
|
|
res.render('user/reconfirm', pageData)
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
settingsPage(req, res, next) {
|
2021-07-28 04:51:20 -04:00
|
|
|
const userId = SessionManager.getLoggedInUserId(req.session)
|
2021-02-22 10:01:02 -05:00
|
|
|
const reconfirmationRemoveEmail = req.query.remove
|
2019-09-30 09:21:31 -04:00
|
|
|
// SSO
|
2019-06-18 11:35:57 -04:00
|
|
|
const ssoError = req.session.ssoError
|
|
|
|
if (ssoError) {
|
|
|
|
delete req.session.ssoError
|
|
|
|
}
|
2019-09-30 09:21:31 -04:00
|
|
|
// Institution SSO
|
2019-10-21 12:02:01 -04:00
|
|
|
let institutionLinked = _.get(req.session, ['saml', 'linked'])
|
|
|
|
if (institutionLinked) {
|
|
|
|
// copy object if exists because _.get does not
|
|
|
|
institutionLinked = Object.assign(
|
|
|
|
{
|
2021-04-27 03:52:58 -04:00
|
|
|
hasEntitlement: _.get(req.session, ['saml', 'hasEntitlement']),
|
2019-10-21 12:02:01 -04:00
|
|
|
},
|
|
|
|
institutionLinked
|
|
|
|
)
|
|
|
|
}
|
2021-02-18 06:46:08 -05:00
|
|
|
const samlError = _.get(req.session, ['saml', 'error'])
|
2019-10-17 11:30:37 -04:00
|
|
|
const institutionEmailNonCanonical = _.get(req.session, [
|
|
|
|
'saml',
|
2021-04-27 03:52:58 -04:00
|
|
|
'emailNonCanonical',
|
2019-10-17 11:30:37 -04:00
|
|
|
])
|
2019-11-13 09:22:54 -05:00
|
|
|
const institutionRequestedEmail = _.get(req.session, [
|
|
|
|
'saml',
|
2021-04-27 03:52:58 -04:00
|
|
|
'requestedEmail',
|
2019-11-13 09:22:54 -05:00
|
|
|
])
|
2021-02-22 10:01:02 -05:00
|
|
|
|
|
|
|
const reconfirmedViaSAML = _.get(req.session, ['saml', 'reconfirmed'])
|
2019-09-30 09:21:31 -04:00
|
|
|
delete req.session.saml
|
2019-07-15 09:09:04 -04:00
|
|
|
let shouldAllowEditingDetails = true
|
|
|
|
if (Settings.ldap && Settings.ldap.updateUserDetailsOnLogin) {
|
|
|
|
shouldAllowEditingDetails = false
|
|
|
|
}
|
|
|
|
if (Settings.saml && Settings.saml.updateUserDetailsOnLogin) {
|
|
|
|
shouldAllowEditingDetails = false
|
|
|
|
}
|
2019-05-29 05:21:06 -04:00
|
|
|
const oauthProviders = Settings.oauthProviders || {}
|
|
|
|
|
2019-07-18 10:19:10 -04:00
|
|
|
UserGetter.getUser(userId, (err, user) => {
|
2019-05-29 05:21:06 -04:00
|
|
|
if (err != null) {
|
|
|
|
return next(err)
|
|
|
|
}
|
2019-07-10 06:40:59 -04:00
|
|
|
res.render('user/settings', {
|
|
|
|
title: 'account_settings',
|
|
|
|
user,
|
|
|
|
hasPassword: !!user.hashedPassword,
|
|
|
|
shouldAllowEditingDetails,
|
|
|
|
languages: Settings.languages,
|
|
|
|
accountSettingsTabActive: true,
|
|
|
|
oauthProviders: UserPagesController._translateProviderDescriptions(
|
|
|
|
oauthProviders,
|
|
|
|
req
|
|
|
|
),
|
|
|
|
oauthUseV2: Settings.oauthUseV2 || false,
|
2019-09-30 09:21:31 -04:00
|
|
|
institutionLinked,
|
2021-02-18 06:46:08 -05:00
|
|
|
samlError,
|
2019-11-13 09:22:54 -05:00
|
|
|
institutionEmailNonCanonical:
|
|
|
|
institutionEmailNonCanonical && institutionRequestedEmail
|
|
|
|
? institutionEmailNonCanonical
|
|
|
|
: undefined,
|
2021-02-22 10:01:02 -05:00
|
|
|
reconfirmedViaSAML,
|
|
|
|
reconfirmationRemoveEmail,
|
2019-10-07 12:48:43 -04:00
|
|
|
samlBeta: req.session.samlBeta,
|
2019-07-10 06:40:59 -04:00
|
|
|
ssoError: ssoError,
|
2021-04-27 03:52:58 -04:00
|
|
|
thirdPartyIds: UserPagesController._restructureThirdPartyIds(user),
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
sessionsPage(req, res, next) {
|
2021-07-28 04:51:20 -04:00
|
|
|
const user = SessionManager.getSessionUser(req.session)
|
2019-07-18 10:19:10 -04:00
|
|
|
logger.log({ userId: user._id }, 'loading sessions page')
|
2021-10-28 09:01:09 -04:00
|
|
|
const currentSession = {
|
|
|
|
ip_address: user.ip_address,
|
|
|
|
session_created: user.session_created,
|
|
|
|
}
|
2021-10-20 15:03:18 -04:00
|
|
|
UserSessionsManager.getAllUserSessions(
|
|
|
|
user,
|
|
|
|
[req.sessionID],
|
|
|
|
(err, sessions) => {
|
|
|
|
if (err != null) {
|
|
|
|
OError.tag(err, 'error getting all user sessions', {
|
|
|
|
userId: user._id,
|
|
|
|
})
|
|
|
|
return next(err)
|
|
|
|
}
|
|
|
|
res.render('user/sessions', {
|
|
|
|
title: 'sessions',
|
2021-10-28 09:01:09 -04:00
|
|
|
currentSession,
|
2021-10-20 15:03:18 -04:00
|
|
|
sessions,
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
}
|
2021-10-20 15:03:18 -04:00
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_restructureThirdPartyIds(user) {
|
|
|
|
// 3rd party identifiers are an array of objects
|
|
|
|
// this turn them into a single object, which
|
|
|
|
// makes data easier to use in template
|
|
|
|
if (
|
|
|
|
!user.thirdPartyIdentifiers ||
|
|
|
|
user.thirdPartyIdentifiers.length === 0
|
|
|
|
) {
|
|
|
|
return null
|
|
|
|
}
|
2019-07-18 10:19:10 -04:00
|
|
|
return user.thirdPartyIdentifiers.reduce((obj, identifier) => {
|
2019-05-29 05:21:06 -04:00
|
|
|
obj[identifier.providerId] = identifier.externalUserId
|
|
|
|
return obj
|
|
|
|
}, {})
|
|
|
|
},
|
|
|
|
|
|
|
|
_translateProviderDescriptions(providers, req) {
|
|
|
|
const result = {}
|
|
|
|
if (providers) {
|
2021-05-05 09:05:04 -04:00
|
|
|
for (const provider in providers) {
|
2019-05-29 05:21:06 -04:00
|
|
|
const data = providers[provider]
|
|
|
|
data.description = req.i18n.translate(
|
|
|
|
data.descriptionKey,
|
2020-06-10 06:22:50 -04:00
|
|
|
Object.assign({}, data.descriptionOptions)
|
2019-05-29 05:21:06 -04:00
|
|
|
)
|
|
|
|
result[provider] = data
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result
|
2021-04-27 03:52:58 -04:00
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-07-18 10:19:10 -04:00
|
|
|
|
|
|
|
module.exports = UserPagesController
|