Created
June 3, 2009 07:46
-
-
Save botanicus/122859 to your computer and use it in GitHub Desktop.
This file contains 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
# coding: utf-8 | |
require "rango" | |
Rango.boot | |
# warden authentication | |
# wiki.github.com/hassox/warden/setup | |
require "warden" | |
Project.import("views.rb") | |
use Warden::Manager do |manager| | |
manager.default_strategies :password | |
# Rango::Controller has class method call which will call Rango::Controller.reroute(action), | |
# for example Login.route_to(:login) which will set login action of Login controller as default | |
# Internally it just rewrites env["rango.controller"] and env["rango.action"] to "Login", resp. "login" | |
manager.failure_app = Twitter | |
end | |
Warden::Manager.serialize_into_session { |user| user.id } | |
Warden::Manager.serialize_from_session { |key| User.get(id) } | |
# Go to login | |
Warden::Manager.before_failure do |env, opts| | |
Twitter.route_to env, 'login' | |
end | |
Warden::Strategies.add(:password) do | |
def authenticate! | |
User.new # just for test | |
end | |
end | |
run Rango.app |
This file contains 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
[00:59:05] params: {} | |
[00:59:05] cookies: {:__utma=>"111872281.2820358207102789000.1240239502.1240239502.1240239502.1", :__utmz=>"111872281.1240239502.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)", :referer=>"/"} | |
[00:59:05] session: {} | |
[00:59:05] Calling filter authenticate for controller #<Twitter:0x133ca88> | |
[00:59:05] params: {} | |
[00:59:05] cookies: {:__utma=>"111872281.2820358207102789000.1240239502.1240239502.1240239502.1", :__utmz=>"111872281.1240239502.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)", :referer=>"/"} | |
[00:59:05] session: {} | |
[00:59:05] Calling filter authenticate for controller #<Twitter:0x133b7f0> | |
ArgumentError: uncaught throw :warden | |
/opt/pkg/ruby-1.9.1/lib/ruby1.9/gems/1.9.1/gems/warden-0.2.1/lib/warden/proxy.rb:72:in `throw' | |
/opt/pkg/ruby-1.9.1/lib/ruby1.9/gems/1.9.1/gems/warden-0.2.1/lib/warden/proxy.rb:72:in `authenticate!' | |
/Users/botanicus/Projects/rango/examples/twitter/views.rb:11:in `authenticate' | |
/Users/botanicus/Projects/rango/rango/lib/rango/mvc/controller.rb:117:in `block in run_filters' | |
/Users/botanicus/Projects/rango/rango/lib/rango/mvc/controller.rb:112:in `each' | |
/Users/botanicus/Projects/rango/rango/lib/rango/mvc/controller.rb:112:in `run_filters' | |
/Users/botanicus/Projects/rango/rango/lib/rango/mvc/controller.rb:52:in `call' | |
/opt/pkg/ruby-1.9.1/lib/ruby1.9/gems/1.9.1/gems/warden-0.2.1/lib/warden/manager.rb:131:in `call_failure_app' | |
/opt/pkg/ruby-1.9.1/lib/ruby1.9/gems/1.9.1/gems/warden-0.2.1/lib/warden/manager.rb:117:in `process_unauthenticated' | |
/opt/pkg/ruby-1.9.1/lib/ruby1.9/gems/1.9.1/gems/warden-0.2.1/lib/warden/manager.rb:54:in `call' | |
/opt/pkg/ruby-1.9.1/lib/ruby1.9/gems/1.9.1/gems/rack-1.0.0/lib/rack/lint.rb:47:in `_call' | |
/opt/pkg/ruby-1.9.1/lib/ruby1.9/gems/1.9.1/gems/rack-1.0.0/lib/rack/lint.rb:35:in `call' | |
/opt/pkg/ruby-1.9.1/lib/ruby1.9/gems/1.9.1/gems/rack-1.0.0/lib/rack/showexceptions.rb:24:in `call' | |
/opt/pkg/ruby-1.9.1/lib/ruby1.9/gems/1.9.1/gems/rack-1.0.0/lib/rack/commonlogger.rb:20:in `_call' | |
/opt/pkg/ruby-1.9.1/lib/ruby1.9/gems/1.9.1/gems/rack-1.0.0/lib/rack/commonlogger.rb:13:in `call' | |
/opt/pkg/ruby-1.9.1/lib/ruby1.9/gems/1.9.1/gems/rack-1.0.0/lib/rack/content_length.rb:13:in `call' | |
/opt/pkg/ruby-1.9.1/lib/ruby1.9/gems/1.9.1/gems/rack-1.0.0/lib/rack/chunked.rb:15:in `call' | |
/opt/pkg/ruby-1.9.1/lib/ruby1.9/gems/1.9.1/gems/thin-1.2.2/lib/thin/connection.rb:76:in `block in pre_process' | |
/opt/pkg/ruby-1.9.1/lib/ruby1.9/gems/1.9.1/gems/thin-1.2.2/lib/thin/connection.rb:74:in `catch' | |
/opt/pkg/ruby-1.9.1/lib/ruby1.9/gems/1.9.1/gems/thin-1.2.2/lib/thin/connection.rb:74:in `pre_process' | |
/opt/pkg/ruby-1.9.1/lib/ruby1.9/gems/1.9.1/gems/thin-1.2.2/lib/thin/connection.rb:57:in `process' | |
/opt/pkg/ruby-1.9.1/lib/ruby1.9/gems/1.9.1/gems/thin-1.2.2/lib/thin/connection.rb:42:in `receive_data' | |
/opt/pkg/ruby-1.9.1/lib/ruby1.9/gems/1.9.1/gems/eventmachine-0.12.6/lib/eventmachine.rb:240:in `run_machine' | |
/opt/pkg/ruby-1.9.1/lib/ruby1.9/gems/1.9.1/gems/eventmachine-0.12.6/lib/eventmachine.rb:240:in `run' | |
/opt/pkg/ruby-1.9.1/lib/ruby1.9/gems/1.9.1/gems/thin-1.2.2/lib/thin/backends/base.rb:57:in `start' | |
/opt/pkg/ruby-1.9.1/lib/ruby1.9/gems/1.9.1/gems/thin-1.2.2/lib/thin/server.rb:156:in `start' | |
/opt/pkg/ruby-1.9.1/lib/ruby1.9/gems/1.9.1/gems/rack-1.0.0/lib/rack/handler/thin.rb:14:in `run' | |
/opt/pkg/ruby-1.9.1/lib/ruby1.9/gems/1.9.1/gems/rack-1.0.0/bin/rackup:176:in `<top (required)>' | |
/opt/pkg/ruby-1.9.1/bin/rackup:19:in `load' | |
/opt/pkg/ruby-1.9.1/bin/rackup:19:in `<main>' | |
127.0.0.1 - - [03/Jun/2009 00:59:05] "GET /unauthenticated HTTP/1.1" 500 94027 0.1222 |
This file contains 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
# coding: utf-8 | |
Rango.import("mvc/controller") | |
Project.import("models") | |
class Twitter < Rango::Controller | |
before :authenticate | |
def authenticate | |
request.env['warden'].authenticate! | |
end | |
def login | |
"Please log in." | |
end | |
def index | |
render "index" | |
end | |
def timeline | |
@posts = Post.all | |
display @posts, "list.html" | |
end | |
def show(id) | |
@post = Post.get(id) | |
raise Error404.new(params) unless @post | |
display @post, "show.html" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment