Skip to content

Commit 73f00aa

Browse files
committed
Enabled the check for existing account, disabled when we started using self-service http password reset, but hadn't started creating accounts yet. Refactored the two confirm*() methods in ietfauth/views.py; they need the same processing, only the templates to use differ.
- Legacy-Id: 4583
1 parent fbf89cd commit 73f00aa

2 files changed

Lines changed: 12 additions & 20 deletions

File tree

ietf/ietfauth/forms.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ def clean_email(self):
4444
email = self.cleaned_data.get('email', '')
4545
if not email:
4646
return email
47-
# if User.objects.filter(username=email).count():
48-
# raise forms.ValidationError(_('Email already in use'))
47+
if User.objects.filter(username=email).count():
48+
raise forms.ValidationError(_('An account with the email address you provided already exists.'))
4949
return email
5050

5151

@@ -80,7 +80,7 @@ class PasswordForm(forms.Form):
8080

8181
def __init__(self, *args, **kwargs):
8282
self.username = kwargs.pop('username')
83-
self.update_user = kwargs.pop('update_user', False)
83+
self.update_user = User.objects.filter(username=self.username).count() > 0
8484
super(PasswordForm, self).__init__(*args, **kwargs)
8585

8686
def clean_password2(self):

ietf/ietfauth/views.py

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ def create_account(request):
114114
context_instance=RequestContext(request))
115115

116116

117-
def confirm_account(request, username, date, realm, registration_hash):
118-
valid = hashlib.md5('%s%s%s%s' % (settings.SECRET_KEY, date, username, realm)).hexdigest() == registration_hash
117+
def process_confirmation(request, username, date, realm, hash):
118+
valid = hashlib.md5('%s%s%s%s' % (settings.SECRET_KEY, date, username, realm)).hexdigest() == hash
119119
if not valid:
120120
raise Http404
121121
request_date = datetime.date(int(date[:4]), int(date[4:6]), int(date[6:]))
@@ -125,11 +125,14 @@ def confirm_account(request, username, date, realm, registration_hash):
125125
if request.method == 'POST':
126126
form = PasswordForm(request.POST, username=username)
127127
if form.is_valid():
128-
form.save()
129-
# TODO: Add the user in the htdigest file
128+
form.save() # Also updates the httpd password file
130129
success = True
131130
else:
132131
form = PasswordForm(username=username)
132+
return form, username, success
133+
134+
def confirm_account(request, username, date, realm, hash):
135+
form, username, success = process_confirmation(request, username, date, realm, hash)
133136
return render_to_response('registration/confirm.html',
134137
{'form': form, 'email': username, 'success': success},
135138
context_instance=RequestContext(request))
@@ -151,19 +154,8 @@ def password_reset_view(request):
151154
context_instance=RequestContext(request))
152155

153156

154-
def confirm_password_reset(request, username, date, realm, reset_hash):
155-
valid = hashlib.md5('%s%s%s%s' % (settings.SECRET_KEY, date, username, realm)).hexdigest() == reset_hash
156-
if not valid:
157-
raise Http404
158-
success = False
159-
if request.method == 'POST':
160-
form = PasswordForm(request.POST, update_user=True, username=username)
161-
if form.is_valid():
162-
form.save()
163-
# TODO: Update the user in the htdigest file
164-
success = True
165-
else:
166-
form = PasswordForm(username=username)
157+
def confirm_password_reset(request, username, date, realm, hash):
158+
form, username, success = process_confirmation(request, username, date, realm, hash)
167159
return render_to_response('registration/change_password.html',
168160
{'form': form,
169161
'success': success,

0 commit comments

Comments
 (0)