class ClaimController < ApplicationController

  skip_before_filter :require_authorization

  def index
    if Mockr.unclaimed? && viewer.authenticated?
      owner = User.create(:facebook_uid => viewer.facebook_uid,
        :name => "Jacob")
      flash[:notice] = "Congratulations #{owner.first_name}, you're now the proud owner of this brand new instance of Mockr!"
      redirect_to root_path
    else
      redirect_to new_session_path
    end
  end
end


class ClaimController < ApplicationController

  skip_before_filter :require_authorization

  def index
    if Mockr.unclaimed? && viewer.authenticated?
      graph_data = ActiveSupport::JSON.decode(
        open("http://graph.facebook.com/#{viewer.facebook_uid}").read)
      owner = User.create(:facebook_uid => viewer.facebook_uid,
                          :name => graph_data['name'])
      flash[:notice] = <<-EOS.squish
        Congratulations #{owner.first_name}, you're now the proud owner of this
        brand new instance of Mockr!
      EOS
      redirect_to root_path
    else
      redirect_to new_session_path
    end
  end
end

Use OpenGraph to get new user's name in claim flow
Use OpenGraph to get new user's name in claim flow

Instead of a "Lost" inspired default name, we utilize the Facebook OpenGraph
JSON API to pull basic contact details based on a Facebook UID.

Change-Id: I78ed6f37f34aad081ed2994bf406f7c37defffcb
Reviewed-on: https://gerrit.causes.com/5113
Reviewed-by: Lann Martin <564fa7a717c51b612962ea128f146981a0e99d90@causes.com>
Tested-by: Adam Derewecki <0e18f44c1fec03ec4083422cb58ba6a09ac4fb2a@causes.com>
