#214 seperate page for password change

This commit is contained in:
Oskar Hahn 2012-07-01 16:56:01 +02:00
parent 68e26ff8c5
commit e1d13e31ae
4 changed files with 39 additions and 15 deletions

View File

@ -0,0 +1,26 @@
{% extends "base.html" %}
{% load i18n %}
{% block title %}{{ block.super }} - {%trans "Change your Password" %}{% endblock %}
{% block submenu %}
{% endblock %}
{% block content %}
<h1>{% trans "Change your password" %}</h1>
<form action="" method="post">{% csrf_token %}
{{ form.as_p }}
<button class="button" type="submit">
<span class="icon ok">{%trans 'Save' %}</span>
</button>
<a href='{% url item_overview %}'>
<button class="button" type="button" onclick="window.location='{% url item_overview %}'">
<span class="icon cancel">{%trans 'Cancel' %}</span>
</button>
</a>
</form>
<p></p>
{% endblock %}

View File

@ -12,7 +12,6 @@
<form action="" method="post">{% csrf_token %} <form action="" method="post">{% csrf_token %}
{{ form_user.as_p }} {{ form_user.as_p }}
{{ form_password.as_p }}
<button class="button" type="submit"> <button class="button" type="submit">
<span class="icon ok">{%trans 'Save' %}</span> <span class="icon ok">{%trans 'Save' %}</span>
@ -23,5 +22,6 @@
</button> </button>
</a> </a>
</form> </form>
<a href="{% url password_change %}">{% trans 'Change your password' %}</a>
<p></p> <p></p>
{% endblock %} {% endblock %}

View File

@ -26,7 +26,6 @@ from django.shortcuts import redirect
from django.template import RequestContext from django.template import RequestContext
from django.contrib.auth.models import User, Group from django.contrib.auth.models import User, Group
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.contrib.auth.forms import SetPasswordForm
from django.contrib import messages from django.contrib import messages
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.utils.translation import ugettext as _, ungettext from django.utils.translation import ugettext as _, ungettext
@ -299,21 +298,17 @@ def group_delete(request, group_id):
@template('participant/settings.html') @template('participant/settings.html')
def user_settings(request): def user_settings(request):
if request.method == 'POST': if request.method == 'POST':
form_user = UsersettingsForm(request.POST,instance=request.user, prefix='user') form_user = UsersettingsForm(request.POST,instance=request.user)
form_password = SetPasswordForm(request.user,request.POST,prefix='password') if form_user.is_valid():
if form_user.is_valid() and form_password.is_valid():
form_user.save() form_user.save()
form_password.save()
messages.success(request, _('User settings successfully saved.')) messages.success(request, _('User settings successfully saved.'))
else: else:
messages.error(request, _('Please check the form for errors.')) messages.error(request, _('Please check the form for errors.'))
else: else:
form_user = UsersettingsForm(instance=request.user, prefix='user') form_user = UsersettingsForm(instance=request.user)
form_password = SetPasswordForm(request.user,prefix='password')
return { return {
'form_user': form_user, 'form_user': form_user,
'form_password': form_password,
'edituser': request.user, 'edituser': request.user,
} }

View File

@ -11,14 +11,11 @@
""" """
from django.conf.urls.defaults import patterns, url, include from django.conf.urls.defaults import patterns, url, include
#todo: use this in evry file
from django.conf import settings from django.conf import settings
from django.utils.importlib import import_module from django.utils.importlib import import_module
import settings from django.shortcuts import redirect
from utils.views import FrontPage from openslides.utils.views import FrontPage
handler500 = 'openslides.utils.views.server_error' handler500 = 'openslides.utils.views.server_error'
@ -66,9 +63,15 @@ urlpatterns += patterns('',
name='user_logout', name='user_logout',
), ),
url(r'^usersettings$', url(r'^usersettings/$',
'participant.views.user_settings', 'participant.views.user_settings',
name='user_settings', name='user_settings',
), ),
url(r'^usersettings/changepassword/$',
'django.contrib.auth.views.password_change',
{'template_name': 'participant/password_change.html',
'post_change_redirect': '/usersettings/'},
name='password_change',
),
) )