Skip to content
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

Feature/axes update #20

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
PY3 = sys.version_info[0] == 3

install_requires = [
'wagtail>=1.5',
'django>=1.8',
'wagtail>=2.1',
'django>=2.0',
'django-password-policies-iplweb>=0.4.4b1',
'django-axes>=2.0.0,<3.0.0',
'django-axes>=5.27.0.0,<5.28.0',
'pyClamd>=0.3.17',
]

Expand Down
11 changes: 11 additions & 0 deletions wagtailenforcer/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,15 @@ class WagtailEnforcerAppConfig(AppConfig):
name = 'wagtailenforcer'

def ready(self):
from django.utils.decorators import method_decorator

from wagtail.admin.views.account import LoginView as WagtailLoginView
from wagtailenforcer import signals # NOQA

from axes import signals # NOQA
from axes.decorators import axes_dispatch
from axes.decorators import axes_form_invalid

# replacement for watch_login: https://github.com/jazzband/django-axes/compare/3.0.1...3.0.2
WagtailLoginView.dispatch = method_decorator(axes_dispatch)(WagtailLoginView.dispatch)
WagtailLoginView.form_invalid = method_decorator(axes_form_invalid)(WagtailLoginView.form_invalid)
2 changes: 1 addition & 1 deletion wagtailenforcer/forms/wagtailusers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from password_policies.forms import PasswordPoliciesForm
from password_policies.forms.fields import PasswordPoliciesField

from wagtail.wagtailusers.forms import UserCreationForm as BaseUserCreationForm
from wagtail.users.forms import UserCreationForm as BaseUserCreationForm

from wagtailenforcer.validators import UpperCaseLetterValidator

Expand Down
4 changes: 2 additions & 2 deletions wagtailenforcer/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from django.db.models.signals import post_save, pre_save
from django.core.signals import got_request_exception
from django.dispatch import receiver
from wagtail.wagtaildocs.models import Document
from wagtail.wagtailimages.models import Image
from wagtail.documents.models import Document
from wagtail.images.models import Image
from .utilities import check_for_virus


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ <h1>{% trans "Set your new password" %}</h1>
and it's not working in the realme.urls either. We pass the hardcoded url using extra_context.
Setting hardcoded url for the moment (unlikely to change)
{% endcomment %}
<p class="help"><a href="{{ reset_password_url }}">{% trans "Request a password reset" %}</a></p>
<p class="help"><a href="/admin/password_reset">{% trans "Request a password reset" %}</a></p>
{% endif %}
</div>
{% endblock %}
24 changes: 11 additions & 13 deletions wagtailenforcer/urls.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from django.conf.urls import url
from django.urls import path, re_path
from django.contrib.auth import views as django_auth_views

from wagtail.wagtailadmin.views import account as wagtail_account_views

from axes.decorators import watch_login
from wagtail.admin.views.account import LoginView as WagtailLoginView

from wagtailenforcer.views import account as account_views
from wagtailenforcer.views.wagtailadmin.account import change_password
Expand All @@ -12,18 +10,18 @@
# Here we put all the overriden Wagtail urls from the different wagtail apps

urlpatterns = [
url(r'^password_reset/$', account_views.password_reset, name='wagtailadmin_password_reset'),
url(r'^password_reset/done/$', account_views.password_reset_done, name='wagtailadmin_password_reset_done'),
url(
path('password_reset/', account_views.password_reset, name='wagtailadmin_password_reset'),
path('password_reset/done/', account_views.password_reset_done, name='wagtailadmin_password_reset_done'),
re_path(
r'^password_reset/confirm/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
account_views.password_reset_confirm,
name='wagtailadmin_password_reset_confirm',
),
url(r'^password_reset/complete/$', account_views.password_reset_complete, name='wagtailadmin_password_reset_complete'),

url(r'^login/$', watch_login(wagtail_account_views.login), name='wagtailadmin_login'),
url(r"^account/change_password/", change_password, name="password_change"),
url(r'^users/(\d+)/$', users.edit, name='wagtailusers_users_edit'),
url(r'^users/new/$', users.create, name='wagtailusers_users_create'),
path('password_reset/complete/', account_views.password_reset_complete, name='wagtailadmin_password_reset_complete'),

path('login/', WagtailLoginView.as_view(), name='wagtailadmin_login'),
# axes watch_login got replaced, look at in apps.ready()
path('account/change_password/', change_password, name="password_change"),
re_path(r'^users/(\d+)/$', users.edit, name='wagtailusers_users_edit'),
path('users/new/', users.create, name='wagtailusers_users_create'),
]
2 changes: 1 addition & 1 deletion wagtailenforcer/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.utils.translation import ugettext as _
from django.contrib.auth.decorators import permission_required

from wagtail.wagtailcore.compat import AUTH_USER_APP_LABEL, AUTH_USER_MODEL_NAME
from wagtail.core.compat import AUTH_USER_APP_LABEL, AUTH_USER_MODEL_NAME

from wagtailenforcer.forms.wagtailusers import UserEditForm

Expand Down
32 changes: 22 additions & 10 deletions wagtailenforcer/views/account.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from wagtail.wagtailadmin.views import account as account_views
from django.urls import reverse_lazy

from wagtail.admin.views import account as account_views


def password_reset(request, **kwargs):
Expand All @@ -7,32 +9,42 @@ def password_reset(request, **kwargs):
'template_name': 'wagtailadmin/account/password_reset/form.html',
'email_template_name': 'wagtailadmin/account/password_reset/email.txt',
'subject_template_name': 'wagtailadmin/account/password_reset/email_subject.txt',
'password_reset_form': PasswordResetForm,
'post_reset_redirect': 'wagtailadmin_password_reset_done',
'form_class': PasswordResetForm,
'success_url': reverse_lazy('wagtailadmin_password_reset_done'),
})
return account_views.password_reset(request, **kwargs)
return account_views.PasswordResetView.as_view(**kwargs)(request)


def password_reset_done(request, **kwargs):
kwargs.update({
'template_name': 'wagtailadmin/account/password_reset/done.html'
})
return account_views.password_reset_done(request, **kwargs)
return account_views.PasswordResetDoneView.as_view(**kwargs)(request)


def password_reset_confirm(request, **kwargs):
from wagtailenforcer.forms.wagtailusers import PasswordForm

# URL params are part of kwargs, which shouldn't go to the as_view() call
request_kwargs = {}
if 'uidb64' in kwargs:
request_kwargs['uidb64'] = kwargs['uidb64']
del kwargs['uidb64']

if 'token' in kwargs:
request_kwargs['token'] = kwargs['token']
del kwargs['token']

kwargs.update({
'template_name': 'wagtailadmin/account/password_reset/enforce_confirm.html',
'post_reset_redirect': 'wagtailadmin_password_reset_complete',
'set_password_form': PasswordForm,
'extra_context': {'reset_password_url': '/admin/password_reset'},
'success_url': reverse_lazy('wagtailadmin_password_reset_complete'),
'form_class': PasswordForm,
})
return account_views.password_reset_confirm(request, **kwargs)
return account_views.PasswordResetConfirmView.as_view(**kwargs)(request, **request_kwargs)


def password_reset_complete(request, **kwargs):
kwargs.update({
'template_name': 'wagtailadmin/account/password_reset/complete.html'
})
return account_views.password_reset_complete(request, **kwargs)
return account_views.PasswordResetCompleteView.as_view(**kwargs)(request)
2 changes: 1 addition & 1 deletion wagtailenforcer/views/axes/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.contrib.auth.decorators import permission_required
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.shortcuts import render, HttpResponseRedirect, get_object_or_404
from django.core.urlresolvers import reverse
from django.urls import reverse
from django.conf import settings
from django.db.models import Q
from django.contrib import messages
Expand Down
12 changes: 1 addition & 11 deletions wagtailenforcer/views/wagtailadmin/account.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
from __future__ import absolute_import, unicode_literals

from functools import wraps

from django.conf import settings
from django.contrib import messages
from django.utils.translation import ugettext as _
from django.contrib.auth import update_session_auth_hash
from django.contrib.auth.forms import PasswordChangeForm
from django.http import Http404
from django.shortcuts import redirect, render

from wagtail.utils.compat import user_is_authenticated
from wagtailenforcer.forms import wagtailadmin
from wagtail.wagtailadmin.utils import get_available_admin_languages
from wagtail.wagtailcore.models import UserPagePermissionsProxy

from wagtail.wagtailusers.models import UserProfile

from password_policies.conf import settings
from password_policies.forms import PasswordPoliciesChangeForm
from password_policies.forms.fields import PasswordPoliciesField


# Helper functions to check password management settings to enable/disable views as appropriate.
Expand All @@ -36,7 +26,7 @@ def change_password(request):
raise Http404

can_change_password = request.user.has_usable_password()

if can_change_password:
if request.method == 'POST':
form = PasswordPoliciesChangeForm(request.user, request.POST)
Expand Down
2 changes: 1 addition & 1 deletion wagtailenforcer/views/wagtailusers/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.utils.translation import ugettext as _
from django.contrib.auth.decorators import permission_required

from wagtail.wagtailcore.compat import AUTH_USER_APP_LABEL, AUTH_USER_MODEL_NAME
from wagtail.core.compat import AUTH_USER_APP_LABEL, AUTH_USER_MODEL_NAME


User = get_user_model()
Expand Down
6 changes: 3 additions & 3 deletions wagtailenforcer/wagtail_hooks.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.core.urlresolvers import reverse
from django.urls import reverse

from wagtail.wagtailcore import hooks
from wagtail.wagtailadmin.menu import MenuItem
from wagtail.core import hooks
from wagtail.admin.menu import MenuItem


@hooks.register('register_settings_menu_item')
Expand Down