aboutsummaryrefslogtreecommitdiffstats
path: root/app.rb
diff options
context:
space:
mode:
authorTeddy Wing2015-12-08 01:43:39 -0500
committerTeddy Wing2015-12-08 01:43:39 -0500
commit8ef7b1279d566f4907be99dfc09c01556e13f770 (patch)
tree914eba778a7bc8d47bffaa15421cf3b2748dc62d /app.rb
parentf3a35d4ff0606ea59aecd67c5daa01ccf51b01a8 (diff)
downloadRuby-Web-Sessions-Exercise-8ef7b1279d566f4907be99dfc09c01556e13f770.tar.bz2
Add app.rb from branch 'solution'
This file has been cleaned from its original implementation in the 'solution' branch to remove the solution to the exercise dealing with the session. Comments are added in spots where additional code must be filled in.
Diffstat (limited to 'app.rb')
-rw-r--r--app.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/app.rb b/app.rb
new file mode 100644
index 0000000..1f52920
--- /dev/null
+++ b/app.rb
@@ -0,0 +1,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