Class: Sorcery::Model::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/sorcery/model/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/sorcery/model/config.rb', line 48

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,
    :@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

Instance Attribute Details

#after_configObject

an array of method names to call after configuration by user. used internally.



35
36
37
# File 'lib/sorcery/model/config.rb', line 35

def after_config
  @after_config
end

#before_authenticateObject

an array of method names to call before authentication completes. used internally.



28
29
30
# File 'lib/sorcery/model/config.rb', line 28

def before_authenticate
  @before_authenticate
end

#crypted_password_attribute_nameObject

change default crypted_password attribute.



14
15
16
# File 'lib/sorcery/model/config.rb', line 14

def crypted_password_attribute_name
  @crypted_password_attribute_name
end

#custom_encryption_providerObject

use an external encryption class.



44
45
46
# File 'lib/sorcery/model/config.rb', line 44

def custom_encryption_provider
  @custom_encryption_provider
end

#downcase_username_before_authenticatingObject

downcase the username before trying to authenticate, default is false



12
13
14
# File 'lib/sorcery/model/config.rb', line 12

def downcase_username_before_authenticating
  @downcase_username_before_authenticating
end

#email_attribute_nameObject

change default email attribute.



10
11
12
# File 'lib/sorcery/model/config.rb', line 10

def email_attribute_name
  @email_attribute_name
end

#email_delivery_methodObject

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



33
34
35
# File 'lib/sorcery/model/config.rb', line 33

def email_delivery_method
  @email_delivery_method
end

#encryption_algorithmObject

encryption algorithm name. See ‘encryption_algorithm=’ below for available options.



46
47
48
# File 'lib/sorcery/model/config.rb', line 46

def encryption_algorithm
  @encryption_algorithm
end

#encryption_keyObject

encryption key used to encrypt reversible encryptions such as AES256.



22
23
24
# File 'lib/sorcery/model/config.rb', line 22

def encryption_key
  @encryption_key
end

#encryption_providerObject (readonly)

change default encryption_provider.



42
43
44
# File 'lib/sorcery/model/config.rb', line 42

def encryption_provider
  @encryption_provider
end

#password_attribute_nameObject

change virtual password attribute, the one which is used until an encrypted one is generated.



8
9
10
# File 'lib/sorcery/model/config.rb', line 8

def password_attribute_name
  @password_attribute_name
end

#salt_attribute_nameObject

change default salt attribute.



18
19
20
# File 'lib/sorcery/model/config.rb', line 18

def salt_attribute_name
  @salt_attribute_name
end

#salt_join_tokenObject

what pattern to use to join the password with the salt



16
17
18
# File 'lib/sorcery/model/config.rb', line 16

def salt_join_token
  @salt_join_token
end

#stretchesObject

how many times to apply encryption to the password.



20
21
22
# File 'lib/sorcery/model/config.rb', line 20

def stretches
  @stretches
end

#subclasses_inherit_configObject

make this configuration inheritable for subclasses. Useful for ActiveRecord’s STI.



24
25
26
# File 'lib/sorcery/model/config.rb', line 24

def subclasses_inherit_config
  @subclasses_inherit_config
end

#submodulesObject

configured in config/application.rb



26
27
28
# File 'lib/sorcery/model/config.rb', line 26

def submodules
  @submodules
end

#token_randomnessObject

Set token randomness



37
38
39
# File 'lib/sorcery/model/config.rb', line 37

def token_randomness
  @token_randomness
end

#username_attribute_namesObject

change default username attribute, for example, to use :email as the login. See ‘username_attribute_names=’ below.



40
41
42
# File 'lib/sorcery/model/config.rb', line 40

def username_attribute_names
  @username_attribute_names
end

Instance Method Details

#reset!Object

Resets all configuration options to their default values.



73
74
75
76
77
# File 'lib/sorcery/model/config.rb', line 73

def reset!
  @defaults.each do |k, v|
    instance_variable_set(k, v)
  end
end