diff --git a/Django_Frontend/monprojet/monapp/templates/monapp/base.html b/Django_Frontend/monprojet/monapp/templates/monapp/base.html
index 9579e3f..4591806 100644
--- a/Django_Frontend/monprojet/monapp/templates/monapp/base.html
+++ b/Django_Frontend/monprojet/monapp/templates/monapp/base.html
@@ -19,6 +19,9 @@
+ {% if user.is_authenticated %}
+
Logged in as: {{ user.username }}
+ {% endif %}
Mon Application
diff --git a/Django_Frontend/monprojet/monapp/views.py b/Django_Frontend/monprojet/monapp/views.py
index 1d7d652..c59726f 100644
--- a/Django_Frontend/monprojet/monapp/views.py
+++ b/Django_Frontend/monprojet/monapp/views.py
@@ -10,11 +10,7 @@
# Create your views here.
-def get_api_url(request: HttpRequest) -> str:
- host = request.get_host()
- protocol = 'https://'# if request.is_secure() else 'http://'
- api_url = f'{protocol}api.{host}/api/common/'
- return api_url
+
def client_create_view(request):
form = ClientForm(request.POST or None)
@@ -60,7 +56,7 @@ def register(request):
form = RegistrationForm(request.POST)
if form.is_valid():
form.save()
- return redirect('login')
+ return redirect('Login')
else:
form = RegistrationForm()
return render(request, 'monapp/register.html', {'form': form})
@@ -74,7 +70,7 @@ def login(request):
user = authenticate(request, username=username, password=password)
if user is not None:
auth_login(request, user)
- return redirect('home')
+ return redirect('Home')
else:
messages.error(request, 'Invalid username or password.')
else:
@@ -82,11 +78,17 @@ def login(request):
return render(request, 'monapp/login.html', {'form': form})
+def get_api_url(request: HttpRequest) -> str:
+ host = request.get_host()
+ protocol = 'https://'
+ api_url = f'{protocol}api.{host}/api/common/'
+ return api_url
+
def view_flights(request):
api_url = get_api_url(request) + 'flights/' # Adjusted to include the API endpoint
try:
- response = requests.get(api_url)
- response.raise_for_status() # This will raise an HTTPError if the response was an error
+ response = requests.get(api_url).json()
+ #response.raise_for_status() # This will raise an HTTPError if the response was an error
flights = response.json()
except requests.exceptions.HTTPError as http_err:
# Handle HTTP errors (e.g., endpoint not found, server error)
diff --git a/Django_Frontend/monprojet/monprojet/settings.py b/Django_Frontend/monprojet/monprojet/settings.py
index 1461a8b..1a9b0e9 100644
--- a/Django_Frontend/monprojet/monprojet/settings.py
+++ b/Django_Frontend/monprojet/monprojet/settings.py
@@ -49,6 +49,13 @@
else:
ALLOWED_HOSTS = [os.getenv('DOMAIN')]
+# Add near the top of the file
+SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
+
+# Enforce HTTPS
+SECURE_SSL_REDIRECT = True
+
+
# Application definition
INSTALLED_APPS = [
diff --git a/Django_api/airline/airline/settings.py b/Django_api/airline/airline/settings.py
index 92aab91..efadd67 100644
--- a/Django_api/airline/airline/settings.py
+++ b/Django_api/airline/airline/settings.py
@@ -41,7 +41,11 @@
else:
ALLOWED_HOSTS = ["api" + os.getenv('DOMAIN')]
+# Add near the top of the file
+SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
+# Enforce HTTPS
+SECURE_SSL_REDIRECT = True
# Application definition
@@ -69,7 +73,7 @@
]
if ENVIRONMENT != 'development':
- CSRF_TRUSTED_ORIGINS = ["https://" + os.getenv('DOMAIN'), "https://api." + os.getenv('DOMAIN')]
+ CSRF_TRUSTED_ORIGINS = ["https://" + os.getenv('DOMAIN'), "https://api." + os.getenv('DOMAIN'), "http://" + os.getenv('DOMAIN'), "http://api." + os.getenv('DOMAIN')]
else:
CSRF_TRUSTED_ORIGINS = ['*']
@@ -165,5 +169,7 @@
CORS_ORIGIN_WHITELIST = [
- "http://localhost:8010",
+ "https://api." + os.getenv('DOMAIN'),
+ "https://sae.local",
+ "http://sae.local",
]
diff --git a/Docker-test/docker-compose.yml b/Docker-test/docker-compose.yml
index a575057..472a5db 100644
--- a/Docker-test/docker-compose.yml
+++ b/Docker-test/docker-compose.yml
@@ -106,8 +106,8 @@ services:
- "traefik.http.routers.django_frontend.entrypoints=websecure"
- "traefik.http.routers.django_frontend.tls=true"
- "traefik.http.routers.django_frontend_http.rule=Host(`${DOMAIN}`)"
- - "traefik.http.routers.django_frontedn_http.entrypoints=web"
- - "traefik.http.routers.django_frontedn_http.middlewares=redirect-to-https@file"
+ - "traefik.http.routers.django_frontend_http.entrypoints=web"
+ - "traefik.http.routers.django_frontend_http.middlewares=redirect-to-https@file"
- "traefik.http.services.django_frontend.loadbalancer.server.url=http://django_frontend:80"
hostname: django_frontend
depends_on:
diff --git a/Docker-test/traefik/dynamic_conf.yml b/Docker-test/traefik/dynamic_conf.yml
index 64f9d8e..b572f69 100644
--- a/Docker-test/traefik/dynamic_conf.yml
+++ b/Docker-test/traefik/dynamic_conf.yml
@@ -1,5 +1,9 @@
http:
middlewares:
+ add-xforwarded-proto-header:
+ headers:
+ customRequestHeaders:
+ X-Forwarded-Proto: "https"
redirect-to-https:
redirectScheme:
scheme: https