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.
- data/.document +5 -0
- data/.gitignore +25 -0
- data/HISTORY.txt +7 -0
- data/README.rdoc +127 -1
- data/Rakefile +45 -13
- data/TODO +4 -0
- data/VERSION +1 -1
- data/app/controllers/sparkly_accounts_controller.rb +20 -13
- data/app/controllers/sparkly_controller.rb +5 -4
- data/app/controllers/sparkly_sessions_controller.rb +16 -9
- data/app/helpers/sparkly_accounts_helper.rb +2 -0
- data/app/helpers/sparkly_helper.rb +2 -0
- data/app/helpers/sparkly_sessions_helper.rb +2 -0
- data/app/models/remembrance_token.rb +3 -1
- data/app/views/sparkly_accounts/_rails2_form.html.erb +24 -0
- data/app/views/sparkly_accounts/_rails3_form.html.erb +26 -0
- data/app/views/sparkly_accounts/edit.html.erb +5 -23
- data/app/views/sparkly_accounts/new.html.erb +4 -23
- data/app/views/sparkly_sessions/_rails2_form.html.erb +22 -0
- data/app/views/sparkly_sessions/_rails3_form.html.erb +22 -0
- data/app/views/sparkly_sessions/new.html.erb +4 -21
- data/features/create_sparkly_account.feature +12 -0
- data/features/delete_sparkly_account.feature +12 -0
- data/features/edit_sparkly_account.feature +54 -0
- data/features/lock_abused_sparkly_account.feature +7 -0
- data/features/login_sparkly_session.feature +43 -0
- data/features/logout_sparkly_session.feature +16 -0
- data/features/setup/sparkly.rb +4 -0
- data/features/show_sparkly_account.feature +13 -0
- data/features/sparkly_session_timeout.feature +6 -0
- data/features/step_definitions/account/account_steps.rb +16 -0
- data/features/step_definitions/account/brief_steps.rb +9 -0
- data/features/step_definitions/debug_steps.rb +3 -0
- data/features/step_definitions/email_steps.rb +182 -0
- data/features/step_definitions/session/brief_steps.rb +0 -0
- data/features/step_definitions/session/logged_in_steps.rb +42 -0
- data/features/step_definitions/session/login_steps.rb +37 -0
- data/features/step_definitions/session/logout_steps.rb +5 -0
- data/features/step_definitions/session_steps.rb +16 -0
- data/features/step_definitions/sparkly_auth_steps.rb +0 -0
- data/features/step_definitions/web_steps.rb +287 -0
- data/features/support/env.rb +10 -0
- data/features/support/paths.rb +35 -0
- data/features/support/sparkly_helpers.rb +42 -0
- data/generators/sparkly/rails2.rb +79 -0
- data/generators/sparkly/rails3.rb +89 -0
- data/generators/sparkly/sparkly_generator.rb +4 -75
- data/generators/sparkly/templates/accounts_controller.rb +14 -13
- data/generators/sparkly/templates/accounts_helper.rb +1 -1
- data/generators/sparkly/templates/sessions_controller.rb +26 -12
- data/generators/sparkly/templates/sessions_helper.rb +1 -1
- data/generators/sparkly/templates/views/sparkly_accounts/_rails2_form.html.erb +24 -0
- data/generators/sparkly/templates/views/sparkly_accounts/_rails3_form.html.erb +26 -0
- data/generators/sparkly/templates/views/sparkly_accounts/edit.html.erb +5 -23
- data/generators/sparkly/templates/views/sparkly_accounts/new.html.erb +4 -23
- data/generators/sparkly/templates/views/sparkly_sessions/_rails2_form.html.erb +22 -0
- data/generators/sparkly/templates/views/sparkly_sessions/_rails3_form.html.erb +22 -0
- data/generators/sparkly/templates/views/sparkly_sessions/new.html.erb +4 -21
- data/lib/auth.rb +22 -1
- data/lib/auth/behavior/base.rb +25 -18
- data/lib/auth/behavior/base/configuration.rb +37 -0
- data/lib/auth/behavior/core.rb +22 -14
- data/lib/auth/behavior/core/authenticated_model_methods.rb +9 -1
- data/lib/auth/behavior/core/controller_extensions.rb +2 -2
- data/lib/auth/behavior/core/controller_extensions/class_methods.rb +1 -1
- data/lib/auth/behavior/core/password_methods.rb +5 -5
- data/lib/auth/behavior/remember_me.rb +7 -3
- data/lib/auth/behavior/remember_me/configuration.rb +8 -11
- data/lib/auth/behavior/remember_me/controller_extensions.rb +1 -1
- data/lib/auth/behavior_lookup.rb +4 -4
- data/lib/auth/builtin_behaviors.rb +3 -0
- data/lib/auth/configuration.rb +71 -25
- data/lib/auth/configuration/keys.rb +50 -0
- data/lib/auth/engine.rb +33 -0
- data/lib/auth/generators/views_generator.rb +13 -4
- data/lib/auth/model.rb +52 -22
- data/{init.rb → rails/hacks/rails2.rb} +1 -14
- data/rails/hacks/rails3.rb +22 -0
- data/rails/init.rb +7 -17
- data/rails/init_rails2.rb +39 -0
- data/rails/init_rails3.rb +2 -0
- data/rails/routes_rails3.rb +37 -0
- data/rake3 +1 -0
- data/rerun.txt +1 -0
- data/run_all_tests +1 -0
- data/sparkly-auth.gemspec +481 -23
- data/spec/behaviors/core/controller_extensions_spec.rb +49 -0
- data/spec/{lib/auth/behavior → behaviors}/core_spec.rb +29 -12
- data/spec/behaviors/remember_me/configuration_spec.rb +16 -0
- data/spec/behaviors/remember_me_spec.rb +167 -0
- data/spec/generators/sanity_checks_spec.rb +58 -0
- data/spec/lib/auth/configuration_spec.rb +61 -0
- data/spec/lib/auth/model_spec.rb +6 -9
- data/spec/lib/auth_spec.rb +2 -2
- data/spec/lib/hacks/rename_attributes_spec.rb +49 -0
- data/spec/routes_spec.rb +8 -2
- data/spec/spec2_helper.rb +52 -0
- data/spec/spec3_helper.rb +72 -0
- data/spec/spec_helper.rb +109 -49
- data/spec_env/rails2/README.1ST +23 -0
- data/spec_env/rails2/Rakefile +10 -0
- data/spec_env/rails2/app/controllers/application_controller.rb +13 -0
- data/spec_env/rails2/app/helpers/application_helper.rb +3 -0
- data/spec_env/rails2/app/models/user.rb +2 -0
- data/spec_env/rails2/app/views/application/not_found.html.erb +9 -0
- data/spec_env/rails2/app/views/layouts/application.html.erb +9 -0
- data/spec_env/rails2/config/boot.rb +110 -0
- data/spec_env/rails2/config/cucumber.yml +7 -0
- data/spec_env/rails2/config/database.yml +25 -0
- data/spec_env/rails2/config/environment.rb +46 -0
- data/spec_env/rails2/config/environments/cucumber.rb +35 -0
- data/spec_env/rails2/config/environments/development.rb +17 -0
- data/spec_env/rails2/config/environments/production.rb +28 -0
- data/spec_env/rails2/config/environments/test.rb +31 -0
- data/spec_env/rails2/config/initializers/backtrace_silencers.rb +7 -0
- data/spec_env/rails2/config/initializers/inflections.rb +10 -0
- data/spec_env/rails2/config/initializers/mime_types.rb +5 -0
- data/spec_env/rails2/config/initializers/new_rails_defaults.rb +21 -0
- data/spec_env/rails2/config/initializers/session_store.rb +15 -0
- data/spec_env/rails2/config/initializers/sparkly_authentication.rb +30 -0
- data/spec_env/rails2/config/locales/en.yml +5 -0
- data/spec_env/rails2/config/routes.rb +46 -0
- data/spec_env/rails2/db/development.sqlite3 +0 -0
- data/spec_env/rails2/db/migrate/001_create_sparkly_passwords.rb +19 -0
- data/spec_env/rails2/db/migrate/002_create_sparkly_remembered_tokens.rb +15 -0
- data/spec_env/rails2/db/migrate/003_add_confirmed_to_sparkly_passwords.rb +9 -0
- data/spec_env/rails2/db/migrate/20100607103543_create_users.rb +12 -0
- data/spec_env/rails2/db/migrate/20100609152058_add_email_to_users.rb +9 -0
- data/spec_env/rails2/db/schema.rb +42 -0
- data/spec_env/rails2/db/seeds.rb +7 -0
- data/spec_env/rails2/db/test.sqlite3 +0 -0
- data/spec_env/rails2/doc/README_FOR_APP +2 -0
- data/spec_env/rails2/doc/sparkly_authentication.txt +56 -0
- data/spec_env/rails2/features/support/env.rb +58 -0
- data/spec_env/rails2/lib/tasks/cucumber.rake +47 -0
- data/spec_env/rails2/lib/tasks/rspec.rake +144 -0
- data/spec_env/rails2/lib/tasks/sparkly_migration.rb +1 -0
- data/spec_env/rails2/log/cucumber.log +8412 -0
- data/spec_env/rails2/log/development.log +317 -0
- data/spec_env/rails2/log/test.log +32053 -0
- data/spec_env/rails2/public/404.html +30 -0
- data/spec_env/rails2/public/422.html +30 -0
- data/spec_env/rails2/public/500.html +30 -0
- data/spec_env/rails2/public/favicon.ico +0 -0
- data/spec_env/rails2/public/images/rails.png +0 -0
- data/spec_env/rails2/public/javascripts/application.js +2 -0
- data/spec_env/rails2/public/javascripts/controls.js +963 -0
- data/spec_env/rails2/public/javascripts/dragdrop.js +973 -0
- data/spec_env/rails2/public/javascripts/effects.js +1128 -0
- data/spec_env/rails2/public/javascripts/prototype.js +4320 -0
- data/spec_env/rails2/public/robots.txt +5 -0
- data/spec_env/rails2/rerun.txt +1 -0
- data/spec_env/rails2/script/about +4 -0
- data/spec_env/rails2/script/autospec +6 -0
- data/spec_env/rails2/script/console +3 -0
- data/spec_env/rails2/script/cucumber +10 -0
- data/spec_env/rails2/script/dbconsole +3 -0
- data/spec_env/rails2/script/destroy +3 -0
- data/spec_env/rails2/script/generate +3 -0
- data/spec_env/rails2/script/performance/benchmarker +3 -0
- data/spec_env/rails2/script/performance/profiler +3 -0
- data/spec_env/rails2/script/plugin +3 -0
- data/spec_env/rails2/script/runner +3 -0
- data/spec_env/rails2/script/server +3 -0
- data/spec_env/rails2/script/spec +10 -0
- data/spec_env/rails2/spec/controllers/sparkly_user_sessions_controller_spec.rb +10 -0
- data/spec_env/rails2/spec/rcov.opts +2 -0
- data/spec_env/rails2/spec/spec.opts +4 -0
- data/spec_env/rails2/spec/spec_helper.rb +54 -0
- data/spec_env/rails2/test/fixtures/users.yml +7 -0
- data/spec_env/rails2/test/performance/browsing_test.rb +9 -0
- data/spec_env/rails2/test/test_helper.rb +38 -0
- data/spec_env/rails2/test/unit/user_test.rb +8 -0
- data/spec_env/rails2/vendor/gems/sparkly-auth-bootstrap-1.0.0/.specification +63 -0
- data/spec_env/rails2/vendor/gems/sparkly-auth-bootstrap-1.0.0/generators/sparkly/sparkly_generator.rb +1 -0
- data/spec_env/rails2/vendor/gems/sparkly-auth-bootstrap-1.0.0/lib/sparkly-auth-bootstrap.rb +6 -0
- data/spec_env/rails2/vendor/gems/sparkly-auth-bootstrap-1.0.0/rails/init.rb +1 -0
- data/spec_env/rails2/vendor/gems/sparkly-auth-bootstrap-1.0.0/sparkly-auth-bootstrap.gemspec +55 -0
- data/spec_env/rails3/.gitignore +4 -0
- data/spec_env/rails3/Gemfile +43 -0
- data/spec_env/rails3/Gemfile.lock +124 -0
- data/spec_env/rails3/README +256 -0
- data/spec_env/rails3/Rakefile +7 -0
- data/spec_env/rails3/app/controllers/application_controller.rb +6 -0
- data/spec_env/rails3/app/helpers/application_helper.rb +2 -0
- data/spec_env/rails3/app/models/user.rb +3 -0
- data/spec_env/rails3/app/views/application/not_found.html.erb +9 -0
- data/spec_env/rails3/app/views/layouts/application.html.erb +22 -0
- data/spec_env/rails3/config.ru +4 -0
- data/spec_env/rails3/config/application.rb +47 -0
- data/spec_env/rails3/config/boot.rb +13 -0
- data/spec_env/rails3/config/cucumber.yml +8 -0
- data/spec_env/rails3/config/database.yml +28 -0
- data/spec_env/rails3/config/environment.rb +5 -0
- data/spec_env/rails3/config/environments/development.rb +22 -0
- data/spec_env/rails3/config/environments/production.rb +49 -0
- data/spec_env/rails3/config/environments/spec.rb +35 -0
- data/spec_env/rails3/config/environments/test.rb +43 -0
- data/spec_env/rails3/config/initializers/backtrace_silencers.rb +7 -0
- data/spec_env/rails3/config/initializers/inflections.rb +10 -0
- data/spec_env/rails3/config/initializers/mime_types.rb +5 -0
- data/spec_env/rails3/config/initializers/secret_token.rb +7 -0
- data/spec_env/rails3/config/initializers/session_store.rb +8 -0
- data/spec_env/rails3/config/initializers/sparkly_authentication.rb +30 -0
- data/spec_env/rails3/config/locales/en.yml +5 -0
- data/spec_env/rails3/config/routes.rb +61 -0
- data/spec_env/rails3/db/migrate/001_create_sparkly_passwords.rb +19 -0
- data/spec_env/rails3/db/migrate/002_create_sparkly_remembered_tokens.rb +15 -0
- data/spec_env/rails3/db/migrate/20100810132843_create_users.rb +13 -0
- data/spec_env/rails3/db/schema.rb +42 -0
- data/spec_env/rails3/db/seeds.rb +7 -0
- data/spec_env/rails3/doc/README_FOR_APP +2 -0
- data/spec_env/rails3/doc/sparkly_authentication.txt +56 -0
- data/spec_env/rails3/features/support/env.rb +62 -0
- data/spec_env/rails3/lib/sparkly/bootstrap.rb +1 -0
- data/spec_env/rails3/lib/tasks/.gitkeep +0 -0
- data/spec_env/rails3/lib/tasks/cucumber.rake +53 -0
- data/spec_env/rails3/lib/tasks/sparkly_migration.rb +1 -0
- data/spec_env/rails3/public/404.html +26 -0
- data/spec_env/rails3/public/422.html +26 -0
- data/spec_env/rails3/public/500.html +26 -0
- data/spec_env/rails3/public/favicon.ico +0 -0
- data/spec_env/rails3/public/images/rails.png +0 -0
- data/spec_env/rails3/public/javascripts/application.js +2 -0
- data/spec_env/rails3/public/javascripts/controls.js +965 -0
- data/spec_env/rails3/public/javascripts/dragdrop.js +974 -0
- data/spec_env/rails3/public/javascripts/effects.js +1123 -0
- data/spec_env/rails3/public/javascripts/prototype.js +6001 -0
- data/spec_env/rails3/public/javascripts/rails.js +175 -0
- data/spec_env/rails3/public/robots.txt +5 -0
- data/spec_env/rails3/public/stylesheets/.gitkeep +0 -0
- data/spec_env/rails3/script/cucumber +10 -0
- data/spec_env/rails3/script/rails +6 -0
- data/spec_env/rails3/test/fixtures/users.yml +7 -0
- data/spec_env/rails3/test/performance/browsing_test.rb +9 -0
- data/spec_env/rails3/test/test_helper.rb +13 -0
- data/spec_env/rails3/test/unit/user_test.rb +8 -0
- data/spec_env/rails3/vendor/plugins/.gitkeep +0 -0
- data/spec_env/rails3/webrat.log +5 -0
- metadata +393 -15
- data/dependencies.rb +0 -1
- data/spec/lib/auth/behavior/remember_me_spec.rb +0 -127
- data/spec/lib/auth/extensions/controller_spec.rb +0 -32
@@ -1,24 +1,6 @@
|
|
1
|
-
<%
|
2
|
-
|
3
|
-
|
4
|
-
|
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
|
-
<%
|
2
|
-
|
3
|
-
|
4
|
-
|
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
|
-
<%
|
2
|
-
|
3
|
-
|
4
|
-
|
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 :
|
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
|
data/lib/auth/behavior/base.rb
CHANGED
@@ -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
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
25
|
-
|
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
|
29
|
-
|
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
|
data/lib/auth/behavior/core.rb
CHANGED
@@ -17,15 +17,20 @@ module Auth
|
|
17
17
|
class Core < Auth::Behavior::Base
|
18
18
|
migration "create_sparkly_passwords"
|
19
19
|
|
20
|
-
def
|
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 =>
|
25
|
-
:message => "must be at least #{
|
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 =>
|
28
|
-
: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
|
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
|
-
|
58
|
-
#
|
59
|
-
|
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 =>
|
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,
|
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 ||=
|
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.
|
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
|
|
@@ -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
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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
|
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
|
11
|
-
|
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
|