devise_koala_connectable 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest CHANGED
@@ -1,7 +1,6 @@
1
1
  CHANGELOG
2
2
  README.rdoc
3
3
  Rakefile
4
- devise_koala_connectable.gemspec
5
4
  lib/devise_koala_connectable.rb
6
5
  lib/devise_koala_connectable/locales/de.yml
7
6
  lib/devise_koala_connectable/locales/en.yml
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require "rubygems"
2
2
  require "rake"
3
3
  require "echoe"
4
4
 
5
- Echoe.new("devise_koala_connectable", "0.1.3") do |p|
5
+ Echoe.new("devise_koala_connectable", "0.1.4") do |p|
6
6
  p.description = "Rails gem for adding Facebook authentification capabillity to devise using koala"
7
7
  p.url = "http://github.com/webmatze/devise_koala_connectable"
8
8
  p.author = "Mathias Karstädt"
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{devise_koala_connectable}
5
- s.version = "0.1.3"
5
+ s.version = "0.1.4"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Mathias Karst\303\244dt"]
9
- s.date = %q{2011-02-24}
9
+ s.date = %q{2011-03-23}
10
10
  s.description = %q{Rails gem for adding Facebook authentification capabillity to devise using koala}
11
11
  s.email = %q{mathias.karstaedt@gmail.com}
12
12
  s.extra_rdoc_files = ["CHANGELOG", "README.rdoc", "lib/devise_koala_connectable.rb", "lib/devise_koala_connectable/locales/de.yml", "lib/devise_koala_connectable/locales/en.yml", "lib/devise_koala_connectable/model.rb", "lib/devise_koala_connectable/schema.rb", "lib/devise_koala_connectable/strategy.rb", "lib/devise_koala_connectable/version.rb", "lib/devise_koala_connectable/view_helpers.rb"]
13
- s.files = ["CHANGELOG", "README.rdoc", "Rakefile", "devise_koala_connectable.gemspec", "lib/devise_koala_connectable.rb", "lib/devise_koala_connectable/locales/de.yml", "lib/devise_koala_connectable/locales/en.yml", "lib/devise_koala_connectable/model.rb", "lib/devise_koala_connectable/schema.rb", "lib/devise_koala_connectable/strategy.rb", "lib/devise_koala_connectable/version.rb", "lib/devise_koala_connectable/view_helpers.rb", "rails/init.rb", "Manifest"]
13
+ s.files = ["CHANGELOG", "README.rdoc", "Rakefile", "lib/devise_koala_connectable.rb", "lib/devise_koala_connectable/locales/de.yml", "lib/devise_koala_connectable/locales/en.yml", "lib/devise_koala_connectable/model.rb", "lib/devise_koala_connectable/schema.rb", "lib/devise_koala_connectable/strategy.rb", "lib/devise_koala_connectable/version.rb", "lib/devise_koala_connectable/view_helpers.rb", "rails/init.rb", "Manifest", "devise_koala_connectable.gemspec"]
14
14
  s.homepage = %q{http://github.com/webmatze/devise_koala_connectable}
15
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Devise_koala_connectable", "--main", "README.rdoc"]
16
16
  s.require_paths = ["lib"]
@@ -14,7 +14,7 @@ require 'devise_koala_connectable/view_helpers'
14
14
  module Devise
15
15
  mattr_accessor :koala_identifier_field
16
16
  @@koala_identifier_field = :koala_identifier
17
-
17
+
18
18
  mattr_accessor :koala_auto_create_account
19
19
  @@koala_auto_create_account = true
20
20
 
@@ -26,7 +26,7 @@ module Devise
26
26
 
27
27
  mattr_accessor :koala_callback_url
28
28
  @@koala_callback_url = nil
29
-
29
+
30
30
  end
31
31
 
32
32
  I18n.load_path.unshift File.expand_path(File.join(File.dirname(__FILE__), *%w[devise_koala_connectable locales en.yml]))
@@ -75,7 +75,7 @@ module Devise #:nodoc:
75
75
  def on_before_koala_success(koala_user)
76
76
  self.send(:before_koala_success, koala_user) if self.respond_to?(:before_koala_success)
77
77
  end
78
-
78
+
79
79
  # Hook that gets called before the auto creation of the user.
80
80
  # Therefore, this hook is only called when koala_auto_create_account config option is enabled.
81
81
  # Useful for fetching additional user info (etc.) from Facebook.
@@ -11,7 +11,7 @@ module Devise #:nodoc:
11
11
  class KoalaConnectable < Base
12
12
 
13
13
  def valid?
14
- ((valid_controller? && cookie_present?) || signed_request?) && mapping.to.respond_to?('authenticate_with_koala')
14
+ ((valid_controller? && cookie_present? && koala_request?) || signed_request?) && mapping.to.respond_to?('authenticate_with_koala')
15
15
  end
16
16
 
17
17
  # Authenticate user with Koala.
@@ -22,7 +22,7 @@ module Devise #:nodoc:
22
22
  raise StandardError, "No api_key or secret_key defined, please see the documentation of Koala gem to setup it." unless klass.koala_app_id.present? and klass.koala_secret_key.present?
23
23
  begin
24
24
  oauth = Koala::Facebook::OAuth.new(klass.koala_app_id, klass.koala_secret_key, klass.koala_callback_url)
25
-
25
+
26
26
  if signed_request?
27
27
  user_info = oauth.parse_signed_request params[:signed_request]
28
28
  unless user_info.present? #if no valid signed facebook request found
@@ -40,61 +40,65 @@ module Devise #:nodoc:
40
40
  user_id = user_info["uid"]
41
41
  access_token = user_info["access_token"]
42
42
  end
43
-
43
+
44
44
  Rails.logger.debug "user_info: #{user_info.to_yaml}"
45
45
 
46
46
  graph = Koala::Facebook::GraphAPI.new(access_token)
47
47
  koala_user = graph.get_object(user_id)
48
-
48
+
49
49
  Rails.logger.debug koala_user.to_yaml
50
50
 
51
51
  unless koala_user
52
- fail(:koala_invalid)
53
- return
52
+ fail!(:koala_invalid)
53
+ return
54
54
  end
55
-
55
+
56
56
  if user = klass.authenticate_with_koala(koala_user)
57
57
  user.on_before_koala_success(koala_user)
58
58
  success!(user)
59
59
  return
60
60
  end
61
-
61
+
62
62
  unless klass.koala_auto_create_account? or signed_request?
63
- fail(:koala_invalid)
64
- return
63
+ fail!(:koala_invalid)
64
+ return
65
65
  end
66
-
66
+
67
67
  user = klass.new
68
68
  user.store_koala_credentials!(koala_user)
69
69
  koala_user["registration"] = user_info if signed_request?
70
70
  user.on_before_koala_auto_create(koala_user)
71
-
71
+
72
72
  user.save(:validate => false)
73
73
  user.on_before_koala_success(koala_user)
74
74
  success!(user)
75
-
75
+
76
76
  rescue Exception => e
77
77
  Rails.logger.error e.to_yaml
78
- fail(:koala_invalid)
78
+ fail!(:koala_invalid)
79
79
  end
80
80
  end
81
-
81
+
82
82
  protected
83
83
  def valid_controller?
84
84
  params[:controller].to_s =~ /sessions/
85
85
  end
86
-
86
+
87
87
  def cookie_present?
88
88
  klass = mapping.to
89
89
  raise StandardError, "No api_key or secret_key defined, please see the documentation of Koala gem to setup it." unless klass.koala_app_id.present? and klass.koala_secret_key.present?
90
90
  oauth = Koala::Facebook::OAuth.new(klass.koala_app_id, klass.koala_secret_key, klass.koala_callback_url)
91
91
  oauth.get_user_info_from_cookies(request.cookies).present?
92
92
  end
93
-
93
+
94
94
  def signed_request?
95
95
  params[:signed_request].present?
96
96
  end
97
97
 
98
+ def koala_request?
99
+ params[:koala].present?
100
+ end
101
+
98
102
  end
99
103
  end
100
104
 
@@ -6,7 +6,7 @@ module Devise #:nodoc:
6
6
  # Koala view helpers to easily add the link to the Facebook connection popup and also the necessary JS code.
7
7
  #
8
8
  module Helpers
9
-
9
+
10
10
  # Creates the link to the Facebook connection popup.
11
11
  # If you create a link without putting the JS code, the popup will load in a new page.
12
12
  # The second parameter is the return URL, it must be absolute (***_url).
@@ -16,13 +16,13 @@ module Devise #:nodoc:
16
16
  #
17
17
  def link_to_koala(link_text, link_url, options={})
18
18
  options = { :unobtrusive => true }.merge(options)
19
- oauth = Koala::Facebook::OAuth.new(Devise::koala_app_id, Devise::koala_secret_key, Devise::koala_callback_url)
20
- link_to link_text, oauth.url_for_oauth_code(:callback => link_url), options
19
+ oauth = Koala::Facebook::OAuth.new(Devise::koala_app_id, Devise::koala_secret_key, Devise::koala_callback_url)
20
+ link_to link_text, oauth.url_for_oauth_code(:callback => link_url), options
21
21
  end
22
22
 
23
23
  # Returns the necessary JS code for the Facebook popup.
24
24
  # It is recommended to put this code just before the </body> tag of your layout.
25
- #
25
+ #
26
26
  # For example :
27
27
  # ...
28
28
  # <%= javascript_include_koala %>
@@ -30,19 +30,19 @@ module Devise #:nodoc:
30
30
  # </html>
31
31
  #
32
32
  def javascript_include_koala
33
- "<div id=\"fb-root\"></div>
33
+ "<div id=\"fb-root\"></div>
34
34
  <script src=\"http://connect.facebook.net/en_US/all.js\"></script>
35
35
  <script>
36
- FB.init({
37
- appId:'#{Devise::koala_app_id}', cookie:true,
38
- status:true, xfbml:true
36
+ FB.init({
37
+ appId:'#{Devise::koala_app_id}', cookie:true,
38
+ status:true, xfbml:true
39
39
  });
40
40
  </script>"
41
41
  end
42
-
42
+
43
43
  # Renders the Facbook Registration Form (XFML).
44
44
  # For more info: http://developers.facebook.com/docs/plugins/registration/
45
- #
45
+ #
46
46
  # For example :
47
47
  # ...
48
48
  # <%= koala_registration_form("/registration", [{:name => "name"}, {:name => "password", :view => "not_prefilled"}, {:name => "birthday", :description => "Geburtstag", :type => "date"}], "callback_function", "de_DE", 600) %>
@@ -51,18 +51,18 @@ module Devise #:nodoc:
51
51
  def koala_registration_form(registration_url = "/", fields = [:name, :email, :password], on_validate = nil, locale = "en_EN", width = nil)
52
52
  width = (width.present?) ? "width=\"#{width.to_s}\" " : ""
53
53
  on_validate = (on_validate.present?) ? "onvalidate=\"#{on_validate}\" " : ""
54
- "<fb:registration
55
- fields='" + fields.to_json + "'
56
- redirect-uri=\"#{registration_url}\"
57
- locale=\"#{locale}\"
54
+ "<fb:registration
55
+ fields='" + fields.to_json + "'
56
+ redirect-uri=\"#{registration_url}\"
57
+ locale=\"#{locale}\"
58
58
  #{on_validate}
59
59
  #{width}>
60
60
  </fb:registration>"
61
61
  end
62
-
62
+
63
63
  # Renders the Facbook Registration Form (Iframe).
64
64
  # For more info: http://developers.facebook.com/docs/plugins/registration/
65
- #
65
+ #
66
66
  # For example :
67
67
  # ...
68
68
  # <%= koala_registration_iframe_form("/registration", [{:name => "name"}, {:name => "password", :view => "not_prefilled"}, {:name => "birthday", :description => "Geburtstag", :type => "date"}], "de_DE", 600, 400) %>
@@ -77,27 +77,28 @@ module Devise #:nodoc:
77
77
  redirect_uri=#{CGI.escape(registration_url)}&
78
78
  locale=#{locale}&
79
79
  fields=" + fields.to_json + "'
80
- scrolling=\"auto\"
81
- frameborder=\"no\"
82
- style=\"border:none\"
83
- allowTransparency=\"true\"
80
+ scrolling=\"auto\"
81
+ frameborder=\"no\"
82
+ style=\"border:none\"
83
+ allowTransparency=\"true\"
84
84
  #{width}
85
85
  #{height}>
86
86
  </iframe>"
87
87
  end
88
-
88
+
89
89
 
90
90
  # Returns the Login To Facebook button.
91
- #
91
+ #
92
92
  # For example :
93
93
  # ...
94
94
  # <%= koala_login_button("Login with Facebook", "/after_login") %>
95
95
  #
96
96
  def koala_login_button(button_text = "Login with Facebook", login_url = "/", registration_url = nil)
97
+ login_url += (login_url =~ /\?/ ? '&koala=true' : '?koala=true')
97
98
  registration = (registration_url.present?) ? "registration-url=\"#{registration_url}\"" : ""
98
99
  "<fb:login-button #{registration} on-login=\"window.location.href = '#{login_url}';\">#{button_text}</fb:login-button>"
99
100
  end
100
-
101
+
101
102
 
102
103
  # Returns the Logout button for Facebook.
103
104
  # It calls the logout_url after logging out of Facbook Connect.
@@ -110,7 +111,7 @@ module Devise #:nodoc:
110
111
  options = { :unobtrusive => true, :onclick => "FB.getLoginStatus(function(status){if(status.session){FB.logout(function(response){document.location.href='#{logout_url}'});}else{document.location.href='#{logout_url}'}})" }.merge(options)
111
112
  link_to button_text, "#", options
112
113
  end
113
-
114
+
114
115
  end
115
116
  end
116
117
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devise_koala_connectable
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 3
10
- version: 0.1.3
9
+ - 4
10
+ version: 0.1.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Mathias Karst\xC3\xA4dt"
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-24 00:00:00 +01:00
18
+ date: 2011-03-23 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -99,7 +99,6 @@ files:
99
99
  - CHANGELOG
100
100
  - README.rdoc
101
101
  - Rakefile
102
- - devise_koala_connectable.gemspec
103
102
  - lib/devise_koala_connectable.rb
104
103
  - lib/devise_koala_connectable/locales/de.yml
105
104
  - lib/devise_koala_connectable/locales/en.yml
@@ -110,6 +109,7 @@ files:
110
109
  - lib/devise_koala_connectable/view_helpers.rb
111
110
  - rails/init.rb
112
111
  - Manifest
112
+ - devise_koala_connectable.gemspec
113
113
  has_rdoc: true
114
114
  homepage: http://github.com/webmatze/devise_koala_connectable
115
115
  licenses: []