/gist:41b7de953fb314c00a7a Secret
Last active
August 29, 2015 14:22
-
-
Save ryana/41b7de953fb314c00a7a 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
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