mirror of
https://github.com/overleaf/overleaf.git
synced 2025-03-15 08:23:08 +00:00
use getSessionUser
rather than getLoggedInUser
This commit is contained in:
parent
9758dd77b3
commit
cc5ddc92bb
6 changed files with 292 additions and 311 deletions
|
@ -24,27 +24,26 @@ module.exports = CollaboratorsInviteController =
|
||||||
inviteToProject: (req, res, next) ->
|
inviteToProject: (req, res, next) ->
|
||||||
projectId = req.params.Project_id
|
projectId = req.params.Project_id
|
||||||
email = req.body.email
|
email = req.body.email
|
||||||
AuthenticationController.getLoggedInUser req, (err, sendingUser) ->
|
sendingUser = AuthenticationController.getSessionUser(req)
|
||||||
return callback(err) if err?
|
sendingUserId = sendingUser._id
|
||||||
sendingUserId = sendingUser._id
|
logger.log {projectId, email, sendingUserId}, "inviting to project"
|
||||||
logger.log {projectId, email, sendingUserId}, "inviting to project"
|
LimitationsManager.canAddXCollaborators projectId, 1, (error, allowed) =>
|
||||||
LimitationsManager.canAddXCollaborators projectId, 1, (error, allowed) =>
|
return next(error) if error?
|
||||||
return next(error) if error?
|
if !allowed
|
||||||
if !allowed
|
logger.log {projectId, email, sendingUserId}, "not allowed to invite more users to project"
|
||||||
logger.log {projectId, email, sendingUserId}, "not allowed to invite more users to project"
|
return res.json {invite: null}
|
||||||
return res.json {invite: null}
|
{email, privileges} = req.body
|
||||||
{email, privileges} = req.body
|
email = EmailHelper.parseEmail(email)
|
||||||
email = EmailHelper.parseEmail(email)
|
if !email? or email == ""
|
||||||
if !email? or email == ""
|
logger.log {projectId, email, sendingUserId}, "invalid email address"
|
||||||
logger.log {projectId, email, sendingUserId}, "invalid email address"
|
return res.sendStatus(400)
|
||||||
return res.sendStatus(400)
|
CollaboratorsInviteHandler.inviteToProject projectId, sendingUser, email, privileges, (err, invite) ->
|
||||||
CollaboratorsInviteHandler.inviteToProject projectId, sendingUser, email, privileges, (err, invite) ->
|
if err?
|
||||||
if err?
|
logger.err {projectId, email, sendingUserId}, "error creating project invite"
|
||||||
logger.err {projectId, email, sendingUserId}, "error creating project invite"
|
return next(err)
|
||||||
return next(err)
|
logger.log {projectId, email, sendingUserId}, "invite created"
|
||||||
logger.log {projectId, email, sendingUserId}, "invite created"
|
EditorRealTimeController.emitToRoom(projectId, 'project:membership:changed', {invites: true})
|
||||||
EditorRealTimeController.emitToRoom(projectId, 'project:membership:changed', {invites: true})
|
return res.json {invite: invite}
|
||||||
return res.json {invite: invite}
|
|
||||||
|
|
||||||
revokeInvite: (req, res, next) ->
|
revokeInvite: (req, res, next) ->
|
||||||
projectId = req.params.Project_id
|
projectId = req.params.Project_id
|
||||||
|
@ -61,13 +60,12 @@ module.exports = CollaboratorsInviteController =
|
||||||
projectId = req.params.Project_id
|
projectId = req.params.Project_id
|
||||||
inviteId = req.params.invite_id
|
inviteId = req.params.invite_id
|
||||||
logger.log {projectId, inviteId}, "resending invite"
|
logger.log {projectId, inviteId}, "resending invite"
|
||||||
AuthenticationController.getLoggedInUser req, (err, sendingUser) ->
|
sendingUser = AuthenticationController.getSessionUser(req)
|
||||||
return callback(err) if err?
|
CollaboratorsInviteHandler.resendInvite projectId, sendingUser, inviteId, (err) ->
|
||||||
CollaboratorsInviteHandler.resendInvite projectId, sendingUser, inviteId, (err) ->
|
if err?
|
||||||
if err?
|
logger.err {projectId, inviteId}, "error resending invite"
|
||||||
logger.err {projectId, inviteId}, "error resending invite"
|
return next(err)
|
||||||
return next(err)
|
res.sendStatus(201)
|
||||||
res.sendStatus(201)
|
|
||||||
|
|
||||||
viewInvite: (req, res, next) ->
|
viewInvite: (req, res, next) ->
|
||||||
projectId = req.params.Project_id
|
projectId = req.params.Project_id
|
||||||
|
@ -76,54 +74,52 @@ module.exports = CollaboratorsInviteController =
|
||||||
logger.log {projectId, token}, "invite not valid, rendering not-valid page"
|
logger.log {projectId, token}, "invite not valid, rendering not-valid page"
|
||||||
res.render "project/invite/not-valid", {title: "Invalid Invite"}
|
res.render "project/invite/not-valid", {title: "Invalid Invite"}
|
||||||
# check if the user is already a member of the project
|
# check if the user is already a member of the project
|
||||||
AuthenticationController.getLoggedInUser req, (err, currentUser) ->
|
currentUser = AuthenticationController.getSessionUser(req)
|
||||||
return callback(err) if err?
|
CollaboratorsHandler.isUserMemberOfProject currentUser._id, projectId, (err, isMember, _privilegeLevel) ->
|
||||||
CollaboratorsHandler.isUserMemberOfProject currentUser._id, projectId, (err, isMember, _privilegeLevel) ->
|
if err?
|
||||||
|
logger.err {err, projectId}, "error checking if user is member of project"
|
||||||
|
return next(err)
|
||||||
|
if isMember
|
||||||
|
logger.log {projectId, userId: currentUser._id}, "user is already a member of this project, redirecting"
|
||||||
|
return res.redirect "/project/#{projectId}"
|
||||||
|
# get the invite
|
||||||
|
CollaboratorsInviteHandler.getInviteByToken projectId, token, (err, invite) ->
|
||||||
if err?
|
if err?
|
||||||
logger.err {err, projectId}, "error checking if user is member of project"
|
logger.err {projectId, token}, "error getting invite by token"
|
||||||
return next(err)
|
return next(err)
|
||||||
if isMember
|
# check if invite is gone, or otherwise non-existent
|
||||||
logger.log {projectId, userId: currentUser._id}, "user is already a member of this project, redirecting"
|
if !invite?
|
||||||
return res.redirect "/project/#{projectId}"
|
logger.log {projectId, token}, "no invite found for this token"
|
||||||
# get the invite
|
return _renderInvalidPage()
|
||||||
CollaboratorsInviteHandler.getInviteByToken projectId, token, (err, invite) ->
|
# check the user who sent the invite exists
|
||||||
|
UserGetter.getUser {_id: invite.sendingUserId}, {email: 1, first_name: 1, last_name: 1}, (err, owner) ->
|
||||||
if err?
|
if err?
|
||||||
logger.err {projectId, token}, "error getting invite by token"
|
logger.err {err, projectId}, "error getting project owner"
|
||||||
return next(err)
|
return next(err)
|
||||||
# check if invite is gone, or otherwise non-existent
|
if !owner?
|
||||||
if !invite?
|
logger.log {projectId}, "no project owner found"
|
||||||
logger.log {projectId, token}, "no invite found for this token"
|
|
||||||
return _renderInvalidPage()
|
return _renderInvalidPage()
|
||||||
# check the user who sent the invite exists
|
# fetch the project name
|
||||||
UserGetter.getUser {_id: invite.sendingUserId}, {email: 1, first_name: 1, last_name: 1}, (err, owner) ->
|
ProjectGetter.getProject projectId, {}, (err, project) ->
|
||||||
if err?
|
if err?
|
||||||
logger.err {err, projectId}, "error getting project owner"
|
logger.err {err, projectId}, "error getting project"
|
||||||
return next(err)
|
return next(err)
|
||||||
if !owner?
|
if !project?
|
||||||
logger.log {projectId}, "no project owner found"
|
logger.log {projectId}, "no project found"
|
||||||
return _renderInvalidPage()
|
return _renderInvalidPage()
|
||||||
# fetch the project name
|
# finally render the invite
|
||||||
ProjectGetter.getProject projectId, {}, (err, project) ->
|
res.render "project/invite/show", {invite, project, owner, title: "Project Invite"}
|
||||||
if err?
|
|
||||||
logger.err {err, projectId}, "error getting project"
|
|
||||||
return next(err)
|
|
||||||
if !project?
|
|
||||||
logger.log {projectId}, "no project found"
|
|
||||||
return _renderInvalidPage()
|
|
||||||
# finally render the invite
|
|
||||||
res.render "project/invite/show", {invite, project, owner, title: "Project Invite"}
|
|
||||||
|
|
||||||
acceptInvite: (req, res, next) ->
|
acceptInvite: (req, res, next) ->
|
||||||
projectId = req.params.Project_id
|
projectId = req.params.Project_id
|
||||||
inviteId = req.params.invite_id
|
inviteId = req.params.invite_id
|
||||||
{token} = req.body
|
{token} = req.body
|
||||||
AuthenticationController.getLoggedInUser req, (err, currentUser) ->
|
currentUser = AuthenticationController.getSessionUser(req)
|
||||||
return callback(err) if err?
|
logger.log {projectId, inviteId, userId: currentUser._id}, "accepting invite"
|
||||||
logger.log {projectId, inviteId, userId: currentUser._id}, "accepting invite"
|
CollaboratorsInviteHandler.acceptInvite projectId, inviteId, token, currentUser, (err) ->
|
||||||
CollaboratorsInviteHandler.acceptInvite projectId, inviteId, token, currentUser, (err) ->
|
if err?
|
||||||
if err?
|
logger.err {projectId, inviteId}, "error accepting invite by token"
|
||||||
logger.err {projectId, inviteId}, "error accepting invite by token"
|
return next(err)
|
||||||
return next(err)
|
EditorRealTimeController.emitToRoom projectId, 'project:membership:changed', {invites: true, members: true}
|
||||||
EditorRealTimeController.emitToRoom projectId, 'project:membership:changed', {invites: true, members: true}
|
AnalyticsManger.recordEvent(currentUser._id, "project-invite-accept", {inviteId:inviteId, projectId:projectId})
|
||||||
AnalyticsManger.recordEvent(currentUser._id, "project-invite-accept", {inviteId:inviteId, projectId:projectId})
|
res.redirect "/project/#{projectId}"
|
||||||
res.redirect "/project/#{projectId}"
|
|
||||||
|
|
|
@ -91,13 +91,12 @@ module.exports = ProjectController =
|
||||||
logger.log project_id:project_id, projectName:projectName, "cloning project"
|
logger.log project_id:project_id, projectName:projectName, "cloning project"
|
||||||
if !AuthenticationController.isUserLoggedIn()?
|
if !AuthenticationController.isUserLoggedIn()?
|
||||||
return res.send redir:"/register"
|
return res.send redir:"/register"
|
||||||
AuthenticationController.getLoggedInUser req, (err, currentUser) ->
|
currentUser = AuthenticationController.getSessionUser(req)
|
||||||
return next(err) if err?
|
projectDuplicator.duplicate currentUser, project_id, projectName, (err, project)->
|
||||||
projectDuplicator.duplicate currentUser, project_id, projectName, (err, project)->
|
if err?
|
||||||
if err?
|
logger.error err:err, project_id: project_id, user_id: currentUser._id, "error cloning project"
|
||||||
logger.error err:err, project_id: project_id, user_id: currentUser._id, "error cloning project"
|
return next(err)
|
||||||
return next(err)
|
res.send(project_id:project._id)
|
||||||
res.send(project_id:project._id)
|
|
||||||
|
|
||||||
|
|
||||||
newProject: (req, res)->
|
newProject: (req, res)->
|
||||||
|
@ -135,52 +134,51 @@ module.exports = ProjectController =
|
||||||
projectListPage: (req, res, next)->
|
projectListPage: (req, res, next)->
|
||||||
timer = new metrics.Timer("project-list")
|
timer = new metrics.Timer("project-list")
|
||||||
user_id = AuthenticationController.getLoggedInUserId(req)
|
user_id = AuthenticationController.getLoggedInUserId(req)
|
||||||
AuthenticationController.getLoggedInUser req, (err, currentUser) ->
|
currentUser = AuthenticationController.getSessionUser(req)
|
||||||
return next(err) if err?
|
async.parallel {
|
||||||
async.parallel {
|
tags: (cb)->
|
||||||
tags: (cb)->
|
TagsHandler.getAllTags user_id, cb
|
||||||
TagsHandler.getAllTags user_id, cb
|
notifications: (cb)->
|
||||||
notifications: (cb)->
|
NotificationsHandler.getUserNotifications user_id, cb
|
||||||
NotificationsHandler.getUserNotifications user_id, cb
|
projects: (cb)->
|
||||||
projects: (cb)->
|
ProjectGetter.findAllUsersProjects user_id, 'name lastUpdated publicAccesLevel archived owner_ref', cb
|
||||||
ProjectGetter.findAllUsersProjects user_id, 'name lastUpdated publicAccesLevel archived owner_ref', cb
|
hasSubscription: (cb)->
|
||||||
hasSubscription: (cb)->
|
LimitationsManager.userHasSubscriptionOrIsGroupMember currentUser, cb
|
||||||
LimitationsManager.userHasSubscriptionOrIsGroupMember currentUser, cb
|
user: (cb) ->
|
||||||
user: (cb) ->
|
User.findById user_id, "featureSwitches", cb
|
||||||
User.findById user_id, "featureSwitches", cb
|
}, (err, results)->
|
||||||
}, (err, results)->
|
if err?
|
||||||
if err?
|
logger.err err:err, "error getting data for project list page"
|
||||||
logger.err err:err, "error getting data for project list page"
|
return next(err)
|
||||||
return next(err)
|
logger.log results:results, user_id:user_id, "rendering project list"
|
||||||
logger.log results:results, user_id:user_id, "rendering project list"
|
tags = results.tags[0]
|
||||||
tags = results.tags[0]
|
notifications = require("underscore").map results.notifications, (notification)->
|
||||||
notifications = require("underscore").map results.notifications, (notification)->
|
notification.html = req.i18n.translate(notification.templateKey, notification.messageOpts)
|
||||||
notification.html = req.i18n.translate(notification.templateKey, notification.messageOpts)
|
return notification
|
||||||
return notification
|
projects = ProjectController._buildProjectList results.projects[0], results.projects[1], results.projects[2]
|
||||||
projects = ProjectController._buildProjectList results.projects[0], results.projects[1], results.projects[2]
|
user = results.user
|
||||||
user = results.user
|
ProjectController._injectProjectOwners projects, (error, projects) ->
|
||||||
ProjectController._injectProjectOwners projects, (error, projects) ->
|
return next(error) if error?
|
||||||
return next(error) if error?
|
|
||||||
|
|
||||||
viewModel = {
|
viewModel = {
|
||||||
title:'your_projects'
|
title:'your_projects'
|
||||||
priority_title: true
|
priority_title: true
|
||||||
projects: projects
|
projects: projects
|
||||||
tags: tags
|
tags: tags
|
||||||
notifications: notifications or []
|
notifications: notifications or []
|
||||||
user: user
|
user: user
|
||||||
hasSubscription: results.hasSubscription[0]
|
hasSubscription: results.hasSubscription[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
if Settings?.algolia?.app_id? and Settings?.algolia?.read_only_api_key?
|
if Settings?.algolia?.app_id? and Settings?.algolia?.read_only_api_key?
|
||||||
viewModel.showUserDetailsArea = true
|
viewModel.showUserDetailsArea = true
|
||||||
viewModel.algolia_api_key = Settings.algolia.read_only_api_key
|
viewModel.algolia_api_key = Settings.algolia.read_only_api_key
|
||||||
viewModel.algolia_app_id = Settings.algolia.app_id
|
viewModel.algolia_app_id = Settings.algolia.app_id
|
||||||
else
|
else
|
||||||
viewModel.showUserDetailsArea = false
|
viewModel.showUserDetailsArea = false
|
||||||
|
|
||||||
res.render 'project/list', viewModel
|
res.render 'project/list', viewModel
|
||||||
timer.done()
|
timer.done()
|
||||||
|
|
||||||
|
|
||||||
loadEditor: (req, res, next)->
|
loadEditor: (req, res, next)->
|
||||||
|
|
|
@ -4,9 +4,8 @@ AuthenticationController = require('../Authentication/AuthenticationController')
|
||||||
module.exports = RefererMiddleware =
|
module.exports = RefererMiddleware =
|
||||||
getUserReferalId: (req, res, next) ->
|
getUserReferalId: (req, res, next) ->
|
||||||
if AuthenticationController.isUserLoggedIn()?
|
if AuthenticationController.isUserLoggedIn()?
|
||||||
AuthenticationController.getLoggedInUser req, (error, user) ->
|
user = AuthenticationController.getSessionUser(req)
|
||||||
return next(error) if error?
|
req.user.referal_id = user.referal_id
|
||||||
req.user.referal_id = user.referal_id
|
next()
|
||||||
next()
|
|
||||||
else
|
else
|
||||||
next()
|
next()
|
||||||
|
|
|
@ -32,168 +32,159 @@ module.exports = SubscriptionController =
|
||||||
|
|
||||||
#get to show the recurly.js page
|
#get to show the recurly.js page
|
||||||
paymentPage: (req, res, next) ->
|
paymentPage: (req, res, next) ->
|
||||||
AuthenticationController.getLoggedInUser req, (error, user) =>
|
user = AuthenticationController.getSessionUser(req)
|
||||||
return next(error) if error?
|
plan = PlansLocator.findLocalPlanInSettings(req.query.planCode)
|
||||||
plan = PlansLocator.findLocalPlanInSettings(req.query.planCode)
|
LimitationsManager.userHasSubscription user, (err, hasSubscription)->
|
||||||
LimitationsManager.userHasSubscription user, (err, hasSubscription)->
|
return next(err) if err?
|
||||||
return next(err) if err?
|
if hasSubscription or !plan?
|
||||||
if hasSubscription or !plan?
|
res.redirect "/user/subscription"
|
||||||
res.redirect "/user/subscription"
|
else
|
||||||
else
|
currency = req.query.currency?.toUpperCase()
|
||||||
currency = req.query.currency?.toUpperCase()
|
GeoIpLookup.getCurrencyCode req.query?.ip || req.ip, (err, recomendedCurrency, countryCode)->
|
||||||
GeoIpLookup.getCurrencyCode req.query?.ip || req.ip, (err, recomendedCurrency, countryCode)->
|
return next(err) if err?
|
||||||
return next(err) if err?
|
if recomendedCurrency? and !currency?
|
||||||
if recomendedCurrency? and !currency?
|
currency = recomendedCurrency
|
||||||
currency = recomendedCurrency
|
RecurlyWrapper.sign {
|
||||||
RecurlyWrapper.sign {
|
subscription:
|
||||||
subscription:
|
plan_code : req.query.planCode
|
||||||
plan_code : req.query.planCode
|
currency: currency
|
||||||
|
account_code: user._id
|
||||||
|
}, (error, signature) ->
|
||||||
|
return next(error) if error?
|
||||||
|
res.render "subscriptions/new",
|
||||||
|
title : "subscribe"
|
||||||
|
plan_code: req.query.planCode
|
||||||
|
currency: currency
|
||||||
|
countryCode:countryCode
|
||||||
|
plan:plan
|
||||||
|
showStudentPlan: req.query.ssp
|
||||||
|
recurlyConfig: JSON.stringify
|
||||||
currency: currency
|
currency: currency
|
||||||
account_code: user._id
|
subdomain: Settings.apis.recurly.subdomain
|
||||||
}, (error, signature) ->
|
showCouponField: req.query.scf
|
||||||
return next(error) if error?
|
showVatField: req.query.svf
|
||||||
res.render "subscriptions/new",
|
couponCode: req.query.cc or ""
|
||||||
title : "subscribe"
|
|
||||||
plan_code: req.query.planCode
|
|
||||||
currency: currency
|
|
||||||
countryCode:countryCode
|
|
||||||
plan:plan
|
|
||||||
showStudentPlan: req.query.ssp
|
|
||||||
recurlyConfig: JSON.stringify
|
|
||||||
currency: currency
|
|
||||||
subdomain: Settings.apis.recurly.subdomain
|
|
||||||
showCouponField: req.query.scf
|
|
||||||
showVatField: req.query.svf
|
|
||||||
couponCode: req.query.cc or ""
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
userSubscriptionPage: (req, res, next) ->
|
userSubscriptionPage: (req, res, next) ->
|
||||||
AuthenticationController.getLoggedInUser req, (error, user) =>
|
user = AuthenticationController.getSessionUser(req)
|
||||||
return next(error) if error?
|
LimitationsManager.userHasSubscriptionOrIsGroupMember user, (err, hasSubOrIsGroupMember, subscription)->
|
||||||
LimitationsManager.userHasSubscriptionOrIsGroupMember user, (err, hasSubOrIsGroupMember, subscription)->
|
return next(err) if err?
|
||||||
return next(err) if err?
|
groupLicenceInviteUrl = SubscriptionDomainHandler.getDomainLicencePage(user)
|
||||||
groupLicenceInviteUrl = SubscriptionDomainHandler.getDomainLicencePage(user)
|
if subscription?.customAccount
|
||||||
if subscription?.customAccount
|
logger.log user: user, "redirecting to custom account page"
|
||||||
logger.log user: user, "redirecting to custom account page"
|
res.redirect "/user/subscription/custom_account"
|
||||||
res.redirect "/user/subscription/custom_account"
|
else if groupLicenceInviteUrl? and !hasSubOrIsGroupMember
|
||||||
else if groupLicenceInviteUrl? and !hasSubOrIsGroupMember
|
logger.log user:user, "redirecting to group subscription invite page"
|
||||||
logger.log user:user, "redirecting to group subscription invite page"
|
res.redirect groupLicenceInviteUrl
|
||||||
res.redirect groupLicenceInviteUrl
|
else if !hasSubOrIsGroupMember
|
||||||
else if !hasSubOrIsGroupMember
|
logger.log user: user, "redirecting to plans"
|
||||||
logger.log user: user, "redirecting to plans"
|
res.redirect "/user/subscription/plans"
|
||||||
res.redirect "/user/subscription/plans"
|
else
|
||||||
else
|
SubscriptionViewModelBuilder.buildUsersSubscriptionViewModel user, (error, subscription, groupSubscriptions) ->
|
||||||
SubscriptionViewModelBuilder.buildUsersSubscriptionViewModel user, (error, subscription, groupSubscriptions) ->
|
return next(error) if error?
|
||||||
return next(error) if error?
|
logger.log user: user, subscription:subscription, hasSubOrIsGroupMember:hasSubOrIsGroupMember, groupSubscriptions:groupSubscriptions, "showing subscription dashboard"
|
||||||
logger.log user: user, subscription:subscription, hasSubOrIsGroupMember:hasSubOrIsGroupMember, groupSubscriptions:groupSubscriptions, "showing subscription dashboard"
|
plans = SubscriptionViewModelBuilder.buildViewModel()
|
||||||
plans = SubscriptionViewModelBuilder.buildViewModel()
|
res.render "subscriptions/dashboard",
|
||||||
res.render "subscriptions/dashboard",
|
title: "your_subscription"
|
||||||
title: "your_subscription"
|
recomendedCurrency: subscription?.currency
|
||||||
recomendedCurrency: subscription?.currency
|
taxRate:subscription?.taxRate
|
||||||
taxRate:subscription?.taxRate
|
plans: plans
|
||||||
plans: plans
|
subscription: subscription || {}
|
||||||
subscription: subscription || {}
|
groupSubscriptions: groupSubscriptions
|
||||||
groupSubscriptions: groupSubscriptions
|
subscriptionTabActive: true
|
||||||
subscriptionTabActive: true
|
user:user
|
||||||
user:user
|
saved_billing_details: req.query.saved_billing_details?
|
||||||
saved_billing_details: req.query.saved_billing_details?
|
|
||||||
|
|
||||||
userCustomSubscriptionPage: (req, res, next)->
|
userCustomSubscriptionPage: (req, res, next)->
|
||||||
AuthenticationController.getLoggedInUser req, (error, user) ->
|
user = AuthenticationController.getSessionUser(req)
|
||||||
return next(error) if error?
|
LimitationsManager.userHasSubscriptionOrIsGroupMember user, (err, hasSubOrIsGroupMember, subscription)->
|
||||||
LimitationsManager.userHasSubscriptionOrIsGroupMember user, (err, hasSubOrIsGroupMember, subscription)->
|
return next(err) if err?
|
||||||
return next(err) if err?
|
if !subscription?
|
||||||
if !subscription?
|
err = new Error("subscription null for custom account, user:#{user?._id}")
|
||||||
err = new Error("subscription null for custom account, user:#{user?._id}")
|
logger.warn err:err, "subscription is null for custom accounts page"
|
||||||
logger.warn err:err, "subscription is null for custom accounts page"
|
return next(err)
|
||||||
return next(err)
|
res.render "subscriptions/custom_account",
|
||||||
res.render "subscriptions/custom_account",
|
title: "your_subscription"
|
||||||
title: "your_subscription"
|
subscription: subscription
|
||||||
subscription: subscription
|
|
||||||
|
|
||||||
|
|
||||||
editBillingDetailsPage: (req, res, next) ->
|
editBillingDetailsPage: (req, res, next) ->
|
||||||
AuthenticationController.getLoggedInUser req, (error, user) ->
|
user = AuthenticationController.getSessionUser(req)
|
||||||
return next(error) if error?
|
LimitationsManager.userHasSubscription user, (err, hasSubscription)->
|
||||||
LimitationsManager.userHasSubscription user, (err, hasSubscription)->
|
return next(err) if err?
|
||||||
return next(err) if err?
|
if !hasSubscription
|
||||||
if !hasSubscription
|
res.redirect "/user/subscription"
|
||||||
res.redirect "/user/subscription"
|
else
|
||||||
else
|
RecurlyWrapper.sign {
|
||||||
RecurlyWrapper.sign {
|
account_code: user._id
|
||||||
account_code: user._id
|
}, (error, signature) ->
|
||||||
}, (error, signature) ->
|
return next(error) if error?
|
||||||
return next(error) if error?
|
res.render "subscriptions/edit-billing-details",
|
||||||
res.render "subscriptions/edit-billing-details",
|
title : "update_billing_details"
|
||||||
title : "update_billing_details"
|
recurlyConfig: JSON.stringify
|
||||||
recurlyConfig: JSON.stringify
|
currency: "USD"
|
||||||
currency: "USD"
|
subdomain: Settings.apis.recurly.subdomain
|
||||||
subdomain: Settings.apis.recurly.subdomain
|
signature : signature
|
||||||
signature : signature
|
successURL : "#{Settings.siteUrl}/user/subscription/billing-details/update"
|
||||||
successURL : "#{Settings.siteUrl}/user/subscription/billing-details/update"
|
user :
|
||||||
user :
|
id : user._id
|
||||||
id : user._id
|
|
||||||
|
|
||||||
updateBillingDetails: (req, res, next) ->
|
updateBillingDetails: (req, res, next) ->
|
||||||
res.redirect "/user/subscription?saved_billing_details=true"
|
res.redirect "/user/subscription?saved_billing_details=true"
|
||||||
|
|
||||||
createSubscription: (req, res, next)->
|
createSubscription: (req, res, next)->
|
||||||
AuthenticationController.getLoggedInUser req, (error, user) ->
|
user = AuthenticationController.getSessionUser(req)
|
||||||
return callback(error) if error?
|
recurly_token_id = req.body.recurly_token_id
|
||||||
recurly_token_id = req.body.recurly_token_id
|
subscriptionDetails = req.body.subscriptionDetails
|
||||||
subscriptionDetails = req.body.subscriptionDetails
|
logger.log recurly_token_id: recurly_token_id, user_id:user._id, subscriptionDetails:subscriptionDetails, "creating subscription"
|
||||||
logger.log recurly_token_id: recurly_token_id, user_id:user._id, subscriptionDetails:subscriptionDetails, "creating subscription"
|
SubscriptionHandler.createSubscription user, subscriptionDetails, recurly_token_id, (err)->
|
||||||
SubscriptionHandler.createSubscription user, subscriptionDetails, recurly_token_id, (err)->
|
if err?
|
||||||
if err?
|
logger.err err:err, user_id:user._id, "something went wrong creating subscription"
|
||||||
logger.err err:err, user_id:user._id, "something went wrong creating subscription"
|
return res.sendStatus 500
|
||||||
return res.sendStatus 500
|
res.sendStatus 201
|
||||||
res.sendStatus 201
|
|
||||||
|
|
||||||
successful_subscription: (req, res, next)->
|
successful_subscription: (req, res, next)->
|
||||||
AuthenticationController.getLoggedInUser req, (error, user) =>
|
user = AuthenticationController.getSessionUser(req)
|
||||||
|
SubscriptionViewModelBuilder.buildUsersSubscriptionViewModel user, (error, subscription) ->
|
||||||
return next(error) if error?
|
return next(error) if error?
|
||||||
SubscriptionViewModelBuilder.buildUsersSubscriptionViewModel user, (error, subscription) ->
|
res.render "subscriptions/successful_subscription",
|
||||||
return next(error) if error?
|
title: "thank_you"
|
||||||
res.render "subscriptions/successful_subscription",
|
subscription:subscription
|
||||||
title: "thank_you"
|
|
||||||
subscription:subscription
|
|
||||||
|
|
||||||
cancelSubscription: (req, res, next) ->
|
cancelSubscription: (req, res, next) ->
|
||||||
AuthenticationController.getLoggedInUser req, (error, user) ->
|
user = AuthenticationController.getSessionUser(req)
|
||||||
return next(error) if error?
|
logger.log user_id:user._id, "canceling subscription"
|
||||||
logger.log user_id:user._id, "canceling subscription"
|
SubscriptionHandler.cancelSubscription user, (err)->
|
||||||
SubscriptionHandler.cancelSubscription user, (err)->
|
if err?
|
||||||
if err?
|
logger.err err:err, user_id:user._id, "something went wrong canceling subscription"
|
||||||
logger.err err:err, user_id:user._id, "something went wrong canceling subscription"
|
return next(err)
|
||||||
return next(err)
|
res.redirect "/user/subscription"
|
||||||
res.redirect "/user/subscription"
|
|
||||||
|
|
||||||
updateSubscription: (req, res, next)->
|
updateSubscription: (req, res, next)->
|
||||||
_origin = req?.query?.origin || null
|
_origin = req?.query?.origin || null
|
||||||
AuthenticationController.getLoggedInUser req, (error, user) ->
|
user = AuthenticationController.getSessionUser(req)
|
||||||
return next(error) if error?
|
planCode = req.body.plan_code
|
||||||
planCode = req.body.plan_code
|
if !planCode?
|
||||||
if !planCode?
|
err = new Error('plan_code is not defined')
|
||||||
err = new Error('plan_code is not defined')
|
logger.err {user_id: user._id, err, planCode, origin: _origin, body: req.body}, "[Subscription] error in updateSubscription form"
|
||||||
logger.err {user_id: user._id, err, planCode, origin: _origin, body: req.body}, "[Subscription] error in updateSubscription form"
|
return next(err)
|
||||||
|
logger.log planCode: planCode, user_id:user._id, "updating subscription"
|
||||||
|
SubscriptionHandler.updateSubscription user, planCode, null, (err)->
|
||||||
|
if err?
|
||||||
|
logger.err err:err, user_id:user._id, "something went wrong updating subscription"
|
||||||
return next(err)
|
return next(err)
|
||||||
logger.log planCode: planCode, user_id:user._id, "updating subscription"
|
res.redirect "/user/subscription"
|
||||||
SubscriptionHandler.updateSubscription user, planCode, null, (err)->
|
|
||||||
if err?
|
|
||||||
logger.err err:err, user_id:user._id, "something went wrong updating subscription"
|
|
||||||
return next(err)
|
|
||||||
res.redirect "/user/subscription"
|
|
||||||
|
|
||||||
reactivateSubscription: (req, res, next)->
|
reactivateSubscription: (req, res, next)->
|
||||||
AuthenticationController.getLoggedInUser req, (error, user) ->
|
user = AuthenticationController.getSessionUser(req)
|
||||||
return next(error) if error?
|
logger.log user_id:user._id, "reactivating subscription"
|
||||||
logger.log user_id:user._id, "reactivating subscription"
|
SubscriptionHandler.reactivateSubscription user, (err)->
|
||||||
SubscriptionHandler.reactivateSubscription user, (err)->
|
if err?
|
||||||
if err?
|
logger.err err:err, user_id:user._id, "something went wrong reactivating subscription"
|
||||||
logger.err err:err, user_id:user._id, "something went wrong reactivating subscription"
|
return next(err)
|
||||||
return next(err)
|
res.redirect "/user/subscription"
|
||||||
res.redirect "/user/subscription"
|
|
||||||
|
|
||||||
recurlyCallback: (req, res, next)->
|
recurlyCallback: (req, res, next)->
|
||||||
logger.log data: req.body, "received recurly callback"
|
logger.log data: req.body, "received recurly callback"
|
||||||
|
@ -207,47 +198,44 @@ module.exports = SubscriptionController =
|
||||||
res.sendStatus 200
|
res.sendStatus 200
|
||||||
|
|
||||||
renderUpgradeToAnnualPlanPage: (req, res, next)->
|
renderUpgradeToAnnualPlanPage: (req, res, next)->
|
||||||
AuthenticationController.getLoggedInUser req, (error, user) ->
|
user = AuthenticationController.getSessionUser(req)
|
||||||
return next(error) if error?
|
LimitationsManager.userHasSubscription user, (err, hasSubscription, subscription)->
|
||||||
LimitationsManager.userHasSubscription user, (err, hasSubscription, subscription)->
|
return next(err) if err?
|
||||||
return next(err) if err?
|
planCode = subscription?.planCode.toLowerCase()
|
||||||
planCode = subscription?.planCode.toLowerCase()
|
if planCode?.indexOf("annual") != -1
|
||||||
if planCode?.indexOf("annual") != -1
|
planName = "annual"
|
||||||
planName = "annual"
|
else if planCode?.indexOf("student") != -1
|
||||||
else if planCode?.indexOf("student") != -1
|
planName = "student"
|
||||||
planName = "student"
|
else if planCode?.indexOf("collaborator") != -1
|
||||||
else if planCode?.indexOf("collaborator") != -1
|
planName = "collaborator"
|
||||||
planName = "collaborator"
|
if !hasSubscription
|
||||||
if !hasSubscription
|
return res.redirect("/user/subscription/plans")
|
||||||
return res.redirect("/user/subscription/plans")
|
logger.log planName:planName, user_id:user._id, "rendering upgrade to annual page"
|
||||||
logger.log planName:planName, user_id:user._id, "rendering upgrade to annual page"
|
res.render "subscriptions/upgradeToAnnual",
|
||||||
res.render "subscriptions/upgradeToAnnual",
|
title: "Upgrade to annual"
|
||||||
title: "Upgrade to annual"
|
planName: planName
|
||||||
planName: planName
|
|
||||||
|
|
||||||
processUpgradeToAnnualPlan: (req, res, next)->
|
processUpgradeToAnnualPlan: (req, res, next)->
|
||||||
AuthenticationController.getLoggedInUser req, (error, user) ->
|
user = AuthenticationController.getSessionUser(req)
|
||||||
return next(error) if error?
|
{planName} = req.body
|
||||||
{planName} = req.body
|
coupon_code = Settings.coupon_codes.upgradeToAnnualPromo[planName]
|
||||||
coupon_code = Settings.coupon_codes.upgradeToAnnualPromo[planName]
|
annualPlanName = "#{planName}-annual"
|
||||||
annualPlanName = "#{planName}-annual"
|
logger.log user_id:user._id, planName:annualPlanName, "user is upgrading to annual billing with discount"
|
||||||
logger.log user_id:user._id, planName:annualPlanName, "user is upgrading to annual billing with discount"
|
SubscriptionHandler.updateSubscription user, annualPlanName, coupon_code, (err)->
|
||||||
SubscriptionHandler.updateSubscription user, annualPlanName, coupon_code, (err)->
|
if err?
|
||||||
if err?
|
logger.err err:err, user_id:user._id, "error updating subscription"
|
||||||
logger.err err:err, user_id:user._id, "error updating subscription"
|
return next(err)
|
||||||
return next(err)
|
res.sendStatus 200
|
||||||
res.sendStatus 200
|
|
||||||
|
|
||||||
extendTrial: (req, res, next)->
|
extendTrial: (req, res, next)->
|
||||||
AuthenticationController.getLoggedInUser req, (error, user) ->
|
user = AuthenticationController.getSessionUser(req)
|
||||||
return next(error) if error?
|
LimitationsManager.userHasSubscription user, (err, hasSubscription, subscription)->
|
||||||
LimitationsManager.userHasSubscription user, (err, hasSubscription, subscription)->
|
return next(err) if err?
|
||||||
return next(err) if err?
|
SubscriptionHandler.extendTrial subscription, 14, (err)->
|
||||||
SubscriptionHandler.extendTrial subscription, 14, (err)->
|
if err?
|
||||||
if err?
|
res.send 500
|
||||||
res.send 500
|
else
|
||||||
else
|
res.send 200
|
||||||
res.send 200
|
|
||||||
|
|
||||||
recurlyNotificationParser: (req, res, next) ->
|
recurlyNotificationParser: (req, res, next) ->
|
||||||
xml = ""
|
xml = ""
|
||||||
|
|
|
@ -78,18 +78,18 @@ module.exports =
|
||||||
|
|
||||||
beginJoinGroup: (req, res)->
|
beginJoinGroup: (req, res)->
|
||||||
subscription_id = req.params.subscription_id
|
subscription_id = req.params.subscription_id
|
||||||
AuthenticationController.getLoggedInUser req, (err, currentUser) ->
|
currentUser = AuthenticationController.getSessionUser(req)
|
||||||
|
if !currentUser?
|
||||||
|
logger.err {subscription_id}, "error getting current user"
|
||||||
|
return res.sendStatus 500
|
||||||
|
licence = SubscriptionDomainHandler.findDomainLicenceBySubscriptionId(subscription_id)
|
||||||
|
if !licence?
|
||||||
|
return ErrorsController.notFound(req, res)
|
||||||
|
SubscriptionGroupHandler.sendVerificationEmail subscription_id, licence.name, currentUser.email, (err)->
|
||||||
if err?
|
if err?
|
||||||
logger.err {subscription_id}, "error getting current user"
|
res.sendStatus 500
|
||||||
return res.sendStatus 500
|
else
|
||||||
licence = SubscriptionDomainHandler.findDomainLicenceBySubscriptionId(subscription_id)
|
res.sendStatus 200
|
||||||
if !licence?
|
|
||||||
return ErrorsController.notFound(req, res)
|
|
||||||
SubscriptionGroupHandler.sendVerificationEmail subscription_id, licence.name, currentUser.email, (err)->
|
|
||||||
if err?
|
|
||||||
res.sendStatus 500
|
|
||||||
else
|
|
||||||
res.sendStatus 200
|
|
||||||
|
|
||||||
completeJoin: (req, res)->
|
completeJoin: (req, res)->
|
||||||
subscription_id = req.params.subscription_id
|
subscription_id = req.params.subscription_id
|
||||||
|
|
|
@ -85,13 +85,13 @@ module.exports = UserController =
|
||||||
metrics.inc "user.logout"
|
metrics.inc "user.logout"
|
||||||
logger.log user: req?.session?.user, "logging out"
|
logger.log user: req?.session?.user, "logging out"
|
||||||
sessionId = req.sessionID
|
sessionId = req.sessionID
|
||||||
AuthenticationController.getLoggedInUser req, (err, user) ->
|
user = AuthenticationController.getSessionUser(req)
|
||||||
req.logout?() # passport logout
|
req.logout?() # passport logout
|
||||||
req.session.destroy (err)->
|
req.session.destroy (err)->
|
||||||
if err
|
if err
|
||||||
logger.err err: err, 'error destorying session'
|
logger.err err: err, 'error destorying session'
|
||||||
UserSessionsManager.untrackSession(user, sessionId)
|
UserSessionsManager.untrackSession(user, sessionId)
|
||||||
res.redirect '/login'
|
res.redirect '/login'
|
||||||
|
|
||||||
register : (req, res, next = (error) ->)->
|
register : (req, res, next = (error) ->)->
|
||||||
email = req.body.email
|
email = req.body.email
|
||||||
|
|
Loading…
Reference in a new issue