Authentication - Rewrite Show views to use django user model
This commit is contained in:
parent
5fb6911960
commit
926ecbceb3
@ -30,7 +30,7 @@
|
|||||||
</section>
|
</section>
|
||||||
<section class="submissions">
|
<section class="submissions">
|
||||||
<a href="/show/{{show.abbr}}" class="button"><i class="fa fa-fw fa-home"></i> Show Index</a>
|
<a href="/show/{{show.abbr}}" class="button"><i class="fa fa-fw fa-home"></i> Show Index</a>
|
||||||
{% if request.session.user_id %}
|
{% if user.is_authenticated %}
|
||||||
<a href="/show/{{show.abbr}}/episode/{{episode.season.number}}/{{episode.episode}}/submit" class="button"><i class="fa fa-fw fa-plus"></i> Submit New Link</a>
|
<a href="/show/{{show.abbr}}/episode/{{episode.season.number}}/{{episode.episode}}/submit" class="button"><i class="fa fa-fw fa-plus"></i> Submit New Link</a>
|
||||||
{% else %}
|
{% else %}
|
||||||
<span class="fillertext"><a href="/login">Log in</a> to submit a link</span>
|
<span class="fillertext"><a href="/login">Log in</a> to submit a link</span>
|
||||||
|
@ -2,11 +2,13 @@ from django.template import RequestContext
|
|||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.views import View
|
from django.views import View
|
||||||
from django.views.generic.base import TemplateView
|
from django.views.generic.base import TemplateView
|
||||||
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.http import Http404
|
from django.http import Http404
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from django.http import HttpResponseRedirect
|
from django.http import HttpResponseRedirect
|
||||||
from django.db.models import Case, When, Value, IntegerField, Count, F
|
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 User
|
||||||
from LandingPage.models import Show
|
from LandingPage.models import Show
|
||||||
@ -85,15 +87,11 @@ class EpisodeView(TemplateView):
|
|||||||
return ctx
|
return ctx
|
||||||
|
|
||||||
# Submission form GET and POST
|
# Submission form GET and POST
|
||||||
|
@login_required
|
||||||
def SubmissionForm(req, abbreviation, season, episode):
|
def SubmissionForm(req, abbreviation, season, episode):
|
||||||
show = Show.objects.get(abbr=abbreviation)
|
show = Show.objects.get(abbr=abbreviation)
|
||||||
episode = Episode.objects.filter(show=show,season__number=season,episode=episode).first()
|
episode = Episode.objects.filter(show=show,season__number=season,episode=episode).first()
|
||||||
|
user = req.user
|
||||||
# Check for login status
|
|
||||||
if not 'user_id' in req.session:
|
|
||||||
return HttpResponse('<h1>Error</h1><p>You need to be logged in to submit. Please <a href=/login>log in</a></p>', status=400)
|
|
||||||
|
|
||||||
user = User.objects.get(user_id=req.session['user_id'])
|
|
||||||
|
|
||||||
# 404's
|
# 404's
|
||||||
if not show:
|
if not show:
|
||||||
@ -144,16 +142,12 @@ def SubmissionForm(req, abbreviation, season, episode):
|
|||||||
|
|
||||||
# Vote request
|
# Vote request
|
||||||
# /show/{{abbr}}/vote/{{submission id}}/{{positive == 1}}
|
# /show/{{abbr}}/vote/{{submission id}}/{{positive == 1}}
|
||||||
class SubmissionVoteSubmit(View):
|
class SubmissionVoteSubmit(LoginRequiredMixin, View):
|
||||||
def post (self, req, abbreviation, subid, positive):
|
def post (self, req, abbreviation, subid, positive):
|
||||||
# Convert positive parameter into a boolean
|
# Convert positive parameter into a boolean
|
||||||
pos_bool = int(positive) == 1
|
pos_bool = int(positive) == 1
|
||||||
|
|
||||||
# Check for login status
|
user = req.user
|
||||||
if not 'user_id' in req.session:
|
|
||||||
return HttpResponse('<h1>Error</h1><p>You need to be logged in to vote. Please <a href=/login>log in</a></p>', status=400)
|
|
||||||
|
|
||||||
user = User.objects.get(user_id=req.session['user_id'])
|
|
||||||
|
|
||||||
# Get the submission from the database
|
# Get the submission from the database
|
||||||
submission = Submission.objects.filter(id=subid).first()
|
submission = Submission.objects.filter(id=subid).first()
|
||||||
|
Reference in New Issue
Block a user