diff --git a/README.md b/README.md
index f8c7372..2118700 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,2 @@
# hackathon-SeatStock
-Hackathon project to build and design a student ticket marketplace with safe transactions,
+Hackathon project to build and design a proof-of-concept student ticket marketplace with safe transactions.
diff --git a/backend/django/Dockerfile b/backend/django/Dockerfile
index 6ac06d6..3f6c15f 100644
--- a/backend/django/Dockerfile
+++ b/backend/django/Dockerfile
@@ -25,4 +25,4 @@ RUN pip install -r requirements.txt
# port where the Django app runs
EXPOSE 8000
# start server
-CMD python seatstock_django/manage.py runserver
+CMD python seatstock_django/manage.py runserver 0.0.0.0:8000
diff --git a/backend/django/requirements.txt b/backend/django/requirements.txt
index d3e4ba5..b7f72e8 100644
--- a/backend/django/requirements.txt
+++ b/backend/django/requirements.txt
@@ -1 +1,4 @@
-django
+django ~= 4.0
+authlib ~= 1.0
+python-dotenv ~= 0.19
+requests ~= 2.27
diff --git a/backend/django/seatstock_django/db.sqlite3 b/backend/django/seatstock_django/db.sqlite3
index e69de29..c642d53 100644
Binary files a/backend/django/seatstock_django/db.sqlite3 and b/backend/django/seatstock_django/db.sqlite3 differ
diff --git a/backend/django/seatstock_django/seatstock_django/settings.py b/backend/django/seatstock_django/seatstock_django/settings.py
index 5f4f41d..8ed281e 100644
--- a/backend/django/seatstock_django/seatstock_django/settings.py
+++ b/backend/django/seatstock_django/seatstock_django/settings.py
@@ -10,7 +10,9 @@ For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.2/ref/settings/
"""
+import os
from pathlib import Path
+from dotenv import load_dotenv, find_dotenv
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
@@ -51,10 +53,13 @@ MIDDLEWARE = [
ROOT_URLCONF = 'seatstock_django.urls'
+BASE_DIR = Path(__file__).resolve().parent.parent
+TEMPLATE_DIR = os.path.join(BASE_DIR, "seatstock_django", "templates")
+
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
- 'DIRS': [],
+ 'DIRS': [TEMPLATE_DIR],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
@@ -84,6 +89,11 @@ DATABASES = {
# Password validation
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators
+# AUTH0
+AUTH0_DOMAIN = os.environ.get("AUTH0_DOMAIN")
+AUTH0_CLIENT_ID = os.environ.get("AUTH0_CLIENT_ID")
+AUTH0_CLIENT_SECRET = os.environ.get("AUTH0_CLIENT_SECRET")
+
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
diff --git a/backend/django/seatstock_django/seatstock_django/templates/index.html b/backend/django/seatstock_django/seatstock_django/templates/index.html
new file mode 100644
index 0000000..f9fd63c
--- /dev/null
+++ b/backend/django/seatstock_django/seatstock_django/templates/index.html
@@ -0,0 +1,16 @@
+
+
+
+ Auth0 Example
+
+
+{% if session %}
+ Welcome {{session.userinfo.name}}!
+ Logout
+
+{% else %}
+ Welcome Guest
+ Login
+{% endif %}
+
+
diff --git a/backend/django/seatstock_django/seatstock_django/urls.py b/backend/django/seatstock_django/seatstock_django/urls.py
index 3b3e8b1..348cd12 100644
--- a/backend/django/seatstock_django/seatstock_django/urls.py
+++ b/backend/django/seatstock_django/seatstock_django/urls.py
@@ -17,6 +17,13 @@ Including another URLconf
from django.contrib import admin
from django.urls import path
+from . import views
+
urlpatterns = [
- path('admin/', admin.site.urls),
+ #path('admin/', admin.site.urls),
+ path("", views.index, name="index"),
+ path("login", views.login, name="login"),
+ path("logout", views.logout, name="logout"),
+ path("callback", views.callback, name="callback"),
+
]
diff --git a/backend/django/seatstock_django/seatstock_django/views.py b/backend/django/seatstock_django/seatstock_django/views.py
new file mode 100644
index 0000000..f48cf77
--- /dev/null
+++ b/backend/django/seatstock_django/seatstock_django/views.py
@@ -0,0 +1,52 @@
+import json
+from authlib.integrations.django_client import OAuth
+from django.conf import settings
+from django.shortcuts import redirect, render, redirect
+from django.urls import reverse
+from urllib.parse import quote_plus, urlencode
+
+oauth = OAuth()
+
+oauth.register(
+ "auth0",
+ client_id=settings.AUTH0_CLIENT_ID,
+ client_secret=settings.AUTH0_CLIENT_SECRET,
+ client_kwargs={
+ "scope": "openid profile email",
+ },
+ server_metadata_url=f"https://{settings.AUTH0_DOMAIN}/.well-known/openid-configuration",
+)
+
+def login(request):
+ return oauth.auth0.authorize_redirect(
+ request, request.build_absolute_uri(reverse("callback"))
+ )
+
+def callback(request):
+ token = oauth.auth0.authorize_access_token(request)
+ request.session["user"] = token
+ return redirect(request.build_absolute_uri(reverse("index")))
+
+def logout(request):
+ request.session.clear()
+
+ return redirect(
+ f"https://{settings.AUTH0_DOMAIN}/v2/logout?"
+ + urlencode(
+ {
+ "returnTo": request.build_absolute_uri(reverse("index")),
+ "client_id": settings.AUTH0_CLIENT_ID,
+ },
+ quote_via=quote_plus,
+ ),
+ )
+
+def index(request):
+ return render(
+ request,
+ "index.html",
+ context={
+ "session": request.session.get("user"),
+ "pretty": json.dumps(request.session.get("user"), indent=4),
+ },
+ )
diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml
index 7006974..e10c5bc 100644
--- a/docker/docker-compose.yml
+++ b/docker/docker-compose.yml
@@ -2,16 +2,18 @@ version: "3.3"
services:
nginx:
+ container_name: seatstock-nginx
image: nginx:latest
restart: unless-stopped
ports:
- "8080:80"
volumes:
- ../frontend:/usr/share/nginx/html
- - ./volumes/config:/usr/share/nginx/html
+ - ./volumes/nginx/config/default.conf:/etc/nginx/conf.d/default.conf:ro
docker-django:
image: docker-django
+ container_name: seatstock-django
restart: unless-stopped
ports:
- "8000:8000"
diff --git a/docker/nginx-restart.sh b/docker/nginx-restart.sh
new file mode 100755
index 0000000..f1bc55b
--- /dev/null
+++ b/docker/nginx-restart.sh
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+docker exec -it seatstock-nginx /etc/init.d/nginx restart
diff --git a/docker/nginx-shell.sh b/docker/nginx-shell.sh
new file mode 100755
index 0000000..b05889c
--- /dev/null
+++ b/docker/nginx-shell.sh
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+docker exec -it seatstock-nginx /bin/bash
diff --git a/docker/start.sh b/docker/start.sh
new file mode 100755
index 0000000..217a5fe
--- /dev/null
+++ b/docker/start.sh
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+docker-compose up -d
diff --git a/docker/stop.sh b/docker/stop.sh
new file mode 100755
index 0000000..f163d8d
--- /dev/null
+++ b/docker/stop.sh
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+docker-compose down
diff --git a/docker/volumes/nginx/config/default.conf b/docker/volumes/nginx/config/default.conf
new file mode 100644
index 0000000..452337c
--- /dev/null
+++ b/docker/volumes/nginx/config/default.conf
@@ -0,0 +1,64 @@
+server {
+ listen 80;
+ listen [::]:80;
+ server_name localhost;
+
+ #access_log /var/log/nginx/host.access.log main;
+
+
+ location /ngxapi/transaction {
+ proxy_pass http://localhost:8000/transaction;
+ }
+
+ location /ngxapi/search {
+ proxy_pass http://localhost:8000/search;
+ }
+
+ location /ngxapi/query_games {
+ proxy_pass http://localhost:8000/query_games;
+ }
+
+ location /ngxapi/account {
+ proxy_pass http://localhost:8000/account;
+ }
+
+
+
+
+ location / {
+ root /usr/share/nginx/html;
+ index index.html index.htm;
+ }
+
+ #error_page 404 /404.html;
+
+ # redirect server error pages to the static page /50x.html
+ #
+ error_page 500 502 503 504 /50x.html;
+ location = /50x.html {
+ root /usr/share/nginx/html;
+ }
+
+ # proxy the PHP scripts to Apache listening on 127.0.0.1:80
+ #
+ #location ~ \.php$ {
+ # proxy_pass http://127.0.0.1;
+ #}
+
+ # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
+ #
+ #location ~ \.php$ {
+ # root html;
+ # fastcgi_pass 127.0.0.1:9000;
+ # fastcgi_index index.php;
+ # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
+ # include fastcgi_params;
+ #}
+
+ # deny access to .htaccess files, if Apache's document root
+ # concurs with nginx's one
+ #
+ #location ~ /\.ht {
+ # deny all;
+ #}
+}