Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

adding episode 285

  • Loading branch information...
commit 0499698776f40d99f1939b086602a637414018d3 1 parent 6fdd190
@ryanb authored
Showing with 2,325 additions and 0 deletions.
  1. +13 −0 episode-285/README
  2. +5 −0 episode-285/auth-after/.gitignore
  3. +1 −0  episode-285/auth-after/.rspec
  4. +36 −0 episode-285/auth-after/Gemfile
  5. +168 −0 episode-285/auth-after/Gemfile.lock
  6. +26 −0 episode-285/auth-after/Guardfile
  7. +7 −0 episode-285/auth-after/README
  8. +7 −0 episode-285/auth-after/Rakefile
  9. BIN  episode-285/auth-after/app/assets/images/rails.png
  10. +9 −0 episode-285/auth-after/app/assets/javascripts/application.js
  11. +3 −0  episode-285/auth-after/app/assets/javascripts/home.js.coffee
  12. +3 −0  episode-285/auth-after/app/assets/javascripts/password_resets.js.coffee
  13. +3 −0  episode-285/auth-after/app/assets/javascripts/sessions.js.coffee
  14. +3 −0  episode-285/auth-after/app/assets/javascripts/users.js.coffee
  15. +91 −0 episode-285/auth-after/app/assets/stylesheets/application.css
  16. +7 −0 episode-285/auth-after/app/assets/stylesheets/home.css.scss
  17. +7 −0 episode-285/auth-after/app/assets/stylesheets/password_resets.css.scss
  18. +7 −0 episode-285/auth-after/app/assets/stylesheets/sessions.css.scss
  19. +7 −0 episode-285/auth-after/app/assets/stylesheets/users.css.scss
  20. +10 −0 episode-285/auth-after/app/controllers/application_controller.rb
  21. +4 −0 episode-285/auth-after/app/controllers/home_controller.rb
  22. +25 −0 episode-285/auth-after/app/controllers/password_resets_controller.rb
  23. +20 −0 episode-285/auth-after/app/controllers/sessions_controller.rb
  24. +14 −0 episode-285/auth-after/app/controllers/users_controller.rb
  25. +2 −0  episode-285/auth-after/app/helpers/application_helper.rb
  26. +2 −0  episode-285/auth-after/app/helpers/home_helper.rb
  27. +2 −0  episode-285/auth-after/app/helpers/password_resets_helper.rb
  28. +2 −0  episode-285/auth-after/app/helpers/sessions_helper.rb
  29. +2 −0  episode-285/auth-after/app/helpers/users_helper.rb
  30. 0  episode-285/auth-after/app/mailers/.gitkeep
  31. +8 −0 episode-285/auth-after/app/mailers/user_mailer.rb
  32. 0  episode-285/auth-after/app/models/.gitkeep
  33. +18 −0 episode-285/auth-after/app/models/user.rb
  34. +3 −0  episode-285/auth-after/app/views/home/index.html.erb
  35. +26 −0 episode-285/auth-after/app/views/layouts/application.html.erb
  36. +23 −0 episode-285/auth-after/app/views/password_resets/edit.html.erb
  37. +7 −0 episode-285/auth-after/app/views/password_resets/new.html.erb
  38. +14 −0 episode-285/auth-after/app/views/sessions/new.html.erb
  39. +5 −0 episode-285/auth-after/app/views/user_mailer/password_reset.text.erb
  40. +27 −0 episode-285/auth-after/app/views/users/new.html.erb
  41. +4 −0 episode-285/auth-after/config.ru
  42. +45 −0 episode-285/auth-after/config/application.rb
  43. +6 −0 episode-285/auth-after/config/boot.rb
  44. +25 −0 episode-285/auth-after/config/database.yml
  45. +5 −0 episode-285/auth-after/config/environment.rb
  46. +32 −0 episode-285/auth-after/config/environments/development.rb
  47. +54 −0 episode-285/auth-after/config/environments/production.rb
  48. +41 −0 episode-285/auth-after/config/environments/test.rb
  49. +7 −0 episode-285/auth-after/config/initializers/backtrace_silencers.rb
  50. +10 −0 episode-285/auth-after/config/initializers/inflections.rb
  51. +5 −0 episode-285/auth-after/config/initializers/mime_types.rb
  52. +7 −0 episode-285/auth-after/config/initializers/secret_token.rb
  53. +8 −0 episode-285/auth-after/config/initializers/session_store.rb
  54. +12 −0 episode-285/auth-after/config/initializers/wrap_parameters.rb
  55. +5 −0 episode-285/auth-after/config/locales/en.yml
  56. +9 −0 episode-285/auth-after/config/routes.rb
  57. +10 −0 episode-285/auth-after/db/migrate/20110613044221_create_users.rb
  58. +6 −0 episode-285/auth-after/db/migrate/20110718213551_add_password_reset_to_users.rb
  59. +24 −0 episode-285/auth-after/db/schema.rb
  60. +7 −0 episode-285/auth-after/db/seeds.rb
  61. +2 −0  episode-285/auth-after/doc/README_FOR_APP
  62. 0  episode-285/auth-after/lib/tasks/.gitkeep
  63. 0  episode-285/auth-after/log/.gitkeep
  64. +26 −0 episode-285/auth-after/public/404.html
  65. +26 −0 episode-285/auth-after/public/422.html
  66. +26 −0 episode-285/auth-after/public/500.html
  67. 0  episode-285/auth-after/public/favicon.ico
  68. +5 −0 episode-285/auth-after/public/robots.txt
  69. +6 −0 episode-285/auth-after/script/rails
  70. +4 −0 episode-285/auth-after/spec/factories.rb
  71. +3 −0  episode-285/auth-after/spec/fixtures/user_mailer/password_reset
  72. +15 −0 episode-285/auth-after/spec/mailers/user_mailer_spec.rb
  73. +24 −0 episode-285/auth-after/spec/models/user_spec.rb
  74. +51 −0 episode-285/auth-after/spec/requests/password_resets_spec.rb
  75. +64 −0 episode-285/auth-after/spec/spec_helper.rb
  76. +9 −0 episode-285/auth-after/spec/support/mailer_macros.rb
  77. 0  episode-285/auth-after/vendor/assets/stylesheets/.gitkeep
  78. 0  episode-285/auth-after/vendor/plugins/.gitkeep
  79. +5 −0 episode-285/auth-before/.gitignore
  80. +1 −0  episode-285/auth-before/.rspec
  81. +34 −0 episode-285/auth-before/Gemfile
  82. +162 −0 episode-285/auth-before/Gemfile.lock
  83. +20 −0 episode-285/auth-before/Guardfile
  84. +7 −0 episode-285/auth-before/README
  85. +7 −0 episode-285/auth-before/Rakefile
  86. BIN  episode-285/auth-before/app/assets/images/rails.png
  87. +9 −0 episode-285/auth-before/app/assets/javascripts/application.js
  88. +3 −0  episode-285/auth-before/app/assets/javascripts/home.js.coffee
  89. +3 −0  episode-285/auth-before/app/assets/javascripts/password_resets.js.coffee
  90. +3 −0  episode-285/auth-before/app/assets/javascripts/sessions.js.coffee
  91. +3 −0  episode-285/auth-before/app/assets/javascripts/users.js.coffee
  92. +91 −0 episode-285/auth-before/app/assets/stylesheets/application.css
  93. +7 −0 episode-285/auth-before/app/assets/stylesheets/home.css.scss
  94. +7 −0 episode-285/auth-before/app/assets/stylesheets/password_resets.css.scss
  95. +7 −0 episode-285/auth-before/app/assets/stylesheets/sessions.css.scss
  96. +7 −0 episode-285/auth-before/app/assets/stylesheets/users.css.scss
  97. +10 −0 episode-285/auth-before/app/controllers/application_controller.rb
  98. +4 −0 episode-285/auth-before/app/controllers/home_controller.rb
  99. +25 −0 episode-285/auth-before/app/controllers/password_resets_controller.rb
  100. +20 −0 episode-285/auth-before/app/controllers/sessions_controller.rb
  101. +14 −0 episode-285/auth-before/app/controllers/users_controller.rb
  102. +2 −0  episode-285/auth-before/app/helpers/application_helper.rb
  103. +2 −0  episode-285/auth-before/app/helpers/home_helper.rb
  104. +2 −0  episode-285/auth-before/app/helpers/password_resets_helper.rb
  105. +2 −0  episode-285/auth-before/app/helpers/sessions_helper.rb
  106. +2 −0  episode-285/auth-before/app/helpers/users_helper.rb
  107. 0  episode-285/auth-before/app/mailers/.gitkeep
  108. +8 −0 episode-285/auth-before/app/mailers/user_mailer.rb
  109. 0  episode-285/auth-before/app/models/.gitkeep
  110. +18 −0 episode-285/auth-before/app/models/user.rb
  111. +3 −0  episode-285/auth-before/app/views/home/index.html.erb
  112. +26 −0 episode-285/auth-before/app/views/layouts/application.html.erb
  113. +23 −0 episode-285/auth-before/app/views/password_resets/edit.html.erb
  114. +7 −0 episode-285/auth-before/app/views/password_resets/new.html.erb
  115. +14 −0 episode-285/auth-before/app/views/sessions/new.html.erb
  116. +5 −0 episode-285/auth-before/app/views/user_mailer/password_reset.text.erb
  117. +27 −0 episode-285/auth-before/app/views/users/new.html.erb
  118. +4 −0 episode-285/auth-before/config.ru
  119. +45 −0 episode-285/auth-before/config/application.rb
  120. +6 −0 episode-285/auth-before/config/boot.rb
  121. +25 −0 episode-285/auth-before/config/database.yml
  122. +5 −0 episode-285/auth-before/config/environment.rb
  123. +32 −0 episode-285/auth-before/config/environments/development.rb
  124. +54 −0 episode-285/auth-before/config/environments/production.rb
  125. +41 −0 episode-285/auth-before/config/environments/test.rb
  126. +7 −0 episode-285/auth-before/config/initializers/backtrace_silencers.rb
  127. +10 −0 episode-285/auth-before/config/initializers/inflections.rb
  128. +5 −0 episode-285/auth-before/config/initializers/mime_types.rb
  129. +7 −0 episode-285/auth-before/config/initializers/secret_token.rb
  130. +8 −0 episode-285/auth-before/config/initializers/session_store.rb
  131. +12 −0 episode-285/auth-before/config/initializers/wrap_parameters.rb
  132. +5 −0 episode-285/auth-before/config/locales/en.yml
  133. +9 −0 episode-285/auth-before/config/routes.rb
  134. +10 −0 episode-285/auth-before/db/migrate/20110613044221_create_users.rb
  135. +6 −0 episode-285/auth-before/db/migrate/20110718213551_add_password_reset_to_users.rb
  136. +24 −0 episode-285/auth-before/db/schema.rb
  137. +7 −0 episode-285/auth-before/db/seeds.rb
  138. +2 −0  episode-285/auth-before/doc/README_FOR_APP
  139. 0  episode-285/auth-before/lib/tasks/.gitkeep
  140. 0  episode-285/auth-before/log/.gitkeep
  141. +26 −0 episode-285/auth-before/public/404.html
  142. +26 −0 episode-285/auth-before/public/422.html
  143. +26 −0 episode-285/auth-before/public/500.html
  144. 0  episode-285/auth-before/public/favicon.ico
  145. +5 −0 episode-285/auth-before/public/robots.txt
  146. +6 −0 episode-285/auth-before/script/rails
  147. +4 −0 episode-285/auth-before/spec/factories.rb
  148. +3 −0  episode-285/auth-before/spec/fixtures/user_mailer/password_reset
  149. +15 −0 episode-285/auth-before/spec/mailers/user_mailer_spec.rb
  150. +24 −0 episode-285/auth-before/spec/models/user_spec.rb
  151. +51 −0 episode-285/auth-before/spec/requests/password_resets_spec.rb
  152. +16 −0 episode-285/auth-before/spec/spec_helper.rb
  153. +9 −0 episode-285/auth-before/spec/support/mailer_macros.rb
  154. 0  episode-285/auth-before/vendor/assets/stylesheets/.gitkeep
  155. 0  episode-285/auth-before/vendor/plugins/.gitkeep
View
13 episode-285/README
@@ -0,0 +1,13 @@
+RailsCasts Episode #285: Spork
+
+http://railscasts.com/episodes/285-spork
+
+Commands used in episode
+
+ rspec .
+ time rspec .
+ bundle
+ spork --bootstrap
+ spork
+ rspec . --drb
+ guard init spork
View
5 episode-285/auth-after/.gitignore
@@ -0,0 +1,5 @@
+.bundle
+db/*.sqlite3
+log/*.log
+tmp/
+.sass-cache/
View
1  episode-285/auth-after/.rspec
@@ -0,0 +1 @@
+--colour
View
36 episode-285/auth-after/Gemfile
@@ -0,0 +1,36 @@
+source 'http://rubygems.org'
+
+gem "rails", "3.1.0"
+
+# Bundle edge Rails instead:
+# gem 'rails', :git => 'git://github.com/rails/rails.git'
+
+gem 'sqlite3'
+
+# Gems used only for assets and not required
+# in production environments by default.
+group :assets do
+ gem 'sass-rails', " ~> 3.1.0"
+ gem 'coffee-rails', "~> 3.1.0"
+ gem 'uglifier'
+end
+
+gem 'jquery-rails'
+
+# Use unicorn as the web server
+# gem 'unicorn'
+
+# Deploy with Capistrano
+# gem 'capistrano'
+
+# To use debugger
+# gem 'ruby-debug19', :require => 'ruby-debug'
+
+gem "rspec-rails", :group => [:test, :development]
+group :test do
+ gem "factory_girl_rails"
+ gem "capybara"
+ gem "guard-rspec"
+ gem "spork", "> 0.9.0.rc"
+ gem "guard-spork"
+end
View
168 episode-285/auth-after/Gemfile.lock
@@ -0,0 +1,168 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ actionmailer (3.1.0)
+ actionpack (= 3.1.0)
+ mail (~> 2.3.0)
+ actionpack (3.1.0)
+ activemodel (= 3.1.0)
+ activesupport (= 3.1.0)
+ builder (~> 3.0.0)
+ erubis (~> 2.7.0)
+ i18n (~> 0.6)
+ rack (~> 1.3.2)
+ rack-cache (~> 1.0.3)
+ rack-mount (~> 0.8.2)
+ rack-test (~> 0.6.1)
+ sprockets (~> 2.0.0)
+ activemodel (3.1.0)
+ activesupport (= 3.1.0)
+ bcrypt-ruby (~> 3.0.0)
+ builder (~> 3.0.0)
+ i18n (~> 0.6)
+ activerecord (3.1.0)
+ activemodel (= 3.1.0)
+ activesupport (= 3.1.0)
+ arel (~> 2.2.1)
+ tzinfo (~> 0.3.29)
+ activeresource (3.1.0)
+ activemodel (= 3.1.0)
+ activesupport (= 3.1.0)
+ activesupport (3.1.0)
+ multi_json (~> 1.0)
+ arel (2.2.1)
+ bcrypt-ruby (3.0.1)
+ builder (3.0.0)
+ capybara (1.1.1)
+ mime-types (>= 1.16)
+ nokogiri (>= 1.3.3)
+ rack (>= 1.0.0)
+ rack-test (>= 0.5.4)
+ selenium-webdriver (~> 2.0)
+ xpath (~> 0.1.4)
+ childprocess (0.2.2)
+ ffi (~> 1.0.6)
+ coffee-rails (3.1.1)
+ coffee-script (>= 2.2.0)
+ railties (~> 3.1.0)
+ coffee-script (2.2.0)
+ coffee-script-source
+ execjs
+ coffee-script-source (1.1.2)
+ diff-lcs (1.1.3)
+ erubis (2.7.0)
+ execjs (1.2.8)
+ multi_json (~> 1.0)
+ factory_girl (2.1.2)
+ activesupport
+ factory_girl_rails (1.2.0)
+ factory_girl (~> 2.1.0)
+ railties (>= 3.0.0)
+ ffi (1.0.9)
+ guard (0.7.0)
+ thor (~> 0.14.6)
+ guard-rspec (0.4.5)
+ guard (>= 0.4.0)
+ guard-spork (0.2.1)
+ guard (>= 0.2.2)
+ spork (>= 0.8.4)
+ hike (1.2.1)
+ i18n (0.6.0)
+ jquery-rails (1.0.14)
+ railties (~> 3.0)
+ thor (~> 0.14)
+ json_pure (1.6.1)
+ mail (2.3.0)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.16)
+ multi_json (1.0.3)
+ nokogiri (1.5.0)
+ polyglot (0.3.2)
+ rack (1.3.3)
+ rack-cache (1.0.3)
+ rack (>= 0.4)
+ rack-mount (0.8.3)
+ rack (>= 1.0.0)
+ rack-ssl (1.3.2)
+ rack
+ rack-test (0.6.1)
+ rack (>= 1.0)
+ rails (3.1.0)
+ actionmailer (= 3.1.0)
+ actionpack (= 3.1.0)
+ activerecord (= 3.1.0)
+ activeresource (= 3.1.0)
+ activesupport (= 3.1.0)
+ bundler (~> 1.0)
+ railties (= 3.1.0)
+ railties (3.1.0)
+ actionpack (= 3.1.0)
+ activesupport (= 3.1.0)
+ rack-ssl (~> 1.3.2)
+ rake (>= 0.8.7)
+ rdoc (~> 3.4)
+ thor (~> 0.14.6)
+ rake (0.9.2)
+ rdoc (3.9.4)
+ rspec (2.6.0)
+ rspec-core (~> 2.6.0)
+ rspec-expectations (~> 2.6.0)
+ rspec-mocks (~> 2.6.0)
+ rspec-core (2.6.4)
+ rspec-expectations (2.6.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.6.0)
+ rspec-rails (2.6.1)
+ actionpack (~> 3.0)
+ activesupport (~> 3.0)
+ railties (~> 3.0)
+ rspec (~> 2.6.0)
+ rubyzip (0.9.4)
+ sass (3.1.7)
+ sass-rails (3.1.2)
+ actionpack (~> 3.1.0)
+ railties (~> 3.1.0)
+ sass (>= 3.1.4)
+ sprockets (~> 2.0.0)
+ tilt (~> 1.3.2)
+ selenium-webdriver (2.7.0)
+ childprocess (>= 0.2.1)
+ ffi (>= 1.0.7)
+ json_pure
+ rubyzip
+ spork (0.9.0.rc9)
+ sprockets (2.0.0)
+ hike (~> 1.2)
+ rack (~> 1.0)
+ tilt (!= 1.3.0, ~> 1.1)
+ sqlite3 (1.3.4)
+ thor (0.14.6)
+ tilt (1.3.3)
+ treetop (1.4.10)
+ polyglot
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.29)
+ uglifier (1.0.3)
+ execjs (>= 0.3.0)
+ multi_json (>= 1.0.2)
+ xpath (0.1.4)
+ nokogiri (~> 1.3)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ capybara
+ coffee-rails (~> 3.1.0)
+ factory_girl_rails
+ guard-rspec
+ guard-spork
+ jquery-rails
+ rails (= 3.1.0)
+ rspec-rails
+ sass-rails (~> 3.1.0)
+ spork (> 0.9.0.rc)
+ sqlite3
+ uglifier
View
26 episode-285/auth-after/Guardfile
@@ -0,0 +1,26 @@
+guard 'spork', :cucumber_env => { 'RAILS_ENV' => 'test' }, :rspec_env => { 'RAILS_ENV' => 'test' } do
+ watch('config/application.rb')
+ watch('config/environment.rb')
+ watch(%r{^config/environments/.+\.rb$})
+ watch(%r{^config/initializers/.+\.rb$})
+ watch('spec/spec_helper.rb')
+ watch(%r{^spec/support/.+\.rb$})
+end
+
+guard 'rspec', :version => 2, :cli => "--drb", :all_on_start => false, :all_after_pass => false do
+ watch(%r{^spec/.+_spec\.rb$})
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
+ watch('spec/spec_helper.rb') { "spec" }
+
+ # Rails example
+ watch(%r{^spec/.+_spec\.rb$})
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
+ watch('spec/spec_helper.rb') { "spec" }
+ watch('config/routes.rb') { "spec/routing" }
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
+ # Capybara request specs
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
+end
View
7 episode-285/auth-after/README
@@ -0,0 +1,7 @@
+= RailsCasts Example Application
+
+Run these commands to try it out.
+
+ bundle
+ rake db:migrate
+ rails s
View
7 episode-285/auth-after/Rakefile
@@ -0,0 +1,7 @@
+#!/usr/bin/env rake
+# Add your own tasks in files placed in lib/tasks ending in .rake,
+# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
+
+require File.expand_path('../config/application', __FILE__)
+
+Auth::Application.load_tasks
View
BIN  episode-285/auth-after/app/assets/images/rails.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
9 episode-285/auth-after/app/assets/javascripts/application.js
@@ -0,0 +1,9 @@
+// This is a manifest file that'll be compiled into including all the files listed below.
+// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
+// be included in the compiled file accessible from http://example.com/assets/application.js
+// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
+// the compiled file.
+//
+//= require jquery
+//= require jquery_ujs
+//= require_tree .
View
3  episode-285/auth-after/app/assets/javascripts/home.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
View
3  episode-285/auth-after/app/assets/javascripts/password_resets.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
View
3  episode-285/auth-after/app/assets/javascripts/sessions.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
View
3  episode-285/auth-after/app/assets/javascripts/users.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
View
91 episode-285/auth-after/app/assets/stylesheets/application.css
@@ -0,0 +1,91 @@
+/*
+ * This is a manifest file that'll automatically include all the stylesheets available in this directory
+ * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
+ * the top of the compiled file, but it's generally better to create a new file per style scope.
+ *= require_self
+ *= require_tree .
+*/
+
+html, body {
+ background-color: #4B7399;
+ font-family: Verdana, Helvetica, Arial;
+ font-size: 14px;
+}
+
+a img {
+ border: none;
+}
+
+a {
+ color: #0000FF;
+}
+
+.clear {
+ clear: both;
+ height: 0;
+ overflow: hidden;
+}
+
+#container {
+ width: 75%;
+ margin: 0 auto;
+ background-color: #FFF;
+ padding: 20px 40px;
+ border: solid 1px black;
+ margin-top: 20px;
+}
+
+#flash_notice, #flash_error, #flash_alert {
+ padding: 5px 8px;
+ margin: 10px 0;
+}
+
+#flash_notice {
+ background-color: #CFC;
+ border: solid 1px #6C6;
+}
+
+#flash_error, #flash_alert {
+ background-color: #FCC;
+ border: solid 1px #C66;
+}
+
+form label {
+ display: block;
+ margin-bottom: 2px;
+}
+
+form .field, form .actions {
+ margin: 12px 0;
+}
+
+.fieldWithErrors {
+ display: inline;
+}
+
+.error_messages {
+ width: 400px;
+ border: 2px solid #CF0000;
+ padding: 0px;
+ margin-bottom: 20px;
+ background-color: #f0f0f0;
+ font-size: 12px;
+}
+
+.error_messages h2 {
+ text-align: left;
+ font-weight: bold;
+ padding: 5px 10px;
+ font-size: 12px;
+ margin: 0;
+ background-color: #c00;
+ color: #fff;
+}
+
+.error_messages p {
+ margin: 8px 10px;
+}
+
+.error_messages ul {
+ margin: 15px 0;
+}
View
7 episode-285/auth-after/app/assets/stylesheets/home.css.scss
@@ -0,0 +1,7 @@
+// Place all the styles related to the home controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
+
+body.home {
+ // Place scoped styles here
+}
View
7 episode-285/auth-after/app/assets/stylesheets/password_resets.css.scss
@@ -0,0 +1,7 @@
+// Place all the styles related to the password_resets controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
+
+body.password-resets {
+ // Place scoped styles here
+}
View
7 episode-285/auth-after/app/assets/stylesheets/sessions.css.scss
@@ -0,0 +1,7 @@
+// Place all the styles related to the sessions controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
+
+body.sessions {
+ // Place scoped styles here
+}
View
7 episode-285/auth-after/app/assets/stylesheets/users.css.scss
@@ -0,0 +1,7 @@
+// Place all the styles related to the users controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
+
+body.users {
+ // Place scoped styles here
+}
View
10 episode-285/auth-after/app/controllers/application_controller.rb
@@ -0,0 +1,10 @@
+class ApplicationController < ActionController::Base
+ protect_from_forgery
+
+ private
+
+ def current_user
+ @current_user ||= User.find(session[:user_id]) if session[:user_id]
+ end
+ helper_method :current_user
+end
View
4 episode-285/auth-after/app/controllers/home_controller.rb
@@ -0,0 +1,4 @@
+class HomeController < ApplicationController
+ def index
+ end
+end
View
25 episode-285/auth-after/app/controllers/password_resets_controller.rb
@@ -0,0 +1,25 @@
+class PasswordResetsController < ApplicationController
+ def new
+ end
+
+ def create
+ user = User.find_by_email(params[:email])
+ user.send_password_reset if user
+ redirect_to root_url, :notice => "Email sent with password reset instructions."
+ end
+
+ def edit
+ @user = User.find_by_password_reset_token!(params[:id])
+ end
+
+ def update
+ @user = User.find_by_password_reset_token!(params[:id])
+ if @user.password_reset_sent_at < 2.hours.ago
+ redirect_to new_password_reset_path, :alert => "Password reset has expired."
+ elsif @user.update_attributes(params[:user])
+ redirect_to root_url, :notice => "Password has been reset!"
+ else
+ render :edit
+ end
+ end
+end
View
20 episode-285/auth-after/app/controllers/sessions_controller.rb
@@ -0,0 +1,20 @@
+class SessionsController < ApplicationController
+ def new
+ end
+
+ def create
+ user = User.find_by_email(params[:email])
+ if user && user.authenticate(params[:password])
+ session[:user_id] = user.id
+ redirect_to root_url, :notice => "Logged in!"
+ else
+ flash.now.alert = "Invalid email or password"
+ render "new"
+ end
+ end
+
+ def destroy
+ session[:user_id] = nil
+ redirect_to root_url, :notice => "Logged out!"
+ end
+end
View
14 episode-285/auth-after/app/controllers/users_controller.rb
@@ -0,0 +1,14 @@
+class UsersController < ApplicationController
+ def new
+ @user = User.new
+ end
+
+ def create
+ @user = User.new(params[:user])
+ if @user.save
+ redirect_to root_url, :notice => "Signed up!"
+ else
+ render "new"
+ end
+ end
+end
View
2  episode-285/auth-after/app/helpers/application_helper.rb
@@ -0,0 +1,2 @@
+module ApplicationHelper
+end
View
2  episode-285/auth-after/app/helpers/home_helper.rb
@@ -0,0 +1,2 @@
+module HomeHelper
+end
View
2  episode-285/auth-after/app/helpers/password_resets_helper.rb
@@ -0,0 +1,2 @@
+module PasswordResetsHelper
+end
View
2  episode-285/auth-after/app/helpers/sessions_helper.rb
@@ -0,0 +1,2 @@
+module SessionsHelper
+end
View
2  episode-285/auth-after/app/helpers/users_helper.rb
@@ -0,0 +1,2 @@
+module UsersHelper
+end
View
0  episode-285/auth-after/app/mailers/.gitkeep
No changes.
View
8 episode-285/auth-after/app/mailers/user_mailer.rb
@@ -0,0 +1,8 @@
+class UserMailer < ActionMailer::Base
+ default from: "from@example.com"
+
+ def password_reset(user)
+ @user = user
+ mail :to => user.email, :subject => "Password Reset"
+ end
+end
View
0  episode-285/auth-after/app/models/.gitkeep
No changes.
View
18 episode-285/auth-after/app/models/user.rb
@@ -0,0 +1,18 @@
+class User < ActiveRecord::Base
+ attr_accessible :email, :password, :password_confirmation
+ has_secure_password
+ validates_presence_of :password, :on => :create
+
+ def send_password_reset
+ generate_token(:password_reset_token)
+ self.password_reset_sent_at = Time.zone.now
+ save!
+ UserMailer.password_reset(self).deliver
+ end
+
+ def generate_token(column)
+ begin
+ self[column] = SecureRandom.urlsafe_base64
+ end while User.exists?(column => self[column])
+ end
+end
View
3  episode-285/auth-after/app/views/home/index.html.erb
@@ -0,0 +1,3 @@
+<h1>Welcome</h1>
+
+<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
View
26 episode-285/auth-after/app/views/layouts/application.html.erb
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Auth Example</title>
+ <%= stylesheet_link_tag "application" %>
+ <%= javascript_include_tag "application" %>
+ <%= csrf_meta_tags %>
+</head>
+<body>
+ <div id="container">
+ <div id="user_nav">
+ <% if current_user %>
+ Logged in as <%= current_user.email %>.
+ <%= link_to "Log out", logout_path %>
+ <% else %>
+ <%= link_to "Sign up", signup_path %> or
+ <%= link_to "log in", login_path %>
+ <% end %>
+ </div>
+ <% flash.each do |name, msg| %>
+ <%= content_tag :div, msg, :id => "flash_#{name}" %>
+ <% end %>
+ <%= yield %>
+ </div>
+</body>
+</html>
View
23 episode-285/auth-after/app/views/password_resets/edit.html.erb
@@ -0,0 +1,23 @@
+<h1>Reset Password</h1>
+
+<%= form_for @user, :url => password_reset_path(params[:id]) do |f| %>
+ <% if @user.errors.any? %>
+ <div class="error_messages">
+ <h2>Form is invalid</h2>
+ <ul>
+ <% for message in @user.errors.full_messages %>
+ <li><%= message %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+ <div class="field">
+ <%= f.label :password %>
+ <%= f.password_field :password %>
+ </div>
+ <div class="field">
+ <%= f.label :password_confirmation %>
+ <%= f.password_field :password_confirmation %>
+ </div>
+ <div class="actions"><%= f.submit "Update Password" %></div>
+<% end %>
View
7 episode-285/auth-after/app/views/password_resets/new.html.erb
@@ -0,0 +1,7 @@
+<%= form_tag password_resets_path, :method => :post do %>
+ <div class="field">
+ <%= label_tag :email %>
+ <%= text_field_tag :email, params[:email] %>
+ </div>
+ <div class="actions"><%= submit_tag "Reset Password" %></div>
+<% end %>
View
14 episode-285/auth-after/app/views/sessions/new.html.erb
@@ -0,0 +1,14 @@
+<h1>Log in</h1>
+
+<%= form_tag sessions_path do %>
+ <div class="field">
+ <%= label_tag :email %>
+ <%= text_field_tag :email, params[:email] %>
+ </div>
+ <div class="field">
+ <%= label_tag :password %>
+ <%= password_field_tag :password %>
+ </div>
+ <p><%= link_to "forgotten password?", new_password_reset_path %></p>
+ <div class="actions"><%= submit_tag "Log in" %></div>
+<% end %>
View
5 episode-285/auth-after/app/views/user_mailer/password_reset.text.erb
@@ -0,0 +1,5 @@
+To reset your password, click the URL below.
+
+<%= edit_password_reset_url(@user.password_reset_token) %>
+
+If you did not request your password to be reset, just ignore this email and your password will continue to stay the same.
View
27 episode-285/auth-after/app/views/users/new.html.erb
@@ -0,0 +1,27 @@
+<h1>Sign Up</h1>
+
+<%= form_for @user do |f| %>
+ <% if @user.errors.any? %>
+ <div class="error_messages">
+ <h2>Form is invalid</h2>
+ <ul>
+ <% for message in @user.errors.full_messages %>
+ <li><%= message %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+ <div class="field">
+ <%= f.label :email %>
+ <%= f.text_field :email %>
+ </div>
+ <div class="field">
+ <%= f.label :password %>
+ <%= f.password_field :password %>
+ </div>
+ <div class="field">
+ <%= f.label :password_confirmation %>
+ <%= f.password_field :password_confirmation %>
+ </div>
+ <div class="actions"><%= f.submit %></div>
+<% end %>
View
4 episode-285/auth-after/config.ru
@@ -0,0 +1,4 @@
+# This file is used by Rack-based servers to start the application.
+
+require ::File.expand_path('../config/environment', __FILE__)
+run Auth::Application
View
45 episode-285/auth-after/config/application.rb
@@ -0,0 +1,45 @@
+require File.expand_path('../boot', __FILE__)
+
+require 'rails/all'
+
+if defined?(Bundler)
+ # If you precompile assets before deploying to production, use this line
+ Bundler.require *Rails.groups(:assets => %w(development test))
+ # If you want your assets lazily compiled in production, use this line
+ # Bundler.require(:default, :assets, Rails.env)
+end
+
+module Auth
+ class Application < Rails::Application
+ # Settings in config/environments/* take precedence over those specified here.
+ # Application configuration should go into files in config/initializers
+ # -- all .rb files in that directory are automatically loaded.
+
+ # Custom directories with classes and modules you want to be autoloadable.
+ # config.autoload_paths += %W(#{config.root}/extras)
+
+ # Only load the plugins named here, in the order given (default is alphabetical).
+ # :all can be used as a placeholder for all plugins not explicitly named.
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
+
+ # Activate observers that should always be running.
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
+
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
+ # config.time_zone = 'Central Time (US & Canada)'
+
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
+ # config.i18n.default_locale = :de
+
+ # Configure the default encoding used in templates for Ruby 1.9.
+ config.encoding = "utf-8"
+
+ # Enable the asset pipeline
+ config.assets.enabled = true
+
+ # Version of your assets, change this if you want to expire all your assets
+ config.assets.version = '1.0'
+ end
+end
View
6 episode-285/auth-after/config/boot.rb
@@ -0,0 +1,6 @@
+require 'rubygems'
+
+# Set up gems listed in the Gemfile.
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
+
+require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
View
25 episode-285/auth-after/config/database.yml
@@ -0,0 +1,25 @@
+# SQLite version 3.x
+# gem install sqlite3
+#
+# Ensure the SQLite 3 gem is defined in your Gemfile
+# gem 'sqlite3'
+development:
+ adapter: sqlite3
+ database: db/development.sqlite3
+ pool: 5
+ timeout: 5000
+
+# Warning: The database defined as "test" will be erased and
+# re-generated from your development database when you run "rake".
+# Do not set this db to the same as development or production.
+test:
+ adapter: sqlite3
+ database: db/test.sqlite3
+ pool: 5
+ timeout: 5000
+
+production:
+ adapter: sqlite3
+ database: db/production.sqlite3
+ pool: 5
+ timeout: 5000
View
5 episode-285/auth-after/config/environment.rb
@@ -0,0 +1,5 @@
+# Load the rails application
+require File.expand_path('../application', __FILE__)
+
+# Initialize the rails application
+Auth::Application.initialize!
View
32 episode-285/auth-after/config/environments/development.rb
@@ -0,0 +1,32 @@
+Auth::Application.configure do
+ # Settings specified here will take precedence over those in config/application.rb
+
+ # In the development environment your application's code is reloaded on
+ # every request. This slows down response time but is perfect for development
+ # since you don't have to restart the web server when you make code changes.
+ config.cache_classes = false
+
+ # Log error messages when you accidentally call methods on nil.
+ config.whiny_nils = true
+
+ # Show full error reports and disable caching
+ config.consider_all_requests_local = true
+ config.action_controller.perform_caching = false
+
+ # Don't care if the mailer can't send
+ config.action_mailer.raise_delivery_errors = false
+
+ # Print deprecation notices to the Rails logger
+ config.active_support.deprecation = :log
+
+ # Only use best-standards-support built into browsers
+ config.action_dispatch.best_standards_support = :builtin
+
+ # Do not compress assets
+ config.assets.compress = false
+
+ # Expands the lines which load the assets
+ config.assets.debug = true
+
+ config.action_mailer.default_url_options = { :host => "localhost:3000" }
+end
View
54 episode-285/auth-after/config/environments/production.rb
@@ -0,0 +1,54 @@
+Auth::Application.configure do
+ # Settings specified here will take precedence over those in config/application.rb
+
+ # Code is not reloaded between requests
+ config.cache_classes = true
+
+ # Full error reports are disabled and caching is turned on
+ config.consider_all_requests_local = false
+ config.action_controller.perform_caching = true
+
+ # Compress JavaScripts and CSS
+ config.assets.compress = true
+
+ # Don't fallback to assets pipeline if a precompiled asset is missed
+ config.assets.compile = false
+
+ # Generate digests for assets URLs
+ config.assets.digest = true
+
+ # Specifies the header that your server uses for sending files
+ # (comment out if your front-end server doesn't support this)
+ config.action_dispatch.x_sendfile_header = "X-Sendfile" # Use 'X-Accel-Redirect' for nginx
+
+ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
+ # config.force_ssl = true
+
+ # See everything in the log (default is :info)
+ # config.log_level = :debug
+
+ # Use a different logger for distributed setups
+ # config.logger = SyslogLogger.new
+
+ # Use a different cache store in production
+ # config.cache_store = :mem_cache_store
+
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server
+ # config.action_controller.asset_host = "http://assets.example.com"
+
+ # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
+ # config.assets.precompile += %w( search.js )
+
+ # Disable delivery errors, bad email addresses will be ignored
+ # config.action_mailer.raise_delivery_errors = false
+
+ # Enable threaded mode
+ # config.threadsafe!
+
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
+ # the I18n.default_locale when a translation can not be found)
+ config.i18n.fallbacks = true
+
+ # Send deprecation notices to registered listeners
+ config.active_support.deprecation = :notify
+end
View
41 episode-285/auth-after/config/environments/test.rb
@@ -0,0 +1,41 @@
+Auth::Application.configure do
+ # Settings specified here will take precedence over those in config/application.rb
+
+ # The test environment is used exclusively to run your application's
+ # test suite. You never need to work with it otherwise. Remember that
+ # your test database is "scratch space" for the test suite and is wiped
+ # and recreated between test runs. Don't rely on the data there!
+ config.cache_classes = true
+
+ # Configure static asset server for tests with Cache-Control for performance
+ config.serve_static_assets = true
+ config.static_cache_control = "public, max-age=3600"
+
+ # Log error messages when you accidentally call methods on nil
+ config.whiny_nils = true
+
+ # Show full error reports and disable caching
+ config.consider_all_requests_local = true
+ config.action_controller.perform_caching = false
+
+ # Raise exceptions instead of rendering exception templates
+ config.action_dispatch.show_exceptions = false
+
+ # Disable request forgery protection in test environment
+ config.action_controller.allow_forgery_protection = false
+
+ # Tell Action Mailer not to deliver emails to the real world.
+ # The :test delivery method accumulates sent emails in the
+ # ActionMailer::Base.deliveries array.
+ config.action_mailer.delivery_method = :test
+
+ # Use SQL instead of Active Record's schema dumper when creating the test database.
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
+ # like if you have constraints or database-specific column types
+ # config.active_record.schema_format = :sql
+
+ # Print deprecation notices to the stderr
+ config.active_support.deprecation = :stderr
+
+ config.action_mailer.default_url_options = { :host => "www.example.com" }
+end
View
7 episode-285/auth-after/config/initializers/backtrace_silencers.rb
@@ -0,0 +1,7 @@
+# Be sure to restart your server when you modify this file.
+
+# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
+# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
+
+# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
+# Rails.backtrace_cleaner.remove_silencers!
View
10 episode-285/auth-after/config/initializers/inflections.rb
@@ -0,0 +1,10 @@
+# Be sure to restart your server when you modify this file.
+
+# Add new inflection rules using the following format
+# (all these examples are active by default):
+# ActiveSupport::Inflector.inflections do |inflect|
+# inflect.plural /^(ox)$/i, '\1en'
+# inflect.singular /^(ox)en/i, '\1'
+# inflect.irregular 'person', 'people'
+# inflect.uncountable %w( fish sheep )
+# end
View
5 episode-285/auth-after/config/initializers/mime_types.rb
@@ -0,0 +1,5 @@
+# Be sure to restart your server when you modify this file.
+
+# Add new mime types for use in respond_to blocks:
+# Mime::Type.register "text/richtext", :rtf
+# Mime::Type.register_alias "text/html", :iphone
View
7 episode-285/auth-after/config/initializers/secret_token.rb
@@ -0,0 +1,7 @@
+# Be sure to restart your server when you modify this file.
+
+# Your secret key for verifying the integrity of signed cookies.
+# If you change this key, all old signed cookies will become invalid!
+# Make sure the secret is at least 30 characters and all random,
+# no regular words or you'll be exposed to dictionary attacks.
+Auth::Application.config.secret_token = '974bcaccc646dc39283570007277652121e461b4427c0bfbe9aaa893e11f28b850d684ad1bf469d2e3b663692a84a74d1919ab5f49c20bc0c413e5bbcda0f416'
View
8 episode-285/auth-after/config/initializers/session_store.rb
@@ -0,0 +1,8 @@
+# Be sure to restart your server when you modify this file.
+
+Auth::Application.config.session_store :cookie_store, key: '_auth_session'
+
+# Use the database for sessions instead of the cookie-based default,
+# which shouldn't be used to store highly confidential information
+# (create the session table with "rails generate session_migration")
+# Auth::Application.config.session_store :active_record_store
View
12 episode-285/auth-after/config/initializers/wrap_parameters.rb
@@ -0,0 +1,12 @@
+# Be sure to restart your server when you modify this file.
+#
+# This file contains settings for ActionController::ParamsWrapper which
+# is enabled by default.
+
+# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
+ActionController::Base.wrap_parameters format: [:json]
+
+# Disable root element in JSON by default.
+if defined?(ActiveRecord)
+ ActiveRecord::Base.include_root_in_json = false
+end
View
5 episode-285/auth-after/config/locales/en.yml
@@ -0,0 +1,5 @@
+# Sample localization file for English. Add more files in this directory for other locales.
+# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
+
+en:
+ hello: "Hello world"
View
9 episode-285/auth-after/config/routes.rb
@@ -0,0 +1,9 @@
+Auth::Application.routes.draw do
+ get "logout" => "sessions#destroy", :as => "logout"
+ get "login" => "sessions#new", :as => "login"
+ get "signup" => "users#new", :as => "signup"
+ root :to => "home#index"
+ resources :users
+ resources :sessions
+ resources :password_resets
+end
View
10 episode-285/auth-after/db/migrate/20110613044221_create_users.rb
@@ -0,0 +1,10 @@
+class CreateUsers < ActiveRecord::Migration
+ def change
+ create_table :users do |t|
+ t.string :email
+ t.string :password_digest
+
+ t.timestamps
+ end
+ end
+end
View
6 episode-285/auth-after/db/migrate/20110718213551_add_password_reset_to_users.rb
@@ -0,0 +1,6 @@
+class AddPasswordResetToUsers < ActiveRecord::Migration
+ def change
+ add_column :users, :password_reset_token, :string
+ add_column :users, :password_reset_sent_at, :datetime
+ end
+end
View
24 episode-285/auth-after/db/schema.rb
@@ -0,0 +1,24 @@
+# This file is auto-generated from the current state of the database. Instead
+# of editing this file, please use the migrations feature of Active Record to
+# incrementally modify your database, and then regenerate this schema definition.
+#
+# Note that this schema.rb definition is the authoritative source for your
+# database schema. If you need to create the application database on another
+# system, you should be using db:schema:load, not running all the migrations
+# from scratch. The latter is a flawed and unsustainable approach (the more migrations
+# you'll amass, the slower it'll run and the greater likelihood for issues).
+#
+# It's strongly recommended to check this file into your version control system.
+
+ActiveRecord::Schema.define(:version => 20110718213551) do
+
+ create_table "users", :force => true do |t|
+ t.string "email"
+ t.string "password_digest"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ t.string "password_reset_token"
+ t.datetime "password_reset_sent_at"
+ end
+
+end
View
7 episode-285/auth-after/db/seeds.rb
@@ -0,0 +1,7 @@
+# This file should contain all the record creation needed to seed the database with its default values.
+# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
+#
+# Examples:
+#
+# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
+# Mayor.create(name: 'Emanuel', city: cities.first)
View
2  episode-285/auth-after/doc/README_FOR_APP
@@ -0,0 +1,2 @@
+Use this README file to introduce your application and point to useful places in the API for learning more.
+Run "rake doc:app" to generate API documentation for your models, controllers, helpers, and libraries.
View
0  episode-285/auth-after/lib/tasks/.gitkeep
No changes.
View
0  episode-285/auth-after/log/.gitkeep
No changes.
View
26 episode-285/auth-after/public/404.html
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>The page you were looking for doesn't exist (404)</title>
+ <style type="text/css">
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
+ div.dialog {
+ width: 25em;
+ padding: 0 4em;
+ margin: 4em auto 0 auto;
+ border: 1px solid #ccc;
+ border-right-color: #999;
+ border-bottom-color: #999;
+ }
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
+ </style>
+</head>
+
+<body>
+ <!-- This file lives in public/404.html -->
+ <div class="dialog">
+ <h1>The page you were looking for doesn't exist.</h1>
+ <p>You may have mistyped the address or the page may have moved.</p>
+ </div>
+</body>
+</html>
View
26 episode-285/auth-after/public/422.html
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>The change you wanted was rejected (422)</title>
+ <style type="text/css">
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
+ div.dialog {
+ width: 25em;
+ padding: 0 4em;
+ margin: 4em auto 0 auto;
+ border: 1px solid #ccc;
+ border-right-color: #999;
+ border-bottom-color: #999;
+ }
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
+ </style>
+</head>
+
+<body>
+ <!-- This file lives in public/422.html -->
+ <div class="dialog">
+ <h1>The change you wanted was rejected.</h1>
+ <p>Maybe you tried to change something you didn't have access to.</p>
+ </div>
+</body>
+</html>
View
26 episode-285/auth-after/public/500.html
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>We're sorry, but something went wrong (500)</title>
+ <style type="text/css">
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
+ div.dialog {
+ width: 25em;
+ padding: 0 4em;
+ margin: 4em auto 0 auto;
+ border: 1px solid #ccc;
+ border-right-color: #999;
+ border-bottom-color: #999;
+ }
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
+ </style>
+</head>
+
+<body>
+ <!-- This file lives in public/500.html -->
+ <div class="dialog">
+ <h1>We're sorry, but something went wrong.</h1>
+ <p>We've been notified about this issue and we'll take a look at it shortly.</p>
+ </div>
+</body>
+</html>
View
0  episode-285/auth-after/public/favicon.ico
No changes.
View
5 episode-285/auth-after/public/robots.txt
@@ -0,0 +1,5 @@
+# See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
+#
+# To ban all spiders from the entire site uncomment the next two lines:
+# User-Agent: *
+# Disallow: /
View
6 episode-285/auth-after/script/rails
@@ -0,0 +1,6 @@
+#!/usr/bin/env ruby
+# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
+
+APP_PATH = File.expand_path('../../config/application', __FILE__)
+require File.expand_path('../../config/boot', __FILE__)
+require 'rails/commands'
View
4 episode-285/auth-after/spec/factories.rb
@@ -0,0 +1,4 @@
+Factory.define :user do |f|
+ f.sequence(:email) { |n| "foo#{n}@example.com" }
+ f.password "secret"
+end
View
3  episode-285/auth-after/spec/fixtures/user_mailer/password_reset
@@ -0,0 +1,3 @@
+UserMailer#password_reset
+
+Hi, find me in app/views/user_mailer/password_reset
View
15 episode-285/auth-after/spec/mailers/user_mailer_spec.rb
@@ -0,0 +1,15 @@
+require "spec_helper"
+
+describe UserMailer do
+ describe "password_reset" do
+ let(:user) { Factory(:user, :password_reset_token => "anything") }
+ let(:mail) { UserMailer.password_reset(user) }
+
+ it "send user password reset url" do
+ mail.subject.should eq("Password Reset")
+ mail.to.should eq([user.email])
+ mail.from.should eq(["from@example.com"])
+ mail.body.encoded.should match(edit_password_reset_path(user.password_reset_token))
+ end
+ end
+end
View
24 episode-285/auth-after/spec/models/user_spec.rb
@@ -0,0 +1,24 @@
+require 'spec_helper'
+
+describe User do
+ describe "#send_password_reset" do
+ let(:user) { Factory(:user) }
+
+ it "generates a unique password_reset_token each time" do
+ user.send_password_reset
+ last_token = user.password_reset_token
+ user.send_password_reset
+ user.password_reset_token.should_not eq(last_token)
+ end
+
+ it "saves the time the password reset was sent" do
+ user.send_password_reset
+ user.reload.password_reset_sent_at.should be_present
+ end
+
+ it "delivers email to user" do
+ user.send_password_reset
+ last_email.to.should include(user.email)
+ end
+ end
+end
View
51 episode-285/auth-after/spec/requests/password_resets_spec.rb
@@ -0,0 +1,51 @@
+require 'spec_helper'
+
+describe "PasswordResets" do
+ it "emails user when requesting password reset" do
+ user = Factory(:user)
+ visit login_path
+ click_link "password"
+ fill_in "Email", :with => user.email
+ click_button "Reset Password"
+ current_path.should eq(root_path)
+ page.should have_content("Email sent")
+ last_email.to.should include(user.email)
+ end
+
+ it "does not email invalid user when requesting password reset" do
+ visit login_path
+ click_link "password"
+ fill_in "Email", :with => "nobody@example.com"
+ click_button "Reset Password"
+ current_path.should eq(root_path)
+ page.should have_content("Email sent")
+ last_email.should be_nil
+ end
+
+ it "updates the user password when confirmation matches" do
+ user = Factory(:user, :password_reset_token => "something", :password_reset_sent_at => 1.hour.ago)
+ visit edit_password_reset_path(user.password_reset_token)
+ fill_in "Password", :with => "foobar"
+ click_button "Update Password"
+ page.should have_content("Password doesn't match confirmation")
+ fill_in "Password", :with => "foobar"
+ fill_in "Password confirmation", :with => "foobar"
+ click_button "Update Password"
+ page.should have_content("Password has been reset")
+ end
+
+ it "reports when password token has expired" do
+ user = Factory(:user, :password_reset_token => "something", :password_reset_sent_at => 5.hour.ago)
+ visit edit_password_reset_path(user.password_reset_token)
+ fill_in "Password", :with => "foobar"
+ fill_in "Password confirmation", :with => "foobar"
+ click_button "Update Password"
+ page.should have_content("Password reset has expired")
+ end
+
+ it "raises record not found when password token is invalid" do
+ lambda {
+ visit edit_password_reset_path("invalid")
+ }.should raise_exception(ActiveRecord::RecordNotFound)
+ end
+end
View
64 episode-285/auth-after/spec/spec_helper.rb
@@ -0,0 +1,64 @@
+require 'rubygems'
+require 'spork'
+
+Spork.prefork do
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
+ ENV["RAILS_ENV"] ||= 'test'
+ require File.expand_path("../../config/environment", __FILE__)
+ require 'rspec/rails'
+ require 'capybara/rspec'
+
+ # Requires supporting ruby files with custom matchers and macros, etc,
+ # in spec/support/ and its subdirectories.
+ Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
+
+ RSpec.configure do |config|
+ config.mock_with :rspec
+ config.use_transactional_fixtures = true
+ config.include(MailerMacros)
+ config.before(:each) { reset_email }
+
+ config.treat_symbols_as_metadata_keys_with_true_values = true
+ config.filter_run :focus => true
+ config.run_all_when_everything_filtered = true
+ end
+end
+
+Spork.each_run do
+ # This code will be run each time you run your specs.
+ FactoryGirl.reload
+end
+
+# --- Instructions ---
+# Sort the contents of this file into a Spork.prefork and a Spork.each_run
+# block.
+#
+# The Spork.prefork block is run only once when the spork server is started.
+# You typically want to place most of your (slow) initializer code in here, in
+# particular, require'ing any 3rd-party gems that you don't normally modify
+# during development.
+#
+# The Spork.each_run block is run each time you run your specs. In case you
+# need to load files that tend to change during development, require them here.
+# With Rails, your application modules are loaded automatically, so sometimes
+# this block can remain empty.
+#
+# Note: You can modify files loaded *from* the Spork.each_run block without
+# restarting the spork server. However, this file itself will not be reloaded,
+# so if you change any of the code inside the each_run block, you still need to
+# restart the server. In general, if you have non-trivial code in this file,
+# it's advisable to move it into a separate file so you can easily edit it
+# without restarting spork. (For example, with RSpec, you could move
+# non-trivial code into a file spec/support/my_helper.rb, making sure that the
+# spec/support/* files are require'd from inside the each_run block.)
+#
+# Any code that is left outside the two blocks will be run during preforking
+# *and* during each_run -- that's probably not what you want.
+#
+# These instructions should self-destruct in 10 seconds. If they don't, feel
+# free to delete them.
+
+
+
+
+
View
9 episode-285/auth-after/spec/support/mailer_macros.rb
@@ -0,0 +1,9 @@
+module MailerMacros
+ def last_email
+ ActionMailer::Base.deliveries.last
+ end
+
+ def reset_email
+ ActionMailer::Base.deliveries = []
+ end
+end
View
0  episode-285/auth-after/vendor/assets/stylesheets/.gitkeep
No changes.
View
0  episode-285/auth-after/vendor/plugins/.gitkeep
No changes.
View
5 episode-285/auth-before/.gitignore
@@ -0,0 +1,5 @@
+.bundle
+db/*.sqlite3
+log/*.log
+tmp/
+.sass-cache/
View
1  episode-285/auth-before/.rspec
@@ -0,0 +1 @@
+--colour
View
34 episode-285/auth-before/Gemfile
@@ -0,0 +1,34 @@
+source 'http://rubygems.org'
+
+gem "rails", "3.1.0"
+
+# Bundle edge Rails instead:
+# gem 'rails', :git => 'git://github.com/rails/rails.git'
+
+gem 'sqlite3'
+
+# Gems used only for assets and not required
+# in production environments by default.
+group :assets do
+ gem 'sass-rails', " ~> 3.1.0"
+ gem 'coffee-rails', "~> 3.1.0"
+ gem 'uglifier'
+end
+
+gem 'jquery-rails'
+
+# Use unicorn as the web server
+# gem 'unicorn'
+
+# Deploy with Capistrano
+# gem 'capistrano'
+
+# To use debugger
+# gem 'ruby-debug19', :require => 'ruby-debug'
+
+gem "rspec-rails", :group => [:test, :development]
+group :test do
+ gem "factory_girl_rails"
+ gem "capybara"
+ gem "guard-rspec"
+end
View
162 episode-285/auth-before/Gemfile.lock
@@ -0,0 +1,162 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ actionmailer (3.1.0)
+ actionpack (= 3.1.0)
+ mail (~> 2.3.0)
+ actionpack (3.1.0)
+ activemodel (= 3.1.0)
+ activesupport (= 3.1.0)
+ builder (~> 3.0.0)
+ erubis (~> 2.7.0)
+ i18n (~> 0.6)
+ rack (~> 1.3.2)
+ rack-cache (~> 1.0.3)
+ rack-mount (~> 0.8.2)
+ rack-test (~> 0.6.1)
+ sprockets (~> 2.0.0)
+ activemodel (3.1.0)
+ activesupport (= 3.1.0)
+ bcrypt-ruby (~> 3.0.0)
+ builder (~> 3.0.0)
+ i18n (~> 0.6)
+ activerecord (3.1.0)
+ activemodel (= 3.1.0)
+ activesupport (= 3.1.0)
+ arel (~> 2.2.1)
+ tzinfo (~> 0.3.29)
+ activeresource (3.1.0)
+ activemodel (= 3.1.0)
+ activesupport (= 3.1.0)
+ activesupport (3.1.0)
+ multi_json (~> 1.0)
+ arel (2.2.1)
+ bcrypt-ruby (3.0.1)
+ builder (3.0.0)
+ capybara (1.1.1)
+ mime-types (>= 1.16)
+ nokogiri (>= 1.3.3)
+ rack (>= 1.0.0)
+ rack-test (>= 0.5.4)
+ selenium-webdriver (~> 2.0)
+ xpath (~> 0.1.4)
+ childprocess (0.2.2)
+ ffi (~> 1.0.6)
+ coffee-rails (3.1.1)
+ coffee-script (>= 2.2.0)
+ railties (~> 3.1.0)
+ coffee-script (2.2.0)
+ coffee-script-source
+ execjs
+ coffee-script-source (1.1.2)
+ diff-lcs (1.1.3)
+ erubis (2.7.0)
+ execjs (1.2.8)
+ multi_json (~> 1.0)
+ factory_girl (2.1.2)
+ activesupport
+ factory_girl_rails (1.2.0)
+ factory_girl (~> 2.1.0)
+ railties (>= 3.0.0)
+ ffi (1.0.9)
+ guard (0.7.0)
+ thor (~> 0.14.6)
+ guard-rspec (0.4.5)
+ guard (>= 0.4.0)
+ hike (1.2.1)
+ i18n (0.6.0)
+ jquery-rails (1.0.14)
+ railties (~> 3.0)
+ thor (~> 0.14)
+ json_pure (1.6.1)
+ mail (2.3.0)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.16)
+ multi_json (1.0.3)
+ nokogiri (1.5.0)
+ polyglot (0.3.2)
+ rack (1.3.3)
+ rack-cache (1.0.3)
+ rack (>= 0.4)
+ rack-mount (0.8.3)
+ rack (>= 1.0.0)
+ rack-ssl (1.3.2)
+ rack
+ rack-test (0.6.1)
+ rack (>= 1.0)
+ rails (3.1.0)
+ actionmailer (= 3.1.0)
+ actionpack (= 3.1.0)
+ activerecord (= 3.1.0)
+ activeresource (= 3.1.0)
+ activesupport (= 3.1.0)
+ bundler (~> 1.0)
+ railties (= 3.1.0)
+ railties (3.1.0)
+ actionpack (= 3.1.0)
+ activesupport (= 3.1.0)
+ rack-ssl (~> 1.3.2)
+ rake (>= 0.8.7)
+ rdoc (~> 3.4)
+ thor (~> 0.14.6)
+ rake (0.9.2)
+ rdoc (3.9.4)
+ rspec (2.6.0)
+ rspec-core (~> 2.6.0)
+ rspec-expectations (~> 2.6.0)
+ rspec-mocks (~> 2.6.0)
+ rspec-core (2.6.4)
+ rspec-expectations (2.6.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.6.0)
+ rspec-rails (2.6.1)
+ actionpack (~> 3.0)
+ activesupport (~> 3.0)
+ railties (~> 3.0)
+ rspec (~> 2.6.0)
+ rubyzip (0.9.4)
+ sass (3.1.7)
+ sass-rails (3.1.2)
+ actionpack (~> 3.1.0)
+ railties (~> 3.1.0)
+ sass (>= 3.1.4)
+ sprockets (~> 2.0.0)
+ tilt (~> 1.3.2)
+ selenium-webdriver (2.7.0)
+ childprocess (>= 0.2.1)
+ ffi (>= 1.0.7)
+ json_pure
+ rubyzip
+ sprockets (2.0.0)
+ hike (~> 1.2)
+ rack (~> 1.0)
+ tilt (!= 1.3.0, ~> 1.1)
+ sqlite3 (1.3.4)
+ thor (0.14.6)
+ tilt (1.3.3)
+ treetop (1.4.10)
+ polyglot
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.29)
+ uglifier (1.0.3)
+ execjs (>= 0.3.0)
+ multi_json (>= 1.0.2)
+ xpath (0.1.4)
+ nokogiri (~> 1.3)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ capybara
+ coffee-rails (~> 3.1.0)
+ factory_girl_rails
+ guard-rspec
+ jquery-rails
+ rails (= 3.1.0)
+ rspec-rails
+ sass-rails (~> 3.1.0)
+ sqlite3
+ uglifier
View
20 episode-285/auth-before/Guardfile
@@ -0,0 +1,20 @@
+# A sample Guardfile
+# More info at https://github.com/guard/guard#readme
+
+guard 'rspec', :version => 2 do
+ watch(%r{^spec/.+_spec\.rb$})
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
+ watch('spec/spec_helper.rb') { "spec" }
+
+ # Rails example
+ watch(%r{^spec/.+_spec\.rb$})
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
+ watch('spec/spec_helper.rb') { "spec" }
+ watch('config/routes.rb') { "spec/routing" }
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
+ # Capybara request specs
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
+end
View
7 episode-285/auth-before/README
@@ -0,0 +1,7 @@
+= RailsCasts Example Application
+
+Run these commands to try it out.
+
+ bundle
+ rake db:migrate
+ rails s
View
7 episode-285/auth-before/Rakefile
@@ -0,0 +1,7 @@
+#!/usr/bin/env rake
+# Add your own tasks in files placed in lib/tasks ending in .rake,
+# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
+
+require File.expand_path('../config/application', __FILE__)
+
+Auth::Application.load_tasks
View
BIN  episode-285/auth-before/app/assets/images/rails.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
9 episode-285/auth-before/app/assets/javascripts/application.js
@@ -0,0 +1,9 @@
+// This is a manifest file that'll be compiled into including all the files listed below.
+// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
+// be included in the compiled file accessible from http://example.com/assets/application.js
+// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
+// the compiled file.
+//
+//= require jquery
+//= require jquery_ujs
+//= require_tree .
View
3  episode-285/auth-before/app/assets/javascripts/home.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
View
3  episode-285/auth-before/app/assets/javascripts/password_resets.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
View
3  episode-285/auth-before/app/assets/javascripts/sessions.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
View
3  episode-285/auth-before/app/assets/javascripts/users.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
View
91 episode-285/auth-before/app/assets/stylesheets/application.css
@@ -0,0 +1,91 @@
+/*
+ * This is a manifest file that'll automatically include all the stylesheets available in this directory
+ * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
+ * the top of the compiled file, but it's generally better to create a new file per style scope.
+ *= require_self
+ *= require_tree .
+*/
+
+html, body {
+ background-color: #4B7399;
+ font-family: Verdana, Helvetica, Arial;
+ font-size: 14px;
+}
+
+a img {
+ border: none;
+}
+
+a {
+ color: #0000FF;
+}
+
+.clear {
+ clear: both;
+ height: 0;
+ overflow: hidden;
+}
+
+#container {
+ width: 75%;
+ margin: 0 auto;
+ background-color: #FFF;
+ padding: 20px 40px;
+ border: solid 1px black;
+ margin-top: 20px;
+}
+
+#flash_notice, #flash_error, #flash_alert {
+ padding: 5px 8px;
+ margin: 10px 0;
+}
+
+#flash_notice {
+ background-color: #CFC;
+ border: solid 1px #6C6;
+}
+
+#flash_error, #flash_alert {
+ background-color: #FCC;
+ border: solid 1px #C66;
+}
+
+form label {
+ display: block;
+ margin-bottom: 2px;
+}
+
+form .field, form .actions {
+ margin: 12px 0;
+}
+
+.fieldWithErrors {
+ display: inline;
+}
+
+.error_messages {
+ width: 400px;
+ border: 2px solid #CF0000;
+ padding: 0px;
+ margin-bottom: 20px;
+ background-color: #f0f0f0;
+ font-size: 12px;
+}
+
+.error_messages h2 {
+ text-align: left;
+ font-weight: bold;
+ padding: 5px 10px;
+ font-size: 12px;
+ margin: 0;
+ background-color: #c00;
+ color: #fff;
+}
+
+.error_messages p {
+ margin: 8px 10px;
+}
+
+.error_messages ul {
+ margin: 15px 0;
+}
View
7 episode-285/auth-before/app/assets/stylesheets/home.css.scss
@@ -0,0 +1,7 @@
+// Place all the styles related to the home controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
+
+body.home {
+ // Place scoped styles here
+}
View
7 episode-285/auth-before/app/assets/stylesheets/password_resets.css.scss
@@ -0,0 +1,7 @@
+// Place all the styles related to the password_resets controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
+
+body.password-resets {
+ // Place scoped styles here
+}
View
7 episode-285/auth-before/app/assets/stylesheets/sessions.css.scss
@@ -0,0 +1,7 @@
+// Place all the styles related to the sessions controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
+
+body.sessions {
+ // Place scoped styles here
+}
View
7 episode-285/auth-before/app/assets/stylesheets/users.css.scss
@@ -0,0 +1,7 @@
+// Place all the styles related to the users controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
+
+body.users {
+ // Place scoped styles here
+}
View
10 episode-285/auth-before/app/controllers/application_controller.rb
@@ -0,0 +1,10 @@
+class ApplicationController < ActionController::Base
+ protect_from_forgery
+
+ private
+
+ def current_user
+ @current_user ||= User.find(session[:user_id]) if session[:user_id]
+ end
+ helper_method :current_user
+end
View
4 episode-285/auth-before/app/controllers/home_controller.rb
@@ -0,0 +1,4 @@
+class HomeController < ApplicationController
+ def index
+ end
+end
View
25 episode-285/auth-before/app/controllers/password_resets_controller.rb
@@ -0,0 +1,25 @@
+class PasswordResetsController < ApplicationController
+ def new
+ end
+
+ def create
+ user = User.find_by_email(params[:email])
+ user.send_password_reset if user
+ redirect_to root_url, :notice => "Email sent with password reset instructions."
+ end
+
+ def edit
+ @user = User.find_by_password_reset_token!(params[:id])
+ end
+
+ def update
+ @user = User.find_by_password_reset_token!(params[:id])
+ if @user.password_reset_sent_at < 2.hours.ago
+ redirect_to new_password_reset_path, :alert => "Password reset has expired."
+ elsif @user.update_attributes(params[:user])
+ redirect_to root_url, :notice => "Password has been reset!"
+ else
+ render :edit
+ end
+ end
+end
View
20 episode-285/auth-before/app/controllers/sessions_controller.rb
@@ -0,0 +1,20 @@
+class SessionsController < ApplicationController
+ def new
+ end
+
+ def create
+ user = User.find_by_email(params[:email])
+ if user && user.authenticate(params[:password])
+ session[:user_id] = user.id
+ redirect_to root_url, :notice => "Logged in!"
+ else
+ flash.now.alert = "Invalid email or password"
+ render "new"
+ end
+ end
+
+ def destroy
+ session[:user_id] = nil
+ redirect_to root_url, :notice => "Logged out!"
+ end
+end
View
14 episode-285/auth-before/app/controllers/users_controller.rb
@@ -0,0 +1,14 @@
+class UsersController < ApplicationController
+ def new
+ @user = User.new
+ end
+
+ def create
+ @user = User.new(params[:user])
+ if @user.save
+ redirect_to root_url, :notice => "Signed up!"
+ else
+ render "new"
+ end
+ end
+end
View
2  episode-285/auth-before/app/helpers/application_helper.rb
@@ -0,0 +1,2 @@
+module ApplicationHelper
+end
View
2  episode-285/auth-before/app/helpers/home_helper.rb
@@ -0,0 +1,2 @@
+module HomeHelper
+end
View
2  episode-285/auth-before/app/helpers/password_resets_helper.rb
@@ -0,0 +1,2 @@
+module PasswordResetsHelper
+end
View
2  episode-285/auth-before/app/helpers/sessions_helper.rb
@@ -0,0 +1,2 @@
+module SessionsHelper
+end
View
2  episode-285/auth-before/app/helpers/users_helper.rb
@@ -0,0 +1,2 @@
+module UsersHelper
+end
View
0  episode-285/auth-before/app/mailers/.gitkeep
No changes.
View
8 episode-285/auth-before/app/mailers/user_mailer.rb
@@ -0,0 +1,8 @@
+class UserMailer < ActionMailer::Base
+ default from: "from@example.com"
+
+ def password_reset(user)
+ @user = user
+ mail :to => user.email, :subject => "Password Reset"
+ end
+end
View
0  episode-285/auth-before/app/models/.gitkeep
No changes.
View
18 episode-285/auth-before/app/models/user.rb
@@ -0,0 +1,18 @@
+class User < ActiveRecord::Base
+ attr_accessible :email, :password, :password_confirmation
+ has_secure_password
+ validates_presence_of :password, :on => :create
+
+ def send_password_reset
+ generate_token(:password_reset_token)
+ self.password_reset_sent_at = Time.zone.now
+ save!
+ UserMailer.password_reset(self).deliver
+ end
+
+ def generate_token(column)
+ begin
+ self[column] = SecureRandom.urlsafe_base64
+ end while User.exists?(column => self[column])
+ end
+end
View
3  episode-285/auth-before/app/views/home/index.html.erb
@@ -0,0 +1,3 @@
+<h1>Welcome</h1>
+
+<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
View
26 episode-285/auth-before/app/views/layouts/application.html.erb
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Auth Example</title>
+ <%= stylesheet_link_tag "application" %>
+ <%= javascript_include_tag "application" %>
+ <%= csrf_meta_tags %>
+</head>
+<body>
+ <div id="container">
+ <div id="user_nav">
+ <% if current_user %>
+ Logged in as <%= current_user.email %>.
+ <%= link_to "Log out", logout_path %>
+ <% else %>
+ <%= link_to "Sign up", signup_path %> or
+ <%= link_to "log in", login_path %>
+ <% end %>
+ </div>
+ <% flash.each do |name, msg| %>
+ <%= content_tag :div, msg, :id => "flash_#{name}" %>
+ <% end %>
+ <%= yield %>
+ </div>
+</body>
+</html>
View
23 episode-285/auth-before/app/views/password_resets/edit.html.erb
@@ -0,0 +1,23 @@
+<h1>Reset Password</h1>
+
+<%= form_for @user, :url => password_reset_path(params[:id]) do |f| %>
+ <% if @user.errors.any? %>
+ <div class="error_messages">
+ <h2>Form is invalid</h2>
+ <ul>
+ <% for message in @user.errors.full_messages %>
+ <li><%= message %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+ <div class="field">