sparkly-auth 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (243) hide show
  1. data/.document +5 -0
  2. data/.gitignore +25 -0
  3. data/HISTORY.txt +7 -0
  4. data/README.rdoc +127 -1
  5. data/Rakefile +45 -13
  6. data/TODO +4 -0
  7. data/VERSION +1 -1
  8. data/app/controllers/sparkly_accounts_controller.rb +20 -13
  9. data/app/controllers/sparkly_controller.rb +5 -4
  10. data/app/controllers/sparkly_sessions_controller.rb +16 -9
  11. data/app/helpers/sparkly_accounts_helper.rb +2 -0
  12. data/app/helpers/sparkly_helper.rb +2 -0
  13. data/app/helpers/sparkly_sessions_helper.rb +2 -0
  14. data/app/models/remembrance_token.rb +3 -1
  15. data/app/views/sparkly_accounts/_rails2_form.html.erb +24 -0
  16. data/app/views/sparkly_accounts/_rails3_form.html.erb +26 -0
  17. data/app/views/sparkly_accounts/edit.html.erb +5 -23
  18. data/app/views/sparkly_accounts/new.html.erb +4 -23
  19. data/app/views/sparkly_sessions/_rails2_form.html.erb +22 -0
  20. data/app/views/sparkly_sessions/_rails3_form.html.erb +22 -0
  21. data/app/views/sparkly_sessions/new.html.erb +4 -21
  22. data/features/create_sparkly_account.feature +12 -0
  23. data/features/delete_sparkly_account.feature +12 -0
  24. data/features/edit_sparkly_account.feature +54 -0
  25. data/features/lock_abused_sparkly_account.feature +7 -0
  26. data/features/login_sparkly_session.feature +43 -0
  27. data/features/logout_sparkly_session.feature +16 -0
  28. data/features/setup/sparkly.rb +4 -0
  29. data/features/show_sparkly_account.feature +13 -0
  30. data/features/sparkly_session_timeout.feature +6 -0
  31. data/features/step_definitions/account/account_steps.rb +16 -0
  32. data/features/step_definitions/account/brief_steps.rb +9 -0
  33. data/features/step_definitions/debug_steps.rb +3 -0
  34. data/features/step_definitions/email_steps.rb +182 -0
  35. data/features/step_definitions/session/brief_steps.rb +0 -0
  36. data/features/step_definitions/session/logged_in_steps.rb +42 -0
  37. data/features/step_definitions/session/login_steps.rb +37 -0
  38. data/features/step_definitions/session/logout_steps.rb +5 -0
  39. data/features/step_definitions/session_steps.rb +16 -0
  40. data/features/step_definitions/sparkly_auth_steps.rb +0 -0
  41. data/features/step_definitions/web_steps.rb +287 -0
  42. data/features/support/env.rb +10 -0
  43. data/features/support/paths.rb +35 -0
  44. data/features/support/sparkly_helpers.rb +42 -0
  45. data/generators/sparkly/rails2.rb +79 -0
  46. data/generators/sparkly/rails3.rb +89 -0
  47. data/generators/sparkly/sparkly_generator.rb +4 -75
  48. data/generators/sparkly/templates/accounts_controller.rb +14 -13
  49. data/generators/sparkly/templates/accounts_helper.rb +1 -1
  50. data/generators/sparkly/templates/sessions_controller.rb +26 -12
  51. data/generators/sparkly/templates/sessions_helper.rb +1 -1
  52. data/generators/sparkly/templates/views/sparkly_accounts/_rails2_form.html.erb +24 -0
  53. data/generators/sparkly/templates/views/sparkly_accounts/_rails3_form.html.erb +26 -0
  54. data/generators/sparkly/templates/views/sparkly_accounts/edit.html.erb +5 -23
  55. data/generators/sparkly/templates/views/sparkly_accounts/new.html.erb +4 -23
  56. data/generators/sparkly/templates/views/sparkly_sessions/_rails2_form.html.erb +22 -0
  57. data/generators/sparkly/templates/views/sparkly_sessions/_rails3_form.html.erb +22 -0
  58. data/generators/sparkly/templates/views/sparkly_sessions/new.html.erb +4 -21
  59. data/lib/auth.rb +22 -1
  60. data/lib/auth/behavior/base.rb +25 -18
  61. data/lib/auth/behavior/base/configuration.rb +37 -0
  62. data/lib/auth/behavior/core.rb +22 -14
  63. data/lib/auth/behavior/core/authenticated_model_methods.rb +9 -1
  64. data/lib/auth/behavior/core/controller_extensions.rb +2 -2
  65. data/lib/auth/behavior/core/controller_extensions/class_methods.rb +1 -1
  66. data/lib/auth/behavior/core/password_methods.rb +5 -5
  67. data/lib/auth/behavior/remember_me.rb +7 -3
  68. data/lib/auth/behavior/remember_me/configuration.rb +8 -11
  69. data/lib/auth/behavior/remember_me/controller_extensions.rb +1 -1
  70. data/lib/auth/behavior_lookup.rb +4 -4
  71. data/lib/auth/builtin_behaviors.rb +3 -0
  72. data/lib/auth/configuration.rb +71 -25
  73. data/lib/auth/configuration/keys.rb +50 -0
  74. data/lib/auth/engine.rb +33 -0
  75. data/lib/auth/generators/views_generator.rb +13 -4
  76. data/lib/auth/model.rb +52 -22
  77. data/{init.rb → rails/hacks/rails2.rb} +1 -14
  78. data/rails/hacks/rails3.rb +22 -0
  79. data/rails/init.rb +7 -17
  80. data/rails/init_rails2.rb +39 -0
  81. data/rails/init_rails3.rb +2 -0
  82. data/rails/routes_rails3.rb +37 -0
  83. data/rake3 +1 -0
  84. data/rerun.txt +1 -0
  85. data/run_all_tests +1 -0
  86. data/sparkly-auth.gemspec +481 -23
  87. data/spec/behaviors/core/controller_extensions_spec.rb +49 -0
  88. data/spec/{lib/auth/behavior → behaviors}/core_spec.rb +29 -12
  89. data/spec/behaviors/remember_me/configuration_spec.rb +16 -0
  90. data/spec/behaviors/remember_me_spec.rb +167 -0
  91. data/spec/generators/sanity_checks_spec.rb +58 -0
  92. data/spec/lib/auth/configuration_spec.rb +61 -0
  93. data/spec/lib/auth/model_spec.rb +6 -9
  94. data/spec/lib/auth_spec.rb +2 -2
  95. data/spec/lib/hacks/rename_attributes_spec.rb +49 -0
  96. data/spec/routes_spec.rb +8 -2
  97. data/spec/spec2_helper.rb +52 -0
  98. data/spec/spec3_helper.rb +72 -0
  99. data/spec/spec_helper.rb +109 -49
  100. data/spec_env/rails2/README.1ST +23 -0
  101. data/spec_env/rails2/Rakefile +10 -0
  102. data/spec_env/rails2/app/controllers/application_controller.rb +13 -0
  103. data/spec_env/rails2/app/helpers/application_helper.rb +3 -0
  104. data/spec_env/rails2/app/models/user.rb +2 -0
  105. data/spec_env/rails2/app/views/application/not_found.html.erb +9 -0
  106. data/spec_env/rails2/app/views/layouts/application.html.erb +9 -0
  107. data/spec_env/rails2/config/boot.rb +110 -0
  108. data/spec_env/rails2/config/cucumber.yml +7 -0
  109. data/spec_env/rails2/config/database.yml +25 -0
  110. data/spec_env/rails2/config/environment.rb +46 -0
  111. data/spec_env/rails2/config/environments/cucumber.rb +35 -0
  112. data/spec_env/rails2/config/environments/development.rb +17 -0
  113. data/spec_env/rails2/config/environments/production.rb +28 -0
  114. data/spec_env/rails2/config/environments/test.rb +31 -0
  115. data/spec_env/rails2/config/initializers/backtrace_silencers.rb +7 -0
  116. data/spec_env/rails2/config/initializers/inflections.rb +10 -0
  117. data/spec_env/rails2/config/initializers/mime_types.rb +5 -0
  118. data/spec_env/rails2/config/initializers/new_rails_defaults.rb +21 -0
  119. data/spec_env/rails2/config/initializers/session_store.rb +15 -0
  120. data/spec_env/rails2/config/initializers/sparkly_authentication.rb +30 -0
  121. data/spec_env/rails2/config/locales/en.yml +5 -0
  122. data/spec_env/rails2/config/routes.rb +46 -0
  123. data/spec_env/rails2/db/development.sqlite3 +0 -0
  124. data/spec_env/rails2/db/migrate/001_create_sparkly_passwords.rb +19 -0
  125. data/spec_env/rails2/db/migrate/002_create_sparkly_remembered_tokens.rb +15 -0
  126. data/spec_env/rails2/db/migrate/003_add_confirmed_to_sparkly_passwords.rb +9 -0
  127. data/spec_env/rails2/db/migrate/20100607103543_create_users.rb +12 -0
  128. data/spec_env/rails2/db/migrate/20100609152058_add_email_to_users.rb +9 -0
  129. data/spec_env/rails2/db/schema.rb +42 -0
  130. data/spec_env/rails2/db/seeds.rb +7 -0
  131. data/spec_env/rails2/db/test.sqlite3 +0 -0
  132. data/spec_env/rails2/doc/README_FOR_APP +2 -0
  133. data/spec_env/rails2/doc/sparkly_authentication.txt +56 -0
  134. data/spec_env/rails2/features/support/env.rb +58 -0
  135. data/spec_env/rails2/lib/tasks/cucumber.rake +47 -0
  136. data/spec_env/rails2/lib/tasks/rspec.rake +144 -0
  137. data/spec_env/rails2/lib/tasks/sparkly_migration.rb +1 -0
  138. data/spec_env/rails2/log/cucumber.log +8412 -0
  139. data/spec_env/rails2/log/development.log +317 -0
  140. data/spec_env/rails2/log/test.log +32053 -0
  141. data/spec_env/rails2/public/404.html +30 -0
  142. data/spec_env/rails2/public/422.html +30 -0
  143. data/spec_env/rails2/public/500.html +30 -0
  144. data/spec_env/rails2/public/favicon.ico +0 -0
  145. data/spec_env/rails2/public/images/rails.png +0 -0
  146. data/spec_env/rails2/public/javascripts/application.js +2 -0
  147. data/spec_env/rails2/public/javascripts/controls.js +963 -0
  148. data/spec_env/rails2/public/javascripts/dragdrop.js +973 -0
  149. data/spec_env/rails2/public/javascripts/effects.js +1128 -0
  150. data/spec_env/rails2/public/javascripts/prototype.js +4320 -0
  151. data/spec_env/rails2/public/robots.txt +5 -0
  152. data/spec_env/rails2/rerun.txt +1 -0
  153. data/spec_env/rails2/script/about +4 -0
  154. data/spec_env/rails2/script/autospec +6 -0
  155. data/spec_env/rails2/script/console +3 -0
  156. data/spec_env/rails2/script/cucumber +10 -0
  157. data/spec_env/rails2/script/dbconsole +3 -0
  158. data/spec_env/rails2/script/destroy +3 -0
  159. data/spec_env/rails2/script/generate +3 -0
  160. data/spec_env/rails2/script/performance/benchmarker +3 -0
  161. data/spec_env/rails2/script/performance/profiler +3 -0
  162. data/spec_env/rails2/script/plugin +3 -0
  163. data/spec_env/rails2/script/runner +3 -0
  164. data/spec_env/rails2/script/server +3 -0
  165. data/spec_env/rails2/script/spec +10 -0
  166. data/spec_env/rails2/spec/controllers/sparkly_user_sessions_controller_spec.rb +10 -0
  167. data/spec_env/rails2/spec/rcov.opts +2 -0
  168. data/spec_env/rails2/spec/spec.opts +4 -0
  169. data/spec_env/rails2/spec/spec_helper.rb +54 -0
  170. data/spec_env/rails2/test/fixtures/users.yml +7 -0
  171. data/spec_env/rails2/test/performance/browsing_test.rb +9 -0
  172. data/spec_env/rails2/test/test_helper.rb +38 -0
  173. data/spec_env/rails2/test/unit/user_test.rb +8 -0
  174. data/spec_env/rails2/vendor/gems/sparkly-auth-bootstrap-1.0.0/.specification +63 -0
  175. data/spec_env/rails2/vendor/gems/sparkly-auth-bootstrap-1.0.0/generators/sparkly/sparkly_generator.rb +1 -0
  176. data/spec_env/rails2/vendor/gems/sparkly-auth-bootstrap-1.0.0/lib/sparkly-auth-bootstrap.rb +6 -0
  177. data/spec_env/rails2/vendor/gems/sparkly-auth-bootstrap-1.0.0/rails/init.rb +1 -0
  178. data/spec_env/rails2/vendor/gems/sparkly-auth-bootstrap-1.0.0/sparkly-auth-bootstrap.gemspec +55 -0
  179. data/spec_env/rails3/.gitignore +4 -0
  180. data/spec_env/rails3/Gemfile +43 -0
  181. data/spec_env/rails3/Gemfile.lock +124 -0
  182. data/spec_env/rails3/README +256 -0
  183. data/spec_env/rails3/Rakefile +7 -0
  184. data/spec_env/rails3/app/controllers/application_controller.rb +6 -0
  185. data/spec_env/rails3/app/helpers/application_helper.rb +2 -0
  186. data/spec_env/rails3/app/models/user.rb +3 -0
  187. data/spec_env/rails3/app/views/application/not_found.html.erb +9 -0
  188. data/spec_env/rails3/app/views/layouts/application.html.erb +22 -0
  189. data/spec_env/rails3/config.ru +4 -0
  190. data/spec_env/rails3/config/application.rb +47 -0
  191. data/spec_env/rails3/config/boot.rb +13 -0
  192. data/spec_env/rails3/config/cucumber.yml +8 -0
  193. data/spec_env/rails3/config/database.yml +28 -0
  194. data/spec_env/rails3/config/environment.rb +5 -0
  195. data/spec_env/rails3/config/environments/development.rb +22 -0
  196. data/spec_env/rails3/config/environments/production.rb +49 -0
  197. data/spec_env/rails3/config/environments/spec.rb +35 -0
  198. data/spec_env/rails3/config/environments/test.rb +43 -0
  199. data/spec_env/rails3/config/initializers/backtrace_silencers.rb +7 -0
  200. data/spec_env/rails3/config/initializers/inflections.rb +10 -0
  201. data/spec_env/rails3/config/initializers/mime_types.rb +5 -0
  202. data/spec_env/rails3/config/initializers/secret_token.rb +7 -0
  203. data/spec_env/rails3/config/initializers/session_store.rb +8 -0
  204. data/spec_env/rails3/config/initializers/sparkly_authentication.rb +30 -0
  205. data/spec_env/rails3/config/locales/en.yml +5 -0
  206. data/spec_env/rails3/config/routes.rb +61 -0
  207. data/spec_env/rails3/db/migrate/001_create_sparkly_passwords.rb +19 -0
  208. data/spec_env/rails3/db/migrate/002_create_sparkly_remembered_tokens.rb +15 -0
  209. data/spec_env/rails3/db/migrate/20100810132843_create_users.rb +13 -0
  210. data/spec_env/rails3/db/schema.rb +42 -0
  211. data/spec_env/rails3/db/seeds.rb +7 -0
  212. data/spec_env/rails3/doc/README_FOR_APP +2 -0
  213. data/spec_env/rails3/doc/sparkly_authentication.txt +56 -0
  214. data/spec_env/rails3/features/support/env.rb +62 -0
  215. data/spec_env/rails3/lib/sparkly/bootstrap.rb +1 -0
  216. data/spec_env/rails3/lib/tasks/.gitkeep +0 -0
  217. data/spec_env/rails3/lib/tasks/cucumber.rake +53 -0
  218. data/spec_env/rails3/lib/tasks/sparkly_migration.rb +1 -0
  219. data/spec_env/rails3/public/404.html +26 -0
  220. data/spec_env/rails3/public/422.html +26 -0
  221. data/spec_env/rails3/public/500.html +26 -0
  222. data/spec_env/rails3/public/favicon.ico +0 -0
  223. data/spec_env/rails3/public/images/rails.png +0 -0
  224. data/spec_env/rails3/public/javascripts/application.js +2 -0
  225. data/spec_env/rails3/public/javascripts/controls.js +965 -0
  226. data/spec_env/rails3/public/javascripts/dragdrop.js +974 -0
  227. data/spec_env/rails3/public/javascripts/effects.js +1123 -0
  228. data/spec_env/rails3/public/javascripts/prototype.js +6001 -0
  229. data/spec_env/rails3/public/javascripts/rails.js +175 -0
  230. data/spec_env/rails3/public/robots.txt +5 -0
  231. data/spec_env/rails3/public/stylesheets/.gitkeep +0 -0
  232. data/spec_env/rails3/script/cucumber +10 -0
  233. data/spec_env/rails3/script/rails +6 -0
  234. data/spec_env/rails3/test/fixtures/users.yml +7 -0
  235. data/spec_env/rails3/test/performance/browsing_test.rb +9 -0
  236. data/spec_env/rails3/test/test_helper.rb +13 -0
  237. data/spec_env/rails3/test/unit/user_test.rb +8 -0
  238. data/spec_env/rails3/vendor/plugins/.gitkeep +0 -0
  239. data/spec_env/rails3/webrat.log +5 -0
  240. metadata +393 -15
  241. data/dependencies.rb +0 -1
  242. data/spec/lib/auth/behavior/remember_me_spec.rb +0 -127
  243. data/spec/lib/auth/extensions/controller_spec.rb +0 -32
@@ -1,24 +1,6 @@
1
- <%form_for model, :url => model_path do |f|%>
2
- <p>
3
- <%=f.error_messages%>
4
- </p>
5
-
6
- <p>
7
- <%=f.label model_config.key%><br/>
8
- <%=f.text_field model_config.key%>
9
- </p>
10
-
11
- <p>
12
- <%=f.label :password%><br/>
13
- <%=f.password_field :password, :value => ''%>
14
- </p>
15
-
16
- <p>
17
- <%=f.label :password_confirmation%><br/>
18
- <%=f.password_field :password_confirmation, :value => ''%>
19
- </p>
20
-
21
- <p>
22
- <%=f.submit "Update Profile"%>
23
- </p>
1
+ <%if Rails::VERSION::MAJOR == 2%>
2
+ <%=render :partial => 'rails2_form'%>
3
+ <%else%>
4
+ <%=render :partial => 'rails3_form'%>
24
5
  <%end%>
6
+
@@ -1,24 +1,5 @@
1
- <%form_for model, :url => model_path do |f|%>
2
- <p>
3
- <%=f.error_messages%>
4
- </p>
5
-
6
- <p>
7
- <%=f.label model_config.key%><br/>
8
- <%=f.text_field model_config.key%>
9
- </p>
10
-
11
- <p>
12
- <%=f.label :password%><br/>
13
- <%=f.password_field :password, :value => ''%>
14
- </p>
15
-
16
- <p>
17
- <%=f.label :password_confirmation%><br/>
18
- <%=f.password_field :password_confirmation, :value => ''%>
19
- </p>
20
-
21
- <p>
22
- <%=f.submit "Sign up"%>
23
- </p>
1
+ <%if Rails::VERSION::MAJOR == 2%>
2
+ <%=render :partial => 'rails2_form'%>
3
+ <%else%>
4
+ <%=render :partial => 'rails3_form'%>
24
5
  <%end%>
@@ -0,0 +1,22 @@
1
+ <%form_for model, :url => model_session_path do |f|%>
2
+ <p>
3
+ <%=f.label model_config.key%><br/>
4
+ <%=f.text_field model_config.key%>
5
+ </p>
6
+
7
+ <p>
8
+ <%=f.label :password%><br/>
9
+ <%=f.password_field :password, :value => ''%>
10
+ </p>
11
+
12
+ <%if sparkly_config.remember_me.enabled?%>
13
+ <p>
14
+ <%=f.check_box :remember_me, :checked => false%>
15
+ <%=f.label :remember_me%>
16
+ </p>
17
+ <%end%>
18
+
19
+ <p>
20
+ <%=f.submit "Sign in"%>
21
+ </p>
22
+ <%end%>
@@ -0,0 +1,22 @@
1
+ <%=form_for model, :url => model_session_path do |f|%>
2
+ <p>
3
+ <%=f.label model_config.key%><br/>
4
+ <%=f.text_field model_config.key%>
5
+ </p>
6
+
7
+ <p>
8
+ <%=f.label :password%><br/>
9
+ <%=f.password_field :password, :value => ''%>
10
+ </p>
11
+
12
+ <%if sparkly_config.remember_me.enabled?%>
13
+ <p>
14
+ <%=f.check_box :remember_me, :checked => false%>
15
+ <%=f.label :remember_me%>
16
+ </p>
17
+ <%end%>
18
+
19
+ <p>
20
+ <%=f.submit "Sign in"%>
21
+ </p>
22
+ <%end%>
@@ -1,22 +1,5 @@
1
- <%form_for model, :url => model_session_path do |f|%>
2
- <p>
3
- <%=f.label model_config.key%><br/>
4
- <%=f.text_field model_config.key%>
5
- </p>
6
-
7
- <p>
8
- <%=f.label :password%><br/>
9
- <%=f.password_field :password, :value => ''%>
10
- </p>
11
-
12
- <%if Auth.remember_me.enabled?%>
13
- <p>
14
- <%=f.check_box :remember_me, :checked => false%>
15
- <%=f.label :remember_me%>
16
- </p>
17
- <%end%>
18
-
19
- <p>
20
- <%=f.submit "Sign in"%>
21
- </p>
1
+ <%if Rails::VERSION::MAJOR == 2%>
2
+ <%=render :partial => 'rails2_form'%>
3
+ <%else%>
4
+ <%=render :partial => 'rails3_form'%>
22
5
  <%end%>
data/lib/auth.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Auth
2
2
  class << self
3
3
  public :delegate
4
- delegate :path, :encryptor, :default_accounts_controller_name, :default_sessions_controller_name,
4
+ delegate :encryptor, :default_accounts_controller_name, :default_sessions_controller_name,
5
5
  :password_update_frequency, :base_controller, :login_required_message, :logout_required_message,
6
6
  :default_destination, :session_duration, :invalid_credentials_message, :login_successful_message,
7
7
  :logout_message, :session_timeout_message, :default_login_path, :account_deleted_message,
@@ -19,6 +19,22 @@ module Auth
19
19
  yield configuration
20
20
  end
21
21
 
22
+ def defer_kickstart?
23
+ @defer_kickstart ||= !!ENV['DEFER_SPARKLY']
24
+ end
25
+
26
+ def defer_kickstart=(a)
27
+ @defer_kickstart = !!a
28
+ end
29
+
30
+ def path
31
+ if @configuration
32
+ @configuration.path
33
+ else
34
+ File.dirname(__FILE__)
35
+ end
36
+ end
37
+
22
38
  # Applies all configuration settings. This is done by the Auth system after it has been configured but before
23
39
  # it processes any requests.
24
40
  def configure!
@@ -50,3 +66,8 @@ module Auth
50
66
  alias_method :kick!, :configure!
51
67
  end
52
68
  end
69
+
70
+ if defined?(Rails) && Rails::VERSION::MAJOR == 3
71
+ # Rails 3 doesn't load rails/init.rb first, so we need to do that ourselves.
72
+ require File.join(File.dirname(__FILE__), "../rails/init")
73
+ end
@@ -1,32 +1,30 @@
1
1
  class Auth::Behavior::Base
2
+ #unloadable
3
+
4
+ attr_reader :options
2
5
  class_inheritable_array :migrations
3
6
  read_inheritable_attribute(:migrations) || write_inheritable_attribute(:migrations, [])
4
7
 
5
- class << self
6
- def apply_to_controllers
7
- # Add additional methods to ApplicationController (or whatever controller Sparkly is told to use)
8
- Auth.base_controller.send(:include, "#{name}::ControllerExtensions".constantize)
9
- # why this doesn't work in cuke?
10
- # if (container = self.class).const_defined?(:ControllerExtensions)
11
- # Auth.base_controller.send(:include, container.const_get(:ControllerExtensions))
12
- # end
13
- #rescue NameError
8
+ def apply(model_config)
9
+ track_behavior(model = model_config.target) do
10
+ apply_to_user(model)
11
+ apply_to_password(Password, model)
12
+ apply_to_controller(Auth.base_controller, model)
14
13
  end
15
14
  end
16
15
 
17
- def apply_to(model)
18
- track_behavior(model.target) do
19
- apply_to_accounts(model)
20
- apply_to_passwords(Password)
21
- end
16
+ alias_method :apply_to, :apply
17
+
18
+ def apply_to_controller(base_controller, user_model)
19
+ be_sure_to_override("apply_to_controller(base_controller, user_model)")
22
20
  end
23
21
 
24
- def apply_to_passwords(password_model)
25
- raise NotImplementedError, "Be sure to override #apply_to_passwords(passwords_model) in your Auth Behavior"
22
+ def apply_to_password(password_model, user_model)
23
+ be_sure_to_override("apply_to_password(password_model, user_model)")
26
24
  end
27
25
 
28
- def apply_to_accounts(model_config)
29
- raise NotImplementedError, "Be sure to override #apply_to_accounts(model_config) in your Auth Behavior"
26
+ def apply_to_user(user_model)
27
+ be_sure_to_override("apply_to_user(user_model)")
30
28
  end
31
29
 
32
30
  private
@@ -52,6 +50,11 @@ class Auth::Behavior::Base
52
50
  def behavior_name
53
51
  self.class.name
54
52
  end
53
+
54
+ private
55
+ def be_sure_to_override(name)
56
+ raise NotImplementedError, "Be sure to override ##{name} in #{self.class.name}"
57
+ end
55
58
 
56
59
  public
57
60
  class << self
@@ -60,5 +63,9 @@ class Auth::Behavior::Base
60
63
  def migration(filename)
61
64
  migrations << filename unless migrations.include?(filename)
62
65
  end
66
+
67
+ # def inherited(base)
68
+ # base.instance_eval { unloadable } # is this necessary?
69
+ # end
63
70
  end
64
71
  end
@@ -0,0 +1,37 @@
1
+ class Auth::Behavior::Base::Configuration
2
+ # Provides a handle back to the root configuration object.
3
+ attr_reader :configuration
4
+
5
+ include Auth::Configuration::Keys
6
+
7
+ class << self
8
+ def configuration_name(new_name = nil)
9
+ if new_name
10
+ @configuration_name = new_name.to_sym
11
+ else
12
+ # the sub removes Configuration, ie Auth::Behavior::Core::Configuration becomes Auth::Behavior::Core
13
+ @configuration_name = name.sub(/\:\:[^\:]*$/, '').demodulize.underscore.to_sym
14
+ end
15
+ end
16
+ end
17
+
18
+ # Returns true if the root configuration object's behaviors include :remember_me.
19
+ def enabled?
20
+ configuration.behaviors.include? configuration_name
21
+ end
22
+
23
+ def configuration_name
24
+ self.class.configuration_name
25
+ end
26
+
27
+ def initialize(configuration)
28
+ @configuration = configuration
29
+ defaults!
30
+ end
31
+
32
+ def defaults!
33
+ raise "Don't forget to override #{self.class.name}#defaults!"
34
+ end
35
+
36
+ alias reset! defaults!
37
+ end
@@ -17,15 +17,20 @@ module Auth
17
17
  class Core < Auth::Behavior::Base
18
18
  migration "create_sparkly_passwords"
19
19
 
20
- def apply_to_passwords(password_model)
20
+ def apply_to_controller(base_controller, user_model)
21
+ base_controller.send(:include, Auth::Behavior::Core::ControllerExtensions)
22
+ end
23
+
24
+ def apply_to_password(password_model, user_model)
25
+ config = user_model.sparkly_config
21
26
  password_model.instance_eval do
22
27
  belongs_to :authenticatable, :polymorphic => true
23
28
 
24
- validates_length_of :unencrypted_secret, :minimum => Auth.minimum_password_length,
25
- :message => "must be at least #{Auth.minimum_password_length} characters",
29
+ validates_length_of :unencrypted_secret, :minimum => config.minimum_password_length,
30
+ :message => "must be at least #{config.minimum_password_length} characters",
26
31
  :if => :secret_changed?
27
- validates_format_of :unencrypted_secret, :with => Auth.password_format, :allow_blank => true,
28
- :message => Auth.password_format_message,
32
+ validates_format_of :unencrypted_secret, :with => config.password_format, :allow_blank => true,
33
+ :message => config.password_format_message,
29
34
  :if => :secret_changed?
30
35
 
31
36
  validates_presence_of :secret
@@ -34,16 +39,21 @@ module Auth
34
39
  validates_presence_of :persistence_token
35
40
  validates_uniqueness_of :persistence_token, :if => :persistence_token_changed?
36
41
  attr_protected :secret, :secret_confirmation
37
-
38
42
  include Auth::Behavior::Core::PasswordMethods
39
43
 
40
44
  validate do |password|
41
45
  password.errors.rename_attribute("unencrypted_secret", "secret")
42
46
  end
47
+
48
+ if Rails::VERSION::MAJOR == 3
49
+ # The hooks have changed.
50
+ after_initialize :after_initialize
51
+ end
43
52
  end
44
53
  end
45
54
 
46
- def apply_to_accounts(model_config)
55
+ def apply_to_user(model)
56
+ model_config = model.sparkly_config
47
57
  model_config.target.instance_eval do
48
58
  has_many :passwords, :dependent => :destroy, :as => :authenticatable, :autosave => true
49
59
 
@@ -54,11 +64,9 @@ module Auth
54
64
 
55
65
  include Auth::Behavior::Core::AuthenticatedModelMethods
56
66
 
57
- after_save do |record|
58
- # clear out old passwords so we're conforming to Auth.password_history_length
59
- while record.passwords.length > Auth.password_history_length
60
- record.passwords.shift.destroy
61
- end
67
+ if Rails::VERSION::MAJOR == 3
68
+ # The hooks have changed.
69
+ after_save :after_save
62
70
  end
63
71
 
64
72
  validate do |account|
@@ -67,14 +75,14 @@ module Auth
67
75
 
68
76
  # the various salts make it impossible to do this:
69
77
  # validates_uniqueness_of :secret, :scope => [ :authenticatable_type, :authenticatable_id ],
70
- # :message => Auth.password_uniqueness_message
78
+ # :message => config.password_uniqueness_message
71
79
  # so we have to do it programmatically.
72
80
  if account.password_changed?
73
81
  secret = account.password_model.unencrypted_secret
74
82
  account.passwords.each do |password|
75
83
  unless password.new_record? # unless it's the one we're creating
76
84
  if password.matches?(secret)
77
- account.errors.add(:password, Auth.password_uniqueness_message)
85
+ account.errors.add(:password, sparkly_config.password_uniqueness_message)
78
86
  end
79
87
  end
80
88
  end
@@ -43,10 +43,18 @@ module Auth::Behavior::Core::AuthenticatedModelMethods
43
43
 
44
44
  def after_save
45
45
  @new_password = nil
46
+ # clear out old passwords so we're conforming to sparkly_config.password_history_length
47
+ while passwords.length > sparkly_config.password_history_length
48
+ passwords.shift.destroy
49
+ end
46
50
  end
47
51
 
48
52
  private
49
53
  def new_password
50
- @new_password ||= returning(Password.new) { |p| passwords << p }
54
+ @new_password ||= begin
55
+ p = Password.new
56
+ passwords << p
57
+ p
58
+ end
51
59
  end
52
60
  end
@@ -1,6 +1,6 @@
1
1
  module Auth::Behavior::Core::ControllerExtensions
2
2
  def self.included(base)
3
- base.instance_eval do
3
+ base.class_eval do
4
4
  include Auth::Behavior::Core::ControllerExtensions::CurrentUser
5
5
  extend Auth::Behavior::Core::ControllerExtensions::ClassMethods
6
6
  helper_method :new_session_path, :current_user
@@ -18,7 +18,7 @@ module Auth::Behavior::Core::ControllerExtensions
18
18
  end
19
19
  end
20
20
 
21
- def store_location(url = request.request_uri)
21
+ def store_location(url = request.respond_to?(:fullpath) ? request.fullpath : request.request_uri)
22
22
  session[:destination] = url
23
23
  end
24
24
 
@@ -21,4 +21,4 @@ module Auth::Behavior::Core::ControllerExtensions::ClassMethods
21
21
  alias_method :requires_logout, :require_logout
22
22
  alias_method :require_no_user, :require_logout
23
23
  alias_method :requires_no_user, :require_logout
24
- end
24
+ end
@@ -47,11 +47,11 @@ module Auth::Behavior::Core::PasswordMethods
47
47
  def secret_with_encryption=(phrase)
48
48
  @unencrypted_secret = phrase
49
49
  encrypted_phrase = phrase.blank? ? phrase : encrypt(phrase)
50
- returning self.secret_without_encryption = encrypted_phrase do
51
- reset_persistence_token
52
- reset_single_access_token unless single_access_token # don't reset after it has a value
53
- reset_perishable_token
54
- end
50
+ self.secret_without_encryption = encrypted_phrase
51
+ reset_persistence_token
52
+ reset_single_access_token unless single_access_token # don't reset after it has a value
53
+ reset_perishable_token
54
+ return encrypted_phrase
55
55
  end
56
56
 
57
57
  def secret_confirmation_with_encryption=(phrase)
@@ -3,12 +3,16 @@ module Auth
3
3
  class RememberMe < Auth::Behavior::Base
4
4
  migration "create_sparkly_remembered_tokens"
5
5
 
6
- def apply_to_passwords(password)
6
+ def apply_to_controller(base_controller, user_model)
7
+ ApplicationController.send(:include, Auth::Behavior::RememberMe::ControllerExtensions)
8
+ end
9
+
10
+ def apply_to_password(password_model, user_model)
7
11
  # no effect
8
12
  end
9
13
 
10
- def apply_to_accounts(model_config)
11
- model_config.target.instance_eval do
14
+ def apply_to_user(user_model)
15
+ user_model.auth_config.target.instance_eval do
12
16
  has_many :remembrance_tokens, :dependent => :destroy, :as => :authenticatable
13
17
  end
14
18
  end