Skip to content

Instantly share code, notes, and snippets.

@ryana
Forked from fjania/gist:6660a531edbe9051a0a8
Last active August 29, 2015 14:22
Show Gist options
  • Save ryana/41b7de953fb314c00a7a to your computer and use it in GitHub Desktop.
Save ryana/41b7de953fb314c00a7a to your computer and use it in GitHub Desktop.
import hashlib
import time
def ramen(request):
ramen_js = '';
if not request.user.is_anonymous():
email = request.user.email
user_id = request.user.id
name = "{} {}".format(request.user.first_name, request.user.last_name)
timestamp = int(time.time())
secret_key = "SECRET_KEY_GOES_HERE"
auth_input = "{}:{}:{}:{}:{}".format(
email,
user_id,
name,
timestamp,
secret_key,
)
auth_hash = hashlib.sha256(auth_input).hexdigest()
ramen_js = '''
<!-- This can go anywhere before the ramen.js tag -->
<script>
window.ramenSettings = {{
organization_id: "555cc17077656204242f0000",
user: {{
name: "{name}",
email: "{email}",
id: "{id}",
}},
timestamp: {timestamp},
auth_hash: "{auth_hash}"
}};
</script>
<!-- This goes before the </body> tag -->
<script src="https://cdn.ramen.is/assets/ramen.js" async>
</script>
'''.format(
name = name,
id = user_id,
email = email,
timestamp = timestamp,
auth_hash = auth_hash,
)
return { 'ramen_js': ramen_js }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment