blob: 1f52920eadbb73009ef6c6ba166b3901073e35c4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
require 'sinatra'
use Rack::Session::Cookie, :secret => "My session secret which shouldn't be committed to the repo in real life"
get '/' do
# The root route should render the :index template when logged out and the
# :logged_in template when logged in.
erb :index
end
post '/' do
if params[:username] == 'hubertfarnsworth' &&
params[:password] == 'secret'
# The user has correctly authenticated. Persist their login status by
# setting a session key here.
redirect '/'
else
'Unrecognized user'
end
end
get '/logout' do
# Unset the session here to log the user out.
redirect '/'
end
|