Permalink
Browse files

Remember my last session

Using new Cookie (tm) Technology, Tomatoist now remembers your last
session and sends you back to it when you return!!
  • Loading branch information...
1 parent 16caf00 commit 9eefd38e7d8d13af983564d05705a926c43b8706 @voxdolo committed Mar 7, 2012
Showing with 12 additions and 1 deletion.
  1. +1 −0 Gemfile
  2. +3 −0 Gemfile.lock
  3. +1 −0 app/app.rb
  4. +7 −1 app/controllers/main.rb
View
@@ -24,3 +24,4 @@ group :test do
end
gem 'padrino', '~> 0.10.5'
+gem 'padrino-cookies', '~> 0.1.0'
View
@@ -82,6 +82,8 @@ GEM
padrino-helpers (= 0.10.5)
padrino-cache (0.10.5)
padrino-core (= 0.10.5)
+ padrino-cookies (0.1.0)
+ padrino-core
padrino-core (0.10.5)
activesupport (~> 3.1.0)
http_router (~> 0.10.2)
@@ -172,6 +174,7 @@ DEPENDENCIES
mocha (~> 0.10.4)
mongoid (~> 2.4.4)
padrino (~> 0.10.5)
+ padrino-cookies (~> 0.1.0)
rack_hoptoad
rake
rspec (~> 2.8.0)
View
@@ -2,6 +2,7 @@ class Tomatoist < Padrino::Application
register HoptoadInitializer
register Padrino::Mailer
register Padrino::Helpers
+ register Padrino::Cookies
##
# Application configuration options
View
@@ -1,13 +1,19 @@
Tomatoist.controller do
get '/' do
- redirect session_path(Session.create)
+ if cookies.has_key?(:current_session)
+ redirect "/#{cookies[:current_session]}"
+ else
+ redirect session_path(Session.create)
+ end
end
get '/faq' do
render(:haml, :faq, layout: :application)
end
get '/:session/?' do
+ return if params[:session] == 'null'
+ cookies.permanent[:current_session] = params[:session]
@session = Session.retrieve(params[:session])
render(:haml, :timers, layout: :application)
end

0 comments on commit 9eefd38

Please sign in to comment.