Module: SinatraMore::WardenPlugin

Defined in:
lib/sinatra_more/warden_plugin.rb

Defined Under Namespace

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
# File 'lib/sinatra_more/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.failure_app = app
    manager.serialize_into_session { |user| user.nil? ? nil : user.id }
    manager.serialize_from_session { |id| id.nil? ? nil : PasswordStrategy.user_class.find(id) }
  end
  app.helpers SinatraMore::OutputHelpers
  app.helpers SinatraMore::WardenHelpers
  Warden::Manager.before_failure { |env,opts| env['REQUEST_METHOD'] = "POST" }
  Warden::Strategies.add(:password, PasswordStrategy)
  PasswordStrategy.user_class = User if defined?(User)
end