{"action":"created","comment":{"url":"https://api.github.com/repos/sempliva/Emotly/pulls/comments/59351017","id":59351017,"diff_hunk":"@@ -43,3 +43,47 @@ def send_email_confirmation(email, confirmation_token):\n                                \"https://emotly.herokuapp.com/confirm_email/\" +\n                                confirmation_token)\n     message.send()\n+\n+\n+# Generate a Json Web Token fro a given user\n+# TODO: add support for different hash algorithms\n+def gen_jwt_token(user, delta=datetime.timedelta(hours=300)):\n+    if user is None:\n+        return None\n+    # generate the header and the payload message\n+    header = {'algo': 'sha256', 'type': 'jwt'}\n+    payload = {'username': user.nickname,\n+               'expire': (user.last_login+delta).strftime(\"%Y:%m:%d %H:%M:%S\")\n+               }\n+    # sign token using a cryptografically hash algoritm\n+    signature = sign_jwt(header, payload)\n+    jwt = {'header': header, 'payload': payload, 'signature': signature}\n+\n+    return jwt\n+\n+\n+# Return True if a given token is valid\n+def verify_jwt_token(user, token):\n+    json_format = json.loads(token)\n+    try:\n+        User.objects.get(nickname=json_format[\"payload\"][\"username\"])","path":"emotly/utils.py","position":27,"original_position":27,"commit_id":"be33bb683ef6d9def96ceaf87137bcad39efd05b","original_commit_id":"be33bb683ef6d9def96ceaf87137bcad39efd05b","user":{"login":"ggc87","id":1409824,"avatar_url":"https://avatars.githubusercontent.com/u/1409824?v=3","gravatar_id":"","url":"https://api.github.com/users/ggc87","html_url":"https://github.com/ggc87","followers_url":"https://api.github.com/users/ggc87/followers","following_url":"https://api.github.com/users/ggc87/following{/other_user}","gists_url":"https://api.github.com/users/ggc87/gists{/gist_id}","starred_url":"https://api.github.com/users/ggc87/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ggc87/subscriptions","organizations_url":"https://api.github.com/users/ggc87/orgs","repos_url":"https://api.github.com/users/ggc87/repos","events_url":"https://api.github.com/users/ggc87/events{/privacy}","received_events_url":"https://api.github.com/users/ggc87/received_events","type":"User","site_admin":false},"body":"I've removed any check on the user.","created_at":"2016-04-12T10:02:17Z","updated_at":"2016-04-12T10:02:18Z","html_url":"https://github.com/sempliva/Emotly/pull/20#discussion_r59351017","pull_request_url":"https://api.github.com/repos/sempliva/Emotly/pulls/20","_links":{"self":{"href":"https://api.github.com/repos/sempliva/Emotly/pulls/comments/59351017"},"html":{"href":"https://github.com/sempliva/Emotly/pull/20#discussion_r59351017"},"pull_request":{"href":"https://api.github.com/repos/sempliva/Emotly/pulls/20"}}},"pull_request":{"url":"https://api.github.com/repos/sempliva/Emotly/pulls/20","id":66067408,"html_url":"https://github.com/sempliva/Emotly/pull/20","diff_url":"https://github.com/sempliva/Emotly/pull/20.diff","patch_url":"https://github.com/sempliva/Emotly/pull/20.patch","issue_url":"https://api.github.com/repos/sempliva/Emotly/issues/20","number":20,"state":"open","locked":false,"title":"Added functions to generate, sign and verify a Json Web Token","user":{"login":"ggc87","id":1409824,"avatar_url":"https://avatars.githubusercontent.com/u/1409824?v=3","gravatar_id":"","url":"https://api.github.com/users/ggc87","html_url":"https://github.com/ggc87","followers_url":"https://api.github.com/users/ggc87/followers","following_url":"https://api.github.com/users/ggc87/following{/other_user}","gists_url":"https://api.github.com/users/ggc87/gists{/gist_id}","starred_url":"https://api.github.com/users/ggc87/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ggc87/subscriptions","organizations_url":"https://api.github.com/users/ggc87/orgs","repos_url":"https://api.github.com/users/ggc87/repos","events_url":"https://api.github.com/users/ggc87/events{/privacy}","received_events_url":"https://api.github.com/users/ggc87/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-04-11T21:41:38Z","updated_at":"2016-04-12T10:02:18Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5c5019534bc17c19a2d5076b65b94b5018987c09","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/sempliva/Emotly/pulls/20/commits","review_comments_url":"https://api.github.com/repos/sempliva/Emotly/pulls/20/comments","review_comment_url":"https://api.github.com/repos/sempliva/Emotly/pulls/comments{/number}","comments_url":"https://api.github.com/repos/sempliva/Emotly/issues/20/comments","statuses_url":"https://api.github.com/repos/sempliva/Emotly/statuses/be33bb683ef6d9def96ceaf87137bcad39efd05b","head":{"label":"sempliva:jwt_token","ref":"jwt_token","sha":"be33bb683ef6d9def96ceaf87137bcad39efd05b","user":{"login":"sempliva","id":18060320,"avatar_url":"https://avatars.githubusercontent.com/u/18060320?v=3","gravatar_id":"","url":"https://api.github.com/users/sempliva","html_url":"https://github.com/sempliva","followers_url":"https://api.github.com/users/sempliva/followers","following_url":"https://api.github.com/users/sempliva/following{/other_user}","gists_url":"https://api.github.com/users/sempliva/gists{/gist_id}","starred_url":"https://api.github.com/users/sempliva/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sempliva/subscriptions","organizations_url":"https://api.github.com/users/sempliva/orgs","repos_url":"https://api.github.com/users/sempliva/repos","events_url":"https://api.github.com/users/sempliva/events{/privacy}","received_events_url":"https://api.github.com/users/sempliva/received_events","type":"Organization","site_admin":false},"repo":{"id":54905411,"name":"Emotly","full_name":"sempliva/Emotly","owner":{"login":"sempliva","id":18060320,"avatar_url":"https://avatars.githubusercontent.com/u/18060320?v=3","gravatar_id":"","url":"https://api.github.com/users/sempliva","html_url":"https://github.com/sempliva","followers_url":"https://api.github.com/users/sempliva/followers","following_url":"https://api.github.com/users/sempliva/following{/other_user}","gists_url":"https://api.github.com/users/sempliva/gists{/gist_id}","starred_url":"https://api.github.com/users/sempliva/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sempliva/subscriptions","organizations_url":"https://api.github.com/users/sempliva/orgs","repos_url":"https://api.github.com/users/sempliva/repos","events_url":"https://api.github.com/users/sempliva/events{/privacy}","received_events_url":"https://api.github.com/users/sempliva/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/sempliva/Emotly","description":"Public instance of the Emotly service","fork":false,"url":"https://api.github.com/repos/sempliva/Emotly","forks_url":"https://api.github.com/repos/sempliva/Emotly/forks","keys_url":"https://api.github.com/repos/sempliva/Emotly/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sempliva/Emotly/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sempliva/Emotly/teams","hooks_url":"https://api.github.com/repos/sempliva/Emotly/hooks","issue_events_url":"https://api.github.com/repos/sempliva/Emotly/issues/events{/number}","events_url":"https://api.github.com/repos/sempliva/Emotly/events","assignees_url":"https://api.github.com/repos/sempliva/Emotly/assignees{/user}","branches_url":"https://api.github.com/repos/sempliva/Emotly/branches{/branch}","tags_url":"https://api.github.com/repos/sempliva/Emotly/tags","blobs_url":"https://api.github.com/repos/sempliva/Emotly/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sempliva/Emotly/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sempliva/Emotly/git/refs{/sha}","trees_url":"https://api.github.com/repos/sempliva/Emotly/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sempliva/Emotly/statuses/{sha}","languages_url":"https://api.github.com/repos/sempliva/Emotly/languages","stargazers_url":"https://api.github.com/repos/sempliva/Emotly/stargazers","contributors_url":"https://api.github.com/repos/sempliva/Emotly/contributors","subscribers_url":"https://api.github.com/repos/sempliva/Emotly/subscribers","subscription_url":"https://api.github.com/repos/sempliva/Emotly/subscription","commits_url":"https://api.github.com/repos/sempliva/Emotly/commits{/sha}","git_commits_url":"https://api.github.com/repos/sempliva/Emotly/git/commits{/sha}","comments_url":"https://api.github.com/repos/sempliva/Emotly/comments{/number}","issue_comment_url":"https://api.github.com/repos/sempliva/Emotly/issues/comments{/number}","contents_url":"https://api.github.com/repos/sempliva/Emotly/contents/{+path}","compare_url":"https://api.github.com/repos/sempliva/Emotly/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sempliva/Emotly/merges","archive_url":"https://api.github.com/repos/sempliva/Emotly/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sempliva/Emotly/downloads","issues_url":"https://api.github.com/repos/sempliva/Emotly/issues{/number}","pulls_url":"https://api.github.com/repos/sempliva/Emotly/pulls{/number}","milestones_url":"https://api.github.com/repos/sempliva/Emotly/milestones{/number}","notifications_url":"https://api.github.com/repos/sempliva/Emotly/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sempliva/Emotly/labels{/name}","releases_url":"https://api.github.com/repos/sempliva/Emotly/releases{/id}","deployments_url":"https://api.github.com/repos/sempliva/Emotly/deployments","created_at":"2016-03-28T16:18:08Z","updated_at":"2016-04-03T18:43:59Z","pushed_at":"2016-04-12T04:07:18Z","git_url":"git://github.com/sempliva/Emotly.git","ssh_url":"git@github.com:sempliva/Emotly.git","clone_url":"https://github.com/sempliva/Emotly.git","svn_url":"https://github.com/sempliva/Emotly","homepage":"","size":1674,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":3,"forks":0,"open_issues":3,"watchers":0,"default_branch":"master"}},"base":{"label":"sempliva:master","ref":"master","sha":"97582312ca84f06dce0bcd475d05f543b2f88386","user":{"login":"sempliva","id":18060320,"avatar_url":"https://avatars.githubusercontent.com/u/18060320?v=3","gravatar_id":"","url":"https://api.github.com/users/sempliva","html_url":"https://github.com/sempliva","followers_url":"https://api.github.com/users/sempliva/followers","following_url":"https://api.github.com/users/sempliva/following{/other_user}","gists_url":"https://api.github.com/users/sempliva/gists{/gist_id}","starred_url":"https://api.github.com/users/sempliva/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sempliva/subscriptions","organizations_url":"https://api.github.com/users/sempliva/orgs","repos_url":"https://api.github.com/users/sempliva/repos","events_url":"https://api.github.com/users/sempliva/events{/privacy}","received_events_url":"https://api.github.com/users/sempliva/received_events","type":"Organization","site_admin":false},"repo":{"id":54905411,"name":"Emotly","full_name":"sempliva/Emotly","owner":{"login":"sempliva","id":18060320,"avatar_url":"https://avatars.githubusercontent.com/u/18060320?v=3","gravatar_id":"","url":"https://api.github.com/users/sempliva","html_url":"https://github.com/sempliva","followers_url":"https://api.github.com/users/sempliva/followers","following_url":"https://api.github.com/users/sempliva/following{/other_user}","gists_url":"https://api.github.com/users/sempliva/gists{/gist_id}","starred_url":"https://api.github.com/users/sempliva/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sempliva/subscriptions","organizations_url":"https://api.github.com/users/sempliva/orgs","repos_url":"https://api.github.com/users/sempliva/repos","events_url":"https://api.github.com/users/sempliva/events{/privacy}","received_events_url":"https://api.github.com/users/sempliva/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/sempliva/Emotly","description":"Public instance of the Emotly service","fork":false,"url":"https://api.github.com/repos/sempliva/Emotly","forks_url":"https://api.github.com/repos/sempliva/Emotly/forks","keys_url":"https://api.github.com/repos/sempliva/Emotly/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sempliva/Emotly/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sempliva/Emotly/teams","hooks_url":"https://api.github.com/repos/sempliva/Emotly/hooks","issue_events_url":"https://api.github.com/repos/sempliva/Emotly/issues/events{/number}","events_url":"https://api.github.com/repos/sempliva/Emotly/events","assignees_url":"https://api.github.com/repos/sempliva/Emotly/assignees{/user}","branches_url":"https://api.github.com/repos/sempliva/Emotly/branches{/branch}","tags_url":"https://api.github.com/repos/sempliva/Emotly/tags","blobs_url":"https://api.github.com/repos/sempliva/Emotly/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sempliva/Emotly/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sempliva/Emotly/git/refs{/sha}","trees_url":"https://api.github.com/repos/sempliva/Emotly/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sempliva/Emotly/statuses/{sha}","languages_url":"https://api.github.com/repos/sempliva/Emotly/languages","stargazers_url":"https://api.github.com/repos/sempliva/Emotly/stargazers","contributors_url":"https://api.github.com/repos/sempliva/Emotly/contributors","subscribers_url":"https://api.github.com/repos/sempliva/Emotly/subscribers","subscription_url":"https://api.github.com/repos/sempliva/Emotly/subscription","commits_url":"https://api.github.com/repos/sempliva/Emotly/commits{/sha}","git_commits_url":"https://api.github.com/repos/sempliva/Emotly/git/commits{/sha}","comments_url":"https://api.github.com/repos/sempliva/Emotly/comments{/number}","issue_comment_url":"https://api.github.com/repos/sempliva/Emotly/issues/comments{/number}","contents_url":"https://api.github.com/repos/sempliva/Emotly/contents/{+path}","compare_url":"https://api.github.com/repos/sempliva/Emotly/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sempliva/Emotly/merges","archive_url":"https://api.github.com/repos/sempliva/Emotly/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sempliva/Emotly/downloads","issues_url":"https://api.github.com/repos/sempliva/Emotly/issues{/number}","pulls_url":"https://api.github.com/repos/sempliva/Emotly/pulls{/number}","milestones_url":"https://api.github.com/repos/sempliva/Emotly/milestones{/number}","notifications_url":"https://api.github.com/repos/sempliva/Emotly/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sempliva/Emotly/labels{/name}","releases_url":"https://api.github.com/repos/sempliva/Emotly/releases{/id}","deployments_url":"https://api.github.com/repos/sempliva/Emotly/deployments","created_at":"2016-03-28T16:18:08Z","updated_at":"2016-04-03T18:43:59Z","pushed_at":"2016-04-12T04:07:18Z","git_url":"git://github.com/sempliva/Emotly.git","ssh_url":"git@github.com:sempliva/Emotly.git","clone_url":"https://github.com/sempliva/Emotly.git","svn_url":"https://github.com/sempliva/Emotly","homepage":"","size":1674,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":3,"forks":0,"open_issues":3,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/sempliva/Emotly/pulls/20"},"html":{"href":"https://github.com/sempliva/Emotly/pull/20"},"issue":{"href":"https://api.github.com/repos/sempliva/Emotly/issues/20"},"comments":{"href":"https://api.github.com/repos/sempliva/Emotly/issues/20/comments"},"review_comments":{"href":"https://api.github.com/repos/sempliva/Emotly/pulls/20/comments"},"review_comment":{"href":"https://api.github.com/repos/sempliva/Emotly/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/sempliva/Emotly/pulls/20/commits"},"statuses":{"href":"https://api.github.com/repos/sempliva/Emotly/statuses/be33bb683ef6d9def96ceaf87137bcad39efd05b"}}}}