Commit 3bd1a320 authored by Grady Moran's avatar Grady Moran
Browse files

Modified requirements.txt to add the django-ratelimit...

Modified requirements.txt to add the django-ratelimit (https://github.com/jsocol/django-ratelimit) version 1.0.1
Modified views.py to take a big chunk out of index function and put it in a post function. This allows the ratelimit decorations to work on that function.
parent b81565da
Pipeline #838 passed with stage
in 1 minute and 12 seconds
......@@ -12,6 +12,7 @@ from django.contrib.auth import REDIRECT_FIELD_NAME
from django.contrib.auth.models import User
from django.contrib.auth.decorators import user_passes_test, login_required
from django.shortcuts import render, get_object_or_404, redirect
from ratelimit.decorators import ratelimit
# App Imports
from go.models import URL, RegisteredUser
......@@ -46,6 +47,19 @@ def index(request):
# If a POST request is received, then the user has submitted a form and it's
# time to parse the form and create a new URL object
if request.method == 'POST':
return redirect('view', post(request).short)
# Render index.html passing the form to the template
return render(request, 'core/index.html', {
'form': url_form,
},
)
#rate limits are completely arbitrary
@ratelimit(key='user', rate='3/m', method='POST', block=True)
@ratelimit(key='user', rate='25/d', method='POST', block=True)
def post(request):
# Now we initialize the form again but this time we have the POST
# request
url_form = URLForm(request.POST, host = request.META.get('HTTP_HOST'))
......@@ -99,14 +113,7 @@ def index(request):
# let's redirect to view this baby.
url.full_clean()
url.save()
return redirect('view', url.short)
# Render index.html passing the form to the template
return render(request, 'core/index.html', {
'form': url_form,
},
)
return url
"""
This view allows the user to view details about a URL. Note that they
......
Django==1.10
django-auth-ldap==1.2.8
django-crispy-forms==1.6.0
django-ratelimit==1.0.1
git+https://github.com/bruno207/django-qrcode.git
flake8==3.0.4
git+https://github.com/kstateome/django-cas.git
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment