{"action":"created","comment":{"url":"https://api.github.com/repos/e-mission/e-mission-server/pulls/comments/71587601","id":71587601,"diff_hunk":"@@ -14,29 +16,47 @@\n \n \n def habiticaRegister(username, email, password, our_uuid):\n-  register_url = url + '/api/v3/user/auth/local/register'\n-  user_request = {'username': username,'email': email,'password': password,'confirmPassword': password}\n-  logging.debug(\"About to register %s\"% user_request)\n-  u = requests.post(register_url, json=user_request)\n-  # Bail out if we get an error\n-  u.raise_for_status()\n-  user_dict = json.loads(u.text)\n-  logging.debug(\"parsed json from habitica has keys = %s\" % user_dict.keys())\n-\n-  #Since we are randomly generating the password, we store it in case users \n-  #want to access their Habitica account from the browser\n-  #Need to create a way from them to retrieve username/password\n-  #metrics_data is used to calculate points based on km biked/walked\n-  #last_timestamp is the last time the user got points, and bike/walk_count are the leftover km\n-  habitica_user_table = edb.get_habitica_db()\n-  habitica_user_table.insert({'user_id': our_uuid, \n-    'metrics_data': {'last_timestamp': arrow.utcnow().timestamp, 'bike_count': 0, 'walk_count': 0},\n-    'habitica_username': username, \n-    'habitica_password': password, \n-    'habitica_id': user_dict['data']['_id'], \n-    'habitica_token': user_dict['data']['apiToken']})\n+  user_dict = {}\n+  #try to login and see if user is already in Habitica\n+  try:\n+    login_url = url + '/api/v3/user/auth/local/login'\n+    user_request = {'username': username,'email': email,'password': password}\n+    logging.debug(\"About to login %s\"% user_request)\n+    u = requests.post(login_url, json=user_request)\n+    user_dict = json.loads(u.text)\n+    logging.debug(\"parsed json from habitica has keys = %s\" % user_dict.keys())\n+\n+  #if u fails, then user is not in Habitica, so needs to create an account\n+  except urllib2.HTTPError:\n+    register_url = url + '/api/v3/user/auth/local/register'\n+    user_request = {'username': username,'email': email,'password': password,'confirmPassword': password}\n+    logging.debug(\"About to register %s\"% user_request)\n+    u = requests.post(register_url, json=user_request)\n+    # Bail out if we get an error\n+    u.raise_for_status()\n+    user_dict = json.loads(u.text)\n+    logging.debug(\"parsed json from habitica has keys = %s\" % user_dict.keys())\n+\n+  #if user is not in e-mission db, create it\n+  if edb.get_habitica_db().find({'user_id': our_uuid}).count() == 0:\n+    #Since we are randomly generating the password, we store it in case users \n+    #want to access their Habitica account from the browser\n+    #Need to create a way from them to retrieve username/password\n+    #metrics_data is used to calculate points based on km biked/walked\n+    #last_timestamp is the last time the user got points, and bike/walk_count are the leftover km\n+    habitica_user_table = edb.get_habitica_db()\n+    habitica_user_table.insert({'user_id': our_uuid, \n+      'metrics_data': {'last_timestamp': arrow.utcnow().timestamp, 'bike_count': 0, 'walk_count': 0},\n+      'habitica_username': username, \n+      'habitica_password': password, \n+      'habitica_id': user_dict['data']['_id'], \n+      'habitica_token': user_dict['data']['apiToken'],\n+      'habitica_group_id': \"\"})\n+  \n+  #Do initial setup and append GroupId to the user\n+  group_id = assist.user_setup(our_uuid)","path":"emission/net/ext_service/habitica/proxy.py","position":75,"original_position":75,"commit_id":"adf060b03af6630462163f664df3ebce6ea176b5","original_commit_id":"adf060b03af6630462163f664df3ebce6ea176b5","user":{"login":"shankari","id":2423263,"avatar_url":"https://avatars.githubusercontent.com/u/2423263?v=3","gravatar_id":"","url":"https://api.github.com/users/shankari","html_url":"https://github.com/shankari","followers_url":"https://api.github.com/users/shankari/followers","following_url":"https://api.github.com/users/shankari/following{/other_user}","gists_url":"https://api.github.com/users/shankari/gists{/gist_id}","starred_url":"https://api.github.com/users/shankari/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shankari/subscriptions","organizations_url":"https://api.github.com/users/shankari/orgs","repos_url":"https://api.github.com/users/shankari/repos","events_url":"https://api.github.com/users/shankari/events{/privacy}","received_events_url":"https://api.github.com/users/shankari/received_events","type":"User","site_admin":false},"body":"this is outside the emission db check, right? Is it idempotent? \r\nRecall that the user may call `habiticaRegister` multiple times and our goal is to support that.\r\n\r\nRight now, I think that if the user calls `habiticaRegister` a second time, she will be randomly re-assigned to a different group.","created_at":"2016-07-20T19:08:52Z","updated_at":"2016-07-20T19:08:52Z","html_url":"https://github.com/e-mission/e-mission-server/pull/325#discussion_r71587601","pull_request_url":"https://api.github.com/repos/e-mission/e-mission-server/pulls/325","_links":{"self":{"href":"https://api.github.com/repos/e-mission/e-mission-server/pulls/comments/71587601"},"html":{"href":"https://github.com/e-mission/e-mission-server/pull/325#discussion_r71587601"},"pull_request":{"href":"https://api.github.com/repos/e-mission/e-mission-server/pulls/325"}}},"pull_request":{"url":"https://api.github.com/repos/e-mission/e-mission-server/pulls/325","id":78197029,"html_url":"https://github.com/e-mission/e-mission-server/pull/325","diff_url":"https://github.com/e-mission/e-mission-server/pull/325.diff","patch_url":"https://github.com/e-mission/e-mission-server/pull/325.patch","issue_url":"https://api.github.com/repos/e-mission/e-mission-server/issues/325","number":325,"state":"open","locked":false,"title":"different vs of habitica setup","user":{"login":"juemura","id":1196510,"avatar_url":"https://avatars.githubusercontent.com/u/1196510?v=3","gravatar_id":"","url":"https://api.github.com/users/juemura","html_url":"https://github.com/juemura","followers_url":"https://api.github.com/users/juemura/followers","following_url":"https://api.github.com/users/juemura/following{/other_user}","gists_url":"https://api.github.com/users/juemura/gists{/gist_id}","starred_url":"https://api.github.com/users/juemura/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/juemura/subscriptions","organizations_url":"https://api.github.com/users/juemura/orgs","repos_url":"https://api.github.com/users/juemura/repos","events_url":"https://api.github.com/users/juemura/events{/privacy}","received_events_url":"https://api.github.com/users/juemura/received_events","type":"User","site_admin":false},"body":"I guess with this we won't need to script to create the 3 party leaders, it'll just find you in habitica and return that. I need to do a check in setup_party to catch errors, but other than that this should be ok.\r\nlmk what you think.","created_at":"2016-07-20T18:35:59Z","updated_at":"2016-07-20T19:08:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6d6c0468dde896ea115c7e82f09fdfaf42e196ad","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/e-mission/e-mission-server/pulls/325/commits","review_comments_url":"https://api.github.com/repos/e-mission/e-mission-server/pulls/325/comments","review_comment_url":"https://api.github.com/repos/e-mission/e-mission-server/pulls/comments{/number}","comments_url":"https://api.github.com/repos/e-mission/e-mission-server/issues/325/comments","statuses_url":"https://api.github.com/repos/e-mission/e-mission-server/statuses/adf060b03af6630462163f664df3ebce6ea176b5","head":{"label":"juemura:habitica_setup_v3","ref":"habitica_setup_v3","sha":"adf060b03af6630462163f664df3ebce6ea176b5","user":{"login":"juemura","id":1196510,"avatar_url":"https://avatars.githubusercontent.com/u/1196510?v=3","gravatar_id":"","url":"https://api.github.com/users/juemura","html_url":"https://github.com/juemura","followers_url":"https://api.github.com/users/juemura/followers","following_url":"https://api.github.com/users/juemura/following{/other_user}","gists_url":"https://api.github.com/users/juemura/gists{/gist_id}","starred_url":"https://api.github.com/users/juemura/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/juemura/subscriptions","organizations_url":"https://api.github.com/users/juemura/orgs","repos_url":"https://api.github.com/users/juemura/repos","events_url":"https://api.github.com/users/juemura/events{/privacy}","received_events_url":"https://api.github.com/users/juemura/received_events","type":"User","site_admin":false},"repo":{"id":62175853,"name":"e-mission-server","full_name":"juemura/e-mission-server","owner":{"login":"juemura","id":1196510,"avatar_url":"https://avatars.githubusercontent.com/u/1196510?v=3","gravatar_id":"","url":"https://api.github.com/users/juemura","html_url":"https://github.com/juemura","followers_url":"https://api.github.com/users/juemura/followers","following_url":"https://api.github.com/users/juemura/following{/other_user}","gists_url":"https://api.github.com/users/juemura/gists{/gist_id}","starred_url":"https://api.github.com/users/juemura/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/juemura/subscriptions","organizations_url":"https://api.github.com/users/juemura/orgs","repos_url":"https://api.github.com/users/juemura/repos","events_url":"https://api.github.com/users/juemura/events{/privacy}","received_events_url":"https://api.github.com/users/juemura/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/juemura/e-mission-server","description":"The backend (server) code for the e-mission server","fork":true,"url":"https://api.github.com/repos/juemura/e-mission-server","forks_url":"https://api.github.com/repos/juemura/e-mission-server/forks","keys_url":"https://api.github.com/repos/juemura/e-mission-server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/juemura/e-mission-server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/juemura/e-mission-server/teams","hooks_url":"https://api.github.com/repos/juemura/e-mission-server/hooks","issue_events_url":"https://api.github.com/repos/juemura/e-mission-server/issues/events{/number}","events_url":"https://api.github.com/repos/juemura/e-mission-server/events","assignees_url":"https://api.github.com/repos/juemura/e-mission-server/assignees{/user}","branches_url":"https://api.github.com/repos/juemura/e-mission-server/branches{/branch}","tags_url":"https://api.github.com/repos/juemura/e-mission-server/tags","blobs_url":"https://api.github.com/repos/juemura/e-mission-server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/juemura/e-mission-server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/juemura/e-mission-server/git/refs{/sha}","trees_url":"https://api.github.com/repos/juemura/e-mission-server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/juemura/e-mission-server/statuses/{sha}","languages_url":"https://api.github.com/repos/juemura/e-mission-server/languages","stargazers_url":"https://api.github.com/repos/juemura/e-mission-server/stargazers","contributors_url":"https://api.github.com/repos/juemura/e-mission-server/contributors","subscribers_url":"https://api.github.com/repos/juemura/e-mission-server/subscribers","subscription_url":"https://api.github.com/repos/juemura/e-mission-server/subscription","commits_url":"https://api.github.com/repos/juemura/e-mission-server/commits{/sha}","git_commits_url":"https://api.github.com/repos/juemura/e-mission-server/git/commits{/sha}","comments_url":"https://api.github.com/repos/juemura/e-mission-server/comments{/number}","issue_comment_url":"https://api.github.com/repos/juemura/e-mission-server/issues/comments{/number}","contents_url":"https://api.github.com/repos/juemura/e-mission-server/contents/{+path}","compare_url":"https://api.github.com/repos/juemura/e-mission-server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/juemura/e-mission-server/merges","archive_url":"https://api.github.com/repos/juemura/e-mission-server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/juemura/e-mission-server/downloads","issues_url":"https://api.github.com/repos/juemura/e-mission-server/issues{/number}","pulls_url":"https://api.github.com/repos/juemura/e-mission-server/pulls{/number}","milestones_url":"https://api.github.com/repos/juemura/e-mission-server/milestones{/number}","notifications_url":"https://api.github.com/repos/juemura/e-mission-server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/juemura/e-mission-server/labels{/name}","releases_url":"https://api.github.com/repos/juemura/e-mission-server/releases{/id}","deployments_url":"https://api.github.com/repos/juemura/e-mission-server/deployments","created_at":"2016-06-28T21:35:53Z","updated_at":"2016-06-28T21:36:01Z","pushed_at":"2016-07-20T18:33:35Z","git_url":"git://github.com/juemura/e-mission-server.git","ssh_url":"git@github.com:juemura/e-mission-server.git","clone_url":"https://github.com/juemura/e-mission-server.git","svn_url":"https://github.com/juemura/e-mission-server","homepage":"https://e-mission.eecs.berkeley.edu","size":92549,"stargazers_count":0,"watchers_count":0,"language":"Jupyter Notebook","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"e-mission:master","ref":"master","sha":"cb483a896b632d69eccdd35fc205704cea1762f0","user":{"login":"e-mission","id":10713694,"avatar_url":"https://avatars.githubusercontent.com/u/10713694?v=3","gravatar_id":"","url":"https://api.github.com/users/e-mission","html_url":"https://github.com/e-mission","followers_url":"https://api.github.com/users/e-mission/followers","following_url":"https://api.github.com/users/e-mission/following{/other_user}","gists_url":"https://api.github.com/users/e-mission/gists{/gist_id}","starred_url":"https://api.github.com/users/e-mission/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/e-mission/subscriptions","organizations_url":"https://api.github.com/users/e-mission/orgs","repos_url":"https://api.github.com/users/e-mission/repos","events_url":"https://api.github.com/users/e-mission/events{/privacy}","received_events_url":"https://api.github.com/users/e-mission/received_events","type":"Organization","site_admin":false},"repo":{"id":26307245,"name":"e-mission-server","full_name":"e-mission/e-mission-server","owner":{"login":"e-mission","id":10713694,"avatar_url":"https://avatars.githubusercontent.com/u/10713694?v=3","gravatar_id":"","url":"https://api.github.com/users/e-mission","html_url":"https://github.com/e-mission","followers_url":"https://api.github.com/users/e-mission/followers","following_url":"https://api.github.com/users/e-mission/following{/other_user}","gists_url":"https://api.github.com/users/e-mission/gists{/gist_id}","starred_url":"https://api.github.com/users/e-mission/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/e-mission/subscriptions","organizations_url":"https://api.github.com/users/e-mission/orgs","repos_url":"https://api.github.com/users/e-mission/repos","events_url":"https://api.github.com/users/e-mission/events{/privacy}","received_events_url":"https://api.github.com/users/e-mission/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/e-mission/e-mission-server","description":"The backend (server) code for the e-mission server","fork":false,"url":"https://api.github.com/repos/e-mission/e-mission-server","forks_url":"https://api.github.com/repos/e-mission/e-mission-server/forks","keys_url":"https://api.github.com/repos/e-mission/e-mission-server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/e-mission/e-mission-server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/e-mission/e-mission-server/teams","hooks_url":"https://api.github.com/repos/e-mission/e-mission-server/hooks","issue_events_url":"https://api.github.com/repos/e-mission/e-mission-server/issues/events{/number}","events_url":"https://api.github.com/repos/e-mission/e-mission-server/events","assignees_url":"https://api.github.com/repos/e-mission/e-mission-server/assignees{/user}","branches_url":"https://api.github.com/repos/e-mission/e-mission-server/branches{/branch}","tags_url":"https://api.github.com/repos/e-mission/e-mission-server/tags","blobs_url":"https://api.github.com/repos/e-mission/e-mission-server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/e-mission/e-mission-server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/e-mission/e-mission-server/git/refs{/sha}","trees_url":"https://api.github.com/repos/e-mission/e-mission-server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/e-mission/e-mission-server/statuses/{sha}","languages_url":"https://api.github.com/repos/e-mission/e-mission-server/languages","stargazers_url":"https://api.github.com/repos/e-mission/e-mission-server/stargazers","contributors_url":"https://api.github.com/repos/e-mission/e-mission-server/contributors","subscribers_url":"https://api.github.com/repos/e-mission/e-mission-server/subscribers","subscription_url":"https://api.github.com/repos/e-mission/e-mission-server/subscription","commits_url":"https://api.github.com/repos/e-mission/e-mission-server/commits{/sha}","git_commits_url":"https://api.github.com/repos/e-mission/e-mission-server/git/commits{/sha}","comments_url":"https://api.github.com/repos/e-mission/e-mission-server/comments{/number}","issue_comment_url":"https://api.github.com/repos/e-mission/e-mission-server/issues/comments{/number}","contents_url":"https://api.github.com/repos/e-mission/e-mission-server/contents/{+path}","compare_url":"https://api.github.com/repos/e-mission/e-mission-server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/e-mission/e-mission-server/merges","archive_url":"https://api.github.com/repos/e-mission/e-mission-server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/e-mission/e-mission-server/downloads","issues_url":"https://api.github.com/repos/e-mission/e-mission-server/issues{/number}","pulls_url":"https://api.github.com/repos/e-mission/e-mission-server/pulls{/number}","milestones_url":"https://api.github.com/repos/e-mission/e-mission-server/milestones{/number}","notifications_url":"https://api.github.com/repos/e-mission/e-mission-server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/e-mission/e-mission-server/labels{/name}","releases_url":"https://api.github.com/repos/e-mission/e-mission-server/releases{/id}","deployments_url":"https://api.github.com/repos/e-mission/e-mission-server/deployments","created_at":"2014-11-07T06:39:02Z","updated_at":"2016-06-11T09:09:56Z","pushed_at":"2016-07-20T18:36:00Z","git_url":"git://github.com/e-mission/e-mission-server.git","ssh_url":"git@github.com:e-mission/e-mission-server.git","clone_url":"https://github.com/e-mission/e-mission-server.git","svn_url":"https://github.com/e-mission/e-mission-server","homepage":"https://e-mission.eecs.berkeley.edu","size":93035,"stargazers_count":2,"watchers_count":2,"language":"Jupyter Notebook","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":29,"mirror_url":null,"open_issues_count":59,"forks":29,"open_issues":59,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/e-mission/e-mission-server/pulls/325"},"html":{"href":"https://github.com/e-mission/e-mission-server/pull/325"},"issue":{"href":"https://api.github.com/repos/e-mission/e-mission-server/issues/325"},"comments":{"href":"https://api.github.com/repos/e-mission/e-mission-server/issues/325/comments"},"review_comments":{"href":"https://api.github.com/repos/e-mission/e-mission-server/pulls/325/comments"},"review_comment":{"href":"https://api.github.com/repos/e-mission/e-mission-server/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/e-mission/e-mission-server/pulls/325/commits"},"statuses":{"href":"https://api.github.com/repos/e-mission/e-mission-server/statuses/adf060b03af6630462163f664df3ebce6ea176b5"}}}}
{"actor":{"display_login":"shankari"}}