diff --git a/spa/api/v1/MixResource.py b/spa/api/v1/MixResource.py index a56d5d7..5d425e4 100755 --- a/spa/api/v1/MixResource.py +++ b/spa/api/v1/MixResource.py @@ -7,9 +7,11 @@ from django.template.loader import render_to_string from tastypie import fields from tastypie.authorization import Authorization from tastypie.constants import ALL_WITH_RELATIONS +from tastypie.exceptions import ImmediateHttpResponse from tastypie.fields import ToOneField -from tastypie.http import HttpGone +from tastypie.http import HttpGone, HttpUnauthorized from tastypie.utils import trailing_slash + from spa.api.v1.BackboneCompatibleResource import BackboneCompatibleResource from spa.api.v1.CommentResource import CommentResource from spa.api.v1.ActivityResource import ActivityResource @@ -150,6 +152,10 @@ class MixResource(BackboneCompatibleResource): f_user = request.GET.get('user', None) if request.GET.get('stream'): + if request.user.is_anonymous(): + raise ImmediateHttpResponse( + HttpUnauthorized("Only logged in users have a stream") + ) semi_filtered = semi_filtered.filter( user__in=request.user.get_profile().following.all()) if f_user is not None: diff --git a/static/js/app/appv2.coffee b/static/js/app/appv2.coffee index 15350cc..6ad06be 100755 --- a/static/js/app/appv2.coffee +++ b/static/js/app/appv2.coffee @@ -48,6 +48,7 @@ define ['backbone', 'marionette', 'vent', 'utils', 'underscore', App.addInitializer -> @listenTo vent, "app:login", -> + console.log "App(vent): app:login" utils.modal "/dlg/LoginView" true diff --git a/static/js/app/appv2.js b/static/js/app/appv2.js index 82e3120..a2fd0ef 100755 --- a/static/js/app/appv2.js +++ b/static/js/app/appv2.js @@ -47,6 +47,7 @@ }); App.addInitializer(function() { this.listenTo(vent, "app:login", function() { + console.log("App(vent): app:login"); utils.modal("/dlg/LoginView"); return true; }); diff --git a/static/js/app/lib/utils.coffee b/static/js/app/lib/utils.coffee index 370a3c7..5efd0d4 100755 --- a/static/js/app/lib/utils.coffee +++ b/static/js/app/lib/utils.coffee @@ -1,5 +1,6 @@ define ['jquery', 'bootstrap', 'toastr'], ($, bootstrap, toastr) -> modal: (url) -> + return if $('#modal-header').length if url if url.indexOf("#") is 0 $(url).modal "open" @@ -8,9 +9,6 @@ define ['jquery', 'bootstrap', 'toastr'], ($, bootstrap, toastr) -> $(data).modal().on "hidden", -> $(this).remove() true - $(data).proceed().on "hidden", -> - alert("Go on so") - true ).success -> $("input:text:visible:first").focus() true diff --git a/static/js/app/lib/utils.js b/static/js/app/lib/utils.js index dcf4d08..d1a0ad6 100755 --- a/static/js/app/lib/utils.js +++ b/static/js/app/lib/utils.js @@ -4,19 +4,18 @@ define(['jquery', 'bootstrap', 'toastr'], function($, bootstrap, toastr) { return { modal: function(url) { + if ($('#modal-header').length) { + return; + } if (url) { if (url.indexOf("#") === 0) { $(url).modal("open"); } else { $.get(url, function(data) { - $(data).modal().on("hidden", function() { + return $(data).modal().on("hidden", function() { $(this).remove(); return true; }); - return $(data).proceed().on("hidden", function() { - alert("Go on so"); - return true; - }); }).success(function() { $("input:text:visible:first").focus(); return true; diff --git a/static/js/app/site.js b/static/js/app/site.js index 82b02a7..de3cae9 100755 --- a/static/js/app/site.js +++ b/static/js/app/site.js @@ -6,7 +6,7 @@ Code provided under the BSD License: */ -define(['jquery'], function ($) { +define(['jquery', 'vent'], function ($, vent) { $(document).ready(function () { if (window.location.hash == '#_=_') { @@ -91,27 +91,38 @@ define(['jquery'], function ($) { }); $.ajaxSetup({ - beforeSend: function(xhr, settings) { - 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; - } - if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) { - // Only send the token to relative URLs i.e. locally. - xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken')); - } - } + beforeSend: function (xhr, settings) { + 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; + } + + if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) { + // Only send the token to relative URLs i.e. locally. + xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken')); + } + }, + statusCode: { + 401: function () { + vent.trigger('app:login'); + window.location.replace('/'); + }, + 403: function () { + vent.trigger('app:denied'); + window.location.replace('/'); + } + } }); if (com.podnoms.settings.isDebug) { diff --git a/static/js/app/views/mix/mixListView.coffee b/static/js/app/views/mix/mixListView.coffee index 27ea9a4..60a9894 100755 --- a/static/js/app/views/mix/mixListView.coffee +++ b/static/js/app/views/mix/mixListView.coffee @@ -4,6 +4,7 @@ define ['marionette', 'vent', 'models/mix/mixCollection', 'views/mix/mixItemView template: _.template(Template) className: "mix-listing audio-listing" + emptyView: Marionette.ItemView.extend(template: "#mix-empty-view") itemView: MixItemView itemViewContainer: "#mix-list-container-ul" diff --git a/static/js/app/views/mix/mixListView.js b/static/js/app/views/mix/mixListView.js index 4aa9e04..0f94593 100755 --- a/static/js/app/views/mix/mixListView.js +++ b/static/js/app/views/mix/mixListView.js @@ -18,6 +18,10 @@ MixListView.prototype.className = "mix-listing audio-listing"; + MixListView.prototype.emptyView = Marionette.ItemView.extend({ + template: "#mix-empty-view" + }); + MixListView.prototype.itemView = MixItemView; MixListView.prototype.itemViewContainer = "#mix-list-container-ul"; diff --git a/templates/views/LoginView.html b/templates/views/LoginView.html index 152c94d..187b164 100755 --- a/templates/views/LoginView.html +++ b/templates/views/LoginView.html @@ -1,6 +1,6 @@ {% load account %} {% load socialaccount %} -