Commit 673d2196 authored by Sofia Papagiannaki's avatar Sofia Papagiannaki
Browse files

Optionally renew token on password reset

Refs: #2612
parent 2fa9f520
......@@ -35,7 +35,8 @@ from datetime import datetime
from django import forms
from django.utils.translation import ugettext as _
from django.contrib.auth.forms import UserCreationForm, AuthenticationForm, PasswordResetForm
from django.contrib.auth.forms import UserCreationForm, AuthenticationForm, \
PasswordResetForm, PasswordChangeForm
from django.core.mail import send_mail
from django.contrib.auth.tokens import default_token_generator
from django.template import Context, loader
......@@ -466,3 +467,22 @@ class InvitationForm(forms.ModelForm):
except Invitation.DoesNotExist:
pass
return username
class ExtendedPasswordChangeForm(PasswordChangeForm):
"""
Extends PasswordChangeForm by enabling user
to optionally renew also the token.
"""
renew = forms.BooleanField(label='Renew token', required=False)
def __init__(self, user, *args, **kwargs):
super(ExtendedPasswordChangeForm, self).__init__(user, *args, **kwargs)
print self.fields.keyOrder
def save(self, commit=True):
user = super(ExtendedPasswordChangeForm, self).save(commit=False)
if self.cleaned_data.get('renew'):
user.renew_token()
if commit:
user.save()
return user
\ No newline at end of file
......@@ -34,7 +34,7 @@
from django.conf.urls.defaults import patterns, include, url
from django.contrib.auth.views import password_change
from astakos.im.forms import ExtendedPasswordResetForm, LoginForm
from astakos.im.forms import ExtendedPasswordResetForm, ExtendedPasswordChangeForm, LoginForm
from astakos.im.settings import IM_MODULES, INVITATIONS_ENABLED, EMAILCHANGE_ENABLED
urlpatterns = patterns('astakos.im.views',
......@@ -73,7 +73,8 @@ if 'local' in IM_MODULES:
url(r'^local/reset/confirm/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/?$',
'password_reset_confirm'),
url(r'^local/password/reset/complete/?$', 'password_reset_complete'),
url(r'^password_change/?$', 'password_change', {'post_change_redirect':'profile'})
url(r'^password_change/?$', 'password_change', {'post_change_redirect':'profile',
'password_change_form':ExtendedPasswordChangeForm})
)
if INVITATIONS_ENABLED:
......
......@@ -532,7 +532,9 @@ def approval_terms(request, term_id=None, template_name='im/approval_terms.html'
@signed_terms_required
def change_password(request):
return password_change(request, post_change_redirect=reverse('astakos.im.views.edit_profile'))
return password_change(request,
post_change_redirect=reverse('astakos.im.views.edit_profile'),
password_change_form=ExtendedPasswordChangeForm)
@transaction.commit_manually
def change_email(request, activation_key=None,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment