From 9c672f7bd078e7099fccb60478010b6959d64cd5 Mon Sep 17 00:00:00 2001 From: Matthew Mongeau Date: Tue, 17 Jul 2012 13:47:49 -0400 Subject: [PATCH] Hook up forms for forgot password functionality. --- .../coffee/src/views/forgot_password.coffee | 0 lms/static/js/form.ext.js | 43 +++++++++++++++++++ lms/static/sass/shared/_modal.scss | 2 +- lms/templates/forgot_password_modal.html | 34 +++++++++++++++ lms/templates/login_modal.html | 41 +++++------------- lms/templates/main.html | 1 + lms/templates/navigation.html | 1 + lms/templates/signup_modal.html | 36 +++------------- lms/urls.py | 2 +- 9 files changed, 98 insertions(+), 62 deletions(-) create mode 100644 lms/static/coffee/src/views/forgot_password.coffee create mode 100644 lms/static/js/form.ext.js create mode 100644 lms/templates/forgot_password_modal.html diff --git a/lms/static/coffee/src/views/forgot_password.coffee b/lms/static/coffee/src/views/forgot_password.coffee new file mode 100644 index 0000000000..e69de29bb2 diff --git a/lms/static/js/form.ext.js b/lms/static/js/form.ext.js new file mode 100644 index 0000000000..417992a622 --- /dev/null +++ b/lms/static/js/form.ext.js @@ -0,0 +1,43 @@ +(function($, undefined) { + var form_ext; + $.form_ext = form_ext = { + ajax: function(options) { + return $.ajax(options); + }, + handleRemote: function(element) { + var method = element.attr('method'); + var url = element.attr('action'); + var data = element.serializeArray(); + var options = { + type: method || 'GET', + data: data, + success: function(data, status, xhr) { + element.trigger("ajax:success", [data, status, xhr]); + }, + complete: function(xhr, status) { + element.trigger("ajax:complete", [xhr, status]); + }, + error: function(xhr, status, error) { + element.trigger("ajax:error", [xhr, status, error]); + } + } + if(url) { options.url = url; } + return form_ext.ajax(options) + }, + CSRFProtection: function(xhr) { + var token = $.cookie('csrftoken'); + if (token) xhr.setRequestHeader('X-CSRFToken', token); + }, + } + $.ajaxPrefilter(function(options, originalOptions, xhr){ if ( !options.crossDomain ) { form_ext.CSRFProtection(xhr); }}); + $(document).delegate('form', 'submit', function(e) { + var form = $(this), + remote = form.data("remote") !== undefined; + + if(remote) { + form_ext.handleRemote(form); + return false; + } + + }); +})(jQuery); diff --git a/lms/static/sass/shared/_modal.scss b/lms/static/sass/shared/_modal.scss index 4a3bed4859..84c57a847c 100644 --- a/lms/static/sass/shared/_modal.scss +++ b/lms/static/sass/shared/_modal.scss @@ -106,7 +106,7 @@ } } - #enroll_error, #login_error { + .modal-form-error { background: $error-red; border: 1px solid rgb(202, 17, 17); color: rgb(143, 14, 14); diff --git a/lms/templates/forgot_password_modal.html b/lms/templates/forgot_password_modal.html new file mode 100644 index 0000000000..18ec20ff04 --- /dev/null +++ b/lms/templates/forgot_password_modal.html @@ -0,0 +1,34 @@ +<%! from django.core.urlresolvers import reverse %> + + + diff --git a/lms/templates/login_modal.html b/lms/templates/login_modal.html index b13e3a2a0e..28d116c9de 100644 --- a/lms/templates/login_modal.html +++ b/lms/templates/login_modal.html @@ -8,7 +8,7 @@
-
+ @@ -25,7 +25,7 @@ @@ -39,36 +39,15 @@ diff --git a/lms/templates/main.html b/lms/templates/main.html index 43f6e9e4f7..fc1dd93beb 100644 --- a/lms/templates/main.html +++ b/lms/templates/main.html @@ -20,6 +20,7 @@ + ## TODO (cpennington): Remove this when we have a good way for modules to specify js to load on the page ## and in the wiki diff --git a/lms/templates/navigation.html b/lms/templates/navigation.html index 4665ba5c0d..435d2c27da 100644 --- a/lms/templates/navigation.html +++ b/lms/templates/navigation.html @@ -51,4 +51,5 @@ %if not user.is_authenticated(): <%include file="login_modal.html" /> <%include file="signup_modal.html" /> + <%include file="forgot_password_modal.html" /> %endif diff --git a/lms/templates/signup_modal.html b/lms/templates/signup_modal.html index df546c6b77..30393c8241 100644 --- a/lms/templates/signup_modal.html +++ b/lms/templates/signup_modal.html @@ -9,7 +9,7 @@
- +
@@ -77,34 +77,12 @@ diff --git a/lms/urls.py b/lms/urls.py index 2cc1b88971..8261fef3be 100644 --- a/lms/urls.py +++ b/lms/urls.py @@ -28,7 +28,7 @@ urlpatterns = ('', url(r'^create_account$', 'student.views.create_account'), url(r'^activate/(?P[^/]*)$', 'student.views.activate_account'), # url(r'^reactivate/(?P[^/]*)$', 'student.views.reactivation_email'), - url(r'^password_reset/$', 'student.views.password_reset'), + url(r'^password_reset/$', 'student.views.password_reset', name='password_reset'), ## Obsolete Django views for password resets ## TODO: Replace with Mako-ized views url(r'^password_change/$', django.contrib.auth.views.password_change,