mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 22:23:42 +01:00
Merge pull request #1713 from sharelatex/ns-captchas-two
turn off captchas for project invite GitOrigin-RevId: 3e044ba8c6bb2ffb77ea4486f7b51a587133839c
This commit is contained in:
@@ -3,21 +3,26 @@ logger = require 'logger-sharelatex'
|
||||
Settings = require 'settings-sharelatex'
|
||||
|
||||
module.exports = CaptchaMiddleware =
|
||||
validateCaptcha: (req, res, next) ->
|
||||
if !Settings.recaptcha?
|
||||
return next()
|
||||
response = req.body['g-recaptcha-response']
|
||||
options =
|
||||
form:
|
||||
secret: Settings.recaptcha.secretKey
|
||||
response: response
|
||||
json: true
|
||||
request.post "https://www.google.com/recaptcha/api/siteverify", options, (error, response, body) ->
|
||||
return next(error) if error?
|
||||
if !body?.success
|
||||
logger.warn {statusCode: response.statusCode, body: body}, 'failed recaptcha siteverify request'
|
||||
return res.status(400).send({errorReason:"cannot_verify_user_not_robot", message:
|
||||
{text:"Sorry, we could not verify that you are not a robot. Please check that Google reCAPTCHA is not being blocked by an ad blocker or firewall."}
|
||||
})
|
||||
else
|
||||
validateCaptcha: (action) ->
|
||||
return (req, res, next) ->
|
||||
if !Settings.recaptcha?.siteKey?
|
||||
return next()
|
||||
inviteAndCaptchaDisabled = action == 'invite' and Settings.recaptcha.disabled.invite
|
||||
registerAndCaptchaDisabled = action == 'register' and Settings.recaptcha.disabled.register
|
||||
if inviteAndCaptchaDisabled or registerAndCaptchaDisabled
|
||||
return next()
|
||||
response = req.body['g-recaptcha-response']
|
||||
options =
|
||||
form:
|
||||
secret: Settings.recaptcha.secretKey
|
||||
response: response
|
||||
json: true
|
||||
request.post "https://www.google.com/recaptcha/api/siteverify", options, (error, response, body) ->
|
||||
return next(error) if error?
|
||||
if !body?.success
|
||||
logger.warn {statusCode: response.statusCode, body: body}, 'failed recaptcha siteverify request'
|
||||
return res.status(400).send({errorReason:"cannot_verify_user_not_robot", message:
|
||||
{text:"Sorry, we could not verify that you are not a robot. Please check that Google reCAPTCHA is not being blocked by an ad blocker or firewall."}
|
||||
})
|
||||
else
|
||||
return next()
|
||||
|
||||
@@ -33,7 +33,7 @@ module.exports =
|
||||
maxRequests: 100
|
||||
timeInterval: 60 * 10
|
||||
}),
|
||||
CaptchaMiddleware.validateCaptcha,
|
||||
CaptchaMiddleware.validateCaptcha('invite'),
|
||||
AuthenticationController.requireLogin(),
|
||||
AuthorizationMiddleware.ensureUserCanAdminProject,
|
||||
CollaboratorsInviteController.inviteToProject
|
||||
|
||||
@@ -374,4 +374,5 @@ module.exports = (app, webRouter, privateApiRouter, publicApiRouter)->
|
||||
appName: Settings.appName
|
||||
siteUrl: Settings.siteUrl
|
||||
recaptchaSiteKeyV3: Settings.recaptcha?.siteKeyV3
|
||||
recaptchaDisabled: Settings.recaptcha?.disabled
|
||||
next()
|
||||
|
||||
Reference in New Issue
Block a user