diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index fb89d82..8bc4d57 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -3,10 +3,10 @@ name: Docker Image CI on: push: branches: - - "main" + - "fbl-integration" - "staging" pull_request: - branches: ["main"] + branches: ["fbl-integration"] env: REGISTRY: ghcr.io diff --git a/fbl_integration/__init__.py b/fbl_integration/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/fbl_integration/admin.py b/fbl_integration/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/fbl_integration/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/fbl_integration/apps.py b/fbl_integration/apps.py new file mode 100644 index 0000000..e953f84 --- /dev/null +++ b/fbl_integration/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class FblIntegrationConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "fbl_integration" diff --git a/fbl_integration/forms.py b/fbl_integration/forms.py new file mode 100644 index 0000000..c604a60 --- /dev/null +++ b/fbl_integration/forms.py @@ -0,0 +1,40 @@ +from typing import Any +from django import forms +from django.conf import settings +from django.utils.translation import gettext_lazy as _ +from datetime import datetime + +class FblAuthForm(forms.Form): + badge_number = forms.CharField(required=True) + dob = forms.CharField(required=True) + + def clean(self) -> dict[str, Any]: + cleaned_data = super(FblAuthForm, self).clean() + badge_number = cleaned_data.get("badge_number") + dob = cleaned_data.get("dob") + + if not badge_number: + raise forms.ValidationError( + _("Badge number is required") + ) + + try: + int(badge_number) + except ValueError: + raise forms.ValidationError( + _("Badge number must be a number") + ) + + if not dob: + raise forms.ValidationError( + _("Date of birth is required") + ) + try: + dob = datetime.strptime(dob, "%d/%m/%Y").strftime("%Y-%m-%d") + except ValueError: + raise forms.ValidationError( + _("Date of birth must be in the format DD/MM/YYYY") + ) + cleaned_data["dob"] = dob + + return cleaned_data \ No newline at end of file diff --git a/fbl_integration/migrations/__init__.py b/fbl_integration/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/fbl_integration/models.py b/fbl_integration/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/fbl_integration/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/fbl_integration/templates/fbl_auth_get_code.html b/fbl_integration/templates/fbl_auth_get_code.html new file mode 100644 index 0000000..a3ff6e0 --- /dev/null +++ b/fbl_integration/templates/fbl_auth_get_code.html @@ -0,0 +1,31 @@ +{% extends 'base.html' %} +{% block content %} +{% load i18n %} +
+
+

+ {% trans 'We sent you an email that contains a code for your login. Please enter the code in the field below.' %} +

+
+ {% csrf_token %} + + {% if get_code_form.non_field_errors %} + + {% endif %} + +
+ + +
+
+ +
+
+
+
+{% endblock %} \ No newline at end of file diff --git a/fbl_integration/templates/fbl_auth_start.html b/fbl_integration/templates/fbl_auth_start.html new file mode 100644 index 0000000..4b3f843 --- /dev/null +++ b/fbl_integration/templates/fbl_auth_start.html @@ -0,0 +1,10 @@ + +{% extends 'base.html' %} +{% block content %} +{% load i18n %} +
+
+ {% include 'partials/attendee_login.html' with fbl_auth_form=form %} +
+
+{% endblock %} \ No newline at end of file diff --git a/fbl_integration/templates/partials/attendee_login.html b/fbl_integration/templates/partials/attendee_login.html new file mode 100644 index 0000000..3572dd8 --- /dev/null +++ b/fbl_integration/templates/partials/attendee_login.html @@ -0,0 +1,32 @@ +{% block attendee_login %} +{% load i18n %} +
+ {% csrf_token %} + + {% if fbl_auth_form.non_field_errors %} + + {% endif %} + +
+ + +
+ + + +
+ +
+
+ {% if general_login %}
{% trans "I don\'t have a seat for this years FBL" %}
{% endif %} +{% endblock %} \ No newline at end of file diff --git a/fbl_integration/tests.py b/fbl_integration/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/fbl_integration/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/fbl_integration/urls.py b/fbl_integration/urls.py new file mode 100644 index 0000000..4678c3a --- /dev/null +++ b/fbl_integration/urls.py @@ -0,0 +1,8 @@ +from django.urls import path + +from .views import fbl_authentication_start, fbl_authentication_get_code + +urlpatterns = [ + path("auth_start", fbl_authentication_start, name="fbl-auth-start"), + path("auth_get_code", fbl_authentication_get_code, name="fbl-auth-get-code") +] diff --git a/fbl_integration/views.py b/fbl_integration/views.py new file mode 100644 index 0000000..6104dd1 --- /dev/null +++ b/fbl_integration/views.py @@ -0,0 +1,19 @@ +from django.shortcuts import render +from .forms import FblAuthForm + +def fbl_authentication_start(request): + if request.method == "POST": + form = FblAuthForm(request.POST) + if form.is_valid(): + + # set hidden fields with dob and badge number + return render(request, "fbl_auth_get_code.html") + else: + return render(request, "fbl_auth_start.html", {"form": form}) + else: + form = FblAuthForm() + + return render(request, "auth_start.html", {"form": form}) + +def fbl_authentication_get_code(request): + return render(request, "fbl_auth_get_code.html") \ No newline at end of file diff --git a/paw/settings.py b/paw/settings.py index 39e68ee..412cf7b 100644 --- a/paw/settings.py +++ b/paw/settings.py @@ -45,6 +45,7 @@ INSTALLED_APPS = [ "django.contrib.messages", "django.contrib.staticfiles", "status", + "fbl_integration", ] AUTH_USER_MODEL = "core.PawUser" @@ -65,7 +66,10 @@ ROOT_URLCONF = "paw.urls" TEMPLATES = [ { "BACKEND": "django.template.backends.django.DjangoTemplates", - "DIRS": [BASE_DIR / 'paw' / 'templates'], + "DIRS": [ + BASE_DIR / 'paw' / 'templates', + BASE_DIR / 'fbl_integration' / 'templates', + ], "APP_DIRS": True, "OPTIONS": { "context_processors": [ diff --git a/paw/templates/core/login.html b/paw/templates/core/login.html index 7a25655..5830f4d 100644 --- a/paw/templates/core/login.html +++ b/paw/templates/core/login.html @@ -9,6 +9,9 @@ {% trans 'Register Account' %}
+ + {% include 'partials/attendee_login.html' with general_login=True %} +
{% csrf_token %} diff --git a/paw/urls.py b/paw/urls.py index 21ca5ff..232fa9b 100644 --- a/paw/urls.py +++ b/paw/urls.py @@ -26,6 +26,7 @@ urlpatterns = [ path("", include("core.urls")), path("", include("ticketing.urls")), path("status", include("status.urls")), + path("fbl/", include("fbl_integration.urls")), ] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) if settings.DEBUG: