Created
June 24, 2013 19:56
-
-
Save laser/5853035 to your computer and use it in GitHub Desktop.
Use the "modular style"
This file contains hidden or 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
######## | |
# app.rb | |
# | |
require 'sinatra/base' | |
class SimpleApp < Sinatra::Base | |
set :root, File.dirname(__FILE__) | |
enable :sessions | |
def require_logged_in | |
redirect('/sessions/new') unless is_authenticated? | |
end | |
def is_authenticated? | |
return !!session[:user_id] | |
end | |
get '/' do | |
erb :login | |
end | |
get '/sessions/new' do | |
erb :login | |
end | |
post '/sessions' do | |
session[:user_id] = params["user_id"] | |
end | |
get '/secrets' do | |
require_logged_in | |
erb :secrets | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment