Merge branch 'main' of https://github.com/aaw3/hackathon-SeatStock
This commit is contained in:
@ -1,2 +1,2 @@
|
|||||||
# hackathon-SeatStock
|
# 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.
|
||||||
|
@ -25,4 +25,4 @@ RUN pip install -r requirements.txt
|
|||||||
# port where the Django app runs
|
# port where the Django app runs
|
||||||
EXPOSE 8000
|
EXPOSE 8000
|
||||||
# start server
|
# start server
|
||||||
CMD python seatstock_django/manage.py runserver
|
CMD python seatstock_django/manage.py runserver 0.0.0.0:8000
|
||||||
|
@ -1 +1,4 @@
|
|||||||
django
|
django ~= 4.0
|
||||||
|
authlib ~= 1.0
|
||||||
|
python-dotenv ~= 0.19
|
||||||
|
requests ~= 2.27
|
||||||
|
Binary file not shown.
@ -10,7 +10,9 @@ For the full list of settings and their values, see
|
|||||||
https://docs.djangoproject.com/en/4.2/ref/settings/
|
https://docs.djangoproject.com/en/4.2/ref/settings/
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from dotenv import load_dotenv, find_dotenv
|
||||||
|
|
||||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||||
@ -51,10 +53,13 @@ MIDDLEWARE = [
|
|||||||
|
|
||||||
ROOT_URLCONF = 'seatstock_django.urls'
|
ROOT_URLCONF = 'seatstock_django.urls'
|
||||||
|
|
||||||
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||||
|
TEMPLATE_DIR = os.path.join(BASE_DIR, "seatstock_django", "templates")
|
||||||
|
|
||||||
TEMPLATES = [
|
TEMPLATES = [
|
||||||
{
|
{
|
||||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||||
'DIRS': [],
|
'DIRS': [TEMPLATE_DIR],
|
||||||
'APP_DIRS': True,
|
'APP_DIRS': True,
|
||||||
'OPTIONS': {
|
'OPTIONS': {
|
||||||
'context_processors': [
|
'context_processors': [
|
||||||
@ -84,6 +89,11 @@ DATABASES = {
|
|||||||
# Password validation
|
# Password validation
|
||||||
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators
|
# 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 = [
|
AUTH_PASSWORD_VALIDATORS = [
|
||||||
{
|
{
|
||||||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
||||||
|
@ -0,0 +1,16 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<title>Auth0 Example</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
{% if session %}
|
||||||
|
<h1>Welcome {{session.userinfo.name}}!</h1>
|
||||||
|
<p><a href="{% url 'logout' %}">Logout</a></p>
|
||||||
|
<div><pre>{{pretty}}</pre></div>
|
||||||
|
{% else %}
|
||||||
|
<h1>Welcome Guest</h1>
|
||||||
|
<p><a href="{% url 'login' %}">Login</a></p>
|
||||||
|
{% endif %}
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -17,6 +17,13 @@ Including another URLconf
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
|
||||||
|
from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
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"),
|
||||||
|
|
||||||
]
|
]
|
||||||
|
52
backend/django/seatstock_django/seatstock_django/views.py
Normal file
52
backend/django/seatstock_django/seatstock_django/views.py
Normal file
@ -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),
|
||||||
|
},
|
||||||
|
)
|
@ -2,16 +2,18 @@ version: "3.3"
|
|||||||
|
|
||||||
services:
|
services:
|
||||||
nginx:
|
nginx:
|
||||||
|
container_name: seatstock-nginx
|
||||||
image: nginx:latest
|
image: nginx:latest
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
ports:
|
ports:
|
||||||
- "8080:80"
|
- "8080:80"
|
||||||
volumes:
|
volumes:
|
||||||
- ../frontend:/usr/share/nginx/html
|
- ../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:
|
docker-django:
|
||||||
image: docker-django
|
image: docker-django
|
||||||
|
container_name: seatstock-django
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
ports:
|
ports:
|
||||||
- "8000:8000"
|
- "8000:8000"
|
||||||
|
3
docker/nginx-restart.sh
Executable file
3
docker/nginx-restart.sh
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
docker exec -it seatstock-nginx /etc/init.d/nginx restart
|
3
docker/nginx-shell.sh
Executable file
3
docker/nginx-shell.sh
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
docker exec -it seatstock-nginx /bin/bash
|
3
docker/start.sh
Executable file
3
docker/start.sh
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
docker-compose up -d
|
3
docker/stop.sh
Executable file
3
docker/stop.sh
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
docker-compose down
|
64
docker/volumes/nginx/config/default.conf
Normal file
64
docker/volumes/nginx/config/default.conf
Normal file
@ -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;
|
||||||
|
#}
|
||||||
|
}
|
Reference in New Issue
Block a user