-
Notifications
You must be signed in to change notification settings - Fork 191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed all the errors for django==4.0 version #88
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,26 @@ | |
from admin_honeypot import listeners | ||
|
||
|
||
class LoginAttempt(models.Model): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this model was accidentally copied and pasted here. It's a duplicate of the model defined on 26, and usually people try to keep |
||
username = models.CharField(_("username"), max_length=255, blank=True, null=True) | ||
ip_address = models.GenericIPAddressField(_("ip address"), protocol='both', blank=True, null=True) | ||
session_key = models.CharField(_("session key"), max_length=50, blank=True, null=True) | ||
user_agent = models.TextField(_("user-agent"), blank=True, null=True) | ||
timestamp = models.DateTimeField(_("timestamp"), auto_now_add=True) | ||
path = models.TextField(_("path"), blank=True, null=True) | ||
|
||
class Meta: | ||
verbose_name = _("login attempt") | ||
verbose_name_plural = _("login attempts") | ||
ordering = ('timestamp',) | ||
|
||
def __str__(self): | ||
return self.username | ||
from django.db import models | ||
from django.utils.translation import gettext_lazy as _ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this import is ok, but just work for Django 4, if anyone is using Django 3, this is version is not working with it, I think is better import djanngo, and do an if like:
|
||
from admin_honeypot import listeners | ||
|
||
|
||
class LoginAttempt(models.Model): | ||
username = models.CharField(_("username"), max_length=255, blank=True, null=True) | ||
ip_address = models.GenericIPAddressField(_("ip address"), protocol='both', blank=True, null=True) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
from django import dispatch | ||
from django.dispatch import Signal | ||
|
||
honeypot = dispatch.Signal() | ||
honeypot = Signal('request') | ||
Comment on lines
+1
to
+3
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would try not to adjust imports if you don't absolutely need to. They make reading a pull request more difficult. The big change here is adding a string argument named 'request' to the signal. But the class Signal:
...
def __init__(self, use_caching=False):
... Can you explain a bit more about what you were trying to fix here? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
from admin_honeypot import views | ||
from django.urls import path, re_path | ||
from django.urls import re_path | ||
|
||
app_name = 'admin_honeypot' | ||
|
||
urlpatterns = [ | ||
path('login/', views.AdminHoneypot.as_view(), name='login'), | ||
re_path(r'^login/$', views.AdminHoneypot.as_view(), name='login'), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using the original |
||
re_path(r'^.*$', views.AdminHoneypot.as_view(), name='index'), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,7 @@ | ||
import django | ||
|
||
from ipware import get_client_ip | ||
|
||
Comment on lines
-2
to
-4
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why was this removed? It solved a valid problem. |
||
from admin_honeypot.forms import HoneypotLoginForm | ||
from admin_honeypot.models import LoginAttempt | ||
from admin_honeypot.signals import honeypot | ||
|
||
from django.contrib.admin.sites import AdminSite | ||
from django.contrib.auth import REDIRECT_FIELD_NAME | ||
from django.contrib.auth.views import redirect_to_login | ||
from django.shortcuts import redirect | ||
|
@@ -36,9 +31,9 @@ def get_form(self, form_class=form_class): | |
|
||
def get_context_data(self, **kwargs): | ||
context = super(AdminHoneypot, self).get_context_data(**kwargs) | ||
path = self.request.get_full_path() | ||
context.update({ | ||
**AdminSite().each_context(self.request), | ||
'app_path': self.request.get_full_path(), | ||
'app_path': path, | ||
REDIRECT_FIELD_NAME: reverse('admin_honeypot:index'), | ||
'title': _('Log in'), | ||
}) | ||
|
@@ -48,11 +43,10 @@ def form_valid(self, form): | |
return self.form_invalid(form) | ||
|
||
def form_invalid(self, form): | ||
ip_address, is_routable = get_client_ip(self.request) | ||
instance = LoginAttempt.objects.create( | ||
username=self.request.POST.get('username'), | ||
session_key=self.request.session.session_key, | ||
ip_address=ip_address, | ||
ip_address=self.request.META.get('REMOTE_ADDR'), | ||
user_agent=self.request.META.get('HTTP_USER_AGENT'), | ||
path=self.request.get_full_path(), | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really don't like these changes.
Reading up on the rationale for using
format_html
, it would seem to prevent XSS attacks, and is easier to use than%
string interpolation.