diff --git a/djangoapps/student/models.py b/djangoapps/student/models.py index 6810ce6d33..b5b89b3171 100644 --- a/djangoapps/student/models.py +++ b/djangoapps/student/models.py @@ -30,13 +30,14 @@ class UserProfile(models.Model): meta = models.CharField(blank=True, max_length=255) # JSON dictionary for future expansion courseware = models.CharField(blank=True, max_length=255, default='course.xml') - def get_meta(): + def get_meta(self): try: js = json.reads(self.meta) except: js = dict() - return json - def set_meta(js): + return js + + def set_meta(self,js): self.meta = json.dumps(js) ## TODO: Should be renamed to generic UserGroup, and possibly diff --git a/djangoapps/student/views.py b/djangoapps/student/views.py index 754cdf8091..7612ad50d4 100644 --- a/djangoapps/student/views.py +++ b/djangoapps/student/views.py @@ -2,6 +2,7 @@ import json import logging import random import string +import uuid from django.conf import settings from django.contrib.auth import logout, authenticate, login @@ -15,7 +16,7 @@ from django.http import HttpResponse, Http404 from django.shortcuts import redirect from mitxmako.shortcuts import render_to_response, render_to_string -from models import Registration, UserProfile +from models import Registration, UserProfile, PendingNameChange, PendingEmailChange from django_future.csrf import ensure_csrf_cookie log = logging.getLogger("mitx.user") @@ -330,12 +331,13 @@ def change_email_request(request): d = {'site':settings.SITE_NAME, 'key':pec.activation_key, 'old_email' : user.email, - 'new_email' : pec.email} + 'new_email' : pec.new_email} subject = render_to_string('emails/email_change_subject.txt',d) + subject = ''.join(subject.splitlines()) message = render_to_string('emails/email_change.txt',d) - res=send_email(subject, message, settings.DEFAULT_FROM_EMAIL, [pec.email]) + res=send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [pec.new_email]) return HttpResponse(json.dumps({'success':True})) @@ -349,14 +351,17 @@ def confirm_email_change(request, key): except: return render_to_response("email_invalid_key.html") - subject = render_to_string('emails/confirm_email_change_subject.txt',d) + user = pec.user + d = {'site':settings.SITE_NAME, + 'old_email' : user.email, + 'new_email' : pec.new_email} + + subject = render_to_string('emails/email_change_subject.txt',d) subject = ''.join(subject.splitlines()) message = render_to_string('emails/confirm_email_change.txt',d) - - user = pec.user - user.email_user(subject, message, DEFAULT_FROM_EMAIL) up = UserProfile.objects.get( user = user ) meta = up.get_meta() + print meta if 'old_emails' not in meta: meta['old_emails'] = [] meta['old_emails'].append(user.email) @@ -365,8 +370,9 @@ def confirm_email_change(request, key): user.email = pec.new_email user.save() pec.delete() + user.email_user(subject, message, settings.DEFAULT_FROM_EMAIL) - return render_to_response("email_change_successful.html") + return render_to_response("email_change_successful.html", d) @ensure_csrf_cookie def change_name_request(request): diff --git a/templates/emails/confirm_email_change.txt b/templates/emails/confirm_email_change.txt new file mode 100644 index 0000000000..fecd0f8975 --- /dev/null +++ b/templates/emails/confirm_email_change.txt @@ -0,0 +1,6 @@ +This is to confirm that you changed the e-mail associated with MITx +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 diff --git a/templates/emails/email_change.txt b/templates/emails/email_change.txt index 32a21bdf0d..8367f3c1c0 100644 --- a/templates/emails/email_change.txt +++ b/templates/emails/email_change.txt @@ -1,8 +1,8 @@ -We received a request to change the e-mail associated with MITx -account ${username} from ${old_email} to ${new_email}. If this is -correct, please confirm your new e-mail address by visiting: +We received a request to change the e-mail associated with your MITx +account from ${old_email} to ${new_email}. If this is correct, please +confirm your new e-mail address by visiting: -http://${ site }/confirmemail/${ key } +http://${ site }/email_confirm/${ key } If you didn't request this, you don't need to do anything; you won't receive any more email from us. Please do not reply to this e-mail; if diff --git a/templates/emails/email_change_done.txt b/templates/emails/email_change_done.txt deleted file mode 100644 index 50fbb2d4b9..0000000000 --- a/templates/emails/email_change_done.txt +++ /dev/null @@ -1,6 +0,0 @@ -This is to confirm that you changed the e-mail associated with MITx -account ${username} from ${oldemail} to ${newemail}. 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 diff --git a/templates/profile.html b/templates/profile.html index c6bb678be3..59152893be 100644 --- a/templates/profile.html +++ b/templates/profile.html @@ -79,18 +79,23 @@ $(function() { }); - $("#submit_email_change").click(function(){ - alert("Test 1"); + $("#change_email_form").submit(function(){ var new_email = $('#new_email_field').val(); var new_password = $('#new_email_password').val(); - postJSON('/email_change/',{"new_email":new_email}, - function(data){}); - alert("Test 2"); + postJSON('/change_email',{"new_email":new_email, + "password":new_password}, + function(data){ + if(data.success){ + $("#change_email").html("Request submitted. You'll receive a confirmation in your in-box."); + } else { + $("#change_email_error").html(data.error); + } + }); log_event("profile", {"type":"email_change_request", "old_email":"${email}", "new_email":new_email}); - alert("Test 3"); + return false; }); }); @@ -201,7 +206,8 @@ $(function() {

Apply to change your name

-
+ +

A member of the course staff will review your request, and if approved, update your information. Please allow up to a week for your requested to be processed.

@@ -224,8 +230,8 @@ $(function() {

Change e-mail

- - + +
  • @@ -249,7 +255,8 @@ $(function() {

    Unenroll

    At the end of the semester, all students who do not complete the course will be automatically dropped. If you would still prefer to deactivate your account, you can:

    - + +
    • diff --git a/urls.py b/urls.py index 23932db22b..2488e77e24 100644 --- a/urls.py +++ b/urls.py @@ -9,8 +9,8 @@ import django.contrib.auth.views urlpatterns = ('', url(r'^$', 'student.views.index'), # Main marketing page, or redirect to courseware - url(r'^email_change$', 'student.views.change_email_request'), - url(r'^email_confirm$', 'student.views.change_email_confirm'), + url(r'^change_email$', 'student.views.change_email_request'), + url(r'^email_confirm/(?P[^/]*)$', 'student.views.confirm_email_change'), url(r'^gradebook$', 'courseware.views.gradebook'), url(r'^event$', 'track.views.user_track'), url(r'^t/(?P