Module: Sorcery::Model::InstanceMethods

Defined in:
lib/sorcery/model.rb

Instance Method Summary collapse

Instance Method Details

#external?Boolean

identifies whether this user is regular, i.e. we hold his credentials in our db, or that he is external, and his credentials are saved elsewhere (twitter/facebook etc.).

Returns:

  • (Boolean)


173
174
175
# File 'lib/sorcery/model.rb', line 173

def external?
  send(sorcery_config.crypted_password_attribute_name).nil?
end

#sorcery_configObject

Returns the class instance variable for configuration, when called by an instance.



167
168
169
# File 'lib/sorcery/model.rb', line 167

def sorcery_config
  self.class.sorcery_config
end

#valid_password?(pass) ⇒ Boolean

Calls the configured encryption provider to compare the supplied password with the encrypted one.

Returns:

  • (Boolean)


178
179
180
181
182
183
184
185
186
187
188
# File 'lib/sorcery/model.rb', line 178

def valid_password?(pass)
  crypted = send(sorcery_config.crypted_password_attribute_name)
  return crypted == pass if sorcery_config.encryption_provider.nil?

  # Ensure encryption provider is using configured values
  self.class.set_encryption_attributes

  salt = send(sorcery_config.salt_attribute_name) unless sorcery_config.salt_attribute_name.nil?

  sorcery_config.encryption_provider.matches?(crypted, pass, salt)
end