Commit 2e905dc7 by Piotr Mitros

More of e-mail change process works

parent 1457c21f
...@@ -30,13 +30,14 @@ class UserProfile(models.Model): ...@@ -30,13 +30,14 @@ class UserProfile(models.Model):
meta = models.CharField(blank=True, max_length=255) # JSON dictionary for future expansion meta = models.CharField(blank=True, max_length=255) # JSON dictionary for future expansion
courseware = models.CharField(blank=True, max_length=255, default='course.xml') courseware = models.CharField(blank=True, max_length=255, default='course.xml')
def get_meta(): def get_meta(self):
try: try:
js = json.reads(self.meta) js = json.reads(self.meta)
except: except:
js = dict() js = dict()
return json return js
def set_meta(js):
def set_meta(self,js):
self.meta = json.dumps(js) self.meta = json.dumps(js)
## TODO: Should be renamed to generic UserGroup, and possibly ## TODO: Should be renamed to generic UserGroup, and possibly
......
...@@ -2,6 +2,7 @@ import json ...@@ -2,6 +2,7 @@ import json
import logging import logging
import random import random
import string import string
import uuid
from django.conf import settings from django.conf import settings
from django.contrib.auth import logout, authenticate, login from django.contrib.auth import logout, authenticate, login
...@@ -15,7 +16,7 @@ from django.http import HttpResponse, Http404 ...@@ -15,7 +16,7 @@ from django.http import HttpResponse, Http404
from django.shortcuts import redirect from django.shortcuts import redirect
from mitxmako.shortcuts import render_to_response, render_to_string 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 from django_future.csrf import ensure_csrf_cookie
log = logging.getLogger("mitx.user") log = logging.getLogger("mitx.user")
...@@ -330,12 +331,13 @@ def change_email_request(request): ...@@ -330,12 +331,13 @@ def change_email_request(request):
d = {'site':settings.SITE_NAME, d = {'site':settings.SITE_NAME,
'key':pec.activation_key, 'key':pec.activation_key,
'old_email' : user.email, 'old_email' : user.email,
'new_email' : pec.email} 'new_email' : pec.new_email}
subject = render_to_string('emails/email_change_subject.txt',d) subject = render_to_string('emails/email_change_subject.txt',d)
subject = ''.join(subject.splitlines())
message = render_to_string('emails/email_change.txt',d) 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})) return HttpResponse(json.dumps({'success':True}))
...@@ -349,14 +351,17 @@ def confirm_email_change(request, key): ...@@ -349,14 +351,17 @@ def confirm_email_change(request, key):
except: except:
return render_to_response("email_invalid_key.html") 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()) subject = ''.join(subject.splitlines())
message = render_to_string('emails/confirm_email_change.txt',d) 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 ) up = UserProfile.objects.get( user = user )
meta = up.get_meta() meta = up.get_meta()
print meta
if 'old_emails' not in meta: if 'old_emails' not in meta:
meta['old_emails'] = [] meta['old_emails'] = []
meta['old_emails'].append(user.email) meta['old_emails'].append(user.email)
...@@ -365,8 +370,9 @@ def confirm_email_change(request, key): ...@@ -365,8 +370,9 @@ def confirm_email_change(request, key):
user.email = pec.new_email user.email = pec.new_email
user.save() user.save()
pec.delete() 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 @ensure_csrf_cookie
def change_name_request(request): def change_name_request(request):
......
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
We received a request to change the e-mail associated with MITx We received a request to change the e-mail associated with your MITx
account ${username} from ${old_email} to ${new_email}. If this is account from ${old_email} to ${new_email}. If this is correct, please
correct, please confirm your new e-mail address by visiting: 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 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 receive any more email from us. Please do not reply to this e-mail; if
......
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
...@@ -79,18 +79,23 @@ $(function() { ...@@ -79,18 +79,23 @@ $(function() {
}); });
$("#submit_email_change").click(function(){ $("#change_email_form").submit(function(){
alert("Test 1");
var new_email = $('#new_email_field').val(); var new_email = $('#new_email_field').val();
var new_password = $('#new_email_password').val(); var new_password = $('#new_email_password').val();
postJSON('/email_change/',{"new_email":new_email}, postJSON('/change_email',{"new_email":new_email,
function(data){}); "password":new_password},
alert("Test 2"); 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", log_event("profile", {"type":"email_change_request",
"old_email":"${email}", "old_email":"${email}",
"new_email":new_email}); "new_email":new_email});
alert("Test 3"); return false;
}); });
}); });
...@@ -201,7 +206,8 @@ $(function() { ...@@ -201,7 +206,8 @@ $(function() {
<div id="apply_name_change" class="leanModal_box"> <div id="apply_name_change" class="leanModal_box">
<h1>Apply to change your name</h1> <h1>Apply to change your name</h1>
<form> <form id="change_name_form">
<div id="change_name_error"> </div>
<fieldset> <fieldset>
<p>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.</p> <p>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.</p>
...@@ -224,8 +230,8 @@ $(function() { ...@@ -224,8 +230,8 @@ $(function() {
<div id="change_email" class="leanModal_box"> <div id="change_email" class="leanModal_box">
<h1>Change e-mail</h1> <h1>Change e-mail</h1>
<form> <form id="change_email_form">
<div id="change_email_error"> </div>
<fieldset> <fieldset>
<ul> <ul>
<li> <li>
...@@ -249,7 +255,8 @@ $(function() { ...@@ -249,7 +255,8 @@ $(function() {
<div id="unenroll_course" class="leanModal_box"> <div id="unenroll_course" class="leanModal_box">
<h1> Unenroll </h1> <h1> Unenroll </h1>
<p> 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: </p> <p> 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: </p>
<form> <form id="unenroll_form">
<div id="unenroll_error"> </div>
<fieldset> <fieldset>
<ul> <ul>
<li> <li>
......
...@@ -9,8 +9,8 @@ import django.contrib.auth.views ...@@ -9,8 +9,8 @@ import django.contrib.auth.views
urlpatterns = ('', urlpatterns = ('',
url(r'^$', 'student.views.index'), # Main marketing page, or redirect to courseware url(r'^$', 'student.views.index'), # Main marketing page, or redirect to courseware
url(r'^email_change$', 'student.views.change_email_request'), url(r'^change_email$', 'student.views.change_email_request'),
url(r'^email_confirm$', 'student.views.change_email_confirm'), url(r'^email_confirm/(?P<key>[^/]*)$', 'student.views.confirm_email_change'),
url(r'^gradebook$', 'courseware.views.gradebook'), url(r'^gradebook$', 'courseware.views.gradebook'),
url(r'^event$', 'track.views.user_track'), url(r'^event$', 'track.views.user_track'),
url(r'^t/(?P<template>[^/]*)$', 'static_template_view.views.index'), url(r'^t/(?P<template>[^/]*)$', 'static_template_view.views.index'),
......
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