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 '/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