devise_koala_connectable 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG ADDED
@@ -0,0 +1,29 @@
1
+ == 0.1.3
2
+
3
+ * enhancements
4
+ * changed logging from info to debug.
5
+ * Added logout_button helper.
6
+ * Added user creation through Facebook Registration form
7
+ * Added koala_registration_form helper
8
+ * Added koala_registration_iframe_form helper
9
+ * login button now accepts an callback url
10
+ * Removed valid_params? method.
11
+
12
+ * bug fix
13
+ * many minor bugfixes
14
+
15
+ == 0.1.2
16
+
17
+ * bug fix
18
+ * changed strings to symbols
19
+ * other minor bugfixes
20
+
21
+ == 0.1.1
22
+
23
+ * bug fix
24
+ * some minor bugfixes
25
+
26
+ == 0.1.0 (yanked)
27
+
28
+ * enhancements
29
+ * initial Version, basic features
data/Manifest CHANGED
@@ -1,3 +1,4 @@
1
+ CHANGELOG
1
2
  README.rdoc
2
3
  Rakefile
3
4
  devise_koala_connectable.gemspec
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.2") do |p|
5
+ Echoe.new("devise_koala_connectable", "0.1.3") 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.2"
5
+ s.version = "0.1.3"
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-17}
9
+ s.date = %q{2011-02-24}
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
- s.extra_rdoc_files = ["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 = ["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"]
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"]
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"]
@@ -0,0 +1,4 @@
1
+ de:
2
+ devise:
3
+ sessions:
4
+ koala_invalid: "Login nicht möglich. Benutzer nicht gefunden."
@@ -11,28 +11,47 @@ module Devise #:nodoc:
11
11
  class KoalaConnectable < Base
12
12
 
13
13
  def valid?
14
- valid_controller? && valid_params? && mapping.to.respond_to?('authenticate_with_koala')
14
+ ((valid_controller? && cookie_present?) || signed_request?) && mapping.to.respond_to?('authenticate_with_koala')
15
15
  end
16
16
 
17
17
  # Authenticate user with Koala.
18
18
  #
19
19
  def authenticate!
20
-
21
20
  klass = mapping.to
22
21
 
23
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?
24
23
  begin
25
24
  oauth = Koala::Facebook::OAuth.new(klass.koala_app_id, klass.koala_secret_key, klass.koala_callback_url)
26
25
 
27
- user_info = oauth.get_user_info_from_cookies(request.cookies)
28
- Rails.logger.info user_info.to_yaml
26
+ if signed_request?
27
+ user_info = oauth.parse_signed_request params[:signed_request]
28
+ unless user_info.present? #if no valid signed facebook request found
29
+ pass
30
+ return
31
+ end
32
+ user_id = user_info["user_id"]
33
+ access_token = user_info["oauth_token"]
34
+ else
35
+ user_info = oauth.get_user_info_from_cookies(request.cookies)
36
+ unless user_info.present? #if no valid facebook Session found
37
+ pass
38
+ return
39
+ end
40
+ user_id = user_info["uid"]
41
+ access_token = user_info["access_token"]
42
+ end
43
+
44
+ Rails.logger.debug "user_info: #{user_info.to_yaml}"
29
45
 
30
- graph = Koala::Facebook::GraphAPI.new(user_info["access_token"])
31
- koala_user = graph.get_object(user_info["uid"])
46
+ graph = Koala::Facebook::GraphAPI.new(access_token)
47
+ koala_user = graph.get_object(user_id)
32
48
 
33
- Rails.logger.info koala_user.to_yaml
49
+ Rails.logger.debug koala_user.to_yaml
34
50
 
35
- fail!(:koala_invalid) and return unless koala_user
51
+ unless koala_user
52
+ fail(:koala_invalid)
53
+ return
54
+ end
36
55
 
37
56
  if user = klass.authenticate_with_koala(koala_user)
38
57
  user.on_before_koala_success(koala_user)
@@ -40,10 +59,14 @@ module Devise #:nodoc:
40
59
  return
41
60
  end
42
61
 
43
- fail!(:koala_invalid) and return unless klass.koala_auto_create_account?
62
+ unless klass.koala_auto_create_account? or signed_request?
63
+ fail(:koala_invalid)
64
+ return
65
+ end
44
66
 
45
67
  user = klass.new
46
68
  user.store_koala_credentials!(koala_user)
69
+ koala_user["registration"] = user_info if signed_request?
47
70
  user.on_before_koala_auto_create(koala_user)
48
71
 
49
72
  user.save(:validate => false)
@@ -52,7 +75,7 @@ module Devise #:nodoc:
52
75
 
53
76
  rescue Exception => e
54
77
  Rails.logger.error e.to_yaml
55
- fail!(:koala_invalid)
78
+ fail(:koala_invalid)
56
79
  end
57
80
  end
58
81
 
@@ -60,9 +83,16 @@ module Devise #:nodoc:
60
83
  def valid_controller?
61
84
  params[:controller].to_s =~ /sessions/
62
85
  end
63
-
64
- def valid_params?
65
- params[:code].present?
86
+
87
+ def cookie_present?
88
+ klass = mapping.to
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
+ oauth = Koala::Facebook::OAuth.new(klass.koala_app_id, klass.koala_secret_key, klass.koala_callback_url)
91
+ oauth.get_user_info_from_cookies(request.cookies).present?
92
+ end
93
+
94
+ def signed_request?
95
+ params[:signed_request].present?
66
96
  end
67
97
 
68
98
  end
@@ -40,15 +40,75 @@ module Devise #:nodoc:
40
40
  </script>"
41
41
  end
42
42
 
43
+ # Renders the Facbook Registration Form (XFML).
44
+ # For more info: http://developers.facebook.com/docs/plugins/registration/
45
+ #
46
+ # For example :
47
+ # ...
48
+ # <%= koala_registration_form("/registration", [{:name => "name"}, {:name => "password", :view => "not_prefilled"}, {:name => "birthday", :description => "Geburtstag", :type => "date"}], "callback_function", "de_DE", 600) %>
49
+ # ...
50
+ #
51
+ def koala_registration_form(registration_url = "/", fields = [:name, :email, :password], on_validate = nil, locale = "en_EN", width = nil)
52
+ width = (width.present?) ? "width=\"#{width.to_s}\" " : ""
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}\"
58
+ #{on_validate}
59
+ #{width}>
60
+ </fb:registration>"
61
+ end
62
+
63
+ # Renders the Facbook Registration Form (Iframe).
64
+ # For more info: http://developers.facebook.com/docs/plugins/registration/
65
+ #
66
+ # For example :
67
+ # ...
68
+ # <%= koala_registration_iframe_form("/registration", [{:name => "name"}, {:name => "password", :view => "not_prefilled"}, {:name => "birthday", :description => "Geburtstag", :type => "date"}], "de_DE", 600, 400) %>
69
+ # ...
70
+ #
71
+ def koala_registration_iframe_form(registration_url = "/", fields = [:name, :email, :password], locale = "en_EN", width = "100%", height = 330)
72
+ width = (width.present?) ? "width=\"#{width.to_s}\" " : ""
73
+ height = (height.present?) ? "height=\"#{height.to_s}\" " : ""
74
+ on_validate = (on_validate.present?) ? "onvalidate=\"#{on_validate}\" " : ""
75
+ "<iframe src='http://www.facebook.com/plugins/registration.php?
76
+ client_id=#{Devise::koala_app_id}&
77
+ redirect_uri=#{CGI.escape(registration_url)}&
78
+ locale=#{locale}&
79
+ fields=" + fields.to_json + "'
80
+ scrolling=\"auto\"
81
+ frameborder=\"no\"
82
+ style=\"border:none\"
83
+ allowTransparency=\"true\"
84
+ #{width}
85
+ #{height}>
86
+ </iframe>"
87
+ end
88
+
43
89
 
44
90
  # Returns the Login To Facebook button.
45
91
  #
46
92
  # For example :
47
93
  # ...
48
- # <%= koala_login_button("Login with Facebook") %>
94
+ # <%= koala_login_button("Login with Facebook", "/after_login") %>
95
+ #
96
+ def koala_login_button(button_text = "Login with Facebook", login_url = "/", registration_url = nil)
97
+ registration = (registration_url.present?) ? "registration-url=\"#{registration_url}\"" : ""
98
+ "<fb:login-button #{registration} on-login=\"window.location.href = '#{login_url}';\">#{button_text}</fb:login-button>"
99
+ end
100
+
101
+
102
+ # Returns the Logout button for Facebook.
103
+ # It calls the logout_url after logging out of Facbook Connect.
104
+ #
105
+ # For example :
106
+ # ...
107
+ # <%= koala_logout_button("Logout","/after_logout") %>
49
108
  #
50
- def koala_login_button(button_text = "Login with Facebook")
51
- "<fb:login-button>#{button_text}</fb:login-button>"
109
+ def koala_logout_button(button_text = "Logout", logout_url = "/", options = {})
110
+ 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
+ link_to button_text, "#", options
52
112
  end
53
113
 
54
114
  end
@@ -26,9 +26,11 @@ module Devise
26
26
 
27
27
  mattr_accessor :koala_callback_url
28
28
  @@koala_callback_url = nil
29
+
29
30
  end
30
31
 
31
- I18n.load_path.unshift File.join(File.dirname(__FILE__), *%w[devise_koala_connectable locales en.yml])
32
+ I18n.load_path.unshift File.expand_path(File.join(File.dirname(__FILE__), *%w[devise_koala_connectable locales en.yml]))
33
+ I18n.load_path.unshift File.expand_path(File.join(File.dirname(__FILE__), *%w[devise_koala_connectable locales de.yml]))
32
34
 
33
35
  Devise.add_module(:koala_connectable,
34
36
  :strategy => true,
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: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 2
10
- version: 0.1.2
9
+ - 3
10
+ version: 0.1.3
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-17 00:00:00 +01:00
18
+ date: 2011-02-24 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -85,6 +85,7 @@ executables: []
85
85
  extensions: []
86
86
 
87
87
  extra_rdoc_files:
88
+ - CHANGELOG
88
89
  - README.rdoc
89
90
  - lib/devise_koala_connectable.rb
90
91
  - lib/devise_koala_connectable/locales/de.yml
@@ -95,6 +96,7 @@ extra_rdoc_files:
95
96
  - lib/devise_koala_connectable/version.rb
96
97
  - lib/devise_koala_connectable/view_helpers.rb
97
98
  files:
99
+ - CHANGELOG
98
100
  - README.rdoc
99
101
  - Rakefile
100
102
  - devise_koala_connectable.gemspec