From d741139e4f028a65620d4a7f3dcafb845e28c2eb Mon Sep 17 00:00:00 2001 From: Tom S Date: Tue, 27 Nov 2012 19:45:38 +0000 Subject: [PATCH 1/4] use new intercom JS - as per intercom docs --- intercom/templates/intercom/_intercom_js.html | 21 ++++--------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/intercom/templates/intercom/_intercom_js.html b/intercom/templates/intercom/_intercom_js.html index 2567590..5ca488f 100644 --- a/intercom/templates/intercom/_intercom_js.html +++ b/intercom/templates/intercom/_intercom_js.html @@ -1,9 +1,9 @@ {% if email %} - + {% endif %} From ae012b7f1d4edadcf9d425b51dd6329e3eb322df Mon Sep 17 00:00:00 2001 From: Tom S Date: Tue, 27 Nov 2012 19:46:35 +0000 Subject: [PATCH 2/4] hash: user.id instead of user.email - compatibility with intercom secure mode --- intercom/templatetags/intercom_tags.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/intercom/templatetags/intercom_tags.py b/intercom/templatetags/intercom_tags.py index 51b7eed..4d7d681 100644 --- a/intercom/templatetags/intercom_tags.py +++ b/intercom/templatetags/intercom_tags.py @@ -13,7 +13,7 @@ def intercom_js(user): if hasattr(settings, "INTERCOM_APP_ID") and user.is_authenticated(): if hasattr(settings, "INTERCOM_USER_HASH_KEY"): - user_hash = sha_constructor(settings.INTERCOM_USER_HASH_KEY + user.email).hexdigest() + user_hash = sha_constructor(settings.INTERCOM_USER_HASH_KEY + user.id).hexdigest() else: user_hash = None From ebd606a0e448351e082b298b50273c3aaa5120c6 Mon Sep 17 00:00:00 2001 From: Tom S Date: Tue, 27 Nov 2012 19:47:42 +0000 Subject: [PATCH 3/4] rearrange if statment in template tag --- intercom/templatetags/intercom_tags.py | 38 +++++++++++++------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/intercom/templatetags/intercom_tags.py b/intercom/templatetags/intercom_tags.py index 4d7d681..780be48 100644 --- a/intercom/templatetags/intercom_tags.py +++ b/intercom/templatetags/intercom_tags.py @@ -11,23 +11,23 @@ @register.inclusion_tag("intercom/_intercom_js.html") def intercom_js(user): - if hasattr(settings, "INTERCOM_APP_ID") and user.is_authenticated(): - if hasattr(settings, "INTERCOM_USER_HASH_KEY"): - user_hash = sha_constructor(settings.INTERCOM_USER_HASH_KEY + user.id).hexdigest() - else: - user_hash = None - - custom_data = {} - for app in getattr(settings, "INTERCOM_APPS", []): - m = __import__(app + ".intercom", globals(), locals(), ["intercom"]) - custom_data.update(m.custom_data(user)) - - return { - "app_id": settings.INTERCOM_APP_ID, - "email": user.email, - "user_hash": user_hash, - "created_at": int(time.mktime(user.date_joined.timetuple())), - "custom_data": simplejson.dumps(custom_data, ensure_ascii=False) - } - else: + if not (hasattr(settings, "INTERCOM_APP_ID") and user.is_authenticated()): return {} + + if hasattr(settings, "INTERCOM_USER_HASH_KEY"): + user_hash = sha_constructor(settings.INTERCOM_USER_HASH_KEY + user.id).hexdigest() + else: + user_hash = None + + custom_data = {} + for app in getattr(settings, "INTERCOM_APPS", []): + m = __import__(app + ".intercom", globals(), locals(), ["intercom"]) + custom_data.update(m.custom_data(user)) + + return { + "app_id": settings.INTERCOM_APP_ID, + "email": user.email, + "user_hash": user_hash, + "created_at": int(time.mktime(user.date_joined.timetuple())), + "custom_data": simplejson.dumps(custom_data, ensure_ascii=False) + } From d55e2700d7f1967c705fb6eab4d8d3002b4db6f5 Mon Sep 17 00:00:00 2001 From: Tom S Date: Thu, 29 Nov 2012 14:47:10 +0000 Subject: [PATCH 4/4] add user_id field --- intercom/templates/intercom/_intercom_js.html | 1 + 1 file changed, 1 insertion(+) diff --git a/intercom/templates/intercom/_intercom_js.html b/intercom/templates/intercom/_intercom_js.html index 5ca488f..2bec399 100644 --- a/intercom/templates/intercom/_intercom_js.html +++ b/intercom/templates/intercom/_intercom_js.html @@ -3,6 +3,7 @@ var intercomSettings = { app_id: '{{ app_id }}', email: '{{ email }}', + user_id: '{{ user.id }}', {% if user_hash %}user_hash: '{{ user_hash }}',{% endif %} custom_data: {{ custom_data|safe }}, created_at: {{ created_at }},