Module: Sinatra::WardenPlugin
- Defined in:
- lib/sinatra/warden_plugin.rb,
lib/sinatra/warden_plugin/warden_helpers.rb
Defined Under Namespace
Modules: WardenHelpers Classes: PasswordStrategy
Class Method Summary collapse
Class Method Details
.registered(app) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/sinatra/warden_plugin.rb', line 31 def self.registered(app) raise "WardenPlugin::Error - Install warden with 'sudo gem install warden' to use plugin!" unless Warden && Warden::Manager app.use Warden::Manager do |manager| manager.default_strategies :password manager.default_serializers :session, :cookie manager.failure_app = app manager.serializers.update(:session) do def serialize(user); user.nil? ? nil : user.id; end def deserialize(id); id.nil? ? nil : PasswordStrategy.user_class.find(id); end end end app.helpers Sinatra::MarkupPlugin::OutputHelpers app.helpers WardenHelpers Warden::Manager.before_failure { |env,opts| env['REQUEST_METHOD'] = "POST" } Warden::Strategies.add(:password, PasswordStrategy) PasswordStrategy.user_class = User if defined?(User) end |