Created
May 1, 2014 10:09
-
-
Save dmgarland/61a83147681069d6b4f2 to your computer and use it in GitHub Desktop.
Sinatra session / login example.
This file contains 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 '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