diff --git a/djangoapps/student/views.py b/djangoapps/student/views.py index 7612ad50d4..5983ccab12 100644 --- a/djangoapps/student/views.py +++ b/djangoapps/student/views.py @@ -308,7 +308,7 @@ def change_email_request(request): new_email = request.POST['new_email'] if len(User.objects.filter(email = new_email)) != 0: - ## CRITICAL TODO: Handle case for e-mails + ## CRITICAL TODO: Handle case sensitivity for e-mails return HttpResponse(json.dumps({'success':False, 'error':'An account with this e-mail already exists.'})) @@ -349,13 +349,17 @@ def confirm_email_change(request, key): try: pec=PendingEmailChange.objects.get(activation_key=key) except: - return render_to_response("email_invalid_key.html") + return render_to_response("invalid_email_key.html", {}) user = pec.user d = {'site':settings.SITE_NAME, 'old_email' : user.email, 'new_email' : pec.new_email} + if len(User.objects.filter(email = pec.new_email)) != 0: + return render_to_response("email_exists.html", d) + + subject = render_to_string('emails/email_change_subject.txt',d) subject = ''.join(subject.splitlines()) message = render_to_string('emails/confirm_email_change.txt',d) @@ -383,6 +387,10 @@ def change_name_request(request): pnc.user = request.User pnc.new_name = request.POST['new_name'] 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() return HttpResponse(json.dumps({'success':True})) diff --git a/templates/emails/confirm_email_change.txt b/templates/emails/confirm_email_change.txt index fecd0f8975..148b973384 100644 --- a/templates/emails/confirm_email_change.txt +++ b/templates/emails/confirm_email_change.txt @@ -3,4 +3,7 @@ from ${old_email} to ${new_email}. If you did not make this request, please contact the course staff immediately. Contact information is listed at: - https://6002x.mitx.mit.edu/t/mitx_help.html + https://${sitename}/t/mitx_help.html + +We keep a log of old e-mails, so if this request was unintentional, we +can investigate. diff --git a/templates/profile.html b/templates/profile.html index 59152893be..9b79ce9780 100644 --- a/templates/profile.html +++ b/templates/profile.html @@ -98,6 +98,25 @@ $(function() { return false; }); + $("#change_name_form").submit(function(){ + var new_name = $('#new_name_field').val(); + var rationale = $('#name_rationale_field').val(); + + postJSON('/change_email',{"new_name":new_name, + "rationale":rationale}, + function(data){ + if(data.success){ + $("#change_email").html("Request submitted. We'll send you an e-mail if we approve the change or need further information."); + } else { + $("#change_email_error").html(data.error); + } + }); + log_event("profile", {"type":"name_change_request", + "new_name":new_name, + "rationale":rationale}); + return false; + }); + }); %block> @@ -214,11 +233,11 @@ $(function() {