Commit 2b173379 by Piotr Mitros

E-mail changes appear to work

parent 2e905dc7
......@@ -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}))
......
......@@ -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.
......@@ -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;
});
});
</script>
</%block>
......@@ -214,11 +233,11 @@ $(function() {
<ul>
<li>
<label>Enter your desired full name, as it will appear on the MITx Certificate: </label>
<input id="new_name" value="" type="text" />
<input id="new_name_field" value="" type="text" />
</li>
<li>
<label>Reason for name change:</label>
<textarea id="name_rationale" value=""></textarea>
<textarea id="name_rationale_field" value=""></textarea>
</li>
<li>
<input type="submit" id="submit">
......
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