Created
August 12, 2016 10:01
-
-
Save hawkz/b5cfc65ec61ddb225ea6695f82341976 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Django & Intercom.io | |
Create a template tag: | |
```python | |
import hashlib as h | |
import hmac as h2 | |
@register.filter(name='hmac') | |
def hmac(userid, key): | |
"""Return the encrypted key""" | |
return h2.new(str(key), str(userid), digestmod=h.sha256).hexdigest() | |
``` | |
In your template do something like: | |
```django | |
{% load your_template_tag_here %} | |
<script> | |
{% if not user.is_authenticated %} | |
window.intercomSettings = { | |
app_id: "XXXXXXXX" | |
}; | |
{% else %} | |
window.intercomSettings = { | |
app_id: "XXXXXXXX", | |
name: "{{ request.user.get_full_name }}", // Full name | |
user_id: "{{ request.user.id }}", // User ID | |
created_at: {{ request.user.date_joined|date:"U" }}, // Signup date as a Unix timestamp | |
user_hash: "{{ request.user.id|hmac:'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' }}" | |
}; | |
{% endif %} | |
</script> | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Django / Intercom.io
Create a template tag:
In your template do something like: