From 329fbce8ad022df8cee47f105ec9f44a6ca27f11 Mon Sep 17 00:00:00 2001 From: Andrea Lepori Date: Mon, 3 Jan 2022 11:20:22 +0100 Subject: sync data from hitobito --- accounts/templates/accounts/index.html | 14 +++++------ accounts/views.py | 45 ++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 7 deletions(-) (limited to 'accounts') diff --git a/accounts/templates/accounts/index.html b/accounts/templates/accounts/index.html index 061da5d..4133270 100644 --- a/accounts/templates/accounts/index.html +++ b/accounts/templates/accounts/index.html @@ -29,17 +29,17 @@ {% csrf_token %}
- +
- +
- +
@@ -67,17 +67,17 @@
- +
- +
- +
@@ -96,7 +96,7 @@
- +
diff --git a/accounts/views.py b/accounts/views.py index 26d45fa..abfd184 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -75,6 +75,18 @@ def auth(request): if len(usercode) > 0: # user exist login(request, usercode[0].user) + + request.user.first_name = resp_data["first_name"] + request.user.last_name = resp_data["last_name"] + request.user.email = resp_data["email"] + request.user.save() + + usercode[0].via = resp_data["address"] + usercode[0].cap = resp_data["zip_code"] + usercode[0].country = resp_data["town"] + usercode[0].born_date = dateparser.parse(resp_data["birthday"]) + usercode[0].save() + return HttpResponseRedirect('/') user = User.objects.create_user(resp_data["email"], resp_data["email"]) @@ -88,6 +100,15 @@ def auth(request): medic = MedicalData() medic.save() userCode = UserCode(user=user, code=code, medic=medic, midata_id=resp_data["id"], midata_token=token["access_token"]) + user.first_name = resp_data["first_name"] + user.last_name = resp_data["last_name"] + user.email = resp_data["email"] + user.save() + + userCode.via = resp_data["address"] + userCode.cap = resp_data["zip_code"] + userCode.country = resp_data["town"] + userCode.born_date = dateparser.parse(resp_data["birthday"]) userCode.save() login(request, user) @@ -459,6 +480,29 @@ def personal_wrapper(request, error, error_text): card_name = '' midata_user = (usercode.midata_id > 0) + midata_disable = "" + + if midata_user: + # request data from user account + headers = { + "Authorization" : "Bearer " + usercode.midata_token, + "X-Scope": "with_roles", + } + + resp = requests.get(api_url, headers=headers) + resp_data = resp.json() + + midata_disable = " disabled" + request.user.first_name = resp_data["first_name"] + request.user.last_name = resp_data["last_name"] + request.user.email = resp_data["email"] + request.user.save() + + usercode.via = resp_data["address"] + usercode.cap = resp_data["zip_code"] + usercode.country = resp_data["town"] + usercode.born_date = dateparser.parse(resp_data["birthday"]) + usercode.save() # fill context context = { @@ -508,6 +552,7 @@ def personal_wrapper(request, error, error_text): 'error': error, 'error_text': error_text, 'midata_user': midata_user, + 'midata_disable': midata_disable, } return render(request, 'accounts/index.html', context) -- cgit v1.2.1