Compare commits

...

297 Commits

Author SHA1 Message Date
José Valim
e4902af15a Release 1.4.7 with a backward compatibility fix. 2011-09-22 11:51:58 +02:00
José Valim
ab9d856568 Add a deprecation warning for previous controller authorization style. 2011-09-22 11:51:09 +02:00
José Valim
dd1d128333 Edited lib/generators/templates/devise.rb via GitHub 2011-09-21 12:58:10 -07:00
José Valim
08a8d7bf51 Prepare for 1.4.6 2011-09-14 16:54:15 -07:00
José Valim
335d36088f Instead of depending on mapping.controller[:session], make it explicit when we allow auth from params. 2011-09-14 16:52:28 -07:00
José Valim
0b9a95e294 Allow --skip-routes to devise generator. 2011-09-14 16:52:28 -07:00
José Valim
98acc84111 Allow options to be passed to authenticate_user! 2011-09-14 16:52:28 -07:00
José Valim
261c01dfa3 Allow :skip => :all 2011-09-14 16:52:28 -07:00
José Valim
ea7f15917f Merge pull request #1322 from trollixx/patch-1
Typo
2011-09-09 03:01:54 -07:00
Oleg Shparber
df3e711ee0 Typo 2011-09-09 12:46:35 +03:00
José Valim
263e903046 Release v1.4.5 2011-09-08 23:55:27 +02:00
George Guimarães
f7bbac0ab9 sets travis to report to maintainers 2011-09-08 08:31:34 -03:00
José Valim
9ebcb691b0 Depend on jdbc master. 2011-09-08 09:05:06 +02:00
José Valim
601e1d3dc9 Update CHANGELOG. 2011-09-08 08:36:06 +02:00
José Valim
7b0a8f9bdc Also try the root route for convenience, closes #1312. 2011-09-08 08:32:05 +02:00
José Valim
dd36324756 No need to finalize Devise helpers all the time, closes #1317 2011-09-08 08:31:08 +02:00
José Valim
1b5d0af824 Merge pull request #1313 from jamescook/fix_bug_with_update_with_password
DatabaseAuthenticatable#clean_up_passwords should set accessors to nil
2011-09-02 10:48:47 -07:00
James Cook
edcca8cd3f DatabaseAuthenticatable#clean_up_passwords should set accessors to nil, not empty string. 2011-09-02 13:14:15 -04:00
José Valim
c95ca15b49 Edited lib/devise.rb via GitHub 2011-09-02 13:35:31 +03:00
José Valim
055117e07a Merge pull request #1308 from rymai/conditional_sign_in_after_password_reset
Implement #1306.
2011-09-01 00:19:56 -07:00
Rémy Coutable
ebbabaea5b After a password reset, don't show "You are now signed in." if the user can't be signed-in anyway. 2011-09-01 00:24:10 +02:00
José Valim
eba53f8f94 Test against 3.1.0. 2011-08-31 17:16:56 +02:00
José Valim
071f54ac59 Release v1.4.4 with a fix for those using :skip in routes. 2011-08-31 16:45:12 +02:00
José Valim
8796c1c601 Do not always skip helpers, instead provide :skip_helpers as option to trigger it manually 2011-08-31 12:02:57 +02:00
José Valim
ef4eb47d50 Release v1.4.3 with improve Rails 3.1 compatibility. 2011-08-30 14:35:19 +02:00
José Valim
295088f9e8 Depend on latest Rails. 2011-08-30 14:33:23 +02:00
José Valim
4222afe3c7 Tidy up latest commits, update CHANGELOG. 2011-08-30 10:50:40 +02:00
José Valim
79d89a3c20 Merge pull request #1297 from seanski/master
Patch for Issue 1259 -- New
2011-08-30 01:44:30 -07:00
Sean Hill
8ad414b217 Added a helper to look for an modifying migration. If one is found during :revoke, the modifying migration is deleted. If the modifying migration is not found, the creating migration is deleted. 2011-08-29 17:53:32 -05:00
José Valim
7b1418be3b Improve the regexp a bit more. 2011-08-29 14:55:56 +02:00
José Valim
7396c6911d Quack, quack, quack. Use duck typing instead of hardcoding everything, closes #1281. 2011-08-29 14:40:49 +02:00
José Valim
673c707085 Update CHANGELOG. 2011-08-29 14:31:09 +02:00
José Valim
f21d05a235 Only generate helpers for the used mappings, closes #1288 2011-08-29 14:29:38 +02:00
José Valim
1dd19c1a72 Wrap :actions constraints in the proper hash, closes #1280 2011-08-29 13:29:30 +02:00
José Valim
a8d9695324 Simplify regexp and ensure it runs against UTF8 chars, closes #1235 2011-08-29 13:15:40 +02:00
Sean Hill
99d539b9a7 Chagned the copy_devise_migration method to properly handle the :revoke behavior using @daf's commit: acf7e9e2ad as a guide. 2011-08-28 16:29:06 -05:00
Sean Hill
179cb2c88a Changed the order of the devise_generator methods to create the model after the migration to properly use model_exists?, and I added tests to prove the generator works. 2011-08-28 16:02:58 -05:00
Sean Hill
9629da863d Added a template to create a migration when the model already exists. Changed the generator code to check if model exists, and if it does, call the new template instead of the standard template. 2011-08-25 07:05:19 -05:00
José Valim
4f76e6f577 Depend on latest bcrypt. 2011-08-25 13:22:48 +02:00
José Valim
0f3cef4091 Merge pull request #1282 from apocalyptiq/master
Allow to set default 'from' header of Devise mails in custom mailer class
2011-08-20 13:48:45 -07:00
Szymon Przybył
7665cbf21d Allow to set default 'from' header of Devise mails in custom mailer class 2011-08-20 22:35:47 +02:00
José Valim
b9413ab316 Merge pull request #1275 from bquorning/it's_not_"it's",_it's_"its"
Fix usage of “its” / “it’s” in documentation
2011-08-16 15:20:01 -07:00
Benjamin Quorning
a3bff7d6a2 Fix usage of "its" / "it's" in documentation 2011-08-16 22:15:25 +02:00
José Valim
7e54dc7903 Edited lib/devise/models/lockable.rb via GitHub 2011-08-16 08:00:44 -07:00
José Valim
fb1220af97 Merge pull request #1264 from invisiblefunnel/master
Fixes small typo in routes documentation
2011-08-11 20:40:25 -07:00
Daniel Whalen
282c7e85ec Fix documentation typo 2011-08-11 20:16:20 -07:00
José Valim
bc15bb53dc Merge pull request #1261 from rumblestrut/patch-1
Changed "It's composed of 12 modules:" to "It's comprised of 12 modules .
2011-08-10 22:20:08 -07:00
Eric J. Gruber
a729e059de Changed "It's composed of 12 modules:" to "It's comprised of 12 modules ..." Comprised is the better word choice in this instance, meaning "Consist of; be made up of." 2011-08-10 21:46:52 -05:00
José Valim
7c628f7689 Merge pull request #1237 from novalis/master
friendly_token should be friendlier
2011-08-10 17:25:06 -07:00
David Turner
6d65c28f1f remove hard-to-distinguish characters from friendly_token 2011-08-10 12:44:30 -04:00
José Valim
31e4ef5e4b Merge pull request #1258 from wildchild/master
Don't require explicit scope in authenticate router extension
2011-08-10 05:23:29 -07:00
Alexander Uvarov
d38341b5e0 Don't require explicit scope in authenticate router extension 2011-08-10 15:41:06 +06:00
Rafael Mendonça França
ff90d9da9c Merge pull request #1251 from michaelklishin/patch-1
Re-add JRuby to the build matrix
2011-08-08 08:01:41 -07:00
Michael Klishin
84c62ed034 Re-add JRuby to the build matrix
We hopefully resolved our JRuby woes on travis-ci.org.
2011-08-07 20:55:59 +04:00
José Valim
e76ba05516 Merge pull request #1249 from ches/mongoid-fixes
Tests that should no longer exclude Mongoid
2011-08-06 08:21:48 -07:00
José Valim
90d99b16f1 Merge pull request #1250 from ches/unenforced-auth-keys
Fix optional enforcement of particular authentication keys
2011-08-06 08:20:30 -07:00
Ches Martin
3cedba1de8 Fix optional enforcement of particular authentication keys
Documentation states that authentication_keys should accept a hash with
values indicating whether or not each key is required. This was added in
b2066cc2 but tests only covered request_keys, and 29afe2d2 later broke
it with a << array operator.
2011-08-06 20:07:49 +07:00
Ches Martin
ccbf26be0a Tests that should no longer exclude Mongoid 2011-08-06 19:28:19 +07:00
José Valim
6448490de5 Edited lib/generators/templates/devise.rb via GitHub 2011-08-05 20:45:39 +03:00
José Valim
98651dae9d Merge pull request #1241 from dbloete/patch-1
Speed up tests by defaulting to 1 stretch in test env
2011-08-05 10:43:54 -07:00
José Valim
bf57ef400d Merge pull request #1247 from michaelklishin/patch-1
It is #rbxday, lets test against Rubinius 2.0 preview, too
2011-08-05 09:36:31 -07:00
Michael Klishin
27cae04446 It is #rbxday, lets test against Rubinius 2.0 preview, too 2011-08-05 20:34:33 +04:00
José Valim
430eadc1b2 Merge pull request #1245 from michaelklishin/patch-1
Disable testing against JRuby, it has known issues on travis-ci.org.
2011-08-05 09:31:36 -07:00
Michael Klishin
e954737a92 Disable testing against JRuby, it has known issues on travis-ci.org.
We will figure out JRuby issues with the JRuby core team and let you know
2011-08-05 16:26:11 +04:00
José Valim
191d5222e7 Merge pull request #1244 from ches/docs
Doc tweaks
2011-08-05 05:22:24 -07:00
Ches Martin
e77af4b40f Doc: DB authenticatable schema no longer includes salt 2011-08-05 20:13:01 +08:00
Ches Martin
da3c47259d Doc: DB authenticatable schema no longer includes salt 2011-08-05 17:33:50 +07:00
Ches Martin
c95575b284 Doc: DatabaseAuthenticatable still uses pepper option 2011-08-05 17:08:26 +07:00
José Valim
7a5086a2be Merge pull request #1242 from ches/mongoid-fixes
Fix failing Mongoid tests
2011-08-04 13:38:57 -07:00
Ches Martin
c3a665320e Merge branch 'master' into mongoid-fixes
* master:
  Untrack Gemfile.lock

Conflicts:
	Gemfile.lock
2011-08-05 03:19:05 +07:00
Dennis Reimann
372dfecf05 Added a comment about the stretch change 2011-08-04 23:00:12 +03:00
Dennis Reimann
68bd6809a7 Speed up tests by defaulting to 1 stretch in test env 2011-08-04 22:50:06 +03:00
Ches Martin
7bfdd07a71 Initializer caveats warning for Mongoid < 2.1 2011-08-05 02:41:31 +07:00
Ches Martin
6bc93173f1 Restore forlorn Mongoid generator tests 2011-08-05 02:40:42 +07:00
Ches Martin
55af9f8a40 Fix failing Mongoid tests
- attr_accessible not set for test user model, making Serializable tests
  inaccurate
- Mongoid does not `include_root_in_json` by default, so enable this for
  consistency with AR tests
- Mark tests pending for Mongoid < 2.1 that fail there due to known bugs
- Add `:mongoid` key for i18n model labels
- Remove outdated shim of `update_attribute` that caused mass assignment
  security to be applied (ugh, that took awhile to find)
2011-08-05 01:38:42 +07:00
José Valim
866b35d27c Merge pull request #1239 from ches/gemfile-lock
Untrack Gemfile.lock
2011-08-04 04:16:50 -07:00
Ches Martin
5374119f18 Untrack Gemfile.lock
Gemfile.lock is for app deployment, not public library development:

http://yehudakatz.com/2010/12/16/clarifying-the-roles-of-the-gemspec-and-gemfile/
2011-08-04 11:33:53 +07:00
José Valim
919404df53 Merge pull request #1228 from dasil003/master
Set up Recoverable to automatically confirm! if Comfirmable
2011-08-02 12:41:09 -07:00
Gabe da Silveira
fd07c74578 Refactor to use method and override 2011-08-02 12:08:38 -07:00
José Valim
560961e3fc Merge pull request #1233 from asanghi/master
sign_in should return true and assert that. fixes #1232
2011-08-02 03:04:51 -07:00
Aditya Sanghi
873e49ab66 sign_in should return true in case user is already signed in and assert that. 2011-08-02 14:35:46 +05:30
José Valim
0f8f786f9f Use a default key on inactive reason. 2011-08-02 11:18:23 +03:00
José Valim
7b3e267729 Merge pull request #1231 from hck/master
added I18n support to inactive_message in RegistrationsController
2011-08-02 01:14:16 -07:00
hck
7264bb55b2 added I18n support to inactive_message in RegistrationsController 2011-08-02 08:11:25 +03:00
Gabe da Silveira
ed6dfed67f Resetting password should confirm implicitly 2011-07-29 14:26:19 -07:00
Gabe da Silveira
3488066031 Spelling correction 2011-07-29 14:17:31 -07:00
José Valim
bc9ea93f50 Merge pull request #1224 from gtalton/patch-2
Edited lib/devise/rails/routes.rb via GitHub
2011-07-29 03:18:40 -07:00
Gerald Talton
1920b79a0d Edited lib/devise/rails/routes.rb via GitHub 2011-07-28 15:23:23 -05:00
José Valim
9131570703 Merge pull request #1221 from hazah/master
Change :except to :only for registration routes
2011-07-26 10:45:36 -07:00
=
770c1a973f Changed :except to :only for devise_registration method of the routing mapper. 2011-07-26 13:42:00 -04:00
José Valim
b7b21a0b72 Merge pull request #1211 from mathieuravaux/master
Issue #1206 fix ((TokenAuthenticatable#params_auth_hash behavior)
2011-07-25 05:11:26 -07:00
Mathieu Ravaux
4d91fb4910 Untangled the logic in Devise::Strategies::TokenAuthenticatable#params_auth_hash 2011-07-25 09:10:25 +02:00
Rafael Mendonça França
4ce9d6f29a Merge pull request #1212 from mattupstate/patch-1
Typo in doc comment
2011-07-23 15:06:02 -07:00
Matt Wright
d2a4c503f7 Typo in doc comment 2011-07-23 15:03:10 -07:00
Mathieu Ravaux
a2700bc17f Fixed issue #1206: TokenAuthenticatable#params_auth_hash behaving in an unexpected way for the authentication token lookup 2011-07-23 17:45:45 +02:00
José Valim
0a04d73883 Merge pull request #1198 from andriytyurnikov/issue_1197
div instead of p in forms
2011-07-14 05:47:46 -07:00
Andriy Tyurnikov
502dae3c1f div instead of p in forms 2011-07-14 15:43:10 +03:00
José Valim
e9c766277d Merge pull request #1194 from waynn/patch-1
quick typo fix
2011-07-11 11:37:18 -07:00
Waynn Lue
762f3907fa quick typo fix 2011-07-11 11:30:52 -07:00
José Valim
3698b64a10 Merge pull request #1190 from joliss/whitespace
Remove whitespace from generator template
2011-07-08 11:25:35 -07:00
Jo Liss
2a6c160d39 Remove whitespace from generator template 2011-07-08 18:41:16 +02:00
José Valim
795754cd60 Merge pull request #1189 from netmute/master
Add ability to override redirect_to path after account confirmation.
2011-07-08 03:27:21 -07:00
Simon Ernst
517343ddb5 Add ability to override redirect_to path after account confirmation. 2011-07-08 11:21:01 +02:00
Rodrigo Flores
90a5e2f9af Added rdoc on the Gemfile 2011-07-02 01:33:34 -03:00
Rodrigo Flores
93180fbb6d Removed a rdoc deprecation warning 2011-07-01 20:37:21 -03:00
José Valim
04cb78947a Edited CHANGELOG.rdoc via GitHub 2011-07-01 04:23:31 -07:00
José Valim
5423f2d5cb Properly deprecate setup_mail 2011-07-01 04:23:12 -07:00
José Valim
51d15b7293 Add more missing :require => true 2011-06-30 15:29:35 -03:00
José Valim
7a2e018df8 Release 1.4.2. 2011-06-30 15:20:13 -03:00
José Valim
1fd4beb18a Move simple_form_for directories to a new location. 2011-06-30 15:09:54 -03:00
José Valim
33d7644b4f Provide a more robust behavior to serializers and add :force_except option 2011-06-30 10:43:33 -03:00
José Valim
5a98e4f4e8 Temporary fix for 3-1-stable that does not implement key? on cookie jar, closes #1179 2011-06-30 08:04:32 -03:00
José Valim
82ae53dd75 Released v1.4.1. 2011-06-29 20:26:35 -03:00
José Valim
07db04e773 Work around AR that does not call serializable_hash on to_xml. 2011-06-29 20:18:10 -03:00
José Valim
6a8ee475fd This was fixed in mongoid, closes #770. 2011-06-29 20:18:10 -03:00
José Valim
767a7a7c21 Ensure handle_unverified_request clean up any cached signed-in user 2011-06-29 20:18:10 -03:00
José Valim
a3b56f7eb1 Merge pull request #1175 from jhllnd/patch-1
Added :registerable to the examples
2011-06-28 04:58:51 -07:00
jhllnd
5e1a998cde Added :registerable to the examples 2011-06-28 03:19:00 -07:00
José Valim
219fbc0056 Fix tests, remove whitespace and update CHANGELOG. 2011-06-28 07:05:35 -03:00
José Valim
dcee6413f4 Merge pull request #1173 from zedtux/master
Internationalization of resource_name in DeviseHelper#devise_error_messages!
2011-06-28 02:58:15 -07:00
Guillaume Hain
e2895239d8 Internationalization of resource_name in DeviseHelper#devise_error_messages! 2011-06-27 20:31:03 +02:00
José Valim
c8077c8d9f Add more docs to routes. 2011-06-27 13:04:40 -03:00
José Valim
46c2d5a8f2 Update CHANGELOG. 2011-06-27 12:16:06 -03:00
José Valim
adb127bb3e Default to delete on new templates. 2011-06-27 12:15:23 -03:00
José Valim
42f0285278 Extract mailer functionality, closes #1164 2011-06-27 12:13:00 -03:00
José Valim
13ef23f517 Add simple form generators. 2011-06-27 11:50:28 -03:00
José Valim
0bf28b19ab Simple use hook_for. 2011-06-27 11:31:29 -03:00
José Valim
29a0af78bc Refactor view generators. 2011-06-27 11:22:44 -03:00
José Valim
cf487c771e Merge pull request #1172 from bjnord/format-false
More transparent implementation of :format => false
2011-06-27 05:15:05 -07:00
Brent J. Nordquist
7e711089a8 More transparent implementat'n of :format => false
Per josevalim, by setting {:format => false} in @scope[:options],
Rails will pick it up, without the need to alter each devise_*()
method individually.
2011-06-27 06:51:04 -05:00
Brent J. Nordquist
1c81a40a76 Support options[:defaults] and @scope[:defaults]
similar to support for :constraints
2011-06-26 19:48:20 -05:00
Rodrigo Flores
dba8f91f99 \o/ Bumping to 1.4.0 \o/ 2011-06-23 09:53:05 -03:00
José Valim
8e70e71143 Update CHANGELOG. 2011-06-23 09:42:32 -03:00
José Valim
f43a7c4f24 Merge pull request #1147 from sj26/master
Authenticated Route Constraints
2011-06-23 05:29:17 -07:00
José Valim
4e56d92ed8 Override serializable_hash instead of to_xml and to_json. 2011-06-23 09:25:50 -03:00
José Valim
5645d733ba Update CHANGELOG. 2011-06-23 09:22:30 -03:00
José Valim
42b07f1f47 Merge remote branch 'origin/issue_json_response'
Conflicts:
	app/controllers/devise/passwords_controller.rb
2011-06-23 09:16:04 -03:00
Samuel Cochran
e75354b3b0 Tests. 2011-06-23 10:44:46 +08:00
Samuel Cochran
80122856c4 Switch to Warden::Proxy#authenticate?
Warden::Proxy#authenticated? and Warden::Proxy#unauthenticated? don't try strategies first.
2011-06-23 10:44:23 +08:00
Rodrigo Flores
308238ab42 Not responding the object on creating unlockable requests 2011-06-22 23:04:55 -03:00
Rodrigo Flores
e937cf78cf Added a test for empty json on unlockable controller response 2011-06-22 23:00:15 -03:00
Rodrigo Flores
2ae2fdc9f8 Returning an empty JSON for creating confirmation requests 2011-06-22 21:27:20 -03:00
Rodrigo Flores
3184834d72 Added tests for confirmable 2011-06-22 21:26:32 -03:00
Rodrigo Flores
8ef5534d92 Moved the test to after the XML tests 2011-06-22 21:04:50 -03:00
Rodrigo Flores
41bb96be5d Returning empty json and empty xml 2011-06-22 19:38:21 -03:00
Rodrigo Flores
b37055fa47 Added a test to return empty json 2011-06-22 19:38:21 -03:00
José Valim
515b727f52 Change default rake. 2011-06-22 15:39:50 -03:00
José Valim
77d6d1e8c2 Do not try to authenticate with no_input_strategies are empty. 2011-06-22 15:28:49 -03:00
José Valim
04b614ce10 Edited app/controllers/devise/passwords_controller.rb via GitHub 2011-06-22 11:03:08 -07:00
José Valim
62e11ddbe4 Update CHANGELOG. 2011-06-22 13:07:19 -03:00
Rodrigo Flores
8e3ab5921f Merge branch 'paranoid-mode' 2011-06-22 12:57:37 -03:00
Rodrigo Flores
1d87997647 Improved paranoid mode generator explanation 2011-06-22 12:52:11 -03:00
Rodrigo Flores
b58e0ef991 Removed useless blank lines 2011-06-22 12:52:11 -03:00
Rodrigo Flores
db959da247 Added a commented line for paranoid mode on generator 2011-06-22 12:52:11 -03:00
Rodrigo Flores
6199252011 Refactored paranoid mode actions for it to appear once 2011-06-22 12:52:11 -03:00
Rodrigo Flores
40c0a7b50b Added paranoid mode to lockable 2011-06-22 12:52:11 -03:00
Rodrigo Flores
422bc4aaa6 Added tests for lockable 2011-06-22 12:52:11 -03:00
Rodrigo Flores
225c89fbf1 Paranoid mode on confirmable 2011-06-22 12:52:10 -03:00
Rodrigo Flores
76281ff15c Added tests for paranoid mode on confirmable 2011-06-22 12:52:10 -03:00
Rodrigo Flores
8b54ff699f Refactoring passwords controller 2011-06-22 12:52:10 -03:00
Rodrigo Flores
7d160650b8 Using the same url in success and failure 2011-06-22 12:52:10 -03:00
Rodrigo Flores
803e46cda7 Refactoring the paranoid controller 2011-06-22 12:52:10 -03:00
Rodrigo Flores
004fe2ad12 Paranoid mode for recoverable 2011-06-22 12:50:34 -03:00
Rodrigo Flores
09baf2091e Refactored the tests to use swap 2011-06-22 12:50:34 -03:00
Rodrigo Flores
135a94b4f7 Added a test for the paranoid mode on recoverable 2011-06-22 12:50:34 -03:00
José Valim
a41d185768 Merge pull request #1158 from crx/validate_after_failing_pw_change
Run validations even when password change will fail
2011-06-22 02:28:06 -07:00
Chase DuBois
c3432e57b1 Test for previous commit 2011-06-21 20:45:07 -04:00
Chase DuBois
a8d88d193e Run validations even when password change will fail, to show a complete list of errors 2011-06-21 17:55:32 -04:00
Samuel Cochran
471e4d6e72 Oh hey, Warden has API for this. Should probably match the name, too. 2011-06-21 08:36:06 +08:00
Samuel Cochran
14fec4cfb3 Add #authenticated and #not_authenticated route constraints 2011-06-18 15:53:46 +08:00
José Valim
4bcd1c6fcd Add script so we can skip mongoid tests. 2011-06-17 11:04:15 -03:00
José Valim
84e1a89c44 Fix failing tests. 2011-06-17 10:46:39 -03:00
José Valim
e0162df465 Merge pull request #1145 from macmartine/master
Added support for Devise routes to honor constraints.
2011-06-17 06:27:05 -07:00
Mac Martine
7631456047 Added support for Devise routes to honor constraints. 2011-06-16 21:24:20 -07:00
José Valim
2bc51ab2bd Merge pull request #1143 from joshk/patch-1
the script section in the travis yml isn't needed
2011-06-16 08:21:45 -07:00
Josh Kalderimis
d23ecef831 the script section in the travis yml isn't needed as this is the default behavior 2011-06-16 07:44:50 -07:00
José Valim
c0017ce76d Merge pull request #1138 from fschwahn/update_without_password
added update_without_password method, closes #801
2011-06-15 10:45:18 -07:00
José Valim
30f9da9d71 Update CHANGELOG. 2011-06-10 11:14:08 +02:00
José Valim
e242ca0937 Fix failing tests. 2011-06-10 11:10:56 +02:00
José Valim
17596b0dc6 Merge pull request #1126 from swrobel/master
Add option to strip extra whitespace from emails or other fields
2011-06-10 01:45:43 -07:00
Stefan Wrobel
8e87a2d80d Add strip_whitespace_keys which works like case_insensitive_keys but strips whitespace from emails 2011-06-10 01:37:43 -07:00
José Valim
4964f53a42 Merge pull request #1092 from xavier/filterwhitelist
Conditional string conversion of auth params (Closes #1079)
2011-06-08 08:39:53 -07:00
José Valim
6250fa8529 Revert "Merge pull request #1103 from Mab879/master"
This reverts commit 944e1c0378, reversing
changes made to 97659a1193.
2011-06-08 17:37:49 +02:00
José Valim
944e1c0378 Merge pull request #1103 from Mab879/master
Controller Generator
2011-06-08 08:34:07 -07:00
Matthew Burket
4f446241a4 Added Controller Generator and tests to go along with it. 2011-05-30 23:07:20 -05:00
José Valim
97659a1193 Merge pull request #1099 from paulbellamy/master
Changing references to SecureRandom in generators and encryptable_test
2011-05-28 07:52:09 -07:00
Paul Bellamy
0bcf71f8df Rails has removed SecureRandom from ActiveSupport in Rails 3.2,
deprecated

* Changing references in generators and encryptable_test
2011-05-28 14:44:54 +01:00
Xavier Defrang
ab3bb9cf4d Conditional string conversion of auth params (Closes #1079) 2011-05-26 15:45:03 +02:00
José Valim
69126a31db Merge pull request #1052 from Thibaut/email-validation
Don't validate email format and uniqueness unless it's changed
2011-05-26 05:24:45 -07:00
José Valim
03e3803cff Merge pull request #1089 from skojin/master
support for named/dedicated openid
2011-05-24 13:33:32 -07:00
Sergey Kojin
58f8c7c613 support for named omniauth open_id strategies 2011-05-25 00:15:24 +04:00
José Valim
acd1c76c3b Merge pull request #1087 from eMxyzptlk/patch-2
Rails has removed SecureRandom from ActiveSupport in Rails 3.2, deprecated
2011-05-23 23:49:59 -07:00
Wael Nasreddine
4c8cc5e3f3 SecureRandom is available since Ruby 1.8.7, remove the unnecessary defined? check. 2011-05-24 08:29:15 +02:00
Wael Nasreddine
72bb33f962 Rails has remove SecureRandom from ActiveSupport in Rails 3.2, deprecated in 3.1
Since it has been deprecated, this patch favors SecureRandom on ActiveSupport::SecureRandom
2011-05-23 15:34:09 -07:00
José Valim
2e61e52520 Fix failing test. 2011-05-23 18:22:32 +02:00
José Valim
75490d0375 Merge pull request #1085 from pechkin/master
Devise.mailer
2011-05-23 08:05:38 -07:00
Artem Pechenyi
0fbe4cb6b9 fix reference storage to support new and old class cache api 2011-05-23 17:29:10 +03:00
José Valim
d2b3f49384 Merge pull request #1067 from naomik/master
added ability to override redirect_to path after sending reset password instructions
2011-05-20 11:12:35 -07:00
José Valim
136992b8df Merge pull request #1070 from joshk/filter_auth_params_fix
dup the conditions hash before calling filter_auth_params, this fixes an
2011-05-20 11:07:34 -07:00
José Valim
a130f848f2 Let's run on rubinius again. 2011-05-18 14:13:33 -04:00
Josh Kalderimis
e10bc9e3c0 dup the conditions hash before calling filter_auth_params, this fixes an issue with reseting your password when using a custom auth field like login 2011-05-16 14:08:22 -04:00
naomi
d56741ca4f added ability to override redirect_to path after sending reset password instructions 2011-05-13 11:39:11 -05:00
Thibaut
92c9ed2d6c Don't validate email format and uniqueness unless it's changed. 2011-05-07 19:02:44 +02:00
José Valim
50a5ad54ce Merge pull request #1051 from rymai/patch-1
Remove :anybody_signed_in? from the controller helpers
2011-05-06 02:59:59 -07:00
Rémy Coutable
9dcb44ba61 :anybody_signed_in? helper was deprecated in 73669e09c8 and removed in fe5ef25614 but not removed from the #helper_method call. 2011-05-06 02:46:23 -07:00
fabian
8bdc4b544f added update_without_password method 2011-05-05 09:24:21 +02:00
José Valim
e763f843c4 Tests pass on 3.0.7 2011-05-04 19:24:11 +02:00
José Valim
b5732e31c6 Bump to 3.0.7. 2011-05-04 19:24:11 +02:00
José Valim
ea24ffdd51 Merge pull request #1046 from fschwahn/do-not-follow.
respect do not track headers in trackable
2011-05-04 06:29:52 -07:00
fabian
56f7fbf2d1 use 'devise.skip_trackable' instead of DNT headers 2011-05-04 15:21:12 +02:00
fabian
89b53ea39c respect do not track headers in trackable 2011-05-04 14:44:37 +02:00
Hugo Baraúna
9cc69277bc Fixes a little typo. 2011-04-29 11:26:12 -07:00
José Valim
7e79ed6d4e Update CHANGELOG. 2011-04-29 14:17:33 +02:00
José Valim
b5190d8df2 Refactor. 2011-04-29 14:11:47 +02:00
José Valim
b03c93c4fe Merged pull request #1041 from ecarnevale/master.
fix for issues #999: HTTP_ACCEPT=*/* should redirect to the default location
2011-04-29 05:03:50 -07:00
Emanuel Carnevale
8e12ddf7ed fix for issues #999: HTTP_ACCEPT=*/* should redirect to the default location 2011-04-29 13:22:52 +02:00
José Valim
4fd866d113 User cannot access sign up and similar pages if he is already signed in through a cookie or token, closes #1036. 2011-04-29 08:56:57 +02:00
José Valim
a59410a254 password_required? should not affect length validation, closes #1037. 2011-04-29 08:33:33 +02:00
José Valim
b1a27ad633 Allow controllers to be given as symbols. 2011-04-25 10:00:28 +02:00
Chase DuBois
4a3ad7f348 Use updated Mongoid gem and remove #destroyed? 2011-04-25 15:50:00 +08:00
Chase DuBois
89e4ab8a45 Moved check against record deletion into forget_me! method in model; added unit test. 2011-04-25 15:49:59 +08:00
Chase DuBois
fd8e34650e Make copy of resource only for update action 2011-04-25 15:49:59 +08:00
Chase DuBois
e26c8ce499 Use #persisted? instead of #frozen? to check whether #forget_me should attempt to clear remember token from database 2011-04-25 15:49:59 +08:00
José Valim
64cf8a4534 Update CHANGELOG. 2011-04-21 19:20:48 +02:00
José Valim
ae976f60ca Mark the token as expired, because invalid gives no clue of what to do next. 2011-04-21 19:17:33 +02:00
José Valim
f152860bc5 Update CHANGELOG. 2011-04-21 14:00:47 +02:00
José Valim
40153b7422 Add tests to previous commit. 2011-04-21 13:56:10 +02:00
Alexander Dreher
fdfe6a8340 Fixes error on missing reset_password_sent_at column.
If the column is not present, you are unabled to reset your password.
2011-04-21 19:51:12 +08:00
Carlos Antonio da Silva
79c100008a Remove old OmniAuth test helpers 2011-04-19 13:13:29 -03:00
José Valim
f132c7891b Update CHANGELOG, bump to 1.4.0.dev. 2011-04-19 14:24:33 +02:00
José Valim
bdad984ace Use Devise::Email::EXACT_PATTERN. 2011-04-19 14:22:14 +02:00
Rodrigo Flores
a229627a54 Removed failing test cases on e-mail validations 2011-04-19 20:16:20 +08:00
Rodrigo Flores
0b598cf132 Changed the e-mail validation regex 2011-04-19 20:16:19 +08:00
Rodrigo Flores
0e657eece1 Added email validation regexes 2011-04-19 20:16:19 +08:00
José Valim
b6cf1df659 Release 1.3.1. 2011-04-19 10:39:56 +02:00
José Valim
29afe2d21c Other minor improvements in the REST code. 2011-04-19 08:36:52 +02:00
José Valim
a722c6236c to_json does not guarantee the order. 2011-04-18 13:03:31 +02:00
José Valim
14aedc416a Wording. 2011-04-18 10:03:39 +02:00
José Valim
9fe0cb4954 use @example.com 2011-04-18 10:00:00 +02:00
SixArm
2a5669967f Change test email addresses to ues RFC 2606 reserved domain example.com 2011-04-18 15:59:13 +08:00
durrantm
13376d22de Edited README.rdoc via GitHub 2011-04-18 15:58:40 +08:00
José Valim
6b21531916 Update CHANGELOG. 2011-04-18 09:56:44 +02:00
José Valim
4a4dcb30ef sessions/new also responds to xml and json now 2011-04-18 09:56:24 +02:00
José Valim
2cfa58b433 Create shared_helpers for duplicated logic in Devise controllers and failure app. 2011-04-17 19:43:54 +02:00
José Valim
c6dd846718 Move the catch to the test level. 2011-04-17 19:37:19 +02:00
José Valim
7a2d76d002 Update changelog, improve coverage. 2011-04-17 18:06:29 +02:00
Andre Arko
e5a8febe3b Change the XML error tag from <hash> to <errors>. Makes way more sense. 2011-04-17 23:54:06 +08:00
Steve Hodgkiss
60809719b8 Fix bug when the reset_password_sent_at field doesn't exist generate_password_token returns nil causing the token not to be saved. 2011-04-17 23:53:50 +08:00
José Valim
ee6a8ab93a Temporarily remove rubinius because C extensions are not compiling. 2011-04-17 00:57:02 -07:00
Juan M. Cuello
c3d92095f8 Update README.
Replace success/failure with notice/alert in I18n section.
2011-04-17 15:15:49 +08:00
José Valim
460beae671 Release 1.3.0. 2011-04-16 13:31:50 +02:00
José Valim
fa6c8ab321 Use inflector to avoid conflicts. 2011-04-16 13:30:15 +02:00
José Valim
d02f86bef5 Update changelog. 2011-04-16 13:19:29 +02:00
José Valim
0d74c1b4f0 Move it to the junk drawer. :) 2011-04-16 13:18:28 +02:00
José Valim
8f3539c14f Don't include the same module several times, closes #765. 2011-04-16 13:16:47 +02:00
José Valim
3d5e692c2c Update CHANGELOG. 2011-04-16 13:16:47 +02:00
Jack Dempsey
cb622e99d8 create new integration test file for flash related tests 2011-04-16 19:16:34 +08:00
Jack Dempsey
567d59e48a update verbiage to be more concise 2011-04-16 19:16:33 +08:00
Jack Dempsey
f89f71262d require_no_authentication now sets flash with I18n message 2011-04-16 19:16:33 +08:00
José Valim
5e2ee5eb6a Downcase keys before validation. 2011-04-16 12:52:59 +02:00
José Valim
34a54dac2d Simply check instead or rescueing. 2011-04-16 12:43:43 +02:00
Mikel Lindsaar
e329930a82 Update DatabaseAuthenticatable#valid_password? to not raise error on empty password
Signed-off-by: José Valim <jose.valim@gmail.com>
2011-04-16 12:41:49 +02:00
José Valim
3940846d79 Update CHANGELOG. 2011-04-15 10:58:27 +02:00
José Valim
c608fbe89e Rollback to require 'test_helper'. If you want to run it in isolation, do ruby -Itest path/to/test/file. 2011-04-15 10:48:44 +02:00
Matias Korhonen
8db00eedea Bump the password maximum length to 128 characters. 2011-04-15 16:39:01 +08:00
John Wilger
0e904dda79 Make it possible to unit-test extensions to Devise::SessionsController
This time with tests
2011-04-15 16:37:15 +08:00
John Wilger
e4af6adaf7 Added test showing previously incorrect behavior of Devise::SessionsController#create 2011-04-15 16:37:15 +08:00
John Wilger
e1c7c49a0c Fix test_helper require so file can be run individually 2011-04-15 16:37:14 +08:00
Hiroki Yoshioka
bd9f148d24 Allow to override the path after resending confirmation instructions. 2011-04-15 16:32:41 +08:00
José Valim
f009011179 Update docs. 2011-04-15 10:31:58 +02:00
Timo Schilling
5adb854aa5 add devise_for :only option
Signed-off-by: José Valim <jose.valim@gmail.com>
2011-04-15 10:31:01 +02:00
José Valim
1f51524bae Edited README.rdoc via GitHub 2011-04-11 01:26:36 -07:00
Casper Klenz-Kitenge
23f8dbed80 Removed notice about using Devise from the git repo, for OAuth support. 2011-04-11 16:24:39 +08:00
José Valim
140acfe4cc Improve error message, closes #974. 2011-04-09 22:52:31 +02:00
Jared Beck
cb2cb2cff7 more helpful message re: secret_token 2011-04-10 04:47:55 +08:00
José Valim
30300fc6b9 Add a test that ensures validation options work. 2011-04-09 22:47:06 +02:00
José Valim
de8982563a Always use :erb. 2011-04-05 22:06:27 +02:00
Kim Joar Bekkelund
e7154b3af9 Add missing action to root_path in readme
On ruby-1.9.2-p136 I got the following error when using `root :to => "home"`:

    actionpack-3.0.5/lib/action_dispatch/routing/mapper.rb:171:in `default_controller_and_action': missing :action (ArgumentError)

Specifying the action solves the problem.
2011-04-05 05:47:10 +08:00
Josh Kalderimis
39360dc419 lets have travis test against many rubies 2011-04-05 02:35:28 +08:00
José Valim
eeb61929ac Be sure request.format is not nil (only reproducible in Rails < 3.0.4). 2011-04-04 07:04:32 -07:00
José Valim
56fd7031e5 Edited lib/generators/devise/views_generator.rb via GitHub 2011-04-04 02:48:41 -07:00
José Valim
425fe7f22d Remove old autoload. 2011-04-01 02:42:06 -07:00
José Valim
ed51fc7636 Tidy up previous commits. 2011-03-30 15:35:38 +02:00
Jean-Daniel Guyot
d23a7ca8d5 Copy-paste error 2011-03-30 21:11:34 +08:00
Jean-Daniel Guyot
1b1dc2a429 typo 2011-03-30 21:11:34 +08:00
Jean-Daniel Guyot
be2aeee70f Add reset_password_within configuration variable. 2011-03-30 21:11:33 +08:00
José Valim
8a3deb98cd Add a descriptive text for those upgrading. 2011-03-30 14:40:03 +02:00
José Valim
e4902143f8 Ensure configuration options are allowed exactly after each module is included. 2011-03-30 14:33:56 +02:00
José Valim
d3a374777b Update CHANGELOG 2011-03-30 14:10:59 +02:00
José Valim
5b94d9b803 Refactor a bit navigational format responses, to not call to_sym and reuse the request_format logic from FailureApp. 2011-03-30 14:09:12 +02:00
Prem Sichanugrist
b6652abc7c Add navigational_formats internal helper which filters out wildcard
Signed-off-by: José Valim <jose.valim@gmail.com>
2011-03-30 13:43:57 +02:00
Prem Sichanugrist
97f0bacfa0 Add support for non-navigational formats in PasswordsController
Signed-off-by: José Valim <jose.valim@gmail.com>
2011-03-30 13:39:08 +02:00
Prem Sichanugrist
210bc6aa66 Add support for non-navigational formats in UnlocksController
Signed-off-by: José Valim <jose.valim@gmail.com>
2011-03-30 13:38:16 +02:00
Prem Sichanugrist
8170d5e340 Add support for non-navigational formats in ConfirmationsController
Signed-off-by: José Valim <jose.valim@gmail.com>
2011-03-30 13:38:00 +02:00
Prem Sichanugrist
6225902034 Add support for non-navigational formats in RegistrationsController
Signed-off-by: José Valim <jose.valim@gmail.com>
2011-03-30 13:37:41 +02:00
Prem Sichanugrist
0487e9eafe Add support for destory_user_session_path in another non-navigational formats such as JSON and XML
Signed-off-by: José Valim <jose.valim@gmail.com>
2011-03-30 13:36:50 +02:00
José Valim
73669e09c8 Remove deprecations, bump to .dev and update template. 2011-03-28 21:26:53 +02:00
123 changed files with 2487 additions and 754 deletions

4
.gitignore vendored
View File

@@ -7,4 +7,6 @@ coverage/*
rdoc/*
pkg
log
test/tmp/*
test/tmp/*
Gemfile.lock

View File

@@ -1 +1,12 @@
script: "rake test"
script: "bundle exec rake test"
rvm:
- 1.8.7
- 1.9.2
- ree
- rbx
- rbx-2.0
- jruby
notifications:
recipients:
- jose.valim@plataformatec.com.br
- carlos@plataformatec.com.br

View File

@@ -1,3 +1,128 @@
== 1.4.7
* bug fix
* Fix backward incompatible change from 1.4.6 for those using custom controllers
== 1.4.6
* enhancements
* Allow devise_for :skip => :all
* Allow options to be passed to authenticate_user!
* Allow --skip-routes to devise generator
* Add allow_params_authentication! to make it explicit when params authentication is allowed in a controller
== 1.4.5
* bug fix
* Failure app tries the root path if a session one does not exist
* No need to finalize Devise helpers all the time (by github.com/bradleypriest)
* Reset password shows proper message if user is not active
* `clean_up_passwords` sets the accessors to nil to skip validations
== 1.4.4
* bug fix
* Do not always skip helpers, instead provide :skip_helpers as option to trigger it manually
== 1.4.3
* enhancements
* Improve Rails 3.1 compatibility
* Use serialize_into_session and serialize_from_session in Warden serialize to improve extensibility
* bug fix
* Generator properly generates a change_table migration if a model already exists
* Properly deprecate setup_mail
* Fix encoding issues with email regexp
* Only generate helpers for the used mappings
* Wrap :action constraints in the proper hash
* deprecations
* Loosened the used email regexp to simply assert the existent of "@". If someone relies on a more strict regexp, they may use https://github.com/SixArm/sixarm_ruby_email_address_validation
== 1.4.2
* bug fix
* Provide a more robust behavior to serializers and add :force_except option
== 1.4.1
* enhancements
* Add :defaults and :format support on router
* Add simple form generators
* Better localization for devise_error_messages! (by github.com/zedtux)
* bug fix
* Ensure to_xml is properly white listened
* Ensure handle_unverified_request clean up any cached signed-in user
== 1.4.0
* enhancements
* Added authenticated and unauthenticated to the router to route the used based on his status (by github.com/sj26)
* Improve e-mail regexp (by github.com/rodrigoflores)
* Add strip_whitespace_keys and default to e-mail (by github.com/swrobel)
* Do not run format and uniqueness validations on e-mail if it hasn't changed (by github.com/Thibaut)
* Added update_without_password to update models but not allowing the password to change (by github.com/fschwahn)
* Added config.paranoid, check the generator for more information (by github.com/rodrigoflores)
* bug fix
* password_required? should not affect length validation
* User cannot access sign up and similar pages if he is already signed in through a cookie or token
* Do not convert booleans to strings on finders (by github.com/xavier)
* Run validations even if current_password fails (by github.com/crx)
* Devise now honors routes constraints (by github.com/macmartine)
* Do not return the user resource when requesting instructions (by github.com/rodrigoflores)
== 1.3.4
* bug fix
* Do not add formats if html or "*/*"
== 1.3.3
* bug fix
* Explicitly mark the token as expired if so
== 1.3.2
* bug fix
* Fix another regression related to reset_password_sent_at (by github.com/alexdreher)
== 1.3.1
* enhancements
* Improve failure_app responses (by github.com/indirect)
* sessions/new and registrations/new also respond to xml and json now
* bug fix
* Fix a regression that occurred if reset_password_sent_at is not present (by github.com/stevehodgkiss)
== 1.3.0
* enhancements
* All controllers can now handle different mime types than html using Responders (by github.com/sikachu)
* Added reset_password_within as configuration option to send the token for recovery (by github.com/jdguyot)
* Bump password length to 128 characters (by github.com/k33l0r)
* Add :only as option to devise_for (by github.com/timoschilling)
* Allow to override path after sending password instructions (by github.com/irohiroki)
* require_no_authentication has its own flash message (by github.com/jackdempsey)
* bug fix
* Fix a bug where configuration options were being included too late
* Ensure Devise::TestHelpers can be used to tests Devise internal controllers (by github.com/jwilger)
* valid_password? should not choke on empty passwords (by github.com/mikel)
* Calling devise more than once does not include previously added modules anymore
* downcase_keys before validation
* backward incompatible changes
* authentication_keys are no longer considered when creating the e-mail validations, the previous behavior was buggy. You must double check if you were relying on such behavior.
== 1.2.1
* enhancements
* Improve update path messages
== 1.2.0
* bug fix

23
Gemfile
View File

@@ -2,28 +2,35 @@ source "http://rubygems.org"
gemspec
gem "rails", "~> 3.0.4"
gem "rails", "~> 3.1.0"
gem "oa-oauth", '~> 0.2.0', :require => "omniauth/oauth"
gem "oa-openid", '~> 0.2.0', :require => "omniauth/openid"
gem "rdoc"
group :test do
gem "webrat", "0.7.2", :require => false
gem "mocha", :require => false
end
platforms :jruby do
gem 'activerecord-jdbc-adapter', :git => 'https://github.com/nicksieger/activerecord-jdbc-adapter.git'
gem 'activerecord-jdbcsqlite3-adapter'
gem 'jruby-openssl'
end
platforms :mri_18 do
group :test do
gem "ruby-debug", ">= 0.10.3"
end
end
platforms :ruby do
group :test do
gem "sqlite3-ruby"
gem "ruby-debug", ">= 0.10.3" if RUBY_VERSION < '1.9'
end
gem "sqlite3-ruby"
group :mongoid do
gem "mongo", "1.1.2"
gem "mongoid", "2.0.0.beta.20"
gem "bson_ext", "1.2.1"
gem "mongo", "~> 1.3.0"
gem "mongoid", "~> 2.0"
gem "bson_ext", "~> 1.3.0"
end
end

View File

@@ -1,158 +0,0 @@
PATH
remote: .
specs:
devise (1.2.rc2)
bcrypt-ruby (~> 2.1.2)
orm_adapter (~> 0.0.3)
warden (~> 1.0.3)
GEM
remote: http://rubygems.org/
specs:
abstract (1.0.0)
actionmailer (3.0.4)
actionpack (= 3.0.4)
mail (~> 2.2.15)
actionpack (3.0.4)
activemodel (= 3.0.4)
activesupport (= 3.0.4)
builder (~> 2.1.2)
erubis (~> 2.6.6)
i18n (~> 0.4)
rack (~> 1.2.1)
rack-mount (~> 0.6.13)
rack-test (~> 0.5.7)
tzinfo (~> 0.3.23)
activemodel (3.0.4)
activesupport (= 3.0.4)
builder (~> 2.1.2)
i18n (~> 0.4)
activerecord (3.0.4)
activemodel (= 3.0.4)
activesupport (= 3.0.4)
arel (~> 2.0.2)
tzinfo (~> 0.3.23)
activerecord-jdbc-adapter (1.1.1)
activerecord-jdbcsqlite3-adapter (1.1.1)
activerecord-jdbc-adapter (= 1.1.1)
jdbc-sqlite3 (~> 3.6.0)
activeresource (3.0.4)
activemodel (= 3.0.4)
activesupport (= 3.0.4)
activesupport (3.0.4)
addressable (2.2.4)
arel (2.0.8)
bcrypt-ruby (2.1.4)
bson (1.2.1)
bson_ext (1.2.1)
builder (2.1.2)
columnize (0.3.2)
erubis (2.6.6)
abstract (>= 1.0.0)
faraday (0.5.7)
addressable (~> 2.2.4)
multipart-post (~> 1.1.0)
rack (>= 1.1.0, < 2)
i18n (0.5.0)
jdbc-sqlite3 (3.6.14.2.056-java)
linecache (0.43)
mail (2.2.15)
activesupport (>= 2.3.6)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.16)
mocha (0.9.12)
mongo (1.1.2)
bson (>= 1.1.1)
mongoid (2.0.0.beta.20)
activemodel (~> 3.0)
mongo (~> 1.1)
tzinfo (~> 0.3.22)
will_paginate (~> 3.0.pre)
multi_json (0.0.5)
multipart-post (1.1.0)
nokogiri (1.4.4)
nokogiri (1.4.4-java)
weakling (>= 0.0.3)
oa-core (0.2.0)
rack (~> 1.1)
oa-oauth (0.2.0)
multi_json (~> 0.0.2)
nokogiri (~> 1.4.2)
oa-core (= 0.2.0)
oauth (~> 0.4.0)
oauth2 (~> 0.1.1)
oa-openid (0.2.0)
oa-core (= 0.2.0)
rack-openid (~> 1.2.0)
ruby-openid-apps-discovery
oauth (0.4.4)
oauth2 (0.1.1)
faraday (~> 0.5.0)
multi_json (~> 0.0.4)
orm_adapter (0.0.4)
polyglot (0.3.1)
rack (1.2.1)
rack-mount (0.6.13)
rack (>= 1.0.0)
rack-openid (1.2.0)
rack (>= 1.1.0)
ruby-openid (>= 2.1.8)
rack-test (0.5.7)
rack (>= 1.0)
rails (3.0.4)
actionmailer (= 3.0.4)
actionpack (= 3.0.4)
activerecord (= 3.0.4)
activeresource (= 3.0.4)
activesupport (= 3.0.4)
bundler (~> 1.0)
railties (= 3.0.4)
railties (3.0.4)
actionpack (= 3.0.4)
activesupport (= 3.0.4)
rake (>= 0.8.7)
thor (~> 0.14.4)
rake (0.8.7)
ruby-debug (0.10.4)
columnize (>= 0.1)
ruby-debug-base (~> 0.10.4.0)
ruby-debug-base (0.10.4)
linecache (>= 0.3)
ruby-openid (2.1.8)
ruby-openid-apps-discovery (1.2.0)
ruby-openid (>= 2.1.7)
sqlite3 (1.3.3)
sqlite3-ruby (1.3.3)
sqlite3 (>= 1.3.3)
thor (0.14.6)
treetop (1.4.9)
polyglot (>= 0.3.1)
tzinfo (0.3.24)
warden (1.0.3)
rack (>= 1.0.0)
weakling (0.0.4-java)
webrat (0.7.2)
nokogiri (>= 1.2.0)
rack (>= 1.0)
rack-test (>= 0.5.3)
will_paginate (3.0.pre2)
PLATFORMS
java
ruby
DEPENDENCIES
activerecord-jdbcsqlite3-adapter
bson_ext (= 1.2.1)
devise!
mocha
mongo (= 1.1.2)
mongoid (= 2.0.0.beta.20)
oa-oauth (~> 0.2.0)
oa-openid (~> 0.2.0)
rails (~> 3.0.4)
ruby-debug (>= 0.10.3)
sqlite3-ruby
webrat (= 0.7.2)

View File

@@ -7,7 +7,7 @@ Devise is a flexible authentication solution for Rails based on Warden. It:
* Allows you to have multiple roles (or models/scopes) signed in at the same time;
* Is based on a modularity concept: use just what you really need.
It's composed of 12 modules:
It's comprised of 12 modules:
* Database Authenticatable: encrypts and stores a password in the database to validate the authenticity of a user while signing in. The authentication can be done both through POST requests or HTTP Basic Authentication.
* Token Authenticatable: signs in a user based on an authentication token (also known as "single access token"). The token can be given both through query string or HTTP Basic Authentication.
@@ -86,7 +86,7 @@ The generator will install an initializer which describes ALL Devise's configura
rails generate devise MODEL
Replace MODEL by the class name you want to add devise, like User, Admin, etc. This will create a model (if one does not exist) and configure it with default Devise modules. The generator will also create a migration file (if your ORM support them) and configure your routes. Continue reading this file to understand exactly what the generator produces and how to use it.
Replace MODEL by the class name used for the applications users, it's frequently 'User' but could also be 'Admin'. This will create a model (if one does not exist) and configure it with default Devise modules. Next, you'll usually run db:migrate as the generator will have created a migration file (if your ORM supports them). This generator also configures your config/routes.rb file, continue reading this file to understand exactly what the generator produces and how to use it.
Support for Rails 2.3.x can be found by installing Devise 1.0.x from the v1.0 branch.
@@ -97,7 +97,7 @@ If you are building your first Rails application, we recommend you to *not* use
* Michael Hartl's online book: http://railstutorial.org/chapters/modeling-and-viewing-users-two#top
* Ryan Bates' Railscast: http://railscasts.com/episodes/250-authentication-from-scratch
Once you have solidified you understanding of Rails and authentication mechanisms, we assure you Devise will be very pleasant to work with. :)
Once you have solidified your understanding of Rails and authentication mechanisms, we assure you Devise will be very pleasant to work with. :)
== Getting started
@@ -108,7 +108,7 @@ Devise must be set up within the model (or models) you want to use. Devise route
We're assuming here you want a User model with some Devise modules, as outlined below:
class User < ActiveRecord::Base
devise :database_authenticatable, :confirmable, :recoverable, :rememberable, :trackable, :validatable
devise :database_authenticatable, :registerable, :confirmable, :recoverable, :rememberable, :trackable, :validatable
end
After you choose which modules to use, you need to set up your migrations. Luckily, Devise has some helpers to save you from this boring work:
@@ -152,7 +152,7 @@ You can access the session for this scope:
After signing in a user, confirming the account or updating the password, Devise will look for a scoped root path to redirect. Example: For a :user resource, it will use user_root_path if it exists, otherwise default root_path will be used. This means that you need to set the root inside your routes:
root :to => "home"
root :to => "home#index"
You can also overwrite after_sign_in_path_for and after_sign_out_path_for to customize your redirect hooks.
@@ -174,7 +174,7 @@ Notice that if your devise model is not called "user" but "member", then the hel
The devise method in your models also accepts some options to configure its modules. For example, you can choose which encryptor to use in database_authenticatable:
devise :database_authenticatable, :confirmable, :recoverable, :stretches => 20
devise :database_authenticatable, :registerable, :confirmable, :recoverable, :stretches => 20
Besides :stretches, you can define :pepper, :encryptor, :confirm_within, :remember_for, :timeout_in, :unlock_in and other values. For details, see the initializer file that was created when you invoked the "devise:install" generator described above.
@@ -259,7 +259,7 @@ Feel free to choose the one you prefer!
=== I18n
Devise uses flash messages with I18n with the flash keys :success and :failure. To customize your app, you can set up your locale file:
Devise uses flash messages with I18n with the flash keys :notice and :alert. To customize your app, you can set up your locale file:
en:
devise:
@@ -315,12 +315,11 @@ If you're using RSpec and want the helpers automatically included within all +de
Do not use such helpers for integration tests such as Cucumber or Webrat. Instead, fill in the form or explicitly set the user in session. For more tips, check the wiki (http://wiki.github.com/plataformatec/devise).
=== OAuth2
=== Omniauth
Devise comes with OAuth support out of the box if you're using Devise from the git repository (for now). You can read more about OAuth2 support in the wiki:
Devise comes with Omniauth support out of the box to authenticate from other providers. You can read more about Omniauth support in the wiki:
* http://github.com/plataformatec/devise/wiki/OAuth2:-Overview
* http://github.com/plataformatec/devise/wiki/OAuth2:-Testing
* https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview
=== Other ORMs

View File

@@ -1,10 +1,10 @@
# encoding: UTF-8
require 'rake/testtask'
require 'rake/rdoctask'
require 'rdoc/task'
desc 'Default: run tests for all ORMs.'
task :default => :pre_commit
task :default => :test
desc 'Run Devise tests for all ORMs.'
task :pre_commit do

View File

@@ -11,11 +11,11 @@ class Devise::ConfirmationsController < ApplicationController
def create
self.resource = resource_class.send_confirmation_instructions(params[resource_name])
if resource.errors.empty?
set_flash_message :notice, :send_instructions
redirect_to new_session_path(resource_name)
if successful_and_sane?(resource)
set_flash_message(:notice, :send_instructions) if is_navigational_format?
respond_with({}, :location => after_resending_confirmation_instructions_path_for(resource_name))
else
render_with_scope :new
respond_with_navigational(resource){ render_with_scope :new }
end
end
@@ -24,10 +24,24 @@ class Devise::ConfirmationsController < ApplicationController
self.resource = resource_class.confirm_by_token(params[:confirmation_token])
if resource.errors.empty?
set_flash_message :notice, :confirmed
sign_in_and_redirect(resource_name, resource)
set_flash_message(:notice, :confirmed) if is_navigational_format?
sign_in(resource_name, resource)
respond_with_navigational(resource){ redirect_to after_confirmation_path_for(resource_name, resource) }
else
render_with_scope :new
respond_with_navigational(resource.errors, :status => :unprocessable_entity){ render_with_scope :new }
end
end
protected
# The path used after resending confirmation instructions.
def after_resending_confirmation_instructions_path_for(resource_name)
new_session_path(resource_name)
end
# The path used after confirmation.
def after_confirmation_path_for(resource_name, resource)
redirect_location(resource_name, resource)
end
end

View File

@@ -12,11 +12,11 @@ class Devise::PasswordsController < ApplicationController
def create
self.resource = resource_class.send_reset_password_instructions(params[resource_name])
if resource.errors.empty?
set_flash_message :notice, :send_instructions
redirect_to new_session_path(resource_name)
if successful_and_sane?(resource)
set_flash_message(:notice, :send_instructions) if is_navigational_format?
respond_with({}, :location => after_sending_reset_password_instructions_path_for(resource_name))
else
render_with_scope :new
respond_with_navigational(resource){ render_with_scope :new }
end
end
@@ -32,10 +32,20 @@ class Devise::PasswordsController < ApplicationController
self.resource = resource_class.reset_password_by_token(params[resource_name])
if resource.errors.empty?
set_flash_message :notice, :updated
sign_in_and_redirect(resource_name, resource)
flash_message = resource.active_for_authentication? ? :updated : :updated_not_active
set_flash_message(:notice, flash_message) if is_navigational_format?
sign_in(resource_name, resource)
respond_with resource, :location => redirect_location(resource_name, resource)
else
render_with_scope :edit
respond_with_navigational(resource){ render_with_scope :edit }
end
end
protected
# The path used after sending reset password instructions
def after_sending_reset_password_instructions_path_for(resource_name)
new_session_path(resource_name)
end
end

View File

@@ -5,8 +5,8 @@ class Devise::RegistrationsController < ApplicationController
# GET /resource/sign_up
def new
build_resource({})
render_with_scope :new
resource = build_resource({})
respond_with_navigational(resource){ render_with_scope :new }
end
# POST /resource
@@ -15,16 +15,17 @@ class Devise::RegistrationsController < ApplicationController
if resource.save
if resource.active_for_authentication?
set_flash_message :notice, :signed_up
sign_in_and_redirect(resource_name, resource)
set_flash_message :notice, :signed_up if is_navigational_format?
sign_in(resource_name, resource)
respond_with resource, :location => redirect_location(resource_name, resource)
else
set_flash_message :notice, :inactive_signed_up, :reason => resource.inactive_message.to_s
set_flash_message :notice, :inactive_signed_up, :reason => inactive_reason(resource) if is_navigational_format?
expire_session_data_after_sign_in!
redirect_to after_inactive_sign_up_path_for(resource)
respond_with resource, :location => after_inactive_sign_up_path_for(resource)
end
else
clean_up_passwords(resource)
render_with_scope :new
respond_with_navigational(resource) { render_with_scope :new }
end
end
@@ -34,22 +35,27 @@ class Devise::RegistrationsController < ApplicationController
end
# PUT /resource
# We need to use a copy of the resource because we don't want to change
# the current user in place.
def update
self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key)
if resource.update_with_password(params[resource_name])
set_flash_message :notice, :updated
set_flash_message :notice, :updated if is_navigational_format?
sign_in resource_name, resource, :bypass => true
redirect_to after_update_path_for(resource)
respond_with resource, :location => after_update_path_for(resource)
else
clean_up_passwords(resource)
render_with_scope :edit
respond_with_navigational(resource){ render_with_scope :edit }
end
end
# DELETE /resource
def destroy
resource.destroy
sign_out_and_redirect(self.resource)
set_flash_message :notice, :destroyed
Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)
set_flash_message :notice, :destroyed if is_navigational_format?
respond_with_navigational(resource){ redirect_to after_sign_out_path_for(resource_name) }
end
# GET /resource/cancel
@@ -78,10 +84,16 @@ class Devise::RegistrationsController < ApplicationController
end
# Overwrite redirect_for_sign_in so it takes uses after_sign_up_path_for.
def redirect_location(scope, resource) #:nodoc:
def redirect_location(scope, resource)
stored_location_for(scope) || after_sign_up_path_for(resource)
end
# Returns the inactive reason translated.
def inactive_reason(resource)
reason = resource.inactive_message.to_s
I18n.t("devise.registrations.reasons.#{reason}", :default => reason)
end
# The path used after sign up for inactive accounts. You need to overwrite
# this method in your own RegistrationsController.
def after_inactive_sign_up_path_for(resource)
@@ -100,11 +112,9 @@ class Devise::RegistrationsController < ApplicationController
end
end
# Authenticates the current scope and gets a copy of the current resource.
# We need to use a copy because we don't want actions like update changing
# the current user in place.
# Authenticates the current scope and gets the current resource from the session.
def authenticate_scope!
send(:"authenticate_#{resource_name}!", true)
self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key)
send(:"authenticate_#{resource_name}!", :force => true)
self.resource = send(:"current_#{resource_name}")
end
end

View File

@@ -1,11 +1,13 @@
class Devise::SessionsController < ApplicationController
prepend_before_filter :require_no_authentication, :only => [ :new, :create ]
prepend_before_filter :allow_params_authentication!, :only => :create
include Devise::Controllers::InternalHelpers
# GET /resource/sign_in
def new
clean_up_passwords(build_resource)
render_with_scope :new
resource = build_resource
clean_up_passwords(resource)
respond_with_navigational(resource, stub_options(resource)){ render_with_scope :new }
end
# POST /resource/sign_in
@@ -19,7 +21,28 @@ class Devise::SessionsController < ApplicationController
# GET /resource/sign_out
def destroy
signed_in = signed_in?(resource_name)
sign_out_and_redirect(resource_name)
Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)
set_flash_message :notice, :signed_out if signed_in
# We actually need to hardcode this, as Rails default responder doesn't
# support returning empty response on GET request
respond_to do |format|
format.any(*navigational_formats) { redirect_to after_sign_out_path_for(resource_name) }
format.all do
method = "to_#{request_format}"
text = {}.respond_to?(method) ? {}.send(method) : ""
render :text => text, :status => :ok
end
end
end
protected
def stub_options(resource)
methods = resource_class.authentication_keys.dup
methods = methods.keys if methods.is_a?(Hash)
methods << :password if resource.respond_to?(:password)
{ :methods => methods, :only => [:password] }
end
end

View File

@@ -12,11 +12,11 @@ class Devise::UnlocksController < ApplicationController
def create
self.resource = resource_class.send_unlock_instructions(params[resource_name])
if resource.errors.empty?
set_flash_message :notice, :send_instructions
redirect_to new_session_path(resource_name)
if successful_and_sane?(resource)
set_flash_message :notice, :send_instructions if is_navigational_format?
respond_with({}, :location => new_session_path(resource_name))
else
render_with_scope :new
respond_with_navigational(resource){ render_with_scope :new }
end
end
@@ -25,10 +25,11 @@ class Devise::UnlocksController < ApplicationController
self.resource = resource_class.unlock_access_by_token(params[:unlock_token])
if resource.errors.empty?
set_flash_message :notice, :unlocked
sign_in_and_redirect(resource_name, resource)
set_flash_message :notice, :unlocked if is_navigational_format?
sign_in(resource_name, resource)
respond_with_navigational(resource){ redirect_to redirect_location(resource_name, resource) }
else
render_with_scope :new
respond_with_navigational(resource.errors, :status => :unprocessable_entity){ render_with_scope :new }
end
end
end

View File

@@ -11,7 +11,7 @@ module DeviseHelper
messages = resource.errors.full_messages.map { |msg| content_tag(:li, msg) }.join
sentence = I18n.t("errors.messages.not_saved",
:count => resource.errors.count,
:resource => resource_name)
:resource => resource.class.model_name.human.downcase)
html = <<-HTML
<div id="error_explanation">

View File

@@ -1,88 +1,15 @@
class Devise::Mailer < ::ActionMailer::Base
include Devise::Controllers::ScopedViews
attr_reader :scope_name, :resource
include Devise::Mailers::Helpers
def confirmation_instructions(record)
setup_mail(record, :confirmation_instructions)
devise_mail(record, :confirmation_instructions)
end
def reset_password_instructions(record)
setup_mail(record, :reset_password_instructions)
devise_mail(record, :reset_password_instructions)
end
def unlock_instructions(record)
setup_mail(record, :unlock_instructions)
end
private
# Configure default email options
def setup_mail(record, action)
initialize_from_record(record)
mail headers_for(action)
end
def initialize_from_record(record)
@scope_name = Devise::Mapping.find_scope!(record)
@resource = instance_variable_set("@#{devise_mapping.name}", record)
end
def devise_mapping
@devise_mapping ||= Devise.mappings[scope_name]
end
def headers_for(action)
headers = {
:subject => translate(devise_mapping, action),
:from => mailer_sender(devise_mapping),
:to => resource.email,
:template_path => template_paths
}
if resource.respond_to?(:headers_for)
headers.merge!(resource.headers_for(action))
end
unless headers.key?(:reply_to)
headers[:reply_to] = headers[:from]
end
headers
end
def mailer_sender(mapping)
if Devise.mailer_sender.is_a?(Proc)
Devise.mailer_sender.call(mapping.name)
else
Devise.mailer_sender
end
end
def template_paths
template_path = [self.class.mailer_name]
template_path.unshift "#{@devise_mapping.scoped_path}/mailer" if self.class.scoped_views?
template_path
end
# Setup a subject doing an I18n lookup. At first, it attemps to set a subject
# based on the current mapping:
#
# en:
# devise:
# mailer:
# confirmation_instructions:
# user_subject: '...'
#
# If one does not exist, it fallbacks to ActionMailer default:
#
# en:
# devise:
# mailer:
# confirmation_instructions:
# subject: '...'
#
def translate(mapping, key)
I18n.t(:"#{mapping.name}_subject", :scope => [:devise, :mailer, key],
:default => [:subject, key.to_s.humanize])
devise_mail(record, :unlock_instructions)
end
end

View File

@@ -3,10 +3,10 @@
<%= form_for(resource, :as => resource_name, :url => confirmation_path(resource_name), :html => { :method => :post }) do |f| %>
<%= devise_error_messages! %>
<p><%= f.label :email %><br />
<%= f.email_field :email %></p>
<div><%= f.label :email %><br />
<%= f.email_field :email %></div>
<p><%= f.submit "Resend confirmation instructions" %></p>
<div><%= f.submit "Resend confirmation instructions" %></div>
<% end %>
<%= render :partial => "devise/shared/links" %>

View File

@@ -4,13 +4,13 @@
<%= devise_error_messages! %>
<%= f.hidden_field :reset_password_token %>
<p><%= f.label :password, "New password" %><br />
<%= f.password_field :password %></p>
<div><%= f.label :password, "New password" %><br />
<%= f.password_field :password %></div>
<p><%= f.label :password_confirmation, "Confirm new password" %><br />
<%= f.password_field :password_confirmation %></p>
<div><%= f.label :password_confirmation, "Confirm new password" %><br />
<%= f.password_field :password_confirmation %></div>
<p><%= f.submit "Change my password" %></p>
<div><%= f.submit "Change my password" %></div>
<% end %>
<%= render :partial => "devise/shared/links" %>

View File

@@ -3,10 +3,10 @@
<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :post }) do |f| %>
<%= devise_error_messages! %>
<p><%= f.label :email %><br />
<%= f.email_field :email %></p>
<div><%= f.label :email %><br />
<%= f.email_field :email %></div>
<p><%= f.submit "Send me reset password instructions" %></p>
<div><%= f.submit "Send me reset password instructions" %></div>
<% end %>
<%= render :partial => "devise/shared/links" %>

View File

@@ -3,19 +3,19 @@
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %>
<%= devise_error_messages! %>
<p><%= f.label :email %><br />
<%= f.email_field :email %></p>
<div><%= f.label :email %><br />
<%= f.email_field :email %></div>
<p><%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
<%= f.password_field :password %></p>
<div><%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
<%= f.password_field :password %></div>
<p><%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation %></p>
<div><%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation %></div>
<p><%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
<%= f.password_field :current_password %></p>
<div><%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
<%= f.password_field :current_password %></div>
<p><%= f.submit "Update" %></p>
<div><%= f.submit "Update" %></div>
<% end %>
<h3>Cancel my account</h3>

View File

@@ -3,16 +3,16 @@
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<p><%= f.label :email %><br />
<%= f.email_field :email %></p>
<div><%= f.label :email %><br />
<%= f.email_field :email %></div>
<p><%= f.label :password %><br />
<%= f.password_field :password %></p>
<div><%= f.label :password %><br />
<%= f.password_field :password %></div>
<p><%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation %></p>
<div><%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation %></div>
<p><%= f.submit "Sign up" %></p>
<div><%= f.submit "Sign up" %></div>
<% end %>
<%= render :partial => "devise/shared/links" %>

View File

@@ -1,17 +1,17 @@
<h2>Sign in</h2>
<%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
<p><%= f.label :email %><br />
<%= f.email_field :email %></p>
<div><%= f.label :email %><br />
<%= f.email_field :email %></div>
<p><%= f.label :password %><br />
<%= f.password_field :password %></p>
<div><%= f.label :password %><br />
<%= f.password_field :password %></div>
<% if devise_mapping.rememberable? -%>
<p><%= f.check_box :remember_me %> <%= f.label :remember_me %></p>
<div><%= f.check_box :remember_me %> <%= f.label :remember_me %></div>
<% end -%>
<p><%= f.submit "Sign in" %></p>
<div><%= f.submit "Sign in" %></div>
<% end %>
<%= render :partial => "devise/shared/links" %>

View File

@@ -3,10 +3,10 @@
<%= form_for(resource, :as => resource_name, :url => unlock_path(resource_name), :html => { :method => :post }) do |f| %>
<%= devise_error_messages! %>
<p><%= f.label :email %><br />
<%= f.email_field :email %></p>
<div><%= f.label :email %><br />
<%= f.email_field :email %></div>
<p><%= f.submit "Resend unlock instructions" %></p>
<div><%= f.submit "Resend unlock instructions" %></div>
<% end %>
<%= render :partial => "devise/shared/links" %>

View File

@@ -3,6 +3,7 @@
en:
errors:
messages:
expired: "has expired, please request a new one"
not_found: "not found"
already_confirmed: "was already confirmed, please try signing in"
not_locked: "was not locked"
@@ -12,6 +13,7 @@ en:
devise:
failure:
already_authenticated: 'You are already signed in.'
unauthenticated: 'You need to sign in or sign up before continuing.'
unconfirmed: 'You have to confirm your account before continuing.'
locked: 'Your account is locked.'
@@ -25,17 +27,25 @@ en:
passwords:
send_instructions: 'You will receive an email with instructions about how to reset your password in a few minutes.'
updated: 'Your password was changed successfully. You are now signed in.'
updated_not_active: 'Your password was changed successfully.'
send_paranoid_instructions: "If your e-mail exists on our database, you will receive a password recovery link on your e-mail"
confirmations:
send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.'
send_paranoid_instructions: 'If your e-mail exists on our database, you will receive an email with instructions about how to confirm your account in a few minutes.'
confirmed: 'Your account was successfully confirmed. You are now signed in.'
registrations:
signed_up: 'Welcome! You have signed up successfully.'
inactive_signed_up: 'You have signed up successfully. However, we could not sign you in because your account is %{reason}.'
updated: 'You updated your account successfully.'
destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.'
reasons:
inactive: 'inactive'
unconfirmed: 'unconfirmed'
locked: 'locked'
unlocks:
send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.'
unlocked: 'Your account was successfully unlocked. You are now signed in.'
send_paranoid_instructions: 'If your account exists, you will receive an email with instructions about how to unlock it in a few minutes.'
omniauth_callbacks:
success: 'Successfully authorized from %{kind} account.'
failure: 'Could not authorize you from %{kind} because "%{reason}".'

View File

@@ -21,5 +21,5 @@ Gem::Specification.new do |s|
s.add_dependency("warden", "~> 1.0.3")
s.add_dependency("orm_adapter", "~> 0.0.3")
s.add_dependency("bcrypt-ruby", "~> 2.1.2")
s.add_dependency("bcrypt-ruby", "~> 3.0")
end

View File

@@ -3,6 +3,7 @@ require 'active_support/core_ext/numeric/time'
require 'active_support/dependencies'
require 'orm_adapter'
require 'set'
require 'securerandom'
module Devise
autoload :FailureApp, 'devise/failure_app'
@@ -16,6 +17,7 @@ module Devise
autoload :InternalHelpers, 'devise/controllers/internal_helpers'
autoload :Rememberable, 'devise/controllers/rememberable'
autoload :ScopedViews, 'devise/controllers/scoped_views'
autoload :SharedHelpers, 'devise/controllers/shared_helpers'
autoload :UrlHelpers, 'devise/controllers/url_helpers'
end
@@ -28,6 +30,10 @@ module Devise
autoload :Sha1, 'devise/encryptors/sha1'
end
module Mailers
autoload :Helpers, 'devise/mailers/helpers'
end
module Strategies
autoload :Base, 'devise/strategies/base'
autoload :Authenticatable, 'devise/strategies/authenticatable'
@@ -41,6 +47,9 @@ module Devise
STRATEGIES = ActiveSupport::OrderedHash.new
URL_HELPERS = ActiveSupport::OrderedHash.new
# Strategies that do not require user input.
NO_INPUT = []
# True values used to check params
TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE']
@@ -73,6 +82,11 @@ module Devise
# False by default for backwards compatibility.
mattr_accessor :case_insensitive_keys
@@case_insensitive_keys = false
# Keys that should have whitespace stripped.
# False by default for backwards compatibility.
mattr_accessor :strip_whitespace_keys
@@strip_whitespace_keys = false
# If http authentication is enabled by default.
mattr_accessor :http_authenticatable
@@ -90,13 +104,15 @@ module Devise
mattr_accessor :http_authentication_realm
@@http_authentication_realm = "Application"
# Email regex used to validate email formats. Adapted from authlogic.
# Email regex used to validate email formats. It simply asserts that
# an one (and only one) @ exists in the given string. This is mainly
# to give user feedback and not to assert the e-mail validity.
mattr_accessor :email_regexp
@@email_regexp = /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i
@@email_regexp = /\A[^@]+@([^@\.]+\.)+[^@\.]+\z/
# Range validation for password length
mattr_accessor :password_length
@@password_length = 6..20
@@password_length = 6..128
# The time the user will be remembered without asking for credentials again.
mattr_accessor :remember_for
@@ -171,6 +187,10 @@ module Devise
mattr_accessor :reset_password_keys
@@reset_password_keys = [ :email ]
# Time interval you can reset your password with a reset password key
mattr_accessor :reset_password_within
@@reset_password_within = nil
# The default scope which is used by warden.
mattr_accessor :default_scope
@@default_scope = nil
@@ -220,15 +240,30 @@ module Devise
@@warden_config = nil
@@warden_config_block = nil
# When true, enter in paranoid mode to avoid user enumeration.
mattr_accessor :paranoid
@@paranoid = false
# Default way to setup Devise. Run rails generate devise_install to create
# a fresh initializer with all configuration values.
def self.setup
yield self
end
class Getter
def initialize name
@name = name
end
def get
ActiveSupport::Dependencies.constantize(@name)
end
end
def self.ref(arg)
if defined?(ActiveSupport::Dependencies::ClassCache)
ActiveSupport::Dependencies::Reference.store(arg)
ActiveSupport::Dependencies::reference(arg)
Getter.new(arg)
else
ActiveSupport::Dependencies.ref(arg)
end
@@ -238,19 +273,9 @@ module Devise
omniauth_configs.keys
end
def self.cookie_domain=(value)
ActiveSupport::Deprecation.warn "Devise.cookie_domain=(value) is deprecated. "
"Please use Devise.cookie_options = { :domain => value } instead."
self.cookie_options[:domain] = value
end
# Get the mailer class from the mailer reference object.
def self.mailer
if defined?(ActiveSupport::Dependencies::ClassCache)
@@mailer_ref.get "Devise::Mailer"
else
@@mailer_ref.get
end
@@mailer_ref.get
end
# Set the mailer reference object to access the mailer.
@@ -291,13 +316,17 @@ module Devise
options.assert_valid_keys(:strategy, :model, :controller, :route)
if strategy = options[:strategy]
STRATEGIES[module_name] = (strategy == true ? module_name : strategy)
strategy = (strategy == true ? module_name : strategy)
STRATEGIES[module_name] = strategy
end
if controller = options[:controller]
CONTROLLERS[module_name] = (controller == true ? module_name : controller)
controller = (controller == true ? module_name : controller)
CONTROLLERS[module_name] = controller
end
NO_INPUT << strategy if strategy && controller != :sessions
if route = options[:route]
case route
when TrueClass
@@ -319,7 +348,8 @@ module Devise
if options[:model]
path = (options[:model] == true ? "devise/models/#{module_name}" : options[:model])
Devise::Models.send(:autoload, module_name.to_s.camelize.to_sym, path)
camelized = ActiveSupport::Inflector.camelize(module_name.to_s)
Devise::Models.send(:autoload, camelized.to_sym, path)
end
Devise::Mapping.add_module module_name
@@ -346,7 +376,8 @@ module Devise
#
def self.omniauth(provider, *args)
@@helpers << Devise::OmniAuth::UrlHelpers
@@omniauth_configs[provider] = Devise::OmniAuth::Config.new(provider, args)
config = Devise::OmniAuth::Config.new(provider, args)
@@omniauth_configs[config.strategy_name.to_sym] = config
end
# Include helpers in the given scope to AC and AV.
@@ -366,6 +397,12 @@ module Devise
Rails::VERSION::STRING[0,3] != "3.0"
end
# Regenerates url helpers considering Devise.mapping
def self.regenerate_helpers!
Devise::Controllers::UrlHelpers.remove_helpers!
Devise::Controllers::UrlHelpers.generate_helpers!
end
# A method used internally to setup warden manager from the Rails initialize
# block.
def self.configure_warden! #:nodoc:
@@ -385,7 +422,7 @@ module Devise
# Generate a friendly string randomically to be used as token.
def self.friendly_token
ActiveSupport::SecureRandom.base64(15).tr('+/=', 'xyz')
SecureRandom.base64(15).tr('+/=lIO0', 'pqrsxyz')
end
# constant-time comparison algorithm to prevent timing attacks

View File

@@ -5,7 +5,7 @@ module Devise
extend ActiveSupport::Concern
included do
helper_method :warden, :signed_in?, :devise_controller?, :anybody_signed_in?
helper_method :warden, :signed_in?, :devise_controller?
end
# Define authentication filters and accessor helpers based on mappings.
@@ -36,8 +36,14 @@ module Devise
mapping = mapping.name
class_eval <<-METHODS, __FILE__, __LINE__ + 1
def authenticate_#{mapping}!(force = false)
warden.authenticate!(:scope => :#{mapping}) if !devise_controller? || force
def authenticate_#{mapping}!(opts={})
if !opts.is_a?(Hash)
opts = { :force => opts }
ActiveSupport::Deprecation.warn "Passing a boolean to authenticate_#{mapping}! " \
"is deprecated, please use :force => \#{opts[:force]} instead", caller
end
opts[:scope] = :#{mapping}
warden.authenticate!(opts) if !devise_controller? || opts.delete(:force)
end
def #{mapping}_signed_in?
@@ -72,6 +78,11 @@ module Devise
false
end
# Tell warden that params authentication is allowed for that specific page.
def allow_params_authentication!
request.env["devise.allow_params_authentication"] = true
end
# Return true if the given scope is signed in session. If no scope given, return
# true if any scope is signed in. Does not run authentication hooks.
def signed_in?(scope=nil)
@@ -80,12 +91,6 @@ module Devise
end
end
def anybody_signed_in?
ActiveSupport::Deprecation.warn "Devise#anybody_signed_in? is deprecated. "
"Please use Devise#signed_in?(nil) instead."
signed_in?
end
# Sign in a user that already was authenticated. This helper is useful for logging
# users in after sign up.
#
@@ -112,6 +117,7 @@ module Devise
warden.session_serializer.store(resource, scope)
elsif warden.user(scope) == resource && !options.delete(:force)
# Do nothing. User already signed in and we are not forcing it.
true
else
warden.set_user(resource, options.merge!(:scope => scope))
end
@@ -224,9 +230,12 @@ module Devise
session.keys.grep(/^devise\./).each { |k| session.delete(k) }
end
# Overwrite Rails' handle unverified request to sign out all scopes.
# Overwrite Rails' handle unverified request to sign out all scopes,
# clear run strategies and remove cached variables.
def handle_unverified_request
sign_out_all_scopes
warden.clear_strategies_cache!
Devise.mappings.each { |_,m| instance_variable_set("@current_#{m.name}", nil) }
super # call the default behaviour which resets the session
end
end

View File

@@ -6,6 +6,7 @@ module Devise
module InternalHelpers #:nodoc:
extend ActiveSupport::Concern
include Devise::Controllers::ScopedViews
include Devise::Controllers::SharedHelpers
included do
helper DeviseHelper
@@ -54,12 +55,19 @@ module Devise
# Checks whether it's a devise mapped resource or not.
def is_devise_resource? #:nodoc:
unknown_action!("Could not find devise mapping for path #{request.fullpath.inspect}") unless devise_mapping
unknown_action! <<-MESSAGE unless devise_mapping
Could not find devise mapping for path #{request.fullpath.inspect}.
Maybe you forgot to wrap your route inside the scope block? For example:
devise_scope :user do
match "/some/route" => "some_devise_controller"
end
MESSAGE
end
# Check whether it's navigational format, such as :html or :iphone, or not.
def is_navigational_format?
Devise.navigational_formats.include?(request.format.to_sym)
# Returns real navigational formats which are supported by Rails
def navigational_formats
@navigational_formats ||= Devise.navigational_formats.select{ |format| Mime::EXTENSION_LOOKUP[format.to_s] }
end
def unknown_action!(msg)
@@ -83,12 +91,27 @@ module Devise
# Example:
# before_filter :require_no_authentication, :only => :new
def require_no_authentication
if warden.authenticated?(resource_name)
no_input = devise_mapping.no_input_strategies
args = no_input.dup.push :scope => resource_name
if no_input.present? && warden.authenticate?(*args)
resource = warden.user(resource_name)
flash[:alert] = I18n.t("devise.failure.already_authenticated")
redirect_to after_sign_in_path_for(resource)
end
end
# Helper for use to validate if an resource is errorless. If we are on paranoid mode, we always should assume it is
# and return false.
def successful_and_sane?(resource)
if Devise.paranoid
set_flash_message :notice, :send_paranoid_instructions if is_navigational_format?
resource.errors.clear
false
else
resource.errors.empty?
end
end
# Sets the flash message with :key, using I18n. By default you are able
# to setup your messages using specific resource scope, and if no one is
# found we look to default scope.
@@ -114,6 +137,12 @@ module Devise
def clean_up_passwords(object) #:nodoc:
object.clean_up_passwords if object.respond_to?(:clean_up_passwords)
end
def respond_with_navigational(*args, &block)
respond_with(*args) do |format|
format.any(*navigational_formats, &block)
end
end
end
end
end

View File

@@ -29,7 +29,7 @@ module Devise
# Forgets the given resource by deleting a cookie
def forget_me(resource)
scope = Devise::Mapping.find_scope!(resource)
resource.forget_me! unless resource.frozen?
resource.forget_me!
cookies.delete("remember_#{scope}_token", forget_cookie_values(resource))
end

View File

@@ -0,0 +1,26 @@
module Devise
module Controllers
# Helpers used in both FailureApp and Devise controllers.
module SharedHelpers
MIME_REFERENCES = Mime::HTML.respond_to?(:ref)
protected
# Helper used by FailureApp and Devise controllers to retrieve proper formats.
def request_format
@request_format ||= if request.format.respond_to?(:ref)
request.format.ref
elsif MIME_REFERENCES
request.format
elsif request.format # Rails < 3.0.4
request.format.to_sym
end
end
# Check whether it's navigational format, such as :html or :iphone, or not.
def is_navigational_format?
Devise.navigational_formats.include?(request_format)
end
end
end
end

View File

@@ -18,22 +18,31 @@ module Devise
#
# Those helpers are added to your ApplicationController.
module UrlHelpers
Devise::URL_HELPERS.each do |module_name, actions|
[:path, :url].each do |path_or_url|
actions.each do |action|
action = action ? "#{action}_" : ""
class_eval <<-URL_HELPERS, __FILE__, __LINE__ + 1
def #{action}#{module_name}_#{path_or_url}(resource_or_scope, *args)
scope = Devise::Mapping.find_scope!(resource_or_scope)
send("#{action}\#{scope}_#{module_name}_#{path_or_url}", *args)
end
URL_HELPERS
end
def self.remove_helpers!
self.instance_methods.map(&:to_s).grep(/_(url|path)$/).each do |method|
remove_method method
end
end
def self.generate_helpers!
mappings = Devise.mappings.values.map(&:used_helpers).flatten.uniq
routes = Devise::URL_HELPERS.slice(*mappings)
routes.each do |module_name, actions|
[:path, :url].each do |path_or_url|
actions.each do |action|
action = action ? "#{action}_" : ""
class_eval <<-URL_HELPERS, __FILE__, __LINE__ + 1
def #{action}#{module_name}_#{path_or_url}(resource_or_scope, *args)
scope = Devise::Mapping.find_scope!(resource_or_scope)
send("#{action}\#{scope}_#{module_name}_#{path_or_url}", *args)
end
URL_HELPERS
end
end
end
end
end
end
end

View File

@@ -10,6 +10,7 @@ module Devise
include ActionController::UrlFor
include ActionController::Redirecting
include Rails.application.routes.url_helpers
include Devise::Controllers::SharedHelpers
delegate :flash, :to => :request
@@ -64,13 +65,21 @@ module Devise
end
def redirect_url
if request_format == :html
send(:"new_#{scope}_session_path")
opts = {}
route = :"new_#{scope}_session_path"
opts[:format] = request_format unless skip_format?
if respond_to?(route)
send(route, opts)
else
send(:"new_#{scope}_session_path", :format => request_format)
root_path(opts)
end
end
def skip_format?
%w(html */*).include? request_format.to_s
end
# Choose whether we should respond in a http authentication fashion,
# including 401 and optional headers.
#
@@ -83,7 +92,7 @@ module Devise
if request.xhr?
Devise.http_authenticatable_on_xhr
else
!(request_format && Devise.navigational_formats.include?(request_format))
!(request_format && is_navigational_format?)
end
end
@@ -96,12 +105,20 @@ module Devise
def http_auth_body
return i18n_message unless request_format
method = "to_#{request_format}"
{}.respond_to?(method) ? { :error => i18n_message }.send(method) : i18n_message
if method == "to_xml"
{ :error => i18n_message }.to_xml(:root => "errors")
elsif {}.respond_to?(method)
{ :error => i18n_message }.send(method)
else
i18n_message
end
end
def recall_app(app)
controller, action = app.split("#")
"#{controller.camelize}Controller".constantize.action(action)
controller_name = ActiveSupport::Inflector.camelize(controller)
controller_klass = ActiveSupport::Inflector.constantize("#{controller_name}Controller")
controller_klass.action(action)
end
def warden
@@ -127,17 +144,5 @@ module Devise
def store_location!
session["#{scope}_return_to"] = attempted_path if request.get? && !http_auth?
end
MIME_REFERENCES = Mime::HTML.respond_to?(:ref)
def request_format
@request_format ||= if request.format.respond_to?(:ref)
request.format.ref
elsif MIME_REFERENCES
request.format
else # Rails < 3.0.4
request.format.to_sym
end
end
end
end

View File

@@ -1,6 +1,6 @@
# Before logout hook to forget the user in the given scope, if it responds
# to forget_me! Also clear remember token to ensure the user won't be
# remembered again. Notice that we forget the user unless the record is frozen.
# remembered again. Notice that we forget the user unless the record is not persisted.
# This avoids forgetting deleted users.
Warden::Manager.before_logout do |record, warden, options|
if record.respond_to?(:forget_me!)

View File

@@ -1,7 +1,7 @@
# Each time a record is set we check whether its session has already timed out
# or not, based on last request time. If so, the record is logged out and
# redirected to the sign in page. Also, each time the request comes and the
# record is set, we set the last request time inside it's scoped session to
# record is set, we set the last request time inside its scoped session to
# verify timeout in the following request.
Warden::Manager.after_set_user do |record, warden, options|
scope = options[:scope]

View File

@@ -3,7 +3,7 @@
# and on authentication. Retrieving the user from session (:fetch) does
# not trigger it.
Warden::Manager.after_set_user :except => :fetch do |record, warden, options|
if record.respond_to?(:update_tracked_fields!) && warden.authenticated?(options[:scope])
if record.respond_to?(:update_tracked_fields!) && warden.authenticated?(options[:scope]) && !warden.request.env['devise.skip_trackable']
record.update_tracked_fields!(warden.request)
end
end

View File

@@ -0,0 +1,91 @@
module Devise
module Mailers
module Helpers
extend ActiveSupport::Concern
included do
include Devise::Controllers::ScopedViews
attr_reader :scope_name, :resource
end
protected
def setup_mail(*args)
ActiveSupport::Deprecation.warn "setup_mail is deprecated, please use devise_mail instead", caller
devise_mail(*args)
end
# Configure default email options
def devise_mail(record, action)
initialize_from_record(record)
mail headers_for(action)
end
def initialize_from_record(record)
@scope_name = Devise::Mapping.find_scope!(record)
@resource = instance_variable_set("@#{devise_mapping.name}", record)
end
def devise_mapping
@devise_mapping ||= Devise.mappings[scope_name]
end
def headers_for(action)
headers = {
:subject => translate(devise_mapping, action),
:from => mailer_sender(devise_mapping),
:to => resource.email,
:template_path => template_paths
}
if resource.respond_to?(:headers_for)
headers.merge!(resource.headers_for(action))
end
unless headers.key?(:reply_to)
headers[:reply_to] = headers[:from]
end
headers
end
def mailer_sender(mapping)
if default_params[:from].present?
default_params[:from]
elsif Devise.mailer_sender.is_a?(Proc)
Devise.mailer_sender.call(mapping.name)
else
Devise.mailer_sender
end
end
def template_paths
template_path = [self.class.mailer_name]
template_path.unshift "#{@devise_mapping.scoped_path}/mailer" if self.class.scoped_views?
template_path
end
# Setup a subject doing an I18n lookup. At first, it attemps to set a subject
# based on the current mapping:
#
# en:
# devise:
# mailer:
# confirmation_instructions:
# user_subject: '...'
#
# If one does not exist, it fallbacks to ActionMailer default:
#
# en:
# devise:
# mailer:
# confirmation_instructions:
# subject: '...'
#
def translate(mapping, key)
I18n.t(:"#{mapping.name}_subject", :scope => [:devise, :mailer, key],
:default => [:subject, key.to_s.humanize])
end
end
end
end

View File

@@ -22,7 +22,8 @@ module Devise
# # is the modules included in the class
#
class Mapping #:nodoc:
attr_reader :singular, :scoped_path, :path, :controllers, :path_names, :class_name, :sign_out_via
attr_reader :singular, :scoped_path, :path, :controllers, :path_names,
:class_name, :sign_out_via, :format, :used_routes, :used_helpers
alias :name :singular
# Receives an object and find a scope for it. If a scope cannot be found,
@@ -58,12 +59,38 @@ module Devise
mod = options[:module] || "devise"
@controllers = Hash.new { |h,k| h[k] = "#{mod}/#{k}" }
@controllers.merge!(options[:controllers] || {})
@controllers.each { |k,v| @controllers[k] = v.to_s }
@path_names = Hash.new { |h,k| h[k] = k.to_s }
@path_names.merge!(:registration => "")
@path_names.merge!(options[:path_names] || {})
@constraints = Hash.new { |h,k| h[k] = k.to_s }
@constraints.merge!(options[:constraints] || {})
@defaults = Hash.new { |h,k| h[k] = k.to_s }
@defaults.merge!(options[:defaults] || {})
@sign_out_via = options[:sign_out_via] || Devise.sign_out_via
@format = options[:format]
singularizer = lambda { |s| s.to_s.singularize.to_sym }
if options.has_key?(:only)
@used_routes = self.routes & Array(options[:only]).map(&singularizer)
elsif options[:skip] == :all
@used_routes = []
else
@used_routes = self.routes - Array(options[:skip]).map(&singularizer)
end
if options[:skip_helpers] == true
@used_helpers = @used_routes
elsif skip = options[:skip_helpers]
@used_helpers = self.routes - Array(skip).map(&singularizer)
else
@used_helpers = self.routes
end
end
# Return modules for the mapping.
@@ -73,17 +100,17 @@ module Devise
# Gives the class the mapping points to.
def to
if defined?(ActiveSupport::Dependencies::ClassCache)
@ref.get @class_name
else
@ref.get
end
@ref.get
end
def strategies
@strategies ||= STRATEGIES.values_at(*self.modules).compact.uniq.reverse
end
def no_input_strategies
self.strategies & Devise::NO_INPUT
end
def routes
@routes ||= ROUTES.values_at(*self.modules).compact.uniq
end
@@ -95,7 +122,15 @@ module Devise
def fullpath
"/#{@path_prefix}/#{@path}".squeeze("/")
end
def constraints
@constraints
end
def defaults
@defaults
end
# Create magic predicates for verifying what module is activated by this map.
# Example:
#

View File

@@ -17,6 +17,9 @@ module Devise
# inside the given class.
#
def self.config(mod, *accessors) #:nodoc:
(class << mod; self; end).send :attr_accessor, :available_configs
mod.available_configs = accessors
accessors.each do |accessor|
mod.class_eval <<-METHOD, __FILE__, __LINE__ + 1
def #{accessor}
@@ -46,13 +49,33 @@ module Devise
#
def devise(*modules)
include Devise::Models::Authenticatable
options = modules.extract_options!
self.devise_modules += modules.map(&:to_sym).uniq.sort_by { |s|
options = modules.extract_options!.dup
selected_modules = modules.map(&:to_sym).uniq.sort_by do |s|
Devise::ALL.index(s) || -1 # follow Devise::ALL order
}
end
devise_modules_hook! do
devise_modules.each { |m| include Devise::Models.const_get(m.to_s.classify) }
selected_modules.each do |m|
mod = Devise::Models.const_get(m.to_s.classify)
if mod.const_defined?("ClassMethods")
class_mod = mod.const_get("ClassMethods")
extend class_mod
if class_mod.respond_to?(:available_configs)
available_configs = class_mod.available_configs
available_configs.each do |config|
next unless options.key?(config)
send(:"#{config}=", options.delete(config))
end
end
end
include mod
end
self.devise_modules |= selected_modules
options.each { |key, value| send(:"#{key}=", value) }
end
end

View File

@@ -1,4 +1,5 @@
require 'devise/hooks/activatable'
require 'devise/models/serializable'
module Devise
module Models
@@ -46,6 +47,8 @@ module Devise
module Authenticatable
extend ActiveSupport::Concern
include Devise::Models::Serializable
included do
class_attribute :devise_modules, :instance_writer => false
self.devise_modules ||= []
@@ -65,20 +68,8 @@ module Devise
end
end
def active?
ActiveSupport::Deprecation.warn "[DEVISE] active? is deprecated, please use active_for_authentication? instead.", caller
active_for_authentication?
end
def active_for_authentication?
my_methods = self.class.instance_methods(false)
if my_methods.include?("active?") || my_methods.include?(:active?)
ActiveSupport::Deprecation.warn "[DEVISE] Overriding active? is deprecated to avoid conflicts. " \
"Please use active_for_authentication? instead.", caller
active?
else
true
end
true
end
def inactive_message
@@ -89,7 +80,16 @@ module Devise
end
module ClassMethods
Devise::Models.config(self, :authentication_keys, :request_keys, :case_insensitive_keys, :http_authenticatable, :params_authenticatable)
Devise::Models.config(self, :authentication_keys, :request_keys, :strip_whitespace_keys, :case_insensitive_keys, :http_authenticatable, :params_authenticatable)
def serialize_into_session(record)
[record.to_key, record.authenticatable_salt]
end
def serialize_from_session(key, salt)
record = to_adapter.get(key)
record if record && record.authenticatable_salt == salt
end
def params_authenticatable?(strategy)
params_authenticatable.is_a?(Array) ?
@@ -112,8 +112,9 @@ module Devise
# end
#
def find_for_authentication(conditions)
filter_auth_params(conditions)
conditions = filter_auth_params(conditions.dup)
(case_insensitive_keys || []).each { |k| conditions[k].try(:downcase!) }
(strip_whitespace_keys || []).each { |k| conditions[k].try(:strip!) }
to_adapter.find_first(conditions)
end
@@ -125,14 +126,15 @@ module Devise
# Find an initialize a group of attributes based on a list of required attributes.
def find_or_initialize_with_errors(required_attributes, attributes, error=:invalid) #:nodoc:
(case_insensitive_keys || []).each { |k| attributes[k].try(:downcase!) }
(strip_whitespace_keys || []).each { |k| attributes[k].try(:strip!) }
attributes = attributes.slice(*required_attributes)
attributes.delete_if { |key, value| value.blank? }
if attributes.size == required_attributes.size
record = to_adapter.find_first(filter_auth_params(attributes))
end
unless record
record = new
@@ -151,9 +153,14 @@ module Devise
# Force keys to be string to avoid injection on mongoid related database.
def filter_auth_params(conditions)
conditions.each do |k, v|
conditions[k] = v.to_s
conditions[k] = v.to_s if auth_param_requires_string_conversion?(v)
end if conditions.is_a?(Hash)
end
# Determine which values should be transformed to string or passed as-is to the query builder underneath
def auth_param_requires_string_conversion?(value)
true unless value.is_a?(TrueClass) || value.is_a?(FalseClass) || value.is_a?(Fixnum)
end
# Generate a token by looping and ensuring does not already exist.
def generate_token(column)

View File

@@ -29,7 +29,7 @@ module Devise
after_create :send_confirmation_instructions, :if => :confirmation_required?
end
# Confirm a user by setting it's confirmed_at to actual time. If the user
# Confirm a user by setting its confirmed_at to actual time. If the user
# is already confirmed, add en error to email field
def confirm!
unless_confirmed do
@@ -84,7 +84,7 @@ module Devise
# Checks if the confirmation for the user is within the limit time.
# We do this by calculating if the difference between today and the
# confirmation sent date does not exceed the confirm in time configured.
# Confirm_in is a model configuration, must always be an integer value.
# Confirm_within is a model configuration, must always be an integer value.
#
# Example:
#
@@ -127,8 +127,13 @@ module Devise
generate_confirmation_token && save(:validate => false)
end
def after_password_reset
super
confirm! unless confirmed?
end
module ClassMethods
# Attempt to find a user by it's email. If a record is found, send new
# Attempt to find a user by its email. If a record is found, send new
# confirmation instructions to it. If not user is found, returns a new user
# with an email not found error.
# Options must contain the user email
@@ -138,7 +143,7 @@ module Devise
confirmable
end
# Find a user by it's confirmation token and try to confirm it.
# Find a user by its confirmation token and try to confirm it.
# If no user is found, returns a new user with an error.
# If the user is already confirmed, create an error for the user
# Options must have the confirmation_token

View File

@@ -10,6 +10,9 @@ module Devise
#
# DatabaseAuthenticable adds the following options to devise_for:
#
# * +pepper+: a random string used to provide a more secure hash. Use
# `rake secret` to generate new keys.
#
# * +stretches+: the cost given to bcrypt.
#
# == Examples
@@ -22,7 +25,8 @@ module Devise
included do
attr_reader :password, :current_password
attr_accessor :password_confirmation
before_save :downcase_keys
before_validation :downcase_keys
before_validation :strip_whitespace
end
# Generates password encryption based on the given value.
@@ -33,6 +37,7 @@ module Devise
# Verifies whether an password (ie from sign in) is the user password.
def valid_password?(password)
return false if encrypted_password.blank?
bcrypt = ::BCrypt::Password.new(self.encrypted_password)
password = ::BCrypt::Engine.hash_secret("#{password}#{self.class.pepper}", bcrypt.salt)
Devise.secure_compare(password, self.encrypted_password)
@@ -57,8 +62,9 @@ module Devise
result = if valid_password?(current_password)
update_attributes(params)
else
self.errors.add(:current_password, current_password.blank? ? :blank : :invalid)
self.attributes = params
self.valid?
self.errors.add(:current_password, current_password.blank? ? :blank : :invalid)
false
end
@@ -66,6 +72,17 @@ module Devise
result
end
# Updates record attributes without asking for the current password.
# Never allows to change the current password
def update_without_password(params={})
params.delete(:password)
params.delete(:password_confirmation)
result = update_attributes(params)
clean_up_passwords
result
end
def after_database_authentication
end
@@ -80,6 +97,10 @@ module Devise
def downcase_keys
(self.class.case_insensitive_keys || []).each { |k| self[k].try(:downcase!) }
end
def strip_whitespace
(self.class.strip_whitespace_keys || []).each { |k| self[k].try(:strip!) }
end
# Digests the password using bcrypt.
def password_digest(password)

View File

@@ -3,13 +3,13 @@ module Devise
# Handles blocking a user access after a certain number of attempts.
# Lockable accepts two different strategies to unlock a user after it's
# blocked: email and time. The former will send an email to the user when
# the lock happens, containing a link to unlock it's account. The second
# the lock happens, containing a link to unlock its account. The second
# will unlock the user automatically after some configured time (ie 2.hours).
# It's also possible to setup lockable to use both email and time strategies.
#
# == Options
#
# Lockable adds the following options to devise_for:
# Lockable adds the following options to +devise+:
#
# * +maximum_attempts+: how many attempts should be accepted before blocking the user.
# * +lock_strategy+: lock the user account by :failed_attempts or :none.
@@ -22,7 +22,7 @@ module Devise
delegate :lock_strategy_enabled?, :unlock_strategy_enabled?, :to => "self.class"
# Lock a user setting it's locked_at to actual time.
# Lock a user setting its locked_at to actual time.
def lock_access!
self.locked_at = Time.now
@@ -132,7 +132,7 @@ module Devise
end
module ClassMethods
# Attempt to find a user by it's email. If a record is found, send new
# Attempt to find a user by its email. If a record is found, send new
# unlock instructions to it. If not user is found, returns a new user
# with an email not found error.
# Options must contain the user email
@@ -142,7 +142,7 @@ module Devise
lockable
end
# Find a user by it's unlock token and try to unlock it.
# Find a user by its unlock token and try to unlock it.
# If no user is found, returns a new user with an error.
# If the user is not locked, creates an error for the user
# Options must have the unlock_token

View File

@@ -29,21 +29,56 @@ module Devise
def reset_password!(new_password, new_password_confirmation)
self.password = new_password
self.password_confirmation = new_password_confirmation
clear_reset_password_token if valid?
if valid?
clear_reset_password_token
after_password_reset
end
save
end
# Resets reset password token and send reset password instructions by email
def send_reset_password_instructions
generate_reset_password_token!
generate_reset_password_token! if should_generate_token?
::Devise.mailer.reset_password_instructions(self).deliver
end
# Checks if the reset password token sent is within the limit time.
# We do this by calculating if the difference between today and the
# sending date does not exceed the confirm in time configured.
# Returns true if the resource is not responding to reset_password_sent_at at all.
# reset_password_within is a model configuration, must always be an integer value.
#
# Example:
#
# # reset_password_within = 1.day and reset_password_sent_at = today
# reset_password_period_valid? # returns true
#
# # reset_password_within = 5.days and reset_password_sent_at = 4.days.ago
# reset_password_period_valid? # returns true
#
# # reset_password_within = 5.days and reset_password_sent_at = 5.days.ago
# reset_password_period_valid? # returns false
#
# # reset_password_within = 0.days
# reset_password_period_valid? # will always return false
#
def reset_password_period_valid?
return true unless respond_to?(:reset_password_sent_at)
reset_password_sent_at && reset_password_sent_at.utc >= self.class.reset_password_within.ago
end
protected
def should_generate_token?
reset_password_token.nil? || !reset_password_period_valid?
end
# Generates a new random token for reset password
def generate_reset_password_token
self.reset_password_token = self.class.reset_password_token
self.reset_password_sent_at = Time.now.utc if respond_to?(:reset_password_sent_at=)
self.reset_password_token
end
# Resets the reset password token with and save the record without
@@ -55,10 +90,14 @@ module Devise
# Removes reset_password token
def clear_reset_password_token
self.reset_password_token = nil
self.reset_password_sent_at = nil if respond_to?(:reset_password_sent_at=)
end
def after_password_reset
end
module ClassMethods
# Attempt to find a user by it's email. If a record is found, send new
# Attempt to find a user by its email. If a record is found, send new
# password instructions to it. If not user is found, returns a new user
# with an email not found error.
# Attributes must contain the user email
@@ -73,18 +112,24 @@ module Devise
generate_token(:reset_password_token)
end
# Attempt to find a user by it's reset_password_token to reset it's
# password. If a user is found, reset it's password and automatically
# Attempt to find a user by its reset_password_token to reset its
# password. If a user is found and token is still valid, reset its password and automatically
# try saving the record. If not user is found, returns a new user
# containing an error in reset_password_token attribute.
# Attributes must contain reset_password_token, password and confirmation
def reset_password_by_token(attributes={})
recoverable = find_or_initialize_with_error_by(:reset_password_token, attributes[:reset_password_token])
recoverable.reset_password!(attributes[:password], attributes[:password_confirmation]) if recoverable.persisted?
if recoverable.persisted?
if recoverable.reset_password_period_valid?
recoverable.reset_password!(attributes[:password], attributes[:password_confirmation])
else
recoverable.errors.add(:reset_password_token, :expired)
end
end
recoverable
end
Devise::Models.config(self, :reset_password_keys)
Devise::Models.config(self, :reset_password_keys, :reset_password_within)
end
end
end

View File

@@ -54,12 +54,14 @@ module Devise
save(:validate => false)
end
# Removes the remember token only if it exists, and save the record
# without validations.
# If the record is persisted, remove the remember token (but only if
# it exists), and save the record without validations.
def forget_me!
self.remember_token = nil if respond_to?(:remember_token=)
self.remember_created_at = nil
save(:validate => false)
if persisted?
self.remember_token = nil if respond_to?(:remember_token=)
self.remember_created_at = nil
save(:validate => false)
end
end
# Remember token should be expired if expiration time not overpass now.

View File

@@ -0,0 +1,43 @@
module Devise
module Models
# This module redefine to_xml and serializable_hash in models for more
# secure defaults. By default, it removes from the serializable model
# all attributes that are *not* accessible. You can remove this default
# by using :force_except and passing a new list of attributes you want
# to exempt. All attributes given to :except will simply add names to
# exempt to Devise internal list.
module Serializable
extend ActiveSupport::Concern
# TODO: to_xml does not call serializable_hash. Hopefully someone will fix this in AR.
%w(to_xml serializable_hash).each do |method|
class_eval <<-RUBY, __FILE__, __LINE__
def #{method}(options=nil)
options ||= {}
if options.key?(:force_except)
options[:except] = options.delete(:force_except)
super(options)
elsif self.class.blacklist_keys?
except = Array(options[:except])
super(options.merge(:except => except + self.class.blacklist_keys))
else
super
end
end
RUBY
end
module ClassMethods
# Return true if we can retrieve blacklist keys from the record.
def blacklist_keys?
@has_except_keys ||= respond_to?(:accessible_attributes) && !accessible_attributes.to_a.empty?
end
# Returns keys that should be removed when serializing the record.
def blacklist_keys
@blacklist_keys ||= to_adapter.column_names.map(&:to_s) - accessible_attributes.to_a.map(&:to_s)
end
end
end
end
end

View File

@@ -5,10 +5,10 @@ module Devise
# Track information about your user sign in. It tracks the following columns:
#
# * sign_in_count - Increased every time a sign in is made (by form, openid, oauth)
# * current_sign_in_at - A tiemstamp updated when the user signs in
# * current_sign_in_at - A timestamp updated when the user signs in
# * last_sign_in_at - Holds the timestamp of the previous sign in
# * current_sign_in_ip - The remote ip updated when the user sign in
# * last_sign_in_at - Holds the remote ip of the previous sign in
# * last_sign_in_ip - Holds the remote ip of the previous sign in
#
module Trackable
def update_tracked_fields!(request)

View File

@@ -2,7 +2,7 @@ module Devise
module Models
# Validatable creates all needed validations for a user email and password.
# It's optional, given you may want to create the validations by yourself.
# Automatically validate if the email is present, unique and it's format is
# Automatically validate if the email is present, unique and its format is
# valid. Also tests presence of password, confirmation and length.
#
# == Options
@@ -10,7 +10,7 @@ module Devise
# Validatable adds the following options to devise_for:
#
# * +email_regexp+: the regular expression used to validate e-mails;
# * +password_length+: a range expressing password length. Defaults to 6..20.
# * +password_length+: a range expressing password length. Defaults to 6..128.
#
module Validatable
# All validations used by this module.
@@ -23,15 +23,12 @@ module Devise
base.class_eval do
validates_presence_of :email, :if => :email_required?
validates_uniqueness_of :email, :scope => authentication_keys[1..-1],
:case_sensitive => (case_insensitive_keys != false), :allow_blank => true
validates_format_of :email, :with => email_regexp, :allow_blank => true
validates_uniqueness_of :email, :case_sensitive => (case_insensitive_keys != false), :allow_blank => true, :if => :email_changed?
validates_format_of :email, :with => email_regexp, :allow_blank => true, :if => :email_changed?
with_options :if => :password_required? do |v|
v.validates_presence_of :password
v.validates_confirmation_of :password
v.validates_length_of :password, :within => password_length, :allow_blank => true
end
validates_presence_of :password, :if => :password_required?
validates_confirmation_of :password, :if => :password_required?
validates_length_of :password, :within => password_length, :allow_blank => true
end
end

View File

@@ -5,7 +5,7 @@ Devise.with_options :model => true do |d|
d.with_options :strategy => true do |s|
routes = [nil, :new, :destroy]
s.add_module :database_authenticatable, :controller => :sessions, :route => { :session => routes }
s.add_module :token_authenticatable, :controller => :sessions, :route => { :session => routes }
s.add_module :token_authenticatable
s.add_module :rememberable
end

View File

@@ -14,19 +14,14 @@ OmniAuth.config.path_prefix = nil
OmniAuth.config.on_failure = Proc.new do |env|
env['devise.mapping'] = Devise::Mapping.find_by_path!(env['PATH_INFO'], :path)
controller_klass = "#{env['devise.mapping'].controllers[:omniauth_callbacks].camelize}Controller"
controller_klass.constantize.action(:failure).call(env)
controller_name = ActiveSupport::Inflector.camelize(env['devise.mapping'].controllers[:omniauth_callbacks])
controller_klass = ActiveSupport::Inflector.constantize("#{controller_name}Controller")
controller_klass.action(:failure).call(env)
end
module Devise
module OmniAuth
autoload :Config, "devise/omniauth/config"
autoload :UrlHelpers, "devise/omniauth/url_helpers"
autoload :TestHelpers, "devise/omniauth/test_helpers"
class << self
delegate :short_circuit_authorizers!, :unshort_circuit_authorizers!,
:test_mode!, :stub!, :reset_stubs!, :to => "Devise::OmniAuth::TestHelpers"
end
end
end

View File

@@ -10,6 +10,12 @@ module Devise
@strategy = nil
end
# open_id strategy can have configurable name
def strategy_name
options = @args.last.is_a?(Hash) && @args.last
options && options[:name] ? options[:name] : @provider
end
def strategy_class
::OmniAuth::Strategies.const_get("#{::OmniAuth::Utils.camelize(@provider.to_s)}")
end

View File

@@ -17,11 +17,14 @@ module Devise
Devise.include_helpers(Devise::Controllers)
end
initializer "devise.navigationals" do
formats = Devise.navigational_formats
if formats.include?(:"*/*") && formats.exclude?("*/*")
puts "[DEVISE] We see the symbol :\"*/*\" in the navigational formats in your initializer " \
"but not the string \"*/*\". Due to changes in latest Rails, please include the latter."
initializer "devise.auth_keys" do
if Devise.authentication_keys.size > 1
puts "[DEVISE] You are configuring Devise to use more than one authentication key. " \
"In previous versions, we automatically added #{Devise.authentication_keys[1..-1].inspect} " \
"as scope to your e-mail validation, but this was changed now. If you were relying in such " \
"behavior, you should remove :validatable from your models and add the validations manually. " \
"To get rid of this warning, you can comment config.authentication_keys in your initializer " \
"and pass the current values as key to the devise call in your model."
end
end
@@ -37,21 +40,16 @@ module Devise
end
end
initializer "devise.encryptor_check" do
case Devise.encryptor
when :bcrypt
puts "[DEVISE] From version 1.2, there is no need to set your encryptor to bcrypt " \
"since encryptors are only enabled if you include :encryptable in your models. " \
"With this change, we can integrate better with bcrypt and get rid of the " \
"password_salt column (since bcrypt stores the salt with password). " \
"Please comment config.encryptor in your initializer to get rid of this warning."
when nil
# Nothing to say
else
puts "[DEVISE] You are using #{Devise.encryptor} as encryptor. From version 1.2, " \
"you need to explicitly add `devise :encryptable, :encryptor => :#{Devise.encryptor}` " \
"to your models and comment the current value in the config/initializers/devise.rb. " \
"You must also add t.encryptable to your existing migrations."
initializer "devise.mongoid_version_warning" do
if defined?(Mongoid)
require 'mongoid/version'
if Mongoid::VERSION.to_f < 2.1
puts "\n[DEVISE] Please note that Mongoid versions prior to 2.1 handle dirty model " \
"object attributes in such a way that the Devise `validatable` module will not apply " \
"its usual uniqueness and format validations for the email field. It is recommended " \
"that you upgrade to Mongoid 2.1+ for this and other fixes, but if for some reason you " \
"are unable to do so, you should add these validations manually.\n"
end
end
end
end

View File

@@ -4,7 +4,12 @@ module ActionDispatch::Routing
# need devise_for mappings already declared to create filters and helpers.
def finalize_with_devise!
finalize_without_devise!
Devise.configure_warden!
@devise_finalized ||= begin
Devise.configure_warden!
Devise.regenerate_helpers!
true
end
end
alias_method_chain :finalize!, :devise
end
@@ -93,12 +98,32 @@ module ActionDispatch::Routing
#
# Also pay attention that when you use a namespace it will affect all the helpers and methods for controllers
# and views. For example, using the above setup you'll end with following methods:
# current_publisher_account, authenticate_publisher_account!, pusblisher_account_signed_in, etc.
# current_publisher_account, authenticate_publisher_account!, publisher_account_signed_in, etc.
#
# * :skip => tell which controller you want to skip routes from being created:
#
# devise_for :users, :skip => :sessions
#
# * :only => the opposite of :skip, tell which controllers only to generate routes to:
#
# devise_for :users, :only => :sessions
#
# * :skip_helpers => skip generating Devise url helpers like new_session_path(@user).
# This is useful to avoid conflicts with previous routes and is false by default.
# It accepts true as option, meaning it will skip all the helpers for the controllers
# given in :skip but it also accepts specific helpers to be skipped:
#
# devise_for :users, :skip => [:registrations, :confirmations], :skip_helpers => true
# devise_for :users, :skip_helpers => [:registrations, :confirmations]
#
# * :format => include "(.:format)" in the generated routes? true by default, set to false to disable:
#
# devise_for :users, :format => false
#
# * :constraints => works the same as Rails' contraints
#
# * :defaults => works the same as Rails' defaults
#
# ==== Scoping
#
# Following Rails 3 routes DSL, you can nest devise_for calls inside a scope:
@@ -124,9 +149,9 @@ module ActionDispatch::Routing
# end
#
# ==== Adding custom actions to override controllers
#
# You can pass a block to devise_for that will add any routes defined in the block to Devise's
# list of known actions. This is important if you add a custom action to a controller that
#
# You can pass a block to devise_for that will add any routes defined in the block to Devise's
# list of known actions. This is important if you add a custom action to a controller that
# overrides an out of the box Devise controller.
# For example:
#
@@ -148,12 +173,16 @@ module ActionDispatch::Routing
# end
#
def devise_for(*resources)
@devise_finalized = false
options = resources.extract_options!
options[:as] ||= @scope[:as] if @scope[:as].present?
options[:module] ||= @scope[:module] if @scope[:module].present?
options[:path_prefix] ||= @scope[:path] if @scope[:path].present?
options[:path_names] = (@scope[:path_names] || {}).merge(options[:path_names] || {})
options[:constraints] = (@scope[:constraints] || {}).merge(options[:constraints] || {})
options[:defaults] = (@scope[:defaults] || {}).merge(options[:defaults] || {})
@scope[:options] = (@scope[:options] || {}).merge({:format => false}) if options[:format] == false
resources.map!(&:to_sym)
@@ -172,12 +201,11 @@ module ActionDispatch::Routing
raise_no_devise_method_error!(mapping.class_name)
end
routes = mapping.routes
routes -= Array(options.delete(:skip)).map { |s| s.to_s.singularize.to_sym }
routes = mapping.used_routes
devise_scope mapping.name do
yield if block_given?
with_devise_exclusive_scope mapping.fullpath, mapping.name do
with_devise_exclusive_scope mapping.fullpath, mapping.name, mapping.constraints, mapping.defaults do
routes.each { |mod| send("devise_#{mod}", mapping, mapping.controllers) }
end
end
@@ -186,11 +214,15 @@ module ActionDispatch::Routing
# Allow you to add authentication request from the router:
#
# authenticate(:user) do
# authenticate do
# resources :post
# end
#
def authenticate(scope)
# authenticate(:admin) do
# resources :users
# end
#
def authenticate(scope=nil)
constraint = lambda do |request|
request.env["warden"].authenticate!(:scope => scope)
end
@@ -200,6 +232,50 @@ module ActionDispatch::Routing
end
end
# Allow you to route based on whether a scope is authenticated. You
# can optionally specify which scope.
#
# authenticated :admin do
# root :to => 'admin/dashboard#show'
# end
#
# authenticated do
# root :to => 'dashboard#show'
# end
#
# root :to => 'landing#show'
#
def authenticated(scope=nil)
constraint = lambda do |request|
request.env["warden"].authenticate? :scope => scope
end
constraints(constraint) do
yield
end
end
# Allow you to route based on whether a scope is *not* authenticated.
# You can optionally specify which scope.
#
# unauthenticated do
# as :user do
# root :to => 'devise/registrations#new'
# end
# end
#
# root :to => 'dashboard#show'
#
def unauthenticated(scope=nil)
constraint = lambda do |request|
not request.env["warden"].authenticate? :scope => scope
end
constraints(constraint) do
yield
end
end
# Sets the devise scope to be used in the controller. If you have custom routes,
# you are required to call this method (also aliased as :as) in order to specify
# to which controller it is targetted.
@@ -211,6 +287,17 @@ module ActionDispatch::Routing
# Notice you cannot have two scopes mapping to the same URL. And remember, if
# you try to access a devise controller without specifying a scope, it will
# raise ActionNotFound error.
#
# Also be aware of that 'devise_scope' and 'as' use the singular form of the
# noun where other devise route commands expect the plural form. This would be a
# good and working example.
#
# devise_scope :user do
# match "/some/route" => "some_devise_controller"
# end
# devise_for :users
#
# Notice and be aware of the differences above between :user and :users
def devise_scope(scope)
constraint = lambda do |request|
request.env["devise.mapping"] = Devise.mappings[scope]
@@ -256,7 +343,7 @@ module ActionDispatch::Routing
:cancel => mapping.path_names[:cancel]
}
resource :registration, :except => :show, :path => mapping.path_names[:registration],
resource :registration, :only => [:new, :create, :edit, :update, :destroy], :path => mapping.path_names[:registration],
:path_names => path_names, :controller => controllers[:registrations] do
get :cancel
end
@@ -272,23 +359,23 @@ module ActionDispatch::Routing
::OmniAuth.config.path_prefix = path_prefix
end
match "#{path_prefix}/:action/callback", :action => Regexp.union(mapping.to.omniauth_providers.map(&:to_s)),
match "#{path_prefix}/:action/callback", :constraints => { :action => Regexp.union(mapping.to.omniauth_providers.map(&:to_s)) },
:to => controllers[:omniauth_callbacks], :as => :omniauth_callback
ensure
@scope[:path] = path
end
def with_devise_exclusive_scope(new_path, new_as) #:nodoc:
old_as, old_path, old_module = @scope[:as], @scope[:path], @scope[:module]
@scope[:as], @scope[:path], @scope[:module] = new_as, new_path, nil
def with_devise_exclusive_scope(new_path, new_as, new_constraints, new_defaults) #:nodoc:
old_as, old_path, old_module, old_constraints, old_defaults = @scope[:as], @scope[:path], @scope[:module], @scope[:constraints], @scope[:defaults]
@scope[:as], @scope[:path], @scope[:module], @scope[:constraints], @scope[:defaults] = new_as, new_path, nil, new_constraints, new_defaults
yield
ensure
@scope[:as], @scope[:path], @scope[:module] = old_as, old_path, old_module
@scope[:as], @scope[:path], @scope[:module], @scope[:constraints], @scope[:defaults] = old_as, old_path, old_module, old_constraints, old_defaults
end
def raise_no_devise_method_error!(klass) #:nodoc:
raise "#{klass} does not respond to 'devise' method. This usually means you haven't " <<
"loaded your ORM file or it's being loaded too late. To fix it, be sure to require 'devise/orm/YOUR_ORM' " <<
raise "#{klass} does not respond to 'devise' method. This usually means you haven't " \
"loaded your ORM file or it's being loaded too late. To fix it, be sure to require 'devise/orm/YOUR_ORM' " \
"inside 'config/initializers/devise.rb' or before your application definition in 'config/application.rb'"
end
end

View File

@@ -15,21 +15,16 @@ end
class Warden::SessionSerializer
def serialize(record)
[record.class.name, record.to_key, record.authenticatable_salt]
klass = record.class
array = klass.serialize_into_session(record)
array.unshift(klass.name)
end
def deserialize(keys)
if keys.size == 2
raise "Devise changed how it stores objects in session. If you are seeing this message, " <<
"you can fix it by changing one character in your cookie secret or cleaning up your " <<
"database sessions if you are using a db store."
end
klass, id, salt = keys
klass, *args = keys
begin
record = klass.constantize.to_adapter.get(id)
record if record && record.authenticatable_salt == salt
ActiveSupport::Inflector.constantize(klass).serialize_from_session(*args)
rescue NameError => e
if e.message =~ /uninitialized constant/
Rails.logger.debug "[Devise] Trying to deserialize invalid class #{klass}"

View File

@@ -3,11 +3,12 @@ module Devise
# and overwrite the apply_schema method.
module Schema
# Creates email when enabled (on by default), encrypted_password and password_salt.
# Creates encrypted_password, and email when it is used as an authentication
# key (default).
#
# == Options
# * :null - When true, allow columns to be null.
# * :default - Should be set to "" when :null is false.
# * :default - Set to "" when :null is false, unless overridden.
#
# == Notes
# For Datamapper compatibility, we explicitly hardcode the limit for the
@@ -15,13 +16,14 @@ module Devise
def database_authenticatable(options={})
null = options[:null] || false
default = options.key?(:default) ? options[:default] : ("" if null == false)
include_email = !self.respond_to?(:authentication_keys) || self.authentication_keys.include?(:email)
include_email = !respond_to?(:authentication_keys) || self.authentication_keys.include?(:email)
apply_devise_schema :email, String, :null => null, :default => default if include_email
apply_devise_schema :encrypted_password, String, :null => null, :default => default, :limit => 128
end
# Creates password salt for encryption support.
# Creates password salt for encryption support when using encryptors other
# than the database_authenticable default of bcrypt.
def encryptable
apply_devise_schema :password_salt, String
end
@@ -38,9 +40,14 @@ module Devise
apply_devise_schema :confirmation_sent_at, DateTime
end
# Creates reset_password_token.
def recoverable
# Creates reset_password_token and reset_password_sent_at.
#
# == Options
# * :reset_within - When true, adds a column that reset passwords within some date
def recoverable(options={})
use_within = options.fetch(:reset_within, Devise.reset_password_within.present?)
apply_devise_schema :reset_password_token, String
apply_devise_schema :reset_password_sent_at, DateTime if use_within
end
# Creates remember_token and remember_created_at.

View File

@@ -85,17 +85,17 @@ module Devise
# By default, a request is valid if the controller is allowed and the VERB is POST.
def valid_request?
valid_controller? && valid_verb?
end
# Check if the controller is the one registered for authentication.
def valid_controller?
mapping.controllers[:sessions] == params[:controller]
end
# Check if it was a POST request.
def valid_verb?
request.post?
if env["devise.allow_params_authentication"]
true
elsif request.post? && mapping.controllers[:sessions] == params[:controller]
ActiveSupport::Deprecation.warn "It seems that you are using a custom SessionsController. " \
"In order for it to work from Devise 1.4.6 forward, you need to add the following:" \
"\n\n prepend_before_filter :allow_params_authentication!, :only => :create\n\n" \
"This will ensure your controller can authenticate from params for the create action.", caller
true
else
false
end
end
# If the request is valid, finally check if params_auth_hash returns a hash.
@@ -157,7 +157,8 @@ module Devise
# becomes simply :database.
def authenticatable_name
@authenticatable_name ||=
self.class.name.split("::").last.underscore.sub("_authenticatable", "").to_sym
ActiveSupport::Inflector.underscore(self.class.name.split("::").last).
sub("_authenticatable", "").to_sym
end
end
end

View File

@@ -9,6 +9,7 @@ module Devise
class Rememberable < Authenticatable
# A valid strategy for rememberable needs a remember token in the cookies.
def valid?
@remember_cookie = nil
remember_cookie.present?
end
@@ -41,10 +42,10 @@ module Devise
"remember_#{scope}_token"
end
# Accessor for remember cookie
def remember_cookie
@remember_cookie ||= cookies.signed[remember_key]
end
end
end
end

View File

@@ -39,7 +39,11 @@ module Devise
# Try both scoped and non scoped keys.
def params_auth_hash
params[scope] || params
if params[scope].kind_of?(Hash) && params[scope].has_key?(authentication_keys.first)
params[scope]
else
params
end
end
# Overwrite authentication keys to use token_authentication_key.

View File

@@ -13,48 +13,11 @@ module Devise
end
end
# This is a Warden::Proxy customized for functional tests. It's meant to
# some of Warden::Manager responsibilities, as retrieving configuration
# options and calling the FailureApp.
class TestWarden < Warden::Proxy #:nodoc:
attr_reader :controller
def initialize(controller)
@controller = controller
manager = Warden::Manager.new(nil) do |config|
config.merge! Devise.warden_config
end
super(controller.request.env, manager)
end
def authenticate!(*args)
catch_with_redirect { super }
end
def user(*args)
catch_with_redirect { super }
end
def catch_with_redirect(&block)
result = catch(:warden, &block)
if result.is_a?(Hash) && !custom_failure? && !@controller.send(:performed?)
result[:action] ||= :unauthenticated
env = @controller.request.env
env["PATH_INFO"] = "/#{result[:action]}"
env["warden.options"] = result
Warden::Manager._run_callbacks(:before_failure, env, result)
status, headers, body = Devise.warden_config[:failure_app].call(env).to_a
@controller.send :render, :status => status, :text => body,
:content_type => headers["Content-Type"], :location => headers["Location"]
nil
else
result
end
end
# Override process to consider warden.
def process(*)
result = nil
_catch_warden { result = super }
result
end
# We need to setup the environment variables and the response in the controller.
@@ -64,7 +27,12 @@ module Devise
# Quick access to Warden::Proxy.
def warden #:nodoc:
@warden ||= (@request.env['warden'] = TestWarden.new(@controller))
@warden ||= begin
manager = Warden::Manager.new(nil) do |config|
config.merge! Devise.warden_config
end
@request.env['warden'] = Warden::Proxy.new(@request.env, manager)
end
end
# sign_in a given resource by storing its keys in the session.
@@ -96,5 +64,27 @@ module Devise
warden.session_serializer.delete(scope, user)
end
protected
def _catch_warden(&block)
result = catch(:warden, &block)
if result.is_a?(Hash) && !warden.custom_failure? && !@controller.send(:performed?)
result[:action] ||= :unauthenticated
env = @controller.request.env
env["PATH_INFO"] = "/#{result[:action]}"
env["warden.options"] = result
Warden::Manager._run_callbacks(:before_failure, env, result)
status, headers, body = Devise.warden_config[:failure_app].call(env).to_a
@controller.send :render, :status => status, :text => body,
:content_type => headers["Content-Type"], :location => headers["Location"]
nil
else
result
end
end
end
end

View File

@@ -1,3 +1,3 @@
module Devise
VERSION = "1.2.0".freeze
VERSION = "1.4.7".freeze
end

View File

@@ -1,6 +1,7 @@
require 'rails/generators/active_record'
require 'generators/devise/orm_helpers'
module ActiveRecord
module Generators
class DeviseGenerator < ActiveRecord::Generators::Base
@@ -9,14 +10,18 @@ module ActiveRecord
include Devise::Generators::OrmHelpers
source_root File.expand_path("../templates", __FILE__)
def copy_devise_migration
if (behavior == :invoke && model_exists?) || (behavior == :revoke && migration_exists?(table_name))
migration_template "migration_existing.rb", "db/migrate/add_devise_to_#{table_name}"
else
migration_template "migration.rb", "db/migrate/devise_create_#{table_name}"
end
end
def generate_model
invoke "active_record:model", [name], :migration => false unless model_exists? && behavior == :invoke
end
def copy_devise_migration
migration_template "migration.rb", "db/migrate/devise_create_#{table_name}"
end
def inject_devise_content
inject_into_class(model_path, class_name, model_contents + <<CONTENT) if model_exists?
# Setup accessible (or protected) attributes for your model

View File

@@ -0,0 +1,34 @@
class AddDeviseTo<%= table_name.camelize %> < ActiveRecord::Migration
def self.up
change_table(:<%= table_name %>) do |t|
t.database_authenticatable :null => false
t.recoverable
t.rememberable
t.trackable
# t.encryptable
# t.confirmable
# t.lockable :lock_strategy => :<%= Devise.lock_strategy %>, :unlock_strategy => :<%= Devise.unlock_strategy %>
# t.token_authenticatable
<% for attribute in attributes -%>
t.<%= attribute.type %> :<%= attribute.name %>
<% end -%>
# Uncomment below if timestamps were not included in your original model.
# t.timestamps
end
add_index :<%= table_name %>, :email, :unique => true
add_index :<%= table_name %>, :reset_password_token, :unique => true
# add_index :<%= table_name %>, :confirmation_token, :unique => true
# add_index :<%= table_name %>, :unlock_token, :unique => true
# add_index :<%= table_name %>, :authentication_token, :unique => true
end
def self.down
# By default, we don't want to make any assumption about how to roll back a migration when your
# model already existed. Please edit below which fields you would like to remove in this migration.
raise ActiveRecord::IrreversibleMigration
end
end

View File

@@ -9,9 +9,12 @@ module Devise
hook_for :orm
class_option :routes, :desc => "Generate routes", :type => :boolean, :default => true
def add_devise_routes
devise_route = "devise_for :#{plural_name}"
devise_route += %Q(, :class_name => "#{class_name}") if class_name.include?("::")
devise_route << %Q(, :class_name => "#{class_name}") if class_name.include?("::")
devise_route << %Q(, :skip => :all) unless options.routes?
route devise_route
end
end

View File

@@ -1,4 +1,4 @@
require 'active_support/secure_random'
require 'securerandom'
module Devise
module Generators
@@ -21,4 +21,4 @@ module Devise
end
end
end
end
end

View File

@@ -14,6 +14,14 @@ CONTENT
def model_exists?
File.exists?(File.join(destination_root, model_path))
end
def migration_exists?(table_name)
Dir.glob("#{File.join(destination_root, migration_path)}/[0-9]*_*.rb").grep(/\d+_add_devise_to_#{table_name}.rb$/).first
end
def migration_path
@migration_path ||= File.join("db", "migrate")
end
def model_path
@model_path ||= File.join("app", "models", "#{file_path}.rb")

View File

@@ -1,26 +1,72 @@
require 'tmpdir'
module Devise
module Generators
# Include this module in your generator to generate Devise views.
# `copy_views` is the main method and by default copies all views
# with forms.
module ViewPathTemplates #:nodoc:
extend ActiveSupport::Concern
included do
argument :scope, :required => false, :default => nil,
:desc => "The scope to copy views to"
public_task :copy_views
end
def copy_views
view_directory :confirmations
view_directory :passwords
view_directory :registrations
view_directory :sessions
view_directory :unlocks
end
protected
def view_directory(name)
directory name.to_s, "#{target_path}/#{name}"
end
def target_path
@target_path ||= "app/views/#{scope || :devise}"
end
end
class SharedViewsGenerator < Rails::Generators::Base #:nodoc:
include ViewPathTemplates
source_root File.expand_path("../../../../app/views/devise", __FILE__)
desc "Copies shared Devise views to your application."
# Override copy_views to just copy mailer and shared.
def copy_views
view_directory :mailer
view_directory :shared
end
end
class FormForGenerator < Rails::Generators::Base #:nodoc:
include ViewPathTemplates
source_root File.expand_path("../../../../app/views/devise", __FILE__)
desc "Copies default Devise views to your application."
end
class SimpleFormForGenerator < Rails::Generators::Base #:nodoc:
include ViewPathTemplates
source_root File.expand_path("../../templates/simple_form_for", __FILE__)
desc "Copies simple form enabled views to your application."
end
class ViewsGenerator < Rails::Generators::Base
source_root File.expand_path("../../../../app/views", __FILE__)
desc "Copies all Devise views to your application."
desc "Copies Devise views to your application."
argument :scope, :required => false, :default => nil,
:desc => "The scope to copy views to"
class_option :template_engine, :type => :string, :aliases => "-t",
:desc => "Template engine for the views. Available options are 'erb', 'haml' and 'slim'."
invoke SharedViewsGenerator
def copy_views
template = options[:template_engine].to_s
case template
when "haml", "slim"
warn "#{template} templates have been removed from Devise gem"
else
directory "devise", "app/views/#{scope || :devise}"
end
end
hook_for :form_builder, :aliases => "-b",
:desc => "Form builder to be used",
:default => defined?(SimpleForm) ? "simple_form_for" : "form_for"
end
end
end

View File

@@ -2,8 +2,9 @@
# four configuration values can also be set straight in your models.
Devise.setup do |config|
# ==> Mailer Configuration
# Configure the e-mail address which will be shown in DeviseMailer.
config.mailer_sender = "please-change-me@config-initializers-devise.com"
# Configure the e-mail address which will be shown in Devise::Mailer,
# note that it will be overwritten if you use your own mailer class with default "from" parameter.
config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com"
# Configure the class responsible to send e-mails.
# config.mailer = "Devise::Mailer"
@@ -36,6 +37,11 @@ Devise.setup do |config|
# to authenticate or find a user. Default is :email.
config.case_insensitive_keys = [ :email ]
# Configure which authentication keys should have whitespace stripped.
# These keys will have whitespace before and after removed upon creating or
# modifying a user and when used to authenticate or find a user. Default is :email.
config.strip_whitespace_keys = [ :email ]
# Tell if authentication through request.params is enabled. True by default.
# config.params_authenticatable = true
@@ -48,21 +54,29 @@ Devise.setup do |config|
# The realm used in Http Basic Authentication. "Application" by default.
# config.http_authentication_realm = "Application"
# It will change confirmation, password recovery and other workflows
# to behave the same regardless if the e-mail provided was right or wrong.
# Does not affect registerable.
# config.paranoid = true
# ==> Configuration for :database_authenticatable
# For bcrypt, this is the cost for hashing the password and defaults to 10. If
# using other encryptors, it sets how many times you want the password re-encrypted.
config.stretches = 10
#
# Limiting the stretches to just one in testing will increase the performance of
# your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
# a value less than 10 in other environments.
config.stretches = Rails.env.test? ? 1 : 10
# Setup a pepper to generate the encrypted password.
# config.pepper = <%= ActiveSupport::SecureRandom.hex(64).inspect %>
# config.pepper = <%= SecureRandom.hex(64).inspect %>
# ==> Configuration for :confirmable
# The time you want to give your user to confirm his account. During this time
# he will be able to access your application without confirming. Default is 0.days
# When confirm_within is zero, the user won't be able to sign in without confirming.
# You can use this to let your user access some features of your application
# without confirming the account, but blocking it after a certain period
# (ie 2 days).
# A period that the user is allowed to access the website even without
# confirming his account. For instance, if set to 2.days, the user will be
# able to access the website for two days without confirming his account,
# access will be blocked just in the third day. Default is 0.days, meaning
# the user cannot access the website without confirming his account.
# config.confirm_within = 2.days
# Defines which key will be used when confirming an account
@@ -82,12 +96,18 @@ Devise.setup do |config|
# to false if you are not using database authenticatable.
config.use_salt_as_remember_token = true
# ==> Configuration for :validatable
# Range for password length. Default is 6..20.
# config.password_length = 6..20
# Options to be passed to the created cookie. For instance, you can set
# :secure => true in order to force SSL only cookies.
# config.cookie_options = {}
# Regex to use to validate the email address
# config.email_regexp = /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i
# ==> Configuration for :validatable
# Range for password length. Default is 6..128.
# config.password_length = 6..128
# Email regex used to validate email formats. It simply asserts that
# an one (and only one) @ exists in the given string. This is mainly
# to give user feedback and not to assert the e-mail validity.
# config.email_regexp = /\A[^@]+@[^@]+\z/
# ==> Configuration for :timeoutable
# The time you want to timeout the user session without activity. After this
@@ -122,6 +142,11 @@ Devise.setup do |config|
# Defines which key will be used when recovering the password for an account
# config.reset_password_keys = [ :email ]
# Time interval you can reset your password with a reset password key.
# Don't put a too small interval or your users won't have the time to
# change their passwords.
config.reset_password_within = 2.hours
# ==> Configuration for :encryptable
# Allow you to use another encryption algorithm besides bcrypt (default). You can use
# :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1,
@@ -165,8 +190,8 @@ Devise.setup do |config|
# Explorer requests.
# config.navigational_formats = [:"*/*", "*/*", :html]
# The default HTTP method used to sign out a resource. Default is :get.
# config.sign_out_via = :get
# The default HTTP method used to sign out a resource. Default is :delete.
config.sign_out_via = :delete
# ==> OmniAuth
# Add a new OmniAuth provider. Check the wiki for more information on setting

View File

@@ -0,0 +1,15 @@
<h2>Resend confirmation instructions</h2>
<%= simple_form_for(resource, :as => resource_name, :url => confirmation_path(resource_name), :html => { :method => :post }) do |f| %>
<%= f.error_notification %>
<div class="inputs">
<%= f.input :email, :required => true %>
</div>
<div class="actions">
<%= f.button :submit, "Resend confirmation instructions" %>
</div>
<% end %>
<%= render :partial => "devise/shared/links" %>

View File

@@ -0,0 +1,19 @@
<h2>Change your password</h2>
<%= simple_form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :put }) do |f| %>
<%= f.error_notification %>
<%= f.input :reset_password_token, :as => :hidden %>
<%= f.full_error :reset_password_token %>
<div class="inputs">
<%= f.input :password, :label => "New password", :required => true %>
<%= f.input :password_confirmation, :label => "Confirm your new password", :required => true %>
</div>
<div class="actions">
<%= f.button :submit, "Change my password" %>
</div>
<% end %>
<%= render :partial => "devise/shared/links" %>

View File

@@ -0,0 +1,15 @@
<h2>Forgot your password?</h2>
<%= simple_form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :post }) do |f| %>
<%= f.error_notification %>
<div class="inputs">
<%= f.input :email, :required => true %>
</div>
<div class="actions">
<%= f.button :submit, "Send me reset password instructions" %>
</div>
<% end %>
<%= render :partial => "devise/shared/links" %>

View File

@@ -0,0 +1,22 @@
<h2>Edit <%= resource_name.to_s.humanize %></h2>
<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %>
<%= f.error_notification %>
<div class="inputs">
<%= f.input :email, :required => true, :autofocus => true %>
<%= f.input :password, :hint => "leave it blank if you don't want to change it", :required => false %>
<%= f.input :password_confirmation, :required => false %>
<%= f.input :current_password, :hint => "we need your current password to confirm your changes", :required => true %>
</div>
<div class="actions">
<%= f.button :submit, "Update" %>
</div>
<% end %>
<h3>Cancel my account</h3>
<p>Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), :confirm => "Are you sure?", :method => :delete %>.</p>
<%= link_to "Back", :back %>

View File

@@ -0,0 +1,17 @@
<h2>Sign up</h2>
<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
<%= f.error_notification %>
<div class="inputs">
<%= f.input :email, :required => true, :autofocus => true %>
<%= f.input :password, :required => true %>
<%= f.input :password_confirmation, :required => true %>
</div>
<div class="actions">
<%= f.button :submit, "Sign up" %>
</div>
<% end %>
<%= render :partial => "devise/shared/links" %>

View File

@@ -0,0 +1,15 @@
<h2>Sign in</h2>
<%= simple_form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
<div class="inputs">
<%= f.input :email, :required => false, :autofocus => true %>
<%= f.input :password, :required => false %>
<%= f.input :remember_me, :as => :boolean if devise_mapping.rememberable? %>
</div>
<div class="actions">
<%= f.button :submit, "Sign in" %>
</div>
<% end %>
<%= render :partial => "devise/shared/links" %>

View File

@@ -0,0 +1,15 @@
<h2>Resend unlock instructions</h2>
<%= simple_form_for(resource, :as => resource_name, :url => unlock_path(resource_name), :html => { :method => :post }) do |f| %>
<%= f.error_notification %>
<div class="inputs">
<%= f.input :email, :required => true %>
</div>
<div class="actions">
<%= f.button :submit, "Resend unlock instructions" %>
</div>
<% end %>
<%= render :partial => "devise/shared/links" %>

View File

@@ -45,6 +45,11 @@ class ControllerAuthenticatableTest < ActionController::TestCase
@controller.authenticate_user!
end
test 'proxy authenticate_user! options to authenticate with user scope' do
@mock_warden.expects(:authenticate!).with(:scope => :user, :recall => "foo")
@controller.authenticate_user!(:recall => "foo")
end
test 'proxy authenticate_admin! to authenticate with admin scope' do
@mock_warden.expects(:authenticate!).with(:scope => :admin)
@controller.authenticate_admin!
@@ -106,7 +111,7 @@ class ControllerAuthenticatableTest < ActionController::TestCase
user = User.new
@mock_warden.expects(:user).returns(user)
@mock_warden.expects(:set_user).never
@controller.sign_in(user)
assert @controller.sign_in(user)
end
test 'sign in again when the user is already in only if force is given' do

View File

@@ -39,12 +39,27 @@ class HelpersTest < ActionController::TestCase
end
test 'require no authentication tests current mapping' do
@mock_warden.expects(:authenticated?).with(:user).returns(true)
@mock_warden.expects(:authenticate?).with(:rememberable, :token_authenticatable, :scope => :user).returns(true)
@mock_warden.expects(:user).with(:user).returns(User.new)
@controller.expects(:redirect_to).with(root_path)
@controller.send :require_no_authentication
end
test 'require no authentication skips if no inputs are available' do
Devise.mappings[:user].expects(:no_input_strategies).returns([])
@mock_warden.expects(:authenticate?).never
@controller.expects(:redirect_to).never
@controller.send :require_no_authentication
end
test 'require no authentication sets a flash message' do
@mock_warden.expects(:authenticate?).with(:rememberable, :token_authenticatable, :scope => :user).returns(true)
@mock_warden.expects(:user).with(:user).returns(User.new)
@controller.expects(:redirect_to).with(root_path)
@controller.send :require_no_authentication
assert flash[:alert] == I18n.t("devise.failure.already_authenticated")
end
test 'signed in resource returns signed in resource for current scope' do
@mock_warden.expects(:authenticate).with(:scope => :user).returns(User.new)
assert_kind_of User, @controller.signed_in_resource
@@ -69,4 +84,11 @@ class HelpersTest < ActionController::TestCase
assert flash[:notice] == 'non-blank'
MyController.send(:protected, :set_flash_message)
end
test 'navigational_formats not returning a wild card' do
MyController.send(:public, :navigational_formats)
Devise.navigational_formats = [:"*/*", :html]
assert_not @controller.navigational_formats.include?(:"*/*")
MyController.send(:protected, :navigational_formats)
end
end

View File

@@ -0,0 +1,16 @@
require 'test_helper'
class SessionsControllerTest < ActionController::TestCase
tests Devise::SessionsController
include Devise::TestHelpers
test "#create doesn't raise exception after Warden authentication fails when TestHelpers included" do
request.env["devise.mapping"] = Devise.mappings[:user]
post :create, :user => {
:email => "nosuchuser@example.com",
:password => "wevdude"
}
assert_equal 200, @response.status
assert_template "devise/sessions/new"
end
end

View File

@@ -58,9 +58,6 @@ class DeviseTest < ActiveSupport::TestCase
assert_equal :fruits, Devise::CONTROLLERS[:kivi]
Devise::ALL.delete(:kivi)
Devise::CONTROLLERS.delete(:kivi)
assert_nothing_raised(Exception) { Devise.add_module(:authenticatable_again, :model => 'devise/model/authenticatable') }
assert defined?(Devise::Models::AuthenticatableAgain)
end
test 'should complain when comparing empty or different sized passes' do

View File

@@ -2,6 +2,10 @@ require 'test_helper'
require 'ostruct'
class FailureTest < ActiveSupport::TestCase
class RootFailureApp < Devise::FailureApp
undef_method :new_user_session_path
end
def self.context(name, &block)
instance_eval(&block)
end
@@ -18,27 +22,31 @@ class FailureTest < ActiveSupport::TestCase
'warden' => OpenStruct.new(:message => nil)
}.merge!(env_params)
@response = Devise::FailureApp.call(env).to_a
@response = (env.delete(:app) || Devise::FailureApp).call(env).to_a
@request = ActionDispatch::Request.new(env)
end
context 'When redirecting' do
test 'return 302 status' do
call_failure
assert_equal 302, @response.first
end
test 'return 302 status for wildcard requests' do
call_failure 'action_dispatch.request.formats' => nil, 'HTTP_ACCEPT' => '*/*'
assert_equal 302, @response.first
end
test 'return to the default redirect location' do
call_failure
assert_equal 302, @response.first
assert_equal 'You need to sign in or sign up before continuing.', @request.flash[:alert]
assert_equal 'http://test.host/users/sign_in', @response.second['Location']
end
test 'return to the default redirect location for wildcard requests' do
call_failure 'action_dispatch.request.formats' => nil, 'HTTP_ACCEPT' => '*/*'
assert_equal 302, @response.first
assert_equal 'http://test.host/users/sign_in', @response.second['Location']
end
test 'return to the root path if no session path is available' do
call_failure :app => RootFailureApp
assert_equal 302, @response.first
assert_equal 'You need to sign in or sign up before continuing.', @request.flash[:alert]
assert_equal 'http://test.host/', @response.second['Location']
end
test 'uses the proxy failure message as symbol' do
call_failure('warden' => OpenStruct.new(:message => :test))
assert_equal 'test', @request.flash[:alert]
@@ -69,7 +77,7 @@ class FailureTest < ActiveSupport::TestCase
assert_equal 302, @response.first
end
end
test 'redirects the correct format if it is a non-html format request' do
swap Devise, :navigational_formats => [:js] do
call_failure('formats' => :js)
@@ -84,6 +92,18 @@ class FailureTest < ActiveSupport::TestCase
assert_equal 401, @response.first
end
test 'return appropriate body for xml' do
call_failure('formats' => :xml)
result = %(<?xml version="1.0" encoding="UTF-8"?>\n<errors>\n <error>You need to sign in or sign up before continuing.</error>\n</errors>\n)
assert_equal result, @response.last.body
end
test 'return appropriate body for json' do
call_failure('formats' => :json)
result = %({"error":"You need to sign in or sign up before continuing."})
assert_equal result, @response.last.body
end
test 'return 401 status for unknown formats' do
call_failure 'formats' => []
assert_equal 401, @response.first
@@ -161,7 +181,7 @@ class FailureTest < ActiveSupport::TestCase
assert @response.third.body.include?('<h2>Sign in</h2>')
assert @response.third.body.include?('Invalid email or password.')
end
test 'calls the original controller if not confirmed email' do
env = {
"warden.options" => { :recall => "devise/sessions#new", :attempted_path => "/users/sign_in", :message => :unconfirmed },
@@ -170,9 +190,9 @@ class FailureTest < ActiveSupport::TestCase
}
call_failure(env)
assert @response.third.body.include?('<h2>Sign in</h2>')
assert @response.third.body.include?('You have to confirm your account before continuing.')
assert @response.third.body.include?('You have to confirm your account before continuing.')
end
test 'calls the original controller if inactive account' do
env = {
"warden.options" => { :recall => "devise/sessions#new", :attempted_path => "/users/sign_in", :message => :inactive },
@@ -181,7 +201,7 @@ class FailureTest < ActiveSupport::TestCase
}
call_failure(env)
assert @response.third.body.include?('<h2>Sign in</h2>')
assert @response.third.body.include?('Your account was not activated yet.')
assert @response.third.body.include?('Your account was not activated yet.')
end
end
end

View File

@@ -13,9 +13,22 @@ if DEVISE_ORM == :active_record
assert_file "app/models/monster.rb", /devise/, /attr_accessible (:[a-z_]+(, )?)+/
assert_migration "db/migrate/devise_create_monsters.rb"
end
test "update model migration when model exists" do
run_generator %w(monster)
assert_file "app/models/monster.rb"
run_generator %w(monster)
assert_migration "db/migrate/add_devise_to_monsters.rb"
end
test "all files are properly deleted" do
run_generator %w(monster)
run_generator %w(monster)
assert_migration "db/migrate/devise_create_monsters.rb"
assert_migration "db/migrate/add_devise_to_monsters.rb"
run_generator %w(monster), :behavior => :revoke
assert_no_migration "db/migrate/add_devise_to_monsters.rb"
assert_migration "db/migrate/devise_create_monsters.rb"
run_generator %w(monster), :behavior => :revoke
assert_no_file "app/models/monster.rb"
assert_no_migration "db/migrate/devise_create_monsters.rb"

View File

@@ -22,6 +22,12 @@ class DeviseGeneratorTest < Rails::Generators::TestCase
assert_file "config/routes.rb", match
end
test "route generation with skip routes" do
run_generator %w(monster name:string --skip-routes)
match = /devise_for :monsters, :skip => :all/
assert_file "config/routes.rb", match
end
def copy_routes
routes = File.expand_path("../../rails_app/config/routes.rb", __FILE__)
destination = File.join(destination_root, "config")

View File

@@ -1,7 +1,7 @@
require "test_helper"
if DEVISE_ORM == :mongo_id
require "generators/mongo_id/devise_generator"
if DEVISE_ORM == :mongoid
require "generators/mongoid/devise_generator"
class MongoidGeneratorTest < Rails::Generators::TestCase
tests Mongoid::Generators::DeviseGenerator
@@ -19,4 +19,5 @@ if DEVISE_ORM == :mongo_id
assert_no_file "app/models/monster.rb"
end
end
end
end

View File

@@ -18,6 +18,16 @@ class ViewsGeneratorTest < Rails::Generators::TestCase
assert_files "admins"
end
test "Assert views with simple form" do
run_generator %w(-b simple_form_for)
assert_files
assert_file "app/views/devise/confirmations/new.html.erb", /simple_form_for/
run_generator %w(users -b simple_form_for)
assert_files "users"
assert_file "app/views/users/confirmations/new.html.erb", /simple_form_for/
end
def assert_files(scope = nil, template_engine = nil)
scope = "devise" if scope.nil?
assert_file "app/views/#{scope}/confirmations/new.html.erb"

View File

@@ -0,0 +1,51 @@
require 'test_helper'
class DeviseHelperTest < ActionController::IntegrationTest
setup do
model_labels = { :models => { :user => "utilisateur" } }
I18n.backend.store_translations :fr,
{
:errors => { :messages => { :not_saved => {
:one => "Erreur lors de l'enregistrement de '%{resource}': 1 erreur.",
:other => "Erreur lors de l'enregistrement de '%{resource}': %{count} erreurs."
} } },
:activerecord => model_labels,
:mongoid => model_labels
}
I18n.locale = 'fr'
end
teardown do
I18n.locale = 'en'
end
test 'test errors.messages.not_saved with single error from i18n' do
get new_user_registration_path
fill_in 'password', :with => 'new_user123'
fill_in 'password confirmation', :with => 'new_user123'
click_button 'Sign up'
assert_have_selector '#error_explanation'
assert_contain "Erreur lors de l'enregistrement de 'utilisateur': 1 erreur"
end
test 'test errors.messages.not_saved with multiple errors from i18n' do
# Dirty tracking behavior prevents email validations from being applied:
# https://github.com/mongoid/mongoid/issues/756
(pending "Fails on Mongoid < 2.1"; break) if defined?(Mongoid) && Mongoid::VERSION.to_f < 2.1
get new_user_registration_path
fill_in 'email', :with => 'invalid_email'
fill_in 'password', :with => 'new_user123'
fill_in 'password confirmation', :with => 'new_user321'
click_button 'Sign up'
assert_have_selector '#error_explanation'
assert_contain "Erreur lors de l'enregistrement de 'utilisateur': 2 erreurs"
end
end

View File

@@ -101,6 +101,54 @@ class AuthenticationSanityTest < ActionController::IntegrationTest
assert_contain 'Private!'
end
test 'signed in as admin should get admin dashboard' do
sign_in_as_admin
assert warden.authenticated?(:admin)
assert_not warden.authenticated?(:user)
get dashboard_path
assert_response :success
assert_template 'home/admin'
assert_contain 'Admin dashboard'
end
test 'signed in as user should get user dashboard' do
sign_in_as_user
assert warden.authenticated?(:user)
assert_not warden.authenticated?(:admin)
get dashboard_path
assert_response :success
assert_template 'home/user'
assert_contain 'User dashboard'
end
test 'not signed in should get no dashboard' do
assert_raises ActionController::RoutingError do
get dashboard_path
end
end
test 'signed in user should not see join page' do
sign_in_as_user
assert warden.authenticated?(:user)
assert_not warden.authenticated?(:admin)
assert_raises ActionController::RoutingError do
get join_path
end
end
test 'not signed in should see join page' do
get join_path
assert_response :success
assert_template 'home/join'
assert_contain 'Join'
end
test 'signed in as user should not be able to access admins actions' do
sign_in_as_user
assert warden.authenticated?(:user)
@@ -205,17 +253,16 @@ class AuthenticationRedirectTest < ActionController::IntegrationTest
assert_nil session[:"user_return_to"]
end
test 'sign in with xml format returns xml response' do
create_user
post user_session_path(:format => 'xml', :user => {:email => "user@test.com", :password => '123456'})
assert_response :success
assert_match /<\?xml version="1.0" encoding="UTF-8"\?>/, response.body
end
test 'redirect to configured home path for a given scope after sign in' do
sign_in_as_admin
assert_equal "/admin_area/home", @request.path
end
test 'require_no_authentication should set the already_authenticated flash message' do
sign_in_as_user
visit new_user_session_path
assert_equal flash[:alert], I18n.t("devise.failure.already_authenticated")
end
end
class AuthenticationSessionTest < ActionController::IntegrationTest
@@ -307,6 +354,20 @@ class AuthenticationWithScopesTest < ActionController::IntegrationTest
end
class AuthenticationOthersTest < ActionController::IntegrationTest
test 'handles unverified requests gets rid of caches' do
swap UsersController, :allow_forgery_protection => true do
post exhibit_user_url(1)
assert_not warden.authenticated?(:user)
sign_in_as_user
assert warden.authenticated?(:user)
post exhibit_user_url(1)
assert_not warden.authenticated?(:user)
assert_equal "User is not authenticated", response.body
end
end
test 'uses the custom controller with the custom controller view' do
get '/admin_area/sign_in'
assert_contain 'Sign in'
@@ -315,8 +376,9 @@ class AuthenticationOthersTest < ActionController::IntegrationTest
end
test 'render 404 on roles without routes' do
get '/admin_area/password/new'
assert_equal 404, response.status
assert_raise ActionController::RoutingError do
get '/admin_area/password/new'
end
end
test 'does not intercept Rails 401 responses' do
@@ -337,9 +399,24 @@ class AuthenticationOthersTest < ActionController::IntegrationTest
end
end
test 'registration in xml format works when recognizing path' do
assert_nothing_raised do
post user_registration_path(:format => 'xml', :user => {:email => "test@example.com", :password => "invalid"} )
test 'sign in stub in xml format' do
get new_user_session_path(:format => 'xml')
assert_equal "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>\n <email></email>\n <password nil=\"true\"></password>\n</user>\n", response.body
end
test 'sign in stub in json format' do
get new_user_session_path(:format => 'json')
assert_match '{"user":{', response.body
assert_match '"email":""', response.body
assert_match '"password":null', response.body
end
test 'sign in stub in json with non attribute key' do
swap Devise, :authentication_keys => [:other_key] do
get new_user_session_path(:format => 'json')
assert_match '{"user":{', response.body
assert_match '"other_key":null', response.body
assert_match '"password":null', response.body
end
end
@@ -354,6 +431,44 @@ class AuthenticationOthersTest < ActionController::IntegrationTest
assert warden.authenticated?(:user)
assert_not warden.authenticated?(:admin)
end
test 'sign in with xml format returns xml response' do
create_user
post user_session_path(:format => 'xml'), :user => {:email => "user@test.com", :password => '123456'}
assert_response :success
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
end
test 'sign out with xml format returns ok response' do
sign_in_as_user
get destroy_user_session_path(:format => 'xml')
assert_response :ok
assert_not warden.authenticated?(:user)
end
test 'sign out with json format returns empty json response' do
sign_in_as_user
get destroy_user_session_path(:format => 'json')
assert_response :ok
assert_not warden.authenticated?(:user)
end
end
class AuthenticationKeysTest < ActionController::IntegrationTest
test 'missing authentication keys cause authentication to abort' do
swap Devise, :authentication_keys => [:subdomain] do
sign_in_as_user
assert_contain "Invalid email or password."
assert_not warden.authenticated?(:user)
end
end
test 'missing authentication keys cause authentication to abort unless marked as not required' do
swap Devise, :authentication_keys => { :email => true, :subdomain => false } do
sign_in_as_user
assert warden.authenticated?(:user)
end
end
end
class AuthenticationRequestKeysTest < ActionController::IntegrationTest
@@ -411,7 +526,9 @@ class AuthenticationSignOutViaTest < ActionController::IntegrationTest
test 'do not allow sign out via get when sign_out_via provides only delete' do
sign_in!(:sign_out_via_delete)
get destroy_sign_out_via_delete_session_path
assert_raise ActionController::RoutingError do
get destroy_sign_out_via_delete_session_path
end
assert warden.authenticated?(:sign_out_via_delete)
end
@@ -423,7 +540,9 @@ class AuthenticationSignOutViaTest < ActionController::IntegrationTest
test 'do not allow sign out via get when sign_out_via provides only post' do
sign_in!(:sign_out_via_post)
get destroy_sign_out_via_delete_session_path
assert_raise ActionController::RoutingError do
get destroy_sign_out_via_delete_session_path
end
assert warden.authenticated?(:sign_out_via_post)
end
@@ -441,7 +560,9 @@ class AuthenticationSignOutViaTest < ActionController::IntegrationTest
test 'do not allow sign out via get when sign_out_via provides delete and post' do
sign_in!(:sign_out_via_delete_or_post)
get destroy_sign_out_via_delete_or_post_session_path
assert_raise ActionController::RoutingError do
get destroy_sign_out_via_delete_or_post_session_path
end
assert warden.authenticated?(:sign_out_via_delete_or_post)
end
end

View File

@@ -37,6 +37,15 @@ class ConfirmationTest < ActionController::IntegrationTest
assert user.reload.confirmed?
end
test 'user should be redirected to a custom path after confirmation' do
Devise::ConfirmationsController.any_instance.stubs(:after_confirmation_path_for).returns("/?custom=1")
user = create_user(:confirm => false)
visit_user_confirmation_with_token(user.confirmation_token)
assert_current_url "/?custom=1"
end
test 'already confirmed user should not be able to confirm the account again' do
user = create_user(:confirm => false)
user.confirmed_at = Time.now
@@ -60,7 +69,7 @@ class ConfirmationTest < ActionController::IntegrationTest
assert_contain 'already confirmed'
end
test 'sign in user automatically after confirming it\'s email' do
test 'sign in user automatically after confirming its email' do
user = create_user(:confirm => false)
visit_user_confirmation_with_token(user.confirmation_token)
@@ -101,4 +110,70 @@ class ConfirmationTest < ActionController::IntegrationTest
assert_contain 'Not confirmed user'
end
end
test 'resent confirmation token with valid E-Mail in XML format should return valid response' do
user = create_user(:confirm => false)
post user_confirmation_path(:format => 'xml'), :user => { :email => user.email }
assert_response :success
assert_equal response.body, {}.to_xml
end
test 'resent confirmation token with invalid E-Mail in XML format should return invalid response' do
user = create_user(:confirm => false)
post user_confirmation_path(:format => 'xml'), :user => { :email => 'invalid.test@test.com' }
assert_response :unprocessable_entity
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
end
test 'confirm account with valid confirmation token in XML format should return valid response' do
user = create_user(:confirm => false)
get user_confirmation_path(:confirmation_token => user.confirmation_token, :format => 'xml')
assert_response :success
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
end
test 'confirm account with invalid confirmation token in XML format should return invalid response' do
user = create_user(:confirm => false)
get user_confirmation_path(:confirmation_token => 'invalid_confirmation', :format => 'xml')
assert_response :unprocessable_entity
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
end
test 'request an account confirmation account with JSON, should return an empty JSON' do
user = create_user(:confirm => false)
post user_confirmation_path, :user => { :email => user.email }, :format => :json
assert_response :success
assert_equal response.body, {}.to_json
end
test "when in paranoid mode and with a valid e-mail, should not say that the e-mail is valid" do
swap Devise, :paranoid => true do
user = create_user(:confirm => false)
visit new_user_session_path
click_link "Didn't receive confirmation instructions?"
fill_in 'email', :with => user.email
click_button 'Resend confirmation instructions'
assert_contain "If your e-mail exists on our database, you will receive an email with instructions about how to confirm your account in a few minutes."
assert_current_url "/users/confirmation"
end
end
test "when in paranoid mode and with a invalid e-mail, should not say that the e-mail is invalid" do
swap Devise, :paranoid => true do
visit new_user_session_path
click_link "Didn't receive confirmation instructions?"
fill_in 'email', :with => "idonthavethisemail@gmail.com"
click_button 'Resend confirmation instructions'
assert_not_contain "1 error prohibited this user from being saved:"
assert_not_contain "Email not found"
assert_contain "If your e-mail exists on our database, you will receive an email with instructions about how to confirm your account in a few minutes."
assert_current_url "/users/confirmation"
end
end
end

View File

@@ -22,6 +22,28 @@ class DatabaseAuthenticationTest < ActionController::IntegrationTest
assert_not warden.authenticated?(:user)
end
end
test 'sign in with email including extra spaces should succeed when email is in the list of strip whitespace keys' do
create_user(:email => ' foo@bar.com ')
sign_in_as_user do
fill_in 'email', :with => 'foo@bar.com'
end
assert warden.authenticated?(:user)
end
test 'sign in with email including extra spaces should fail when email is NOT the list of strip whitespace keys' do
swap Devise, :strip_whitespace_keys => [] do
create_user(:email => 'foo@bar.com')
sign_in_as_user do
fill_in 'email', :with => ' foo@bar.com '
end
assert_not warden.authenticated?(:user)
end
end
test 'sign in should not authenticate if not using proper authentication keys' do
swap Devise, :authentication_keys => [:username] do

View File

@@ -1,6 +1,14 @@
require 'test_helper'
class HttpAuthenticationTest < ActionController::IntegrationTest
test 'handles unverified requests gets rid of caches but continues signed in' do
swap UsersController, :allow_forgery_protection => true do
create_user
post exhibit_user_url(1), {}, "HTTP_AUTHORIZATION" => "Basic #{ActiveSupport::Base64.encode64("user@test.com:123456")}"
assert warden.authenticated?(:user)
assert_equal "User is authenticated", response.body
end
end
test 'sign in should authenticate with http' do
sign_in_as_new_user_with_http

View File

@@ -1,7 +1,7 @@
require 'test_helper'
class LockTest < ActionController::IntegrationTest
def visit_user_unlock_with_token(unlock_token)
visit user_unlock_path(:unlock_token => unlock_token)
end
@@ -37,7 +37,7 @@ class LockTest < ActionController::IntegrationTest
end
test 'unlocked pages should not be available if email strategy is disabled' do
visit "/admins/sign_in"
visit "/admin_area/sign_in"
assert_raise Webrat::NotFoundError do
click_link "Didn't receive unlock instructions?"
@@ -47,8 +47,9 @@ class LockTest < ActionController::IntegrationTest
visit new_admin_unlock_path
end
visit "/admins/unlock/new"
assert_response :not_found
assert_raise ActionController::RoutingError do
visit "/admin_area/unlock/new"
end
end
test 'user with invalid unlock token should not be able to unlock an account' do
@@ -72,7 +73,7 @@ class LockTest < ActionController::IntegrationTest
assert_not user.reload.access_locked?
end
test "sign in user automatically after unlocking it's account" do
test "sign in user automatically after unlocking its account" do
user = create_user(:locked => true)
visit_user_unlock_with_token(user.unlock_token)
assert warden.authenticated?(:user)
@@ -106,4 +107,95 @@ class LockTest < ActionController::IntegrationTest
end
end
test 'user should be able to request a new unlock token via XML request' do
user = create_user(:locked => true)
ActionMailer::Base.deliveries.clear
post user_unlock_path(:format => 'xml'), :user => {:email => user.email}
assert_response :success
assert_equal response.body, {}.to_xml
assert_equal 1, ActionMailer::Base.deliveries.size
end
test 'unlocked user should not be able to request a unlock token via XML request' do
user = create_user(:locked => false)
ActionMailer::Base.deliveries.clear
post user_unlock_path(:format => 'xml'), :user => {:email => user.email}
assert_response :unprocessable_entity
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
assert_equal 0, ActionMailer::Base.deliveries.size
end
test 'user with valid unlock token should be able to unlock account via XML request' do
user = create_user(:locked => true)
assert user.access_locked?
get user_unlock_path(:format => 'xml', :unlock_token => user.unlock_token)
assert_response :success
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
end
test 'user with invalid unlock token should not be able to unlock the account via XML request' do
get user_unlock_path(:format => 'xml', :unlock_token => 'invalid_token')
assert_response :unprocessable_entity
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
end
test "when using json to ask a unlock request, should not return the user" do
user = create_user(:locked => true)
post user_unlock_path(:format => "json", :user => {:email => user.email})
assert_response :success
assert_equal response.body, {}.to_json
end
test "in paranoid mode, when trying to unlock an user that exists it should not say that it exists if it is locked" do
swap Devise, :paranoid => true do
user = create_user(:locked => true)
visit new_user_session_path
click_link "Didn't receive unlock instructions?"
fill_in 'email', :with => user.email
click_button 'Resend unlock instructions'
assert_current_url "/users/unlock"
assert_contain "If your account exists, you will receive an email with instructions about how to unlock it in a few minutes."
end
end
test "in paranoid mode, when trying to unlock an user that exists it should not say that it exists if it is not locked" do
swap Devise, :paranoid => true do
user = create_user(:locked => false)
visit new_user_session_path
click_link "Didn't receive unlock instructions?"
fill_in 'email', :with => user.email
click_button 'Resend unlock instructions'
assert_current_url "/users/unlock"
assert_contain "If your account exists, you will receive an email with instructions about how to unlock it in a few minutes."
end
end
test "in paranoid mode, when trying to unlock an user that does not exists it should not say that it does not exists" do
swap Devise, :paranoid => true do
visit new_user_session_path
click_link "Didn't receive unlock instructions?"
fill_in 'email', :with => "arandomemail@hotmail.com"
click_button 'Resend unlock instructions'
assert_not_contain "1 error prohibited this user from being saved:"
assert_not_contain "Email not found"
assert_current_url "/users/unlock"
assert_contain "If your account exists, you will receive an email with instructions about how to unlock it in a few minutes."
end
end
end

View File

@@ -114,9 +114,7 @@ class OmniauthableIntegrationTest < ActionController::IntegrationTest
test "generates a proper link when SCRIPT_NAME is set" do
header 'SCRIPT_NAME', '/q'
visit "/users/sign_in"
click_link "Sign in with Facebook"
assert_equal '/q/users/auth/facebook', current_url
assert_select "a", :href => "/q/users/auth/facebook"
end
test "handles callback error parameter according to the specification" do

View File

@@ -17,7 +17,7 @@ class PasswordTest < ActionController::IntegrationTest
click_button 'Send me reset password instructions'
end
def reset_password(options={}, &block)
def reset_password(options={}, &block)
visit edit_user_password_path(:reset_password_token => options[:reset_password_token]) unless options[:visit] == false
assert_response :success
@@ -29,11 +29,11 @@ class PasswordTest < ActionController::IntegrationTest
test 'reset password with email of different case should succeed when email is in the list of case insensitive keys' do
create_user(:email => 'Foo@Bar.com')
request_forgot_password do
fill_in 'email', :with => 'foo@bar.com'
end
assert_current_url '/users/sign_in'
assert_contain 'You will receive an email with instructions about how to reset your password in a few minutes.'
end
@@ -41,11 +41,11 @@ class PasswordTest < ActionController::IntegrationTest
test 'reset password with email of different case should fail when email is NOT the list of case insensitive keys' do
swap Devise, :case_insensitive_keys => [] do
create_user(:email => 'Foo@Bar.com')
request_forgot_password do
fill_in 'email', :with => 'foo@bar.com'
end
assert_response :success
assert_current_url '/users/password'
assert_have_selector "input[type=email][value='foo@bar.com']"
@@ -53,6 +53,32 @@ class PasswordTest < ActionController::IntegrationTest
end
end
test 'reset password with email with extra whitespace should succeed when email is in the list of strip whitespace keys' do
create_user(:email => 'foo@bar.com')
request_forgot_password do
fill_in 'email', :with => ' foo@bar.com '
end
assert_current_url '/users/sign_in'
assert_contain 'You will receive an email with instructions about how to reset your password in a few minutes.'
end
test 'reset password with email with extra whitespace should fail when email is NOT the list of strip whitespace keys' do
swap Devise, :strip_whitespace_keys => [] do
create_user(:email => 'foo@bar.com')
request_forgot_password do
fill_in 'email', :with => ' foo@bar.com '
end
assert_response :success
assert_current_url '/users/password'
assert_have_selector "input[type=email][value=' foo@bar.com ']"
assert_contain 'not found'
end
end
test 'authenticated user should not be able to visit forgot password page' do
sign_in_as_user
assert warden.authenticated?(:user)
@@ -121,7 +147,7 @@ class PasswordTest < ActionController::IntegrationTest
reset_password :reset_password_token => user.reload.reset_password_token
assert_current_url '/'
assert_contain 'Your password was changed successfully.'
assert_contain 'Your password was changed successfully. You are now signed in.'
assert user.reload.valid_password?('987654321')
end
@@ -140,7 +166,7 @@ class PasswordTest < ActionController::IntegrationTest
assert user.reload.valid_password?('987654321')
end
test 'sign in user automatically after changing it\'s password' do
test 'sign in user automatically after changing its password' do
user = create_user
request_forgot_password
reset_password :reset_password_token => user.reload.reset_password_token
@@ -148,13 +174,95 @@ class PasswordTest < ActionController::IntegrationTest
assert warden.authenticated?(:user)
end
test 'does not sign in user automatically after changing it\'s password if it\'s not active' do
user = create_user(:confirm => false)
test 'does not sign in user automatically after changing its password if it\'s locked' do
user = create_user(:locked => true)
request_forgot_password
reset_password :reset_password_token => user.reload.reset_password_token
assert_contain 'Your password was changed successfully.'
assert_not_contain 'You are now signed in.'
assert_equal new_user_session_path, @request.path
assert !warden.authenticated?(:user)
end
test 'sign in user automatically and confirm after changing its password if it\'s not confirmed' do
user = create_user(:confirm => false)
request_forgot_password
reset_password :reset_password_token => user.reload.reset_password_token
assert warden.authenticated?(:user)
assert user.reload.confirmed?
end
test 'reset password request with valid E-Mail in XML format should return valid response' do
create_user
post user_password_path(:format => 'xml'), :user => {:email => "user@test.com"}
assert_response :success
assert_equal response.body, { }.to_xml
end
test 'reset password request with invalid E-Mail in XML format should return valid response' do
create_user
post user_password_path(:format => 'xml'), :user => {:email => "invalid.test@test.com"}
assert_response :unprocessable_entity
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
end
test 'change password with valid parameters in XML format should return valid response' do
user = create_user
request_forgot_password
put user_password_path(:format => 'xml'), :user => {:reset_password_token => user.reload.reset_password_token, :password => '987654321', :password_confirmation => '987654321'}
assert_response :success
assert warden.authenticated?(:user)
end
test 'change password with invalid token in XML format should return invalid response' do
user = create_user
request_forgot_password
put user_password_path(:format => 'xml'), :user => {:reset_password_token => 'invalid.token', :password => '987654321', :password_confirmation => '987654321'}
assert_response :unprocessable_entity
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
end
test 'change password with invalid new password in XML format should return invalid response' do
user = create_user
request_forgot_password
put user_password_path(:format => 'xml'), :user => {:reset_password_token => user.reload.reset_password_token, :password => '', :password_confirmation => '987654321'}
assert_response :unprocessable_entity
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
end
test "when using json requests to ask a confirmable request, should not return the object" do
user = create_user(:confirm => false)
post user_password_path(:format => :json), :user => { :email => user.email }
assert_response :success
assert_equal response.body, "{}"
end
test "when in paranoid mode and with an invalid e-mail, asking to reset a password should display a message that does not indicates that the e-mail does not exists in the database" do
swap Devise, :paranoid => true do
visit_new_password_path
fill_in "email", :with => "arandomemail@test.com"
click_button 'Send me reset password instructions'
assert_not_contain "1 error prohibited this user from being saved:"
assert_not_contain "Email not found"
assert_contain "If your e-mail exists on our database, you will receive a password recovery link on your e-mail"
assert_current_url "/users/password"
end
end
test "when in paranoid mode and with a valid e-mail, asking to reset password should display a message that does not indicates that the email exists in the database and redirect to the failure route" do
swap Devise, :paranoid => true do
user = create_user
visit_new_password_path
fill_in 'email', :with => user.email
click_button 'Send me reset password instructions'
assert_contain "If your e-mail exists on our database, you will receive a password recovery link on your e-mail"
assert_current_url "/users/password"
end
end
end

View File

@@ -69,6 +69,10 @@ class RegistrationTest < ActionController::IntegrationTest
end
test 'a guest user cannot sign up with invalid information' do
# Dirty tracking behavior prevents email validations from being applied:
# https://github.com/mongoid/mongoid/issues/756
(pending "Fails on Mongoid < 2.1"; break) if defined?(Mongoid) && Mongoid::VERSION.to_f < 2.1
get new_user_registration_path
fill_in 'email', :with => 'invalid_email'
@@ -87,6 +91,10 @@ class RegistrationTest < ActionController::IntegrationTest
end
test 'a guest should not sign up with email/password that already exists' do
# Dirty tracking behavior prevents email validations from being applied:
# https://github.com/mongoid/mongoid/issues/756
(pending "Fails on Mongoid < 2.1"; break) if defined?(Mongoid) && Mongoid::VERSION.to_f < 2.1
user = create_user
get new_user_registration_path
@@ -118,14 +126,14 @@ class RegistrationTest < ActionController::IntegrationTest
sign_in_as_user
get edit_user_registration_path
fill_in 'email', :with => 'user.new@email.com'
fill_in 'email', :with => 'user.new@example.com'
fill_in 'current password', :with => '123456'
click_button 'Update'
assert_current_url '/'
assert_contain 'You updated your account successfully.'
assert_equal "user.new@email.com", User.first.email
assert_equal "user.new@example.com", User.first.email
end
test 'a signed in user should still be able to use the website after changing his password' do
@@ -146,13 +154,13 @@ class RegistrationTest < ActionController::IntegrationTest
sign_in_as_user
get edit_user_registration_path
fill_in 'email', :with => 'user.new@email.com'
fill_in 'email', :with => 'user.new@example.com'
fill_in 'current password', :with => 'invalid'
click_button 'Update'
assert_template 'registrations/edit'
assert_contain 'user@test.com'
assert_have_selector 'form input[value="user.new@email.com"]'
assert_have_selector 'form input[value="user.new@example.com"]'
assert_equal "user@test.com", User.first.email
end
@@ -206,4 +214,63 @@ class RegistrationTest < ActionController::IntegrationTest
assert_nil @request.session["devise.foo_bar"]
assert_redirected_to new_user_registration_path
end
test 'a user with XML sign up stub' do
get new_user_registration_path(:format => 'xml')
assert_response :success
assert_match %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>), response.body
assert_no_match(/<confirmation-token/, response.body)
end
test 'a user with JSON sign up stub' do
get new_user_registration_path(:format => 'json')
assert_response :success
assert_match %({"user":), response.body
assert_no_match(/"confirmation_token"/, response.body)
end
test 'an admin sign up with valid information in XML format should return valid response' do
post admin_registration_path(:format => 'xml'), :admin => { :email => 'new_user@test.com', :password => 'new_user123', :password_confirmation => 'new_user123' }
assert_response :success
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<admin>)
admin = Admin.last :order => "id"
assert_equal admin.email, 'new_user@test.com'
end
test 'a user sign up with valid information in XML format should return valid response' do
post user_registration_path(:format => 'xml'), :user => { :email => 'new_user@test.com', :password => 'new_user123', :password_confirmation => 'new_user123' }
assert_response :success
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
user = User.last :order => "id"
assert_equal user.email, 'new_user@test.com'
end
test 'a user sign up with invalid information in XML format should return invalid response' do
post user_registration_path(:format => 'xml'), :user => { :email => 'new_user@test.com', :password => 'new_user123', :password_confirmation => 'invalid' }
assert_response :unprocessable_entity
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
end
test 'a user update information with valid data in XML format should return valid response' do
user = sign_in_as_user
put user_registration_path(:format => 'xml'), :user => { :current_password => '123456', :email => 'user.new@test.com' }
assert_response :success
assert_equal user.reload.email, 'user.new@test.com'
end
test 'a user update information with invalid data in XML format should return invalid response' do
user = sign_in_as_user
put user_registration_path(:format => 'xml'), :user => { :current_password => 'invalid', :email => 'user.new@test.com' }
assert_response :unprocessable_entity
assert_equal user.reload.email, 'user@test.com'
end
test 'a user cancel his account in XML format should return valid response' do
user = sign_in_as_user
delete user_registration_path(:format => 'xml')
assert_response :success
assert_equal User.count, 0
end
end

View File

@@ -38,6 +38,18 @@ class RememberMeTest < ActionController::IntegrationTest
assert_nil request.cookies["remember_user_cookie"]
end
test 'handles unverified requests gets rid of caches' do
swap UsersController, :allow_forgery_protection => true do
post exhibit_user_url(1)
assert_not warden.authenticated?(:user)
create_user_and_remember
post exhibit_user_url(1)
assert_equal "User is not authenticated", response.body
assert_not warden.authenticated?(:user)
end
end
test 'generate remember token after sign in' do
user = sign_in_as_user :remember_me => true
assert request.cookies["remember_user_token"]
@@ -69,7 +81,14 @@ class RememberMeTest < ActionController::IntegrationTest
assert_response :success
assert warden.authenticated?(:user)
assert warden.user(:user) == user
assert_match /remember_user_token[^\n]*HttpOnly\n/, response.headers["Set-Cookie"], "Expected Set-Cookie header in response to set HttpOnly flag on remember_user_token cookie."
assert_match /remember_user_token[^\n]*HttpOnly/, response.headers["Set-Cookie"], "Expected Set-Cookie header in response to set HttpOnly flag on remember_user_token cookie."
end
test 'remember the user before sign up and redirect him to his home' do
user = create_user_and_remember
get new_user_registration_path
assert warden.authenticated?(:user)
assert_redirected_to root_path
end
test 'cookies are destroyed on unverified requests' do

View File

@@ -13,6 +13,17 @@ class TokenAuthenticationTest < ActionController::IntegrationTest
end
end
test 'authenticate with valid authentication token key and value through params, when params with the same key as scope exist' do
swap Devise, :token_authentication_key => :secret_token do
user = create_user_with_authentication_token
post exhibit_user_path(user), Devise.token_authentication_key => user.authentication_token, :user => { :some => "data" }
assert_response :success
assert_contain 'User is authenticated'
assert warden.authenticated?(:user)
end
end
test 'authenticate with valid authentication token key but does not store if stateless' do
swap Devise, :token_authentication_key => :secret_token, :stateless_token => true do
sign_in_as_new_user_with_token

View File

@@ -61,4 +61,21 @@ class TrackableHooksTest < ActionController::IntegrationTest
assert_nil user.last_sign_in_at
end
end
test "do not track if devise.skip_trackable is set" do
user = create_user
sign_in_as_user do
header 'devise.skip_trackable', '1'
end
user.reload
assert_equal 0, user.sign_in_count
visit destroy_user_session_path
sign_in_as_user do
header 'devise.skip_trackable', false
end
user.reload
assert_equal 1, user.sign_in_count
end
end

View File

@@ -4,6 +4,7 @@ class ConfirmationInstructionsTest < ActionMailer::TestCase
def setup
setup_mailer
Devise.mailer = 'Devise::Mailer'
Devise.mailer_sender = 'test@example.com'
end
@@ -35,6 +36,11 @@ class ConfirmationInstructionsTest < ActionMailer::TestCase
assert_equal ['test@example.com'], mail.from
end
test 'setup sender from custom mailer defaults' do
Devise.mailer = 'Users::Mailer'
assert_equal ['custom@example.com'], mail.from
end
test 'setup reply to as copy from sender' do
assert_equal ['test@example.com'], mail.reply_to
end

View File

@@ -4,6 +4,7 @@ class ResetPasswordInstructionsTest < ActionMailer::TestCase
def setup
setup_mailer
Devise.mailer = 'Devise::Mailer'
Devise.mailer_sender = 'test@example.com'
end
@@ -38,6 +39,11 @@ class ResetPasswordInstructionsTest < ActionMailer::TestCase
assert_equal ['test@example.com'], mail.from
end
test 'setup sender from custom mailer defaults' do
Devise.mailer = 'Users::Mailer'
assert_equal ['custom@example.com'], mail.from
end
test 'setup reply to as copy from sender' do
assert_equal ['test@example.com'], mail.reply_to
end

View File

@@ -4,6 +4,7 @@ class UnlockInstructionsTest < ActionMailer::TestCase
def setup
setup_mailer
Devise.mailer = 'Devise::Mailer'
Devise.mailer_sender = 'test@example.com'
end
@@ -38,6 +39,11 @@ class UnlockInstructionsTest < ActionMailer::TestCase
assert_equal ['test@example.com'], mail.from
end
test 'setup sender from custom mailer defaults' do
Devise.mailer = 'Users::Mailer'
assert_equal ['custom@example.com'], mail.from
end
test 'setup reply to as copy from sender' do
assert_equal ['test@example.com'], mail.reply_to
end

View File

@@ -31,6 +31,10 @@ class MappingTest < ActiveSupport::TestCase
assert_equal "admin_area", Devise.mappings[:admin].path
end
test 'allows to skip all routes' do
assert_equal [], Devise.mappings[:skip_admin].used_routes
end
test 'sign_out_via defaults to :get' do
assert_equal :get, Devise.mappings[:user].sign_out_via
end
@@ -50,6 +54,11 @@ class MappingTest < ActiveSupport::TestCase
assert_equal [:rememberable, :database_authenticatable], Devise.mappings[:admin].strategies
end
test 'has no input strategies depending on the model declaration' do
assert_equal [:rememberable, :token_authenticatable], Devise.mappings[:user].no_input_strategies
assert_equal [:rememberable], Devise.mappings[:admin].no_input_strategies
end
test 'find scope for a given object' do
assert_equal :user, Devise::Mapping.find_scope!(User)
assert_equal :user, Devise::Mapping.find_scope!(:user)

View File

@@ -111,17 +111,17 @@ class ConfirmableTest < ActiveSupport::TestCase
end
test 'should return a new user if no email was found' do
confirmation_user = User.send_confirmation_instructions(:email => "invalid@email.com")
confirmation_user = User.send_confirmation_instructions(:email => "invalid@example.com")
assert_not confirmation_user.persisted?
end
test 'should add error to new user email if no email was found' do
confirmation_user = User.send_confirmation_instructions(:email => "invalid@email.com")
confirmation_user = User.send_confirmation_instructions(:email => "invalid@example.com")
assert confirmation_user.errors[:email]
assert_equal "not found", confirmation_user.errors[:email].join
end
test 'should send email instructions for the user confirm it\'s email' do
test 'should send email instructions for the user confirm its email' do
user = create_user
assert_email_sent do
User.send_confirmation_instructions(:email => user.email)
@@ -219,7 +219,7 @@ class ConfirmableTest < ActiveSupport::TestCase
assert user.reload.active_for_authentication?
end
test 'should find a user to send email instructions for the user confirm it\'s email by authentication_keys' do
test 'should find a user to send email instructions for the user confirm its email by authentication_keys' do
swap Devise, :authentication_keys => [:username, :email] do
user = create_user
confirm_user = User.send_confirmation_instructions(:email => user.email, :username => user.username)

View File

@@ -6,12 +6,45 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
# case_insensitive_keys is set to :email by default.
email = 'Foo@Bar.com'
user = new_user(:email => email)
assert_equal email, user.email
user.save!
assert_equal email.downcase, user.email
end
test 'should remove whitespace from strip whitespace keys when saving' do
# strip_whitespace_keys is set to :email by default.
email = ' foo@bar.com '
user = new_user(:email => email)
assert_equal email, user.email
user.save!
assert_equal email.strip, user.email
end
test 'find_for_authentication and filter_auth_params should not modify the conditions hash' do
FilterAuthUser = Class.new(User) do
def self.filter_auth_params(conditions)
if conditions.is_a?(Hash) && login = conditions.delete('login')
key = login.include?('@') ? :email : :username
conditions[key] = login
end
super(conditions)
end
end
conditions = { 'login' => 'foo@bar.com' }
FilterAuthUser.find_for_authentication(conditions)
assert_equal({ 'login' => 'foo@bar.com' }, conditions)
end
test "filter_auth_params should not convert booleans and integer to strings" do
conditions = { 'login' => 'foo@bar.com', "bool1" => true, "bool2" => false, "fixnum" => 123, "will_be_converted" => (1..10) }
conditions = User.__send__(:filter_auth_params, conditions)
assert_equal( { 'login' => 'foo@bar.com', "bool1" => true, "bool2" => false, "fixnum" => 123, "will_be_converted" => "1..10" }, conditions)
end
test 'should respond to password and password confirmation' do
user = new_user
assert user.respond_to?(:password)
@@ -48,6 +81,18 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
assert_not user.valid_password?('654321')
end
test 'should not raise error with an empty password' do
user = create_user
user.encrypted_password = ''
assert_nothing_raised { user.valid_password?('123456') }
end
test 'should be an invalid password if the user has an empty password' do
user = create_user
user.encrypted_password = ''
assert_not user.valid_password?('654321')
end
test 'should respond to current password' do
assert new_user.respond_to?(:current_password)
end
@@ -58,7 +103,7 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
:password => 'pass321', :password_confirmation => 'pass321')
assert user.reload.valid_password?('pass321')
end
test 'should add an error to current password when it is invalid' do
user = create_user
assert_not user.update_with_password(:current_password => 'other',
@@ -75,10 +120,19 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
assert_match "can't be blank", user.errors[:current_password].join
end
test 'should run validations even when current password is invalid or blank' do
user = UserWithValidation.create!(valid_attributes)
user.save
assert user.persisted?
assert_not user.update_with_password(:username => "")
assert_match "usertest", user.reload.username
assert_match "can't be blank", user.errors[:username].join
end
test 'should ignore password and its confirmation if they are blank' do
user = create_user
assert user.update_with_password(:current_password => '123456', :email => "new@email.com")
assert_equal "new@email.com", user.email
assert user.update_with_password(:current_password => '123456', :email => "new@example.com")
assert_equal "new@example.com", user.email
end
test 'should not update password with invalid confirmation' do
@@ -95,4 +149,23 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
assert user.password.blank?
assert user.password_confirmation.blank?
end
test 'should update the user without password' do
user = create_user
user.update_without_password(:email => 'new@example.com')
assert_equal 'new@example.com', user.email
end
test 'should not update password without password' do
user = create_user
user.update_without_password(:password => 'pass321', :password_confirmation => 'pass321')
assert !user.reload.valid_password?('pass321')
assert user.valid_password?('123456')
end
test 'downcase_keys with validation' do
user = User.create(:email => "HEllO@example.com", :password => "123456")
user = User.create(:email => "HEllO@example.com", :password => "123456")
assert !user.valid?
end
end

View File

@@ -31,8 +31,10 @@ class EncryptableTest < ActiveSupport::TestCase
test 'should generate a base64 hash using SecureRandom for password salt' do
swap_with_encryptor Admin, :sha1 do
ActiveSupport::SecureRandom.expects(:base64).with(15).returns('friendly_token')
assert_equal 'friendly_token', create_admin.password_salt
SecureRandom.expects(:base64).with(15).returns('01lI')
salt = create_admin.password_salt
assert_not_equal '01lI', salt
assert_equal 4, salt.size
end
end

View File

@@ -163,12 +163,12 @@ class LockableTest < ActiveSupport::TestCase
end
test 'should return a new user if no email was found' do
unlock_user = User.send_unlock_instructions(:email => "invalid@email.com")
unlock_user = User.send_unlock_instructions(:email => "invalid@example.com")
assert_not unlock_user.persisted?
end
test 'should add error to new user email if no email was found' do
unlock_user = User.send_unlock_instructions(:email => "invalid@email.com")
unlock_user = User.send_unlock_instructions(:email => "invalid@example.com")
assert_equal 'not found', unlock_user.errors[:email].join
end

Some files were not shown because too many files have changed in this diff Show More