Sha256: f605f2c094b0ef4b3049a58dab7db37e74b5ab5853e0aab5c08ea8d936558b68

Contents?: true

Size: 790 Bytes

Versions: 6

Compression:

Stored size: 790 Bytes

Contents

module Shield
  module Model
    def authenticate(username, password)
      user = fetch(username)

      if user and is_valid_password?(user, password)
        return user
      end
    end

    def fetch(login)
      raise FetchMissing
    end

    def is_valid_password?(user, password)
      Shield::Password.check(password, user.crypted_password)
    end

    class FetchMissing < Class.new(StandardError)
      def message
        %{
          !! You need to implement `fetch`.
          Below is a quick example implementation (in Ohm):

            def fetch(email)
              find(:email => email).first
            end

          For more example implementations, check out
          http://github.com/cyx/shield-contrib
        }.gsub(/^ {10}/, "")
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
shield-0.1.0 lib/shield/model.rb
shield-0.1.0.rc1 lib/shield/model.rb
shield-0.0.4 lib/shield/model.rb
shield-0.0.3 lib/shield/model.rb
shield-0.0.2 lib/shield/model.rb
shield-0.0.1 lib/shield/model.rb