Skip to content

Commit

Permalink
Merge branch 'v0.16.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
barseghyanartur committed Apr 4, 2020
2 parents 473df88 + 1077c93 commit 49f3fd9
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 43 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Expand Up @@ -15,6 +15,12 @@ are used for versioning (schema follows below):
0.3.4 to 0.4).
- All backwards incompatible changes are mentioned in this document.

0.16.3
------
2020-04-04

- Fixes in ``invisible_recaptcha`` plugin. Treat empty ``SITE_KEY`` as error.

0.16.2
------
2020-04-03
Expand Down
6 changes: 6 additions & 0 deletions docs/changelog.rst
Expand Up @@ -15,6 +15,12 @@ are used for versioning (schema follows below):
0.3.4 to 0.4).
- All backwards incompatible changes are mentioned in this document.

0.16.3
------
2020-04-04

- Fixes in ``invisible_recaptcha`` plugin. Treat empty ``SITE_KEY`` as error.

0.16.2
------
2020-04-03
Expand Down
2 changes: 1 addition & 1 deletion examples/simple/settings/base.py
Expand Up @@ -430,7 +430,7 @@ def gettext(s):
# LOGIN_URL = '/accounts/login/'
# LOGIN_REDIRECT_URL = '/fobi/' # Important for passing the selenium tests

LOGIN_URL = '/en/accounts/login/'
LOGIN_URL = '/en/login/'
LOGIN_REDIRECT_URL = '/en/fobi/' # Important for passing the selenium tests

# LOGIN_URL = '/accounts/login/'
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -4,7 +4,7 @@
from distutils.version import LooseVersion
from setuptools import setup, find_packages

version = '0.16.2'
version = '0.16.3'

# ***************************************************************************
# ************************** Django version *********************************
Expand Down
2 changes: 1 addition & 1 deletion src/fobi/__init__.py
@@ -1,5 +1,5 @@
__title__ = 'django-fobi'
__version__ = '0.16.2'
__version__ = '0.16.3'
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
__copyright__ = '2014-2020 Artur Barseghyan'
__license__ = 'GPL 2.0/LGPL 2.1'
Expand Down
@@ -1,7 +1,5 @@
from django.conf import settings

from . import defaults

__title__ = 'fobi.contrib.plugins.form_elements.security.' \
'invisible_recaptcha.conf'
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
Expand All @@ -26,8 +24,9 @@ def get_setting(setting, override=None):
"""
if override is not None:
return override
key = 'FOBI_PLUGIN_INVISIBLE_RECAPTCHA_{0}'.format(setting)

key = "FOBI_PLUGIN_INVISIBLE_RECAPTCHA_{0}".format(setting)
if hasattr(settings, key):
return getattr(settings, key)
else:
return getattr(defaults, setting)

return ""

This file was deleted.

Expand Up @@ -8,17 +8,12 @@
;

function g_recaptcha_onSubmit(token) {
console.log("g_recaptcha_onSubmit")
// document.getElementById("fobi-form").submit();
// document.getElementsByClassName("form-horizontal").submit();
// $('form.form-horizontal').submit();
$('form#fobi-form').submit();
}

$(document).ready(function() {
var siteKey = window.InvisibleRecaptchaSiteKey || "";
var siteKey = $("[data-recaptcha-field]").val();
if (siteKey) {
// var submitFormButton = $('form.form-horizontal button[type=submit]');
var submitFormButton = $('form#fobi-form button[type=submit]');
submitFormButton.addClass('g-recaptcha');
submitFormButton.attr('data-sitekey', siteKey);
Expand Down
@@ -1,6 +1,4 @@
# from django.utils.html import format_html
from django.forms.widgets import HiddenInput
from django.utils.safestring import mark_safe

from fobi.base import FormElementPluginWidget

Expand All @@ -22,23 +20,17 @@ class InvisibleRecaptchaWidget(HiddenInput):
"""Invisible recaptcha widget."""

def __init__(self, *args, **kwargs):
attrs = kwargs.get('attrs', {})
attrs.update({'data-customforms': 'disabled'})
kwargs.update({'attrs': attrs})
super(InvisibleRecaptchaWidget, self).__init__(*args, **kwargs)
site_key = get_setting("SITE_KEY")
if not site_key:
raise ValueError("SITE_KEY not set")

attrs = kwargs.get("attrs", {})
attrs["data-customforms"] = "disabled"
attrs["data-recaptcha-field"] = "true"
attrs["value"] = site_key

def render(self, *args, **kwargs):
"""Returns this Widget rendered as HTML, as a Unicode string."""
html = super(InvisibleRecaptchaWidget, self).render(*args, **kwargs)
g_recaptcha_sitekey = get_setting('SITE_KEY')
invisible_recaptcha_html = """
<script>
var InvisibleRecaptchaSiteKey = "{g_recaptcha_sitekey}";
</script>
""".format(
g_recaptcha_sitekey=g_recaptcha_sitekey
)
return html + mark_safe(invisible_recaptcha_html)
kwargs["attrs"] = attrs
super(InvisibleRecaptchaWidget, self).__init__(*args, **kwargs)


class BaseInvisibleRecaptchaWidget(FormElementPluginWidget):
Expand Down

0 comments on commit 49f3fd9

Please sign in to comment.