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 ++++++++++++++++++++++++++++++++++ manager/settings.py | 11 ++++----- version.txt | 2 +- 4 files changed, 58 insertions(+), 14 deletions(-) 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) diff --git a/manager/settings.py b/manager/settings.py index b922de7..904600b 100644 --- a/manager/settings.py +++ b/manager/settings.py @@ -57,7 +57,6 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', - "django_extensions", ] MIDDLEWARE = [ @@ -72,14 +71,14 @@ MIDDLEWARE = [ AUTHLIB_OAUTH_CLIENTS = { 'hitobito': { - 'client_id': 'uZOLGZDioF0FBm5FlkSYkiCJ0nsNErZmLgCDMbWiHYY', - 'client_secret': '-Vv4El7-UmiSoET_tvgqeNnJzrSN_76b9I_zKFZFKpo', - 'access_token_url': 'https://demo.hitobito.com/oauth/token', + 'client_id': 't5yYztJorDVXRE7PgPy7AttzarwTFW8faPrm56wsbSg', + 'client_secret': 'hgpsKjMGymVsi-dAeOFMWv2V2IpIbdILZJ1SIOT5cSA', + 'access_token_url': 'https://pbs.puzzle.ch/oauth/token', 'access_token_params': None, 'refresh_token_url': None, - 'authorize_url': 'https://demo.hitobito.com/oauth/authorize', + 'authorize_url': 'https://pbs.puzzle.ch/oauth/authorize', 'authorize_params': None, - 'api_url': "https://demo.hitobito.com/oauth/profile", + 'api_url': "https://pbs.puzzle.ch/oauth/profile", 'client_kwargs': {"grant_type": "authorization_code", "scope": "with_roles"}, } } diff --git a/version.txt b/version.txt index f283d1b..6fcdb3a 100644 --- a/version.txt +++ b/version.txt @@ -1,2 +1,2 @@ version=0.4 -rev=10 +rev=11 -- cgit v1.2.1