{"action":"created","comment":{"url":"https://api.github.com/repos/elektronaut/sugar/pulls/comments/25137843","id":25137843,"diff_hunk":"@@ -1,109 +1,115 @@\n class FacebookController < ApplicationController\n-\n   requires_user only: [:connect, :disconnect]\n   before_action :detect_admin_signup, only: [:signup]\n \n-  protected\n-\n-    def detect_admin_signup\n-      @admin_signup = true if User.count(:all) == 0\n-    end\n+  def login\n+    if @user_info ||= get_user_info(code: params[:code])\n \n-    def get_access_token(code, options={})\n-      return nil unless code\n+      # User exists\n+      if set_current_user(User.find_by_facebook_uid(@user_info[:id]))\n+        redirect_to discussions_url\n \n-      options[:redirect_uri] ||= login_facebook_url\n-\n-      access_token_url = \"https://graph.facebook.com/oauth/access_token\" +\n-                          \"?client_id=#{Sugar.config.facebook_app_id}\" +\n-                          \"&redirect_uri=#{options[:redirect_uri]}\" +\n-                          \"&client_secret=#{Sugar.config.facebook_api_secret}\" +\n-                          \"&code=#{code}\"\n-      begin\n-        response = open(access_token_url).read\n-        if response =~ /access_token=/\n-          CGI::parse(response)['access_token'].first\n-        else\n-          nil\n-        end\n-      rescue => e\n-        logger.error \"Facebook authentication error: #{e.message}\"\n-        nil\n+      # Go to signup if allowed\n+      elsif Sugar.config.signups_allowed\n+        signup\n+      else\n+        flash[:notice] = \"Could not find your Facebook account\"\n+        redirect_to login_users_url\n       end\n+    else\n+      flash[:error] = \"Failed to verify your Facebook account\"\n+      redirect_to login_users_url\n     end\n+  end\n \n-    def get_user_info(options={})\n-      if options[:code]\n-        options[:access_token] ||= get_access_token(options[:code], options)\n-      end\n-      if options[:access_token]\n-        begin\n-          response = open(\"https://graph.facebook.com/me?access_token=#{options[:access_token]}\").read\n-          JSON.parse(response).symbolize_keys\n-        rescue => e\n-          logger.error \"Facebook API error: #{e.message}\"\n-          nil\n-        end\n-      else\n-        nil\n+  def signup\n+    if @user_info ||= get_user_info(\n+      code: params[:code],\n+      redirect_uri: signup_facebook_url\n+    )\n+      session[:facebook_user_params] = {\n+        facebook_uid: @user_info[:id],\n+        email:        @user_info[:email],\n+        realname:     @user_info[:name],\n+        username:     (@user_info[:username] || @user_info[:name])\n+      }\n+    else\n+      flash[:error] = \"Failed to verify your Facebook account\"\n+    end\n+    redirect_to new_user_url\n+  end\n+\n+  def connect\n+    if @user_info ||= get_user_info(\n+      code: params[:code],\n+      redirect_uri: connect_facebook_url\n+    )\n+      if @user_info[:id]\n+        current_user.update_attribute(:facebook_uid, @user_info[:id])\n       end\n+    else\n+      flash[:error] = \"Failed to verify your Facebook account\"\n     end\n+    redirect_to edit_user_page_url(\n+      id:   current_user.username,\n+      page: \"services\"\n+    )\n+  end\n \n-  public\n+  def disconnect\n+    current_user.update_attribute(:facebook_uid, nil)\n+    flash[:notice] = \"You have disconnected your Facebook account\"\n+    redirect_to edit_user_page_url(\n+      id:   current_user.username,\n+      page: \"services\"\n+    )\n+  end\n \n-    def login\n-      if @user_info ||= get_user_info(code: params[:code])\n+  protected\n \n-        # User exists\n-        if set_current_user(User.find_by_facebook_uid(@user_info[:id]))\n-          redirect_to discussions_url and return\n+  def detect_admin_signup\n+    @admin_signup = true if User.count(:all) == 0\n+  end\n \n-        # Go to signup if allowed\n-        elsif Sugar.config.signups_allowed\n-          signup and return\n+  def get_access_token(code, options = {})","path":"app/controllers/facebook_controller.rb","position":122,"original_position":122,"commit_id":"fc82a056c506aa7ddda36213d8999a98778cdd26","original_commit_id":"fc82a056c506aa7ddda36213d8999a98778cdd26","user":{"login":"houndci","id":6697940,"avatar_url":"https://avatars.githubusercontent.com/u/6697940?v=3","gravatar_id":"","url":"https://api.github.com/users/houndci","html_url":"https://github.com/houndci","followers_url":"https://api.github.com/users/houndci/followers","following_url":"https://api.github.com/users/houndci/following{/other_user}","gists_url":"https://api.github.com/users/houndci/gists{/gist_id}","starred_url":"https://api.github.com/users/houndci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/houndci/subscriptions","organizations_url":"https://api.github.com/users/houndci/orgs","repos_url":"https://api.github.com/users/houndci/repos","events_url":"https://api.github.com/users/houndci/events{/privacy}","received_events_url":"https://api.github.com/users/houndci/received_events","type":"User","site_admin":false},"body":"Assignment Branch Condition size for get_access_token is too high. [20.62/15]","created_at":"2015-02-22T22:49:16Z","updated_at":"2015-02-22T22:49:16Z","html_url":"https://github.com/elektronaut/sugar/pull/75#discussion_r25137843","pull_request_url":"https://api.github.com/repos/elektronaut/sugar/pulls/75","_links":{"self":{"href":"https://api.github.com/repos/elektronaut/sugar/pulls/comments/25137843"},"html":{"href":"https://github.com/elektronaut/sugar/pull/75#discussion_r25137843"},"pull_request":{"href":"https://api.github.com/repos/elektronaut/sugar/pulls/75"}}},"pull_request":{"url":"https://api.github.com/repos/elektronaut/sugar/pulls/75","id":29778462,"html_url":"https://github.com/elektronaut/sugar/pull/75","diff_url":"https://github.com/elektronaut/sugar/pull/75.diff","patch_url":"https://github.com/elektronaut/sugar/pull/75.patch","issue_url":"https://api.github.com/repos/elektronaut/sugar/issues/75","number":75,"state":"open","locked":false,"title":"Style update","user":{"login":"elektronaut","id":5549,"avatar_url":"https://avatars.githubusercontent.com/u/5549?v=3","gravatar_id":"","url":"https://api.github.com/users/elektronaut","html_url":"https://github.com/elektronaut","followers_url":"https://api.github.com/users/elektronaut/followers","following_url":"https://api.github.com/users/elektronaut/following{/other_user}","gists_url":"https://api.github.com/users/elektronaut/gists{/gist_id}","starred_url":"https://api.github.com/users/elektronaut/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elektronaut/subscriptions","organizations_url":"https://api.github.com/users/elektronaut/orgs","repos_url":"https://api.github.com/users/elektronaut/repos","events_url":"https://api.github.com/users/elektronaut/events{/privacy}","received_events_url":"https://api.github.com/users/elektronaut/received_events","type":"User","site_admin":false},"body":"Work in progress","created_at":"2015-02-22T22:37:07Z","updated_at":"2015-02-22T22:49:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"96953cb229917c3c03290077942a814c5a852647","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/elektronaut/sugar/pulls/75/commits","review_comments_url":"https://api.github.com/repos/elektronaut/sugar/pulls/75/comments","review_comment_url":"https://api.github.com/repos/elektronaut/sugar/pulls/comments{/number}","comments_url":"https://api.github.com/repos/elektronaut/sugar/issues/75/comments","statuses_url":"https://api.github.com/repos/elektronaut/sugar/statuses/fc82a056c506aa7ddda36213d8999a98778cdd26","head":{"label":"elektronaut:style-update","ref":"style-update","sha":"fc82a056c506aa7ddda36213d8999a98778cdd26","user":{"login":"elektronaut","id":5549,"avatar_url":"https://avatars.githubusercontent.com/u/5549?v=3","gravatar_id":"","url":"https://api.github.com/users/elektronaut","html_url":"https://github.com/elektronaut","followers_url":"https://api.github.com/users/elektronaut/followers","following_url":"https://api.github.com/users/elektronaut/following{/other_user}","gists_url":"https://api.github.com/users/elektronaut/gists{/gist_id}","starred_url":"https://api.github.com/users/elektronaut/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elektronaut/subscriptions","organizations_url":"https://api.github.com/users/elektronaut/orgs","repos_url":"https://api.github.com/users/elektronaut/repos","events_url":"https://api.github.com/users/elektronaut/events{/privacy}","received_events_url":"https://api.github.com/users/elektronaut/received_events","type":"User","site_admin":false},"repo":{"id":183523,"name":"sugar","full_name":"elektronaut/sugar","owner":{"login":"elektronaut","id":5549,"avatar_url":"https://avatars.githubusercontent.com/u/5549?v=3","gravatar_id":"","url":"https://api.github.com/users/elektronaut","html_url":"https://github.com/elektronaut","followers_url":"https://api.github.com/users/elektronaut/followers","following_url":"https://api.github.com/users/elektronaut/following{/other_user}","gists_url":"https://api.github.com/users/elektronaut/gists{/gist_id}","starred_url":"https://api.github.com/users/elektronaut/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elektronaut/subscriptions","organizations_url":"https://api.github.com/users/elektronaut/orgs","repos_url":"https://api.github.com/users/elektronaut/repos","events_url":"https://api.github.com/users/elektronaut/events{/privacy}","received_events_url":"https://api.github.com/users/elektronaut/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/elektronaut/sugar","description":"Totally sweet Ruby on Rails-based forum software","fork":false,"url":"https://api.github.com/repos/elektronaut/sugar","forks_url":"https://api.github.com/repos/elektronaut/sugar/forks","keys_url":"https://api.github.com/repos/elektronaut/sugar/keys{/key_id}","collaborators_url":"https://api.github.com/repos/elektronaut/sugar/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/elektronaut/sugar/teams","hooks_url":"https://api.github.com/repos/elektronaut/sugar/hooks","issue_events_url":"https://api.github.com/repos/elektronaut/sugar/issues/events{/number}","events_url":"https://api.github.com/repos/elektronaut/sugar/events","assignees_url":"https://api.github.com/repos/elektronaut/sugar/assignees{/user}","branches_url":"https://api.github.com/repos/elektronaut/sugar/branches{/branch}","tags_url":"https://api.github.com/repos/elektronaut/sugar/tags","blobs_url":"https://api.github.com/repos/elektronaut/sugar/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/elektronaut/sugar/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/elektronaut/sugar/git/refs{/sha}","trees_url":"https://api.github.com/repos/elektronaut/sugar/git/trees{/sha}","statuses_url":"https://api.github.com/repos/elektronaut/sugar/statuses/{sha}","languages_url":"https://api.github.com/repos/elektronaut/sugar/languages","stargazers_url":"https://api.github.com/repos/elektronaut/sugar/stargazers","contributors_url":"https://api.github.com/repos/elektronaut/sugar/contributors","subscribers_url":"https://api.github.com/repos/elektronaut/sugar/subscribers","subscription_url":"https://api.github.com/repos/elektronaut/sugar/subscription","commits_url":"https://api.github.com/repos/elektronaut/sugar/commits{/sha}","git_commits_url":"https://api.github.com/repos/elektronaut/sugar/git/commits{/sha}","comments_url":"https://api.github.com/repos/elektronaut/sugar/comments{/number}","issue_comment_url":"https://api.github.com/repos/elektronaut/sugar/issues/comments{/number}","contents_url":"https://api.github.com/repos/elektronaut/sugar/contents/{+path}","compare_url":"https://api.github.com/repos/elektronaut/sugar/compare/{base}...{head}","merges_url":"https://api.github.com/repos/elektronaut/sugar/merges","archive_url":"https://api.github.com/repos/elektronaut/sugar/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/elektronaut/sugar/downloads","issues_url":"https://api.github.com/repos/elektronaut/sugar/issues{/number}","pulls_url":"https://api.github.com/repos/elektronaut/sugar/pulls{/number}","milestones_url":"https://api.github.com/repos/elektronaut/sugar/milestones{/number}","notifications_url":"https://api.github.com/repos/elektronaut/sugar/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/elektronaut/sugar/labels{/name}","releases_url":"https://api.github.com/repos/elektronaut/sugar/releases{/id}","created_at":"2009-04-23T12:44:42Z","updated_at":"2015-02-22T02:08:40Z","pushed_at":"2015-02-22T22:49:06Z","git_url":"git://github.com/elektronaut/sugar.git","ssh_url":"git@github.com:elektronaut/sugar.git","clone_url":"https://github.com/elektronaut/sugar.git","svn_url":"https://github.com/elektronaut/sugar","homepage":"","size":13200,"stargazers_count":92,"watchers_count":92,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":32,"mirror_url":null,"open_issues_count":4,"forks":32,"open_issues":4,"watchers":92,"default_branch":"master"}},"base":{"label":"elektronaut:master","ref":"master","sha":"df29495508849aede14bcc6e8ef4248230dc4497","user":{"login":"elektronaut","id":5549,"avatar_url":"https://avatars.githubusercontent.com/u/5549?v=3","gravatar_id":"","url":"https://api.github.com/users/elektronaut","html_url":"https://github.com/elektronaut","followers_url":"https://api.github.com/users/elektronaut/followers","following_url":"https://api.github.com/users/elektronaut/following{/other_user}","gists_url":"https://api.github.com/users/elektronaut/gists{/gist_id}","starred_url":"https://api.github.com/users/elektronaut/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elektronaut/subscriptions","organizations_url":"https://api.github.com/users/elektronaut/orgs","repos_url":"https://api.github.com/users/elektronaut/repos","events_url":"https://api.github.com/users/elektronaut/events{/privacy}","received_events_url":"https://api.github.com/users/elektronaut/received_events","type":"User","site_admin":false},"repo":{"id":183523,"name":"sugar","full_name":"elektronaut/sugar","owner":{"login":"elektronaut","id":5549,"avatar_url":"https://avatars.githubusercontent.com/u/5549?v=3","gravatar_id":"","url":"https://api.github.com/users/elektronaut","html_url":"https://github.com/elektronaut","followers_url":"https://api.github.com/users/elektronaut/followers","following_url":"https://api.github.com/users/elektronaut/following{/other_user}","gists_url":"https://api.github.com/users/elektronaut/gists{/gist_id}","starred_url":"https://api.github.com/users/elektronaut/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elektronaut/subscriptions","organizations_url":"https://api.github.com/users/elektronaut/orgs","repos_url":"https://api.github.com/users/elektronaut/repos","events_url":"https://api.github.com/users/elektronaut/events{/privacy}","received_events_url":"https://api.github.com/users/elektronaut/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/elektronaut/sugar","description":"Totally sweet Ruby on Rails-based forum software","fork":false,"url":"https://api.github.com/repos/elektronaut/sugar","forks_url":"https://api.github.com/repos/elektronaut/sugar/forks","keys_url":"https://api.github.com/repos/elektronaut/sugar/keys{/key_id}","collaborators_url":"https://api.github.com/repos/elektronaut/sugar/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/elektronaut/sugar/teams","hooks_url":"https://api.github.com/repos/elektronaut/sugar/hooks","issue_events_url":"https://api.github.com/repos/elektronaut/sugar/issues/events{/number}","events_url":"https://api.github.com/repos/elektronaut/sugar/events","assignees_url":"https://api.github.com/repos/elektronaut/sugar/assignees{/user}","branches_url":"https://api.github.com/repos/elektronaut/sugar/branches{/branch}","tags_url":"https://api.github.com/repos/elektronaut/sugar/tags","blobs_url":"https://api.github.com/repos/elektronaut/sugar/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/elektronaut/sugar/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/elektronaut/sugar/git/refs{/sha}","trees_url":"https://api.github.com/repos/elektronaut/sugar/git/trees{/sha}","statuses_url":"https://api.github.com/repos/elektronaut/sugar/statuses/{sha}","languages_url":"https://api.github.com/repos/elektronaut/sugar/languages","stargazers_url":"https://api.github.com/repos/elektronaut/sugar/stargazers","contributors_url":"https://api.github.com/repos/elektronaut/sugar/contributors","subscribers_url":"https://api.github.com/repos/elektronaut/sugar/subscribers","subscription_url":"https://api.github.com/repos/elektronaut/sugar/subscription","commits_url":"https://api.github.com/repos/elektronaut/sugar/commits{/sha}","git_commits_url":"https://api.github.com/repos/elektronaut/sugar/git/commits{/sha}","comments_url":"https://api.github.com/repos/elektronaut/sugar/comments{/number}","issue_comment_url":"https://api.github.com/repos/elektronaut/sugar/issues/comments{/number}","contents_url":"https://api.github.com/repos/elektronaut/sugar/contents/{+path}","compare_url":"https://api.github.com/repos/elektronaut/sugar/compare/{base}...{head}","merges_url":"https://api.github.com/repos/elektronaut/sugar/merges","archive_url":"https://api.github.com/repos/elektronaut/sugar/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/elektronaut/sugar/downloads","issues_url":"https://api.github.com/repos/elektronaut/sugar/issues{/number}","pulls_url":"https://api.github.com/repos/elektronaut/sugar/pulls{/number}","milestones_url":"https://api.github.com/repos/elektronaut/sugar/milestones{/number}","notifications_url":"https://api.github.com/repos/elektronaut/sugar/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/elektronaut/sugar/labels{/name}","releases_url":"https://api.github.com/repos/elektronaut/sugar/releases{/id}","created_at":"2009-04-23T12:44:42Z","updated_at":"2015-02-22T02:08:40Z","pushed_at":"2015-02-22T22:49:06Z","git_url":"git://github.com/elektronaut/sugar.git","ssh_url":"git@github.com:elektronaut/sugar.git","clone_url":"https://github.com/elektronaut/sugar.git","svn_url":"https://github.com/elektronaut/sugar","homepage":"","size":13200,"stargazers_count":92,"watchers_count":92,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":32,"mirror_url":null,"open_issues_count":4,"forks":32,"open_issues":4,"watchers":92,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/elektronaut/sugar/pulls/75"},"html":{"href":"https://github.com/elektronaut/sugar/pull/75"},"issue":{"href":"https://api.github.com/repos/elektronaut/sugar/issues/75"},"comments":{"href":"https://api.github.com/repos/elektronaut/sugar/issues/75/comments"},"review_comments":{"href":"https://api.github.com/repos/elektronaut/sugar/pulls/75/comments"},"review_comment":{"href":"https://api.github.com/repos/elektronaut/sugar/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/elektronaut/sugar/pulls/75/commits"},"statuses":{"href":"https://api.github.com/repos/elektronaut/sugar/statuses/fc82a056c506aa7ddda36213d8999a98778cdd26"}}}}