49 lines
1.3 KiB
Python
49 lines
1.3 KiB
Python
# -*- 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 JsonResponse
|
|
from django.views import View
|
|
|
|
from core.hep_client import HepClient, HepClientException
|
|
|
|
|
|
class RegistrationProxyView(View):
|
|
|
|
def post(self, request, *args, **kwargs):
|
|
hep_client = HepClient()
|
|
data = json.loads(request.body)
|
|
|
|
if not self.terms_accepted(data['customer']):
|
|
return JsonResponse(
|
|
{
|
|
'message': 'Die AGBs und die Datenschutzbestimmungen müssen akzeptiert werden'
|
|
},
|
|
status=400)
|
|
|
|
data['customer']['group_id'] = 5
|
|
|
|
try:
|
|
hep_data = hep_client.customer_create(data)
|
|
except HepClientException as e:
|
|
return JsonResponse(e.args[1], status=e.args[0])
|
|
|
|
response_data = hep_data.copy()
|
|
del response_data['confirmation']
|
|
|
|
return JsonResponse(response_data)
|
|
|
|
def terms_accepted(self, customer):
|
|
if 'accepted_terms' in customer and customer['accepted_terms']:
|
|
del customer['accepted_terms']
|
|
return True
|
|
|
|
return False
|