diff --git a/app/models/auth_user.rb b/app/models/auth_user.rb index 8a637c81..e5b47fcc 100644 --- a/app/models/auth_user.rb +++ b/app/models/auth_user.rb @@ -9,6 +9,8 @@ class AuthUser < AuthRecord length: {maximum: 30} validates :uid, uniqueness: {scope: :provider, allow_nil: true} + + validate :has_at_least_one_login_method has_one :user, foreign_key: :remote_id, inverse_of: :auth_user @@ -136,6 +138,13 @@ class AuthUser < AuthRecord end end + def has_at_least_one_login_method + if !uses_password? && !email? && !uses_neopass? + errors.add(:base, "You must have either a password, an email, or a " + + "NeoPass. Otherwise, you can't log in!") + end + end + def self.find_by_omniauth(auth) find_by(provider: auth.provider, uid: auth.uid) end