class Sorcery::Model::Config
Attributes
an array of method names to call after configuration by user. used internally.
an array of method names to call before authentication completes. used internally.
change default crypted_password attribute.
use an external encryption class.
downcase the username before trying to authenticate, default is false
change default email attribute.
method to send email related options: `:deliver_later`, `:deliver_now`, `:deliver` Default: :deliver (Rails version < 4.2) or :deliver_now (Rails version 4.2+) method to send email related
encryption algorithm name. See 'encryption_algorithm=' below for available options.
encryption key used to encrypt reversible encryptions such as AES256.
change default encryption_provider.
change virtual password attribute, the one which is used until an encrypted one is generated.
application-specific secret token that is joined with the password and its salt. Currently available with BCrypt (default crypt provider) only.
change default salt attribute.
what pattern to use to join the password with the salt APPLICABLE TO MD5, SHA1, SHA256, SHA512. Other crypt providers (incl. BCrypt) ignore this parameter.
how many times to apply encryption to the password.
make this configuration inheritable for subclasses. Useful for ActiveRecord's STI.
configured in config/application.rb
Set token randomness
change default username attribute, for example, to use :email as the login. See 'username_attribute_names=' below.
Public Class Methods
# File lib/sorcery/model/config.rb, line 52 def initialize @defaults = { :@submodules => [], :@username_attribute_names => [:email], :@password_attribute_name => :password, :@downcase_username_before_authenticating => false, :@email_attribute_name => :email, :@crypted_password_attribute_name => :crypted_password, :@encryption_algorithm => :bcrypt, :@encryption_provider => CryptoProviders::BCrypt, :@custom_encryption_provider => nil, :@encryption_key => nil, :@pepper => '', :@salt_join_token => '', :@salt_attribute_name => :salt, :@stretches => nil, :@subclasses_inherit_config => false, :@before_authenticate => [], :@after_config => [], :@email_delivery_method => default_email_delivery_method, :@token_randomness => 15 } reset! end
Public Instance Methods
# File lib/sorcery/model/config.rb, line 88 def custom_encryption_provider=(provider) @custom_encryption_provider = @encryption_provider = provider end
# File lib/sorcery/model/config.rb, line 92 def encryption_algorithm=(algo) @encryption_algorithm = algo @encryption_provider = case @encryption_algorithm.to_sym when :none then nil when :md5 then CryptoProviders::MD5 when :sha1 then CryptoProviders::SHA1 when :sha256 then CryptoProviders::SHA256 when :sha512 then CryptoProviders::SHA512 when :aes256 then CryptoProviders::AES256 when :bcrypt then CryptoProviders::BCrypt when :custom then @custom_encryption_provider else raise ArgumentError, "Encryption algorithm supplied, #{algo}, is invalid" end end
Resets all configuration options to their default values.
# File lib/sorcery/model/config.rb, line 78 def reset! @defaults.each do |k, v| instance_variable_set(k, v) end end
# File lib/sorcery/model/config.rb, line 84 def username_attribute_names=(fields) @username_attribute_names = fields.is_a?(Array) ? fields : [fields] end
Private Instance Methods
# File lib/sorcery/model/config.rb, line 109 def default_email_delivery_method # Rails 4.2 deprecates #deliver rails_version_bigger_than_or_equal?('4.2.0') ? :deliver_now : :deliver end
# File lib/sorcery/model/config.rb, line 114 def rails_version_bigger_than_or_equal?(version) Gem::Version.new(version) <= Gem::Version.new(Rails.version) end