Add captcha field for django admin's login page.
Project description
django-admin-safe-login
Add captcha field for django admin's login page.
Install
pip install django-admin-safe-login
Usage
pro/settings.py
INSTALLED_APPS = [
...
'django_static_jquery3',
'django_secure_password_input',
'django_admin_safe_login',
'captcha',
...
]
CAPTCHA_IMAGE_SIZE = (100, 30)
ENABLE_LOGIN_CAPTCHA = True
Note:
- Insert django_static_jquery3, django_secure_password_input, django_admin_safe_login and captcha into INSTALLED_APPS.
- Application django_static_jquery3 provides static jquery.js.
- Application django_secure_password_input provides rsa encryption and decryption function for password field.
- Application django_admin_safe_login provides all functions about safe login.
- Application captcha provides image captcha functions.
- Configuration item CAPTCHA_IMAGE_SIZE is required, and must set to (100, 30) so that it will not break the display style. If you want other size image, you have to rewrite some css code.
- Configuration item ENABLE_LOGIN_CAPTCHA is optional, it's default to True value. You can use it for disable captcha for a short time. If you want remove the captcha functional, just remove the app django_admin_safe_login.
pro/urls.py
from django.urls import path
from django.urls import include
urlpatterns = [
...
path('captcha/', include("captcha.urls")),
...
]
Note:
- Include captcha.urls is required so that the captcha image can be displayed.
When things go down!
We have override some part of admin/login.html. But the admin/login.html content may change in future releases. So you should known what part is overrided.
{% extends "admin/login.html" %}
{% load i18n static %}
{% block extrastyle %}
{{ block.super }}
<!-- resource files included below is ours -->
<link rel="stylesheet" type="text/css" href="{% static "django-admin-safe-login/css/django-admin-safe-login.css" %}" />
<script src="{% static "jquery3/jquery.js" %}"></script>
<script src="{% static "django-admin-safe-login/js/django-admin-safe-login.js" %}"></script>
<!-- resource files included above is ours -->
{% endblock %}
{% block content %}
.....
<form action="{{ app_path }}" method="post" id="login-form">{% csrf_token %}
......
<div class="form-row">
{{ form.password.errors }}
{{ form.password.label_tag }} {{ form.password }}
....
</div>
<!-- form-row below is ours -->
<div class="form-row">
<label for="id_captcha" class="required">{% trans "Captcha" %}</label>
<div class="captcha-input">
{{ form.captcha }}
</div>
{% if not form.this_is_the_login_form.errors %}{{ form.captcha.errors }}{% endif %}
</div>
<!-- form-row above is ours -->
......
</form>
......
{% endblock %}
Steps:
- Our login.html is extends from "admin/login.html"
- Override block extrastyle, append our css and js.
- Override block content, all content of this block must copy from "admin/login.html", and add our form-row after form-row of password.
Releases
v0.2.0 2020/03/07
- Add rsa encryption and decrption functions for password field.
- Fix requirements.txt missing django-static-jquery3 problem.
v0.1.0 2020/03/06
- First release.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file django-admin-safe-login-0.2.0.tar.gz
.
File metadata
- Download URL: django-admin-safe-login-0.2.0.tar.gz
- Upload date:
- Size: 10.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee4425b1c2559f1fe2b8be512df4b05c0b9edd008ec0e36471dbdc93c74ebe40 |
|
MD5 | b59ea8c7c20fd95759fc9b595386f11a |
|
BLAKE2b-256 | 059b368ee855776e54f4180c7dd449934d2afccc5b19b7a81bd20ff427b36197 |