diff --git a/server/api/urls.py b/server/api/urls.py index 69beea15..51835b5f 100644 --- a/server/api/urls.py +++ b/server/api/urls.py @@ -5,7 +5,7 @@ from graphene_django.views import GraphQLView from api.schema_public import schema -from core.views import PrivateGraphQLView +from core.views import PrivateGraphQLView, ConfirmationKeyView app_name = 'api' urlpatterns = [ @@ -17,5 +17,6 @@ if settings.DEBUG: urlpatterns += [url(r'^graphiql-public', csrf_exempt(GraphQLView.as_view(schema=schema, graphiql=True, pretty=True)))] urlpatterns += [url(r'^graphiql', csrf_exempt(PrivateGraphQLView.as_view(graphiql=True, pretty=True)))] + urlpatterns += [url(r'^confirmation', ConfirmationKeyDisplayView.as_view(), name='confirmation_key_display')] diff --git a/server/core/hep_client.py b/server/core/hep_client.py index 58a1fafd..6779b193 100644 --- a/server/core/hep_client.py +++ b/server/core/hep_client.py @@ -34,8 +34,7 @@ class HepClientUnauthorizedException(Exception): class HepClient: - URL = 'https://stage.hep-verlag.ch' - # URL = 'https://www.hep-verlag.ch' + URL = settings.HEP_URL WEBSITE_ID = 1 HEADERS = { 'accept': 'application/json', @@ -118,13 +117,14 @@ class HepClient: }) return response.json() - def customers_search(self, email): + def customers_search(self, admin_token, email): response = self._call("/rest/V1/customers/search?searchCriteria[filterGroups][0][filters][0][field]" - "=email&searchCriteria[filterGroups][0][filters][0][value]={}".format(email)) + "=email&searchCriteria[filterGroups][0][filters][0][value]={}".format(email), method='get', + additional_headers={'authorization': 'Bearer {}'.format(admin_token)}) json_data = response.json() - if len(json_data) > 0: - return json_data[0] + if len(json_data['items']) > 0: + return json_data['items'][0] return None def _customer_orders(self, admin_token, customer_id): diff --git a/server/core/settings.py b/server/core/settings.py index 86f66bb7..204cf128 100644 --- a/server/core/settings.py +++ b/server/core/settings.py @@ -374,5 +374,6 @@ USE_LOCAL_REGISTRATION = False # HEP HEP_ADMIN_USER = "adminuser" HEP_ADMIN_PASSWORD = "password" +HEP_URL = 'https://stage.hep-verlag.ch' diff --git a/server/core/templates/confirmation_key.html b/server/core/templates/confirmation_key.html new file mode 100644 index 00000000..876f9568 --- /dev/null +++ b/server/core/templates/confirmation_key.html @@ -0,0 +1,10 @@ + + + + + Confirmation + + + Email bestÃĪtitgen + + diff --git a/server/core/views.py b/server/core/views.py index b495cfc1..8ccd7dd2 100644 --- a/server/core/views.py +++ b/server/core/views.py @@ -7,9 +7,13 @@ from django.http.response import HttpResponse from django.shortcuts import render from django.urls import reverse_lazy from django.views.decorators.csrf import ensure_csrf_cookie +from django.views.generic import TemplateView from graphene_django.views import GraphQLView from django.utils.translation import gettext_lazy as _ +from core.hep_client import HepClient +from core.models import AdminData + class PrivateGraphQLView(LoginRequiredMixin, GraphQLView): pass @@ -73,3 +77,20 @@ class LegacySetPasswordConfirmView(PasswordResetConfirmView): class LegacySetPasswordCompleteView(PasswordResetCompleteView): template_name = 'registration/set_password_complete.html' title = _('Passwort setzen erfolgreich') + + +class ConfirmationKeyDisplayView(TemplateView): + + template_name = 'confirmation_key.html' + + def get_context_data(self, request, *args, **kwargs): + + email = request.GET.get('email', '') + + hep_client = HepClient() + admin_token = AdminData.objects.get_admin_token() + hep_user = hep_client.customers_search(admin_token, email) + + context = super().get_context_data(**kwargs) + context['confirmation_key'] = hep_user['confirmation'] + return context