hassox (owner)

Revisions

gist: 104234 Download_button fork
public
Public Clone URL: git://gist.github.com/104234.git
Embed All Files: show embed
warden_initializer.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
## Rails 2.3.2 Integration Setup
Rails.configuration.middleware.use Warden::Manager do |manager|
  manager.default_strategies :password
  manager.failure_app = LoginController
end
 
# Rails needs the action to be passed in with the params
# This part should be pluginized
Warden::Manager.before_failure do |env, opts|
  request = env["action_controller.rescue.request"]
  request.params["action"] = "unauthenticated"
end
 
# Warden Application Setup
Warden::Manager.serialize_into_session{ |user| user } # Stores the raw object in the session...
Warden::Manager.serialize_from_session{ |user| user } # Not Good with an ORM!
 
Warden::Strategies.add(:password) do
  
  def valid?
    params["password"] || params["login"]
  end
  
  def authenticate!
     if params["login"] == "hassox" && params["password"] == "sekrit"
       success!("hassox") # sets the "hassox" string object as the authenticated user
     else
       fail!("Bad")
     end
  end
end