Skip to content

Instantly share code, notes, and snippets.

@dmgarland
Created May 1, 2014 10:09
Show Gist options
  • Save dmgarland/61a83147681069d6b4f2 to your computer and use it in GitHub Desktop.
Save dmgarland/61a83147681069d6b4f2 to your computer and use it in GitHub Desktop.
Sinatra session / login example.
require 'sinatra'
enable :sessions
before do
if request.path != '/login' && !session[:logged_in]
redirect '/login'
end
end
get '/login' do
# show a login page
endd
post '/login' do
if params[:password] == "COOLBEANS"
session[:logged_in] = true
end
end
get '/members_area' do
"SECRET"
end
get '/checkout' do
"SECRET"
end
get '/profile' do
"SECRET"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment