Sha256: 6eec586185d8b0ca61c5fee8f3515bfb423b02af5f2af0d3eaef5b80c5901b6a

Contents?: true

Size: 1.08 KB

Versions: 3

Compression:

Stored size: 1.08 KB

Contents

class ApplicationController < Sinatra::Base
  # Configure Warden for authentication
  enable :sessions

  use Warden::Manager do |config|
    config.serialize_into_session{|user| user.id}
    config.serialize_from_session{|id| User.find(id)}
    config.scope_defaults :default, strategies: [:password], action: 'auth/invalid'
    config.failure_app = self
  end

  Warden::Manager.before_failure {|env,opts| env['REQUEST_METHOD'] = 'POST'}
  Warden::Strategies.add(:password) do
    def valid?
      params['user'] && params['user']['username'] && params['user']['password']
    end
    def authenticate!
      unless (user = User.find_by_username params['user']['username'])
        fail! 'The username you entered does not exist'
      else
        user.authenticate(params['user']['password']) ? success!(user) : fail!('Could not log in')
      end
    end
  end

  helpers do
    def current_user
      env['warden'].user
    end

    def authenticated?
      !!current_user
    end

    def authenticate
      env['warden'].authenticate!
    end

    alias_method :logged_in?, :authenticated?
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
eucalypt-0.2.2 lib/eucalypt/eucalypt-security/namespaces/security-warden/templates/warden.tt
eucalypt-0.2.1 lib/eucalypt/eucalypt-security/namespaces/security-warden/templates/warden.tt
eucalypt-0.2.0 lib/eucalypt/eucalypt-security/namespaces/security-warden/templates/warden.tt