Skip to content

Commit

Permalink
The default behavior is now to save the user without validations and …
Browse files Browse the repository at this point in the history
…then in an application specific interface ask for the additional user details to make the user valid. I also added an option to make this configurable with the facebook_valid_user you can now set if the user should be valid prior to save.
  • Loading branch information
kalasjocke committed Jul 16, 2009
1 parent 25fd049 commit dd1a9de
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions lib/authlogic_facebook_connect/session.rb
Expand Up @@ -8,6 +8,23 @@ def self.included(klass)
end

module Config
# Should the user be saved with our without validations?
#
# The default behavior is to save the user without validations and then
# in an application specific interface ask for the additional user
# details to make the user valid as facebook just provides a facebook id.
#
# This is useful if you do want to turn on user validations, maybe if you
# just have facebook connect as an additional authentication solution and
# you already have valid users.
#
# * <tt>Default:</tt> true
# * <tt>Accepts:</tt> Boolean
def facebook_valid_user(value = nil)
rw_config(:facebook_valid_user, value, false)
end
alias_method :facebook_valid_user=, :facebook_valid_user

# What user field should be used for the facebook UID?
#
# This is useful if you want to use a single field for multiple types of
Expand Down Expand Up @@ -48,12 +65,19 @@ def validate_by_facebook_connect
# We assign it after the call to new in case the attribute is protected.
new_user = klass.new
new_user.send(:"#{facebook_uid_field}=", facebook_session.user.uid)

self.attempted_record = new_user

if facebook_valid_user
errors.add_to_base(
I18n.t('error_messages.facebook_user_creation_failed',
:default => 'There was a problem creating a new user ' +
'for your Facebook account')) unless self.attempted_record.valid?

errors.add_to_base(
I18n.t('error_messages.facebook_user_creation_failed',
:default => 'There was a problem creating a new user ' +
'for your Facebook account')) unless attempted_record.valid?
self.attempted_record = nil
else
self.attempted_record.save_with_validation(false)
end
rescue Facebooker::Session::SessionExpired
errors.add_to_base(I18n.t('error_messages.facebooker_session_expired',
:default => "Your Facebook Connect session has expired, please reconnect."))
Expand All @@ -67,6 +91,10 @@ def authenticating_with_facebook_connect?
end

private
def facebook_valid_user
self.class.facebook_valid_user
end

def facebook_uid_field
self.class.facebook_uid_field
end
Expand Down

0 comments on commit dd1a9de

Please sign in to comment.