-
Notifications
You must be signed in to change notification settings - Fork 1
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 #108 from NIAEFEUP/feature/exchange
Feature/exchange
- Loading branch information
Showing
38 changed files
with
1,743 additions
and
50 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 was deleted.
Oops, something went wrong.
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,28 @@ | ||
DEBUG=1 | ||
SECRET_KEY=foo | ||
|
||
JWT_KEY=change_in_production | ||
|
||
DOMAIN=http://localhost:3100/ | ||
|
||
POSTGRES_DB=tts | ||
POSTGRES_USER=root | ||
POSTGRES_PASSWORD=root | ||
POSTGRES_HOST=db | ||
POSTGRES_PORT=5432 | ||
|
||
TTS_REDIS_HOST=tts_redis | ||
TTS_REDIS_PORT=6379 | ||
TTS_REDIS_USERNAME= | ||
TTS_REDIS_PASSWORD= | ||
|
||
SENDER_EMAIL_ADDRESS= | ||
STUDENT_EMAIL_DOMAIN=@up.pt | ||
|
||
VERIFY_EXCHANGE_TOKEN_EXPIRATION_SECONDS=86400 | ||
|
||
OIDC_RP_CLIENT_ID= | ||
OIDC_RP_CLIENT_SECRET= | ||
|
||
SIGARRA_USERNAME= | ||
SIGARRA_PASSWORD= |
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 |
---|---|---|
@@ -1,31 +1,36 @@ | ||
#!/bin/sh | ||
#!/bin/sh | ||
|
||
# WARNING: The script will not work if formated with CRLF. | ||
# WARNING: The script will not work if formated with CRLF. | ||
|
||
# Configure the shell behaviour. | ||
# Configure the shell behaviour. | ||
set -e | ||
if [[ "${DEBUG}" == 1 ]] | ||
then set -x | ||
fi | ||
if [[ "${DEBUG}" == 1 ]]; then | ||
set -x | ||
fi | ||
|
||
# Get parameters. | ||
cmd="$@" | ||
|
||
# Waits for PostgreSQL initialization. | ||
# Waits for PostgreSQL initialization. | ||
until PGPASSWORD="${POSTGRES_PASSWORD}" psql -h "${POSTGRES_HOST}" -U "${POSTGRES_USER}" "${POSTGRES_DB}" -c 'select 1'; do | ||
>&2 echo "PostgreSQL is unavailable - sleeping" | ||
sleep 4 | ||
>&2 echo "PostgreSQL is unavailable - sleeping" | ||
sleep 4 | ||
done | ||
>&2 echo "PostgreSQL is up - executing command" | ||
>&2 echo "PostgreSQL is up - executing command" | ||
|
||
echo "ENTRYPOINT RAN" | ||
|
||
# Migrate the Django. | ||
python manage.py inspectdb > university/models.py | ||
python manage.py makemigrations | ||
python manage.py migrate | ||
python manage.py migrate --fake sessions zero | ||
python manage.py migrate university --fake | ||
python manage.py migrate --fake-initial | ||
python manage.py inspectdb >university/models.py | ||
|
||
# Initialize redis worker for celery and celery's beat scheduler in the background | ||
celery -A tasks worker --loglevel=INFO & | ||
celery -A tasks beat & | ||
|
||
# Initializes the API. | ||
# Initializes the API. | ||
exec $cmd |
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
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 |
---|---|---|
@@ -1,3 +0,0 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. | ||
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,29 @@ | ||
from mozilla_django_oidc.auth import OIDCAuthenticationBackend | ||
from university.controllers.SigarraController import SigarraController | ||
from university.controllers.StudentController import StudentController | ||
from university.models import UserCourseUnits, Class | ||
|
||
class CustomOIDCAuthentationBackend(OIDCAuthenticationBackend): | ||
|
||
def create_user(self, claims): | ||
user = super(CustomOIDCAuthentationBackend, self).create_user(claims) | ||
|
||
user.first_name = claims.get('given_name', '') | ||
user.last_name = claims.get('family_name', '').split(' ')[-1] | ||
user.username = claims.get('nmec', '') | ||
user.password = "" # User does not have password | ||
user.save() | ||
|
||
StudentController.populate_user_course_unit_data(user.username) | ||
|
||
return user | ||
|
||
def update_user(self, user, claims): | ||
user.first_name = claims.get('given_name', '') | ||
user.last_name = claims.get('family_name', '').split(' ')[-1] | ||
user.save() | ||
|
||
StudentController.populate_user_course_unit_data(user.username, erase_previous=True) | ||
|
||
return user | ||
|
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,43 @@ | ||
import re | ||
|
||
from django.http import HttpResponseForbidden | ||
|
||
class AuthMiddleware: | ||
def __init__(self, get_response): | ||
self.get_response = get_response | ||
self.auth_paths = [ | ||
'/logout/', | ||
'/auth/info/', | ||
'/student/schedule/', | ||
re.compile(r'^/student/\w+/photo/$'), | ||
re.compile(r'^/schedule_sigarra/\d+/$'), | ||
re.compile(r'^/class_sigarra_schedule/\d+/.+/$'), | ||
re.compile(r'^/exchange/marketplace/$'), | ||
re.compile(r'^/exchange/direct/$'), | ||
re.compile(r'^/exchange/options/$'), | ||
'/is_admin/', | ||
'/export/', | ||
'/direct_exchange/history/', | ||
'/marketplace_exchange/', | ||
'/submit_marketplace_exchange/', | ||
] | ||
|
||
def __call__(self, request): | ||
in_paths = False | ||
|
||
for path in self.auth_paths: | ||
if isinstance(path, str) and request.path == path: | ||
in_paths = True | ||
break | ||
elif isinstance(path, re.Pattern) and path.match(request.path): | ||
in_paths = True | ||
break | ||
|
||
if not in_paths: | ||
return self.get_response(request) | ||
|
||
if not request.user.is_authenticated: | ||
return HttpResponseForbidden() | ||
|
||
return self.get_response(request) | ||
|
Oops, something went wrong.