Permalink
Browse files

get fb auth working

  • Loading branch information...
1 parent e54c6be commit 5bf3a03db390d7e679803ec06b04c7e3fbde20ad @aaronbrethorst aaronbrethorst committed Mar 28, 2012
@@ -15,7 +15,7 @@ def create
end
def login_with_facebook
- redirect_to oauth.url_for_oauth_code
+ redirect_to oauth.url_for_oauth_code(:permissions => "email")
end
def complete_login_with_facebook
@@ -25,7 +25,8 @@ def complete_login_with_facebook
@user = Authentication.load_user_from_facebook_access_token(@access_token)
if @user
- log_in_user(@user)
+ sign_in @user
+ redirect_back_or @user
else
flash.now[:error] = t('facebook-error')
redirect_to signup_path
@@ -42,10 +43,4 @@ def destroy
def oauth
@oauth ||= Koala::Facebook::OAuth.new(FACEBOOK_APP_ID, FACEBOOK_APP_SECRET, FACEBOOK_CALLBACK_URL)
end
-
- def log_in_user(user)
- response.headers[HEADER_AUTH_TOKEN] = @user.remember_token
- render :nothing => true, :status => :created
- end
-
end
@@ -34,7 +34,8 @@ def self.load_user_from_facebook_profile(profile)
# otherwise, create the new user and auth objects. make sure they both get created or neither do.
Authentication.transaction do
- user = User.create!(:first_name => profile['name'].split(' ')[0], :last_name => profile['name'].split(' ')[1], :email => profile['email'], :password => SecureRandom.base64(15).tr('+/=lIO0', 'pqrsxyz'))
+ pass = SecureRandom.base64(15).tr('+/=lIO0', 'pqrsxyz')
+ user = User.create!(:first_name => profile['name'].split(' ')[0], :last_name => profile['name'].split(' ')[1], :email => profile['email'], :password => pass, :password_confirmation => pass)
auth = Authentication.create!(:user_id => user.id, :provider => 'facebook', :uid => profile['id'], :data_hash => profile)
end
return user
@@ -0,0 +1,11 @@
+class CreateAuthentications < ActiveRecord::Migration
+ def change
+ create_table :authentications do |t|
+ t.integer :user_id
+ t.string :uid
+ t.string :provider
+ t.text :data_hash
+ t.timestamps
+ end
+ end
+end
View
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120328053931) do
+ActiveRecord::Schema.define(:version => 20120328222810) do
create_table "answers", :force => true do |t|
t.string "name"
@@ -28,6 +28,15 @@
add_index "answers", ["list_id", "created_at"], :name => "index_answers_on_list_id_and_created_at"
+ create_table "authentications", :force => true do |t|
+ t.integer "user_id"
+ t.string "uid"
+ t.string "provider"
+ t.text "data_hash"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
create_table "lists", :force => true do |t|
t.string "name"
t.string "details"
@@ -0,0 +1,11 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+# This model initially had no columns defined. If you add columns to the
+# model remove the '{}' from the fixture names and add the columns immediately
+# below each fixture, per the syntax in the comments below
+#
+one: {}
+# column: value
+#
+two: {}
+# column: value
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class AuthenticationTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end

0 comments on commit 5bf3a03

Please sign in to comment.