diff --git a/Show/templates/episode.html b/Show/templates/episode.html index 9563ae7..0fa4fbe 100644 --- a/Show/templates/episode.html +++ b/Show/templates/episode.html @@ -30,7 +30,7 @@
 Show Index - {% if request.session.user_id %} + {% if user.is_authenticated %}  Submit New Link {% else %} Log in to submit a link diff --git a/Show/views.py b/Show/views.py index ba23497..f2e2ce4 100644 --- a/Show/views.py +++ b/Show/views.py @@ -2,11 +2,13 @@ from django.template import RequestContext from django.shortcuts import render from django.views import View from django.views.generic.base import TemplateView +from django.contrib.auth.decorators import login_required from django.conf import settings from django.http import Http404 from django.http import HttpResponse from django.http import HttpResponseRedirect from django.db.models import Case, When, Value, IntegerField, Count, F +from django.contrib.auth.mixins import LoginRequiredMixin from LandingPage.models import User from LandingPage.models import Show @@ -85,15 +87,11 @@ class EpisodeView(TemplateView): return ctx # Submission form GET and POST +@login_required def SubmissionForm(req, abbreviation, season, episode): show = Show.objects.get(abbr=abbreviation) episode = Episode.objects.filter(show=show,season__number=season,episode=episode).first() - - # Check for login status - if not 'user_id' in req.session: - return HttpResponse('

Error

You need to be logged in to submit. Please log in

', status=400) - - user = User.objects.get(user_id=req.session['user_id']) + user = req.user # 404's if not show: @@ -144,16 +142,12 @@ def SubmissionForm(req, abbreviation, season, episode): # Vote request # /show/{{abbr}}/vote/{{submission id}}/{{positive == 1}} -class SubmissionVoteSubmit(View): +class SubmissionVoteSubmit(LoginRequiredMixin, View): def post (self, req, abbreviation, subid, positive): # Convert positive parameter into a boolean pos_bool = int(positive) == 1 - # Check for login status - if not 'user_id' in req.session: - return HttpResponse('

Error

You need to be logged in to vote. Please log in

', status=400) - - user = User.objects.get(user_id=req.session['user_id']) + user = req.user # Get the submission from the database submission = Submission.objects.filter(id=subid).first()