├── .gitignore ├── AUTHORS.txt ├── LICENSE.txt ├── MANIFEST.in ├── README.rst ├── captcha_admin ├── __init__.py ├── admin.py ├── forms.py ├── models.py ├── sites.py └── templates │ └── admin │ └── captcha_login.html └── setup.py /.gitignore: -------------------------------------------------------------------------------- 1 | *.py[oc] 2 | *.mo 3 | *.db 4 | cache/ 5 | *.kdevelop 6 | *.kdevses 7 | *.egg-info 8 | MANIFEST 9 | build/ 10 | dist/ 11 | -------------------------------------------------------------------------------- /AUTHORS.txt: -------------------------------------------------------------------------------- 1 | Daniel Barreto 2 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 Daniel Barreto 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include README.rst 2 | include LICENSE.txt 3 | recursive-include captcha_admin/templates *.html 4 | recursive-include captcha_admin/tests/templates *.html 5 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | Not longer supported. I won't be addressing issues, only PRs, BUT I also won't be updating the PYPI package, so safest bet would be to go with a different package. 2 | 3 | ====================== 4 | Django Captcha Admin 5 | ====================== 6 | 7 | Simple way to add a ReCaptcha_ field to your admin login page. 8 | 9 | 4 simple steps 10 | ============== 11 | 12 | 1. Install ``django-captcha-admin`` from pypi:: 13 | 14 | $> pip install django-captcha-admin 15 | 16 | 2. Add ``captcha_admin`` and ``captcha`` to your ``INSTALLED_APPS``:: 17 | 18 | INSTALLED_APPS = ( 19 | ... 20 | 'captcha_admin', 21 | 'captcha', 22 | ) 23 | 24 | 3. Add your captcha keys to your settings, the way django-recaptcha_ 25 | indicates:: 26 | 27 | RECAPTCHA_PUBLIC_KEY = 'your-public-key' 28 | RECAPTCHA_PRIVATE_KEY = 'your-private-key' 29 | # If I'm not a Robot is required add: 30 | NOCAPTCHA = True 31 | 32 | 4. Edit your code so instead of importing ``admin`` from 33 | ``django.contrib``, you import it from ``captcha_admin``:: 34 | 35 | from captcha_admin import admin 36 | 37 | # This should stay the same 38 | admin.autodiscover() 39 | 40 | urlpatterns = patterns( 41 | ... 42 | url(r'^admin/', include(admin.site.urls)), # and this... 43 | ... 44 | ) 45 | 46 | That's it! 47 | 48 | .. _ReCaptcha: https://www.google.com/recaptcha/ 49 | .. _django-recaptcha: https://github.com/praekelt/django-recaptcha 50 | -------------------------------------------------------------------------------- /captcha_admin/__init__.py: -------------------------------------------------------------------------------- 1 | VERSION = (0, 2, 0, 'final', 0) 2 | 3 | __author__ = u'Daniel Barreto' 4 | 5 | 6 | __license__ = u'MIT' 7 | __maintainer__ = u'Daniel Barreto' 8 | __email__ = 'daniel.barreto.n@gmail.com' 9 | __status__ = 'Beta' 10 | 11 | def get_version(version=VERSION): 12 | "Returns a PEP 386-compliant version number from VERSION." 13 | if version is None: 14 | return '0.0' 15 | else: 16 | assert len(version) == 5 17 | assert version[3] in ('alpha', 'beta', 'rc', 'final') 18 | 19 | # Now build the two parts of the version number: 20 | # main = X.Y[.Z] 21 | # sub = .devN - for pre-alpha releases 22 | # | {a|b|c}N - for alpha, beta and rc releases 23 | 24 | parts = 2 if version[2] == 0 else 3 25 | main = '.'.join(str(x) for x in version[:parts]) 26 | 27 | sub = '' 28 | if version[3] != 'final': 29 | mapping = {'alpha': 'a', 'beta': 'b', 'rc': 'c'} 30 | sub = mapping[version[3]] + str(version[4]) 31 | 32 | return str(main + sub) 33 | -------------------------------------------------------------------------------- /captcha_admin/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from django.contrib.admin import autodiscover 3 | from django.contrib.auth.admin import UserAdmin, GroupAdmin 4 | from django.contrib.auth.models import User, Group 5 | 6 | from .sites import AdminSite 7 | 8 | site = AdminSite() 9 | admin.site = site 10 | admin.site.register(Group, GroupAdmin) 11 | admin.site.register(User, UserAdmin) 12 | -------------------------------------------------------------------------------- /captcha_admin/forms.py: -------------------------------------------------------------------------------- 1 | from django.contrib.admin.forms import ( 2 | AdminAuthenticationForm as _AdminAuthenticationForm 3 | ) 4 | 5 | from captcha.fields import ReCaptchaField 6 | 7 | 8 | class AdminAuthenticationForm(_AdminAuthenticationForm): 9 | captcha = ReCaptchaField(attrs={'theme': 'clean'}) 10 | -------------------------------------------------------------------------------- /captcha_admin/models.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/volrath/django-captcha-admin/d6feea6d8ab3449545cc6b75a29e8cf6e0180d09/captcha_admin/models.py -------------------------------------------------------------------------------- /captcha_admin/sites.py: -------------------------------------------------------------------------------- 1 | from django.contrib.admin.sites import AdminSite as _AdminSite 2 | 3 | from .forms import AdminAuthenticationForm 4 | 5 | 6 | class AdminSite(_AdminSite): 7 | login_form = AdminAuthenticationForm 8 | login_template = 'admin/captcha_login.html' 9 | -------------------------------------------------------------------------------- /captcha_admin/templates/admin/captcha_login.html: -------------------------------------------------------------------------------- 1 | {% extends "admin/base_site.html" %} 2 | {% load i18n static %} 3 | 4 | {% block extrastyle %} 5 | {{ block.super }} 6 | 9 | {% endblock %} 10 | 11 | {% block bodyclass %}login{% endblock %} 12 | 13 | {% block nav-global %}{% endblock %} 14 | 15 | {% block content_title %}{% endblock %} 16 | 17 | {% block breadcrumbs %}{% endblock %} 18 | 19 | {% block content %} 20 | {% if form.errors and not form.non_field_errors and not form.this_is_the_login_form.errors %} 21 |

22 | {% blocktrans count counter=form.errors.items|length %}Please correct the error below.{% plural %}Please correct the errors below.{% endblocktrans %} 23 |

24 | {% endif %} 25 | 26 | {% if form.non_field_errors or form.this_is_the_login_form.errors %} 27 | {% for error in form.non_field_errors|add:form.this_is_the_login_form.errors %} 28 |

29 | {{ error }} 30 |

31 | {% endfor %} 32 | {% endif %} 33 | 34 |
35 |
{% csrf_token %} 36 |
37 | {% if not form.this_is_the_login_form.errors %}{{ form.username.errors }}{% endif %} 38 | {{ form.username }} 39 |
40 |
41 | {% if not form.this_is_the_login_form.errors %}{{ form.password.errors }}{% endif %} 42 | {{ form.password }} 43 | 44 | 45 |
46 |
47 | {{ form.captcha.errors }} 48 | {{ form.captcha }} 49 |
50 | {% url 'admin_password_reset' as password_reset_url %} 51 | {% if password_reset_url %} 52 | 55 | {% endif %} 56 |
57 | 58 |
59 |
60 | 61 | 64 |
65 | {% endblock %} 66 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from distutils.core import setup 2 | from captcha_admin import get_version, __maintainer__, __email__ 3 | 4 | 5 | long_description = open('README.rst').read() 6 | 7 | 8 | setup( 9 | name = 'django-captcha-admin', 10 | version = get_version().replace(' ', '-'), 11 | url = 'http://github.com/volrath/django-captcha-admin', 12 | author = __maintainer__, 13 | author_email = __email__, 14 | license = 'MIT', 15 | packages = ['captcha_admin'], 16 | package_data= { 17 | 'captcha_admin': ['templates/admin/*'] 18 | }, 19 | data_files=[('', ['LICENSE.txt', 'README.rst'])], 20 | install_requires=['django-recaptcha == 1.3.0'], 21 | description = 'Provides a recaptcha field in django\'s default admin login page.', 22 | long_description=long_description, 23 | classifiers = ['Development Status :: 5 - Production/Stable', 24 | 'Environment :: Web Environment', 25 | 'Framework :: Django', 26 | 'Intended Audience :: Developers', 27 | 'License :: OSI Approved :: MIT License', 28 | 'Topic :: Internet :: WWW/HTTP :: Dynamic Content'] 29 | ) 30 | --------------------------------------------------------------------------------