sparkly-auth 1.0.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
data/.document
ADDED
data/.gitignore
ADDED
data/HISTORY.txt
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
* 1.1.0 - 08-13-2010
|
|
2
|
+
* Official support for Rails 3 (tested against rails-3.0.0.rc)
|
|
3
|
+
* Better internal design
|
|
4
|
+
* Minor bugfixes
|
|
5
|
+
* Better support for per-model configuration
|
|
6
|
+
* Improved API for custom behaviors
|
|
7
|
+
|
|
1
8
|
* 1.0.1 - 08-09-2010
|
|
2
9
|
* Added /[user]/login and /[user]/logout to routes ([user]_login_path and [user]_logout_path, respectively)
|
|
3
10
|
|
data/README.rdoc
CHANGED
|
@@ -1,6 +1,132 @@
|
|
|
1
1
|
= sparkly-auth
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Rails authentication -- with sparkles!
|
|
4
|
+
|
|
5
|
+
== about the gem
|
|
6
|
+
|
|
7
|
+
After playing with a bunch of other auth gems out there, in the end I decided I had to roll my own. Unlike the
|
|
8
|
+
others (and the reason I undertook this task), Sparkly Auth errs on the side of security. By default, (that is,
|
|
9
|
+
unless you go changing configuration options that water down its auth mechanisms), this gem produces a PCI/DSS-
|
|
10
|
+
compliant authentication scheme which I'm now putting to work at my Real Job at Ingenico (www.ingenico.com). (We
|
|
11
|
+
now have two Web-based payment applications depending on Sparkly Auth.)
|
|
12
|
+
|
|
13
|
+
There is an ongoing battle between security and convenience. They say you can pick one, but not both. While
|
|
14
|
+
I'm not going to claim that Sparkly singlehandedly settles this dispute, I will say that Sparkly lets you choose
|
|
15
|
+
between varying shades of gray, rather than choosing between black and white. Sparkly Auth provides a plethora of
|
|
16
|
+
configuration options to let you apply a more user-friendly authentication solution to your site, while making
|
|
17
|
+
it crystal clear what the security tradeoff will be.
|
|
18
|
+
|
|
19
|
+
Sparkly supports multiple user models, multiple controllers, and all that jazz -- but doesn't force it on you.
|
|
20
|
+
A default value is provided for virtually every possible option, and the options are conveniently tucked away
|
|
21
|
+
in the class documentation -- there for you when you need it, but not breathing down your neck when you don't.
|
|
22
|
+
|
|
23
|
+
=== what does security mean?
|
|
24
|
+
|
|
25
|
+
So that's the high level overview. If you've read this far then maybe you're wondering exactly what kind of
|
|
26
|
+
authentication security Sparkly Auth brings to the table. Well, here's The List. Some other solutions out there
|
|
27
|
+
cover portions of it; others cover other portions. But I've yet to find one (besides Sparkly) that does it all.
|
|
28
|
+
|
|
29
|
+
One last disclaimer: all of this can be modified or disabled entirely. So don't think that because it's listed
|
|
30
|
+
here, dependencies HAVE to use it. I've got a number of side apps written that use Sparkly but, for example,
|
|
31
|
+
completely disable the password update policy.
|
|
32
|
+
|
|
33
|
+
* Enforces a strong password policy by default (7-digit uppercase, lowercase and numeric)
|
|
34
|
+
* Enforces a periodic password update (once every 30 days)
|
|
35
|
+
* Enforces a unique password (can't match any of the previous 4 passwords by default)
|
|
36
|
+
* Automatically signs the user out after 30 minutes of inactivity
|
|
37
|
+
* Provides secure single-access tokens for authentication without cookies (e.g. Web Service consumers)
|
|
38
|
+
* Locks an account for 30 minutes after 5 invalid login attempts
|
|
39
|
+
* Provides generators for controllers and views, so that you can add (or remove) layers quickly and painlessly
|
|
40
|
+
-- even on a per-model or per-controller basis, if your application uses more than one
|
|
41
|
+
* Allows you to change which parent controller has access to the logged-in user (defaults to ApplicationController)
|
|
42
|
+
* Behaviors (including even the core behavior) are plug-and-play and can be easily swapped in/out, and custom
|
|
43
|
+
behaviors can be added
|
|
44
|
+
* Encryption methods can be easily replaced
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
Since my own personal use cases for Sparkly Auth vary widely, so do its capabilities. Not only can the above
|
|
48
|
+
be disabled, but it also sports (for example) a "Remember Me" checkbox that would otherwise circumvent some
|
|
49
|
+
of the above precautions. Obviously, the checkbox is disabled by default.
|
|
50
|
+
|
|
51
|
+
== installation
|
|
52
|
+
|
|
53
|
+
In Rails 2, add "sparkly-auth" to your gem dependencies:
|
|
54
|
+
config.gem 'sparkly-auth'
|
|
55
|
+
|
|
56
|
+
In Rails 3, add "sparkly-auth" to your Gemfile:
|
|
57
|
+
gem 'sparkly-auth'
|
|
58
|
+
|
|
59
|
+
== setting up
|
|
60
|
+
|
|
61
|
+
(In the examples below, replace 'script/generate' with 'rails generate' if you're using Rails 3.)
|
|
62
|
+
|
|
63
|
+
For a step-by-step guide, run
|
|
64
|
+
|
|
65
|
+
script/generate sparkly help
|
|
66
|
+
|
|
67
|
+
Basically, the you have to run
|
|
68
|
+
|
|
69
|
+
script/generate sparkly config
|
|
70
|
+
script/generate sparkly migrations
|
|
71
|
+
|
|
72
|
+
and optionally (if you plan to override the controllers and/or views),
|
|
73
|
+
|
|
74
|
+
script/generate sparkly controllers
|
|
75
|
+
script/generate sparkly views
|
|
76
|
+
|
|
77
|
+
Assuming you have a User model (or that you've edited config/initializers/sparkly_authentication.rb to taste),
|
|
78
|
+
you should be ready to go!
|
|
79
|
+
|
|
80
|
+
You should take a quick gander at config/initializers/sparkly_authentication.rb just to see what's in there.
|
|
81
|
+
|
|
82
|
+
== routes
|
|
83
|
+
|
|
84
|
+
Unless you disable them, Sparkly Auth will automatically generate a set of routes for its controllers. Run
|
|
85
|
+
|
|
86
|
+
rake routes
|
|
87
|
+
|
|
88
|
+
and you should see something like this:
|
|
89
|
+
|
|
90
|
+
new_user_session GET /user/session/new(.:format)
|
|
91
|
+
edit_user_session GET /user/session/edit(.:format)
|
|
92
|
+
user_session GET /user/session(.:format)
|
|
93
|
+
PUT /user/session(.:format)
|
|
94
|
+
DELETE /user/session(.:format)
|
|
95
|
+
POST /user/session(.:format)
|
|
96
|
+
user_login /user/login
|
|
97
|
+
user_logout /user/logout
|
|
98
|
+
new_user GET /user/new(.:format)
|
|
99
|
+
edit_user GET /user/edit(.:format)
|
|
100
|
+
user GET /user(.:format)
|
|
101
|
+
PUT /user(.:format)
|
|
102
|
+
DELETE /user(.:format)
|
|
103
|
+
POST /user(.:format)
|
|
104
|
+
/:controller/:action/:id
|
|
105
|
+
/:controller/:action/:id(.:format)
|
|
106
|
+
|
|
107
|
+
This assumes you're authenticating against a single User model. Obviously, if you're authenticating against
|
|
108
|
+
a different model (or more than one), the routes will be changed to suit.
|
|
109
|
+
|
|
110
|
+
== migration
|
|
111
|
+
|
|
112
|
+
I'm working on rake tasks that help you migrate from other authentication solutions to Sparkly Auth, largely
|
|
113
|
+
because I had to do so myself. So without further ado, here's how you can do that:
|
|
114
|
+
|
|
115
|
+
=== Authlogic
|
|
116
|
+
|
|
117
|
+
After running the various Sparkly migrations, simply run:
|
|
118
|
+
|
|
119
|
+
rake auth:migrate:authlogic
|
|
120
|
+
|
|
121
|
+
Done.
|
|
122
|
+
|
|
123
|
+
If you've set up an Authlogic encryptor other than SHA512, you'll want to use that encryptor for Sparkly. In
|
|
124
|
+
this case, don't disable Authlogic the dependency (but DO remove the various hooks from your code), and in your
|
|
125
|
+
config/initializers/sparkly_authentication.rb file, add the following line:
|
|
126
|
+
|
|
127
|
+
config.encryptor = Authlogic::CryptoProviders::Wordpress # or whatever.
|
|
128
|
+
|
|
129
|
+
That should be it (it was for me). If you have any troubles, drop me a line so I can update this documentation!
|
|
4
130
|
|
|
5
131
|
== Note on Patches/Pull Requests
|
|
6
132
|
|
data/Rakefile
CHANGED
|
@@ -6,33 +6,47 @@ begin
|
|
|
6
6
|
Jeweler::Tasks.new do |gem|
|
|
7
7
|
gem.name = "sparkly-auth"
|
|
8
8
|
gem.summary = %Q{User authentication with Sparkles!}
|
|
9
|
-
gem.description = %Q{As fate would have it, I found other authentication solutions unable to suit my needs. So I rolled my own.}
|
|
9
|
+
gem.description = %Q{As fate would have it, I found other authentication solutions unable to suit my needs. So I rolled my own, totally supporting Rails 2 AND 3.}
|
|
10
10
|
gem.email = "sinisterchipmunk@gmail.com"
|
|
11
11
|
gem.homepage = "http://www.thoughtsincomputation.com"
|
|
12
12
|
gem.authors = ["Colin MacKenzie IV"]
|
|
13
|
-
gem.add_dependency "sc-core-ext", ">= 1.2.
|
|
13
|
+
gem.add_dependency "sc-core-ext", ">= 1.2.1"
|
|
14
14
|
gem.add_development_dependency 'rspec-rails', '>= 1.3.2'
|
|
15
15
|
gem.add_development_dependency 'webrat', '>= 0.7.1'
|
|
16
16
|
gem.add_development_dependency 'genspec', '>= 0.1.1'
|
|
17
17
|
gem.add_development_dependency 'email_spec', '>= 0.6.2'
|
|
18
18
|
# WHY does jeweler insist on using test/* files? THEY DON'T EXIST!
|
|
19
|
-
gem.test_files = FileList['spec/**/*']
|
|
19
|
+
gem.test_files = FileList['spec/**/*'] + FileList['spec_env/**/*'] + FileList['features/**/*']
|
|
20
20
|
end
|
|
21
21
|
Jeweler::GemcutterTasks.new
|
|
22
22
|
rescue LoadError
|
|
23
23
|
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
spec
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
26
|
+
begin
|
|
27
|
+
require 'spec/rake/spectask'
|
|
28
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
|
29
|
+
spec.libs << 'lib' << 'spec'
|
|
30
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
|
34
|
+
spec.libs << 'lib' << 'spec'
|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
|
36
|
+
spec.rcov = true
|
|
37
|
+
spec.rcov_opts = %w{--rails --exclude osx\/objc,gems\/,spec\/,features\/}
|
|
38
|
+
end
|
|
39
|
+
rescue LoadError
|
|
40
|
+
require 'rspec/core/rake_task'
|
|
41
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
|
42
|
+
spec.pattern = "spec/**/*_spec.rb"
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
|
46
|
+
spec.pattern = "spec/**/*_spec.rb"
|
|
47
|
+
spec.rcov = true
|
|
48
|
+
spec.rcov_opts = %w{--rails --exclude osx\/objc,gems\/,spec\/,features\/}
|
|
49
|
+
end
|
|
36
50
|
end
|
|
37
51
|
|
|
38
52
|
task :spec => :check_dependencies
|
|
@@ -46,5 +60,23 @@ Rake::RDocTask.new do |rdoc|
|
|
|
46
60
|
rdoc.rdoc_dir = 'rdoc'
|
|
47
61
|
rdoc.title = "sparkly-auth #{version}"
|
|
48
62
|
rdoc.rdoc_files.include('README*')
|
|
63
|
+
rdoc.rdoc_files.include('HISTORY*')
|
|
64
|
+
rdoc.rdoc_files.include('LICENSE*')
|
|
49
65
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
50
66
|
end
|
|
67
|
+
|
|
68
|
+
# Haven't got this working yet.
|
|
69
|
+
#namespace :spec do
|
|
70
|
+
# desc "runs specs, and if they pass, runs Rails2 specs and then Rails3 specs."
|
|
71
|
+
# task :all => [:spec, :rails2, :rails3]
|
|
72
|
+
#
|
|
73
|
+
# desc "runs Rails2 specs"
|
|
74
|
+
# task :rails2 do
|
|
75
|
+
# system("cd spec/support/rails2 && spec spec -c && cucumber")
|
|
76
|
+
# end
|
|
77
|
+
#
|
|
78
|
+
# desc "runs Rails3 specs"
|
|
79
|
+
# task :rails3 do
|
|
80
|
+
# system("cd spec/support/rails3 && rspec spec -c && cucumber")
|
|
81
|
+
# end
|
|
82
|
+
#end
|
data/TODO
ADDED
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.0
|
|
1
|
+
1.1.0
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
class SparklyAccountsController < SparklyController
|
|
2
|
-
unloadable
|
|
3
2
|
require_login_for :show, :edit, :update, :destroy
|
|
4
3
|
|
|
5
4
|
# GET new_model_url
|
|
@@ -9,8 +8,8 @@ class SparklyAccountsController < SparklyController
|
|
|
9
8
|
# POST model_url
|
|
10
9
|
def create
|
|
11
10
|
if model.save
|
|
12
|
-
login!(model)
|
|
13
|
-
redirect_back_or_default
|
|
11
|
+
login!(model) if sparkly_config.login_after_signup
|
|
12
|
+
redirect_back_or_default sparkly_config.default_destination, sparkly_config.account_created_message
|
|
14
13
|
else
|
|
15
14
|
render :action => 'new'
|
|
16
15
|
end
|
|
@@ -32,7 +31,7 @@ class SparklyAccountsController < SparklyController
|
|
|
32
31
|
end
|
|
33
32
|
|
|
34
33
|
if model.save
|
|
35
|
-
redirect_back_or_default user_path,
|
|
34
|
+
redirect_back_or_default user_path, sparkly_config.account_updated_message
|
|
36
35
|
else
|
|
37
36
|
render :action => 'edit'
|
|
38
37
|
end
|
|
@@ -43,17 +42,25 @@ class SparklyAccountsController < SparklyController
|
|
|
43
42
|
current_user && current_user.destroy
|
|
44
43
|
logout!
|
|
45
44
|
@current_user = nil
|
|
46
|
-
flash[:notice] =
|
|
47
|
-
redirect_back_or_default
|
|
45
|
+
flash[:notice] = sparkly_config.account_deleted_message
|
|
46
|
+
redirect_back_or_default sparkly_config.default_destination
|
|
48
47
|
end
|
|
49
48
|
|
|
50
49
|
protected
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
50
|
+
def find_user_model
|
|
51
|
+
# password fields are protected attrs, so we need to exclude them then add them explicitly.
|
|
52
|
+
self.model_instance = current_user || begin
|
|
53
|
+
model = model_class.new(model_params.without(:password, :password_confirmation))
|
|
54
|
+
model.password = model_params[:password]
|
|
55
|
+
model.password_confirmation = model_params[:password_confirmation]
|
|
56
|
+
model
|
|
58
57
|
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Uncomment if you don't trust the params[:model] set up by Sparkly routing, or if you've
|
|
61
|
+
# disabled them.
|
|
62
|
+
#
|
|
63
|
+
#def model_name
|
|
64
|
+
# "User"
|
|
65
|
+
#end
|
|
59
66
|
end
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
class SparklyController < (Auth.base_controller)
|
|
2
|
-
unloadable
|
|
3
2
|
helper_method :model_class, :model_instance, :model_name, :model, :model_path, :new_model_path, :edit_model_path,
|
|
4
|
-
:model_config, :model_session_path, :model_params
|
|
3
|
+
:model_config, :model_session_path, :model_params, :sparkly_config, :auth_config
|
|
5
4
|
before_filter :find_user_model
|
|
6
5
|
|
|
7
6
|
protected
|
|
@@ -36,12 +35,14 @@ class SparklyController < (Auth.base_controller)
|
|
|
36
35
|
end
|
|
37
36
|
|
|
38
37
|
def model_config
|
|
39
|
-
|
|
38
|
+
model_class.sparkly_config
|
|
40
39
|
end
|
|
41
40
|
|
|
42
41
|
def model_params
|
|
43
42
|
params[model_name.underscore] || {}
|
|
44
43
|
end
|
|
45
44
|
|
|
46
|
-
alias_method :model, :model_instance
|
|
45
|
+
alias_method :model, :model_instance
|
|
46
|
+
alias_method :auth_config, :model_config
|
|
47
|
+
alias_method :sparkly_config, :model_config
|
|
47
48
|
end
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
class SparklySessionsController < SparklyController
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
require_logout_for :new, :create
|
|
3
|
+
|
|
4
4
|
# GET new_model_session_url
|
|
5
5
|
def new
|
|
6
6
|
end
|
|
7
7
|
|
|
8
8
|
# POST model_session_url
|
|
9
9
|
def create
|
|
10
|
-
if session[:locked_out_at] && session[:locked_out_at] >
|
|
11
|
-
flash[:error] =
|
|
10
|
+
if session[:locked_out_at] && session[:locked_out_at] > sparkly_config.account_lock_duration.ago
|
|
11
|
+
flash[:error] = sparkly_config.account_locked_message
|
|
12
12
|
render :action => 'new'
|
|
13
13
|
return
|
|
14
14
|
end
|
|
@@ -18,14 +18,14 @@ class SparklySessionsController < SparklyController
|
|
|
18
18
|
|
|
19
19
|
if model && model.password_matches?(model_params[:password])
|
|
20
20
|
login! model, :remember => remember_me?
|
|
21
|
-
redirect_back_or_default
|
|
21
|
+
redirect_back_or_default sparkly_config.default_destination, sparkly_config.login_successful_message
|
|
22
22
|
else
|
|
23
23
|
session[:login_failures] = session[:login_failures].to_i + 1
|
|
24
|
-
if
|
|
24
|
+
if sparkly_config.max_login_failures && session[:login_failures] >= sparkly_config.max_login_failures
|
|
25
25
|
session[:locked_out_at] = Time.now
|
|
26
|
-
flash[:error] =
|
|
26
|
+
flash[:error] = sparkly_config.account_locked_message
|
|
27
27
|
else
|
|
28
|
-
flash[:error] =
|
|
28
|
+
flash[:error] = sparkly_config.invalid_credentials_message
|
|
29
29
|
end
|
|
30
30
|
render :action => "new"
|
|
31
31
|
end
|
|
@@ -34,10 +34,17 @@ class SparklySessionsController < SparklyController
|
|
|
34
34
|
# DELETE model_session_url
|
|
35
35
|
def destroy
|
|
36
36
|
logout!(:forget => true)
|
|
37
|
-
redirect_back_or_default
|
|
37
|
+
redirect_back_or_default sparkly_config.default_destination, sparkly_config.logout_message
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
private
|
|
41
|
+
# Uncomment if you don't trust the params[:model] set up by Sparkly routing, or if you've
|
|
42
|
+
# disabled them.
|
|
43
|
+
#
|
|
44
|
+
#def model_name
|
|
45
|
+
# "User"
|
|
46
|
+
#end
|
|
47
|
+
|
|
41
48
|
def remember_me?
|
|
42
49
|
remembrance = model_params[:remember_me]
|
|
43
50
|
if remembrance.kind_of?(String)
|
|
@@ -9,7 +9,9 @@ class RemembranceToken < ActiveRecord::Base
|
|
|
9
9
|
"#{authenticatable_type}|#{authenticatable_id}|#{series_token}|#{remembrance_token}"
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
before_validation :regenerate_remembrance_token
|
|
13
|
+
|
|
14
|
+
def regenerate_remembrance_token
|
|
13
15
|
regenerate if new_record?
|
|
14
16
|
end
|
|
15
17
|
|
|
@@ -0,0 +1,24 @@
|
|
|
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(model.new_record? ? "Sign up" : "Update Profile")%>
|
|
23
|
+
</p>
|
|
24
|
+
<%end%>
|