aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--accounts/templates/accounts/index.html14
-rw-r--r--accounts/views.py45
-rw-r--r--manager/settings.py11
-rw-r--r--version.txt2
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 %}
<div class="row">
<div class="input-field col l4 s12">
- <input name="first_name" value="{{first_name}}" id="first_name" type="text" {{validation_dic.first_name|safe}}>
+ <input name="first_name" value="{{first_name}}" id="first_name" type="text" {{validation_dic.first_name|safe}} {{midata_disable}}>
<label for="first_name">Nome</label>
<span class="helper-text" data-error="Campo richiesto"></span>
</div>
<div class="input-field col l4 s12">
- <input name="last_name" value="{{last_name}}" id="last_name" type="text" {{validation_dic.last_name|safe}}>
+ <input name="last_name" value="{{last_name}}" id="last_name" type="text" {{validation_dic.last_name|safe}} {{midata_disable}}>
<label for="last_name">Cognome</label>
<span class="helper-text" data-error="Campo richiesto"></span>
</div>
<div class="input-field col l4 s12">
- <input name="birth_date" value="{{birth_date}}" id="birth_date" type="text" {{validation_dic.birth_date|safe}}>
+ <input name="birth_date" value="{{birth_date}}" id="birth_date" type="text" {{validation_dic.birth_date|safe}} {{midata_disable}}>
<label for="birth_date">Data di nascita</label>
<span class="helper-text" data-error="Campo richiesto"></span>
</div>
@@ -67,17 +67,17 @@
<span class="helper-text" data-error="Campo richiesto"></span>
</div>
<div class="input-field col l12 s12">
- <input value="{{via}}" name="via" id="via" type="text" {{validation_dic.via|safe}}>
+ <input value="{{via}}" name="via" id="via" type="text" {{validation_dic.via|safe}} {{midata_disable}}>
<label for="via">Via e numero</label>
<span class="helper-text" data-error="Campo richiesto"></span>
</div>
<div class="input-field col l4 s12">
- <input value="{{cap}}" name="cap" id="cap" type="text" {{validation_dic.cap|safe}}>
+ <input value="{{cap}}" name="cap" id="cap" type="text" {{validation_dic.cap|safe}} {{midata_disable}}>
<label for="cap">CAP</label>
<span class="helper-text" data-error="Campo richiesto"></span>
</div>
<div class="input-field col l4 s12">
- <input value="{{country}}" name="country" id="country" type="text" {{validation_dic.country|safe}}>
+ <input value="{{country}}" name="country" id="country" type="text" {{validation_dic.country|safe}} {{midata_disable}}>
<label for="country">Comune</label>
<span class="helper-text" data-error="Campo richiesto"></span>
</div>
@@ -96,7 +96,7 @@
<label for="home_phone">Telefono di casa</label>
</div>
<div class="input-field col l4 s12">
- <input value="{{email}}" name="email" id="email" type="text" {{validation_dic.email|safe}}>
+ <input value="{{email}}" name="email" id="email" type="text" {{validation_dic.email|safe}} {{midata_disable}}>
<label for="email">Email</label>
<span class="helper-text" data-error="Campo richiesto"></span>
</div>
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