Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

external? turned true when password and password confirmation is nil #758

Open
takashi opened this issue Feb 28, 2016 · 2 comments
Open

Comments

@takashi
Copy link

takashi commented Feb 28, 2016

I try to implement simple password authentication and oauth login with sorcery to my app.

when I try to signup without password and password confirmation, external? has been true

here's my code

class User < ActiveRecord::Base
  authenticates_with_sorcery!
  authenticates_with_sorcery! do |config|
    config.authentications_class = Authentication
  end

  validates :password, presence: true, if: :password_required?
  validates :password, confirmation: true, if: :password_required?
  validates :password, length: { minimum: 8 }, allow_blank: true


  private
  def password_required?
    new_record? && !external?
  end
end

In password_required?, external? has been true and validation has been ignored when password and password_confirmation is nil.

How can I turn on validation in this case?

@arnvald
Copy link
Collaborator

arnvald commented Mar 1, 2016

Hey @takashi, the implementation of external? in Sorcery is not great. You can change it for example to:

def external?
  authentications.present?
end

This way users will not require password only if they have at least one authentication assigned (i.e. that they come from some oAuth provider)

@takashi
Copy link
Author

takashi commented Mar 10, 2016

Hi @arnvald,
thank you for giving me the good solution. I'd like to implement ur solution as default implementation of sorcery's external? . is there any reason not to implement external? this way?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants