Skip to content

Commit

Permalink
Add support for invisible reCAPTCHAs
Browse files Browse the repository at this point in the history
  • Loading branch information
jimchamp committed Sep 1, 2023
1 parent f7388d6 commit e8b13ff
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
4 changes: 4 additions & 0 deletions conf/openlibrary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ plugin_recaptcha:
public_key: ''
private_key: ''

plugin_invisible_recaptcha:
public_key: ''
private_key: ''

plugin_inside:
search_endpoint: https://be-api.us.archive.org/fts/v1/search

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ export function initRealTimeValidation() {
$('#signup').on('click', function(e) {
e.preventDefault();
if (! (window.grecaptcha && window.grecaptcha.getResponse().length)) {
alert(ugettext('Please complete all fields and click the reCAPTCHA checkbox before proceeding.'));
return;
}
validateEmail();
Expand Down
4 changes: 2 additions & 2 deletions openlibrary/plugins/upstream/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ def get_form(self) -> forms.RegisterForm:

def get_recap(self):
if self.is_plugin_enabled('recaptcha'):
public_key = config.plugin_recaptcha.public_key
private_key = config.plugin_recaptcha.private_key
public_key = config.plugin_invisible_recaptcha.public_key
private_key = config.plugin_invisible_recaptcha.private_key
return recaptcha.Recaptcha(public_key, private_key)

def is_plugin_enabled(self, name):
Expand Down
16 changes: 5 additions & 11 deletions openlibrary/templates/account/create.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,15 @@ <h1>$_("Sign Up")</h1>

<hr/>

$if form.has_recaptcha:
<div class="formElement">
<div class="label smaller lighter">$_("If you have security settings or privacy blockers installed, please disable them to see the reCAPTCHA.")</div>
<div class="g-recaptcha" data-sitekey="$form['recaptcha'].public_key"></div>
<div class="input">
$if form['recaptcha'].error:
<span class="invalid clearfix">$_('Incorrect. Please try again.')</span>
</div>
</div>

<small>$:_("By signing up, you agree to the Internet Archive's <a href='//archive.org/about/terms.php' target='_blank'>Terms of Service</a>.")</small>

<div class="formElement bottom">
<br/>
<button type="submit" name="signup" id="signup" class="larger">$_("Sign Up")</button>
$ sitekey = classes = ''
$if form.has_recaptcha:
$ classes = 'g-recaptcha'
$ sitekey = "data-sitekey=%s" % form['recaptcha'].public_key
<button type="submit" name="signup" id="signup" class="larger $classes" $sitekey>$_("Sign Up")</button>
<a href="javascript:history.go(-1);" class="smaller attn">$_("Cancel")</a>
</div>
</form>
Expand Down

0 comments on commit e8b13ff

Please sign in to comment.