# HG changeset patch # User Brian Neal # Date 1378069125 18000 # Node ID 4a49d4ac319fb25c99ac9f61f1984d66405794b7 # Parent 81e0be69b3a54b5c6eca9e786bb3d1e9f8c7e7d3 For #51, remove the ajax popup login window. diff -r 81e0be69b3a5 -r 4a49d4ac319f accounts/static/js/ajax_login.js --- a/accounts/static/js/ajax_login.js Sun Sep 01 11:59:28 2013 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,82 +0,0 @@ -$(function() { - var loginError = $('#login-error'); - var userBox = $('#ajax-login-username'); - var passBox = $('#ajax-login-password'); - var loginDialog = $('#login-dialog').dialog({ - autoOpen: false, - height: 375, - width: 380, - modal: true, - buttons: [ - { - id: "login-button", - text: "Login", - click: function() { - loginError.text('').hide(); - $("#login-button").button("disable"); - $.ajax({ - url: '/accounts/login/ajax/', - type: 'POST', - data: { - username: userBox.val(), - password: passBox.val(), - csrfmiddlewaretoken: csrf_token - }, - dataType: 'json', - success: function(data, textStatus) { - $("#login-button").button("enable"); - if (data.success) { - loginDialog.dialog("close"); - if (window.location.pathname == "/accounts/logout/") { - window.location.replace("/"); - } - else { - $('#header-nav').html(data.navbar_html); - } - } - else { - loginError.text(data.error).show(); - userBox.val(''); - passBox.val(''); - userBox.focus(); - } - }, - error: function (xhr, textStatus, ex) { - $("#login-button").button("enable"); - if (xhr.status == 403) { - loginDialog.dialog("close"); - alert("Oops, we are detecting some strange behavior and are blocking this action. If you feel this is an error, please feel free to contact us. Thank you."); - window.location.href = "/"; - } - else { - loginError.text('Oops, an error occurred. If this problem persists, please contact us.').show(); - } - } - }); - } - }, - { - id: "cancel-button", - text: "Cancel", - click: function() { - loginDialog.dialog("close"); - } - } - ], - focus: function() { - $(':input', this).keyup(function(event) { - if (event.keyCode == 13) { - var loginButton = $("#login-button"); - if (!loginButton.button("option", "disabled")) { - loginButton.click(); - } - } - }); - } - }); - $('#login-link').click(function() { - loginError.text('').hide(); - loginDialog.dialog("open"); - return false; - }); -}); diff -r 81e0be69b3a5 -r 4a49d4ac319f accounts/urls.py --- a/accounts/urls.py Sun Sep 01 11:59:28 2013 -0500 +++ b/accounts/urls.py Sun Sep 01 15:58:45 2013 -0500 @@ -4,7 +4,6 @@ from django.views.generic import TemplateView urlpatterns = patterns('accounts.views', - url(r'^login/ajax/$', 'login_ajax', name='accounts-login_ajax'), url(r'^register/$', 'register', name='accounts-register'), (r'^register/thanks/$', 'register_thanks'), (r'^register/confirm/(?P[\w.@+-]{1,30})/(?P[a-zA-Z0-9]{20})/$', 'register_confirm'), diff -r 81e0be69b3a5 -r 4a49d4ac319f accounts/views.py --- a/accounts/views.py Sun Sep 01 11:59:28 2013 -0500 +++ b/accounts/views.py Sun Sep 01 15:58:45 2013 -0500 @@ -2,17 +2,12 @@ Views for the accounts application. """ -import json import logging from django.shortcuts import render -from django.template import RequestContext -from django.template.loader import render_to_string -from django.http import HttpResponse, HttpResponseRedirect +from django.http import HttpResponseRedirect from django.core.urlresolvers import reverse from django.conf import settings -from django.contrib.auth.forms import AuthenticationForm -from django.contrib.auth import login from accounts.models import PendingUser from accounts.forms import RegisterForm, ForgotUsernameForm @@ -80,35 +75,6 @@ ####################################################################### -@log_auth_failures('Login') -def login_ajax(request): - """ - This view function handles a login via AJAX. - - """ - if not request.is_ajax(): - return HttpResponseRedirect(reverse('accounts-login')) - - response = { - 'success': False, - 'error': '', - 'navbar_html': '' - } - - if request.method == "POST": - form = AuthenticationForm(data=request.POST) - if form.is_valid(): - login(request, form.get_user()) - response['success'] = True - response['navbar_html'] = render_to_string('navbar.html', - {'user': request.user}, RequestContext(request)) - else: - response['error'] = 'Invalid username or password' - - return HttpResponse(json.dumps(response), content_type='application/json') - -####################################################################### - def username_query(request): """This view handles forgotten username queries.""" if request.user.is_authenticated(): diff -r 81e0be69b3a5 -r 4a49d4ac319f antispam/decorators.py --- a/antispam/decorators.py Sun Sep 01 11:59:28 2013 -0500 +++ b/antispam/decorators.py Sun Sep 01 15:58:45 2013 -0500 @@ -2,7 +2,6 @@ This module contains decorators for the antispam application. """ -import json from functools import wraps import logging @@ -19,16 +18,10 @@ if request.method == 'POST': - # Figure out if the view succeeded; if it is a non-ajax view, - # then success means a redirect is about to occur. If it is - # an ajax view, we have to decode the json response. - success = False - if not request.is_ajax(): - success = (response and response.has_header('location') and - response.status_code == 302) - elif response: - json_resp = json.loads(response.content) - success = json_resp['success'] + # Figure out if the view succeeded; success means a redirect is + # about to occur. + success = (response and response.has_header('location') and + response.status_code == 302) if not success: username = request.POST.get('username') diff -r 81e0be69b3a5 -r 4a49d4ac319f sg101/templates/accounts/ajax_login_form.html --- a/sg101/templates/accounts/ajax_login_form.html Sun Sep 01 11:59:28 2013 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,17 +0,0 @@ -
-

-
-
- -
- - -
-
-
    -
  • Forgot your username? You can recover it here.
  • -
  • Forgot your password? You can reset it here.
  • -
  • Don't have an account? Why don't you register?
  • -
  • Having problems? Please contact us.
  • -
-
diff -r 81e0be69b3a5 -r 4a49d4ac319f sg101/templates/base.html --- a/sg101/templates/base.html Sun Sep 01 11:59:28 2013 -0500 +++ b/sg101/templates/base.html Sun Sep 01 15:58:45 2013 -0500 @@ -34,11 +34,6 @@ -{% if not user.is_authenticated %} -{% script_tags "jquery-ui" %} - - -{% endif %} {% block begin_body %}{% endblock %}
@@ -122,9 +117,6 @@
-{% if not user.is_authenticated %} - {% include "accounts/ajax_login_form.html" %} -{% endif %} {% block end_body %}{% endblock %} diff -r 81e0be69b3a5 -r 4a49d4ac319f sg101/templates/navbar.html --- a/sg101/templates/navbar.html Sun Sep 01 11:59:28 2013 -0500 +++ b/sg101/templates/navbar.html Sun Sep 01 15:58:45 2013 -0500 @@ -7,7 +7,13 @@
  • Search
  • Logout
  • {% else %} -
  • Login
  • +
  • + {% if request.path != "/accounts/logout/" %} + Login + {% else %} + Login + {% endif %} +
  • Register
  • {% endif %}