-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #301 from SELab-2/frontend_testen
Frontend testen
- Loading branch information
Showing
101 changed files
with
4,884 additions
and
2,938 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
from django.contrib.auth.models import User | ||
from api.models.gebruiker import Gebruiker | ||
from api.serializers.gebruiker import GebruikerSerializer | ||
from api.serializers.template import TemplateSerializer | ||
from django.core.files import File | ||
import os | ||
|
||
|
||
class AuthenticationUserMiddleware: | ||
""" | ||
Middleware voor authenticatie van gebruikers en het aanmaken van gebruikersindeling. | ||
Args: | ||
get_response (callable): De volgende middleware in de keten. | ||
Returns: | ||
HttpResponse: Een HTTP-response-object. | ||
Raises: | ||
Redirect: Redirect naar de inlog-URL als er geen autorisatiegegevens zijn. | ||
""" | ||
|
||
def __init__(self, get_response): | ||
self.get_response = get_response | ||
|
||
def __call__(self, request): | ||
|
||
mail = "[email protected]" | ||
try: | ||
user = User.objects.get(username=mail) | ||
except User.DoesNotExist: | ||
user = User.objects.create_user( | ||
username=mail, | ||
email=mail, | ||
first_name="Lesgever", | ||
last_name="Testing", | ||
) | ||
|
||
request.user = user | ||
|
||
try: | ||
Gebruiker.objects.get(pk=request.user.id) | ||
except Gebruiker.DoesNotExist: | ||
directory_path = "api/base_templates" | ||
for filename in os.listdir(directory_path): | ||
file_path = os.path.join(directory_path, filename) | ||
with open(file_path, "rb") as f: | ||
django_file = File(f) | ||
template_data = {"user": request.user.id, "bestand": django_file} | ||
serializer = TemplateSerializer(data=template_data) | ||
if serializer.is_valid(): | ||
serializer.save() | ||
|
||
gebruiker_post_data = { | ||
"user": request.user.id, | ||
"subjects": [], | ||
"is_lesgever": True, | ||
} | ||
serializer = GebruikerSerializer(data=gebruiker_post_data) | ||
if serializer.is_valid(): | ||
serializer.save() | ||
|
||
return self.get_response(request) | ||
|
||
|
||
class DisableCSRFMiddleware(object): | ||
def __init__(self, get_response): | ||
self.get_response = get_response | ||
|
||
def __call__(self, request): | ||
setattr(request, "_dont_enforce_csrf_checks", True) | ||
response = self.get_response(request) | ||
return response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
from django.conf import settings | ||
from django.shortcuts import redirect | ||
from django.contrib.auth.models import User | ||
from api.models.gebruiker import Gebruiker | ||
from api.serializers.gebruiker import GebruikerSerializer | ||
from api.serializers.template import TemplateSerializer | ||
from django.core.files import File | ||
import requests | ||
import os | ||
|
||
URL = "https://graph.microsoft.com/v1.0/me" | ||
|
||
|
||
class AuthenticationUserMiddleware: | ||
""" | ||
Middleware voor authenticatie van gebruikers en het aanmaken van gebruikersindeling. | ||
Args: | ||
get_response (callable): De volgende middleware in de keten. | ||
Returns: | ||
HttpResponse: Een HTTP-response-object. | ||
Raises: | ||
Redirect: Redirect naar de inlog-URL als er geen autorisatiegegevens zijn. | ||
""" | ||
|
||
def __init__(self, get_response): | ||
self.get_response = get_response | ||
|
||
def __call__(self, request): | ||
if request.path in ["/oauth2/login", "/oauth2/callback"]: | ||
return self.get_response(request) | ||
|
||
if request.user.is_anonymous: | ||
authorization = request.headers.get("Authorization") | ||
if authorization: | ||
headers = { | ||
"Authorization": authorization, | ||
"Content-Type": "application/json", | ||
} | ||
|
||
response = requests.get(url=URL, headers=headers) | ||
json_data = response.json() | ||
mail = json_data.get("mail") | ||
first_name = json_data.get("givenName") | ||
last_name = json_data.get("surname") | ||
try: | ||
user = User.objects.get(username=mail) | ||
except User.DoesNotExist: | ||
user = User.objects.create_user( | ||
username=mail, | ||
email=mail, | ||
first_name=first_name, | ||
last_name=last_name, | ||
) | ||
|
||
request.user = user | ||
else: | ||
return redirect(settings.LOGIN_URL) | ||
|
||
try: | ||
Gebruiker.objects.get(pk=request.user.id) | ||
except Gebruiker.DoesNotExist: | ||
directory_path = "api/base_templates" | ||
for filename in os.listdir(directory_path): | ||
file_path = os.path.join(directory_path, filename) | ||
with open(file_path, "rb") as f: | ||
django_file = File(f) | ||
template_data = {"user": request.user.id, "bestand": django_file} | ||
serializer = TemplateSerializer(data=template_data) | ||
if serializer.is_valid(): | ||
serializer.save() | ||
|
||
gebruiker_post_data = { | ||
"user": request.user.id, | ||
"subjects": [], | ||
"is_lesgever": False, | ||
} | ||
serializer = GebruikerSerializer(data=gebruiker_post_data) | ||
if serializer.is_valid(): | ||
serializer.save() | ||
|
||
return self.get_response(request) | ||
|
||
|
||
class DisableCSRFMiddleware(object): | ||
def __init__(self, get_response): | ||
self.get_response = get_response | ||
|
||
def __call__(self, request): | ||
setattr(request, "_dont_enforce_csrf_checks", True) | ||
response = self.get_response(request) | ||
return response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
from django.contrib.auth.models import User | ||
from api.models.gebruiker import Gebruiker | ||
from api.serializers.gebruiker import GebruikerSerializer | ||
from api.serializers.template import TemplateSerializer | ||
from django.core.files import File | ||
import os | ||
|
||
|
||
class AuthenticationUserMiddleware: | ||
""" | ||
Middleware voor authenticatie van gebruikers en het aanmaken van gebruikersindeling. | ||
Args: | ||
get_response (callable): De volgende middleware in de keten. | ||
Returns: | ||
HttpResponse: Een HTTP-response-object. | ||
Raises: | ||
Redirect: Redirect naar de inlog-URL als er geen autorisatiegegevens zijn. | ||
""" | ||
|
||
def __init__(self, get_response): | ||
self.get_response = get_response | ||
|
||
def __call__(self, request): | ||
|
||
mail = "[email protected]" | ||
try: | ||
user = User.objects.get(username=mail) | ||
except User.DoesNotExist: | ||
user = User.objects.create_user( | ||
username=mail, | ||
email=mail, | ||
first_name="Student", | ||
last_name="Testing", | ||
) | ||
|
||
request.user = user | ||
|
||
try: | ||
Gebruiker.objects.get(pk=request.user.id) | ||
except Gebruiker.DoesNotExist: | ||
directory_path = "api/base_templates" | ||
for filename in os.listdir(directory_path): | ||
file_path = os.path.join(directory_path, filename) | ||
with open(file_path, "rb") as f: | ||
django_file = File(f) | ||
template_data = {"user": request.user.id, "bestand": django_file} | ||
serializer = TemplateSerializer(data=template_data) | ||
if serializer.is_valid(): | ||
serializer.save() | ||
|
||
gebruiker_post_data = { | ||
"user": request.user.id, | ||
"subjects": [], | ||
"is_lesgever": False, | ||
} | ||
serializer = GebruikerSerializer(data=gebruiker_post_data) | ||
if serializer.is_valid(): | ||
serializer.save() | ||
|
||
return self.get_response(request) | ||
|
||
|
||
class DisableCSRFMiddleware(object): | ||
def __init__(self, get_response): | ||
self.get_response = get_response | ||
|
||
def __call__(self, request): | ||
setattr(request, "_dont_enforce_csrf_checks", True) | ||
response = self.get_response(request) | ||
return response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,3 +26,4 @@ package-lock.json | |
*.sw? | ||
./src/authConfig/authSecrets.ts | ||
./package-lock.json | ||
package-lock.json |
Oops, something went wrong.