In theory, finish the whole app

This commit is contained in:
Nico Schottelius 2018-12-24 17:38:13 +01:00
parent 9d44fc939d
commit feddecd5e1
11 changed files with 47 additions and 3 deletions

View file

@ -1 +1,2 @@
django>=2.1.4
pyotp

0
returnok/__init__.py Normal file
View file

3
returnok/admin.py Normal file
View file

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

5
returnok/apps.py Normal file
View file

@ -0,0 +1,5 @@
from django.apps import AppConfig
class ReturnokConfig(AppConfig):
name = 'returnok'

View file

3
returnok/models.py Normal file
View file

@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

3
returnok/tests.py Normal file
View file

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

7
returnok/urls.py Normal file
View file

@ -0,0 +1,7 @@
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
]

13
returnok/views.py Normal file
View file

@ -0,0 +1,13 @@
import pyotp
import json
from django.http import HttpResponse
from django.conf import settings
def index(request):
answer = {}
answer['token'] = pyotp.TOTP(settings.UNGLEICHOTP['UNGLEICHOTPSEED'])
answer['name'] = settings.UNGLEICHOTP['UNGLEICHOTPNAME']
answer['realm'] = settings.UNGLEICHOTP['UNGLEICHOTPREALM']
return HttpResponse(json.dumps(answer))

View file

@ -12,6 +12,15 @@ https://docs.djangoproject.com/en/2.1/ref/settings/
import os
UNGLEICHOTP={}
for env in ['UNGLEICHOTPREALM', 'UNGLEICHOTPNAME', 'UNGLEICHOTPSEED' ]:
if not env in os.environ:
raise Exception("Required environment variable missing: {}".format(env))
UNGLEICHOTP[env] = os.environ[env]
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

View file

@ -13,9 +13,9 @@ Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('returnok.urls')
]