django-powcaptcha 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- django-powcaptcha-0.0.1/PKG-INFO +69 -0
- django-powcaptcha-0.0.1/README.md +41 -0
- django-powcaptcha-0.0.1/django_powcaptcha/__init__.py +20 -0
- django-powcaptcha-0.0.1/django_powcaptcha/apps.py +6 -0
- django-powcaptcha-0.0.1/django_powcaptcha/client.py +49 -0
- django-powcaptcha-0.0.1/django_powcaptcha/fields.py +42 -0
- django-powcaptcha-0.0.1/django_powcaptcha/widgets.py +27 -0
- django-powcaptcha-0.0.1/django_powcaptcha.egg-info/PKG-INFO +69 -0
- django-powcaptcha-0.0.1/django_powcaptcha.egg-info/SOURCES.txt +14 -0
- django-powcaptcha-0.0.1/django_powcaptcha.egg-info/dependency_links.txt +1 -0
- django-powcaptcha-0.0.1/django_powcaptcha.egg-info/not-zip-safe +1 -0
- django-powcaptcha-0.0.1/django_powcaptcha.egg-info/requires.txt +1 -0
- django-powcaptcha-0.0.1/django_powcaptcha.egg-info/top_level.txt +1 -0
- django-powcaptcha-0.0.1/setup.cfg +4 -0
- django-powcaptcha-0.0.1/setup.py +40 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: django-powcaptcha
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Django PowCaptcha form field/widget app.
|
|
5
|
+
Home-page: https://github.com/aeyoll/django-powcaptcha
|
|
6
|
+
Author: Jean-Philippe Bidegain
|
|
7
|
+
Author-email: jp@bidega.in
|
|
8
|
+
License: BSD
|
|
9
|
+
Project-URL: Changelog, https://github.com/aeyoll/django-powcaptcha/blob/main/CHANGELOG.md
|
|
10
|
+
Project-URL: Issue Tracker, https://github.com/aeyoll/django-powcaptcha/issues
|
|
11
|
+
Keywords: django,powcaptcha
|
|
12
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
13
|
+
Classifier: Framework :: Django
|
|
14
|
+
Classifier: Framework :: Django :: 3.2
|
|
15
|
+
Classifier: Framework :: Django :: 4.1
|
|
16
|
+
Classifier: Framework :: Django :: 4.2
|
|
17
|
+
Classifier: Intended Audience :: Developers
|
|
18
|
+
Classifier: License :: OSI Approved :: BSD License
|
|
19
|
+
Classifier: Operating System :: OS Independent
|
|
20
|
+
Classifier: Programming Language :: Python
|
|
21
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
|
|
22
|
+
Classifier: Programming Language :: Python :: 3
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
Requires-Dist: django
|
|
28
|
+
|
|
29
|
+
# Django PowCaptcha
|
|
30
|
+
|
|
31
|
+
Django PowCaptcha form field/widget integration app.
|
|
32
|
+
|
|
33
|
+
## Installation
|
|
34
|
+
|
|
35
|
+
1. Install with `pip install django-powcaptcha`.
|
|
36
|
+
|
|
37
|
+
2. Add `'django_powcaptcha'` to your `INSTALLED_APPS` setting.
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
INSTALLED_APPS = [
|
|
41
|
+
...,
|
|
42
|
+
'django_powcaptcha',
|
|
43
|
+
...
|
|
44
|
+
]
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
3. Add settings.
|
|
48
|
+
|
|
49
|
+
For example:
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
POWCAPTCHA_API_URL = 'https://captcha.yourdomain.com'
|
|
53
|
+
POWCAPTCHA_API_KEY = 'MyPOWCAPTCHAPrivateKey456'
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Usage
|
|
57
|
+
|
|
58
|
+
### Fields
|
|
59
|
+
|
|
60
|
+
The quickest way to add PowCaptcha to a form is to use the included
|
|
61
|
+
`PowCaptchaField` field class. For example:
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
from django import forms
|
|
65
|
+
from django_powcaptcha.fields import PowCaptchaField
|
|
66
|
+
|
|
67
|
+
class FormWithCaptcha(forms.Form):
|
|
68
|
+
captcha = PowCaptchaField()
|
|
69
|
+
```
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Django PowCaptcha
|
|
2
|
+
|
|
3
|
+
Django PowCaptcha form field/widget integration app.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
1. Install with `pip install django-powcaptcha`.
|
|
8
|
+
|
|
9
|
+
2. Add `'django_powcaptcha'` to your `INSTALLED_APPS` setting.
|
|
10
|
+
|
|
11
|
+
```python
|
|
12
|
+
INSTALLED_APPS = [
|
|
13
|
+
...,
|
|
14
|
+
'django_powcaptcha',
|
|
15
|
+
...
|
|
16
|
+
]
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
3. Add settings.
|
|
20
|
+
|
|
21
|
+
For example:
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
POWCAPTCHA_API_URL = 'https://captcha.yourdomain.com'
|
|
25
|
+
POWCAPTCHA_API_KEY = 'MyPOWCAPTCHAPrivateKey456'
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
### Fields
|
|
31
|
+
|
|
32
|
+
The quickest way to add PowCaptcha to a form is to use the included
|
|
33
|
+
`PowCaptchaField` field class. For example:
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
from django import forms
|
|
37
|
+
from django_powcaptcha.fields import PowCaptchaField
|
|
38
|
+
|
|
39
|
+
class FormWithCaptcha(forms.Form):
|
|
40
|
+
captcha = PowCaptchaField()
|
|
41
|
+
```
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import django
|
|
2
|
+
from django.conf import settings
|
|
3
|
+
from django.core.exceptions import ImproperlyConfigured
|
|
4
|
+
|
|
5
|
+
SETTINGS_TYPES = {
|
|
6
|
+
'POWCAPTCHA_API_URL': str,
|
|
7
|
+
'POWCAPTCHA_API_KEY': str,
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
# Validate settings types.
|
|
11
|
+
for variable, instance_type in SETTINGS_TYPES.items():
|
|
12
|
+
if hasattr(settings, variable) and not isinstance(
|
|
13
|
+
getattr(settings, variable), instance_type
|
|
14
|
+
):
|
|
15
|
+
raise ImproperlyConfigured(
|
|
16
|
+
'Setting %s is not of type' % variable, instance_type
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
if django.VERSION < (3, 2):
|
|
20
|
+
default_app_config = 'django_recaptcha.apps.DjangoRecaptchaConfig'
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from urllib.error import HTTPError
|
|
3
|
+
from urllib.request import Request, build_opener
|
|
4
|
+
|
|
5
|
+
from django.conf import settings
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class PowCaptchaValidationException(Exception):
|
|
9
|
+
pass
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def powcaptcha_request(path, params):
|
|
13
|
+
domain = getattr(settings, 'POWCAPTCHA_API_URL')
|
|
14
|
+
token = getattr(settings, 'POWCAPTCHA_API_TOKEN')
|
|
15
|
+
|
|
16
|
+
request_object = Request(
|
|
17
|
+
url=f'https://{domain}/{path}',
|
|
18
|
+
data=params,
|
|
19
|
+
headers={
|
|
20
|
+
'Authorization': f'Bearer {token}',
|
|
21
|
+
},
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
opener_args = []
|
|
25
|
+
opener = build_opener(*opener_args)
|
|
26
|
+
|
|
27
|
+
return opener.open(
|
|
28
|
+
request_object,
|
|
29
|
+
timeout=5
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def get_challenge():
|
|
34
|
+
path = 'GetChallenges?difficultyLevel=5'
|
|
35
|
+
response = powcaptcha_request(path, [])
|
|
36
|
+
challenges = json.loads(response.read().decode('utf-8'))
|
|
37
|
+
|
|
38
|
+
# @Todo: implement caching
|
|
39
|
+
|
|
40
|
+
return challenges[0]
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def validate_captcha(challenge: str, nonce: str):
|
|
44
|
+
path = f'Verify?challenge={challenge}&nonce={nonce}'
|
|
45
|
+
|
|
46
|
+
try:
|
|
47
|
+
powcaptcha_request(path, [])
|
|
48
|
+
except HTTPError as error:
|
|
49
|
+
raise PowCaptchaValidationException(error.code)
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
|
|
3
|
+
from django import forms
|
|
4
|
+
from django.conf import settings
|
|
5
|
+
from django.core.exceptions import ValidationError
|
|
6
|
+
from django.utils.translation import gettext_lazy as _
|
|
7
|
+
|
|
8
|
+
from django_powcaptcha import client
|
|
9
|
+
from django_powcaptcha.client import PowCaptchaValidationException
|
|
10
|
+
from django_powcaptcha.widgets import PowCaptchaWidget
|
|
11
|
+
|
|
12
|
+
logger = logging.getLogger(__name__)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class PowCaptchaField(forms.CharField):
|
|
16
|
+
widget = PowCaptchaWidget
|
|
17
|
+
default_error_messages = {
|
|
18
|
+
'captcha_invalid': _('Error verifying reCAPTCHA, please try again.'),
|
|
19
|
+
'captcha_error': _('Error verifying reCAPTCHA, please try again.'),
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
def __init__(self, api_key=None, api_url=None, *args, **kwargs):
|
|
23
|
+
super().__init__(*args, **kwargs)
|
|
24
|
+
|
|
25
|
+
self.required = True
|
|
26
|
+
|
|
27
|
+
# Setup instance variables.
|
|
28
|
+
self.api_key = api_key or getattr(settings, 'POWCAPTCHA_API_KEY')
|
|
29
|
+
self.api_url = api_url or getattr(settings, 'POWCAPTCHA_API_URL')
|
|
30
|
+
|
|
31
|
+
def validate(self, value):
|
|
32
|
+
super().validate(value)
|
|
33
|
+
|
|
34
|
+
try:
|
|
35
|
+
client.validate_captcha(
|
|
36
|
+
challenge='',
|
|
37
|
+
nonce='',
|
|
38
|
+
)
|
|
39
|
+
except PowCaptchaValidationException:
|
|
40
|
+
raise ValidationError(
|
|
41
|
+
self.error_messages['captcha_error'], code='captcha_error'
|
|
42
|
+
)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from django.conf import settings
|
|
2
|
+
from django.forms import widgets
|
|
3
|
+
|
|
4
|
+
from django_powcaptcha.client import get_challenge
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class PowCaptchaWidget(widgets.Widget):
|
|
8
|
+
input_type = 'hidden'
|
|
9
|
+
template_name = 'django_recaptcha/widget.html'
|
|
10
|
+
|
|
11
|
+
def get_context(self, name, value, attrs):
|
|
12
|
+
context = super().get_context(name, value, attrs)
|
|
13
|
+
context.update(
|
|
14
|
+
{
|
|
15
|
+
'captcha_url': settings.POWCAPTCHA_API_URL,
|
|
16
|
+
'captcha_challenge': get_challenge(),
|
|
17
|
+
'captcha_callback': 'myCaptchaCallback',
|
|
18
|
+
}
|
|
19
|
+
)
|
|
20
|
+
return context
|
|
21
|
+
|
|
22
|
+
# def build_attrs(self, base_attrs, extra_attrs=None):
|
|
23
|
+
# attrs = super().build_attrs(base_attrs, extra_attrs)
|
|
24
|
+
# attrs['data-sqr-captcha-url'] = settings.POWCAPTCHA_API_URL
|
|
25
|
+
# attrs['data-sqr-captcha-challenge'] = self.get_challenge()
|
|
26
|
+
# attrs['data-sqr-captcha-callback'] = 'myCaptchaCallback'
|
|
27
|
+
# return attrs
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: django-powcaptcha
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Django PowCaptcha form field/widget app.
|
|
5
|
+
Home-page: https://github.com/aeyoll/django-powcaptcha
|
|
6
|
+
Author: Jean-Philippe Bidegain
|
|
7
|
+
Author-email: jp@bidega.in
|
|
8
|
+
License: BSD
|
|
9
|
+
Project-URL: Changelog, https://github.com/aeyoll/django-powcaptcha/blob/main/CHANGELOG.md
|
|
10
|
+
Project-URL: Issue Tracker, https://github.com/aeyoll/django-powcaptcha/issues
|
|
11
|
+
Keywords: django,powcaptcha
|
|
12
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
13
|
+
Classifier: Framework :: Django
|
|
14
|
+
Classifier: Framework :: Django :: 3.2
|
|
15
|
+
Classifier: Framework :: Django :: 4.1
|
|
16
|
+
Classifier: Framework :: Django :: 4.2
|
|
17
|
+
Classifier: Intended Audience :: Developers
|
|
18
|
+
Classifier: License :: OSI Approved :: BSD License
|
|
19
|
+
Classifier: Operating System :: OS Independent
|
|
20
|
+
Classifier: Programming Language :: Python
|
|
21
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
|
|
22
|
+
Classifier: Programming Language :: Python :: 3
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
Requires-Dist: django
|
|
28
|
+
|
|
29
|
+
# Django PowCaptcha
|
|
30
|
+
|
|
31
|
+
Django PowCaptcha form field/widget integration app.
|
|
32
|
+
|
|
33
|
+
## Installation
|
|
34
|
+
|
|
35
|
+
1. Install with `pip install django-powcaptcha`.
|
|
36
|
+
|
|
37
|
+
2. Add `'django_powcaptcha'` to your `INSTALLED_APPS` setting.
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
INSTALLED_APPS = [
|
|
41
|
+
...,
|
|
42
|
+
'django_powcaptcha',
|
|
43
|
+
...
|
|
44
|
+
]
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
3. Add settings.
|
|
48
|
+
|
|
49
|
+
For example:
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
POWCAPTCHA_API_URL = 'https://captcha.yourdomain.com'
|
|
53
|
+
POWCAPTCHA_API_KEY = 'MyPOWCAPTCHAPrivateKey456'
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Usage
|
|
57
|
+
|
|
58
|
+
### Fields
|
|
59
|
+
|
|
60
|
+
The quickest way to add PowCaptcha to a form is to use the included
|
|
61
|
+
`PowCaptchaField` field class. For example:
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
from django import forms
|
|
65
|
+
from django_powcaptcha.fields import PowCaptchaField
|
|
66
|
+
|
|
67
|
+
class FormWithCaptcha(forms.Form):
|
|
68
|
+
captcha = PowCaptchaField()
|
|
69
|
+
```
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
setup.cfg
|
|
3
|
+
setup.py
|
|
4
|
+
django_powcaptcha/__init__.py
|
|
5
|
+
django_powcaptcha/apps.py
|
|
6
|
+
django_powcaptcha/client.py
|
|
7
|
+
django_powcaptcha/fields.py
|
|
8
|
+
django_powcaptcha/widgets.py
|
|
9
|
+
django_powcaptcha.egg-info/PKG-INFO
|
|
10
|
+
django_powcaptcha.egg-info/SOURCES.txt
|
|
11
|
+
django_powcaptcha.egg-info/dependency_links.txt
|
|
12
|
+
django_powcaptcha.egg-info/not-zip-safe
|
|
13
|
+
django_powcaptcha.egg-info/requires.txt
|
|
14
|
+
django_powcaptcha.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
django
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
django_powcaptcha
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
from setuptools import find_packages, setup
|
|
2
|
+
|
|
3
|
+
long_desc = open("README.md").read()
|
|
4
|
+
|
|
5
|
+
setup(
|
|
6
|
+
name="django-powcaptcha",
|
|
7
|
+
version="0.0.1",
|
|
8
|
+
description="Django PowCaptcha form field/widget app.",
|
|
9
|
+
long_description=long_desc,
|
|
10
|
+
long_description_content_type="text/markdown",
|
|
11
|
+
author="Jean-Philippe Bidegain",
|
|
12
|
+
author_email="jp@bidega.in",
|
|
13
|
+
license="BSD",
|
|
14
|
+
url="https://github.com/aeyoll/django-powcaptcha",
|
|
15
|
+
project_urls={
|
|
16
|
+
"Changelog": "https://github.com/aeyoll/django-powcaptcha/blob/main/CHANGELOG.md",
|
|
17
|
+
"Issue Tracker": "https://github.com/aeyoll/django-powcaptcha/issues",
|
|
18
|
+
},
|
|
19
|
+
packages=find_packages(),
|
|
20
|
+
install_requires=["django"],
|
|
21
|
+
keywords=["django", "powcaptcha"],
|
|
22
|
+
include_package_data=True,
|
|
23
|
+
classifiers=[
|
|
24
|
+
"Development Status :: 5 - Production/Stable",
|
|
25
|
+
"Framework :: Django",
|
|
26
|
+
"Framework :: Django :: 3.2",
|
|
27
|
+
"Framework :: Django :: 4.1",
|
|
28
|
+
"Framework :: Django :: 4.2",
|
|
29
|
+
"Intended Audience :: Developers",
|
|
30
|
+
"License :: OSI Approved :: BSD License",
|
|
31
|
+
"Operating System :: OS Independent",
|
|
32
|
+
"Programming Language :: Python",
|
|
33
|
+
"Topic :: Internet :: WWW/HTTP :: Dynamic Content",
|
|
34
|
+
"Programming Language :: Python :: 3",
|
|
35
|
+
"Programming Language :: Python :: 3.9",
|
|
36
|
+
"Programming Language :: Python :: 3.10",
|
|
37
|
+
"Programming Language :: Python :: 3.11",
|
|
38
|
+
],
|
|
39
|
+
zip_safe=False,
|
|
40
|
+
)
|