blob: ef95715e98eede6c5f76c2afdf9cca553737040c (
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
|
require 'sinatra'
use Rack::Session::Cookie, :secret => "My session secret which shouldn't be committed to the repo in real life"
get '/' do
if session[:user]
"Logged in with user id #{session[:user]}"
else
erb :index
end
end
post '/' do
if params[:username] == 'hubertfarnsworth' &&
params[:password] == 'secret'
session[:user] = 1
redirect '/'
else
'Unrecognized user'
end
end
get '/logout' do
session[:user] = nil
redirect '/'
end
|