Merge pull request #1427 from sharelatex/ew-recaptcha

add recaptcha validate middleware to reg and add recaptcha v3

GitOrigin-RevId: 35375b7887832b40bc570cf848cab9c62243443b
This commit is contained in:
Ersun Warncke 2019-01-21 13:09:02 -04:00 committed by sharelatex
parent a906504dac
commit ef9875c5a6
7 changed files with 34 additions and 2 deletions

View file

@ -373,4 +373,5 @@ module.exports = (app, webRouter, privateApiRouter, publicApiRouter)->
isOverleaf: Settings.overleaf?
appName: Settings.appName
siteUrl: Settings.siteUrl
recaptchaSiteKeyV3: Settings.recaptcha?.siteKeyV3
next()

View file

@ -99,7 +99,10 @@ html(
body
if(settings.recaptcha)
script(src="https://www.google.com/recaptcha/api.js?render=explicit")
if (settings.recaptcha.siteKeyV3)
script(src="https://www.google.com/recaptcha/api.js?render="+settings.recaptcha.siteKeyV3)
else
script(src="https://www.google.com/recaptcha/api.js?render=explicit")
div(
id="recaptcha"
class="g-recaptcha"

View file

@ -14,7 +14,7 @@
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
define(['base', 'libs/passfield'], function(App) {
App.directive('asyncForm', ($http, validateCaptcha) => ({
App.directive('asyncForm', ($http, validateCaptcha, validateCaptchaV3) => ({
controller: [
'$scope',
function($scope) {
@ -33,6 +33,9 @@ define(['base', 'libs/passfield'], function(App) {
if (callback == null) {
callback = function(response) {}
}
if (attrs.captchaActionName) {
validateCaptchaV3(attrs.captchaActionName)
}
if (attrs.captcha != null) {
return validateCaptcha(callback)
} else {

View file

@ -55,6 +55,7 @@ define([
'directives/videoPlayState',
'services/queued-http',
'services/validateCaptcha',
'services/validateCaptchaV3',
'services/wait-for',
'filters/formatDate',
'main/event',

View file

@ -27,6 +27,7 @@ define(['base'], App =>
$http,
ide,
validateCaptcha,
validateCaptchaV3,
settings,
event_tracking
) {
@ -160,6 +161,9 @@ define(['base'], App =>
// Skip this existing member
return addNextMember()
}
// do v3 captcha to collect data only
validateCaptchaV3('invite')
// do v2 captcha
return validateCaptcha(function(response) {
let inviteId, request
$scope.grecaptchaResponse = response

View file

@ -54,6 +54,7 @@ define([
'directives/bookmarkableTabset',
'services/queued-http',
'services/validateCaptcha',
'services/validateCaptchaV3',
'filters/formatDate',
'components/inputSuggestions',
'__MAIN_CLIENTSIDE_INCLUDES__'

View file

@ -0,0 +1,19 @@
define(['base'], function(App) {
return App.factory('validateCaptchaV3', function() {
const grecaptcha = window.grecaptcha
const ExposedSettings = window.ExposedSettings
return function validateCaptchaV3(actionName, callback = () => {}) {
if (!grecaptcha) {
return
}
if (!ExposedSettings || !ExposedSettings.recaptchaSiteKeyV3) {
return
}
grecaptcha.ready(function() {
grecaptcha
.execute(ExposedSettings.recaptchaSiteKeyV3, { action: actionName })
.then(callback)
})
}
})
})