Skip to content

Commit 47142b8

Browse files
author
Nicholas Watson
committed
updating for Facebook integration
1 parent 2586af0 commit 47142b8

File tree

7 files changed

+21
-37
lines changed

7 files changed

+21
-37
lines changed

app/controllers/entropi_social/user_registrations_controller.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ def new
1010
# POST /resource/sign_up
1111
def create
1212
@user = User.new(params[:user])
13-
14-
if @user.save
15-
13+
14+
if @user.save
1615
flash[:notice] = I18n.t("devise.registrations.signed_up")
17-
1816
sign_in_and_redirect(:user, @user)
1917
else
2018
clean_up_passwords(@user)

app/models/user.rb

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,5 @@ class User < ActiveRecord::Base
1717
has_many :groups, :as => :groupable
1818

1919
accepts_nested_attributes_for :profile
20-
21-
=begin
22-
class << self
23-
24-
def find_for_facebook_oauth(access_token, signed_in_resource=nil)
25-
data = access_token.extra.raw_info
26-
if user = User.where(:email => data.email).first
27-
user
28-
else # Create a user with a stub password.
29-
User.create!(:email => data.email, :password => Devise.friendly_token[0,20])
30-
end
31-
end
32-
33-
def new_with_session(params, session)
34-
super.tap do |user|
35-
if data = session["devise.facebook_data"] && session["devise.facebook_data"]["extra"]["raw_info"]
36-
user.email = data["email"]
37-
end
38-
end
39-
end
40-
41-
end
42-
=end
4320

4421
end

config/initializers/devise.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# session. If you need permissions, you should implement that in a before filter.
2626
# You can also supply a hash where the value is a boolean determining whether
2727
# or not authentication should be aborted when the value is not present.
28-
config.authentication_keys = [ :username ]
28+
config.authentication_keys = [ :email ]
2929

3030
# Configure parameters from the request object used for authentication. Each entry
3131
# given should be a request method and it will automatically be passed to the

db/migrate/20111118193950_setup_entropi_social.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
class SetupEntropiSocial < ActiveRecord::Migration
22
def up
33
create_table :users do |t|
4-
t.string :username
54
t.integer :invitation_limit, :default => 0
65
t.database_authenticatable :null => false
76
t.invitable

lib/entropi_social.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
require "entropi_social/engine"
22
require 'devise'
33
require 'entropi_social/strategies/facebook'
4-
54
require 'entropi_social/authorize'
65
require 'entropi_social/commentable'
6+
require 'entropi_social/models/user'
77

88
module EntropiSocial
99
end

lib/entropi_social/models/user.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,20 @@ module EntropiSocial
22
module Models
33
module User
44

5-
def self.included(user_model)
6-
user_model.extend ClassMethods
5+
def self.included(base)
6+
base.extend ClassMethods
7+
end
8+
9+
module InstanceMethods
10+
711
end
812

913
module ClassMethods
10-
11-
14+
#include EntropiSocial::Models::User::InstanceMethods
1215
end
16+
17+
18+
1319
end
1420
end
1521
end

lib/entropi_social/strategies/facebook.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@ def self.included(user_model)
77
end
88

99
module ClassMethods
10-
1110
def find_for_facebook_oauth(access_token, signed_in_resource=nil)
1211
data = access_token.extra.raw_info
12+
logger.info data
1313
if user = User.where(:email => data.email).first
1414
user
15-
else # Create a user with a stub password.
16-
User.create!(:email => data.email, :password => Devise.friendly_token[0,20])
15+
else # Create a user with a stub password.
16+
User.create!(:email => data.email, :password => Devise.friendly_token[0,20], :profile => profile)
17+
profile = user.build_profile(:first_name => access_token.info.first_name, :last_name => access_token.info.first_name)
18+
profile.save!
19+
return user
1720
end
1821
end
1922

@@ -26,6 +29,7 @@ def new_with_session(params, session)
2629
end
2730

2831
end
32+
2933
end
3034
end
3135
end

0 commit comments

Comments
 (0)