diff --git a/djadmin2/core.py b/djadmin2/core.py
index fe6c181..4fef83b 100644
--- a/djadmin2/core.py
+++ b/djadmin2/core.py
@@ -4,6 +4,7 @@ WARNING: This file about to undergo major refactoring by @pydanny per Issue #99.
from django.conf.urls import patterns, include, url
from django.conf import settings
+from django.contrib.auth.decorators import login_required
from django.core.exceptions import ImproperlyConfigured
from django.utils.importlib import import_module
@@ -135,7 +136,21 @@ class Admin2(object):
view=self.api_index_view.as_view(**self.get_api_index_kwargs()),
name='api-index'
),
+
+ url(regex=r'^password_change/$',
+ regex=rlogin_required(views.PasswordChangeView.as_view()),
+ name='password-change'
+ ),
+ url(regex=r'^password_change_done/$',
+ login_required(views.PasswordChangeDoneView.as_view()),
+ name='password-change-done'
+ ),
+ url(regex=r'^logout/$',
+ login_required(views.LogoutView.as_view()),
+ name='logout'
+ ),
)
+
for model, model_admin in self.registry.iteritems():
model_options = utils.model_options(model)
urlpatterns += patterns('',
diff --git a/djadmin2/templates/admin2/bootstrap/auth/login.html b/djadmin2/templates/admin2/bootstrap/auth/login.html
new file mode 100644
index 0000000..e69de29
diff --git a/djadmin2/templates/admin2/bootstrap/auth/logout.html b/djadmin2/templates/admin2/bootstrap/auth/logout.html
new file mode 100644
index 0000000..e2a30f4
--- /dev/null
+++ b/djadmin2/templates/admin2/bootstrap/auth/logout.html
@@ -0,0 +1,13 @@
+{% extends "admin2/bootstrap/base.html" %}
+
+{% load i18n %}
+{% load admin2_tags %}
+
+{% block content %}
+
+{% endblock content %}
diff --git a/djadmin2/templates/admin2/bootstrap/auth/password_change_done.html b/djadmin2/templates/admin2/bootstrap/auth/password_change_done.html
new file mode 100644
index 0000000..1478ceb
--- /dev/null
+++ b/djadmin2/templates/admin2/bootstrap/auth/password_change_done.html
@@ -0,0 +1,15 @@
+{% extends "admin2/bootstrap/base.html" %}
+
+{% load i18n %}
+{% load admin2_tags %}
+
+{% block title %}{% trans 'Password change successful' %}{% endblock %}
+{% block page_title %}{% trans 'Password change successful' %}{% endblock %}
+
+{% block content %}
+
+
+
{% trans 'Your password was changed.' %}
+
+
+{% endblock content %}
diff --git a/djadmin2/templates/admin2/bootstrap/auth/password_change_form.html b/djadmin2/templates/admin2/bootstrap/auth/password_change_form.html
new file mode 100644
index 0000000..d976718
--- /dev/null
+++ b/djadmin2/templates/admin2/bootstrap/auth/password_change_form.html
@@ -0,0 +1,27 @@
+{% extends "admin2/bootstrap/base.html" %}
+
+{% load i18n %}
+{% load admin2_tags %}
+
+{% block page_title %}{% trans "Password change" %}{% endblock %}
+
+{% block content %}
+
+
+
Please enter your old password, for security's sake, and then enter your new password twice so we can verify you typed it in correctly.
+
+ {% if form.errors %}
+
+ {% blocktrans count counter=form.errors.items|length %}Please correct the error below.{% plural %}Please correct the errors below.{% endblocktrans %}
+
+ {% endif %}
+
+
+
+
+
+{% endblock content %}
diff --git a/djadmin2/templates/admin2/bootstrap/base.html b/djadmin2/templates/admin2/bootstrap/base.html
index bbe98b1..ec7684f 100644
--- a/djadmin2/templates/admin2/bootstrap/base.html
+++ b/djadmin2/templates/admin2/bootstrap/base.html
@@ -13,16 +13,16 @@
-
Django-Admin2
+
Django-Admin2
diff --git a/djadmin2/tests/test_core.py b/djadmin2/tests/test_core.py
index f7f97f3..df549fc 100644
--- a/djadmin2/tests/test_core.py
+++ b/djadmin2/tests/test_core.py
@@ -32,4 +32,4 @@ class Admin2Test(TestCase):
def test_get_urls(self):
self.admin2.register(Thing)
- self.assertEquals(5, len(self.admin2.get_urls()))
+ self.assertEquals(7, len(self.admin2.get_urls()))
diff --git a/djadmin2/views.py b/djadmin2/views.py
index 7c129f7..ccb62a5 100644
--- a/djadmin2/views.py
+++ b/djadmin2/views.py
@@ -1,4 +1,8 @@
-from django.core.urlresolvers import reverse
+from django.contrib.auth.forms import PasswordChangeForm
+from django.contrib.auth.views import logout
+from django.contrib.auth import get_user_model
+
+from django.core.urlresolvers import reverse, reverse_lazy
from django.http import HttpResponseRedirect
from django.utils.encoding import force_text
from django.utils.text import capfirst
@@ -128,3 +132,38 @@ class ModelDeleteView(AdminModel2Mixin, generic.DeleteView):
'deletable_objects': collector.nested(_format_callback)
})
return context
+
+
+class PasswordChangeView(Admin2Mixin, generic.UpdateView):
+
+ default_template_name = 'auth/password_change_form.html'
+ form_class = PasswordChangeForm
+ model = get_user_model()
+ success_url = reverse_lazy('admin2:password-change-done')
+
+ def get_form_kwargs(self, **kwargs):
+ data = {'user': self.get_object()}
+
+ if self.request.method in ('POST', 'PUT'):
+ data.update({
+ 'data': self.request.POST
+ })
+
+ return data
+
+ def get_object(self, **kwargs):
+ return self.request.user
+
+
+class PasswordChangeDoneView(Admin2Mixin, generic.TemplateView):
+
+ default_template_name = 'auth/password_change_done.html'
+
+
+class LogoutView(Admin2Mixin, generic.TemplateView):
+
+ default_template_name = 'auth/logout.html'
+
+ def get(self, request, *args, **kwargs):
+ return logout(request, template_name=self.get_template_names(),
+ *args, **kwargs)