Created
April 29, 2010 14:33
-
-
Save nabeken/383682 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
helpers do | |
def protected! | |
response = callcc do |cont| | |
auth = Rack::Auth::Digest::MD5.new(cont, "Administrator only") do |username| | |
"password" # username is ignored, or Password is always 'password' in this example. | |
end | |
auth.opaque = $$.to_s | |
auth.call(request.env) | |
end | |
throw(:halt, response) if response.first == 401 | |
end | |
end | |
# Example: | |
# | |
# get '/admin/?' do | |
# protected! | |
# something to do... | |
# end | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment