{"action":"created","comment":{"url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/comments/61769966","id":61769966,"diff_hunk":"@@ -251,6 +279,88 @@ def confirm_email_get(token, auth=None, **kwargs):\n     ))\n \n \n+@collect_auth\n+def verified_email_get(auth=None, **kwargs):\n+    \"\"\"Called at login to see if there are emails to add or users to merge.\n+    methods: GET\n+    \"\"\"\n+    # user = User.load(kwargs['uid'])\n+    user = auth.user\n+    verified_emails = []\n+    for token in user.email_verifications:\n+        if user.verify_token(token):\n+            if user.email_verifications[token]['confirmed']:\n+                try:\n+                    user_merge = User.find_one(Q('emails', 'eq', user.email_verifications[token]['email'].lower()))\n+                except NoResultsFound:\n+                    user_merge = False\n+\n+                verified_emails.append({'address': user.email_verifications[token]['email'],\n+                                        'token': token,\n+                                        'confirmed': user.email_verifications[token]['confirmed'],\n+                                        'user_merge': user_merge.email if user_merge else False})\n+    return verified_emails\n+\n+\n+@collect_auth\n+def verified_email_remove(auth=None, **kwargs):\n+    \"\"\"Called at login if user cancels their merge or email add.\n+    methods: PUT\n+    \"\"\"\n+    user = auth.user\n+    confirmed_email = request.json.get('address')\n+    email_verifications = deepcopy(user.email_verifications)\n+    for token in user.email_verifications:\n+        if user.email_verifications[token]['email'] == confirmed_email:\n+            if user.verify_token(token):\n+                email_verifications.pop(token)\n+    user.email_verifications = email_verifications\n+    user.save()\n+    return {\n+        'status': 'success',\n+        'removed_email': confirmed_email\n+    }, 200\n+\n+\n+@collect_auth\n+def verified_email_add(auth=None, **kwargs):\n+    \"\"\"Called at login if user confirms their merge or email add.\n+    methods: PUT\n+    \"\"\"\n+    user = auth.user\n+    confirmed_email = request.json.get('address')","path":"framework/auth/views.py","position":147,"original_position":147,"commit_id":"2cb0c6854f964a4381be36744e6744300b5ea7d6","original_commit_id":"2cb0c6854f964a4381be36744e6744300b5ea7d6","user":{"login":"sloria","id":2379650,"avatar_url":"https://avatars.githubusercontent.com/u/2379650?v=3","gravatar_id":"","url":"https://api.github.com/users/sloria","html_url":"https://github.com/sloria","followers_url":"https://api.github.com/users/sloria/followers","following_url":"https://api.github.com/users/sloria/following{/other_user}","gists_url":"https://api.github.com/users/sloria/gists{/gist_id}","starred_url":"https://api.github.com/users/sloria/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sloria/subscriptions","organizations_url":"https://api.github.com/users/sloria/orgs","repos_url":"https://api.github.com/users/sloria/repos","events_url":"https://api.github.com/users/sloria/events{/privacy}","received_events_url":"https://api.github.com/users/sloria/received_events","type":"User","site_admin":false},"body":"Why is it necessary for the client to pass the email address? It doesn't appear to be used except for a check on ~L345. It looks like the `token` will suffice to confirm the email.","created_at":"2016-05-02T17:22:24Z","updated_at":"2016-05-02T17:22:24Z","html_url":"https://github.com/CenterForOpenScience/osf.io/pull/5528#discussion_r61769966","pull_request_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/5528","_links":{"self":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/comments/61769966"},"html":{"href":"https://github.com/CenterForOpenScience/osf.io/pull/5528#discussion_r61769966"},"pull_request":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/5528"}}},"pull_request":{"url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/5528","id":67739252,"html_url":"https://github.com/CenterForOpenScience/osf.io/pull/5528","diff_url":"https://github.com/CenterForOpenScience/osf.io/pull/5528.diff","patch_url":"https://github.com/CenterForOpenScience/osf.io/pull/5528.patch","issue_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/5528","number":5528,"state":"open","locked":false,"title":"[rfr][feature] Log out users merging or adding email","user":{"login":"billyhunt","id":6232068,"avatar_url":"https://avatars.githubusercontent.com/u/6232068?v=3","gravatar_id":"","url":"https://api.github.com/users/billyhunt","html_url":"https://github.com/billyhunt","followers_url":"https://api.github.com/users/billyhunt/followers","following_url":"https://api.github.com/users/billyhunt/following{/other_user}","gists_url":"https://api.github.com/users/billyhunt/gists{/gist_id}","starred_url":"https://api.github.com/users/billyhunt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/billyhunt/subscriptions","organizations_url":"https://api.github.com/users/billyhunt/orgs","repos_url":"https://api.github.com/users/billyhunt/repos","events_url":"https://api.github.com/users/billyhunt/events{/privacy}","received_events_url":"https://api.github.com/users/billyhunt/received_events","type":"User","site_admin":false},"body":"Associated with \r\n\r\nhttps://openscience.atlassian.net/browse/OSF-5536\r\n\r\nAnd a based on https://github.com/CenterForOpenScience/osf.io/pull/5000\r\n\r\n### Purpose\r\n\r\nExisting users who add an email or merge an account have unexpected behaviors, depending on whom is logged in.  \r\n\r\nFor example, when adding an email, whomever clicks the link sent when adding an email is automatically logged in which is a security risk.  \r\n\r\nMerging is also less then optimal, depending on whom is logged in.  If UserA is merged into UserB.\r\n\r\nWhen UserA is logged in, the merge will succeed.\r\nWhen UserB is logged in, the merge will fail with no error message.  \r\n\r\n\r\n### Changes:\r\n\r\n* Whomever is logged in will be logged out whenever an email is added or a user is merged.  The user will be directed to a login screen and told which username they should log in as.\r\n* After they log in, they will be given the choice to add the email or merge, with the text of the choice changing depending on whether they are merging or adding an email.\r\n*  If they choose Yes, then the merge or email add occurs.\r\n*  If they choose no, they are removed from the user profile as a user to add.\r\n","created_at":"2016-04-25T15:27:45Z","updated_at":"2016-05-02T17:22:24Z","closed_at":null,"merged_at":null,"merge_commit_sha":"cd7f03ccd2235cf1e88c5ee7c4efaccb8b6882d7","assignee":null,"milestone":{"url":"https://api.github.com/repos/CenterForOpenScience/osf.io/milestones/68","html_url":"https://github.com/CenterForOpenScience/osf.io/milestones/improvements%20release","labels_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/milestones/68/labels","id":1704484,"number":68,"title":"improvements release","description":"","creator":{"login":"sloria","id":2379650,"avatar_url":"https://avatars.githubusercontent.com/u/2379650?v=3","gravatar_id":"","url":"https://api.github.com/users/sloria","html_url":"https://github.com/sloria","followers_url":"https://api.github.com/users/sloria/followers","following_url":"https://api.github.com/users/sloria/following{/other_user}","gists_url":"https://api.github.com/users/sloria/gists{/gist_id}","starred_url":"https://api.github.com/users/sloria/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sloria/subscriptions","organizations_url":"https://api.github.com/users/sloria/orgs","repos_url":"https://api.github.com/users/sloria/repos","events_url":"https://api.github.com/users/sloria/events{/privacy}","received_events_url":"https://api.github.com/users/sloria/received_events","type":"User","site_admin":false},"open_issues":17,"closed_issues":16,"state":"open","created_at":"2016-04-13T19:02:06Z","updated_at":"2016-05-02T16:00:16Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/5528/commits","review_comments_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/5528/comments","review_comment_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/comments{/number}","comments_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/5528/comments","statuses_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/statuses/2cb0c6854f964a4381be36744e6744300b5ea7d6","head":{"label":"billyhunt:feature/logout-users-before-merge","ref":"feature/logout-users-before-merge","sha":"2cb0c6854f964a4381be36744e6744300b5ea7d6","user":{"login":"billyhunt","id":6232068,"avatar_url":"https://avatars.githubusercontent.com/u/6232068?v=3","gravatar_id":"","url":"https://api.github.com/users/billyhunt","html_url":"https://github.com/billyhunt","followers_url":"https://api.github.com/users/billyhunt/followers","following_url":"https://api.github.com/users/billyhunt/following{/other_user}","gists_url":"https://api.github.com/users/billyhunt/gists{/gist_id}","starred_url":"https://api.github.com/users/billyhunt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/billyhunt/subscriptions","organizations_url":"https://api.github.com/users/billyhunt/orgs","repos_url":"https://api.github.com/users/billyhunt/repos","events_url":"https://api.github.com/users/billyhunt/events{/privacy}","received_events_url":"https://api.github.com/users/billyhunt/received_events","type":"User","site_admin":false},"repo":{"id":33544748,"name":"osf.io","full_name":"billyhunt/osf.io","owner":{"login":"billyhunt","id":6232068,"avatar_url":"https://avatars.githubusercontent.com/u/6232068?v=3","gravatar_id":"","url":"https://api.github.com/users/billyhunt","html_url":"https://github.com/billyhunt","followers_url":"https://api.github.com/users/billyhunt/followers","following_url":"https://api.github.com/users/billyhunt/following{/other_user}","gists_url":"https://api.github.com/users/billyhunt/gists{/gist_id}","starred_url":"https://api.github.com/users/billyhunt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/billyhunt/subscriptions","organizations_url":"https://api.github.com/users/billyhunt/orgs","repos_url":"https://api.github.com/users/billyhunt/repos","events_url":"https://api.github.com/users/billyhunt/events{/privacy}","received_events_url":"https://api.github.com/users/billyhunt/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/billyhunt/osf.io","description":"Facilitating Open Science","fork":true,"url":"https://api.github.com/repos/billyhunt/osf.io","forks_url":"https://api.github.com/repos/billyhunt/osf.io/forks","keys_url":"https://api.github.com/repos/billyhunt/osf.io/keys{/key_id}","collaborators_url":"https://api.github.com/repos/billyhunt/osf.io/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/billyhunt/osf.io/teams","hooks_url":"https://api.github.com/repos/billyhunt/osf.io/hooks","issue_events_url":"https://api.github.com/repos/billyhunt/osf.io/issues/events{/number}","events_url":"https://api.github.com/repos/billyhunt/osf.io/events","assignees_url":"https://api.github.com/repos/billyhunt/osf.io/assignees{/user}","branches_url":"https://api.github.com/repos/billyhunt/osf.io/branches{/branch}","tags_url":"https://api.github.com/repos/billyhunt/osf.io/tags","blobs_url":"https://api.github.com/repos/billyhunt/osf.io/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/billyhunt/osf.io/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/billyhunt/osf.io/git/refs{/sha}","trees_url":"https://api.github.com/repos/billyhunt/osf.io/git/trees{/sha}","statuses_url":"https://api.github.com/repos/billyhunt/osf.io/statuses/{sha}","languages_url":"https://api.github.com/repos/billyhunt/osf.io/languages","stargazers_url":"https://api.github.com/repos/billyhunt/osf.io/stargazers","contributors_url":"https://api.github.com/repos/billyhunt/osf.io/contributors","subscribers_url":"https://api.github.com/repos/billyhunt/osf.io/subscribers","subscription_url":"https://api.github.com/repos/billyhunt/osf.io/subscription","commits_url":"https://api.github.com/repos/billyhunt/osf.io/commits{/sha}","git_commits_url":"https://api.github.com/repos/billyhunt/osf.io/git/commits{/sha}","comments_url":"https://api.github.com/repos/billyhunt/osf.io/comments{/number}","issue_comment_url":"https://api.github.com/repos/billyhunt/osf.io/issues/comments{/number}","contents_url":"https://api.github.com/repos/billyhunt/osf.io/contents/{+path}","compare_url":"https://api.github.com/repos/billyhunt/osf.io/compare/{base}...{head}","merges_url":"https://api.github.com/repos/billyhunt/osf.io/merges","archive_url":"https://api.github.com/repos/billyhunt/osf.io/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/billyhunt/osf.io/downloads","issues_url":"https://api.github.com/repos/billyhunt/osf.io/issues{/number}","pulls_url":"https://api.github.com/repos/billyhunt/osf.io/pulls{/number}","milestones_url":"https://api.github.com/repos/billyhunt/osf.io/milestones{/number}","notifications_url":"https://api.github.com/repos/billyhunt/osf.io/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/billyhunt/osf.io/labels{/name}","releases_url":"https://api.github.com/repos/billyhunt/osf.io/releases{/id}","deployments_url":"https://api.github.com/repos/billyhunt/osf.io/deployments","created_at":"2015-04-07T13:28:52Z","updated_at":"2016-01-27T14:23:25Z","pushed_at":"2016-05-02T16:13:24Z","git_url":"git://github.com/billyhunt/osf.io.git","ssh_url":"git@github.com:billyhunt/osf.io.git","clone_url":"https://github.com/billyhunt/osf.io.git","svn_url":"https://github.com/billyhunt/osf.io","homepage":"http://osf.io","size":129250,"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":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"develop"}},"base":{"label":"CenterForOpenScience:release/0.68.0","ref":"release/0.68.0","sha":"80bdf67f469496a08025c18617ee33067d5acd8a","user":{"login":"CenterForOpenScience","id":3344584,"avatar_url":"https://avatars.githubusercontent.com/u/3344584?v=3","gravatar_id":"","url":"https://api.github.com/users/CenterForOpenScience","html_url":"https://github.com/CenterForOpenScience","followers_url":"https://api.github.com/users/CenterForOpenScience/followers","following_url":"https://api.github.com/users/CenterForOpenScience/following{/other_user}","gists_url":"https://api.github.com/users/CenterForOpenScience/gists{/gist_id}","starred_url":"https://api.github.com/users/CenterForOpenScience/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CenterForOpenScience/subscriptions","organizations_url":"https://api.github.com/users/CenterForOpenScience/orgs","repos_url":"https://api.github.com/users/CenterForOpenScience/repos","events_url":"https://api.github.com/users/CenterForOpenScience/events{/privacy}","received_events_url":"https://api.github.com/users/CenterForOpenScience/received_events","type":"Organization","site_admin":false},"repo":{"id":10199599,"name":"osf.io","full_name":"CenterForOpenScience/osf.io","owner":{"login":"CenterForOpenScience","id":3344584,"avatar_url":"https://avatars.githubusercontent.com/u/3344584?v=3","gravatar_id":"","url":"https://api.github.com/users/CenterForOpenScience","html_url":"https://github.com/CenterForOpenScience","followers_url":"https://api.github.com/users/CenterForOpenScience/followers","following_url":"https://api.github.com/users/CenterForOpenScience/following{/other_user}","gists_url":"https://api.github.com/users/CenterForOpenScience/gists{/gist_id}","starred_url":"https://api.github.com/users/CenterForOpenScience/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CenterForOpenScience/subscriptions","organizations_url":"https://api.github.com/users/CenterForOpenScience/orgs","repos_url":"https://api.github.com/users/CenterForOpenScience/repos","events_url":"https://api.github.com/users/CenterForOpenScience/events{/privacy}","received_events_url":"https://api.github.com/users/CenterForOpenScience/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/CenterForOpenScience/osf.io","description":"Facilitating Open Science","fork":false,"url":"https://api.github.com/repos/CenterForOpenScience/osf.io","forks_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/forks","keys_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/keys{/key_id}","collaborators_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/teams","hooks_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/hooks","issue_events_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/events{/number}","events_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/events","assignees_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/assignees{/user}","branches_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/branches{/branch}","tags_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/tags","blobs_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/git/refs{/sha}","trees_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/git/trees{/sha}","statuses_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/statuses/{sha}","languages_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/languages","stargazers_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/stargazers","contributors_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/contributors","subscribers_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/subscribers","subscription_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/subscription","commits_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/commits{/sha}","git_commits_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/git/commits{/sha}","comments_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/comments{/number}","issue_comment_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/comments{/number}","contents_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/contents/{+path}","compare_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/compare/{base}...{head}","merges_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/merges","archive_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/downloads","issues_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues{/number}","pulls_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls{/number}","milestones_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/milestones{/number}","notifications_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/labels{/name}","releases_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/releases{/id}","deployments_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/deployments","created_at":"2013-05-21T15:53:37Z","updated_at":"2016-05-02T03:08:48Z","pushed_at":"2016-05-02T16:50:53Z","git_url":"git://github.com/CenterForOpenScience/osf.io.git","ssh_url":"git@github.com:CenterForOpenScience/osf.io.git","clone_url":"https://github.com/CenterForOpenScience/osf.io.git","svn_url":"https://github.com/CenterForOpenScience/osf.io","homepage":"http://osf.io","size":274605,"stargazers_count":215,"watchers_count":215,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":166,"mirror_url":null,"open_issues_count":236,"forks":166,"open_issues":236,"watchers":215,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/5528"},"html":{"href":"https://github.com/CenterForOpenScience/osf.io/pull/5528"},"issue":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/5528"},"comments":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/5528/comments"},"review_comments":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/5528/comments"},"review_comment":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/5528/commits"},"statuses":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/statuses/2cb0c6854f964a4381be36744e6744300b5ea7d6"}}}}