Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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