mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Refactor front end code into validateCaptcha service
This commit is contained in:
parent
0b03bbc7c3
commit
69499847e4
6 changed files with 36 additions and 31 deletions
|
@ -53,9 +53,6 @@ html(itemscope, itemtype='http://schema.org/Product')
|
|||
- else
|
||||
script(type='text/javascript').
|
||||
window.ga = function() { console.log("would send to GA", arguments) };
|
||||
|
||||
- if (settings.recaptcha)
|
||||
script(src="https://www.google.com/recaptcha/api.js")
|
||||
|
||||
script(type="text/javascript").
|
||||
window.csrfToken = "#{csrfToken}";
|
||||
|
@ -100,6 +97,15 @@ html(itemscope, itemtype='http://schema.org/Product')
|
|||
}
|
||||
|
||||
body
|
||||
if(settings.recaptcha)
|
||||
script(src="https://www.google.com/recaptcha/api.js?render=explicit")
|
||||
div(
|
||||
id="recaptcha"
|
||||
class="g-recaptcha"
|
||||
data-sitekey=settings.recaptcha.siteKey
|
||||
data-size="invisible"
|
||||
data-badge="inline"
|
||||
)
|
||||
|
||||
- if(typeof(suppressSystemMessages) == "undefined")
|
||||
.system-messages(
|
||||
|
|
|
@ -102,14 +102,6 @@ script(type='text/ng-template', id='shareProjectModalTemplate')
|
|||
i.fa.fa-times
|
||||
.row.invite-controls
|
||||
form(ng-show="canAddCollaborators")
|
||||
- if (settings.recaptcha)
|
||||
div(
|
||||
id="recaptcha"
|
||||
class="g-recaptcha"
|
||||
data-sitekey=settings.recaptcha.siteKey
|
||||
data-size="invisible"
|
||||
data-badge="inline"
|
||||
)
|
||||
.small #{translate("share_with_your_collabs")}
|
||||
.form-group
|
||||
tags-input(
|
||||
|
|
|
@ -33,6 +33,7 @@ define [
|
|||
"directives/expandableTextArea"
|
||||
"directives/videoPlayState"
|
||||
"services/queued-http"
|
||||
"services/validateCaptcha"
|
||||
"filters/formatDate"
|
||||
"main/event"
|
||||
"main/account-upgrade"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
define [
|
||||
"base"
|
||||
], (App) ->
|
||||
App.controller "ShareProjectModalController", ($scope, $modalInstance, $timeout, projectMembers, projectInvites, $modal, $http, ide) ->
|
||||
App.controller "ShareProjectModalController", ($scope, $modalInstance, $timeout, projectMembers, projectInvites, $modal, $http, ide, validateCaptcha) ->
|
||||
$scope.inputs = {
|
||||
privileges: "readAndWrite"
|
||||
contacts: []
|
||||
|
@ -55,25 +55,6 @@ define [
|
|||
getCurrentInviteEmails = () ->
|
||||
($scope.project.invites || []).map (u) -> u.email
|
||||
|
||||
_recaptchaCallbacks = []
|
||||
onRecaptchaSubmit = (token) ->
|
||||
for cb in _recaptchaCallbacks
|
||||
cb(token)
|
||||
_recaptchaCallbacks = []
|
||||
|
||||
recaptchaId = null
|
||||
validateCaptcha = (callback = (response) ->) =>
|
||||
if !grecaptcha?
|
||||
return callback()
|
||||
reset = () ->
|
||||
grecaptcha.reset()
|
||||
_recaptchaCallbacks.push callback
|
||||
_recaptchaCallbacks.push reset
|
||||
if !recaptchaId?
|
||||
el = $('.g-recaptcha')[0]
|
||||
recaptchaId = grecaptcha.render(el, {callback: onRecaptchaSubmit})
|
||||
grecaptcha.execute(recaptchaId)
|
||||
|
||||
$scope.filterAutocompleteUsers = ($query) ->
|
||||
currentMemberEmails = getCurrentMemberEmails()
|
||||
return $scope.autocompleteContacts.filter (contact) ->
|
||||
|
|
|
@ -30,6 +30,7 @@ define [
|
|||
"directives/maxHeight"
|
||||
"directives/creditCards"
|
||||
"services/queued-http"
|
||||
"services/validateCaptcha"
|
||||
"filters/formatDate"
|
||||
"__MAIN_CLIENTSIDE_INCLUDES__"
|
||||
], () ->
|
||||
|
|
24
services/web/public/coffee/services/validateCaptcha.coffee
Normal file
24
services/web/public/coffee/services/validateCaptcha.coffee
Normal file
|
@ -0,0 +1,24 @@
|
|||
define [
|
||||
"base"
|
||||
], (App) ->
|
||||
App.factory "validateCaptcha", () ->
|
||||
_recaptchaCallbacks = []
|
||||
onRecaptchaSubmit = (token) ->
|
||||
for cb in _recaptchaCallbacks
|
||||
cb(token)
|
||||
_recaptchaCallbacks = []
|
||||
|
||||
recaptchaId = null
|
||||
validateCaptcha = (callback = (response) ->) =>
|
||||
if !grecaptcha?
|
||||
return callback()
|
||||
reset = () ->
|
||||
grecaptcha.reset()
|
||||
_recaptchaCallbacks.push callback
|
||||
_recaptchaCallbacks.push reset
|
||||
if !recaptchaId?
|
||||
el = $('.g-recaptcha')[0]
|
||||
recaptchaId = grecaptcha.render(el, {callback: onRecaptchaSubmit})
|
||||
grecaptcha.execute(recaptchaId)
|
||||
|
||||
return validateCaptcha
|
Loading…
Reference in a new issue