Skip to content

Commit b76c192

Browse files
authored
Merge pull request #16 from springload/change-pass
Change pass
2 parents a61a86d + 2b9fb75 commit b76c192

File tree

5 files changed

+68
-2
lines changed

5 files changed

+68
-2
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
88

99
...
1010

11+
## [1.1.6] - 2018-06-22
12+
13+
### Added
14+
15+
- Add change password form
16+
17+
1118
## [1.1.5] - 2018-06-21
1219

1320
### Fixed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
setup(
3030
name='wagtailenforcer',
31-
version='1.1.5',
31+
version='1.1.6',
3232
description='WagtailEnforcer, the Wagtail arm of the law.',
3333
author='Springload',
3434
author_email='hello@springload.co.nz',

wagtailenforcer/urls.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from axes.decorators import watch_login
77

88
from wagtailenforcer.views import account as account_views
9+
from wagtailenforcer.views.wagtailadmin.account import change_password
910
from wagtailenforcer.views.wagtailusers import users
1011

1112
# Here we put all the overriden Wagtail urls from the different wagtail apps
@@ -21,7 +22,7 @@
2122
url(r'^password_reset/complete/$', account_views.password_reset_complete, name='wagtailadmin_password_reset_complete'),
2223

2324
url(r'^login/$', watch_login(wagtail_account_views.login), name='wagtailadmin_login'),
24-
25+
url(r"^account/change_password/", change_password, name="password_change"),
2526
url(r'^users/(\d+)/$', users.edit, name='wagtailusers_users_edit'),
2627
url(r'^users/new/$', users.create, name='wagtailusers_users_create'),
2728

wagtailenforcer/views/wagtailadmin/__init__.py

Whitespace-only changes.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
from __future__ import absolute_import, unicode_literals
2+
3+
from functools import wraps
4+
5+
from django.conf import settings
6+
from django.contrib import messages
7+
from django.utils.translation import ugettext as _
8+
from django.contrib.auth import update_session_auth_hash
9+
from django.contrib.auth.forms import PasswordChangeForm
10+
from django.http import Http404
11+
from django.shortcuts import redirect, render
12+
13+
from wagtail.utils.compat import user_is_authenticated
14+
from wagtailenforcer.forms import wagtailadmin
15+
from wagtail.wagtailadmin.utils import get_available_admin_languages
16+
from wagtail.wagtailcore.models import UserPagePermissionsProxy
17+
18+
from wagtail.wagtailusers.models import UserProfile
19+
20+
from password_policies.conf import settings
21+
from password_policies.forms import PasswordPoliciesChangeForm
22+
from password_policies.forms.fields import PasswordPoliciesField
23+
24+
25+
# Helper functions to check password management settings to enable/disable views as appropriate.
26+
# These are functions rather than class-level constants so that they can be overridden in tests
27+
# by override_settings
28+
29+
30+
def password_management_enabled():
31+
return getattr(settings, "WAGTAIL_PASSWORD_MANAGEMENT_ENABLED", True)
32+
33+
34+
def change_password(request):
35+
if not password_management_enabled():
36+
raise Http404
37+
38+
can_change_password = request.user.has_usable_password()
39+
40+
if can_change_password:
41+
if request.method == 'POST':
42+
form = PasswordPoliciesChangeForm(request.user, request.POST)
43+
44+
if form.is_valid():
45+
form.save()
46+
update_session_auth_hash(request, form.user)
47+
48+
messages.success(request, _("Your password has been changed successfully!"))
49+
return redirect('wagtailadmin_account')
50+
else:
51+
form = PasswordPoliciesChangeForm(request.user)
52+
else:
53+
form = None
54+
55+
return render(request, 'wagtailadmin/account/change_password.html', {
56+
'form': form,
57+
'can_change_password': can_change_password,
58+
})

0 commit comments

Comments
 (0)