fbdoorman 0.8.0.4 → 0.8.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -18,7 +18,7 @@ Jeweler::Tasks.new do |gem|
18
18
  gem.summary = "Rails authentication with facebook single sign-on OR email & password."
19
19
  gem.description = "Painless user registration and sign-in using Facebook single sign-on with JS. Typical email login still works too."
20
20
  gem.email = "pelaez89@gmail.com"
21
- gem.version = "0.8.0.4"
21
+ gem.version = "0.8.0.5"
22
22
  gem.homepage = "http://github.com/davidpelaez/minifb-clearance"
23
23
  gem.authors = ["Fbdoorman: David Pelaez","MiniFB: Appoxy","Clearance: Thoughtbot"]
24
24
  gem.files = FileList["[A-Z]*", "{app,config,generators,lib,shoulda_macros,rails}/**/*"]
@@ -3,29 +3,23 @@ class Clearance::FacebookController < ApplicationController
3
3
  #Js is informing that the cookie was created
4
4
  def index
5
5
  if signed_in? then
6
- redirect_to FB_LOGGED_PATH #Evita multiples logins y hace que solo tenga sentido llamar el metodo con un nuevo cookie
6
+ redirect_to LOGGED_PATH #Evita multiples logins y hace que solo tenga sentido llamar el metodo con un nuevo cookie
7
7
  else #If there's no signed in user
8
8
  #The code arrives here
9
+ #Validate the token in the cookie
9
10
  @fbcookie = parse_fb_cookie
10
- ##Works sometimes, others sends: JSON::ParserError Exception: source did not contain any JSON!
11
- #Bucle posiblemente infinito y chambon para lidiar con la excepcion mientras se soluciona
12
- incomplete = true
13
- while incomplete do
14
- begin
15
- incomplete = false #Intento salir del bucle
16
- fbu = MiniFB::OAuthSession.new(@fbcookie["access_token"], 'es_ES').get "me"
17
- rescue JSON::ParserError
18
- incomplete = true #Reingreso en el bucle
19
- end
11
+ if authenticated_fbu? then
12
+ @user = find_fbuser(fbu.id) #The one from the DB
13
+ #If the user exists
14
+ if @user then
15
+ sign_in_fbu(@user, params[:token], params[:expiration])
16
+ else #If theres no user with that id
17
+ #Register this user
18
+ register_fbu(fbu)
19
+ end
20
+ else #The token isn't valid
21
+ closed
20
22
  end
21
- @user = find_fbuser(fbu.id) #The one from the DB
22
- #If the user exists
23
- if @user then
24
- sign_in_fbu(@user)
25
- else #If theres no user with that id
26
- #Register this user
27
- register_fbu(fbu)
28
- end
29
23
  end
30
24
  end
31
25
 
@@ -37,7 +31,7 @@ class Clearance::FacebookController < ApplicationController
37
31
 
38
32
  def sign_in_fbu(myuser)
39
33
  sign_in(myuser)
40
- redirect_to FB_LOGGED_PATH and return
34
+ redirect_to LOGGED_PATH and return
41
35
  end
42
36
 
43
37
  #Here I reply the create the new user, I changed te verifications so that fbid is unique and password is optional
@@ -48,9 +42,9 @@ class Clearance::FacebookController < ApplicationController
48
42
  @user.name = new_user.name
49
43
  @user.email2 = new_user.email
50
44
  if @user.save
51
- sign_in_fbu(@user)
45
+ sign_in_fbu(@user, params[:token], params[:expiration])
52
46
  else
53
- render :text => "No se pudo registrar su usuario de FB"
47
+ render :text => "Please contact the administrator, the Facebook user couldn't be created."
54
48
  end
55
49
  end
56
50
 
@@ -64,12 +64,18 @@ module Clearance
64
64
  #
65
65
  # @example
66
66
  # sign_in(@user)
67
- def sign_in(user)
67
+ def sign_in(user, fb_token = nil, token_expiration = nil)
68
68
  if user
69
69
  cookies[:remember_token] = {
70
70
  :value => user.remember_token,
71
71
  :expires => 1.year.from_now.utc
72
72
  }
73
+ if user_from_fb? then
74
+ cookies[:fb_token] = {
75
+ :value => fb_token,
76
+ :expires => token_expiration
77
+ }
78
+ end
73
79
  self.current_user = user
74
80
  end
75
81
  end
@@ -81,8 +87,7 @@ module Clearance
81
87
  def sign_out
82
88
  current_user.reset_remember_token! if current_user
83
89
  cookies.delete(:remember_token)
84
- #Remove FB cookie
85
- delete_fb_cookie
90
+ cookies.delete(:fb_token)
86
91
  self.current_user = nil
87
92
  end
88
93
 
@@ -99,6 +104,7 @@ module Clearance
99
104
  def fb_deny_access(flash_message = nil)
100
105
  store_location
101
106
  flash[:failure] = flash_message if flash_message
107
+
102
108
  redirect_to FB_CLOSED_URL
103
109
  end
104
110
 
@@ -24,9 +24,7 @@ def authenticated_fbu?
24
24
  #The user is authenticated if the UID than own the token is the same as the one in current user
25
25
  end
26
26
 
27
- def delete_fb_cookie
28
- cookies.delete("fbs_#{FB_APP_ID}".to_sym)
29
- end
27
+
30
28
 
31
29
 
32
30
  def facebook_js
data/lib/fbdoorman.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require 'mini_fb'
2
2
  require 'facebook_helpers'
3
+ require 'request_parser'
4
+
3
5
  require 'clearance/extensions/errors'
4
6
  require 'clearance/extensions/rescue'
5
7
  require 'clearance/configuration'
@@ -21,8 +23,8 @@ FB_CALLBACK_URL = "#{FB[:base_url]}/facebook"
21
23
  #This routed will be name with clearance routes as /facebookclosed
22
24
  FB_CLOSED_URL = "#{FB[:base_url]}/fbclosed"
23
25
 
24
- FB_LOGGED_PATH = FB[:after_login_path]
25
- FB_REGISTERED_PATH = FB[:after_register_path]
26
+ LOGGED_PATH = FB[:after_login_path]
27
+ REGISTERED_PATH = FB[:after_register_path]
26
28
 
27
29
  URL_AFTER_CREATE = FB[:url_after_create]
28
30
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fbdoorman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0.4
4
+ version: 0.8.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: