Move AccountMergeEmailController to integration module

This commit is contained in:
Shane Kilkelly 2018-09-13 09:26:16 +01:00
parent 54a5c563fb
commit 843f1c6b35
2 changed files with 33 additions and 43 deletions

View file

@ -1,36 +1,36 @@
UserGetter = require '../User/UserGetter'
UserUpdater = require '../User/UserUpdater'
OneTimeTokenHandler = require '../Security/OneTimeTokenHandler'
logger = require 'logger-sharelatex'
Settings = require 'settings-sharelatex'
# UserGetter = require '../User/UserGetter'
# UserUpdater = require '../User/UserUpdater'
# OneTimeTokenHandler = require '../Security/OneTimeTokenHandler'
# logger = require 'logger-sharelatex'
# Settings = require 'settings-sharelatex'
module.exports = AccountMergeEmailController =
# module.exports = AccountMergeEmailController =
confirmMergeFromEmail: (req, res, next) ->
token = req.query.token
if !token
return res.status(400).send()
OneTimeTokenHandler.getValueFromTokenAndExpire 'account-merge-email-to-ol', token, (err, data) ->
return next(err) if err?
if !data
return res.status(404).send()
if data.origin != 'sl'
logger.log {}, "Only sharelatex origin supported"
return res.status(501).send()
{ sl_id, v1_id, final_email } = data
UserGetter.getUser sl_id, {_id: 1, overleaf: 1}, (err, user) ->
return next(err) if err?
if !user?
logger.err {userId: sl_id}, 'SL user not found for account-merge'
return res.status(400).send()
if user?.overleaf?.id?
logger.err {userId: sl_id}, 'SL user is already linked to overleaf'
return res.status(400).send()
logger.log {sl_id, v1_id, final_email, origin: data.origin},
"[AccountMergeEmailController] about to merge sharelatex and overleaf-v1 accounts"
UserUpdater.mergeSharelatexAndV1Accounts sl_id, v1_id, final_email, (err) ->
return next(err) if err?
res.render 'account_merge/finish', {
finalEmail: final_email
}
# confirmMergeFromEmail: (req, res, next) ->
# token = req.query.token
# if !token
# return res.status(400).send()
# OneTimeTokenHandler.getValueFromTokenAndExpire 'account-merge-email-to-ol', token, (err, data) ->
# return next(err) if err?
# if !data
# return res.status(404).send()
# if data.origin != 'sl'
# logger.log {}, "Only sharelatex origin supported"
# return res.status(501).send()
# { sl_id, v1_id, final_email } = data
# UserGetter.getUser sl_id, {_id: 1, overleaf: 1}, (err, user) ->
# return next(err) if err?
# if !user?
# logger.err {userId: sl_id}, 'SL user not found for account-merge'
# return res.status(400).send()
# if user?.overleaf?.id?
# logger.err {userId: sl_id}, 'SL user is already linked to overleaf'
# return res.status(400).send()
# logger.log {sl_id, v1_id, final_email, origin: data.origin},
# "[AccountMergeEmailController] about to merge sharelatex and overleaf-v1 accounts"
# UserUpdater.mergeSharelatexAndV1Accounts sl_id, v1_id, final_email, (err) ->
# return next(err) if err?
# res.render 'account_merge/finish', {
# finalEmail: final_email
# }

View file

@ -50,7 +50,6 @@ TokenAccessController = require('./Features/TokenAccess/TokenAccessController')
Features = require('./infrastructure/Features')
LinkedFilesRouter = require './Features/LinkedFiles/LinkedFilesRouter'
TemplatesRouter = require './Features/Templates/TemplatesRouter'
AccountMergeEmailController = require './Features/AccountMerge/AccountMergeEmailController'
logger = require("logger-sharelatex")
_ = require("underscore")
@ -344,15 +343,6 @@ module.exports = class Router
webRouter.post '/admin/messages', AuthorizationMiddlewear.ensureUserIsSiteAdmin, AdminController.createMessage
webRouter.post '/admin/messages/clear', AuthorizationMiddlewear.ensureUserIsSiteAdmin, AdminController.clearMessages
webRouter.get '/account-merge/email/confirm',
RateLimiterMiddlewear.rateLimit({
endpointName: "account-merge-email-confirm",
ipOnly: true,
maxRequests: 10
timeInterval: 60
}),
AccountMergeEmailController.confirmMergeFromEmail
privateApiRouter.get '/perfTest', (req,res)->
res.send("hello")