module Sorcery::Model::InstanceMethods

Public Instance Methods

external?() click to toggle source

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.).

# File lib/sorcery/model.rb, line 171
def external?
  send(sorcery_config.crypted_password_attribute_name).nil?
end
sorcery_config() click to toggle source

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

# File lib/sorcery/model.rb, line 165
def sorcery_config
  self.class.sorcery_config
end
valid_password?(pass) click to toggle source

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

# File lib/sorcery/model.rb, line 176
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

Protected Instance Methods

clear_virtual_password() click to toggle source
# File lib/sorcery/model.rb, line 195
def clear_virtual_password
  config = sorcery_config
  send(:"#{config.password_attribute_name}=", nil)

  return unless respond_to?(:"#{config.password_attribute_name}_confirmation=")

  send(:"#{config.password_attribute_name}_confirmation=", nil)
end
encrypt_password() click to toggle source

creates new salt and saves it. encrypts password with salt and saves it.

# File lib/sorcery/model.rb, line 189
def encrypt_password
  config = sorcery_config
  send(:"#{config.salt_attribute_name}=", new_salt = TemporaryToken.generate_random_token) unless config.salt_attribute_name.nil?
  send(:"#{config.crypted_password_attribute_name}=", self.class.encrypt(send(config.password_attribute_name), new_salt))
end
generic_send_email(method, mailer) click to toggle source

calls the requested email method on the configured mailer supports both the ActionMailer 3 way of calling, and the plain old Ruby object way.

# File lib/sorcery/model.rb, line 206
def generic_send_email(method, mailer)
  config = sorcery_config
  mail = config.send(mailer).send(config.send(method), self)
  return unless mail.respond_to?(config.email_delivery_method)

  mail.send(config.email_delivery_method)
end