Registering now temporarily logs you in. A message is displayed on the dashboard, reminding you to activate your account. Logging in shows a reminder about activating.
This commit is contained in:
@@ -83,7 +83,6 @@ def index(request):
|
|||||||
@login_required
|
@login_required
|
||||||
@ensure_csrf_cookie
|
@ensure_csrf_cookie
|
||||||
def dashboard(request):
|
def dashboard(request):
|
||||||
csrf_token = csrf(request)['csrf_token']
|
|
||||||
user = request.user
|
user = request.user
|
||||||
enrollments = CourseEnrollment.objects.filter(user=user)
|
enrollments = CourseEnrollment.objects.filter(user=user)
|
||||||
|
|
||||||
@@ -101,8 +100,13 @@ def dashboard(request):
|
|||||||
except ItemNotFoundError:
|
except ItemNotFoundError:
|
||||||
log.error("User {0} enrolled in non-existant course {1}"
|
log.error("User {0} enrolled in non-existant course {1}"
|
||||||
.format(user.username, enrollment.course_id))
|
.format(user.username, enrollment.course_id))
|
||||||
|
|
||||||
|
|
||||||
|
message = ""
|
||||||
|
if not user.is_active:
|
||||||
|
message = render_to_string('registration/activate_account_notice.html', {'email': user.email})
|
||||||
|
|
||||||
context = {'csrf': csrf_token, 'courses': courses}
|
context = {'courses': courses, 'message' : message}
|
||||||
return render_to_response('dashboard.html', context)
|
return render_to_response('dashboard.html', context)
|
||||||
|
|
||||||
|
|
||||||
@@ -112,7 +116,7 @@ def login_user(request, error=""):
|
|||||||
''' AJAX request to log in the user. '''
|
''' AJAX request to log in the user. '''
|
||||||
if 'email' not in request.POST or 'password' not in request.POST:
|
if 'email' not in request.POST or 'password' not in request.POST:
|
||||||
return HttpResponse(json.dumps({'success': False,
|
return HttpResponse(json.dumps({'success': False,
|
||||||
'error': 'Invalid login'})) # TODO: User error message
|
'value': 'There was an error receiving your login information. Please email us.'})) # TODO: User error message
|
||||||
|
|
||||||
email = request.POST['email']
|
email = request.POST['email']
|
||||||
password = request.POST['password']
|
password = request.POST['password']
|
||||||
@@ -121,14 +125,14 @@ def login_user(request, error=""):
|
|||||||
except User.DoesNotExist:
|
except User.DoesNotExist:
|
||||||
log.warning("Login failed - Unknown user email: {0}".format(email))
|
log.warning("Login failed - Unknown user email: {0}".format(email))
|
||||||
return HttpResponse(json.dumps({'success': False,
|
return HttpResponse(json.dumps({'success': False,
|
||||||
'error': 'Invalid login'})) # TODO: User error message
|
'value': 'Email or password is incorrect.'})) # TODO: User error message
|
||||||
|
|
||||||
username = user.username
|
username = user.username
|
||||||
user = authenticate(username=username, password=password)
|
user = authenticate(username=username, password=password)
|
||||||
if user is None:
|
if user is None:
|
||||||
log.warning("Login failed - password for {0} is invalid".format(email))
|
log.warning("Login failed - password for {0} is invalid".format(email))
|
||||||
return HttpResponse(json.dumps({'success': False,
|
return HttpResponse(json.dumps({'success': False,
|
||||||
'error': 'Invalid login'}))
|
'value': 'Email or password is incorrect.'}))
|
||||||
|
|
||||||
if user is not None and user.is_active:
|
if user is not None and user.is_active:
|
||||||
try:
|
try:
|
||||||
@@ -147,7 +151,7 @@ def login_user(request, error=""):
|
|||||||
|
|
||||||
log.warning("Login failed - Account not active for user {0}".format(username))
|
log.warning("Login failed - Account not active for user {0}".format(username))
|
||||||
return HttpResponse(json.dumps({'success':False,
|
return HttpResponse(json.dumps({'success':False,
|
||||||
'error': 'Account not active. Check your e-mail.'}))
|
'value': 'This account has not been activated. Please check your e-mail for the activation instructions.'}))
|
||||||
|
|
||||||
@ensure_csrf_cookie
|
@ensure_csrf_cookie
|
||||||
def logout_user(request):
|
def logout_user(request):
|
||||||
@@ -275,10 +279,15 @@ def create_account(request, post_override=None):
|
|||||||
log.exception(sys.exc_info())
|
log.exception(sys.exc_info())
|
||||||
js['value'] = 'Could not send activation e-mail.'
|
js['value'] = 'Could not send activation e-mail.'
|
||||||
return HttpResponse(json.dumps(js))
|
return HttpResponse(json.dumps(js))
|
||||||
|
|
||||||
js={'success': True,
|
# Immediately after a user creates an account, we log them in. They are only
|
||||||
'value': render_to_string('registration/reg_complete.html', {'email': post_vars['email'],
|
# logged in until they close the browser. They can't log in again until they click
|
||||||
'csrf': csrf(request)['csrf_token']})}
|
# the activation link from the email.
|
||||||
|
login_user = authenticate(username=post_vars['username'], password = post_vars['password'] )
|
||||||
|
login(request, login_user)
|
||||||
|
request.session.set_expiry(0)
|
||||||
|
|
||||||
|
js={'success': True}
|
||||||
return HttpResponse(json.dumps(js), mimetype="application/json")
|
return HttpResponse(json.dumps(js), mimetype="application/json")
|
||||||
|
|
||||||
def create_random_account(create_account_function):
|
def create_random_account(create_account_function):
|
||||||
|
|||||||
@@ -9,6 +9,10 @@
|
|||||||
<%block name="title"><title>Dashboard</title></%block>
|
<%block name="title"><title>Dashboard</title></%block>
|
||||||
|
|
||||||
<section class="container dashboard">
|
<section class="container dashboard">
|
||||||
|
|
||||||
|
<section class="dashboard-banner">
|
||||||
|
${message}
|
||||||
|
</section>
|
||||||
|
|
||||||
<section class="profile-sidebar">
|
<section class="profile-sidebar">
|
||||||
<header class="profile">
|
<header class="profile">
|
||||||
|
|||||||
@@ -1,34 +0,0 @@
|
|||||||
<!-- TODO: http://docs.jquery.com/Plugins/Validation -->
|
|
||||||
<div id="login_div">
|
|
||||||
<header>
|
|
||||||
<h1>Log in to <span class="edx">edX</span></h1>
|
|
||||||
<p class="no-account">If you don’t have an account yet, <a href="#enroll" rel="leanModal">please enroll here</a></p>
|
|
||||||
</header>
|
|
||||||
<!--[if lte IE 9]>
|
|
||||||
<p class="ie-warning">You are using a browser that is not supported by <span class="edx">edX</span>, and you might not be able to complete pieces of the course. Please download the latest version of <a href="http://www.mozilla.org/en-US/firefox/new/">Firefox</a> or <a href="https://www.google.com/chrome">Chrome</a> to get the full experience.</p>
|
|
||||||
<![endif]-->
|
|
||||||
|
|
||||||
<form id="login_form" method="post">
|
|
||||||
<ol>
|
|
||||||
<li>
|
|
||||||
<label>E-mail*</label>
|
|
||||||
<input name="email" id="li_email" type="email" required>
|
|
||||||
</li>
|
|
||||||
|
|
||||||
<li>
|
|
||||||
<label>Password*</label>
|
|
||||||
<input name="password" id="li_password" type="password" required>
|
|
||||||
</li>
|
|
||||||
|
|
||||||
<li class="remember">
|
|
||||||
<label><input name="remember" id="remember" type="checkbox">Remember me</label>
|
|
||||||
</li>
|
|
||||||
|
|
||||||
</ol>
|
|
||||||
<input name="submit" id="login_button" type="submit" value="Log in">
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<div class="lost-password">
|
|
||||||
<div id="lost_password"><a class="" rel="leanModal" href="#pwd_reset">Lost password?</a></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
@@ -44,9 +44,9 @@
|
|||||||
location.href="${reverse('dashboard')}";
|
location.href="${reverse('dashboard')}";
|
||||||
} else {
|
} else {
|
||||||
if($('#login_error').length == 0) {
|
if($('#login_error').length == 0) {
|
||||||
$('#login_form').prepend('<div id="login_error" class="modal-form-error">Email or password is incorrect.</div>');
|
$('#login_form').prepend('<div id="login_error" class="modal-form-error"></div>');
|
||||||
}
|
}
|
||||||
$('#login_error').stop().css("display", "block");
|
$('#login_error').html(json.value).stop().css("display", "block");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})(this)
|
})(this)
|
||||||
|
|||||||
@@ -1,178 +0,0 @@
|
|||||||
<%! from django.core.urlresolvers import reverse %>
|
|
||||||
<%namespace name='static' file='static_content.html'/>
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title><%block name="title">MITx: MIT's new online learning initiative</%block></title>
|
|
||||||
|
|
||||||
<meta name="description" content="<%block name="description">MITx will offer a portfolio of MIT courses for free to a virtual community of learners around the world</%block>" />
|
|
||||||
|
|
||||||
<meta name="keywords" content="<%block name="keywords">MITx, online learning, MIT, online laboratory, education, learners, undergraduate, certificate</%block>" />
|
|
||||||
|
|
||||||
<!--link rel="stylesheet" href="${ settings.LIB_URL }jquery.treeview.css" type="text/css" media="all" /-->
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
|
||||||
|
|
||||||
<script type="text/javascript" src="${static.url('js/jquery.min.js')}"></script>
|
|
||||||
<script type="text/javascript" src="${static.url('js/jquery-ui.min.js')}"></script>
|
|
||||||
|
|
||||||
<script type="text/javascript" src="${static.url('js/jquery.leanModal.min.js')}"></script>
|
|
||||||
<!--script type="text/javascript" src="${static.url('js/swfobject/swfobject.js')}"></script-->
|
|
||||||
<!--script type="text/javascript" src="${static.url('js/jquery.treeview.js')}"></script-->
|
|
||||||
<!--script type="text/javascript" src="${static.url('js/video_player.js')}"></script-->
|
|
||||||
<!-- <script type="text/javascript" src="${static.url('js/schematic.js')}"></script> -->
|
|
||||||
|
|
||||||
<script src="${static.url('js/html5shiv.js')}"></script>
|
|
||||||
|
|
||||||
<%block name="headextra"/>
|
|
||||||
|
|
||||||
<script type="text/javascript">
|
|
||||||
function getCookie(name) {
|
|
||||||
var cookieValue = null;
|
|
||||||
if (document.cookie && document.cookie != '') {
|
|
||||||
var cookies = document.cookie.split(';');
|
|
||||||
for (var i = 0; i < cookies.length; i++) {
|
|
||||||
var cookie = jQuery.trim(cookies[i]);
|
|
||||||
// Does this cookie string begin with the name we want?
|
|
||||||
if (cookie.substring(0, name.length + 1) == (name + '=')) {
|
|
||||||
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return cookieValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
function postJSON(url, data, callback) {
|
|
||||||
$.ajax({type:'POST',
|
|
||||||
url: url,
|
|
||||||
dataType: 'json',
|
|
||||||
data: data,
|
|
||||||
success: callback,
|
|
||||||
headers : {'X-CSRFToken':getCookie('csrftoken')}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<%block name="header">
|
|
||||||
<header class="announcement <%block name="header_class"/>">
|
|
||||||
<div class="anouncement-wrapper">
|
|
||||||
<%block name="header_nav">
|
|
||||||
<nav>
|
|
||||||
<h1><a href="http://mitx.mit.edu/">MITx</a></h1>
|
|
||||||
% if settings.COURSEWARE_ENABLED:
|
|
||||||
<%block name="login_area">
|
|
||||||
<a rel="leanModal" class="login" href="#login">Log In</a>
|
|
||||||
</%block>
|
|
||||||
% endif
|
|
||||||
</nav>
|
|
||||||
</%block>
|
|
||||||
|
|
||||||
<%block name="header_text">
|
|
||||||
<section>
|
|
||||||
<h1><em>MITx</em></h1>
|
|
||||||
<h2>MIT’s new online learning initiative</h2>
|
|
||||||
</section>
|
|
||||||
</%block>
|
|
||||||
</div>
|
|
||||||
</header>
|
|
||||||
</%block>
|
|
||||||
|
|
||||||
${self.body()}
|
|
||||||
<%block name="bodyextra"/>
|
|
||||||
|
|
||||||
<footer>
|
|
||||||
<div class="footer-wrapper">
|
|
||||||
<p> Copyright © 2012. MIT. <a href="${reverse('copyright')}">Some rights reserved.</a></p>
|
|
||||||
|
|
||||||
<ul>
|
|
||||||
<li><a href="${reverse('tos')}">Terms of Service</a></li>
|
|
||||||
<li><a href="${reverse('privacy')}">Privacy Policy</a></li>
|
|
||||||
<li><a href="${reverse('honor')}">Honor Code</a></li>
|
|
||||||
<li><a href="${reverse('help_edx')}">Help</a></li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<ul aria-label="Social Links" class="social">
|
|
||||||
<li class="linkedin">
|
|
||||||
<a href="http://www.linkedin.com/groups/Friends-Alumni-MITx-4316538">Linked In</a>
|
|
||||||
</li>
|
|
||||||
<li class="twitter">
|
|
||||||
<a href="https://twitter.com/#!/MyMITx">Twitter</a>
|
|
||||||
</li>
|
|
||||||
<li class="facebook">
|
|
||||||
<a href="http://www.facebook.com/pages/MITx/378592442151504">Facebook</a>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</footer>
|
|
||||||
|
|
||||||
% if settings.COURSEWARE_ENABLED:
|
|
||||||
<div id="login" class="leanModal_box"><%include file="login.html" /></div>
|
|
||||||
% endif
|
|
||||||
<div id="pwd_reset" class="leanModal_box"><%include file="password_reset_form.html" /></div>
|
|
||||||
<div id="reset_done" class="leanModal_box"></div>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
$(document).ready(function(){
|
|
||||||
/* Handles when the user tries to log in. Grabs form data. Does AJAX.
|
|
||||||
Either shows error, or redirects. */
|
|
||||||
$('form#login_form').submit(function(e) {
|
|
||||||
e.preventDefault();
|
|
||||||
var submit_data={};
|
|
||||||
$.each($("[id^=li_]"), function(index,value){
|
|
||||||
submit_data[value.name]=value.value;
|
|
||||||
});
|
|
||||||
submit_data["remember"] = ($('#remember').attr("checked")? true : false);
|
|
||||||
|
|
||||||
postJSON('/login',
|
|
||||||
submit_data,
|
|
||||||
function(json) {
|
|
||||||
if(json.success) {
|
|
||||||
location.href="/info";
|
|
||||||
} else if($('#login_error').length == 0) {
|
|
||||||
$('#login_form').prepend('<div id="login_error">Email or password is incorrect.</div>');
|
|
||||||
} else {
|
|
||||||
$('#login_error').stop().css("background-color", "#933").animate({ backgroundColor: "#333"}, 2000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
$('form#pwd_reset_form').submit(function(e) {
|
|
||||||
e.preventDefault();
|
|
||||||
var submit_data = {};
|
|
||||||
submit_data['email'] = $('#id_email').val();
|
|
||||||
postJSON('/password_reset/',
|
|
||||||
submit_data,
|
|
||||||
function(json){
|
|
||||||
if (json.success) {
|
|
||||||
$('#pwd_reset').html(json.value);
|
|
||||||
} else {
|
|
||||||
$('#pwd_error').html(json.error).stop().css("background-color", "#933").animate({ backgroundColor: "#333"}, 2000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
$(function(){
|
|
||||||
$("a[rel*=leanModal]").leanModal();
|
|
||||||
|
|
||||||
$("a.login").click(function(){
|
|
||||||
$("#login_form #li_email").focus();
|
|
||||||
});
|
|
||||||
|
|
||||||
$("a.enroll").click(function(){
|
|
||||||
$("#enroll_form #ca_email").focus();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<%block name="js_extra"/>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
3
lms/templates/registration/activate_account_notice.html
Normal file
3
lms/templates/registration/activate_account_notice.html
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<h2>Thanks For Registering!</h2>
|
||||||
|
<p class='activation-message'>Your account is not active yet. An activation link has been sent to <strong>${ email }</strong>, along with
|
||||||
|
instructions for activating your account.</p>
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
<header>
|
|
||||||
<h2>Thanks For Registering!</h2>
|
|
||||||
<hr>
|
|
||||||
</header>
|
|
||||||
|
|
||||||
<p class='activation-message'>Please check your email. An activation link has been sent to <strong>${ email }</strong>, along with
|
|
||||||
instructions for activating your account.</p>
|
|
||||||
@@ -121,7 +121,7 @@
|
|||||||
(function() {
|
(function() {
|
||||||
$(document).delegate('#enroll_form', 'ajax:success', function(data, json, xhr) {
|
$(document).delegate('#enroll_form', 'ajax:success', function(data, json, xhr) {
|
||||||
if(json.success) {
|
if(json.success) {
|
||||||
$('#enroll').html(json.value);
|
location.href="${reverse('dashboard')}";
|
||||||
} else {
|
} else {
|
||||||
$('#enroll_error').html(json.value).stop().css("display", "block");
|
$('#enroll_error').html(json.value).stop().css("display", "block");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user