From 0efcf25f0554319fbbded9207c04692d1e1832f5 Mon Sep 17 00:00:00 2001 From: Nikolai Kristiansen Date: Mon, 10 Oct 2011 21:40:26 +0200 Subject: [PATCH] Password change and reset function with templates. Try reusing https://docs.djangoproject.com/en/dev/topics/auth/#module-django.contrib.auth.views to greatest extent. --- main/forms.py | 7 ++++++- templates/public/index.html | 4 ++++ templates/registration/password_change_done.html | 7 +++++++ templates/registration/password_change_form.html | 12 ++++++++++++ .../registration/password_reset_complete.html | 5 +++++ templates/registration/password_reset_confirm.html | 14 ++++++++++++++ templates/registration/password_reset_done.html | 7 +++++++ templates/registration/password_reset_email.html | 2 ++ templates/registration/password_reset_form.html | 12 ++++++++++++ templates/registration/password_reset_subject.txt | 1 + urls.py | 9 +++++++-- 11 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 templates/registration/password_change_done.html create mode 100644 templates/registration/password_reset_complete.html create mode 100644 templates/registration/password_reset_confirm.html create mode 100644 templates/registration/password_reset_done.html create mode 100644 templates/registration/password_reset_email.html create mode 100644 templates/registration/password_reset_form.html create mode 100644 templates/registration/password_reset_subject.txt diff --git a/main/forms.py b/main/forms.py index bbb713c..f04a697 100644 --- a/main/forms.py +++ b/main/forms.py @@ -1,3 +1,8 @@ -from django.contrib.auth.forms import PasswordChangeForm +from django.contrib.auth.forms import PasswordChangeForm, SetPasswordForm class LDAPPasswordChangeForm(PasswordChangeForm): + # TODO: Change password here + pass + +class LDAPSetPasswordForm(SetPasswordForm): + # TODO: Set password here pass diff --git a/templates/public/index.html b/templates/public/index.html index ab5f8f9..66438b1 100644 --- a/templates/public/index.html +++ b/templates/public/index.html @@ -1 +1,5 @@ +{% extends "base.html" %} +{% block content %} {{request.user}}s profile +Forgot password? +{% endblock %} diff --git a/templates/registration/password_change_done.html b/templates/registration/password_change_done.html new file mode 100644 index 0000000..51add04 --- /dev/null +++ b/templates/registration/password_change_done.html @@ -0,0 +1,7 @@ +{% extends "base.html" %} +{% block title %}Change password done{% endblock %} +{% block content %} +

+The page shown after a user has changed their password. +

+{% endblock %} diff --git a/templates/registration/password_change_form.html b/templates/registration/password_change_form.html index e69de29..efe1bee 100644 --- a/templates/registration/password_change_form.html +++ b/templates/registration/password_change_form.html @@ -0,0 +1,12 @@ +{% extends "base.html" %} +{% block title %}Change password{% endblock %} +{% block content %} +

+Allows a user to change their password. +

+
+{{form}} + +
+{% endblock %} + diff --git a/templates/registration/password_reset_complete.html b/templates/registration/password_reset_complete.html new file mode 100644 index 0000000..3c67b27 --- /dev/null +++ b/templates/registration/password_reset_complete.html @@ -0,0 +1,5 @@ +{% extends "base.html" %} +{% block title %}Password reset complete{% endblock %} +{% block content %} +The page shown after a user has been emailed a link to reset their password. +{% endblock %} diff --git a/templates/registration/password_reset_confirm.html b/templates/registration/password_reset_confirm.html new file mode 100644 index 0000000..7b15828 --- /dev/null +++ b/templates/registration/password_reset_confirm.html @@ -0,0 +1,14 @@ +{% extends "base.html" %} +{% block title %}Password reset confirmation{% endblock %} +{% block content %} +

+Presents a form for entering a new password. +

+{% if validlink %} +
+ {{form}} + +{% else %} + The password reset link is not valid or allready used. +{% endif %} +{% endblock %} diff --git a/templates/registration/password_reset_done.html b/templates/registration/password_reset_done.html new file mode 100644 index 0000000..7fa7a1b --- /dev/null +++ b/templates/registration/password_reset_done.html @@ -0,0 +1,7 @@ +{% extends "base.html" %} +{% block title %}Password reset done{% endblock %} +{% block content %} +

+The page shown after a user has been emailed a link to reset their password. +

+{% endblock %} diff --git a/templates/registration/password_reset_email.html b/templates/registration/password_reset_email.html new file mode 100644 index 0000000..ac12a26 --- /dev/null +++ b/templates/registration/password_reset_email.html @@ -0,0 +1,2 @@ +Someone asked for password reset for email {{ email }}. Follow the link below: +{{ protocol }}://{{ site_name }}{% url 'auth_password_reset_confirm' uidb36=uid token=token %} diff --git a/templates/registration/password_reset_form.html b/templates/registration/password_reset_form.html new file mode 100644 index 0000000..5c5f040 --- /dev/null +++ b/templates/registration/password_reset_form.html @@ -0,0 +1,12 @@ +{% extends "base.html" %} +{% block title %}Reset password{% endblock %} +{% block content %} +

+Allows a user to reset their password by generating a one-time use link that can be used to reset the password, and sending that link to the user's registered email address. + + {{ form }} + +

+

+{% endblock %} + diff --git a/templates/registration/password_reset_subject.txt b/templates/registration/password_reset_subject.txt new file mode 100644 index 0000000..5e162fb --- /dev/null +++ b/templates/registration/password_reset_subject.txt @@ -0,0 +1 @@ +[neuf-userinfo] Reset password diff --git a/urls.py b/urls.py index d6f65eb..5af0857 100644 --- a/urls.py +++ b/urls.py @@ -1,17 +1,22 @@ from django.conf.urls.defaults import * from django.contrib import admin -from main.forms import LDAPPasswordChangeForm +from main.forms import LDAPPasswordChangeForm, LDAPSetPasswordForm admin.autodiscover() urlpatterns = patterns('', (r'^admin/', include(admin.site.urls)), (r'^admin/doc/', include('django.contrib.admindocs.urls')), (r'^accounts/$', 'main.views.profile'), - (r'^accounts/logout/$', 'django.contrib.auth.views.logout'), (r'^accounts/password/change$', 'django.contrib.auth.views.password_change', {'password_change_form': LDAPPasswordChangeForm}), (r'^accounts/password/change/done$', 'django.contrib.auth.views.password_change_done'), + (r'^accounts/password/reset$', 'django.contrib.auth.views.password_reset'), + (r'^accounts/password/reset/done$', 'django.contrib.auth.views.password_reset_done'), + (r'^accounts/password/reset/confirm$', 'django.contrib.auth.views.password_reset_confirm', + {'set_password_form': LDAPSetPasswordForm}), + (r'^accounts/password/reset/complete$', 'django.contrib.auth.views.password_reset_complete'), (r'^accounts/login/$', 'django.contrib.auth.views.login'), + (r'^accounts/logout/$', 'django.contrib.auth.views.logout'), (r'^accounts/(?P)/', 'main.views.profile'), (r'^$', 'main.views.index'), )