Skip to content

Instantly share code, notes, and snippets.

@markmarkoh
Created January 10, 2010 20:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markmarkoh/273762 to your computer and use it in GitHub Desktop.
Save markmarkoh/273762 to your computer and use it in GitHub Desktop.
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