Просмотр исходного кода

Merge pull request #1427 from sharelatex/ew-recaptcha

add recaptcha validate middleware to reg and add recaptcha v3

GitOrigin-RevId: 35375b7887832b40bc570cf848cab9c62243443b
Ersun Warncke 7 лет назад
Родитель
Сommit
ef9875c5a6

+ 1 - 0
services/web/app/coffee/infrastructure/ExpressLocals.coffee

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

+ 4 - 1
services/web/app/views/layout.pug

@@ -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"

+ 4 - 1
services/web/public/src/directives/asyncForm.js

@@ -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 {

+ 1 - 0
services/web/public/src/ide.js

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

+ 4 - 0
services/web/public/src/ide/share/controllers/ShareProjectModalController.js

@@ -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

+ 1 - 0
services/web/public/src/main.js

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

+ 19 - 0
services/web/public/src/services/validateCaptchaV3.js

@@ -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)
+      })
+    }
+  })
+})