开发者

Ruby on Rails: Adding Facebook login to existing Authlogic login

开发者 https://www.devze.com 2023-01-12 08:25 出处:网络
I have an existing site that is working well with Authlogic login. I\'m trying to add Facebook login as an option, using the authlogic_facebook_connect plugin, but it\'s not working properly.

I have an existing site that is working well with Authlogic login.

I'm trying to add Facebook login as an option, using the authlogic_facebook_connect plugin, but it's not working properly.

I'm following the instructions located here: http://github.com/jbasdf/authlogic_facebook_connect

On my registration form, I added the Facebook connect button using the procedure outlined, and when it is clicked, it is successfully posting to the form with the aut开发者_StackOverflowhenticity_token of the user, and nothing else, which I believe is the intended result. The controller code is extremely simple:

@new_user = User.new(params[:user])
@new_user.save

In my User model, I added the following before_connect method, which is never being called:

def before_connect(facebook_session)
  self.email = facebook_session.user.email
  reset_persistence_token
end 

I know this is not being called, because even if I add a line like raise "Error' to before_connect no error is occurring.

The actual save is failing, because of a number of authlogic's own internal validations. I'm getting:

  • Email is too short (minimum is 6 characters)
  • Email should look like an email address.
  • Password is too short (minimum is 4 characters)
  • Password confirmation is too short (minimum is 4 characters)

Of course these are all empty, because nothing is being posted, and no password is even expected. I assume Authlogic is running the password tests because I have a password field in the database, which I need to keep to get regular logins to work.

What am I doing wrong here?


I'm not sure if this is the correct way, but finally got this to work simply by disabling all the problematic validations by AuthLogic, and recoding them myself in my app.

This is the code that I included in my User model:

acts_as_authentic do |c|
  c.validate_login_field = false
  c.validate_email_field = false
  c.validate_password_field = false
end
0

精彩评论

暂无评论...
验证码 换一张
取 消