# Path: esteid/views.py
# class SKTestView(TemplateView):
#     template_name = "esteid/test.html"
# 
#     def get_context_data(self, **kwargs):
#         context = super(SKTestView, self).get_context_data(**kwargs)
# 
#         try:
#             files = self.request.session["__ddoc_files"]
# 
#         except KeyError:
#             files = {}
# 
#         context.update(
#             {
#                 "files": files,
#             }
#         )
# 
#         return context
# 
#     def post(self, request, *args, **kwargs):
#         """This method is only for testing and can
#         be used to add some files to the session.
# 
#         actions:
# 
#             - add_file
#             - remove_file
#         """
#         try:
#             files = request.session["__ddoc_files"]
# 
#         except KeyError:
#             files = {}
# 
#         action = request.POST.get("action", "add_file")
# 
#         if action == "remove_file":
#             file_name = request.POST.get("file_name", "")
# 
#             n_files = {}
#             for key, file in files.items():
#                 if key != file_name:
#                     n_files[key] = file
# 
#             files = n_files
# 
#         else:
#             for key, file in request.FILES.items():
#                 file_name = file.name
# 
#                 idx = 1
#                 while file_name in files.keys():
#                     file_name = f"{idx}_{file_name}"
#                     idx += 1
# 
#                 files[file_name] = dict(
#                     content=base64.b64encode(file.read()).decode(),
#                     content_type=file.content_type,
#                     size=file.size,
#                 )
# 
#         request.session["__ddoc_files"] = files
# 
#         return HttpResponseRedirect(".")
# 
# class TestDownloadContainerView(View):
#     def get(self, request, *args, **kwargs):
#         request.session.pop("__ddoc_files", None)
# 
#         container_file = request.session.pop("__ddoc_container_file", None)
#         logging.info("Got container temp file name '%s'", container_file)
#         file_contents = None
#         if container_file:
#             try:
#                 with open(container_file, "rb") as f:
#                     file_contents = f.read()
#             except FileNotFoundError:
#                 pass
# 
#         if not file_contents:
#             response = HttpResponse("Error: no container file found", status=409)
#         else:
#             # Download the file
#             response = HttpResponse(file_contents, content_type=Container.MIME_TYPE)
#             response["Content-Disposition"] = "attachment; filename=" + "signed.bdoc"
#         return response
# 
# class TestIdCardFinishView(TestSignStatusViewMixin, ApiView):
#     ACTION_CLASS = IdCardFinishAction
# 
#     def build_action_kwargs(self, request):
#         return dict(signature_value=request.POST["signature_value"])
# 
# class TestIdCardSignView(TestFilesMixin, ApiView):
#     def post(self, request, *args, **kwargs):
#         return IdCardPrepareAction.do_action(self, certificate=request.POST["certificate"])
# 
# class TestMobileIdSignView(TestFilesMixin, ApiView):
#     def post(self, request, *args, **kwargs):
#         return MobileIdSignAction.do_action(
#             self,
#             id_code=request.POST.get("id_code", ""),
#             phone_number=request.POST.get("phone_nr", ""),
#             language=request.POST.get("language", None),
#         )
# 
# class TestMobileIdStatusView(TestSignStatusViewMixin, ApiView):
#     ACTION_CLASS = MobileIdStatusAction
# 
# class TestSmartIdSignView(TestFilesMixin, ApiView):
#     def post(self, request, *args, **kwargs):
#         return SmartIdSignAction.do_action(
#             self,
#             id_code=request.POST.get("id_code", ""),
#             language=request.POST.get("language", None),
#         )
# 
# class TestSmartIdStatusView(TestSignStatusViewMixin, ApiView):
#     ACTION_CLASS = SmartIdStatusAction


import os
import esteid.flowtest.urls
from django.conf import settings
from django.conf.urls import include, url
from django.conf.urls.static import static
from django.views.generic import TemplateView
from .views import (
    SKTestView,
    TestDownloadContainerView,
    TestIdCardFinishView,
    TestIdCardSignView,
    TestMobileIdSignView,
    TestMobileIdStatusView,
    TestSmartIdSignView,
    TestSmartIdStatusView,
)





urlpatterns = []

# In a project, the URLs can be included if settings.DEBUG is on.
# In tests, settings.DEBUG is False for unknown reasons, so we check that the root urlconf points at this file.
if settings.DEBUG or settings.ROOT_URLCONF == __name__:
    urlpatterns += [
        url("^$", SKTestView.as_view(), name="sk_test"),
        # NOTE: compare the template test-new.html to test.html locally to see JS changes.
        url(r"^new/", SKTestView.as_view(template_name="esteid/test-new.html"), name="sk_test_new"),
        url(r"^new-auth/", TemplateView.as_view(template_name="esteid/auth-new.html"), name="sk_test_auth_new"),
        url(r"^download/", TestDownloadContainerView.as_view(), name="download_signed_container"),
        url(r"^id/start/", TestIdCardSignView.as_view(), name="test_id_start"),
        url(r"^id/finish/", TestIdCardFinishView.as_view(), name="test_id_finish"),
        url(r"^mid/start/", TestMobileIdSignView.as_view(), name="test_mid_start"),
        url(r"^mid/status/", TestMobileIdStatusView.as_view(), name="test_mid_status"),
        url(r"^smartid/start/", TestSmartIdSignView.as_view(), name="test_smartid_start"),

# Path: esteid/views.py
# class SKTestView(TemplateView):
#     template_name = "esteid/test.html"
# 
#     def get_context_data(self, **kwargs):
#         context = super(SKTestView, self).get_context_data(**kwargs)
# 
#         try:
#             files = self.request.session["__ddoc_files"]
# 
#         except KeyError:
#             files = {}
# 
#         context.update(
#             {
#                 "files": files,
#             }
#         )
# 
#         return context
# 
#     def post(self, request, *args, **kwargs):
#         """This method is only for testing and can
#         be used to add some files to the session.
# 
#         actions:
# 
#             - add_file
#             - remove_file
#         """
#         try:
#             files = request.session["__ddoc_files"]
# 
#         except KeyError:
#             files = {}
# 
#         action = request.POST.get("action", "add_file")
# 
#         if action == "remove_file":
#             file_name = request.POST.get("file_name", "")
# 
#             n_files = {}
#             for key, file in files.items():
#                 if key != file_name:
#                     n_files[key] = file
# 
#             files = n_files
# 
#         else:
#             for key, file in request.FILES.items():
#                 file_name = file.name
# 
#                 idx = 1
#                 while file_name in files.keys():
#                     file_name = f"{idx}_{file_name}"
#                     idx += 1
# 
#                 files[file_name] = dict(
#                     content=base64.b64encode(file.read()).decode(),
#                     content_type=file.content_type,
#                     size=file.size,
#                 )
# 
#         request.session["__ddoc_files"] = files
# 
#         return HttpResponseRedirect(".")
# 
# class TestDownloadContainerView(View):
#     def get(self, request, *args, **kwargs):
#         request.session.pop("__ddoc_files", None)
# 
#         container_file = request.session.pop("__ddoc_container_file", None)
#         logging.info("Got container temp file name '%s'", container_file)
#         file_contents = None
#         if container_file:
#             try:
#                 with open(container_file, "rb") as f:
#                     file_contents = f.read()
#             except FileNotFoundError:
#                 pass
# 
#         if not file_contents:
#             response = HttpResponse("Error: no container file found", status=409)
#         else:
#             # Download the file
#             response = HttpResponse(file_contents, content_type=Container.MIME_TYPE)
#             response["Content-Disposition"] = "attachment; filename=" + "signed.bdoc"
#         return response
# 
# class TestIdCardFinishView(TestSignStatusViewMixin, ApiView):
#     ACTION_CLASS = IdCardFinishAction
# 
#     def build_action_kwargs(self, request):
#         return dict(signature_value=request.POST["signature_value"])
# 
# class TestIdCardSignView(TestFilesMixin, ApiView):
#     def post(self, request, *args, **kwargs):
#         return IdCardPrepareAction.do_action(self, certificate=request.POST["certificate"])
# 
# class TestMobileIdSignView(TestFilesMixin, ApiView):
#     def post(self, request, *args, **kwargs):
#         return MobileIdSignAction.do_action(
#             self,
#             id_code=request.POST.get("id_code", ""),
#             phone_number=request.POST.get("phone_nr", ""),
#             language=request.POST.get("language", None),
#         )
# 
# class TestMobileIdStatusView(TestSignStatusViewMixin, ApiView):
#     ACTION_CLASS = MobileIdStatusAction
# 
# class TestSmartIdSignView(TestFilesMixin, ApiView):
#     def post(self, request, *args, **kwargs):
#         return SmartIdSignAction.do_action(
#             self,
#             id_code=request.POST.get("id_code", ""),
#             language=request.POST.get("language", None),
#         )
# 
# class TestSmartIdStatusView(TestSignStatusViewMixin, ApiView):
#     ACTION_CLASS = SmartIdStatusAction


# Path: esteid/urls.py
import os
import esteid.flowtest.urls
from django.conf import settings
from django.conf.urls import include, url
from django.conf.urls.static import static
from django.views.generic import TemplateView
from .views import (
    SKTestView,
    TestDownloadContainerView,
    TestIdCardFinishView,
    TestIdCardSignView,
    TestMobileIdSignView,
    TestMobileIdStatusView,
    TestSmartIdSignView,
    TestSmartIdStatusView,
)






urlpatterns = []

# In a project, the URLs can be included if settings.DEBUG is on.
# In tests, settings.DEBUG is False for unknown reasons, so we check that the root urlconf points at this file.
if settings.DEBUG or settings.ROOT_URLCONF == __name__:
    urlpatterns += [
        url("^$", SKTestView.as_view(), name="sk_test"),
        # NOTE: compare the template test-new.html to test.html locally to see JS changes.
        url(r"^new/", SKTestView.as_view(template_name="esteid/test-new.html"), name="sk_test_new"),
        url(r"^new-auth/", TemplateView.as_view(template_name="esteid/auth-new.html"), name="sk_test_auth_new"),
        url(r"^download/", TestDownloadContainerView.as_view(), name="download_signed_container"),
        url(r"^id/start/", TestIdCardSignView.as_view(), name="test_id_start"),
        url(r"^id/finish/", TestIdCardFinishView.as_view(), name="test_id_finish"),
        url(r"^mid/start/", TestMobileIdSignView.as_view(), name="test_mid_start"),
        url(r"^mid/status/", TestMobileIdStatusView.as_view(), name="test_mid_status"),
        url(r"^smartid/start/", TestSmartIdSignView.as_view(), name="test_smartid_start"),

        url(r"^smartid/status/", TestSmartIdStatusView.as_view(), name="test_smartid_status"),