Oauth worknig

master
Paul Wagener 7 years ago
parent 80dd9e0d07
commit e1e357e3ef
  1. 1
      requirements.txt
  2. 11
      securityquiz/settings.py
  3. 4
      templates/index.html
  4. 16
      views.py

@ -1,3 +1,4 @@
django django
django-oauth-toolkit django-oauth-toolkit
django-cors-headers django-cors-headers
pyopenssl

@ -9,7 +9,8 @@ https://docs.djangoproject.com/en/1.6/ref/settings/
""" """
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os, sys import os
import sys
BASE_DIR = os.path.dirname(os.path.dirname(__file__)) BASE_DIR = os.path.dirname(os.path.dirname(__file__))
CLOSED = False CLOSED = False
@ -26,7 +27,7 @@ DEBUG = False
if 'runserver' in sys.argv: if 'runserver' in sys.argv:
DEBUG = True DEBUG = True
ALLOWED_HOSTS = ['websec.paulwagener.nl'] ALLOWED_HOSTS = ['websec.paulwagener.nl', '127.0.0.1']
# Application definition # Application definition
@ -43,7 +44,7 @@ INSTALLED_APPS = (
'corsheaders', 'corsheaders',
) )
MIDDLEWARE_CLASSES = ( MIDDLEWARE = (
'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware', 'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware', 'django.middleware.csrf.CsrfViewMiddleware',
@ -101,7 +102,6 @@ TEMPLATES = [
'django.template.context_processors.debug', 'django.template.context_processors.debug',
'django.template.context_processors.request', 'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth', 'django.contrib.auth.context_processors.auth',
'securityquiz.settings.closed',
'django.contrib.messages.context_processors.messages', 'django.contrib.messages.context_processors.messages',
], ],
}, },
@ -111,6 +111,3 @@ TEMPLATES = [
STATICFILES_DIRS = ( STATICFILES_DIRS = (
PROJECT_PATH + '/static', PROJECT_PATH + '/static',
) )
def closed(request):
return {'CLOSED': CLOSED}

@ -29,11 +29,11 @@
<li> <li>
<a href="/?wachtwoorden">Wachtwoorden</a> <a href="/?wachtwoorden">Wachtwoorden</a>
</li> </li>
<!--
<li> <li>
<a href="/?oauth">OAuth</a> <a href="/?oauth">OAuth</a>
</li> </li>
<!--
<li> <li>
<a href="/?certificaten">Certificaten</a> <a href="/?certificaten">Certificaten</a>
</li> </li>

@ -6,9 +6,25 @@ from quiz.models import LetsEncryptChallenge
from oauth2_provider.views.generic import ProtectedResourceView from oauth2_provider.views.generic import ProtectedResourceView
import datetime import datetime
import pytz import pytz
from django.contrib.auth import login
from django.contrib.auth.models import User
def home(request, url): def home(request, url):
if not request.user.is_authenticated:
try:
user = User.objects.get()
except User.DoesNotExist:
user = User.objects.create_user(
'cursist', 'cursist@websec.paulwagener.nl', 'cursist')
user.save()
login(request, user)
# Make sure there is always a user
if url == 'sql' or url == '': if url == 'sql' or url == '':
template = 'sql.html' template = 'sql.html'
elif url == 'xss': elif url == 'xss':

Loading…
Cancel
Save