Created
January 10, 2010 20:51
-
-
Save markmarkoh/273762 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
require 'rubygems' | |
require 'sinatra' | |
require 'haml' | |
require 'model' | |
set :port, 80 | |
get '/' do | |
protected! | |
@upload_types = pie Chart.upload_types | |
haml :index | |
end | |
helpers do | |
#use HTTP Auth to protect the data | |
def protected! | |
response['WWW-Authenticate'] = %(Basic realm="Admin Only") and \ | |
throw(:halt, [401, "Not authorized\n"]) and \ | |
return unless authorized? | |
end | |
def authorized? | |
@auth ||= Rack::Auth::Basic::Request.new(request.env) | |
@auth.provided? && @auth.basic? && @auth.credentials && @auth.credentials == ['USER', 'PASS'] | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment