require 'sinatra' require 'sinatra/contrib' def logged_in? cookies[:success] == 'true' end get '/' do cookies[:success] ||= false if logged_in? <<-HTML Hi there logged-in user! HTML else redirect '/login' end end get '/fail_4_times' do @@tries ||= 0 @@tries += 1 if @@tries <= 5 # Return a 0 error code. 0 else 'Stuff' end end get '/fail' do # Return a 0 error code. 0 end get '/login' do <<-HTML
HTML end post '/login' do if params['username'] == 'john' && params['password'] == 'doe' && params['token'] == 'secret!' cookies[:success] = true redirect '/' else 'Boohoo...' end end get '/congrats' do <<-EOHTML Congrats, get to the audit! EOHTML end get '/link' do if logged_in? <<-EOHTML Inject here #{params[:input]} EOHTML end end