Module: Sinatra::Security::Identification

Defined in:
lib/sinatra/security/identification.rb

Overview

The identification module is mixed into Sinatra::Security::User. The API loosely applies to Ohm, although it will work with ActiveRecord.

If you wish to override any of these, it’s as simple as defining your own method in your User class.

Examples:


class User < Ohm::Model
  include Sinatra::Security::User
end

User.respond_to?(:find_by_login)
# => true

User.respond_to?(:authenticate)
# => true

Instance Method Summary collapse

Instance Method Details

#authenticate(login, password) ⇒ User?

Finds the User matching the given login / password combination.



28
29
30
31
32
33
34
# File 'lib/sinatra/security/identification.rb', line 28

def authenticate(, password)
  if user = ()
    if Sinatra::Security::Password::Hashing.check(password, user.crypted_password)
      user
    end
  end
end

#find_by_login(login) ⇒ User?

Used internally by User::authenticate to find the user given the :email value.

See Also:

  • LoginField::attr_name


45
46
47
# File 'lib/sinatra/security/identification.rb', line 45

def ()
  find( => ).first
end