Module: Sorcery::Model::ClassMethods
- Defined in:
- lib/sorcery/model.rb
Instance Method Summary collapse
-
#authenticate(*credentials) ⇒ Object
The default authentication method.
-
#encrypt(*tokens) ⇒ Object
encrypt tokens using current encryption_provider.
-
#sorcery_config ⇒ Object
Returns the class instance variable for configuration, when called by the class itself.
Instance Method Details
#authenticate(*credentials) ⇒ Object
The default authentication method. Takes a username and password, Finds the user by the username and compares the user’s password to the one supplied to the method. returns the user if success, nil otherwise.
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/sorcery/model.rb', line 105 def authenticate(*credentials) raise ArgumentError, "at least 2 arguments required" if credentials.size < 2 return false if credentials[0].blank? if @sorcery_config.downcase_username_before_authenticating credentials[0].downcase! end user = find_by_credentials(credentials) set_encryption_attributes _salt = user.send(@sorcery_config.salt_attribute_name) if user && !@sorcery_config.salt_attribute_name.nil? && !@sorcery_config.encryption_provider.nil? user if user && @sorcery_config.before_authenticate.all? {|c| user.send(c)} && credentials_match?(user.send(@sorcery_config.crypted_password_attribute_name),credentials[1],_salt) end |
#encrypt(*tokens) ⇒ Object
encrypt tokens using current encryption_provider.
123 124 125 126 127 128 129 130 |
# File 'lib/sorcery/model.rb', line 123 def encrypt(*tokens) return tokens.first if @sorcery_config.encryption_provider.nil? set_encryption_attributes() CryptoProviders::AES256.key = @sorcery_config.encryption_key @sorcery_config.encryption_provider.encrypt(*tokens) end |
#sorcery_config ⇒ Object
Returns the class instance variable for configuration, when called by the class itself.
97 98 99 |
# File 'lib/sorcery/model.rb', line 97 def sorcery_config @sorcery_config end |