Working .env setup
This commit is contained in:
@@ -1,3 +1,50 @@
|
||||
from django.shortcuts import render
|
||||
import hmac
|
||||
import random
|
||||
import time
|
||||
|
||||
# Create your views here.
|
||||
from django.conf import settings
|
||||
from django.shortcuts import redirect, render
|
||||
|
||||
from common.middleware import gate_whitelist
|
||||
|
||||
|
||||
def _under_lockout(request):
|
||||
lock_until = request.session.get('lock_until')
|
||||
if lock_until and time.time() < lock_until:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def _start_lockout(request):
|
||||
duration = random.randint(30, 300)
|
||||
request.session['lock_until'] = time.time() + duration
|
||||
|
||||
|
||||
@gate_whitelist
|
||||
def gate(request):
|
||||
if request.method == 'POST':
|
||||
if _under_lockout(request):
|
||||
return render(request, 'landing/gate.html', {
|
||||
'error': 'Incorrect password.',
|
||||
})
|
||||
|
||||
submitted = request.POST.get('password', '')
|
||||
master = settings.PASSWORD or ''
|
||||
if hmac.compare_digest(submitted, master):
|
||||
request.session['authorized'] = True
|
||||
request.session.pop('lock_until', None)
|
||||
return redirect('home')
|
||||
else:
|
||||
_start_lockout(request)
|
||||
return render(request, 'landing/gate.html', {
|
||||
'error': 'Incorrect password.',
|
||||
})
|
||||
|
||||
if request.session.get('authorized'):
|
||||
return redirect('home')
|
||||
|
||||
return render(request, 'landing/gate.html')
|
||||
|
||||
|
||||
def home(request):
|
||||
return render(request, 'landing/home.html')
|
||||
Reference in New Issue
Block a user