Sha256: e908686570f5071150ac17ad48615f645f9c4aefeb09d10051528e4d41ece660

Contents?: true

Size: 906 Bytes

Versions: 23

Compression:

Stored size: 906 Bytes

Contents

module Challah
  # Allows authentication by username and password.
  class PasswordTechnique
    # grab the params we want from this request
    def initialize(session)
      @username = session.username? ? session.username : nil
      @password = session.password? ? session.password : nil
    end

    # if we can successfully authenticate, return a User instance, otherwise nil
    def authenticate
      if username? and password?
        user = ::User.find_for_session(username)

        if user
          if user.active?
            if user.authenticate(@password)
              return user
            end
          end

          user.failed_authentication!
          user = nil
        end
      end

      nil
    end

    def password?
      !!@password
    end

    def persist?
      true
    end

    def username?
      !!@username
    end

    def username
      @username
    end
  end
end

Version data entries

23 entries across 22 versions & 2 rubygems

Version Path
challah-1.0.0 lib/challah/techniques/password_technique.rb
challah-1.0.0.beta3 lib/challah/techniques/password_technique.rb
challah-1.0.0.beta2 lib/challah/techniques/password_technique.rb
challah-1.0.0.beta lib/challah/techniques/password_technique.rb
challah-0.9.1.beta.3 lib/challah/techniques/password_technique.rb
challah-0.9.1.beta.2 lib/challah/techniques/password_technique.rb
challah-0.9.1.beta lib/challah/techniques/password_technique.rb
challah-0.9.0 lib/challah/techniques/password_technique.rb
challah-0.9.0.pre lib/challah/techniques/password_technique.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.3/lib/challah/techniques/password_technique.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.0.pre/lib/challah/techniques/password_technique.rb
challah-0.8.3 lib/challah/techniques/password_technique.rb
challah-0.8.2 lib/challah/techniques/password_technique.rb
challah-0.8.1 lib/challah/techniques/password_technique.rb
challah-0.8.0 lib/challah/techniques/password_technique.rb
challah-rolls-0.1.0 vendor/bundle/gems/challah-0.8.0.pre/lib/challah/techniques/password_technique.rb
challah-0.8.0.pre lib/challah/techniques/password_technique.rb
challah-0.7.1 lib/challah/techniques/password_technique.rb
challah-0.7.0 lib/challah/techniques/password_technique.rb
challah-0.7.0.pre lib/challah/techniques/password_technique.rb