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)


143
144
145
# File 'lib/sorcery/model.rb', line 143

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.



137
138
139
# File 'lib/sorcery/model.rb', line 137

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)


148
149
150
151
152
153
154
155
# File 'lib/sorcery/model.rb', line 148

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

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

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