From 60b547273d1892462db87f76cdf6f97977dc24c5 Mon Sep 17 00:00:00 2001 From: Bridger Maxwell Date: Sat, 21 Jul 2012 15:31:48 -0400 Subject: [PATCH] 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. --- common/djangoapps/student/views.py | 29 ++- lms/templates/dashboard.html | 4 + lms/templates/login.html | 34 ---- lms/templates/login_modal.html | 4 +- lms/templates/marketing.html | 178 ------------------ .../registration/activate_account_notice.html | 3 + lms/templates/registration/reg_complete.html | 7 - lms/templates/signup_modal.html | 2 +- 8 files changed, 29 insertions(+), 232 deletions(-) delete mode 100644 lms/templates/login.html delete mode 100644 lms/templates/marketing.html create mode 100644 lms/templates/registration/activate_account_notice.html delete mode 100644 lms/templates/registration/reg_complete.html diff --git a/common/djangoapps/student/views.py b/common/djangoapps/student/views.py index 9d2ea93049..003500b48e 100644 --- a/common/djangoapps/student/views.py +++ b/common/djangoapps/student/views.py @@ -83,7 +83,6 @@ def index(request): @login_required @ensure_csrf_cookie def dashboard(request): - csrf_token = csrf(request)['csrf_token'] user = request.user enrollments = CourseEnrollment.objects.filter(user=user) @@ -101,8 +100,13 @@ def dashboard(request): except ItemNotFoundError: log.error("User {0} enrolled in non-existant course {1}" .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) @@ -112,7 +116,7 @@ def login_user(request, error=""): ''' AJAX request to log in the user. ''' if 'email' not in request.POST or 'password' not in request.POST: 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'] password = request.POST['password'] @@ -121,14 +125,14 @@ def login_user(request, error=""): except User.DoesNotExist: log.warning("Login failed - Unknown user email: {0}".format(email)) 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 user = authenticate(username=username, password=password) if user is None: log.warning("Login failed - password for {0} is invalid".format(email)) return HttpResponse(json.dumps({'success': False, - 'error': 'Invalid login'})) + 'value': 'Email or password is incorrect.'})) if user is not None and user.is_active: try: @@ -147,7 +151,7 @@ def login_user(request, error=""): log.warning("Login failed - Account not active for user {0}".format(username)) 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 def logout_user(request): @@ -275,10 +279,15 @@ def create_account(request, post_override=None): log.exception(sys.exc_info()) js['value'] = 'Could not send activation e-mail.' return HttpResponse(json.dumps(js)) - - js={'success': True, - 'value': render_to_string('registration/reg_complete.html', {'email': post_vars['email'], - 'csrf': csrf(request)['csrf_token']})} + + # Immediately after a user creates an account, we log them in. They are only + # logged in until they close the browser. They can't log in again until they click + # 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") def create_random_account(create_account_function): diff --git a/lms/templates/dashboard.html b/lms/templates/dashboard.html index a12b8c2f37..e7b295732f 100644 --- a/lms/templates/dashboard.html +++ b/lms/templates/dashboard.html @@ -9,6 +9,10 @@ <%block name="title">Dashboard
+ +
+ ${message} +
diff --git a/lms/templates/login.html b/lms/templates/login.html deleted file mode 100644 index 0ab5206073..0000000000 --- a/lms/templates/login.html +++ /dev/null @@ -1,34 +0,0 @@ - -
-
-

Log in to edX

- -
- - -
-
    -
  1. - - -
  2. - -
  3. - - -
  4. - -
  5. - -
  6. - -
- -
- - -
diff --git a/lms/templates/login_modal.html b/lms/templates/login_modal.html index 28d116c9de..0d23a477f6 100644 --- a/lms/templates/login_modal.html +++ b/lms/templates/login_modal.html @@ -44,9 +44,9 @@ location.href="${reverse('dashboard')}"; } else { if($('#login_error').length == 0) { - $('#login_form').prepend(''); + $('#login_form').prepend(''); } - $('#login_error').stop().css("display", "block"); + $('#login_error').html(json.value).stop().css("display", "block"); } }); })(this) diff --git a/lms/templates/marketing.html b/lms/templates/marketing.html deleted file mode 100644 index a0d53802b5..0000000000 --- a/lms/templates/marketing.html +++ /dev/null @@ -1,178 +0,0 @@ -<%! from django.core.urlresolvers import reverse %> -<%namespace name='static' file='static_content.html'/> - - - - <%block name="title">MITx: MIT's new online learning initiative</%block> - - MITx will offer a portfolio of MIT courses for free to a virtual community of learners around the world" /> - - MITx, online learning, MIT, online laboratory, education, learners, undergraduate, certificate" /> - - - - - - - - - - - - - - - - <%block name="headextra"/> - - - - - - - <%block name="header"> -
"> -
- <%block name="header_nav"> - - - - <%block name="header_text"> -
-

MITx

-

MIT’s new online learning initiative

-
- -
-
- - - ${self.body()} - <%block name="bodyextra"/> - - - - % if settings.COURSEWARE_ENABLED: -
<%include file="login.html" />
- % endif -
<%include file="password_reset_form.html" />
-
- - - - <%block name="js_extra"/> - - diff --git a/lms/templates/registration/activate_account_notice.html b/lms/templates/registration/activate_account_notice.html new file mode 100644 index 0000000000..ca051902b1 --- /dev/null +++ b/lms/templates/registration/activate_account_notice.html @@ -0,0 +1,3 @@ +

Thanks For Registering!

+

Your account is not active yet. An activation link has been sent to ${ email }, along with +instructions for activating your account.

diff --git a/lms/templates/registration/reg_complete.html b/lms/templates/registration/reg_complete.html deleted file mode 100644 index aea7e6df1a..0000000000 --- a/lms/templates/registration/reg_complete.html +++ /dev/null @@ -1,7 +0,0 @@ -
-

Thanks For Registering!

-
-
- -

Please check your email. An activation link has been sent to ${ email }, along with -instructions for activating your account.

diff --git a/lms/templates/signup_modal.html b/lms/templates/signup_modal.html index ee59f40396..acbba87eab 100644 --- a/lms/templates/signup_modal.html +++ b/lms/templates/signup_modal.html @@ -121,7 +121,7 @@ (function() { $(document).delegate('#enroll_form', 'ajax:success', function(data, json, xhr) { if(json.success) { - $('#enroll').html(json.value); + location.href="${reverse('dashboard')}"; } else { $('#enroll_error').html(json.value).stop().css("display", "block"); }