From 05c5ac34828ebc3b84a6110fa9a92da48352b291 Mon Sep 17 00:00:00 2001 From: David Ormsbee Date: Thu, 11 Oct 2012 11:04:18 -0400 Subject: [PATCH 1/9] Allow people who haven't activated to reset their password. --- common/djangoapps/student/views.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/common/djangoapps/student/views.py b/common/djangoapps/student/views.py index b19833bbed..bca8ff9d76 100644 --- a/common/djangoapps/student/views.py +++ b/common/djangoapps/student/views.py @@ -517,6 +517,17 @@ def password_reset(request): ''' Attempts to send a password reset e-mail. ''' if request.method != "POST": raise Http404 + + # By default, Django doesn't allow Users with is_active = False to reset their passwords, + # but this bites people who signed up a long time ago, never activated, and forgot their + # password. So for their sake, we'll auto-activate a user for whome password_reset is called. + try: + user = User.objects.get(email=request.POST['email']) + user.is_active = True + user.save() + except: + log.exception("Tried to auto-activate user to enable password reset, but failed.") + form = PasswordResetForm(request.POST) if form.is_valid(): form.save(use_https = request.is_secure(), @@ -541,10 +552,6 @@ def reactivation_email(request): return HttpResponse(json.dumps({'success': False, 'error': 'No inactive user with this e-mail exists'})) - if user.is_active: - return HttpResponse(json.dumps({'success': False, - 'error': 'User is already active'})) - reg = Registration.objects.get(user=user) reg.register(user) From 96bdd03406896746db38f1daabfc80a1a44a5b6a Mon Sep 17 00:00:00 2001 From: David Ormsbee Date: Fri, 12 Oct 2012 09:54:47 -0400 Subject: [PATCH 2/9] re-enable email change functionality --- lms/templates/dashboard.html | 119 ++++++++++++++++++++++++++++++----- lms/urls.py | 2 +- 2 files changed, 104 insertions(+), 17 deletions(-) diff --git a/lms/templates/dashboard.html b/lms/templates/dashboard.html index 6be72277cc..9b59dc2cd9 100644 --- a/lms/templates/dashboard.html +++ b/lms/templates/dashboard.html @@ -16,19 +16,46 @@ $(".unenroll").click(function(event) { $("#unenroll_course_id").val( $(event.target).data("course-id") ); $("#unenroll_course_number").text( $(event.target).data("course-number") ); - }); - $(document).delegate('#unenroll_form', 'ajax:success', function(data, json, xhr) { - if(json.success) { - location.href="${reverse('dashboard')}"; - } else { - if($('#unenroll_error').length == 0) { - $('#unenroll_form').prepend(''); - } - $('#unenroll_error').text(json.error).stop().css("display", "block"); - } - }); + $(document).delegate('#unenroll_form', 'ajax:success', function(data, json, xhr) { + if(json.success) { + location.href="${reverse('dashboard')}"; + } else { + if($('#unenroll_error').length == 0) { + $('#unenroll_form').prepend(''); + } + $('#unenroll_error').text(json.error).stop().css("display", "block"); + } + }); + + $('#pwd_reset_button').click(function() { + $.post('${reverse("password_reset")}', + {"email" : $('#id_email').val()}, + function(data){ + $("#password_reset_complete_link").click(); + }); + }); + + $("#change_email_form").submit(function(){ + var new_email = $('#new_email_field').val(); + var new_password = $('#new_email_password').val(); + + $.post('${reverse("change_email")}', + {"new_email" : new_email, "password" : new_password}, + function(data) { + if (data.success) { + $("#change_email_title").html("Please verify your new email"); + $("#change_email_body").html("

You'll receive a confirmation in your " + + "in-box. Please click the link in the " + + "email to confirm the email change.

"); + } else { + $("#change_email_error").html(data.error); + } + }); + return false; + }); + })(this) @@ -48,10 +75,17 @@ @@ -121,13 +155,11 @@ - - + + + diff --git a/lms/urls.py b/lms/urls.py index 662e41235e..ac61b85248 100644 --- a/lms/urls.py +++ b/lms/urls.py @@ -19,7 +19,7 @@ urlpatterns = ('', # (specifically missing get parameters in certain cases) url(r'^debug_request$', 'util.views.debug_request'), - url(r'^change_email$', 'student.views.change_email_request'), + url(r'^change_email$', 'student.views.change_email_request', name="change_email"), url(r'^email_confirm/(?P[^/]*)$', 'student.views.confirm_email_change'), url(r'^change_name$', 'student.views.change_name_request'), url(r'^accept_name_change$', 'student.views.accept_name_change'), From 01ac01b62ca00ba99140ef4c32633935e68cb33f Mon Sep 17 00:00:00 2001 From: David Ormsbee Date: Fri, 12 Oct 2012 14:31:20 -0400 Subject: [PATCH 3/9] Re-enable change name, and fix up change email styles --- common/djangoapps/student/views.py | 25 +++-- lms/templates/dashboard.html | 103 +++++++++++++++------ lms/templates/email_change_successful.html | 2 +- lms/urls.py | 2 +- 4 files changed, 93 insertions(+), 39 deletions(-) diff --git a/common/djangoapps/student/views.py b/common/djangoapps/student/views.py index bca8ff9d76..a2369574d2 100644 --- a/common/djangoapps/student/views.py +++ b/common/djangoapps/student/views.py @@ -672,9 +672,12 @@ def change_name_request(request): pnc.rationale = request.POST['rationale'] if len(pnc.new_name) < 2: return HttpResponse(json.dumps({'success': False, 'error': 'Name required'})) - if len(pnc.rationale) < 2: - return HttpResponse(json.dumps({'success': False, 'error': 'Rationale required'})) pnc.save() + + # The following automatically accepts name change requests. Remove this to + # go back to the old system where it gets queued up for admin approval. + accept_name_change_by_id(pnc.id) + return HttpResponse(json.dumps({'success': True})) @@ -709,14 +712,9 @@ def reject_name_change(request): return HttpResponse(json.dumps({'success': True})) -@ensure_csrf_cookie -def accept_name_change(request): - ''' JSON: Name change process. Course staff clicks 'accept' on a given name change ''' - if not request.user.is_staff: - raise Http404 - +def accept_name_change_by_id(id): try: - pnc = PendingNameChange.objects.get(id=int(request.POST['id'])) + pnc = PendingNameChange.objects.get(id=id) except PendingNameChange.DoesNotExist: return HttpResponse(json.dumps({'success': False, 'error': 'Invalid ID'})) @@ -735,3 +733,12 @@ def accept_name_change(request): pnc.delete() return HttpResponse(json.dumps({'success': True})) + + +@ensure_csrf_cookie +def accept_name_change(request): + ''' JSON: Name change process. Course staff clicks 'accept' on a given name change ''' + if not request.user.is_staff: + raise Http404 + + return accept_name_change_by_id(int(request.POST['id'])) diff --git a/lms/templates/dashboard.html b/lms/templates/dashboard.html index 9b59dc2cd9..3fdcbb5c1c 100644 --- a/lms/templates/dashboard.html +++ b/lms/templates/dashboard.html @@ -46,16 +46,33 @@ function(data) { if (data.success) { $("#change_email_title").html("Please verify your new email"); - $("#change_email_body").html("

You'll receive a confirmation in your " + + $("#change_email_form").html("

You'll receive a confirmation in your " + "in-box. Please click the link in the " + "email to confirm the email change.

"); } else { - $("#change_email_error").html(data.error); + $("#change_email_error").html(data.error).stop().css("display", "block"); } }); return false; }); + $("#change_name_form").submit(function(){ + var new_name = $('#new_name_field').val(); + var rationale = $('#name_rationale_field').val(); + + $.post('${reverse("change_name")}', + {"new_name":new_name, "rationale":rationale}, + function(data) { + if(data.success) { + location.reload(); + // $("#change_name_body").html("

Name changed.

"); + } else { + $("#change_name_error").html(data.error).stop().css("display", "block"); + } + }); + return false; + }); + })(this) @@ -75,13 +92,13 @@