Add proxy for registration call
This commit is contained in:
parent
fff752f59d
commit
b572523a33
|
|
@ -3,7 +3,7 @@ import * as axios from 'axios'
|
|||
const hepBaseUrl = 'https://stage.hep-verlag.ch';
|
||||
|
||||
export function register(registrationData) {
|
||||
return axios.post(`${hepBaseUrl}/rest/deutsch/V1/customers`, registrationData);
|
||||
return axios.post('/api/proxy/registration/', registrationData);
|
||||
}
|
||||
|
||||
export function login(username, password) {
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@ import Logo from '@/components/icons/Logo';
|
|||
margin: 0 auto;
|
||||
}
|
||||
|
||||
|
||||
.public {
|
||||
grid-template-areas: "h" "c" "f";
|
||||
|
||||
|
|
@ -44,7 +43,13 @@ import Logo from '@/components/icons/Logo';
|
|||
width: 100%;
|
||||
}
|
||||
|
||||
&__content, &__logo {
|
||||
&__content {
|
||||
@include content-block();
|
||||
margin-bottom: $large-spacing;
|
||||
}
|
||||
|
||||
|
||||
&__logo {
|
||||
@include content-block();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
from django.conf import settings
|
||||
from django.conf.urls import url
|
||||
from django.urls import include
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from graphene_django.views import GraphQLView
|
||||
|
||||
|
|
@ -11,6 +12,9 @@ app_name = 'api'
|
|||
urlpatterns = [
|
||||
url(r'^graphql-public', csrf_exempt(GraphQLView.as_view(schema=schema))),
|
||||
url(r'^graphql', csrf_exempt(PrivateGraphQLView.as_view())),
|
||||
|
||||
# hep proxy
|
||||
url(r'^proxy/', include('registration.urls', namespace="registration")),
|
||||
]
|
||||
|
||||
if settings.DEBUG:
|
||||
|
|
|
|||
|
|
@ -82,18 +82,7 @@ class HepClient:
|
|||
response = self._call('/rest/V1/customers/me', method='put', data={'confirmationKey': confirmation_key})
|
||||
return response.json()
|
||||
|
||||
def customer_create(self, customer_data, address):
|
||||
|
||||
if customer_data['prefix'] == 'Herr':
|
||||
customer_data['gender'] = 1
|
||||
else:
|
||||
customer_data['gender'] = 2
|
||||
|
||||
address['country_id'] = 'CH'
|
||||
address['default_billing'] = True
|
||||
address['default_shipping'] = True
|
||||
|
||||
customer_data['addresses'] = [address]
|
||||
def customer_create(self, customer_data):
|
||||
|
||||
response = self._call('/rest/deutsch/V1/customers', method='post', data=customer_data)
|
||||
return response.json()
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ from django.conf import settings
|
|||
from django.conf.urls import url, include
|
||||
from django.conf.urls.static import static
|
||||
from django.contrib import admin
|
||||
from django.urls import re_path, path
|
||||
from django.urls import re_path
|
||||
from django.views.generic import RedirectView
|
||||
from wagtail.admin import urls as wagtailadmin_urls
|
||||
from wagtail.core import urls as wagtail_urls
|
||||
|
|
|
|||
|
|
@ -0,0 +1,86 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# ITerativ GmbH
|
||||
# http://www.iterativ.ch/
|
||||
#
|
||||
# Copyright (c) 2020 ITerativ GmbH. All rights reserved.
|
||||
#
|
||||
# Created on 25.02.20
|
||||
# @author: chrigu <christian.cueni@iterativ.ch>
|
||||
import json
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
import requests
|
||||
from django.test import TestCase, Client
|
||||
from django.urls import reverse
|
||||
|
||||
from core.hep_client import HepClient
|
||||
from core.tests.mock_hep_data_factory import MockResponse
|
||||
|
||||
RESPONSE = {
|
||||
'id': 1234,
|
||||
'confirmation': 'abdc1234',
|
||||
'firstname': 'Pesche',
|
||||
'lastname': 'Zubrüti',
|
||||
'email': 'aschima@ch.ch',
|
||||
'prefix': 'Herr',
|
||||
'gender': 1,
|
||||
'addresses': [
|
||||
{
|
||||
'country_id': 'CH',
|
||||
'street': ['Weg 1'],
|
||||
'postcode': '1234',
|
||||
'city': 'Äussere Einöde',
|
||||
'firstname': 'Pesche',
|
||||
'lastname': 'Zubrüti',
|
||||
'prefix': 'Herr',
|
||||
'default_shipping': True,
|
||||
'default_billing': True,
|
||||
}
|
||||
],
|
||||
}
|
||||
|
||||
DATA = {
|
||||
'customer': {
|
||||
'firstname': 'Pesche',
|
||||
'lastname': 'Zubrüti',
|
||||
'email': 'aschima@ch.ch',
|
||||
'prefix': 'Herr',
|
||||
'gender': 1,
|
||||
'addresses': [
|
||||
{
|
||||
'country_id': 'CH',
|
||||
'street': ['Weg 1'],
|
||||
'postcode': '1234',
|
||||
'city': 'Äussere Einöde',
|
||||
'firstname': 'Pesche',
|
||||
'lastname': 'Zubrüti',
|
||||
'prefix': 'Herr',
|
||||
'default_shipping': True,
|
||||
'default_billing': True,
|
||||
}
|
||||
],
|
||||
'password': '123454abasfd'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class ProxyTest(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.client = Client()
|
||||
|
||||
@patch.object(HepClient, 'customer_create', return_value=RESPONSE)
|
||||
def test_proxy_filters_confirmation_key(self, create_mock):
|
||||
|
||||
response = self.client.post(reverse('api:registration:proxy'), DATA)
|
||||
found = 'confirmation' in response.json().keys()
|
||||
self.assertFalse(found)
|
||||
|
||||
@patch.object(requests, 'post', return_value=MockResponse(400,
|
||||
data={'message': 'Ein Kunde mit der gleichen E-Mail-Adresse existiert bereits in einer zugeordneten Website.'}))
|
||||
def test_handles_400(self, create_mock):
|
||||
|
||||
response = self.client.post(reverse('api:registration:proxy'), DATA)
|
||||
self.assertEquals(response.json()['message'], 'Ein Kunde mit der gleichen E-Mail-Adresse existiert bereits in einer zugeordneten Website.')
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# ITerativ GmbH
|
||||
# http://www.iterativ.ch/
|
||||
#
|
||||
# Copyright (c) 2020 ITerativ GmbH. All rights reserved.
|
||||
#
|
||||
# Created on 25.02.20
|
||||
# @author: chrigu <christian.cueni@iterativ.ch>
|
||||
from django.conf.urls import url
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
|
||||
from registration.view import RegistrationProxyView
|
||||
|
||||
app_name = 'registration'
|
||||
urlpatterns = [
|
||||
url(r'^registration/', csrf_exempt(RegistrationProxyView.as_view()), name="proxy"),
|
||||
]
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# ITerativ GmbH
|
||||
# http://www.iterativ.ch/
|
||||
#
|
||||
# Copyright (c) 2020 ITerativ GmbH. All rights reserved.
|
||||
#
|
||||
# Created on 25.02.20
|
||||
# @author: chrigu <christian.cueni@iterativ.ch>
|
||||
import json
|
||||
|
||||
from django.http import HttpResponse
|
||||
from django.views import View
|
||||
|
||||
from core.hep_client import HepClient, HepClientException
|
||||
|
||||
|
||||
class RegistrationProxyView(View):
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
hep_client = HepClient()
|
||||
|
||||
if request.POST:
|
||||
data = request.POST
|
||||
else:
|
||||
data = json.loads(request.body)
|
||||
|
||||
try:
|
||||
hep_data = hep_client.customer_create(data)
|
||||
except HepClientException as e:
|
||||
return HttpResponse(json.dumps(e.args[1]), status=e.args[0], content_type='application/json')
|
||||
|
||||
response_data = hep_data.copy()
|
||||
del response_data['confirmation']
|
||||
|
||||
return HttpResponse(json.dumps(response_data), content_type='application/json')
|
||||
|
||||
Loading…
Reference in New Issue