Created
July 19, 2010 06:21
-
-
Save hassox/481065 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Guard < Padrino::Application | |
register Padrino::Helpers | |
require 'sass/plugin/rack' | |
Warden::Manager.serialize_into_session{|user| user.id } | |
Warden::Manager.serialize_from_session{|id| User.get(id) } | |
Warden::Manager.before_failure do |env,opts| | |
# Sinatra is very sensitive to the request method | |
# since authentication could fail on any type of method, we need | |
# to set it for the failure app so it is routed to the correct block | |
puts "============== #{opts.inspect}" | |
env['REQUEST_METHOD'] = "POST" | |
end | |
Warden::Strategies.add(:basic) do | |
def valid? | |
username && params["password"] | |
end | |
def username | |
params['email'] || params['login'] | |
end | |
def authenticate! | |
u = User.authenticate(username, params["password"]) | |
u.nil? ? fail! : success!(u) | |
end | |
end | |
Sass::Plugin.options[:template_location] = File.join(Padrino.root, "guard/app/sass") | |
Sass::Plugin.options[:css_location] = File.join(Padrino.root, "public/css") | |
configure do | |
use Sass::Plugin::Rack | |
use Rack::Session::DataMapper | |
use Rack::Flash | |
use Warden::Manager do |config| | |
config.default_scope :default | |
config.scope_defaults :default, | |
:strategies => [:basic], | |
:action => "sessions/unauthenticated" | |
config.failure_app = Guard | |
end | |
end | |
end | |
include CoreApp::Guard |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment