From 36c8ee73bd230643a28465b270bfc0f84424bad4 Mon Sep 17 00:00:00 2001 From: Fergal Moran Date: Sun, 1 Jun 2014 22:02:48 +0100 Subject: [PATCH] Fixed logout redirect --- spa/urls.py | 1 + spa/views.py | 11 ++++-- static/js/dss/app.coffee | 7 ++++ .../dss/apps/header/views/headerView.coffee | 7 ++-- static/js/dss/lib/controller.coffee | 3 ++ static/js/dss/lib/router.coffee | 1 + static/js/dss/lib/utils.coffee | 39 ++++++++++++------- static/js/dss/templates/header.jst | 9 +---- 8 files changed, 51 insertions(+), 27 deletions(-) diff --git a/spa/urls.py b/spa/urls.py index 74a87b5..3b6481a 100755 --- a/spa/urls.py +++ b/spa/urls.py @@ -45,6 +45,7 @@ urlpatterns = patterns( url(r'^ajax/', include(ajax.urls)), url(r'^debug/', include(debug.urls)), url(r'^audio/', include(audio.urls)), + url(r'^logout/', 'spa.views.logout_user'), url(r'^st/events/', 'spa.static.get_events'), url(r'^api/', include(api.urls)), url(r'^comments/', include('django.contrib.comments.urls')), diff --git a/spa/views.py b/spa/views.py index 1505859..e635e43 100755 --- a/spa/views.py +++ b/spa/views.py @@ -1,6 +1,7 @@ import logging import uuid -from django.http import HttpResponseServerError +from django.contrib.auth import logout +from django.http import HttpResponseServerError, HttpResponseRedirect from django.shortcuts import render_to_response, redirect from django.template import loader, Context from django.template.context import RequestContext @@ -46,6 +47,10 @@ def app(request): context_instance=RequestContext(request)) +def logout_user(request): + logout(request) + return HttpResponseRedirect("/") + def default(request): if 'HTTP_USER_AGENT' in request.META and request.META['HTTP_USER_AGENT'].startswith('facebookexternalhit'): return social_redirect(request) @@ -67,6 +72,6 @@ def debug_500(request, template_name='debug_500.html'): """ t = loader.get_template(template_name) # You need to create a 500.html template. ltype, lvalue, ltraceback = sys.exc_info() - sys.exc_clear() #for fun, and to point out I only -think- this hasn't happened at - #this point in the process already + sys.exc_clear() # for fun, and to point out I only -think- this hasn't happened at + # this point in the process already return HttpResponseServerError(t.render(Context({'type': ltype, 'value': lvalue, 'traceback': ltraceback}))) diff --git a/static/js/dss/app.coffee b/static/js/dss/app.coffee index b3ddbf3..874e4af 100644 --- a/static/js/dss/app.coffee +++ b/static/js/dss/app.coffee @@ -38,6 +38,13 @@ utils.modal "/dlg/LoginView" true + @listenTo @vent, "app:logout", -> + console.log "App(vent): app:logout" + $.get "/logout", (data) -> + window.location.reload(); + return + true + @listenTo @vent, "app:donate", -> console.log("App: donate") utils.modal "/dlg/Donate" diff --git a/static/js/dss/apps/header/views/headerView.coffee b/static/js/dss/apps/header/views/headerView.coffee index d87db22..e8368c4 100644 --- a/static/js/dss/apps/header/views/headerView.coffee +++ b/static/js/dss/apps/header/views/headerView.coffee @@ -6,6 +6,7 @@ "click #header-random-button": "showRandom" "click #header-play-pause-button": "togglePlayState" "click #header-login-button": "login" + "click #header-logout-button": "logout" "click #header-donate-button": "donate" "click #header-live-button.btn-success": "playLive" "click #header-live-button.btn-danger": "pauseLive" @@ -34,12 +35,12 @@ login: -> App.vent.trigger('app:login') + logout: -> + App.vent.trigger('app:logout') + donate: -> App.vent.trigger('app:donate') - logout: -> - utils.showAlert "Success", "You are now logged out" - trackChanged: (data) -> $(@el).find("#track-description").text data.title $(@el).find("#track-description").attr "href", "#" + data.item_url diff --git a/static/js/dss/lib/controller.coffee b/static/js/dss/lib/controller.coffee index 0cc287c..f2f1387 100644 --- a/static/js/dss/lib/controller.coffee +++ b/static/js/dss/lib/controller.coffee @@ -11,6 +11,9 @@ doLogin: -> App.vent.trigger('app:login') + doLogout: -> + App.vent.trigger('app:logout') + showSchedule: -> App.contentRegion.show(new ScheduleShowLayout()) App.vent.trigger('show:schedule:show') diff --git a/static/js/dss/lib/router.coffee b/static/js/dss/lib/router.coffee index 933c165..aa8c78a 100644 --- a/static/js/dss/lib/router.coffee +++ b/static/js/dss/lib/router.coffee @@ -18,6 +18,7 @@ "schedule": "showSchedule", "login": "doLogin" + "logout": "doLogout" "users": "showUserList" "user/:slug/favourites": "showUserFavourites" diff --git a/static/js/dss/lib/utils.coffee b/static/js/dss/lib/utils.coffee index 0a11a46..7300e4c 100644 --- a/static/js/dss/lib/utils.coffee +++ b/static/js/dss/lib/utils.coffee @@ -21,7 +21,7 @@ if url.indexOf("#") is 0 $(url).modal "open" else - $.get(url,(data) -> + $.get(url, (data) -> $(data).modal().on "hidden", -> $(this).remove() true @@ -45,7 +45,7 @@ if url.indexOf("#") is 0 $(url).modal "open" else - $.get(url,(data) -> + $.get(url, (data) -> $(data).modal('show').on("shown.bs.modal", (e) -> $(this).find("#yes-no-positive").click -> success() @@ -64,18 +64,18 @@ toastOptions: -> toastr.options = - closeButton: true - debug: false - positionClass: "toast-bottom-left" - onclick: null - showDuration: "300" - hideDuration: "1000" - timeOut: "5000" - extendedTimeOut: "1000" - showEasing: "swing" - hideEasing: "linear" - showMethod: "fadeIn" - hideMethod: "fadeOut" + closeButton: true + debug: false + positionClass: "toast-bottom-left" + onclick: null + showDuration: "300" + hideDuration: "1000" + timeOut: "5000" + extendedTimeOut: "1000" + showEasing: "swing" + hideEasing: "linear" + showMethod: "fadeIn" + hideMethod: "fadeOut" showError: (title, message) -> @toastOptions() @@ -204,4 +204,15 @@ $.ajaxSetup window.location.replace "/" return +$(document).on "submit", "form[method=post]", -> + console.log("Submitting form") + unless document.cookie.match("csrftoken=([a-zA-Z0-9]{32})") + c = "" + while c.length < 32 + c += "abcdefghijklmnopqrstuvwxyz".charAt(Math.random() * 26) + document.cookie = "csrftoken=" + c + "; path=/" + $(this).append "" unless @csrfmiddlewaretoken + $(@csrfmiddlewaretoken).val document.cookie.match("csrftoken=([a-zA-Z0-9]{32})")[1] + return + diff --git a/static/js/dss/templates/header.jst b/static/js/dss/templates/header.jst index 7edd224..921a50a 100644 --- a/static/js/dss/templates/header.jst +++ b/static/js/dss/templates/header.jst @@ -16,7 +16,7 @@ class="fa fa-cogs fa fa-white">Random
  • Podcast
  • - <% if (com.podnoms.settings.liveEnabled != -1) { %> + <% if (com.podnoms.settings.liveEnabled ) { %>
  •  Listen Live @@ -67,12 +67,7 @@
  • - - + Logout