Compare commits

...

997 Commits

Author SHA1 Message Date
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
José Valim
da510508bb Release 1.2.0 2011-03-25 15:53:59 +01:00
José Valim
02ae0c22ef Update CHANGELOG. 2011-03-25 15:40:46 +01:00
José Valim
edee511cd1 Rename active? to active_for_authentication? 2011-03-25 15:40:46 +01:00
Jack Dempsey
fbd35ec332 new cache api requires passing a key to get 2011-03-25 06:38:26 +08:00
José Valim
30b35e3727 Fix syntax error. 2011-03-24 20:25:54 +01:00
Jack Dempsey
330cafd3d2 use reference if available otherwise ref 2011-03-25 03:16:41 +08:00
Jack Dempsey
fe9024218c ref will be reference in 3.1 2011-03-25 03:16:40 +08:00
José Valim
0c9bd3259e 2011-03-23 10:21:11 -07:00
José Valim
b23e2e807a Note about navigational formats. 2011-03-18 16:04:52 +01:00
José Valim
7876acf960 Oops, fix silly mistake. 2011-03-16 05:52:53 -07:00
José Valim
74166e224b Faster uniqueness queries, closes #917 2011-03-15 12:53:17 +01:00
José Valim
cb778d033f Squeeze "/" 2011-03-14 11:04:51 -07:00
José Valim
1bf7da148a Properly ignore path prefix on omniauthable 2011-03-14 18:35:06 +01:00
José Valim
d58a72ee32 Remove stuff deprecated on .rc2 2011-03-14 11:22:09 +01:00
Vinicius Baggio
15d195d2f0 Fixing OmniAuth integration tests since now it has support for failure scenarios 2011-03-12 13:58:19 -03:00
José Valim
4f093574da Release 1.2.rc2. 2011-03-11 20:56:50 +01:00
José Valim
64457e2c1f Update to latest omniauth. 2011-03-11 20:55:36 +01:00
José Valim
3f4fb1a769 Improve previous patch. 2011-03-11 20:46:08 +01:00
gilles
1982ad9f57 fix for possible injection with mongo
Signed-off-by: José Valim <jose.valim@gmail.com>
2011-03-11 20:24:24 +01:00
José Valim
569d205ca7 Gemfile.lock, Y U CHANGING? 2011-03-11 20:17:02 +01:00
José Valim
63b72cd512 Edited app/helpers/devise_helper.rb via GitHub 2011-03-06 05:25:09 -08:00
Michael Klaus
bb89ca4865 Added link to i18n wiki page. 2011-03-06 14:30:07 +08:00
José Valim
307fe6cb60 Revert two previous commits. Rails is broken, it needs to be fixed instead. 2011-03-02 10:13:38 +01:00
José Valim
fe2d7b5ffe Don't cache variable otherwise reloading in development is busted. 2011-03-02 00:16:09 -08:00
Jan Xie
d445db9e5e use Inflector#constantize to get class, compatible with rails edge commit 7b6bfe84f332a3c99656f73cf0251bce0a16ba88 2011-03-02 16:13:15 +08:00
Guilherme Silveira
e4cae200f4 simplifying comparisons (avoind too much negatives) and adding unit test cases 2011-02-27 15:14:02 +08:00
José Valim
a535b047ff Add .travis.yml configuration. 2011-02-25 22:25:34 +01:00
Vinicius Baggio
aa81df261c Warn about an incompatibility between Devise and Mongoid 2011-02-25 18:17:14 -03:00
Vinicius Baggio
0cc900e7cf Reset lock attempts count when lock is expired. Closes #825 2011-02-25 17:59:27 -03:00
Vinicius Baggio
9bff1cf658 Fixing assertion in integration test 2011-02-25 14:57:49 -03:00
Vinicius Baggio
305059f573 Consider SCRIPT_NAME on omniauth url helper. Closes #876 2011-02-25 14:20:12 -03:00
José Valim
392e664036 Be sure to halt on failures, closes #856 2011-02-24 22:31:48 +01:00
José Valim
43a3431c3e Add a test to ensure user.remember_me = true followed by a sign in sends the cookie, closes #776 2011-02-24 22:24:21 +01:00
José Valim
930d5874ca Raise here instead of a warning. 2011-02-24 22:12:54 +01:00
José Valim
3375985ab8 Update CHANGELOG. 2011-02-24 21:58:51 +01:00
José Valim
2e43944567 Move rememberable back to a hook. 2011-02-24 21:55:52 +01:00
Vinicius Baggio
352edc024b Cleaning up test helpers related to OmniAuth.
Developers should rely on OmniAuth's new testing API. Check
https://github.com/intridea/omniauth/wiki/Integration-Testing
for more details.
2011-02-24 16:50:22 -03:00
Vinicius Baggio
b5e289c9a8 Updating bson_ext gem version 2011-02-23 14:34:15 -03:00
Vinicius Baggio
42d002702c Considering namespaces while generating the routes. Closes #682 2011-02-23 14:24:47 -03:00
Vinicius Baggio
6bd65209d5 Added a test case for Devise Generator 2011-02-23 14:24:47 -03:00
Vinicius Baggio
970457f2c2 Fixing test error when dealing with multiple time zones 2011-02-23 14:24:42 -03:00
Alexander Uvarov
bbaaefa995 Relax dependency on ActiveModel::Dirty
Signed-off-by: José Valim <jose.valim@gmail.com>
2011-02-18 12:28:56 +01:00
Joey Aghion
fdf6a48a7e Custom failure apps no longer ignored in test mode. 2011-02-18 15:53:04 +08:00
José Valim
7113beac81 Bring back behavior for < 3.0.4. 2011-02-16 20:59:58 +01:00
José Valim
0c5acc6f38 Update CHANGELOG. 2011-02-15 11:35:24 +01:00
José Valim
dd721f1857 Use secure compare as well. 2011-02-15 11:33:54 +01:00
José Valim
ae75186c52 Update CHANGELOG. 2011-02-15 10:59:41 +01:00
José Valim
ca293d17ba Implement Rails' handle unverified request. 2011-02-15 10:58:38 +01:00
José Valim
add8f8a203 Works on 3.0.4. 2011-02-15 10:27:34 +01:00
José Valim
6a6ed6702e Improve tests and update CHANGELOG. 2011-02-15 10:07:08 +01:00
Nate Todd
2d0f887ba7 Preventing timeoutable from interfering with stateless tokens.
Signed-off-by: José Valim <jose.valim@gmail.com>
2011-02-15 09:54:13 +01:00
José Valim
3109b0924b Remove --haml and --slim views from Devise. 2011-02-15 09:49:11 +01:00
José Valim
bbafb70655 Update CHANGELOG. 2011-02-15 09:45:37 +01:00
José Valim
aac9c40cba Ensure after hooks are called on registrations controller, closes #852 2011-02-15 09:41:35 +01:00
Jo Liss
f964ea526b Skip test that fails with Mongoid.
The test suite passes now.
2011-02-10 23:00:14 +08:00
Jo Liss
bca43a7576 Require 'rails' in devise.rb.
This way we can require 'devise' without requiring 'rails' beforehand.
2011-02-10 23:00:13 +08:00
Jo Liss
8440ed0101 Make Devise::friendly_token 20 characters long.
This makes the tokens better suited for URLs in plain-text emails, and
is still secure for all practical purposes.
2011-02-10 21:42:58 +08:00
Jeffrey Jones
cb5e0c4a7b Simplified logic for checking if the email is present and moved the Mongoid classes out of eval statements 2011-02-10 16:16:33 +08:00
Jeffrey Jones
0287d8cc80 When using database_authenticatable Devise will now only create an email field when appropriate.
(If using default authentication_keys or custom authentication_keys with email included)

Test written for Mongoid, not sure how to test for active_record yet.
2011-02-10 16:16:33 +08:00
José Valim
a48c815dc8 Update CHANGELOG. 2011-02-09 10:13:08 +01:00
José Valim
f332d7e932 Add a test to show recoverable works as expected if password is blank. 2011-02-09 10:11:48 +01:00
José Valim
a14b833581 Update Copyright years. 2011-02-09 00:02:54 -08:00
Carlos Antonio da Silva
c9fe8885f9 Spaces 2011-02-06 19:23:36 -02:00
Carlos Antonio da Silva
e1c3b915e7 Remove require to rake and devise version from Rakefile 2011-02-06 19:19:28 -02:00
Nico Ritsche
f06bed279a corrected 'an user' to 'a user' in comments and docs 2011-02-06 23:46:49 +08:00
Julien Desrosiers
3fd206c591 update README to add ruby_parser as a dependency for generating the Haml templates 2011-02-06 03:06:57 +08:00
John Plummer
7a1852e9f5 Allow send confirmation to change keys used 2011-02-05 16:19:01 +08:00
José Valim
76a4800446 Words. 2011-01-31 15:16:58 +01:00
José Valim
5f93d8355c A tip for newcommers. 2011-01-31 14:06:35 +01:00
Carlos Antonio da Silva
1f8909458f Fix typo 2011-01-26 22:26:40 -02:00
José Valim
68f699bfd4 Do not change default behavior of previous apps. 2011-01-21 10:55:40 +01:00
José Valim
0615c0a0a4 Fix infinite redirect issues. Closes #787 and closes #795. 2011-01-20 09:22:41 +01:00
José Valim
c78bb68c66 Revert "Fix an issue causing infinite redirects in production, closes #720"
This reverts commit a156576ce9.

Conflicts:

	lib/devise/controllers/internal_helpers.rb
2011-01-20 09:16:44 +01:00
José Valim
d018970c4b Revert "Doh. Use respond_to :all."
This reverts commit 555435e6fe.
2011-01-20 09:14:38 +01:00
Jo Liss
971f68f97d README: Call the Google Group a mailing list; merge Testing section into Contributing; minor fixes for consistency. 2011-01-16 01:35:53 +08:00
Jo Liss
4207c2321f Fix the module sorting in devise method. 2011-01-15 07:38:06 +08:00
Jo Liss
54dc82ad25 Generate add_index for :authentication_token (used by :token_authenticatable). 2011-01-15 06:42:30 +08:00
Jo Liss
fa239b984a Do not silently ignore invalid modules passed to devise method in model.
The & operator seemed to be only used to force sorting, but as a
side effect we got suboptimal error handling.
2011-01-15 06:42:29 +08:00
Jo Liss
692f7b27ff typos (remaining instances of authenticable -> authenticatable) 2011-01-13 13:02:17 +08:00
Jo Liss
258eb1c7e6 Move config.pepper from encryptable into database_authenticatable section in the initializer.
config.pepper is used by both database_authenticatable and encryptable,
but encryptable requires database_authenticatable anyway, so it makes
more sense to have it in the database_authenticatable section.
2011-01-13 13:02:17 +08:00
Jo Liss
aa61034d40 Add Testing section to README (issue #766). 2011-01-13 13:02:16 +08:00
Jo Liss
42f2196d01 Rakefile: exit on failing test
And the world can always use more snark. ;-)
2011-01-12 00:53:47 +08:00
vagmi
d87521723d fix create_haml_views. see issue 761 for details
accessing a variable before assigning causes nil exception
2011-01-11 19:06:48 +08:00
siong1987
6e91edd5e3 failure_app redirects to the correct format if it is a non-html request. This is to ensure that firefox redirects the correct format since firefox doesn't inherit accept info. also fix issue 675 that is resurrected by issue 754. 2011-01-11 18:27:14 +08:00
Andrés Mejía
fb4ec6e9da Fixing parameters for _omniauth_authorize_path method after short-circuiting it. 2011-01-08 02:37:05 +08:00
José Valim
7ff0231ab7 Don't pass options forward, this fixes uncaught warden error. Unfortunately could not write a test for it, although easily reproducible in Rails applications. Closes #754 2011-01-03 16:25:23 +01:00
Carlos Antonio da Silva
3f086656aa Fix RegistrationsController routes comments 2011-01-02 20:17:48 -02:00
Carlos Antonio da Silva
55cb7195b8 Implicit self 2011-01-02 20:13:37 -02:00
José Valim
555435e6fe Doh. Use respond_to :all. 2010-12-30 14:49:15 +01:00
Richard Aday
88d4aca2c4 Adding tests for reset_password_keys and unlock_keys 2010-12-30 03:11:03 +08:00
Richard Aday
038eb321d4 Allowing reset_password_keys and unlock_keys to be set through the config 2010-12-30 03:10:56 +08:00
José Valim
c8c84c77c6 Respond to all formats if none is specified. 2010-12-29 16:01:11 +01:00
José Valim
8f20b13f84 By default, just require e-mail on recover and lockable. 2010-12-28 23:00:23 +01:00
José Valim
af1295284c rememberable cookie now is httponly by default 2010-12-25 12:04:04 +01:00
JamesFerguson
1b43cb5203 Added assertion testing that remember_user_token cookie is flagged as HttpOnly.
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-12-25 11:49:40 +01:00
José Valim
b34f456096 Invoke callbacks using the correct API 2010-12-25 11:41:14 +01:00
Josh Starcher
e95eb93eb7 added failing test for Warden before_failure hooks 2010-12-25 18:21:20 +08:00
Josh Starcher
1a2590dc08 Warden before_failure hooks are an array, not a proc 2010-12-25 18:21:20 +08:00
José Valim
1cdb02bd54 More tiny fixes 2010-12-25 11:15:56 +01:00
José Valim
7759c8b3f3 Update CHANGELOG 2010-12-25 11:11:56 +01:00
José Valim
b32883a7c5 Small fixes in views generator 2010-12-25 11:07:52 +01:00
José Valim
27051cb2fe responder formats should be inherited from ApplicationController 2010-12-25 11:04:39 +01:00
Prem Sichanugrist
e8e3df3891 Add support for non-navigational format response to SessionsController
This will make Devise::SessionsController return the authenticated object in the requested format instead of redirect the client to another page upon success authentication.
2010-12-25 17:57:15 +08:00
Fred Wu
2561cd4eac Use an instance variale when removing the temp directories otherwise the create_haml_views method gets called twice. 2010-12-23 17:05:05 +08:00
Fred Wu
146090f86e Added more clarification for the devise:views generator. 2010-12-23 17:05:05 +08:00
Fred Wu
4519364eaf Added support for generating Slim view templates. 2010-12-23 17:05:03 +08:00
Uģis Ozols
f56c588a6a Fix typo. 2010-12-23 15:48:03 +08:00
siong1987
379d8c69a5 Issue 675: recall option is now passed for not confirmed email and inactive account. 2010-12-23 02:24:26 +08:00
José Valim
13e8bc22e3 Move duplicate sign_in logic to sign_in(). 2010-12-20 10:02:27 +01:00
José Valim
c27bc21af9 Update CHANGELOG. 2010-12-18 09:39:55 +01:00
José Valim
a156576ce9 Fix an issue causing infinite redirects in production, closes #720 2010-12-18 09:38:41 +01:00
José Valim
b942520dc4 No need to use expand_path as we assume the test directory is in the . 2010-12-18 08:22:01 +01:00
Andrés Mejía
a2e92a2ef2 Adding mongoid generator tests. 2010-12-18 15:15:43 +08:00
Andrés Mejía
60be68436b Adding tests for Active Record generator 2010-12-18 15:15:43 +08:00
Andrés Mejía
fe4eaf2d12 Invoking the model generator even if the model exists but only when the behavior is :revoke (i.e. we are running 'rails destroy' instead of 'rails generate') 2010-12-18 15:15:42 +08:00
Andrés Mejía
845c186f48 Removing caching from #model_exists? so it doesn't return a false positive when the method is called, the file is deleted and then the method is called again. 2010-12-18 15:15:42 +08:00
José Valim
9f832d2cb2 Remove Jeweler. 2010-12-16 16:37:42 +01:00
José Valim
a23a52b2f7 Update dependencies versions. 2010-12-11 10:24:52 +01:00
Carlos Antonio da Silva
7ed1fb116f Cleanup requires in generators tests, fixing issue with load error in Ruby 1.9.2 2010-12-09 23:52:30 -02:00
José Valim
b50fd1a72e Fix e-mail regexp. Closes #698 2010-12-01 17:19:45 +01:00
José Valim
2305e8f8cf Improve README. 2010-11-30 14:17:18 +01:00
José Valim
f2f9232b89 Fix typo. 2010-11-30 05:01:19 -08:00
José Valim
cb62597afa Improve messages. 2010-11-30 12:23:09 +01:00
José Valim
089c316f37 Improve message. 2010-11-29 00:56:43 -08:00
José Valim
ec5bfe9119 Ensure to convert keys on indifferent hash. 2010-11-27 19:45:25 +01:00
José Valim
912969b5a0 Update CHANGELOG. 2010-11-27 08:10:44 -08:00
Gavin Hughes
fe5ef25614 Deprecate anybody_signed_in? in favor of signed_in?(nil) 2010-11-28 00:09:23 +08:00
José Valim
1d6944d201 Update gemspec with 1.2.rc release. 2010-11-26 12:19:22 +01:00
Carlos Antonio da Silva
268eae1013 Add update_attribute method to Mongoid Shim for devise tests, to fix failing test
Mongoid does not have this method in the current beta version (2.0.0.beta.20).
2010-11-26 01:14:27 -02:00
Carlos Antonio da Silva
eb7760b4b2 Make sure to load test gems only in Devise test env 2010-11-26 00:55:16 -02:00
Carlos Antonio da Silva
112f499937 Use UTC for Mongoid timestamps, so it conforms with AR. 2010-11-26 00:54:08 -02:00
Carlos Antonio da Silva
a582d4dca1 Configure Gemfile to use Rails 3.0.x. Also bump mongo related and webrat gem versions 2010-11-26 00:53:57 -02:00
José Valim
4977bd1222 Fix indifferent access on session issue. 2010-11-25 00:06:39 +01:00
Carlos Antonio da Silva
ed30114bd8 Fix changelog e cleanup white spaces 2010-11-21 11:25:37 -02:00
José Valim
71450998c5 Avoid session fixation attacks. 2010-11-20 23:18:41 +01:00
José Valim
6f205fe4c4 Tidy up. 2010-11-20 21:44:53 +01:00
Steve Ross
4a8f9a9ba8 set_flash_message: Added conditional to make certain flash entries are not set if message is blank.
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-11-20 21:42:25 +01:00
José Valim
d8016ea3fd Ensure namespaces has proper scoped views, closes #654 2010-11-20 21:41:26 +01:00
José Valim
6bfcbeffdd Tidy up and update CHANGELOG. 2010-11-20 21:19:12 +01:00
José Valim
094790295c Merge remote branch 'adahl/master' 2010-11-20 20:57:02 +01:00
Andrew Dahl
8d1e23c67d add unit and integration tests for case insensitive keys 2010-11-20 15:54:01 +01:00
Andrew Dahl
e911abf13b changed case_insensitive_keys config setting to an array and added downcasing of keys as a before filter on database authentication module 2010-11-18 23:29:53 +01:00
Andrew Dahl
26b1bc4107 Revert "remember to downcase on registration"
This reverts commit 0c0444c078.
2010-11-18 22:28:23 +01:00
Andrew Dahl
0c0444c078 remember to downcase on registration 2010-11-18 21:58:00 +01:00
Andrew Dahl
94c666e439 first attempt 2010-11-18 21:24:42 +01:00
José Valim
67645c68f7 Move extra helpers names to the bottom. 2010-11-15 06:55:47 -08:00
Romain Pechayre
13968f49af Updated README for better layout of modification of previous commit 2010-11-15 22:54:02 +08:00
Romain Pechayre
1b05d8c3bd Updated README to remove unclarity about user autogenerated helper methods 2010-11-15 22:54:02 +08:00
Andrés Mejía
020f919dcd Tpyo. 2010-11-15 18:35:15 +08:00
José Valim
b70b72b6b0 Rollback to use the regexp result. 2010-11-15 10:01:45 +01:00
Denis Hennessy
19219cbe0f Fix for HTTP Basic Auth when base64 encoded string wraps
When using a token longer than approximately 45 characters, the base64 encoded string passed in
the HTTP_AUTHORIZATION header will contain newline characters. The existing implementation used
a regex which didn't handle this case correctly.
2010-11-15 16:40:39 +08:00
Robert Peters
32c6f7b00b For #646 - modify the configuration text that is output for confirm_within so that it matches the actual default value. If you use nil as a value, it crashes trying to call nil.ago 2010-11-13 15:50:33 +08:00
José Valim
67a49f3b75 Ensure authenticatable_salt can be nil. 2010-11-11 22:51:39 +01:00
José Valim
14d772972d No need to set a pepper in a bcrypt world. 2010-11-11 12:54:09 -08:00
José Valim
b2496d1bc1 Smallish updates. 2010-11-11 13:53:52 +01:00
José Valim
2d2c4c63be Update gemspec. 2010-11-11 13:28:25 +01:00
José Valim
c7efb68a77 Devise does not intercept 401 returned from applications anymore 2010-11-09 23:42:14 +01:00
José Valim
2366530d55 Update CHANGELOG. 2010-11-09 23:31:35 +01:00
José Valim
505bd39700 failure_app now properly handles nil request.format 2010-11-09 23:30:53 +01:00
José Valim
07fedb4383 Merge branch 'omniauth' 2010-11-09 22:28:05 +01:00
José Valim
931b902583 Fix failing tests. 2010-11-09 22:27:46 +01:00
José Valim
835d1044ae Fix a problem with IE7 headers. 2010-11-08 22:45:42 +01:00
José Valim
f49efdff13 Update Gemfile.lock. 2010-11-08 22:33:13 +01:00
José Valim
1f44c61d08 Improve error messages, closes #574 2010-11-06 08:54:03 +01:00
José Valim
ad8d2d7d99 Be more helpful in the already confirmed message, closes #613 2010-11-06 08:54:03 +01:00
José Valim
74edcb8bec Add test/tmp/* to gitignore. 2010-11-06 08:54:03 +01:00
stJhimy
e8dd48c824 Added test for Devise::Generators::ViewsGenerator with scope
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-11-06 08:54:03 +01:00
stJhimy
0948334393 Added test for Devise::Generators::ViewsGenerators with no params
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-11-06 08:54:03 +01:00
stJhimy
3b1f1ea719 Added test for Devise::Generators::InstallGenerator
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-11-06 08:54:03 +01:00
Mike Gehard
9b468816dd Add in some instructions for getting routes to a custom action on a Devise override controller 2010-11-06 15:52:29 +08:00
José Valim
4210499f7f Improve error messages, closes #574 2010-11-05 10:08:38 -02:00
José Valim
2aeaf4b109 Be more helpful in the already confirmed message, closes #613 2010-11-05 10:03:52 -02:00
bUg
ab033ea986 fix for omniauth 0.2.0 2010-11-04 08:21:34 +08:00
David A. Cuadrado
09a46695f2 omniauth route should not add a ? if no param is given 2010-10-31 03:06:53 +08:00
David A. Cuadrado
bf19b15914 added open id support via omniauth 2010-10-31 03:06:52 +08:00
bUg
94622054de tests for Devise::Mapping.find_by_path! 2010-10-30 08:57:14 +08:00
bUg
c429fe8d1c fixed bug 'Could not find a valid mapping for path /users/auth/:provider/callback' when devise_for called inside scope 2010-10-30 08:57:13 +08:00
bUg
d8f33b8925 omniauth routes fix, see devise issue #600 2010-10-29 20:48:40 +08:00
José Valim
e30c0f3319 Do not automatically set filter_parameters. 2010-10-26 18:07:06 -02:00
José Valim
976d77defe Add test/tmp/* to gitignore. 2010-10-26 18:01:23 -02:00
stJhimy
4b776c4910 Added test for Devise::Generators::ViewsGenerator with scope
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-10-26 18:00:45 -02:00
stJhimy
f53f02f385 Added test for Devise::Generators::ViewsGenerators with no params
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-10-26 18:00:39 -02:00
stJhimy
b3d3deb12f Added test for Devise::Generators::InstallGenerator
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-10-26 18:00:33 -02:00
bUg
6b04312be5 get -> match for omniauth callbacks
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-10-26 17:55:18 -02:00
José Valim
31edd76369 Remove crazy controllers handling code. 2010-10-18 15:01:38 +02:00
José Valim
3d1152fb8f Update README and CHANGELOG. 2010-10-18 15:01:38 +02:00
José Valim
ca038677f2 Update gemspec. 2010-10-18 15:00:34 +02:00
José Valim
3e38043085 Properly handle failure. 2010-10-18 15:00:34 +02:00
José Valim
611261c64e More tests for Omniauth. 2010-10-18 15:00:34 +02:00
José Valim
2f360bf201 Remove OAuth2 in favor of OmniAuth. 2010-10-18 15:00:34 +02:00
José Valim
5d4e4fbb88 Automatically set OmniAuth path prefix 2010-10-18 15:00:34 +02:00
José Valim
21d5e50054 Basic omniauth support. 2010-10-18 15:00:34 +02:00
George Guimarães
bca72ddf59 fixing typo and whitespaces 2010-10-16 20:17:39 -03:00
Jared Morgan
0aa21dca4c Use to_adapter.get in Warden::SessionSerializer#deserialize 2010-10-17 04:22:22 +08:00
Jared Morgan
31170b9100 Use to_adapter in two more methods
Authenticatable.generate_token and Warden::SessionSerializer#deserialize
2010-10-17 04:22:22 +08:00
José Valim
cdbd03c45a Simplify I18n lookup. 2010-10-14 14:43:41 +02:00
José Valim
fb81453274 Update Gemfile. 2010-10-14 08:45:17 +02:00
José Valim
8539f5f915 Do not depend on orm_adapter git repo. 2010-10-10 22:06:53 +02:00
José Valim
8a8ba6c70c Depend on ORM Adapter. 2010-10-10 17:51:32 +02:00
José Valim
b409184a98 Update CHANGELOG. 2010-10-10 17:51:32 +02:00
José Valim
e4c5158851 Sign out by default will destroy the existing session. 2010-10-10 17:51:32 +02:00
José Valim
7bc37e5237 Provide a better encryptor message and update Gemfile.lock. 2010-10-10 17:51:32 +02:00
Sean Cribbs
9f032350e3 Use ActiveModel's to_key instead of id.
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-10-10 17:51:32 +02:00
José Valim
b4a99f6698 Use gemspec in Gemfile. 2010-10-10 17:51:31 +02:00
José Valim
94ccfc5322 Remove deprecation warnings on Rails 3.1. 2010-10-10 17:51:31 +02:00
Sebastián Gamboa
721843c841 Allow to conditionally skip email validation. 2010-10-05 05:42:20 +08:00
takahashim
a1c80b6211 use I18n'ed header on error messages block 2010-10-04 15:38:07 +08:00
dewski
69ecbd1fa3 removed the occurances of =%> at the end of erb blocks and replaced them with -%> 2010-10-02 05:56:29 +08:00
José Valim
ec5f8ae831 Update RDoc. 2010-09-30 04:47:13 -07:00
José Valim
db1ce8eeb2 Sign up now check if the user is active or not and redirect him accordingly setting the inactive_signed_up message. This commit also moves after_update_path_for to inside RegistrationsController, not allowing it to be overriden inside ApplicationController anymore. 2010-09-30 09:12:00 +02:00
José Valim
e01dccaefb Fix recoverable tests. 2010-09-30 09:05:11 +02:00
Pat Allan
16c39a9f17 Making sure timeoutable respects rememberable if both are loaded. 2010-09-29 15:27:54 +08:00
José Valim
fbb77a6edd Ensure bcrypt also uses pepper for backward compatibility. 2010-09-28 17:45:34 +02:00
Kevin
ab690bf36f Use Rails 3 email_field helper instead of text_field for email 2010-09-28 06:18:05 +08:00
Joey Geiger
c8cb7d270d Use a better label to enforce that you are changing your password to a new one. 2010-09-28 01:26:56 +08:00
José Valim
3e9b2092f8 Regenerate gemspec. 2010-09-27 09:36:09 +02:00
José Valim
ef3480004c Ensure we are pointing to the proper sessions controller on failure. 2010-09-26 21:12:05 +02:00
Carlos Antonio da Silva
ffaba3f1d3 Avoid RAILS_DEFAULT_LOGGER deprecation warning from Webrat
This must be fixed in Webrat.
2010-09-26 14:53:36 -03:00
Carlos Antonio da Silva
f60123ce01 Bump webrat to 0.7.1 2010-09-26 14:45:00 -03:00
Carlos Antonio da Silva
a7cc3388b4 Regenerate devise config file for tests and get all tests green on mongoid 2010-09-26 14:31:08 -03:00
Carlos Antonio da Silva
98e69cfd71 Remove unused options param for token_auth schema, and avoid creating a new hash 2010-09-26 14:08:25 -03:00
Carlos Antonio da Silva
6a09daf570 Don't need to extend ActiveSupport::Concern anymore in oauth helpers 2010-09-26 11:47:56 -03:00
José Valim
fbac68d51a This helpers are useless outside oauth context. 2010-09-26 13:40:09 +02:00
José Valim
2169e5de97 OAuth shortcut should use paths instead of urls. 2010-09-26 13:28:30 +02:00
José Valim
4d8d1f5222 Uncomment pepper in configuration. 2010-09-26 01:44:37 -07:00
Carlos Antonio da Silva
0bc80cec35 Remove autoload for Bcrypt encryptor, it does not exist anymore 2010-09-25 23:14:31 -03:00
José Valim
38f3f6318a cookie_domain is deprecated in favor of cookie_options which uses session_options by default. 2010-09-25 21:13:54 +02:00
José Valim
1dfcbe3bd4 Regenerate gemspec to force latest warden version. 2010-09-25 20:29:33 +02:00
José Valim
531f221be7 Allow :stateless_token to be set to true avoiding users to be stored in session through token authentication 2010-09-25 20:28:14 +02:00
José Valim
617e142e34 Store the salt in session and expire the session if the user changes his password 2010-09-25 17:24:56 +02:00
José Valim
6613653df0 Update CHANGELOG. 2010-09-25 16:10:59 +02:00
José Valim
09088706bb Extract encryptors into their own module for better bcrypt support. 2010-09-25 16:08:46 +02:00
José Valim
31d821c2e0 Allow to Rememberable to work without remember_token relying on salt if possible.
This comes with the benefit that if you change your password, all remember tokens expires, and it also requires one field less in the database.

The downside is that if you want remember_me_across_browser to be false, it won't work unless you use the token. It also requires you to be using database_authenticable.

Using salt is now the default in Devise.
2010-09-25 13:07:24 +02:00
José Valim
1ed674afa8 Use Admin in old rememberable tests. 2010-09-25 12:04:38 +02:00
José Valim
2aa1d2f3b7 Increase the size of the friendly token.
The chance of someone to successfully guess a random token in the website is:

(number_of_users / 2388636399360109977557402041718133080829429159844757507642063199359529632522467783435119230976)
2010-09-25 11:51:57 +02:00
José Valim
c12d75eecf Do not rely on controller being available in params. 2010-09-25 11:22:18 +02:00
José Valim
b6089145c1 Warden 1.0! :mantears: 2010-09-25 11:22:17 +02:00
Carlos Antonio da Silva
d02ea3153b Small doc fix 2010-09-24 08:59:39 -03:00
José Valim
dd11f43014 All tests green on latest mongoid. 2010-09-24 11:30:08 +02:00
José Valim
f96061b350 Update docs and CHANGELOG based on the 1.1.3 release from v1.1 branch. 2010-09-24 09:43:40 +02:00
Carlos Antonio da Silva
aaeb053c1d Update CHANGELOG 2010-09-24 00:15:00 -03:00
Martin Davidsson
ec0e105c52 Incorporate feedback from carlosantoniodasilva and update rememberable
tests
2010-09-24 11:08:59 +08:00
Martin Davidsson
f3e348f6f4 Merge options hash instead of overwriting it
The forgetable hook will delete cookies based on the :scope in an
options hash but it was overwriting the options and setting them to
either an empty hash or a hash with a single :domain key. Because the
:scope was lost, the hook was trying to delete the 'remember__token'
instead of the more typical 'remember_user_token' cookie.
2010-09-24 11:08:58 +08:00
José Valim
589de27bcd Stop using inject({}) to build hashes. It is harder to read and slower. 2010-09-22 23:29:17 +02:00
Trevor Turk
fdb4cd5b38 Major update to README - encourage use of the Wiki 2010-09-22 07:31:31 +08:00
José Valim
d6084ab1f7 Improve CHANGELOG. 2010-09-21 12:09:53 +02:00
Thibaud Guillaume-Gentil
c121d8026e Avoid BCrypt::Errors::InvalidSalt: invalid salt
when password_salt is nil.

Signed-off-by: José Valim <jose.valim@gmail.com>
2010-09-21 12:09:07 +02:00
José Valim
5429f940e7 Refactor code related with authentication keys on password recovery and account unlocking, closes #396. 2010-09-21 12:05:17 +02:00
RStankov
850afec96e make User#send_reset_password_instructions to require all authentication_keys
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-09-21 11:47:07 +02:00
RStankov
fb86f772e7 make User#send_unlock_instructions to require all authentication_keys
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-09-21 11:46:57 +02:00
José Valim
b2066cc229 Add request_keys support. Closes #401. 2010-09-21 11:45:44 +02:00
José Valim
fc37436a24 Update CHANGELOG. 2010-09-21 10:52:24 +02:00
José Valim
7c630fdb5e Do not execute Warden::Callbacks on Devise::TestHelpers. Closes #414. 2010-09-21 10:50:01 +02:00
Sam Grönblom
57ab87a1b6 Added four tests related to Warden callbacks
Two tests are to ensure that the callbacks are called at all. The other
two test ensure that the user parameter provided to the callback is not
nil.

Signed-off-by: José Valim <jose.valim@gmail.com>
2010-09-21 10:31:09 +02:00
José Valim
ff0b4deb1a Add reply-to to e-mail headers by default. Closes #474 2010-09-21 10:07:02 +02:00
Pat Allan
29e9be92b0 Reworking the internals of Devise::Mailer - mainly so headers can be tweaked without overwriting/rewriting #setup_mail. (I'm using a custom mailer which is a subclass of Devise::Mailer, and want to change headers/templates in some situations - but perhaps this is useful generally). 2010-09-20 21:02:28 +08:00
Carlos Antonio da Silva
0388380614 Small comment fix 2010-09-17 20:58:32 -03:00
takahashim
a9f7b3258a fix TypeError in test_sign_in_with_script_name(AuthenticationOthersTest) 2010-09-16 23:02:49 +08:00
Pelle Braendgaard
7b069e641b Improved test thanks to Jose Valim. 2010-09-14 03:55:10 +08:00
Pelle Braendgaard
2fdb71716f The http authentication code was not checking for the type of authentication in the Authentication header.
This caused issues with OAuth header authentication.
Please note I have added a test but I'm not sure it works right as it doesn't fails without the change :-)
But it does fix failures in the oauth-plugin provider specs using devise.
2010-09-14 03:55:09 +08:00
Carlos Antonio da Silva
5c928df66b Strip some whitespaces 2010-09-09 21:11:23 -03:00
James Miller
0f0eb4e8ce Fix for failed first-ever logins on PostgreSQL where column default is nil 2010-09-02 05:46:56 +08:00
Vinicius Baggio
006f48232f Fixing typo in documentation 2010-09-01 17:50:52 -03:00
Hugo Baraúna
6e71eca2dd Updates the docs link from rdoc.info to rubydoc.info
RubyDoc.info is a new guy in the ruby community that was built to replace Rdoc.info. Actually, RubyDoc.info is a result of the merge betwenn yardoc.org/docs and rdoc.info.
2010-08-31 16:17:17 -07:00
José Valim
31d7020637 Reorganize tests for failure app and add entries to CHANGELOG. 2010-08-31 23:55:25 +02:00
José Valim
c8bd965462 Depend on Rails 3 gem in Gemfile. 2010-08-31 23:47:16 +02:00
Santiago Pastorino
e582112369 set WWW-Authenticate header on http_auth if request is not xhr 2010-09-01 05:35:40 +08:00
Daniel Lopes
736654e1bc adding docs for the namespace behavior 2010-08-31 23:59:50 +08:00
Santiago Pastorino
5fb5efbd42 Returning WWW-authenticate on ajaxs calls depends only on Devise.http_authenticatable_on_xhr config 2010-08-31 23:51:58 +08:00
Brian Rose
bf122d8fea Remove inaccurate documentation regarding confirmable and changing emails. 2010-08-27 20:11:03 +08:00
José Valim
daf4b35f85 Update Gemfile lock. 2010-08-26 11:54:45 -03:00
José Valim
ee49077072 :default options is used, closes #452 2010-08-26 08:30:43 -03:00
Fred Wu
c6002bb9bd Corrected the mongoid git repo. 2010-08-25 23:01:52 +08:00
José Valim
5701542adc Update CHANGELOG. 2010-08-25 08:52:04 -03:00
José Valim
c96e17dd8d Ensure routes works for all rails 3 versions. 2010-08-25 08:51:17 -03:00
George Guimarães
1e17b6a5ec Typo in initializer 2010-08-25 00:41:26 -03:00
José Valim
219c05ce49 Small fix in the README. 2010-08-23 14:02:15 -07:00
José Valim
08da923276 Add more docs to the cancel action. 2010-08-23 13:51:37 -07:00
George Guimarães
a9aab6bd27 Changes the comments in devise initializer to reflect the default options. 2010-08-23 16:50:42 -03:00
José Valim
e1006bd6c6 Merge branch 'master' of github.com:plataformatec/devise 2010-08-23 10:26:52 -03:00
José Valim
b8ab9a835b Disable HTTP Authentication by default. You can turn it on in the initializer. 2010-08-23 10:22:31 -03:00
José Valim
617b95fdcd sign_out_all_scopes is true by default. 2010-08-23 09:18:39 -03:00
José Valim
ab7f3bc175 Added Devise.sign_out_via. 2010-08-23 09:05:40 -03:00
José Valim
3d3bb352fb Update CHANGELOG. 2010-08-23 09:02:57 -03:00
José Valim
731650a0f1 after_sign_in_path_for always receives a resource 2010-08-23 08:56:10 -03:00
José Valim
6754ae761c Update README. 2010-08-17 15:38:07 -07:00
Carlos Antonio da Silva
81c49c69df Fix failing helper test and test descriptions 2010-08-13 09:02:51 -03:00
Martin Rehfeld
f3385e96ab use :sign_out_via to control the method(s) for the destroy_*_session_path route 2010-08-13 19:16:59 +08:00
Martin Rehfeld
f04e633542 provide :sign_out_via option for Devise::Mapping 2010-08-13 19:16:58 +08:00
Fred Wu
701bbf2d3c Updated the views generator to respect the rails :template_engine option. 2010-08-06 18:40:46 +08:00
Carlos Antonio da Silva
01c272c692 Add some tests to helper creation using namespaces, to better show how it works. 2010-08-02 08:52:12 -03:00
José Valim
c0c7aefce4 Smallish update to README. 2010-08-02 13:22:45 +02:00
José Valim
c31b1f2146 Remove skipped handling from OAuth in favor of exceptions and rescue_from syntax. 2010-07-28 21:51:26 +02:00
José Valim
a707423d23 Merge remote branch 'stepheneb/jruby' 2010-07-28 13:36:54 +02:00
Jared Morgan
afaf42df5a Add note to README about dm-devise project 2010-07-28 19:29:46 +08:00
Stephen Bannasch
fcef459db3 updated Gemfile.lock 2010-07-27 15:02:07 -04:00
Stephen Bannasch
cd985667db merge with master 2010-07-27 14:57:17 -04:00
Stephen Bannasch
83dc11df14 Gemfile works with JRuby 1.5.1, tests run
The :mongoid group does not work in JRuby so the group
is only defined for the platform: 'ruby'.

In addition installing ruby-debug in JRuby is a manual process so
only include the dependency if we are using the platform: 'ruby'

Here are the steps necessary to run the devise tests in JRuby
using rvm:

  rvm install jruby
  rvm use jruby@devise --create
  gem install bundler --pre
  gem install jeweler
  bundle install
  rake test
2010-07-27 14:35:18 -04:00
José Valim
e6218b3ac2 Update CHANGELOG from branch. 2010-07-27 16:32:09 +02:00
José Valim
d6c6e7cfe1 Fix generators bug. 2010-07-27 16:14:09 +02:00
José Valim
9d5a5beb59 Register helper_methods on demand. 2010-07-27 15:34:08 +02:00
Pat Allan
0a3099663e Let's just include the test helpers for controller specs, not all specs. 2010-07-27 21:00:57 +08:00
Pat Allan
fd35b36c4a Presumed Markdown syntax - switching inline code to RDoc. 2010-07-27 21:00:56 +08:00
Pat Allan
2d67432c23 Expanding on testing docs a little to be more useful for those using RSpec. ActionController::TestCase doesn't seem to be used in RSpec 2 - and besides, we want the setup method called so Warden is automatically initialised. 2010-07-27 21:00:56 +08:00
José Valim
2308361fe0 Update README about OAuth2 support. 2010-07-26 20:43:51 +02:00
José Valim
817a7802e1 Remove deprecated stuff, tag 1.2.0 as version. 2010-07-26 20:39:40 +02:00
José Valim
33ce94363e Merge branch 'oauth'. Welcome to the future. 2010-07-26 20:34:01 +02:00
José Valim
fefbf51c79 scope_signed_in? helpers now simply delegate to current_scope to improve performance. 2010-07-26 20:33:23 +02:00
José Valim
a36cb6e758 Improve docs for routes customization. 2010-07-26 20:33:23 +02:00
José Valim
3beb6ef1a6 Do not eager load all controllers. Otherwise this will force OAuth to be loaded. 2010-07-26 20:33:23 +02:00
José Valim
ac69078534 Improve TODO. 2010-07-26 20:33:23 +02:00
José Valim
4ac6b6e407 Unit tests for OAuth. 2010-07-26 20:33:23 +02:00
José Valim
9222601c5b Expand README on OAuth testing. 2010-07-26 20:33:23 +02:00
José Valim
4bfa98eb7c More and more tests to DeviseOauth. 2010-07-26 20:33:23 +02:00
José Valim
00c6f583e2 More OAuth tests. 2010-07-26 20:33:22 +02:00
José Valim
adba4e2262 Register cancel route so a shortcut is created. 2010-07-26 20:33:22 +02:00
José Valim
ac8221aca7 Add cancel to registrations controller as a way to delete information from session. 2010-07-26 20:33:22 +02:00
Carlos Antonio da Silva
d0d88cf259 Minor tweaks in OAuth README 2010-07-26 20:33:22 +02:00
José Valim
bd8d11e291 More minor tweaks to README> 2010-07-26 20:33:22 +02:00
José Valim
0d6f303735 Add a small connection stubbing API. 2010-07-26 20:33:22 +02:00
José Valim
ef841ca17d Start to add helpers for OAuth tests. 2010-07-26 20:33:22 +02:00
José Valim
eb3118e89a Add OAuth2 documentation. 2010-07-26 20:33:21 +02:00
José Valim
5d6900dcdb Remove old generators. 2010-07-26 20:32:06 +02:00
José Valim
bd1006d321 Add the possibility to skip OAuth authentication by returning nil from the finder method. 2010-07-26 20:32:06 +02:00
José Valim
17ec0c08ed Expire all /_oauth_token$/ keys in session after sign in, so if two users create accounts in the same session, the facebook account will be linked just to the first one. 2010-07-26 20:32:06 +02:00
José Valim
b31d60ce7c Implement error handling for OAuth. 2010-07-26 20:32:05 +02:00
José Valim
b87dc84079 Add oauth links to default template. 2010-07-26 20:32:05 +02:00
José Valim
0aa41d6388 Tidy up lose ends. 2010-07-26 20:32:05 +02:00
José Valim
8bf6a66e05 Make Devise::Oauth follow the same conventions as Devise::controllers. 2010-07-26 20:32:05 +02:00
José Valim
3ba424774e Remove deprecated code. 2010-07-26 20:32:05 +02:00
José Valim
1a9db03b22 Do not rely on load time anymore. Instead, provide a helper that is called whenever a mapping is given. 2010-07-26 20:32:05 +02:00
José Valim
faf771c798 Add OAuth url helpers. 2010-07-26 20:32:04 +02:00
José Valim
bd8294aecf More OAuth setup. 2010-07-26 20:32:04 +02:00
José Valim
6c5be8dfd5 Initial routes and module setup. 2010-07-26 20:32:04 +02:00
José Valim
9ab64c53f4 Release 1.1.0. 2010-07-26 20:25:28 +02:00
José Valim
c5999c8f61 Tests green on mongoid as well. 2010-07-26 20:25:02 +02:00
José Valim
680f2612f4 Update CHANGELOG. 2010-07-26 11:52:05 +02:00
José Valim
81620fecab More about extend remember period feature. 2010-07-23 23:57:31 +02:00
Trevor Turk
2939a61a49 documentation tweaks for extend_remember_period 2010-07-24 01:06:10 +08:00
José Valim
058d433f28 Add extend_remember_period, closes #340. 2010-07-23 16:32:22 +02:00
Stefan Huber
5aeb8cf1cf small documentation fix 2010-07-23 01:33:08 +08:00
José Valim
abfd7e5a4b Warn in case you are using the previous session schema, closes #386 2010-07-19 00:11:51 +02:00
José Valim
869c658e3b Always loop before generating a token. 2010-07-18 23:32:56 +02:00
José Valim
5e64699a5f Add filters as convenient default. 2010-07-18 12:17:04 +02:00
Jinzhu
aecc014d33 Attributes for devise generator 2010-07-17 15:09:01 +08:00
José Valim
55fd7e3b0a Consider ApplicationController url_options in for PathChecker. 2010-07-16 08:40:21 +02:00
José Valim
b4794e041b Save confirmation token to the database, if one does not exist but was requested, closes #377 2010-07-14 18:03:34 +02:00
Carlos Antonio da Silva
4f6113ab68 Fix docs about after_sign_in_path_for and routes 2010-07-13 22:22:26 -03:00
José Valim
05d23f1a00 Do not check the constant, otherwise class renaming will trigger errors as well. 2010-07-12 10:42:02 +02:00
José Valim
e567c00dd8 Store classes as string in session, to avoid serialization and stale data issues, closes #356 2010-07-12 07:48:19 +02:00
José Valim
ebe3e791d6 Email should be case insensitive, closes #372 2010-07-12 07:29:45 +02:00
José Valim
2602ef41cf Do not add unlock routes unless unlock strategy is email or both, closes #373 2010-07-12 07:24:21 +02:00
José Valim
a87bc4a861 Also pass stretches to salt generation. 2010-07-12 06:59:49 +02:00
José Valim
eca511a8f2 Use confirmed_at as flag. 2010-07-08 08:21:14 +02:00
José Valim
9c5ff02ff1 Update CHANGELOG and tidy up tests. 2010-07-07 21:32:13 +02:00
James Pellow
9f29ca480b Add http_authenticatable_on_xhr option
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-07-07 21:26:29 +02:00
James Pellow
b9df42c350 Add tests for http_authenticatable_on_xhr option 2010-07-08 03:21:13 +08:00
José Valim
bd0e2a3180 devise_for now accepts a block. All routes inside the block uses the scope defined by devise_for.
You are now allowed to do:

  devise_for :users do
    # Non conventional sign_in route
    get "/sign_in" => "devise/sessions#new"
  end

And it should work as expected.
2010-07-07 10:51:14 +02:00
José Valim
750560ae87 Ensure method is always POST on new.html.erb forms, closes #365. Also, start to remove usage of assert_template. 2010-07-06 16:01:22 +02:00
José Valim
e2a4ebce4a Consider script name in PathChecker. 2010-07-06 16:01:22 +02:00
Carlos Antonio da Silva
77b7692b57 Regenerate devise initializar and get rid of some deprecation warnings from Devise and Rails. 2010-07-06 08:40:32 -03:00
José Valim
ae6322efb5 No longer retrieve the user from paths, but use the env hash. This change deprecates use_default_scope.
If you have non conventional routes and want to specify the scope for a controller, you can do that at the router level:

  as :user do
    get "/sign_in", :to => "devise/session#new"
  end

This is saying: when accessing "/sign_in", devise should use the user scope. Meaning that users signed through that form will be signed to the user scope.
2010-07-06 01:33:32 +02:00
Carlos Antonio da Silva
238226e33a Adding a small note about security and issues 2010-07-05 14:26:58 -03:00
José Valim
96a9c88420 Improve docs on finders after taking a look at the wiki. 2010-07-05 19:11:37 +02:00
José Valim
dd612753f9 Extract redirect_url from failure app to its own method. 2010-07-05 15:22:44 +02:00
José Valim
35923c9c69 Move template_paths to its own module. 2010-07-05 13:27:15 +02:00
José Valim
f54013a181 Do not hardcode to devise/mailer in order to allow inheritance to work. 2010-07-05 10:05:08 +02:00
José Valim
1cf77028c1 Bump version to 1.1.0 but do not release yet. We are only using this as flag for those using Devise as git with bundler due to the latest changes. 2010-07-04 17:34:33 +02:00
José Valim
7774accb6c Remove data_mapper support.
Devise 1.1.0 will be released soon. This new version will support activerecord and mongoid as default ORMs. From now on, Devise will prefer ORM extensions as gems since this is the best way to handle dependencies.

For example, to allow Devise to work with Datamapper, it requires at least activemodel, dm-rails and dm-timestamps. If the ORM support comes from Devise gem, we cannot add dm-rails and dm-timestamps as dependencies, relying on the developer and documentation to find these out and install them.

Other ORMs may still be added to Devise, as long as they are supported by the community, extend Devise test suite to have all tests passing and they necessarily use ActiveModel::Validations.
2010-07-04 17:22:57 +02:00
José Valim
6c49b428b3 Add flexibility to devise generators by using ORM hooks. 2010-07-04 17:15:24 +02:00
José Valim
7113dfe93a Ensure to convert template engine to string to properly match haml, closes #359 2010-07-04 13:13:00 +02:00
José Valim
4083d679d4 Add documentation to the new :module method. 2010-07-04 13:11:04 +02:00
José Valim
7a1adbb61e Improve integration of devise with new router scope. 2010-07-04 11:53:12 +02:00
José Valim
18cccae82f Update bundler, Rails and improve tests for previous commit. 2010-07-02 08:12:00 +02:00
klacointe
e9fbb3d7ef fix AbstractController::ActionNotFound when use
route with specific format (ie xml, json...)
2010-07-02 13:25:33 +08:00
José Valim
04c25539c2 Add remember_me to attr_accessible on generation. 2010-07-01 12:38:48 -07:00
José Valim
55bc0ace5a Update CHANGELOG. 2010-07-01 13:58:08 +02:00
José Valim
421256d294 Devise should respect script_name and path_info contracts. This closes #331, a long standing bug with Passenger. 2010-07-01 13:50:05 +02:00
José Valim
8e3ef2a620 Add entry to CHANGELOG. 2010-06-30 12:49:41 +02:00
Trevor Turk
aefcd53765 more tests for remember_across_browsers
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-06-30 12:42:59 +02:00
Trevor Turk
0eb9208503 changelog note for remember_across_browsers
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-06-30 12:42:49 +02:00
Trevor Turk
8824b767f3 remember_across_browsers option for rememberable module
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-06-30 12:42:42 +02:00
José Valim
2103a673f0 Allow devise_for to be scoped with the scope method. This commit requires latest commits in Rails master. 2010-06-30 12:41:44 +02:00
José Valim
78e7642bd2 Tests green again. 2010-06-29 21:41:34 +02:00
José Valim
8526056bde Merge branch 'master' of github.com:plataformatec/devise 2010-06-29 12:02:06 +02:00
José Valim
4b272767d6 Fix a bug in Devise::TestHelpers where current_user was returning a Response object for non active accounts, closes #341. 2010-06-29 11:52:10 +02:00
José Valim
84c34ff0c4 Be more specific about master. 2010-06-28 12:25:03 -07:00
Maxim Filatov
4db3ac820b sign_out_all_scopes is false by default 2010-06-25 02:29:52 +08:00
Maxim Filatov
503d27f2e1 Renew devise:install due to sign_out_everybody => sign_out_all_scopes 2010-06-25 02:29:50 +08:00
Denis Lifanov
2475faf9c7 warden.logout(*scopes) instead of warden.logout(*Devise.mappings.keys) 2010-06-25 02:29:49 +08:00
Denis Lifanov
819db39263 simplification (sign_out_everybody => sign_out_all_scopes) 2010-06-25 02:29:48 +08:00
Maxim Filatov
f864259f1e Added config.sign_out_scoped to devise:install 2010-06-25 02:29:47 +08:00
Maxim Filatov
12ae21117c Missed rdoc 2010-06-25 02:29:46 +08:00
Denis Lifanov
1a224c7486 move sign_out_scoped logic to the Devise::SessionsController#destroy 2010-06-25 02:29:45 +08:00
Denis Lifanov
f10b747f7f Devise.sign_out_scoped option added 2010-06-25 02:29:43 +08:00
Denis Lifanov
8370006591 we should not fetch Devise.mappings.keys twice in #sign_out_everybody 2010-06-25 02:29:42 +08:00
Denis Lifanov
1924a915a8 sign_out_everybody helper (as a convenient proxy to warden) 2010-06-25 02:29:41 +08:00
José Valim
7a45043bc8 Be more friendly if the user goes ahead and adds devise_for :users before defining the model. 2010-06-24 16:51:30 +02:00
Rob Holland
ad63e25c89 config.load_paths is now config.autoload_paths 2010-06-24 19:28:34 +08:00
José Valim
895a7a4951 Use Rails master. 2010-06-23 12:52:44 +02:00
José Valim
b8c2bbe73c Revert "Revert "Track Deprecation of :name_prefix in Rails 3 RC""
Devise master will now follow Rails master.

This reverts commit b2c2cb272f.
2010-06-23 12:42:23 +02:00
José Valim
b76bf10203 Update README. 2010-06-23 12:42:13 +02:00
José Valim
748eced9e8 Release RC2 (for Rails 3.0.0.beta4) 2010-06-23 12:39:04 +02:00
José Valim
a39312e26b Ensure flash messages work with Devise::TestHelper, closes #327 2010-06-23 12:39:04 +02:00
José Valim
b2c2cb272f Revert "Track Deprecation of :name_prefix in Rails 3 RC"
Let's wait until a new Rails 3 release is out before applying this to maintain compatibility with Rails 3 beta 4.

This reverts commit 21874d8559.
2010-06-23 12:39:04 +02:00
José Valim
fccde42f20 Do not show model exist message on revoke behavior, closes #334 2010-06-23 12:39:04 +02:00
Jared Morgan
e90732c8c3 Remove #save! method from test DM User model
DM has a #save! method, so it's no longer needed. Having it call #save
caused #valid? to be called where tests were expecting validations to be
skipped.
2010-06-23 18:38:39 +08:00
bodhi
21874d8559 Track Deprecation of :name_prefix in Rails 3 RC 2010-06-23 14:56:01 +08:00
José Valim
cfadaf80a2 Merge with jm81 and snusnu datamapper forks. 2010-06-22 21:01:37 +02:00
José Valim
df444663ac Bring datamapper Gemfile back. 2010-06-22 21:00:46 +02:00
Jared Morgan
5b63605c94 Add dm-serializer to Gemfile so DM models respond to #to_xml
Fixes 3 Missing template errors
2010-06-22 11:00:36 -05:00
José Valim
3660cbac30 Do not execute after initializers if production. 2010-06-21 14:07:58 +02:00
José Valim
92cf50454b Add Rails 3 + Mongoid example to the README. 2010-06-20 01:29:53 -07:00
Postmodern
29ba790e07 Do not use ActiveRecord only methods in tests. 2010-06-19 17:30:10 -07:00
snusnu
4e2cd157c1 Specs surely don't pass, but they run at least! 2010-06-19 17:30:10 -07:00
snusnu
194959f312 Updated Gemfile to include DataMapper-1.0.0 (from git for now) 2010-06-19 17:30:10 -07:00
José Valim
e3b815de49 Bring encrypted password limit back. 2010-06-18 22:00:31 +02:00
José Valim
ac0105d15f No need to limit password. 2010-06-17 00:36:09 -07:00
Carlos Antonio da Silva
7dbd2eac2a Confirmable is not default anymore, so remove it from generated migration. 2010-06-17 01:57:42 -03:00
José Valim
025c3875b6 Update gemspec, closes #316. 2010-06-13 21:48:43 +02:00
José Valim
f1a990c2ae Do not show messages if eager loading to call help. 2010-06-13 13:34:49 +02:00
José Valim
1f4a31f1cf Update generators to use Rails 3 syntax, i.e devise:install instead of devise_install. 2010-06-13 13:10:33 +02:00
José Valim
31910b85a2 Regenerate .gemspec 2010-06-13 12:40:40 +02:00
José Valim
5e1ef9319e Check if the user is already signing out before timing out his connection, closes #273. 2010-06-13 12:40:13 +02:00
José Valim
70a429d9ff Split tests files a bit. 2010-06-13 12:11:15 +02:00
José Valim
f16d01869a Rename apply_schema to apply_devise_schema and refactor Mongoid part a bit. 2010-06-13 11:48:45 +02:00
José Valim
290cfd1f72 Be more generic on TestHelpers. 2010-06-13 11:09:59 +02:00
José Valim
ed22295963 Fix a couple things based on community feedback (love ya!) 2010-06-13 10:51:46 +02:00
José Valim
a2f84852af Allow the mailer class to be configured. 2010-06-12 20:56:55 +02:00
José Valim
c4a4032b6b Use ActiveSupport::Dependencies.ref to abstract constant lookup logic. 2010-06-12 20:48:37 +02:00
José Valim
80895c3b9a Make I18n key for mailer compatible with lookup shortcuts, closes #245 2010-06-12 20:29:43 +02:00
José Valim
84686d285c Be more clear that Rails 2.3 users should use the v1.0 branch README. 2010-06-12 06:56:15 -07:00
José Valim
6c18c92598 Update gemspec. 2010-06-12 15:30:43 +02:00
José Valim
0333caeb92 Make bcrypt the default encryptor and automatically add a pepper on generation. 2010-06-12 14:46:55 +02:00
José Valim
bece09c653 Comment out datamapper scenario because it simply does not work currently. 2010-06-12 13:30:55 +02:00
SSDany
cd78a26f88 add #anybody_signed_in? to helpers 2010-06-12 05:11:04 +08:00
SSDany
5c9fe5e769 anybody_signed_in? helper 2010-06-12 05:11:03 +08:00
José Valim
fb0aec09f1 Talk about beta 4 in the README. 2010-06-11 09:10:36 -07:00
José Valim
5f2a19d784 Also need a klass reader. 2010-06-09 02:50:45 -07:00
José Valim
cc608f82dd Properly check if devise method is present. 2010-06-09 02:50:28 -07:00
José Valim
7e784b258c Update Devise generator error message. 2010-06-09 02:41:30 -07:00
José Valim
870912d458 beta 4 works, yay. 2010-06-09 01:27:38 +02:00
Lloyd Pick
f0c0f5f11b fixed a few spelling/grammar mistakes 2010-05-28 20:24:39 +08:00
Antonio Tapiador del Dujo
7dc1842cc4 Add note about default routes in devise configuration 2010-05-25 18:58:20 +08:00
José Valim
28b10e397f Update CHANGELOG 2010-05-25 00:03:03 +02:00
Alexander Uvarov
6ff77c9fdf Add merb-auth like router helper 2010-05-25 05:51:32 +08:00
José Valim
d98882d745 Tidy up previous commit. 2010-05-24 22:50:25 +02:00
Joseph DelCioppio
80977c6dee Added after_update_path to registrations controller. Users can now specify the path that their app should return to after updated a resource. If not specified it will return to the root, or the resource's root if specified. 2010-05-25 04:25:32 +08:00
José Valim
7c82d3ee67 Move the generator bit to the top. 2010-05-21 07:42:34 -07:00
José Valim
0150fddb4c Depends on warden 0.10.5. 2010-05-20 01:24:11 +02:00
bodhi
c8ec42a41c Update documentation to track deprecation of :as in #devise_for 2010-05-19 15:50:48 +08:00
José Valim
bff64a6291 Added navigational formats to specify when it should return a 302 and when a 401, closes #234 and #249. 2010-05-16 19:13:38 +02:00
José Valim
a65fd873dd Update CHANGELOG 2010-05-16 14:55:35 +02:00
Paul Rosania
592fa59e88 Automatically create the confirmation_token when email is sent for optionally confirmable models
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-05-16 14:54:05 +02:00
Paul Rosania
02c2df65cd Mark confirmable roles as active when confirmation_required? is false
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-05-16 14:53:08 +02:00
José Valim
59bee679ca Add tests to cookie domain, closes #254. 2010-05-16 14:13:56 +02:00
Mantas Masalskis
21129ae38c custom domain cookie support
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-05-16 12:30:00 +02:00
José Valim
f1bbce58f3 Add tests to previous commit. 2010-05-16 12:14:02 +02:00
Davide Marquês
8e173f486c Enable :registration in the :path_names configuration option.
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-05-16 12:00:43 +02:00
José Valim
e905762611 Clean up the whole loading mess and closes #247. This commit depends on latest Rails. 2010-05-16 00:38:40 +02:00
José Valim
d38421dde8 Green tests on Rails master, closes #261 2010-05-15 10:39:11 +02:00
José Valim
6162e1f5ff Devise install now accepts --orm option. 2010-05-15 10:28:29 +02:00
José Valim
08c5179869 Update registerable on readme. 2010-05-11 02:37:46 -07:00
José Valim
bb39243da2 data_mapper uses underscore (ht: Yehuda Katz) 2010-05-05 02:28:40 -07:00
José Valim
9bdc711324 Update README. 2010-05-03 14:00:32 +02:00
José Valim
a4351b0b77 Update master CHANGELOG. 2010-05-03 13:57:57 +02:00
José Valim
416bff3daa Merge branch 'master' of github.com:plataformatec/devise 2010-05-03 00:12:58 +02:00
José Valim
07204c500d Confirmable is not default anymore. This provides a better bootstrap experience. 2010-05-03 00:08:48 +02:00
gitman
f5bc66521f patch-244 for improving commented help for :confirmable configuration
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-05-03 00:06:16 +02:00
Britto
fb0f8fcd0d typo 2010-04-29 05:45:44 +08:00
José Valim
61fbec858e Add a missing TODO 2010-04-26 07:34:06 -07:00
José Valim
25302de1f8 Add a link to the second screencast to the README. 2010-04-25 10:02:51 +02:00
José Valim
b86c1c241b Use markup in views as Ryan Bates does in the screencast. 2010-04-25 10:02:11 +02:00
José Valim
2bf9e462fa Update CHANGELOG. 2010-04-25 09:59:10 +02:00
Jacques Crocker
57712737b2 Fixing up devise generator for mongoid and datamapper. Will insert devise configuration after the module include so that it works, closes #226.
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-04-25 09:47:14 +02:00
Ryan Booker
c582e9cb0f Fix grammar in notice, closes #229
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-04-25 09:44:04 +02:00
José Valim
d750b48879 Include model_session helpers in view, closes #227 2010-04-25 09:40:07 +02:00
José Valim
708fe78d86 Ensure password confirmation is always required, closes #228 2010-04-25 09:38:56 +02:00
José Valim
41311eb38d Move mailer configuration to the app. 2010-04-25 09:26:51 +02:00
José Valim
da971e4249 .bundle directory should NOT be ignored. 2010-04-23 13:51:10 +02:00
hpoydar
eb23ca0ca7 Include bson_ext in Gemfile
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-04-23 13:50:49 +02:00
hpoydar
c9fe7900c3 Removed references to mongo_ext, since mongoid now uses bson_ext
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-04-23 13:50:41 +02:00
José Valim
9d6a78f7f4 Add ldap_authenticatable to README. 2010-04-22 20:55:27 +02:00
José Valim
4da63c5395 Ensure routes are loaded before application classes are eager loaded, closes #212. 2010-04-22 19:59:52 +02:00
José Valim
b5f892bcdb No need to check if AR is defined. 2010-04-20 17:22:16 +02:00
José Valim
3135487931 More more logic to Authenticatable. 2010-04-16 22:00:06 +02:00
José Valim
9291ab55b8 Fix compatibility with Mongoid and Datamapper, closes #206. 2010-04-15 21:39:56 +02:00
José Valim
1db86a0810 More information about ecosystem in the README. 2010-04-15 21:20:00 +02:00
José Valim
fb832e6ffe Replace devise_for :admin by devise_for :admins. 2010-04-15 11:31:13 -07:00
José Valim
ca6248cfd3 Release devise 1.1.rc1. 2010-04-15 08:45:33 +02:00
José Valim
b9c0676a01 Get rid of deprecation warnings. 2010-04-15 08:43:39 +02:00
José Valim
731f156f50 Do not show unlock link unless strategy is e-mail. Closes #204. 2010-04-15 08:40:15 +02:00
José Valim
b2a50db1df Fix a bug with STI. Closes #195. 2010-04-15 08:34:57 +02:00
José Valim
6bd0c7fc2b :as and :scope in routes is deprecated. Use :path and :singular instead. Closes #199. 2010-04-15 08:21:13 +02:00
José Valim
4e674ab9a0 No need to wait for routes finalization to include UrlHelpers, closes #200. 2010-04-14 08:59:09 +02:00
José Valim
cbfeb59fb3 Regerate gemspec. 2010-04-13 23:44:25 +02:00
José Valim
8db559148c All tests green on latest Rails beta. 2010-04-13 23:28:13 +02:00
José Valim
7403c9f80e Fix a mailer bug in Rails 3. 2010-04-13 23:11:12 +02:00
José Valim
f3d654a733 :activatable is added by default. 2010-04-13 13:35:34 -07:00
José Valim
bafc859f75 Fix small typo in the README. 2010-04-12 10:31:22 -07:00
José Valim
bf63824aae Improve wording in the README. 2010-04-12 04:48:22 -07:00
José Valim
32d37cebed Properly use scope in views generator. 2010-04-12 04:39:16 -07:00
José Valim
d2ebaa43ec Be more helpful in the sign up message for new comers. 2010-04-09 23:13:34 +02:00
José Valim
045af3a614 Change README shown in devise_install. 2010-04-09 09:50:45 -07:00
José Valim
a96fdcf0bd Change authenticatable to database_authenticatable in README. 2010-04-07 22:24:00 -07:00
José Valim
fd934f1434 Revert "Only triggers http in failure app if devise.authentication_method is :http."
It has not fixed the problem it was supposed to fix.
This reverts commit 9d1a52978c.
2010-04-06 22:36:41 +02:00
José Valim
b2fe7e49fd Kill .bundle dir 2010-04-06 17:56:41 +02:00
José Valim
22392f23f2 Authenticatable shuold be loaded at the end. 2010-04-06 17:27:49 +02:00
José Valim
3ce98d4163 Regenerate gemspec. 2010-04-06 16:56:14 +02:00
José Valim
c07b5ae858 :activatable is included by default in your models. If you are building a strategy for devise, you now need to call validate(resource), since Devise has now a default API to validate resources before and after signing them in. You can still use other Warden::Strategies with Devise, but they won't work with a few modules like unlockable (they never did, but now we have a single point to make it work). 2010-04-06 16:34:22 +02:00
José Valim
dbe116c255 Add more info to README. 2010-04-06 13:43:38 +02:00
José Valim
9d1a52978c Only triggers http in failure app if devise.authentication_method is :http. 2010-04-06 13:40:39 +02:00
José Valim
0d3c6b9d99 Small changes to token_authenticatable. 2010-04-06 13:26:56 +02:00
Andre Medeiros
71f74a10f7 Solved deprecation warnings
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-04-06 12:06:42 +02:00
José Valim
0bd75469ba Update README. 2010-04-05 12:21:02 +02:00
José Valim
1591294b7a Compatibility with Rails beta 3. 2010-04-05 11:46:26 +02:00
José Valim
f9cbd3c457 Add 1.0.6 entries to master changelog 2010-04-03 13:27:17 +02:00
José Valim
66ca9f5ce0 Update README to point to the RC0 gem. 2010-04-03 13:22:14 +02:00
José Valim
d3c31ef16d Releasing 1.1.rc0 which is compatible with Rails 3.0.0.beta2. There is just one known bug with this new Rails version, which means we are close to a final Devise 'Rock Your Socks Off 1.1' version. 2010-04-03 13:20:00 +02:00
José Valim
b974b7bc78 Move failure messages from devise.sessions to devise.failure. 2010-04-03 13:11:45 +02:00
José Valim
23e608e27b No need to append ?unauthenticated=true in URLs anymore since Flash was moved to a middleware in Rails 3. 2010-04-03 11:43:31 +02:00
José Valim
0f7b311171 Add lockable to migration. 2010-04-02 20:36:27 +02:00
postmodern
27c4280eca Expend the length of the encrypted_password field to 128 to allow storing BCrypt or SHA512 passwords.
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-04-02 20:31:33 +02:00
José Valim
1ba525a0e9 Tidying up some lose ends and adding more docs. 2010-04-01 22:11:59 +02:00
José Valim
d8b6ba9022 Bump warden to 0.10.3 2010-04-01 19:24:22 +02:00
José Valim
f5d01c217d TokenAuthenticatable now works with HTTP Basic Auth by default (take a look at Highrise API for a good example). This basically allows you to pass the authentication token as HTTP Basic Auth username. 2010-04-01 19:09:33 +02:00
José Valim
2b5a068246 Move part of the logic in SessionsController#create to the FailureApp. Whenever Warden is invoked with a :recall, the failure app will recall the chosen controller and the action given to recall. 2010-04-01 17:30:55 +02:00
José Valim
13b8ddf54c Ensure customs pass through sessions_controller. 2010-04-01 14:00:21 +02:00
José Valim
16666b7587 Get rid of flash hook and clean up passwords after registration. 2010-04-01 13:23:49 +02:00
José Valim
dac7887d7c Allow the dummy application in test/rails_app to boot. 2010-04-01 12:49:11 +02:00
Fred Wu
42d06a241b Added support for HAML 3+.
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-04-01 00:14:16 +02:00
José Valim
3d1a04fd83 Fix warden configuration. 2010-03-31 22:04:48 +02:00
José Valim
1d65a76cf3 Move remember_me hook inside strategies. 2010-03-31 21:43:19 +02:00
José Valim
015c74e734 Use message verifier in cookies. Previous implementation allowed brute force attacks by cookies. Even though it is impossible for the brute force attack to succeed, the current implementation blocks the attacker even before hitting the database. 2010-03-31 13:31:45 +02:00
José Valim
6cc32db2dd Add lock_strategy. 2010-03-31 11:54:11 +02:00
José Valim
597a930c74 We do not use t() helpers in views, so there is no reason why this particular one should use them. 2010-03-30 20:06:56 +02:00
José Valim
d7f614b726 Make config.devise available on config/application.rb 2010-03-30 11:08:16 +02:00
José Valim
e04c5ba977 More work with unlock_strategy equals to none. 2010-03-30 01:58:06 +02:00
José Valim
4fc41dd68a Regenerate gemspec. 2010-03-30 01:50:54 +02:00
José Valim
22e1fa0cb9 Small cleanup. 2010-03-30 00:29:57 +02:00
Josh Kalderimis
a6a018253e minor change to content type checking to make it more flexible when utf8 is returned
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-03-30 00:23:46 +02:00
José Valim
81926c2cd2 Allow :unlock_strategy to be :none. 2010-03-30 00:07:11 +02:00
José Valim
7d14f0bbb9 Allow several authentications to share a common path. 2010-03-29 23:44:47 +02:00
José Valim
e038d82410 Merge branch 'master' of github.com:plataformatec/devise 2010-03-29 21:02:56 +02:00
José Valim
65b8908960 Create authenticatable base model and strategy. 2010-03-29 20:52:48 +02:00
José Valim
1c5d4771ff Initial work on making the authentication stack more flexible. 2010-03-29 16:13:19 +02:00
José Valim
604b7ef61c Move http authenticatable response to failure app. 2010-03-29 15:16:14 +02:00
José Valim
0d704c02ca Fix link on README. 2010-03-29 00:53:51 -07:00
Jacques Crocker
1c39590e20 Devise / DataMapper updates
allows devise to work with the upcoming dm-validation changes
2010-03-28 20:53:22 -07:00
Jacques Crocker
6d31e368bf Use persisted? instead of new_record?
In order to be more ActiveModel compliant, lets use persisted? whereever we can. Particularly for datamapper, new_record? causes api warnings. Better to stick to the ActiveModel api I think.
2010-03-28 20:53:13 -07:00
José Valim
63deb0e80a Update CHANGELOG. 2010-03-28 23:15:45 +02:00
José Valim
2a082f3e4c Fix some unlockable bugs. 2010-03-28 23:09:28 +02:00
Josh Kalderimis
97b7ba8659 added imapable to the README
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-03-28 22:02:38 +02:00
José Valim
bc00a13a3a Update gemspec. 2010-03-28 15:24:21 +02:00
José Valim
033db1ca7c Do not depend on silence_missing_strategies! anymore. This speeds up strategies matching because we don't need to check if the model duck types to the strategy and it doesn't trigger uneeded strategies. 2010-03-28 14:55:05 +02:00
José Valim
066c6e8771 Do not force halt on authenticatable. This allows other strategies (like devise_imapable or even devise_facebook_connectable) to hook into sessions controller as well.
Those strategies should follow the same convention, allowing them to be cascated.
2010-03-28 12:52:12 +02:00
José Valim
96c8238b02 Remove duplicated method. 2010-03-28 07:24:56 +02:00
José Valim
4b7a9204b8 More configuration to validatable. 2010-03-28 07:19:23 +02:00
José Valim
ea71be8d2a More compatibility with Rails master. 2010-03-28 07:15:52 +02:00
Jacques Crocker
6bcf18b04f Mongoid support cleanup
moving test specific == override part of the test models and not part of the Compatibility module included in all Mongoid docs. Made sure that nothing in devise itself uses this == between 2 different models, its purely for assert_equal
2010-03-27 16:16:36 -07:00
Jacques Crocker
bb504e08aa Initial Datamapper test suite
Test suite runs, however there's still some failing tests. This allows us to at least have a working test suite so they can fix these datamapper spec failures individually.
2010-03-27 16:15:23 -07:00
Jacques Crocker
afe6a8c8c8 Merge branch 'master' of git://github.com/plataformatec/devise 2010-03-27 16:10:30 -07:00
José Valim
a53cc74fd9 Revert "Move password_required? to authenticatable. This allow you to reuse it when building your own validations."
This reverts commit 386e7be823.
2010-03-27 12:31:38 +01:00
Jacques Crocker
fd035b841b Additional configuration for validatable
Added the ability to customize password length (via Devise.password_length) and the regular expression used for validating email (via Devise.email_regex)
2010-03-26 13:52:12 -07:00
Jacques Crocker
e127463ac8 Adding Mongoid 2.0 Support, Removing MongoMapper for now 2010-03-26 13:37:38 -07:00
José Valim
bd4b29c0fd sign_in_count shoud default to zero. 2010-03-26 12:56:24 +01:00
Carlos Antonio da Silva
6f41284714 Merge branch 'master' of github.com:plataformatec/devise 2010-03-26 08:44:42 -03:00
Carlos Antonio da Silva
a5ba2ac1a8 Use prepend_before_filter in require_no_authentication.
We need to be sure require_no_authentication runs before other user filters that may call some Devise helper (ie current_xxx).

Conflicts:

	app/controllers/devise/passwords_controller.rb
	app/controllers/devise/registrations_controller.rb
	app/controllers/devise/sessions_controller.rb
	app/controllers/devise/unlocks_controller.rb
	lib/devise/controllers/internal_helpers.rb
	test/rails_app/app/controllers/application_controller.rb
2010-03-26 08:26:51 -03:00
José Valim
386e7be823 Move password_required? to authenticatable. This allow you to reuse it when building your own validations. 2010-03-26 12:19:01 +01:00
José Valim
ca4e09390e Compatibility with Ruby 1.9.1 and 1.9.2. 2010-03-26 11:27:19 +01:00
Andreas Haller
5c19605d6f Fixed test: calling Mail::Body#encoded to get a String (Rails 3)
From Rails' CHANGELOG
… Mail.body returns a Mail::Body class object, need to call #encoded or #decoded to get the string you want.

Signed-off-by: José Valim <jose.valim@gmail.com>
2010-03-26 11:00:46 +01:00
José Valim
e136573905 Improve workflow with devise generator. 2010-03-26 10:36:15 +01:00
José Valim
ae729aedc3 Allow devise to work with association proxies. 2010-03-26 10:19:31 +01:00
José Valim
12b64c691f Add support to multipart e-mails (just put them in your mailers folder) and headers customization by simply defining headers_for in your model. 2010-03-26 10:01:24 +01:00
Josh Kalderimis
4d3a3ceb43 added test to confirm order in ALL is being adhered to when adding and including module in model
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-03-26 09:31:25 +01:00
José Valim
c76df8239f Require no authentication on unlockable. 2010-03-23 17:56:32 +01:00
José Valim
28a6be456a Require files before monkey patching them. 2010-03-23 16:28:17 +01:00
José Valim
76e45ecb12 Bring unloadable back. 2010-03-23 00:39:27 +01:00
José Valim
8fbbe34bdd Fix routes generation on Rails master. 2010-03-16 14:48:30 +01:00
José Valim
3a84fd4f3f Ensure devise_views is always executed. 2010-03-16 02:51:59 +01:00
José Valim
37bb6948a2 Update README to tell about Rails edge and Devise edge. 2010-03-15 03:21:12 -07:00
Ørjan Blom
f129b9ffd7 don't use a static name in a public directory, and delete after use.
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-03-14 15:02:54 +01:00
Fred Wu
6ce33b7b57 Updated the gem dependencies.
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-03-14 11:22:26 +01:00
José Valim
185541b9e4 Use template engine as option since it's the one used by rails. 2010-03-14 09:39:59 +01:00
Ørjan Blom
e81d428d53 update gem dependencies
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-03-14 09:28:13 +01:00
Fred Wu
de92be39f2 Use Ruby's tmp directory instead of a ghost directory inside the devise gem folder.
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-03-14 09:25:57 +01:00
Fred Wu
3f85fa88c3 Use 'rescue' to ensure the presence of Haml.
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-03-14 09:25:52 +01:00
Fred Wu
2ebbc30540 Made sure no deprecated HAML templates (in case any) will get copied over.
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-03-14 09:25:45 +01:00
Fred Wu
b8091928a0 A more user friendly way of checking the existence of Haml.
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-03-14 09:25:39 +01:00
Fred Wu
cbd35a846a Added verification for HAML >= 2.3.
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-03-14 09:25:31 +01:00
Fred Wu
90e8253205 Added HAML as a template engine option to devise_views generator (-t or --engine). HAML files are created based on the erb files on the fly using 'html2haml' command that comes with HAML.
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-03-14 09:25:19 +01:00
José Valim
3f0bae1968 Allow to give :skip in devise_for to skip routes for an specific controller. 2010-03-12 09:54:57 +01:00
José Valim
59b26d8427 All tests pass using Rails master. 2010-03-11 18:39:32 +01:00
José Valim
cbc3747039 No need to check if app.routes.url_helpers exists. I.e. Devise master now *requires* Rails master (aka beta1). 2010-03-10 08:59:22 -07:00
José Valim
ed3a460bad Allow to give a scope when copying views. 2010-03-10 16:53:09 +01:00
José Valim
ac742e3271 Clean up lockable and class methods API. 2010-03-10 16:13:54 +01:00
Fred Wu
cd17099401 Create the devise_views directory in './app/views' instead of the root.
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-03-10 15:29:30 +01:00
José Valim
829c85631b Aim for Rails 3.0.0.beta1 compatibility. A few issues are still pending with Warden. 2010-03-10 15:00:12 +01:00
Ørjan Blom
1a740774e3 use Devise.encryptor setting when creating the migration
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-03-09 10:38:39 +01:00
Philip MacIver
bb9f594cc8 Changed the datamapper orm so that the default value is only deleted when it is nill, this is so that is a value is set to another value except nil by default through devise, that value will be maintained in datamapper
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-03-06 18:14:37 +01:00
Philip MacIver
d64e146ec9 Modified the datamapper orm so that it actually works with devise
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-03-06 16:18:53 +01:00
Philip MacIver
0a0d7ba577 Typo in the datamapper orm stopped it from being loaded properly
Signed-off-by: Carlos Antonio da Silva <carlosantoniodasilva@gmail.com>
2010-03-04 20:44:09 -03:00
José Valim
288b92d2be Update CHANGELOG. 2010-03-03 12:25:28 +01:00
José Valim
1d4f4c19c9 Release pre4 with improved controller handling. 2010-03-03 12:22:04 +01:00
José Valim
901c6ae4df Always get a new object on edit, update and delete. 2010-03-03 12:12:06 +01:00
José Valim
0e64bc74b7 Move trackabe logic to the model. 2010-03-03 12:03:43 +01:00
José Valim
038627574c Keep modules definition in a different file. 2010-03-03 12:03:43 +01:00
José Valim
af39afcdf8 More refactoring. 2010-03-03 12:03:43 +01:00
José Valim
1660831002 Give more flexibility when swapping controllers. 2010-03-03 12:03:42 +01:00
Carlos Antonio da Silva
03e11e4a18 We also have sign up as a valid path name for routes 2010-02-27 09:35:26 -03:00
José Valim
20ca0dc981 Add info about devise_facebook_connectable. 2010-02-27 09:13:42 +01:00
Daniel Kehoe
5c59f4cd1b Fixes to syntax, diction and spelling in README. 2010-02-27 16:04:38 +08:00
Daniel Kehoe
5bc741cdab Add a section 'Examples' to the README mentioning plataformatec/devise_example and fortuity/subdomain-authentication 2010-02-27 16:04:37 +08:00
Daniel Kehoe
cfb3305ae5 Add a section 'Related Applications' to the README with a mention of devise_invitable 2010-02-27 16:04:37 +08:00
Lucas Uyezu
8525b56318 SQLite requries a default value when the column is NOT NULL
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-02-25 08:33:38 +01:00
José Valim
bcb46bbccb Do not forget frozen records. 2010-02-25 08:00:10 +01:00
José Valim
484361e815 Improve error message on undefined method devise. 2010-02-25 07:54:06 +01:00
José Valim
94511c1a43 Bump to 1.1.pre3 2010-02-24 22:19:46 +01:00
Andrei Bocan
c914c143bc Fix typo in route description 2010-02-24 18:22:43 +08:00
José Valim
e03e137c35 Update warden which fixes a security issue. 2010-02-23 19:47:45 +01:00
snusnu
a12ca2955f Avoid datamapper deprecation warnings 2010-02-24 01:52:08 +08:00
José Valim
e6f3034b11 Do not remove options from MongoMapper and DataMapper in find. 2010-02-23 15:51:29 +01:00
José Valim
33cf55aa13 Add link to wiki on README. 2010-02-19 23:54:55 -07:00
José Valim
e9682a3e64 In Rails 3, for some reason, you need to restart the server after copying views. 2010-02-19 23:54:05 -07:00
Jacques Crocker
3f37ce03c8 Gemfile fix for mongomapper
Points MongoMapper dependency to use a fork on MongoMapper that supports Rails3.
2010-02-19 20:32:32 +08:00
Jacques Crocker
4a51394af5 MongoMapper test suite fixes 2010-02-19 20:32:31 +08:00
Carlos Antonio da Silva
b3283e097d Use available warden_options method instead of env. 2010-02-19 09:07:37 -02:00
Paul Campbell
e9c16d852e add paragraphs to html emails
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-02-19 10:20:02 +01:00
José Valim
1c6f18cb8b Since Devise::FailureApp is now a metal, we can get rid of this default_url_options stuff. 2010-02-19 10:13:53 +01:00
José Valim
4a0b9c663a Use metal for Devise::FailureApp. \m/ 2010-02-19 09:52:12 +01:00
José Valim
f0eb4348f3 Deprecate Devise.orm. This allows you to use several ORMs with Devise and reduces the required API. 2010-02-19 09:26:17 +01:00
José Valim
3ac399f2ff Returns the proper response body based on the rquest for 401. 2010-02-18 19:38:13 +01:00
José Valim
889803151d Release 1.1.pre2 2010-02-18 18:06:01 +01:00
José Valim
35e058b279 Fix the undefined method devise issue. 2010-02-18 18:04:08 +01:00
José Valim
104d5b0441 There is no such thing as magic, my dear Watson. 2010-02-18 17:59:05 +01:00
José Valim
968ebe1b15 Uses the same content type as request on http authenticatable 401 responses 2010-02-17 21:40:01 +01:00
José Valim
1282fc03cf Add missing autoload. 2010-02-17 16:53:17 +01:00
José Valim
a79e8e0404 Tiny change in generator README. 2010-02-17 16:37:27 +01:00
José Valim
6d6633d1fb Release 1.1.pre which is Rails 3 compatible. 2010-02-17 13:53:05 +01:00
José Valim
fdf06861b0 Load Devise ORM after initialization. 2010-02-17 13:18:08 +01:00
José Valim
f6cc219210 Devise now allows you to have custom controlleers. Check the README for more information. 2010-02-17 13:15:19 +01:00
José Valim
691f9324f5 Use ActiveSupport::Concern. 2010-02-17 12:35:38 +01:00
José Valim
8e21373946 Rename devise/shared/_devise_links to devise/shared/links. 2010-02-17 12:30:08 +01:00
José Valim
02e8c04cde Update views generator and now have scoped views. 2010-02-17 12:26:54 +01:00
José Valim
5bf2eb3850 Updated .gitignore. 2010-02-17 11:11:27 +01:00
José Valim
443a2d8343 Moved devise_install to rails 3 generators. 2010-02-17 11:10:24 +01:00
José Valim
38bfe3f990 First generator for Rails 3. 2010-02-17 11:00:10 +01:00
José Valim
b4bbd3b892 Get all tests passing for ActiveRecord and allow MongoMapper tests to run. 2010-02-17 10:11:43 +01:00
José Valim
33941d1f62 All tests passing (except two which are errors in Rails). Now generators and initialization process. 2010-02-16 21:23:58 +01:00
José Valim
e6e66481b8 Got all tests in test/models and failure app ones passing. 369 tests, 805 assertions, 13 failures, 2 errors. 2010-02-16 17:00:36 +01:00
José Valim
d466849c57 More tests passing for Rails 3 compatibility. 369 tests, 788 assertions, 34 failures, 16 errors. 2010-02-16 16:11:30 +01:00
José Valim
b3e11c5aca Got another bunch of tests passing on Rails 3. 369 tests, 731 assertions, 33 failures, 53 errors. 2010-02-16 14:57:10 +01:00
José Valim
766316b5e7 Got tests running on Rails 3: 369 tests, 486 assertions, 45 failures, 124 errors. 2010-02-16 14:31:49 +01:00
Paul Campbell
6d29bcc467 Add mention of flash[:notice] and flash[:alert] 2010-02-15 22:29:23 +08:00
José Valim
ee87ec398a Updated gemspec. 2010-02-15 14:23:00 +01:00
José Valim
3e37fe8d4d Bump to 1.0.1 2010-02-15 14:19:08 +01:00
José Valim
48a94cdece Avoid mass assignment error messages with current password. 2010-02-15 14:17:12 +01:00
José Valim
bdacffab58 Make HttpAuthenticatable opt-in. 2010-02-15 14:11:33 +01:00
José Valim
085b12a710 Add registerable to defaults. 2010-02-15 14:06:50 +01:00
Carlos Antonio da Silva
3435c53725 Fix typo: autoload Clearance encryptor and not Authlogic one. 2010-02-12 13:02:11 -02:00
Carlos Antonio da Silva
01dec7fc78 README and TODO minor updates. 2010-02-12 01:54:47 -02:00
José Valim
4bfbeea7e6 Release 1.0.0 2010-02-09 02:17:20 +01:00
José Valim
2a9e8dca73 Allow authenticatable to used in change_table statements 2010-02-09 00:26:26 +01:00
José Valim
1b6f1b9752 Add registerable integration tests. 2010-02-09 00:08:57 +01:00
José Valim
732e31528e More changes in update_with_password. 2010-02-08 23:14:03 +01:00
José Valim
d7db5b1eea More work on edit. 2010-02-08 20:38:47 +01:00
José Valim
2761a75437 Refactor on routes. 2010-02-08 20:25:20 +01:00
José Valim
8a15ac6e4a Stub out other views for Registerable. 2010-02-08 19:07:24 +01:00
José Valim
9798ad7455 Allow scoped views to be customized per controller/mailer class. 2010-02-08 17:33:22 +01:00
José Valim
54cd2cc0e8 Use _ instead of . 2010-02-08 17:15:12 +01:00
Carlos Antonio da Silva
445070f6ec Use sign_up instead of registration in routes. Fix issue with users being signed in while attempting to sign up with info from already existing user. Also fix signed up flash. 2010-02-08 11:03:15 -02:00
Carlos Antonio da Silva
9856646fac Merge with master 2010-02-06 09:24:00 -02:00
José Valim
60fd9d26ea Rely on duck type instead of mappings settings. 2010-02-06 10:06:22 +01:00
José Valim
1cf4dc798d Add Http Basic Authentication support. 2010-02-06 01:33:32 +01:00
José Valim
2f441fb60b Commit new gemspec. 2010-02-05 21:38:50 +01:00
José Valim
e02810d528 Move to 0.9.2. 2010-02-05 21:37:28 +01:00
José Valim
c146cad448 Ensure inactive user cannot sign in. 2010-02-05 21:36:19 +01:00
Carlos Antonio da Silva
49d1978863 We do not need to check for registerable active inside the view. 2010-02-05 00:02:49 -02:00
Carlos Antonio da Silva
658059f31a Bring Devise::ALL back to modules and improving lockable docs. 2010-02-04 20:09:53 -02:00
Carlos Antonio da Silva
21359fb433 Refactoring a bit models and lockable. Also remove devise :all deprecation. 2010-02-04 20:09:53 -02:00
Carlos Antonio da Silva
60714cd449 autload Registerable. Extracting default routes and path_names to constants. Fix evals for better debugging and stack trace. 2010-02-04 20:09:53 -02:00
Carlos Antonio da Silva
6b837cb285 Introducing Registerable module, allowing users to sign up. 2010-02-04 20:08:38 -02:00
Carlos Antonio da Silva
4de1e43b7a Fix "return_to" to always save the request_uri, overwriting the return to url when the user types another forbidden url before sign in.
This way the user will be redirected to the last attempted url and not the first one.
2010-02-04 08:46:22 -02:00
Matt Powell
02a99b9766 deprecate find(:first) and find(:all) in MongoMapper 2010-02-03 16:53:49 +08:00
José Valim
a9e2337aeb Change EMAIL_REGEXP so it can be used in javascript. 2010-02-02 13:28:47 +01:00
José Valim
3781a0f47b Tidy up token authentication implementation. 2010-02-02 13:21:00 +01:00
Jonas Grimfelt
4878bdb60b Second version of token_authenticatable reflecting feedback: Nuked all hook-stuff. Should be easy to custom-reset authentication tokens by inheritance.
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-02-02 12:37:06 +01:00
Jonas Grimfelt
e1440fb430 Initial support for authorization using "authentication token" (a.k.a. "single access token") - new module. Corresponding changes to Devise core to hook events like "after_changed_password" (only one added now - only one that makes much sense for latest module) easily. Unit and integration tests included. NOTE: One failing test for hooking Warden::Manager.after_authentication - gets ignored for some reason.
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-02-02 12:36:44 +01:00
José Valim
c03b4ff339 Add gemspec since it's required by bundler. 2010-02-01 16:32:36 +01:00
José Valim
ca794776c1 Bump to 0.9.1. 2010-01-25 20:19:47 +01:00
José Valim
b4707c2bae Use self. just to stay in the same pattern. 2010-01-25 19:29:14 +01:00
jgeiger
b3fd742aea bcrypt requires the salt to be over 29 chars 2010-01-22 23:04:03 +08:00
David Palm
bc05d28d3f Devise::Mapping#raw_path does not consider relative_url_root so that route helpers work (no more session_path(:user) => '/abc/abc/users/sign_in')
Devise::Mapping#parsed_path considers relative_url_root so that initial redirects still work with non empty relative_url_roots
2010-01-22 23:03:48 +08:00
José Valim
e4e9e16623 Bump to 0.9.0. 2010-01-21 15:30:13 +01:00
José Valim
345bf159e2 Add latest commities entries to CHANGELOG. 2010-01-21 09:15:07 +01:00
Jonas Grimfelt
0c7c762c16 Fixed some Ruby 1.9 issues/bugs. 2010-01-21 16:06:19 +08:00
Jonas Grimfelt
f50ec773b2 New convenient helper method for extending Devise with additional modules: Devise::add_module. 2010-01-21 16:06:17 +08:00
Carlos Antonio da Silva
6d80418fd1 Changing flash messages to new Rails defaults :notice/:alert 2010-01-20 17:46:14 -02:00
José Valim
b4183cbaa2 Url helpers should rely find_scope! 2010-01-19 17:19:40 +01:00
José Valim
04ce9d1e6f Should accept path prefixes not starting with slash. 2010-01-16 14:39:57 +01:00
José Valim
ef25da992c Use an OrderedHash to fix problems with test suite working in some machines but no in others. 2010-01-16 14:32:52 +01:00
José Valim
394b1ff444 Bring mongomapper up to date. Remember that you need mongo_ext in order to use MongoMapper with Devise. 2010-01-16 11:22:09 +01:00
José Valim
a5b2ee5171 Improve documentation for after_sign_in_path_for. 2010-01-16 10:56:35 +01:00
José Valim
fdc2e795d7 Simplify links requirement. 2010-01-14 16:04:13 +01:00
José Valim
a32e90a1d6 Update CHANGELOG and dependencies. 2010-01-14 15:53:17 +01:00
José Valim
2afad49a96 Bring rememberable back. 2010-01-14 15:47:14 +01:00
José Valim
f46d1b1d81 Add support to Warden 0.9.0.pre 2010-01-14 13:38:02 +01:00
José Valim
66f4cfd3eb Clean up tests. 2010-01-13 19:53:12 +01:00
José Valim
efc0ae230a Deprecate :all. 2010-01-13 19:45:24 +01:00
José Valim
f075a6babe Tidying up. 2010-01-13 18:46:04 +01:00
José Valim
19f9ecfcb6 Updating CHANGELOG. 2010-01-13 18:27:26 +01:00
José Valim
d4442837d5 Clean up whitespace and remove deprecated stuff. 2010-01-13 18:23:04 +01:00
José Valim
b581f86317 DRY up controllers. 2010-01-13 18:12:13 +01:00
José Valim
d0ccd14c54 Merge remote branch 'mhfs/master' 2010-01-13 17:49:20 +01:00
Marcelo Silveira
f4b438bb1e adding links refactory to changelog 2010-01-09 13:36:04 -02:00
Marcelo Silveira
6c4274fae6 fixing mongo tests 2010-01-09 13:16:07 -02:00
Marcelo Silveira
827d0ce14c refactoring attempts track to avoid saving the model twice 2010-01-09 13:12:24 -02:00
Marcelo Silveira
915afa5f0a forgot the partial.. 2010-01-09 12:59:24 -02:00
Marcelo Silveira
4498acb1d0 moved view links into a partial and I18n'ed them 2010-01-09 12:58:51 -02:00
Marcelo Silveira
9c4ddc6465 - Maximum attempts changed from 5 to 20
- Lockable is not turned on by default
- Fixed lockable incompatibilities with latest commits
2010-01-09 11:41:28 -02:00
Marcelo Silveira
32991e13c4 Merge and fix conflicts. 2010-01-09 11:22:27 -02:00
Marcelo Silveira
d2fa737aa0 introducing lockable implementation 2010-01-01 17:57:35 -02:00
254 changed files with 10276 additions and 3898 deletions

6
.gitignore vendored
View File

@@ -3,6 +3,10 @@
*~
coverage/*
*.sqlite3
.bundle
rdoc/*
devise.gemspec
pkg
log
test/tmp/*
Gemfile.lock

8
.travis.yml Normal file
View File

@@ -0,0 +1,8 @@
script: "bundle exec rake test"
rvm:
- 1.8.7
- 1.9.2
- ree
- rbx
- rbx-2.0
- jruby

View File

@@ -1,15 +1,412 @@
== 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
* Properly ignore path prefix on omniauthable
* Faster uniqueness queries
* Rename active? to active_for_authentication? to avoid conflicts
== 1.2.rc2
* enhancements
* Make friendly_token 20 chars long
* Use secure_compare
* bug fix
* Fix an issue causing infinite redirects in production
* rails g destroy works properly with devise generators (by github.com/andmej)
* before_failure callbacks should work on test helpers (by github.com/twinge)
* rememberable cookie now is httponly by default (by github.com/JamesFerguson)
* Add missing confirmation_keys (by github.com/JohnPlummer)
* Ensure after_* hooks are called on RegistrationsController
* When using database_authenticatable Devise will now only create an email field when appropriate (if using default authentication_keys or custom authentication_keys with email included)
* Ensure stateless token does not trigger timeout (by github.com/pixelauthority)
* Implement handle_unverified_request for Rails 3.0.4 compatibility and improve FailureApp reliance on symbols
* Consider namespaces while generating routes
* Custom failure apps no longer ignored in test mode (by github.com/jaghion)
* Do not depend on ActiveModel::Dirty
* Manual sign_in now triggers remember token
* Be sure to halt strategies on failures
* Consider SCRIPT_NAME on Omniauth paths
* Reset failed attempts when lock is expired
* Ensure there is no Mongoid injection
* deprecations
* Deprecated anybody_signed_in? in favor of signed_in? (by github.com/gavinhughes)
* Removed --haml and --slim view templates
* Devise::OmniAuth helpers were deprecated and removed in favor of Omniauth.config.test_mode
== 1.2.rc
* deprecations
* cookie_domain is deprecated in favor of cookie_options
* after_update_path_for can no longer be defined in ApplicationController
* enhancements
* Added OmniAuth support
* Added ORM adapter to abstract ORM iteraction
* sign_out_via is available in the router to configure the method used for sign out (by github.com/martinrehfeld)
* Improved Ajax requests handling in failure app (by github.com/spastorino)
* Added request_keys to easily use request specific values (like subdomain) in authentication
* Increased the size of friendly_token to 60 characters (reduces the chances of a successful brute attack)
* Ensure the friendly token does not include "_" or "-" since some e-mails may not autolink it properly (by github.com/rymai)
* Extracted encryptors into :encryptable for better bcrypt support
* :rememberable is now able to use salt as token if no remember_token is provided
* Store the salt in session and expire the session if the user changes his password
* Allow :stateless_token to be set to true avoiding users to be stored in session through token authentication
* cookie_options uses session_options values by default
* Sign up now check if the user is active or not and redirect him accordingly setting the inactive_signed_up message
* Use ActiveModel#to_key instead of #id
* sign_out_all_scopes now destroys the whole session
* Added case_insensitive_keys that automatically downcases the given keys, by default downcases only e-mail (by github.com/adahl)
* default behavior changes
* sign_out_all_scopes defaults to true as security measure
* http authenticatable is disabled by default
* Devise does not intercept 401 returned from applications
* bugfix
* after_sign_in_path_for always receives a resource
* Do not execute Warden::Callbacks on Devise::TestHelpers (by github.com/sgronblo)
* Allow password recovery and account unlocking to change used keys (by github.com/RStankov)
* FailureApp now properly handles nil request.format
* Fix a bug causing FailureApp to return with HTTP Auth Headers for IE7
* Ensure namespaces has proper scoped views
* Ensure Devise does not set empty flash messages (by github.com/sxross)
== 1.1.6
* Use a more secure e-mail regexp
* Implement Rails 3.0.4 handle unverified request
* Use secure_compare to compare passwords
== 1.1.5
* bugfix
* Ensure to convert keys on indifferent hash
* defaults
* Set config.http_authenticatable to false to avoid confusion
== 1.1.4
* bugfix
* Avoid session fixation attacks
== 1.1.3
* bugfix
* Add reply-to to e-mail headers by default
* Updated the views generator to respect the rails :template_engine option (by github.com/fredwu)
* Check the type of HTTP Authentication before using Basic headers
* Avoid invalid_salt errors by checking salt presence (by github.com/thibaudgg)
* Forget user deletes the right cookie before logout, not remembering the user anymore (by github.com/emtrane)
* Fix for failed first-ever logins on PostgreSQL where column default is nil (by github.com/bensie)
* :default options is now honored in migrations
== 1.1.2
* bugfix
* Compatibility with latest Rails routes schema
== 1.1.1
* bugfix
* Fix a small bug where generated locale file was empty on devise:install
== 1.1.0
* enhancements
* Rememberable module allows user to be remembered across browsers and is enabled by default (by github.com/trevorturk)
* Rememberable module allows you to activate the period the remember me token is extended (by github.com/trevorturk)
* devise_for can now be used together with scope method in routes but with a few limitations (check the documentation)
* Support `as` or `devise_scope` in the router to specify controller access scope
* HTTP Basic Auth can now be disabled/enabled for xhr(ajax) requests using http_authenticatable_on_xhr option (by github.com/pellja)
* bug fix
* Fix a bug in Devise::TestHelpers where current_user was returning a Response object for non active accounts
* Devise should respect script_name and path_info contracts
* Fix a bug when accessing a path with (.:format) (by github.com/klacointe)
* Do not add unlock routes unless unlock strategy is email or both
* Email should be case insensitive
* Store classes as string in session, to avoid serialization and stale data issues
* deprecations
* use_default_scope is deprecated and has no effect. Use :as or :devise_scope in the router instead
== 1.1.rc2
* enhancements
* Allow to set cookie domain for the remember token. (by github.com/mantas)
* Added navigational formats to specify when it should return a 302 and when a 401.
* Added authenticate(scope) support in routes (by github.com/wildchild)
* Added after_update_path_for to registrations controller (by github.com/thedelchop)
* Allow the mailer object to be replaced through config.mailer = "MyOwnMailer"
* bug fix
* Fix a bug where session was timing out on sign out
* deprecations
* bcrypt is now the default encryptor
* devise.mailer.confirmations_instructions now should be devise.mailer.confirmations_instructions.subject
* devise.mailer.user.confirmations_instructions now should be devise.mailer.confirmations_instructions.user_subject
* Generators now use Rails 3 syntax (devise:install) instead of devise_install
== 1.1.rc1
* enhancements
* Rails 3 compatibility
* All controllers and views are namespaced, for example: Devise::SessionsController and "devise/sessions"
* Devise.orm is deprecated. This reduces the required API to hook your ORM with devise
* Use metal for failure app
* HTML e-mails now have proper formatting
* Allow to give :skip and :controllers in routes
* Move trackable logic to the model
* E-mails now use any template available in the filesystem. Easy to create multipart e-mails
* E-mails asks headers_for in the model to set the proper headers
* Allow to specify haml in devise_views
* Compatibility with Mongoid
* Make config.devise available on config/application.rb
* TokenAuthenticatable now works with HTTP Basic Auth
* Allow :unlock_strategy to be :none and add :lock_strategy which can be :failed_attempts or none. Setting those values to :none means that you want to handle lock and unlocking by yourself
* No need to append ?unauthenticated=true in URLs anymore since Flash was moved to a middleware in Rails 3
* :activatable is included by default in your models
* bug fix
* Fix a bug with STI
* deprecations
* Rails 3 compatible only
* Removed support for MongoMapper
* Scoped views are no longer "sessions/users/new". Now use "users/sessions/new"
* Devise.orm is deprecated, just require "devise/orm/YOUR_ORM" instead
* Devise.default_url_options is deprecated, just modify ApplicationController.default_url_options
* All messages under devise.sessions, except :signed_in and :signed_out, should be moved to devise.failure
* :as and :scope in routes is deprecated. Use :path and :singular instead
== 1.0.8
* enhancements
* Support for latest MongoMapper
* Added anybody_signed_in? helper (by github.com/SSDany)
* bug fix
* confirmation_required? is properly honored on active? calls. (by github.com/paulrosania)
== 1.0.7
* bug fix
* Ensure password confirmation is always required
* deprecations
* authenticatable was deprecated and renamed to database_authenticatable
* confirmable is not included by default on generation
== 1.0.6
* bug fix
* Do not allow unlockable strategies based on time to access a controller.
* Do not send unlockable email several times.
* Allow controller to upstram custom! failures to Warden.
== 1.0.5
* bug fix
* Use prepend_before_filter in require_no_authentication.
* require_no_authentication on unlockable.
* Fix a bug when giving an association proxy to devise.
* Do not use lock! on lockable since it's part of ActiveRecord API.
== 1.0.4
* bug fix
* Fixed a bug when deleting an account with rememberable
* Fixed a bug with custom controllers
== 1.0.3
* enhancements
* HTML e-mails now have proper formatting
* Do not remove MongoMapper options in find
== 1.0.2
* enhancements
* Allows you set mailer content type (by github.com/glennr)
* bug fix
* Uses the same content type as request on http authenticatable 401 responses
== 1.0.1
* enhancements
* HttpAuthenticatable is not added by default automatically.
* Avoid mass assignment error messages with current password.
* bug fix
* Fixed encryptors autoload
== 1.0.0
* deprecation
* :old_password in update_with_password is deprecated, use :current_password instead
* enhancements
* Added Registerable
* Added Http Basic Authentication support
* Allow scoped_views to be customized per controller/mailer class
* [#99] Allow authenticatable to used in change_table statements
== 0.9.2
* bug fix
* Ensure inactive user cannot sign in
* Ensure redirect to proper url after sign up
* enhancements
* Added gemspec to repo
* Added token authenticatable (by github.com/grimen)
== 0.9.1
* bug fix
* Allow bigger salt size (by github.com/jgeiger)
* Fix relative url root
== 0.9.0
* deprecation
* devise :all is deprecated
* :success and :failure flash messages are now :notice and :alert
* enhancements
* Added devise lockable (by github.com/mhfs)
* Warden 0.9.0 compatibility
* Mongomapper 0.6.10 compatibility
* Added Devise.add_module as hooks for extensions (by github.com/grimen)
* Ruby 1.9.1 compatibility (by github.com/grimen)
* bug fix
* Accept path prefix not starting with slash
* url helpers should rely on find_scope!
== 0.8.2
* enhancements
* Allow Devise.mailer_sender to be a proc (by github/grimen)
* Allow Devise.mailer_sender to be a proc (by github.com/grimen)
* bug fix
* Fix bug with passenger, update is required to anyone deploying on passenger (by github/dvdpalm)
* Fix bug with passenger, update is required to anyone deploying on passenger (by github.com/dvdpalm)
== 0.8.1
* enhancements
* Move salt to encryptors
* Devise::Lockable
* Moved view links into partial and I18n'ed them
* bug fix
* Bcrypt generator was not being loaded neither setting the proper salt

34
Gemfile Normal file
View File

@@ -0,0 +1,34 @@
source "http://rubygems.org"
gemspec
gem "rails", "~> 3.1.0.rc8"
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-jdbcsqlite3-adapter'
end
platforms :mri_18 do
group :test do
gem "ruby-debug", ">= 0.10.3"
end
end
platforms :ruby do
gem "sqlite3-ruby"
group :mongoid do
gem "mongo", "~> 1.3.0"
gem "mongoid", "~> 2.0"
gem "bson_ext", "~> 1.3.0"
end
end

View File

@@ -1,4 +1,4 @@
Copyright 2009 Plataforma Tecnologia. http://blog.plataformatec.com.br
Copyright 2009-2011 Plataforma Tecnologia. http://blog.plataformatec.com.br
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the

View File

@@ -7,61 +7,114 @@ 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.
Right now it's composed of six modules included by default when you invoke "devise :all" in your models:
It's comprised of 12 modules:
* Authenticatable: responsible for encrypting password and validating authenticity of a user while signing in.
* Confirmable: responsible for verifying whether an account is already confirmed to sign in, and to send emails with confirmation instructions.
* Recoverable: takes care of reseting the user password and send reset instructions.
* Rememberable: manages generating and clearing token for remember the user from a saved cookie.
* Trackable: tracks sign in count, timestamps and ip.
* Validatable: creates all needed validations for email and password. It's totally optional, so you're able to to customize validations by yourself.
* 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.
* Omniauthable: adds Omniauth (github.com/intridea/omniauth) support;
* Confirmable: sends emails with confirmation instructions and verifies whether an account is already confirmed during sign in.
* Recoverable: resets the user password and sends reset instructions.
* Registerable: handles signing up users through a registration process, also allowing them to edit and destroy their account.
* Rememberable: manages generating and clearing a token for remembering the user from a saved cookie.
* Trackable: tracks sign in count, timestamps and IP address.
* Timeoutable: expires sessions that have no activity in a specified period of time.
* Validatable: provides validations of email and password. It's optional and can be customized, so you're able to define your own validations.
* Lockable: locks an account after a specified number of failed sign-in attempts. Can unlock via email or after a specified time period.
* Encryptable: adds support of other authentication mechanisms besides the built-in Bcrypt (the default).
And it also includes the optional modules:
== Information
* Activatable: if you need to activate accounts by other means, which are not through confirmation, use this module.
* Timeoutable: expires sessions without activity in a certain period of time.
=== The Devise wiki
There's an example application using Devise at http://github.com/plataformatec/devise_example .
The Devise Wiki has lots of additional information about Devise including many "how-to" articles and answers to the most frequently asked questions. Please browse the Wiki after finishing this README:
== Dependencies
http://wiki.github.com/plataformatec/devise
Devise is based on Warden (http://github.com/hassox/warden), a Rack Authentication Framework so you need to install it as a gem. Please ensure you have it installed in order to use devise (see installation below).
=== Bug reports
If you discover a problem with Devise, we would like to know about it. However, we ask that you please review these guidelines before submitting a bug report:
http://github.com/plataformatec/devise/wiki/Bug-reports
If you found a security bug, do *NOT* use the GitHub issue tracker. Send email or a private GitHub message to the maintainers listed at the bottom of the README.
=== Mailing list
If you have any questions, comments, or concerns, please use the Google Group instead of the GitHub issue tracker:
http://groups.google.com/group/plataformatec-devise
=== RDocs
You can view the Devise documentation in RDoc format here:
http://rubydoc.info/github/plataformatec/devise/master/frames
If you need to use Devise with Rails 2.3, you can always run `gem server` from the command line after you install the gem to access the old documentation.
=== Example applications
There are a few example applications available on GitHub that demonstrate various features of Devise with different versions of Rails. You can view them here:
http://github.com/plataformatec/devise/wiki/Example-Applications
=== Extensions
Our community has created a number of extensions that add functionality above and beyond what is included with Devise. You can view a list of available extensions and add your own here:
http://github.com/plataformatec/devise/wiki/Extensions
=== Contributing
We hope that you will consider contributing to Devise. Please read this short overview for some information about how to get started:
http://github.com/plataformatec/devise/wiki/Contributing
You will usually want to write tests for your changes. To run the test suite, `cd` into Devise's top-level directory and run `bundle install` and `rake`. For the tests to pass, you will need to have a MongoDB server (version 1.6 or newer) running on your system.
== Installation
All gems are on gemcutter, so you need to add gemcutter to your sources if you haven't yet:
You can use the latest Rails 3 gem with the latest Devise gem:
sudo gem sources -a http://gemcutter.org/
gem install devise
Install warden gem if you don't have it installed (requires 0.6.4 or higher):
After you install Devise and add it to your Gemfile, you need to run the generator:
sudo gem install warden
rails generate devise:install
Install devise gem:
The generator will install an initializer which describes ALL Devise's configuration options and you MUST take a look at it. When you are done, you are ready to add Devise to any of your models using the generator:
sudo gem install devise
rails generate devise MODEL
Configure warden and devise gems inside your app:
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.
config.gem 'warden'
config.gem 'devise'
Support for Rails 2.3.x can be found by installing Devise 1.0.x from the v1.0 branch.
Run the generator:
== Starting with Rails?
ruby script/generate devise_install
If you are building your first Rails application, we recommend you to *not* use Devise. Devise requires a good understanding of the Rails Framework. In such cases, we advise you to start a simple authentication system from scratch, today we have two resources:
And you're ready to go. The generator will install an initializer which describes Devise's configuration options. Be sure to take a look.
* 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
== Basic Usage
Once you have solidified your understanding of Rails and authentication mechanisms, we assure you Devise will be very pleasant to work with. :)
This is a walkthrough with all steps you need to setup a devise resource, including model, migration, route files, and optional configuration. You can also check out the *Generators* section below to help you start.
== Getting started
Devise must be set up within the model (or models) you want to use, and devise routes must be created inside your config/routes.rb file.
This is a walkthrough with all steps you need to setup a devise resource, including model, migration, route files, and optional configuration.
We're assuming here you want a User model. First of all you have to setup a migration with the following fields:
Devise must be set up within the model (or models) you want to use. Devise routes must be created inside your config/routes.rb file.
We're assuming here you want a User model with some Devise modules, as outlined below:
class User < ActiveRecord::Base
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:
create_table :users do |t|
t.authenticatable
t.database_authenticatable
t.confirmable
t.recoverable
t.rememberable
@@ -69,95 +122,79 @@ We're assuming here you want a User model. First of all you have to setup a migr
t.timestamps
end
You may also want to add some indexes to improve performance:
Devise doesn't use _attr_accessible_ or _attr_protected_ inside its modules, so be sure to define attributes as accessible or protected in your model.
add_index :your_table, :email
add_index :your_table, :confirmation_token # for confirmable
add_index :your_table, :reset_password_token # for recoverable
Configure your routes after setting up your model. Open your config/routes.rb file and add:
Now let's setup a User model adding the devise line:
devise_for :users
class User < ActiveRecord::Base
devise :all
end
This will use your User model to create a set of needed routes (you can see them by running `rake routes`). If you invoked the devise generator, you noticed that this is exactly what the generator produces for us: model, routes and migrations.
This will include the six default modules outlined at the beginning. You can exclude and remove any module at will:
Don't forget to run rake db:migrate and you are ready to go! But don't stop reading here, we still have a lot to tell you.
# Include timeout configuration
devise :all, :timeoutable
=== Controller filters and helpers
# Remove validations
devise :all, :except => :validatable
Remember that Devise don't rely on _attr_accessible_ or _attr_protected_ inside its modules, so be sure to setup what attributes are accessible or protected in your model.
== Model configuration
In addition to :except, you can provide :pepper, :stretches, :encryptor, :authentication_keys, :confirm_within, :remember_for and :timeout as options to devise method.
All those options are described in "config/initializers/devise.rb", which is generated when you invoke `ruby script/generate devise_install` in your application root.
== Routes
The next step after setting up your model is to configure your routes for devise. You do this by opening up your config/routes.rb and adding:
map.devise_for :users
This is going to look inside you User model and create a set of needed routes (you can see them by running `rake routes`).
There are also some options available for configuring your routes, as :class_name (to set the class for that route), :as and :path_names, where the last two have the same meaning as in common routes. The available :path_names are:
map.devise_for :users, :as => "usuarios", :path_names => { :sign_in => 'login', :sign_out => 'logout', :password => 'secret', :confirmation => 'verification' }
Be sure to check devise_for documentation for detailed description.
== Controller filters and helpers
Devise is gonna create some helpers to use inside your controllers and views. To setup a controller that needs user authentication, just add this before_filter:
Devise will create some helpers to use inside your controllers and views. To set up a controller with user authentication, just add this before_filter:
before_filter :authenticate_user!
To verify if a user is signed in, you have the following helper:
To verify if a user is signed in, use the following helper:
user_signed_in?
And to get the current signed in user this helper is available:
For the current signed-in user, this helper is available:
current_user
You have also access to the session for this scope:
You can access the session for this scope:
user_session
After signing in a user, confirming it's account or updating it's 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. To do it so, you need to create e default root inside your routes for your application:
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:
map.root :controller => 'home'
root :to => "home#index"
You can also overwrite after_sign_in_path_for and after_sign_out_path_for to customize better your redirect hooks.
You can also overwrite after_sign_in_path_for and after_sign_out_path_for to customize your redirect hooks.
Finally, if you are using confirmable or recoverable, you also need to setup default url options for the mailer in each environment. Here's is the configuration for config/environments/development.rb:
Finally, you need to set up default url options for the mailer in each environment. Here is the configuration for config/environments/development.rb:
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
== Views
Notice that if your devise model is not called "user" but "member", then the helpers you should use are:
By default devise will use the same views for all scopes/roles you have. But what if you need so different views to each of them? Devise also has an easy way to accomplish it: just setup config,scoped_views to true inside your devise config file, and you will be able to have views based on scope like 'sessions/users/new' and 'sessions/admin/new'. If no view is found within the scope, Devise will fallback to the default view.
before_filter :authenticate_member!
== Tidying up
member_signed_in?
Devise let's you setup as many roles as you want, so let's say you already have this User model and also want an Admin model with just authentication, trackable and timeoutable stuff and none of confirmation or password recovery. Just follow the same steps:
current_member
member_session
=== Configuring Models
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, :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.
=== Configuring multiple models
Devise allows you to set up as many roles as you want. For example, you may have a User model and also want an Admin model with just authentication, trackable, lockable and timeoutable features and no confirmation or password-recovery features. Just follow these steps:
# Create a migration with the required fields
create_table :admins do |t|
t.authenticatable
t.database_authenticatable
t.lockable
t.trackable
t.timestamps
end
# Inside your Admin model
devise :authenticatable, :trackable, :timeoutable
devise :database_authenticatable, :trackable, :timeoutable, :lockable
# Inside your routes
map.devise_for :admin
devise_for :admins
# Inside your protected controller
before_filter :authenticate_admin!
@@ -167,27 +204,62 @@ Devise let's you setup as many roles as you want, so let's say you already have
current_admin
admin_session
== Generators
=== Configuring views
Devise comes with some generators to help you start:
We built Devise to help you quickly develop an application that uses authentication. However, we don't want to be in your way when you need to customize it.
ruby script/generate devise_install
Since Devise is an engine, all its views are packaged inside the gem. These views will help you get started, but after sometime you may want to change them. If this is the case, you just need to invoke the following generator, and it will copy all views to your application:
This will generate an initializer, with a description of all configuration values. You can also generate models through:
rails generate devise:views
ruby script/generate devise Model
If you have more than one role in your application (such as "User" and "Admin"), you will notice that Devise uses the same views for all roles. Fortunately, Devise offers an easy way to customize views. All you need to do is set "config.scoped_views = true" inside "config/initializers/devise.rb".
A model configured with all devise modules and attr_accessible for default fields will be created. The generator will also create the migration and configure your routes for devise.
After doing so, you will be able to have views based on the role like "users/sessions/new" and "admins/sessions/new". If no view is found within the scope, Devise will use the default view at "devise/sessions/new". You can also use the generator to generate scoped views:
You can also copy devise views to your application, being able to modify them based on your needs. To do it so, run the following command:
rails generate devise:views users
ruby script/generate devise_views
=== Configuring controllers
This is gonna copy all session, password, confirmation and mailer views to your app/views folder.
If the customization at the views level is not enough, you can customize each controller by following these steps:
== I18n
1) Create your custom controller, for example a Admins::SessionsController:
Devise uses flash messages with I18n with the flash keys :success and :failure. To customize your app, you can setup your locale file this way:
class Admins::SessionsController < Devise::SessionsController
end
2) Tell the router to use this controller:
devise_for :admins, :controllers => { :sessions => "admins/sessions" }
3) And since we changed the controller, it won't use the "devise/sessions" views, so remember to copy "devise/sessions" to "admin/sessions".
Remember that Devise uses flash messages to let users know if sign in was successful or failed. Devise expects your application to call "flash[:notice]" and "flash[:alert]" as appropriate.
=== Configuring routes
Devise also ships with default routes. If you need to customize them, you should probably be able to do it through the devise_for method. It accepts several options like :class_name, :path_prefix and so on, including the possibility to change path names for I18n:
devise_for :users, :path => "usuarios", :path_names => { :sign_in => 'login', :sign_out => 'logout', :password => 'secret', :confirmation => 'verification', :unlock => 'unblock', :registration => 'register', :sign_up => 'cmon_let_me_in' }
Be sure to check devise_for documentation for details.
If you have the need for more deep customization, for instance to also allow "/sign_in" besides "/users/sign_in", all you need to do is to create your routes normally and wrap them in a +devise_scope+ block in the router:
devise_scope :user do
get "sign_in", :to => "devise/sessions#new"
end
This way you tell devise to use the scope :user when "/sign_in" is accessed. Notice +devise_scope+ is also aliased as +as+ and you can also give a block to +devise_for+, resulting in the same behavior:
devise_for :users do
get "sign_in", :to => "devise/sessions#new"
end
Feel free to choose the one you prefer!
=== I18n
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:
@@ -204,19 +276,22 @@ You can also create distinct messages based on the resource you've configured us
admin:
signed_in: 'Hello admin!'
Devise mailer uses the same pattern to create subject messages:
The Devise mailer uses a similar pattern to create subject messages:
en:
devise:
mailer:
confirmation_instructions: 'Hello everybody!'
user:
confirmation_instructions: 'Hello User! Please confirm your email'
reset_password_instructions: 'Reset instructions'
confirmation_instructions:
subject: 'Hello everybody!'
user_subject: 'Hello User! Please confirm your email'
reset_password_instructions:
subject: 'Reset instructions'
Take a look at our locale file to check all available messages.
Take a look at our locale file to check all available messages. You may also be interested in one of the many translations that are available on our wiki:
== Test helpers
http://github.com/plataformatec/devise/wiki/I18n
=== Test helpers
Devise includes some tests helpers for functional specs. To use them, you just need to include Devise::TestHelpers in your test class and use the sign_in and sign_out method. Such methods have the same signature as in controllers:
@@ -226,44 +301,53 @@ Devise includes some tests helpers for functional specs. To use them, you just n
sign_out :user # sign_out(scope)
sign_out @user # sign_out(resource)
You can include the Devise Test Helpers in all of your tests by adding the following to the bottom of your test/test_helper.rb or spec/spec_helper.rb file:
You can include the Devise Test Helpers in all of your tests by adding the following to the bottom of your test/test_helper.rb file:
class ActionController::TestCase
include Devise::TestHelpers
end
Do not use such helpers for integration tests like Cucumber, Webrat... Just fill in the form or explicitly set the user in session. For more tips, check the wiki (http://wiki.github.com/plataformatec/devise).
If you're using RSpec and want the helpers automatically included within all +describe+ blocks, add a file called spec/support/devise.rb with the following contents:
== Migrating from other solutions
RSpec.configure do |config|
config.include Devise::TestHelpers, :type => :controller
end
Devise implements encryption strategies for Clearance, Authlogic and Restful-Authentication. To make use of it set the desired encryptor in the encryptor initializer config option. You might also need to rename your encrypted password and salt columns to match Devises's one (encrypted_password and password_salt).
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).
== Other ORMs
=== Omniauth
Devise was made to work from scratch with ActiveRecord. However it currently supports DataMapper and MongoMapper as well.
To use it, just set Devise.orm or configure it in the initialization file (which is created with devise_install).
Devise comes with Omniauth support out of the box to authenticate from other providers. You can read more about Omniauth support in the wiki:
== TODO
* https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview
Please refer to TODO file.
=== Other ORMs
== Maintainers
Devise supports ActiveRecord (default) and Mongoid. To choose other ORM, you just need to require it in the initializer file.
=== Migrating from other solutions
Devise implements encryption strategies for Clearance, Authlogic and Restful-Authentication. To make use of these strategies, you need set the desired encryptor in the encryptor initializer config option and add :encryptable to your model. You might also need to rename your encrypted password and salt columns to match Devise's fields (encrypted_password and password_salt).
== Additional information
=== Warden
Devise is based on Warden, which is a general Rack authentication framework created by Daniel Neighman. We encourage you to read more about Warden here:
http://github.com/hassox/warden
=== Contributors
We have a long list of valued contributors. Check them all at:
http://github.com/plataformatec/devise/contributors
=== Maintainers
* José Valim (http://github.com/josevalim)
* Carlos Antônio da Silva (http://github.com/carlosantoniodasilva)
== Contributors
== License
* Marcelo Silveira (http://github.com/mhfs)
* Cyril Mougel (http://github.com/shingara)
* Jonas Grimfelt (http://github.com/grimen)
== Bugs and Feedback
If you discover any bugs or want to drop a line, feel free to create an issue on
GitHub or send an e-mail to the mailing list.
http://github.com/plataformatec/devise/issues
http://groups.google.com/group/plataformatec-devise
MIT License. Copyright 2009 Plataforma Tecnologia. http://blog.plataformatec.com.br
MIT License. Copyright 2010 Plataforma Tecnologia. http://blog.plataformatec.com.br

View File

@@ -1,18 +1,18 @@
# encoding: UTF-8
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
require File.join(File.dirname(__FILE__), 'lib', 'devise', 'version')
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
Dir[File.join(File.dirname(__FILE__), 'test', 'orm', '*.rb')].each do |file|
orm = File.basename(file).split(".").first
system "rake test DEVISE_ORM=#{orm}"
# "Some day, my son, rake's inner wisdom will reveal itself. Until then,
# take this `system` -- may its brute force protect you well."
exit 1 unless system "rake test DEVISE_ORM=#{orm}"
end
end
@@ -32,22 +32,3 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_files.include('README.rdoc')
rdoc.rdoc_files.include('lib/**/*.rb')
end
begin
require 'jeweler'
Jeweler::Tasks.new do |s|
s.name = "devise"
s.version = Devise::VERSION
s.summary = "Flexible authentication solution for Rails with Warden"
s.email = "contact@plataformatec.com.br"
s.homepage = "http://github.com/plataformatec/devise"
s.description = "Flexible authentication solution for Rails with Warden"
s.authors = ['José Valim', 'Carlos Antônio']
s.files = FileList["[A-Z]*", "{app,config,generators,lib}/**/*", "init.rb"]
s.add_dependency("warden", "~> 0.8.1")
end
Jeweler::GemcutterTasks.new
rescue LoadError
puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
end

6
TODO
View File

@@ -1,6 +0,0 @@
* Make test run with DataMapper (ActiveRecord, MongoMapper)
* Add Registerable support
* Add http authentication support
* Extract SessionSerializer tests from Authenticatable
* Extract CookieSerializer tests from Authenticatable
* Extract Activatable tests from Confirmable

View File

@@ -1,33 +0,0 @@
class ConfirmationsController < ApplicationController
include Devise::Controllers::Helpers
# GET /resource/confirmation/new
def new
build_resource
render_with_scope :new
end
# POST /resource/confirmation
def create
self.resource = resource_class.send_confirmation_instructions(params[resource_name])
if resource.errors.empty?
set_flash_message :success, :send_instructions
redirect_to new_session_path(resource_name)
else
render_with_scope :new
end
end
# GET /resource/confirmation?confirmation_token=abcdef
def show
self.resource = resource_class.confirm!(:confirmation_token => params[:confirmation_token])
if resource.errors.empty?
set_flash_message :success, :confirmed
sign_in_and_redirect(resource_name, resource)
else
render_with_scope :new
end
end
end

View File

@@ -0,0 +1,47 @@
class Devise::ConfirmationsController < ApplicationController
include Devise::Controllers::InternalHelpers
# GET /resource/confirmation/new
def new
build_resource({})
render_with_scope :new
end
# POST /resource/confirmation
def create
self.resource = resource_class.send_confirmation_instructions(params[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
respond_with_navigational(resource){ render_with_scope :new }
end
end
# GET /resource/confirmation?confirmation_token=abcdef
def show
self.resource = resource_class.confirm_by_token(params[:confirmation_token])
if resource.errors.empty?
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
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

@@ -0,0 +1,26 @@
class Devise::OmniauthCallbacksController < ApplicationController
include Devise::Controllers::InternalHelpers
def failure
set_flash_message :alert, :failure, :kind => failed_strategy.name.to_s.humanize, :reason => failure_message
redirect_to after_omniauth_failure_path_for(resource_name)
end
protected
def failed_strategy
env["omniauth.error.strategy"]
end
def failure_message
exception = env["omniauth.error"]
error = exception.error_reason if exception.respond_to?(:error_reason)
error ||= exception.error if exception.respond_to?(:error)
error ||= env["omniauth.error.type"].to_s
error.to_s.humanize if error
end
def after_omniauth_failure_path_for(scope)
new_session_path(scope)
end
end

View File

@@ -0,0 +1,50 @@
class Devise::PasswordsController < ApplicationController
prepend_before_filter :require_no_authentication
include Devise::Controllers::InternalHelpers
# GET /resource/password/new
def new
build_resource({})
render_with_scope :new
end
# POST /resource/password
def create
self.resource = resource_class.send_reset_password_instructions(params[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
respond_with_navigational(resource){ render_with_scope :new }
end
end
# GET /resource/password/edit?reset_password_token=abcdef
def edit
self.resource = resource_class.new
resource.reset_password_token = params[:reset_password_token]
render_with_scope :edit
end
# PUT /resource/password
def update
self.resource = resource_class.reset_password_by_token(params[resource_name])
if resource.errors.empty?
set_flash_message(:notice, :updated) if is_navigational_format?
sign_in(resource_name, resource)
respond_with resource, :location => redirect_location(resource_name, resource)
else
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

@@ -0,0 +1,120 @@
class Devise::RegistrationsController < ApplicationController
prepend_before_filter :require_no_authentication, :only => [ :new, :create, :cancel ]
prepend_before_filter :authenticate_scope!, :only => [:edit, :update, :destroy]
include Devise::Controllers::InternalHelpers
# GET /resource/sign_up
def new
resource = build_resource({})
respond_with_navigational(resource){ render_with_scope :new }
end
# POST /resource
def create
build_resource
if resource.save
if resource.active_for_authentication?
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 => inactive_reason(resource) if is_navigational_format?
expire_session_data_after_sign_in!
respond_with resource, :location => after_inactive_sign_up_path_for(resource)
end
else
clean_up_passwords(resource)
respond_with_navigational(resource) { render_with_scope :new }
end
end
# GET /resource/edit
def edit
render_with_scope :edit
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 if is_navigational_format?
sign_in resource_name, resource, :bypass => true
respond_with resource, :location => after_update_path_for(resource)
else
clean_up_passwords(resource)
respond_with_navigational(resource){ render_with_scope :edit }
end
end
# DELETE /resource
def destroy
resource.destroy
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
# Forces the session data which is usually expired after sign
# in to be expired now. This is useful if the user wants to
# cancel oauth signing in/up in the middle of the process,
# removing all OAuth session data.
def cancel
expire_session_data_after_sign_in!
redirect_to new_registration_path(resource_name)
end
protected
# Build a devise resource passing in the session. Useful to move
# temporary session data to the newly created user.
def build_resource(hash=nil)
hash ||= params[resource_name] || {}
self.resource = resource_class.new_with_session(hash, session)
end
# The path used after sign up. You need to overwrite this method
# in your own RegistrationsController.
def after_sign_up_path_for(resource)
after_sign_in_path_for(resource)
end
# Overwrite redirect_for_sign_in so it takes uses after_sign_up_path_for.
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)
root_path
end
# The default url to be used after updating a resource. You need to overwrite
# this method in your own RegistrationsController.
def after_update_path_for(resource)
if defined?(super)
ActiveSupport::Deprecation.warn "Defining after_update_path_for in ApplicationController " <<
"is deprecated. Please add a RegistrationsController to your application and define it there."
super
else
after_sign_in_path_for(resource)
end
end
# Authenticates the current scope and gets the current resource from the session.
def authenticate_scope!
send(:"authenticate_#{resource_name}!", true)
self.resource = send(:"current_#{resource_name}")
end
end

View File

@@ -0,0 +1,47 @@
class Devise::SessionsController < ApplicationController
prepend_before_filter :require_no_authentication, :only => [ :new, :create ]
include Devise::Controllers::InternalHelpers
# GET /resource/sign_in
def new
resource = build_resource
clean_up_passwords(resource)
respond_with_navigational(resource, stub_options(resource)){ render_with_scope :new }
end
# POST /resource/sign_in
def create
resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#new")
set_flash_message(:notice, :signed_in) if is_navigational_format?
sign_in(resource_name, resource)
respond_with resource, :location => redirect_location(resource_name, resource)
end
# GET /resource/sign_out
def destroy
signed_in = signed_in?(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

@@ -0,0 +1,35 @@
class Devise::UnlocksController < ApplicationController
prepend_before_filter :require_no_authentication
include Devise::Controllers::InternalHelpers
# GET /resource/unlock/new
def new
build_resource({})
render_with_scope :new
end
# POST /resource/unlock
def create
self.resource = resource_class.send_unlock_instructions(params[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
respond_with_navigational(resource){ render_with_scope :new }
end
end
# GET /resource/unlock?unlock_token=abcdef
def show
self.resource = resource_class.unlock_access_by_token(params[:unlock_token])
if resource.errors.empty?
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
respond_with_navigational(resource.errors, :status => :unprocessable_entity){ render_with_scope :new }
end
end
end

View File

@@ -1,42 +0,0 @@
class PasswordsController < ApplicationController
include Devise::Controllers::Helpers
before_filter :require_no_authentication
# GET /resource/password/new
def new
build_resource
render_with_scope :new
end
# POST /resource/password
def create
self.resource = resource_class.send_reset_password_instructions(params[resource_name])
if resource.errors.empty?
set_flash_message :success, :send_instructions
redirect_to new_session_path(resource_name)
else
render_with_scope :new
end
end
# GET /resource/password/edit?reset_password_token=abcdef
def edit
self.resource = resource_class.new
resource.reset_password_token = params[:reset_password_token]
render_with_scope :edit
end
# PUT /resource/password
def update
self.resource = resource_class.reset_password!(params[resource_name])
if resource.errors.empty?
set_flash_message :success, :updated
sign_in_and_redirect(resource_name, resource)
else
render_with_scope :edit
end
end
end

View File

@@ -1,33 +0,0 @@
class SessionsController < ApplicationController
include Devise::Controllers::Helpers
before_filter :require_no_authentication, :only => [ :new, :create ]
# GET /resource/sign_in
def new
Devise::FLASH_MESSAGES.each do |message|
set_now_flash_message :failure, message if params.try(:[], message) == "true"
end
build_resource
render_with_scope :new
end
# POST /resource/sign_in
def create
if authenticate(resource_name)
set_flash_message :success, :signed_in
sign_in_and_redirect(resource_name)
else
set_now_flash_message :failure, warden.message || :invalid
build_resource
render_with_scope :new
end
end
# GET /resource/sign_out
def destroy
set_flash_message :success, :signed_out if signed_in?(resource_name)
sign_out_and_redirect(resource_name)
end
end

View File

@@ -0,0 +1,25 @@
module DeviseHelper
# A simple way to show error messages for the current devise resource. If you need
# to customize this method, you can either overwrite it in your application helpers or
# copy the views to your application.
#
# This method is intended to stay simple and it is unlikely that we are going to change
# it to add more behavior or options.
def devise_error_messages!
return "" if resource.errors.empty?
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.class.model_name.human.downcase)
html = <<-HTML
<div id="error_explanation">
<h2>#{sentence}</h2>
<ul>#{messages}</ul>
</div>
HTML
html.html_safe
end
end

View File

@@ -0,0 +1,15 @@
class Devise::Mailer < ::ActionMailer::Base
include Devise::Mailers::Helpers
def confirmation_instructions(record)
devise_mail(record, :confirmation_instructions)
end
def reset_password_instructions(record)
devise_mail(record, :reset_password_instructions)
end
def unlock_instructions(record)
devise_mail(record, :unlock_instructions)
end
end

View File

@@ -1,62 +0,0 @@
class DeviseMailer < ::ActionMailer::Base
# Deliver confirmation instructions when the user is created or its email is
# updated, and also when confirmation is manually requested
def confirmation_instructions(record)
setup_mail(record, :confirmation_instructions)
end
# Deliver reset password instructions when manually requested
def reset_password_instructions(record)
setup_mail(record, :reset_password_instructions)
end
private
# Configure default email options
def setup_mail(record, key)
mapping = Devise::Mapping.find_by_class(record.class)
raise "Invalid devise resource #{record}" unless mapping
subject translate(mapping, key)
from mailer_sender(mapping)
recipients record.email
sent_on Time.now
content_type 'text/html'
body render_with_scope(key, mapping, mapping.name => record, :resource => record)
end
def render_with_scope(key, mapping, assigns)
if Devise.scoped_views
begin
render :file => "devise_mailer/#{mapping.as}/#{key}", :body => assigns
rescue ActionView::MissingTemplate
render :file => "devise_mailer/#{key}", :body => assigns
end
else
render :file => "devise_mailer/#{key}", :body => assigns
end
end
def mailer_sender(mapping)
if Devise.mailer_sender.is_a?(Proc)
Devise.mailer_sender.call(mapping.name)
else
Devise.mailer_sender
end
end
# Setup subject namespaced by model. It means you're able to setup your
# messages using specific resource scope, or provide a default one.
# Example (i18n locale file):
#
# en:
# devise:
# mailer:
# confirmation_instructions: '...'
# user:
# confirmation_instructions: '...'
def translate(mapping, key)
I18n.t(:"#{mapping.name}.#{key}", :scope => [:devise, :mailer], :default => key)
end
end

View File

@@ -1,16 +0,0 @@
<h2>Resend confirmation instructions</h2>
<% form_for resource_name, resource, :url => confirmation_path(resource_name) do |f| %>
<%= f.error_messages %>
<p><%= f.label :email %></p>
<p><%= f.text_field :email %></p>
<p><%= f.submit "Resend confirmation instructions" %></p>
<% end %>
<%= link_to "Sign in", new_session_path(resource_name) %><br />
<%- if devise_mapping.recoverable? %>
<%= link_to "Forgot password?", new_password_path(resource_name) %><br />
<% end -%>

View File

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

View File

@@ -0,0 +1,5 @@
<p>Welcome <%= @resource.email %>!</p>
<p>You can confirm your account through the link below:</p>
<p><%= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) %></p>

View File

@@ -0,0 +1,8 @@
<p>Hello <%= @resource.email %>!</p>
<p>Someone has requested a link to change your password, and you can do this through the link below.</p>
<p><%= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @resource.reset_password_token) %></p>
<p>If you didn't request this, please ignore this email.</p>
<p>Your password won't change until you access the link above and create a new one.</p>

View File

@@ -0,0 +1,7 @@
<p>Hello <%= @resource.email %>!</p>
<p>Your account has been locked due to an excessive amount of unsuccessful sign in attempts.</p>
<p>Click the link below to unlock your account:</p>
<p><%= link_to 'Unlock my account', unlock_url(@resource, :unlock_token => @resource.unlock_token) %></p>

View File

@@ -0,0 +1,16 @@
<h2>Change your password</h2>
<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :put }) do |f| %>
<%= devise_error_messages! %>
<%= f.hidden_field :reset_password_token %>
<div><%= f.label :password, "New password" %><br />
<%= f.password_field :password %></div>
<div><%= f.label :password_confirmation, "Confirm new password" %><br />
<%= f.password_field :password_confirmation %></div>
<div><%= f.submit "Change my password" %></div>
<% end %>
<%= render :partial => "devise/shared/links" %>

View File

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

View File

@@ -0,0 +1,25 @@
<h2>Edit <%= resource_name.to_s.humanize %></h2>
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %>
<%= devise_error_messages! %>
<div><%= f.label :email %><br />
<%= f.email_field :email %></div>
<div><%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
<%= f.password_field :password %></div>
<div><%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation %></div>
<div><%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
<%= f.password_field :current_password %></div>
<div><%= f.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,18 @@
<h2>Sign up</h2>
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<div><%= f.label :email %><br />
<%= f.email_field :email %></div>
<div><%= f.label :password %><br />
<%= f.password_field :password %></div>
<div><%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation %></div>
<div><%= f.submit "Sign up" %></div>
<% end %>
<%= render :partial => "devise/shared/links" %>

View File

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

View File

@@ -0,0 +1,25 @@
<%- if controller_name != 'sessions' %>
<%= link_to "Sign in", new_session_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.registerable? && controller_name != 'registrations' %>
<%= link_to "Sign up", new_registration_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.recoverable? && controller_name != 'passwords' %>
<%= link_to "Forgot your password?", new_password_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
<%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %>
<%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.omniauthable? %>
<%- resource_class.omniauth_providers.each do |provider| %>
<%= link_to "Sign in with #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider) %><br />
<% end -%>
<% end -%>

View File

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

View File

@@ -1,5 +0,0 @@
Welcome <%= @resource.email %>!
You can confirm your account through the link below:
<%= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) %>

View File

@@ -1,8 +0,0 @@
Hello <%= @resource.email %>!
Someone has requested a link to change your password, and you can do this through the link below.
<%= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @resource.reset_password_token) %>
If you didn't request this, please ignore this email.
Your password won't change until you access the link above and create a new one.

View File

@@ -1,20 +0,0 @@
<h2>Change your password</h2>
<% form_for resource_name, resource, :url => password_path(resource_name), :html => { :method => :put } do |f| %>
<%= f.error_messages %>
<%= f.hidden_field :reset_password_token %>
<p><%= f.label :password %></p>
<p><%= f.password_field :password %></p>
<p><%= f.label :password_confirmation %></p>
<p><%= f.password_field :password_confirmation %></p>
<p><%= f.submit "Change my password" %></p>
<% end %>
<%= link_to "Sign in", new_session_path(resource_name) %><br />
<%- if devise_mapping.confirmable? %>
<%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %><br />
<% end -%>

View File

@@ -1,16 +0,0 @@
<h2>Forgot your password?</h2>
<% form_for resource_name, resource, :url => password_path(resource_name) do |f| %>
<%= f.error_messages %>
<p><%= f.label :email %></p>
<p><%= f.text_field :email %></p>
<p><%= f.submit "Send me reset password instructions" %></p>
<% end %>
<%= link_to "Sign in", new_session_path(resource_name) %><br />
<%- if devise_mapping.confirmable? %>
<%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %><br />
<% end -%>

View File

@@ -1,25 +0,0 @@
<h2>Sign in</h2>
<%- if devise_mapping.authenticatable? %>
<% form_for resource_name, resource, :url => session_path(resource_name) do |f| -%>
<p><%= f.label :email %></p>
<p><%= f.text_field :email %></p>
<p><%= f.label :password %></p>
<p><%= f.password_field :password %></p>
<% if devise_mapping.rememberable? -%>
<p><%= f.check_box :remember_me %> <%= f.label :remember_me %></p>
<% end -%>
<p><%= f.submit "Sign in" %></p>
<% end -%>
<% end%>
<%- if devise_mapping.recoverable? %>
<%= link_to "Forgot password?", new_password_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.confirmable? %>
<%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %><br />
<% end -%>

57
config/locales/en.yml Normal file
View File

@@ -0,0 +1,57 @@
# Additional translations at http://github.com/plataformatec/devise/wiki/I18n
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"
not_saved:
one: "1 error prohibited this %{resource} from being saved:"
other: "%{count} errors prohibited this %{resource} from being saved:"
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.'
invalid: 'Invalid email or password.'
invalid_token: 'Invalid authentication token.'
timeout: 'Your session expired, please sign in again to continue.'
inactive: 'Your account was not activated yet.'
sessions:
signed_in: 'Signed in successfully.'
signed_out: 'Signed out successfully.'
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.'
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}".'
mailer:
confirmation_instructions:
subject: 'Confirmation instructions'
reset_password_instructions:
subject: 'Reset password instructions'
unlock_instructions:
subject: 'Unlock Instructions'

25
devise.gemspec Normal file
View File

@@ -0,0 +1,25 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "devise/version"
Gem::Specification.new do |s|
s.name = "devise"
s.version = Devise::VERSION.dup
s.platform = Gem::Platform::RUBY
s.summary = "Flexible authentication solution for Rails with Warden"
s.email = "contact@plataformatec.com.br"
s.homepage = "http://github.com/plataformatec/devise"
s.description = "Flexible authentication solution for Rails with Warden"
s.authors = ['José Valim', 'Carlos Antônio']
s.rubyforge_project = "devise"
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
s.add_dependency("warden", "~> 1.0.3")
s.add_dependency("orm_adapter", "~> 0.0.3")
s.add_dependency("bcrypt-ruby", "~> 3.0")
end

View File

@@ -1,5 +0,0 @@
To create a devise resource user:
script/generate devise User
This will generate a model named User, a route map for devise called :users, and a migration file for table :users with all devise modules.

View File

@@ -1,15 +0,0 @@
require File.expand_path(File.dirname(__FILE__) + "/lib/route_devise.rb")
class DeviseGenerator < Rails::Generator::NamedBase
def manifest
record do |m|
m.directory(File.join('app', 'models', class_path))
m.template 'model.rb', File.join('app', 'models', "#{file_path}.rb")
m.migration_template 'migration.rb', 'db/migrate', :migration_file_name => "devise_create_#{table_name}"
m.route_devise table_name
end
end
end

View File

@@ -1,32 +0,0 @@
module Rails
module Generator
module Commands
class Create < Base
# Create devise route. Based on route_resources
def route_devise(*resources)
resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
sentinel = 'ActionController::Routing::Routes.draw do |map|'
logger.route "map.devise_for #{resource_list}"
unless options[:pretend]
gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
"#{match}\n map.devise_for #{resource_list}\n"
end
end
end
end
class Destroy < RewindBase
# Destroy devise route. Based on route_resources
def route_devise(*resources)
resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
look_for = "\n map.devise_for #{resource_list}\n"
logger.route "map.devise_for #{resource_list}"
gsub_file 'config/routes.rb', /(#{look_for})/mi, ''
end
end
end
end
end

View File

@@ -1,21 +0,0 @@
class DeviseCreate<%= table_name.camelize %> < ActiveRecord::Migration
def self.up
create_table(:<%= table_name %>) do |t|
t.authenticatable :encryptor => :sha1, :null => false
t.confirmable
t.recoverable
t.rememberable
t.trackable
t.timestamps
end
add_index :<%= table_name %>, :email, :unique => true
add_index :<%= table_name %>, :confirmation_token, :unique => true
add_index :<%= table_name %>, :reset_password_token, :unique => true
end
def self.down
drop_table :<%= table_name %>
end
end

View File

@@ -1,5 +0,0 @@
class <%= class_name %> < ActiveRecord::Base
devise :all
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation
end

View File

@@ -1,3 +0,0 @@
To copy a Devise initializer to your Rails App, with some configuration values, just do:
script/generate devise_install

View File

@@ -1,15 +0,0 @@
class DeviseInstallGenerator < Rails::Generator::Base
def manifest
record do |m|
m.directory "config/initializers"
m.template "devise.rb", "config/initializers/devise.rb"
m.directory "config/locales"
m.file "../../../lib/devise/locales/en.yml", "config/locales/devise.en.yml"
m.readme "README"
end
end
end

View File

@@ -1,86 +0,0 @@
# Use this hook to configure devise mailer, warden hooks and so forth. The first
# four configuration values can also be set straight in your models.
Devise.setup do |config|
# Configure Devise modules used by default. You should always set this value
# because if Devise adds a new strategy, it won't be added to your application
# by default, unless you configure it here.
#
# Remember that Devise includes other modules on its own (like :activatable
# and :timeoutable) which are not included here and also plugins. So be sure
# to check the docs for a complete set.
config.all = [:authenticatable, :confirmable, :recoverable, :rememberable, :trackable, :validatable]
# Configure the e-mail address which will be shown in DeviseMailer.
config.mailer_sender = "please-change-me@config-initializers-devise.com"
# Invoke `rake secret` and use the printed value to setup a pepper to generate
# the encrypted password. By default no pepper is used.
# config.pepper = "rake secret output"
# Configure how many times you want the password is reencrypted. Default is 10.
# config.stretches = 10
# Define which will be the encryption algorithm. Supported algorithms are :sha1
# (default), :sha512 and :bcrypt. Devise also supports encryptors from others
# authentication tools as :clearance_sha1, :authlogic_sha512 (then you should set
# stretches above to 20 for default behavior) and :restful_authentication_sha1
# (then you should set stretches to 10, and copy REST_AUTH_SITE_KEY to pepper)
# config.encryptor = :sha1
# Configure which keys are used when authenticating an user. By default is
# just :email. You can configure it to use [:username, :subdomain], so for
# authenticating an user, both parameters are required. Remember that those
# parameters are used only when authenticating and not when retrieving from
# session. If you need permissions, you should implement that in a before filter.
# config.authentication_keys = [ :email ]
# The time you want give to your user to confirm his account. During this time
# he will be able to access your application without confirming. Default is nil.
# config.confirm_within = 2.days
# The time the user will be remembered without asking for credentials again.
# config.remember_for = 2.weeks
# The time you want to timeout the user session without activity. After this
# time the user will be asked for credentials again.
# config.timeout_in = 10.minutes
# Load and configure the ORM. Supports :active_record, :data_mapper and :mongo_mapper.
# require 'devise/orm/mongo_mapper'
# config.orm = :mongo_mapper
# Turn scoped views on. Before rendering "sessions/new", it will first check for
# "sessions/users/new". It's turned off by default because it's slower if you
# are using only default views.
# config.scoped_views = true
# By default, devise detects the role accessed based on the url. So whenever
# accessing "/users/sign_in", it knows you are accessing an User. This makes
# routes as "/sign_in" not possible, unless you tell Devise to use the default
# scope, setting true below.
# config.use_default_scope = true
# Configure the default scope used by Devise. By default it's the first devise
# role declared in your routes.
# config.default_scope = :user
# If you want to use other strategies, that are not (yet) supported by Devise,
# you can configure them inside the config.warden block. The example below
# allows you to setup OAuth, using http://github.com/roman/warden_oauth
#
# config.warden do |manager|
# manager.oauth(:twitter) do |twitter|
# twitter.consumer_secret = <YOUR CONSUMER SECRET>
# twitter.consumer_key = <YOUR CONSUMER KEY>
# twitter.options :site => 'http://twitter.com'
# end
# manager.default_strategies.unshift :twitter_oauth
# end
# Configure default_url_options if you are using dynamic segments in :path_prefix
# for devise_for.
#
# config.default_url_options do
# { :locale => I18n.locale }
# end
end

View File

@@ -1,3 +0,0 @@
To copy all session, password, confirmation and mailer views from devise to your app just run the following command:
script/generate devise_views

View File

@@ -1,21 +0,0 @@
class DeviseViewsGenerator < Rails::Generator::Base
def initialize(*args)
super
@source_root = options[:source] || File.join(spec.path, '..', '..')
end
def manifest
record do |m|
m.directory "app/views"
Dir[File.join(@source_root, "app", "views", "**/*.erb")].each do |file|
file = file.gsub(@source_root, "")[1..-1]
m.directory File.dirname(file)
m.file file, file
end
end
end
end

View File

@@ -1,2 +0,0 @@
# We need to load devise here to ensure routes extensions are loaded.
require 'devise'

View File

@@ -1,103 +1,158 @@
require 'rails'
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'
autoload :Mapping, 'devise/mapping'
autoload :OmniAuth, 'devise/omniauth'
autoload :PathChecker, 'devise/path_checker'
autoload :Schema, 'devise/schema'
autoload :TestHelpers, 'devise/test_helpers'
module Controllers
autoload :Filters, 'devise/controllers/filters'
autoload :Helpers, 'devise/controllers/helpers'
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
module Encryptors
autoload :Base, 'devise/encryptors/base'
autoload :Bcrypt, 'devise/encryptors/bcrypt'
autoload :AuthlogicSha512, 'devise/encryptors/authlogic_sha512'
autoload :AuthlogicSha1, 'devise/encryptors/authlogic_sha1'
autoload :ClearanceSha1, 'devise/encryptors/clearance_sha1'
autoload :RestfulAuthenticationSha1, 'devise/encryptors/restful_authentication_sha1'
autoload :Sha512, 'devise/encryptors/sha512'
autoload :Sha1, 'devise/encryptors/sha1'
end
module Orm
autoload :ActiveRecord, 'devise/orm/active_record'
autoload :DataMapper, 'devise/orm/data_mapper'
autoload :MongoMapper, 'devise/orm/mongo_mapper'
module Mailers
autoload :Helpers, 'devise/mailers/helpers'
end
ALL = [:authenticatable, :activatable, :confirmable, :recoverable, :rememberable,
:timeoutable, :trackable, :validatable]
module Strategies
autoload :Base, 'devise/strategies/base'
autoload :Authenticatable, 'devise/strategies/authenticatable'
end
# Maps controller names to devise modules
CONTROLLERS = {
:sessions => [:authenticatable],
:passwords => [:recoverable],
:confirmations => [:confirmable]
}
# Constants which holds devise configuration for extensions. Those should
# not be modified by the "end user" (this is why they are constants).
ALL = []
CONTROLLERS = ActiveSupport::OrderedHash.new
ROUTES = ActiveSupport::OrderedHash.new
STRATEGIES = ActiveSupport::OrderedHash.new
URL_HELPERS = ActiveSupport::OrderedHash.new
STRATEGIES = [:authenticatable]
SERIALIZERS = [:session, :cookie]
# Strategies that do not require user input.
NO_INPUT = []
# True values used to check params
TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE']
# Maps the messages types that are used in flash message.
FLASH_MESSAGES = [ :unauthenticated, :unconfirmed, :invalid, :timeout, :inactive ]
# Declare encryptors length which are used in migrations.
ENCRYPTORS_LENGTH = {
:sha1 => 40,
:sha512 => 128,
:clearance_sha1 => 40,
:restful_authentication_sha1 => 40,
:authlogic_sha512 => 128,
:bcrypt => 60
:authlogic_sha512 => 128
}
# Email regex used to validate email formats. Retrieved from authlogic.
EMAIL_REGEX = /\A[\w\.%\+\-]+@(?:[A-Z0-9\-]+\.)+(?:[A-Z]{2,4}|museum|travel)\z/i
# Used to encrypt password. Please generate one with rake secret.
mattr_accessor :pepper
@@pepper = nil
# Custom domain for cookies. Not set by default
mattr_accessor :cookie_options
@@cookie_options = {}
# The number of times to encrypt password.
mattr_accessor :stretches
@@stretches = 10
# Keys used when authenticating an user.
# Keys used when authenticating a user.
mattr_accessor :authentication_keys
@@authentication_keys = [ :email ]
# Time interval where the remember me token is valid.
# Request keys used when authenticating a user.
mattr_accessor :request_keys
@@request_keys = []
# Keys that should be case-insensitive.
# 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
@@http_authenticatable = false
# If http headers should be returned for ajax requests. True by default.
mattr_accessor :http_authenticatable_on_xhr
@@http_authenticatable_on_xhr = true
# If params authenticatable is enabled by default.
mattr_accessor :params_authenticatable
@@params_authenticatable = true
# The realm used in Http Basic Authentication.
mattr_accessor :http_authentication_realm
@@http_authentication_realm = "Application"
# 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[^@]+@([^@\.]+\.)+[^@\.]+\z/
# Range validation for password length
mattr_accessor :password_length
@@password_length = 6..128
# The time the user will be remembered without asking for credentials again.
mattr_accessor :remember_for
@@remember_for = 2.weeks
# If true, a valid remember token can be re-used between multiple browsers.
mattr_accessor :remember_across_browsers
@@remember_across_browsers = true
# If true, extends the user's remember period when remembered via cookie.
mattr_accessor :extend_remember_period
@@extend_remember_period = false
# If true, uses salt as remember token and does not create it in the database.
# By default is false for backwards compatibility.
mattr_accessor :use_salt_as_remember_token
@@use_salt_as_remember_token = false
# Time interval you can access your account before confirming your account.
mattr_accessor :confirm_within
@@confirm_within = 0.days
# Defines which key will be used when confirming an account
mattr_accessor :confirmation_keys
@@confirmation_keys = [ :email ]
# Time interval to timeout the user session without activity.
mattr_accessor :timeout_in
@@timeout_in = 30.minutes
# Used to encrypt password. Please generate one with rake secret.
mattr_accessor :pepper
@@pepper = nil
# Used to define the password encryption algorithm.
mattr_accessor :encryptor
@@encryptor = :sha1
# Store scopes mappings.
mattr_accessor :mappings
@@mappings = {}
# Stores the chosen ORM.
mattr_accessor :orm
@@orm = :active_record
# Configure default options used in :all.
mattr_accessor :all
@@all = Devise::ALL.dup
@@encryptor = nil
# Tells if devise should apply the schema in ORMs where devise declaration
# and schema belongs to the same class (as Datamapper and MongoMapper).
# and schema belongs to the same class (as Datamapper and Mongoid).
mattr_accessor :apply_schema
@@apply_schema = true
@@ -106,9 +161,35 @@ module Devise
mattr_accessor :scoped_views
@@scoped_views = false
# Tell when to use the default scope, if one cannot be found from routes.
mattr_accessor :use_default_scope
@@use_default_scope
# Defines which strategy can be used to lock an account.
# Values: :failed_attempts, :none
mattr_accessor :lock_strategy
@@lock_strategy = :failed_attempts
# Defines which key will be used when locking and unlocking an account
mattr_accessor :unlock_keys
@@unlock_keys = [ :email ]
# Defines which strategy can be used to unlock an account.
# Values: :email, :time, :both
mattr_accessor :unlock_strategy
@@unlock_strategy = :both
# Number of authentication tries before locking an account
mattr_accessor :maximum_attempts
@@maximum_attempts = 20
# Time interval to unlock the account if :time is defined as unlock_strategy.
mattr_accessor :unlock_in
@@unlock_in = 1.hour
# Defines which key will be used when recovering the password for an account
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
@@ -116,70 +197,247 @@ module Devise
# Address which sends Devise e-mails.
mattr_accessor :mailer_sender
@@mailer_sender
@@mailer_sender = nil
class << self
# Default way to setup Devise. Run script/generate devise_install to create
# a fresh initializer with all configuration values.
def setup
yield self
# Authentication token params key name of choice. E.g. /users/sign_in?some_key=...
mattr_accessor :token_authentication_key
@@token_authentication_key = :auth_token
# If true, authentication through token does not store user in session
mattr_accessor :stateless_token
@@stateless_token = false
# Which formats should be treated as navigational.
# We need both :"*/*" and "*/*" to work on different Rails versions.
mattr_accessor :navigational_formats
@@navigational_formats = [:"*/*", "*/*", :html]
# When set to true, signing out a user signs out all other scopes.
mattr_accessor :sign_out_all_scopes
@@sign_out_all_scopes = true
# The default method used while signing out
mattr_accessor :sign_out_via
@@sign_out_via = :get
# PRIVATE CONFIGURATION
# Store scopes mappings.
mattr_reader :mappings
@@mappings = ActiveSupport::OrderedHash.new
# Omniauth configurations.
mattr_reader :omniauth_configs
@@omniauth_configs = ActiveSupport::OrderedHash.new
# Define a set of modules that are called when a mapping is added.
mattr_reader :helpers
@@helpers = Set.new
@@helpers << Devise::Controllers::Helpers
# Private methods to interface with Warden.
mattr_accessor :warden_config
@@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
# Sets warden configuration using a block that will be invoked on warden
# initialization.
#
# Devise.initialize do |config|
# config.confirm_within = 2.days
#
# config.warden do |manager|
# # Configure warden to use other strategies, like oauth.
# manager.oauth(:twitter)
# end
# end
def warden(&block)
@warden_config = block
def get
ActiveSupport::Dependencies.constantize(@name)
end
end
def self.ref(arg)
if defined?(ActiveSupport::Dependencies::ClassCache)
ActiveSupport::Dependencies::reference(arg)
Getter.new(arg)
else
ActiveSupport::Dependencies.ref(arg)
end
end
def self.omniauth_providers
omniauth_configs.keys
end
# Get the mailer class from the mailer reference object.
def self.mailer
@@mailer_ref.get
end
# Set the mailer reference object to access the mailer.
def self.mailer=(class_name)
@@mailer_ref = ref(class_name)
end
self.mailer = "Devise::Mailer"
# Small method that adds a mapping to Devise.
def self.add_mapping(resource, options)
mapping = Devise::Mapping.new(resource, options)
@@mappings[mapping.name] = mapping
@@default_scope ||= mapping.name
@@helpers.each { |h| h.define_helpers(mapping) }
mapping
end
# Make Devise aware of an 3rd party Devise-module (like invitable). For convenience.
#
# == Options:
#
# +model+ - String representing the load path to a custom *model* for this module (to autoload.)
# +controller+ - Symbol representing the name of an exisiting or custom *controller* for this module.
# +route+ - Symbol representing the named *route* helper for this module.
# +strategy+ - Symbol representing if this module got a custom *strategy*.
#
# All values, except :model, accept also a boolean and will have the same name as the given module
# name.
#
# == Examples:
#
# Devise.add_module(:party_module)
# Devise.add_module(:party_module, :strategy => true, :controller => :sessions)
# Devise.add_module(:party_module, :model => 'party_module/model')
#
def self.add_module(module_name, options = {})
ALL << module_name
options.assert_valid_keys(:strategy, :model, :controller, :route)
if strategy = options[:strategy]
strategy = (strategy == true ? module_name : strategy)
STRATEGIES[module_name] = strategy
end
# Configure default url options to be used within Devise and ActionController.
def default_url_options(&block)
Devise::Mapping.metaclass.send :define_method, :default_url_options, &block
if controller = options[:controller]
controller = (controller == true ? module_name : controller)
CONTROLLERS[module_name] = controller
end
# A method used internally to setup warden manager from the Rails initialize
# block.
def configure_warden(config) #:nodoc:
config.default_strategies *Devise::STRATEGIES
config.default_serializers *Devise::SERIALIZERS
config.failure_app = Devise::FailureApp
config.silence_missing_strategies!
config.silence_missing_serializers!
config.default_scope = Devise.default_scope
NO_INPUT << strategy if strategy && controller != :sessions
# If the user provided a warden hook, call it now.
@warden_config.try :call, config
if route = options[:route]
case route
when TrueClass
key, value = module_name, []
when Symbol
key, value = route, []
when Hash
key, value = route.keys.first, route.values.flatten
else
raise ArgumentError, ":route should be true, a Symbol or a Hash"
end
URL_HELPERS[key] ||= []
URL_HELPERS[key].concat(value)
URL_HELPERS[key].uniq!
ROUTES[module_name] = key
end
# The class of the configured ORM
def orm_class
Devise::Orm.const_get(@@orm.to_s.camelize.to_sym)
if options[:model]
path = (options[:model] == true ? "devise/models/#{module_name}" : options[:model])
camelized = ActiveSupport::Inflector.camelize(module_name.to_s)
Devise::Models.send(:autoload, camelized.to_sym, path)
end
# Generate a friendly string randomically to be used as token.
def friendly_token
ActiveSupport::SecureRandom.base64(15).tr('+/=', '-_ ').strip.delete("\n")
Devise::Mapping.add_module module_name
end
# Sets warden configuration using a block that will be invoked on warden
# initialization.
#
# Devise.initialize do |config|
# config.confirm_within = 2.days
#
# config.warden do |manager|
# # Configure warden to use other strategies, like oauth.
# manager.oauth(:twitter)
# end
# end
def self.warden(&block)
@@warden_config_block = block
end
# Specify an omniauth provider.
#
# config.omniauth :github, APP_ID, APP_SECRET
#
def self.omniauth(provider, *args)
@@helpers << Devise::OmniAuth::UrlHelpers
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.
def self.include_helpers(scope)
ActiveSupport.on_load(:action_controller) do
include scope::Helpers if defined?(scope::Helpers)
include scope::UrlHelpers
end
ActiveSupport.on_load(:action_view) do
include scope::UrlHelpers
end
end
# Returns true if Rails version is bigger than 3.0.x
def self.rack_session?
Rails::VERSION::STRING[0,3] != "3.0"
end
# Renegeres 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:
@@warden_configured ||= begin
warden_config.failure_app = Devise::FailureApp
warden_config.default_scope = Devise.default_scope
warden_config.intercept_401 = false
Devise.mappings.each_value do |mapping|
warden_config.scope_defaults mapping.name, :strategies => mapping.strategies
end
@@warden_config_block.try :call, Devise.warden_config
true
end
end
# Generate a friendly string randomically to be used as token.
def self.friendly_token
SecureRandom.base64(15).tr('+/=lIO0', 'pqrsxyz')
end
# constant-time comparison algorithm to prevent timing attacks
def self.secure_compare(a, b)
return false if a.blank? || b.blank? || a.bytesize != b.bytesize
l = a.unpack "C#{a.bytesize}"
res = 0
b.each_byte { |byte| res |= byte ^ l.shift }
res == 0
end
end
begin
require 'warden'
rescue
gem 'warden'
require 'warden'
end
# Clear some Warden default configuration which will be overwritten
Warden::Strategies.clear!
Warden::Serializers.clear!
require 'warden'
require 'devise/mapping'
require 'devise/models'
require 'devise/modules'
require 'devise/rails'

View File

@@ -1,186 +0,0 @@
module Devise
module Controllers
# Those filters are convenience methods added to ApplicationController to
# deal with Warden.
module Filters
def self.included(base)
base.class_eval do
helper_method :warden, :signed_in?, :devise_controller?,
*Devise.mappings.keys.map { |m| [:"current_#{m}", :"#{m}_signed_in?"] }.flatten
# Use devise default_url_options. We have to declare it here to overwrite
# default definitions.
def default_url_options(options=nil)
Devise::Mapping.default_url_options
end
end
end
# The main accessor for the warden proxy instance
def warden
request.env['warden']
end
# Return true if it's a devise_controller. false to all controllers unless
# the controllers defined inside devise. Useful if you want to apply a before
# filter to all controller, except the ones in devise:
#
# before_filter :my_filter, :unless => { |c| c.devise_controller? }
def devise_controller?
false
end
# Attempts to authenticate the given scope by running authentication hooks,
# but does not redirect in case of failures.
def authenticate(scope)
warden.authenticate(:scope => scope)
end
# Attempts to authenticate the given scope by running authentication hooks,
# redirecting in case of failures.
def authenticate!(scope)
warden.authenticate!(:scope => scope)
end
# Check if the given scope is signed in session, without running
# authentication hooks.
def signed_in?(scope)
warden.authenticated?(scope)
end
# Sign in an user that already was authenticated. This helper is useful for logging
# users in after sign up.
#
# Examples:
#
# sign_in :user, @user # sign_in(scope, resource)
# sign_in @user # sign_in(resource)
#
def sign_in(resource_or_scope, resource=nil)
scope ||= Devise::Mapping.find_scope!(resource_or_scope)
resource ||= resource_or_scope
warden.set_user(resource, :scope => scope)
end
# Sign out a given user or scope. This helper is useful for signing out an user
# after deleting accounts.
#
# Examples:
#
# sign_out :user # sign_out(scope)
# sign_out @user # sign_out(resource)
#
def sign_out(resource_or_scope)
scope = Devise::Mapping.find_scope!(resource_or_scope)
warden.user(scope) # Without loading user here, before_logout hook is not called
warden.raw_session.inspect # Without this inspect here. The session does not clear.
warden.logout(scope)
end
# Returns and delete the url stored in the session for the given scope. Useful
# for giving redirect backs after sign up:
#
# Example:
#
# redirect_to stored_location_for(:user) || root_path
#
def stored_location_for(resource_or_scope)
scope = Devise::Mapping.find_scope!(resource_or_scope)
session.delete(:"#{scope}.return_to")
end
# The default url to be used after signing in. This is used by all Devise
# controllers and you can overwrite it in your ApplicationController to
# provide a custom hook for a custom resource.
#
# By default, it first tries to find a resource_root_path, otherwise it
# uses the root path. For a user scope, you can define the default url in
# the following way:
#
# map.user_root '/users', :controller => 'users' # creates user_root_path
#
# map.resources :users do |users|
# users.root # creates user_root_path
# end
#
# If none of these are defined, root_path is used.
def after_sign_in_path_for(resource_or_scope)
scope = Devise::Mapping.find_scope!(resource_or_scope)
home_path = :"#{scope}_root_path"
respond_to?(home_path, true) ? send(home_path) : root_path
end
# The default to be used after signing out. This is used by all Devise
# controllers and you can overwrite it in your ApplicationController to
# provide a custom hook for a custom resource.
#
# By default is the root_path.
def after_sign_out_path_for(resource_or_scope)
root_path
end
# Sign in an user and tries to redirect first to the stored location and
# then to the url specified by after_sign_in_path_for.
#
# If just a symbol is given, consider that the user was already signed in
# through other means and just perform the redirection.
def sign_in_and_redirect(*args)
sign_in(*args) unless args.size == 1 && args.first.is_a?(Symbol)
redirect_to stored_location_for(args.first) || after_sign_in_path_for(args.first)
end
# Sign out an user and tries to redirect to the url specified by
# after_sign_out_path_for.
def sign_out_and_redirect(resource_or_scope)
sign_out(resource_or_scope)
redirect_to after_sign_out_path_for(resource_or_scope)
end
# Define authentication filters and accessor helpers based on mappings.
# These filters should be used inside the controllers as before_filters,
# so you can control the scope of the user who should be signed in to
# access that specific controller/action.
# Example:
#
# Maps:
# User => :authenticatable
# Admin => :authenticatable
#
# Generated methods:
# authenticate_user! # Signs user in or redirect
# authenticate_admin! # Signs admin in or redirect
# user_signed_in? # Checks whether there is an user signed in or not
# admin_signed_in? # Checks whether there is an admin signed in or not
# current_user # Current signed in user
# current_admin # Currend signed in admin
# user_session # Session data available only to the user scope
# admin_session # Session data available only to the admin scope
#
# Use:
# before_filter :authenticate_user! # Tell devise to use :user map
# before_filter :authenticate_admin! # Tell devise to use :admin map
#
Devise.mappings.each_key do |mapping|
class_eval <<-METHODS, __FILE__, __LINE__
def authenticate_#{mapping}!
warden.authenticate!(:scope => :#{mapping})
end
def #{mapping}_signed_in?
warden.authenticated?(:#{mapping})
end
def current_#{mapping}
@current_#{mapping} ||= warden.user(:#{mapping})
end
def #{mapping}_session
warden.session(:#{mapping})
end
METHODS
end
end
end
end

View File

@@ -1,120 +1,232 @@
module Devise
module Controllers
# Those helpers are used only inside Devise controllers and should not be
# included in ApplicationController since they all depend on the url being
# accessed.
# Those helpers are convenience methods added to ApplicationController.
module Helpers
extend ActiveSupport::Concern
def self.included(base)
base.class_eval do
unloadable
included do
helper_method :warden, :signed_in?, :devise_controller?
end
helper_method :resource, :scope_name, :resource_name, :resource_class, :devise_mapping, :devise_controller?
hide_action :resource, :scope_name, :resource_name, :resource_class, :devise_mapping, :devise_controller?
# Define authentication filters and accessor helpers based on mappings.
# These filters should be used inside the controllers as before_filters,
# so you can control the scope of the user who should be signed in to
# access that specific controller/action.
# Example:
#
# Roles:
# User
# Admin
#
# Generated methods:
# authenticate_user! # Signs user in or redirect
# authenticate_admin! # Signs admin in or redirect
# user_signed_in? # Checks whether there is a user signed in or not
# admin_signed_in? # Checks whether there is an admin signed in or not
# current_user # Current signed in user
# current_admin # Current signed in admin
# user_session # Session data available only to the user scope
# admin_session # Session data available only to the admin scope
#
# Use:
# before_filter :authenticate_user! # Tell devise to use :user map
# before_filter :authenticate_admin! # Tell devise to use :admin map
#
def self.define_helpers(mapping) #:nodoc:
mapping = mapping.name
skip_before_filter *Devise.mappings.keys.map { |m| :"authenticate_#{m}!" }
before_filter :is_devise_resource?
class_eval <<-METHODS, __FILE__, __LINE__ + 1
def authenticate_#{mapping}!(force = false)
warden.authenticate!(:scope => :#{mapping}) if !devise_controller? || force
end
def #{mapping}_signed_in?
!!current_#{mapping}
end
def current_#{mapping}
@current_#{mapping} ||= warden.authenticate(:scope => :#{mapping})
end
def #{mapping}_session
current_#{mapping} && warden.session(:#{mapping})
end
METHODS
ActiveSupport.on_load(:action_controller) do
helper_method "current_#{mapping}", "#{mapping}_signed_in?", "#{mapping}_session"
end
end
# Gets the actual resource stored in the instance variable
def resource
instance_variable_get(:"@#{resource_name}")
# The main accessor for the warden proxy instance
def warden
request.env['warden']
end
# Proxy to devise map name
def resource_name
devise_mapping.name
end
alias :scope_name :resource_name
# Proxy to devise map class
def resource_class
devise_mapping.to
end
# Attempt to find the mapped route for devise based on request path
def devise_mapping
@devise_mapping ||= begin
mapping = Devise::Mapping.find_by_path(request.path)
mapping ||= Devise.mappings[Devise.default_scope] if Devise.use_default_scope
mapping
end
end
# Overwrites devise_controller? to return true
# Return true if it's a devise_controller. false to all controllers unless
# the controllers defined inside devise. Useful if you want to apply a before
# filter to all controllers, except the ones in devise:
#
# before_filter :my_filter, :unless => { |c| c.devise_controller? }
def devise_controller?
true
false
end
protected
# Checks whether it's a devise mapped resource or not.
def is_devise_resource? #:nodoc:
raise ActionController::UnknownAction unless devise_mapping && devise_mapping.allows?(controller_name)
end
# Sets the resource creating an instance variable
def resource=(new_resource)
instance_variable_set(:"@#{resource_name}", new_resource)
end
# Build a devise resource without setting password and password confirmation fields.
def build_resource
self.resource ||= begin
attributes = params[resource_name].try(:except, :password, :password_confirmation)
resource_class.new(attributes || {})
# 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)
[ scope || Devise.mappings.keys ].flatten.any? do |scope|
warden.authenticate?(:scope => scope)
end
end
# Helper for use in before_filters where no authentication is required.
# Sign in a user that already was authenticated. This helper is useful for logging
# users in after sign up.
#
# All options given to sign_in is passed forward to the set_user method in warden.
# The only exception is the :bypass option, which bypass warden callbacks and stores
# the user straight in session. This option is useful in cases the user is already
# signed in, but we want to refresh the credentials in session.
#
# Examples:
#
# sign_in :user, @user # sign_in(scope, resource)
# sign_in @user # sign_in(resource)
# sign_in @user, :event => :authentication # sign_in(resource, options)
# sign_in @user, :bypass => true # sign_in(resource, options)
#
def sign_in(resource_or_scope, *args)
options = args.extract_options!
scope = Devise::Mapping.find_scope!(resource_or_scope)
resource = args.last || resource_or_scope
expire_session_data_after_sign_in!
if options[:bypass]
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
end
# Sign out a given user or scope. This helper is useful for signing out a user
# after deleting accounts.
#
# Examples:
#
# sign_out :user # sign_out(scope)
# sign_out @user # sign_out(resource)
#
def sign_out(resource_or_scope=nil)
return sign_out_all_scopes unless resource_or_scope
scope = Devise::Mapping.find_scope!(resource_or_scope)
warden.user(scope) # Without loading user here, before_logout hook is not called
warden.raw_session.inspect # Without this inspect here. The session does not clear.
warden.logout(scope)
end
# Sign out all active users or scopes. This helper is useful for signing out all roles
# in one click. This signs out ALL scopes in warden.
def sign_out_all_scopes
Devise.mappings.keys.each { |s| warden.user(s) }
warden.raw_session.inspect
warden.logout
end
# Returns and delete the url stored in the session for the given scope. Useful
# for giving redirect backs after sign up:
#
# Example:
# before_filter :require_no_authentication, :only => :new
def require_no_authentication
redirect_to after_sign_in_path_for(resource_name) if warden.authenticated?(resource_name)
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.
# Example (i18n locale file):
#
# en:
# devise:
# passwords:
# #default_scope_messages - only if resource_scope is not found
# user:
# #resource_scope_messages
# redirect_to stored_location_for(:user) || root_path
#
# Please refer to README or en.yml locale file to check what messages are
# available.
def set_flash_message(key, kind, now=false)
flash_hash = now ? flash.now : flash
flash_hash[key] = I18n.t(:"#{resource_name}.#{kind}",
:scope => [:devise, controller_name.to_sym], :default => kind)
def stored_location_for(resource_or_scope)
scope = Devise::Mapping.find_scope!(resource_or_scope)
session.delete("#{scope}_return_to")
end
# Shortcut to set flash.now message. Same rules applied from set_flash_message
def set_now_flash_message(key, kind)
set_flash_message(key, kind, true)
# The default url to be used after signing in. This is used by all Devise
# controllers and you can overwrite it in your ApplicationController to
# provide a custom hook for a custom resource.
#
# By default, it first tries to find a resource_root_path, otherwise it
# uses the root path. For a user scope, you can define the default url in
# the following way:
#
# map.user_root '/users', :controller => 'users' # creates user_root_path
#
# map.namespace :user do |user|
# user.root :controller => 'users' # creates user_root_path
# end
#
#
# If the resource root path is not defined, root_path is used. However,
# if this default is not enough, you can customize it, for example:
#
# def after_sign_in_path_for(resource)
# if resource.is_a?(User) && resource.can_publish?
# publisher_url
# else
# super
# end
# end
#
def after_sign_in_path_for(resource_or_scope)
scope = Devise::Mapping.find_scope!(resource_or_scope)
home_path = "#{scope}_root_path"
respond_to?(home_path, true) ? send(home_path) : root_path
end
# Render a view for the specified scope. Turned off by default.
# Accepts just :controller as option.
def render_with_scope(action, options={})
controller_name = options.delete(:controller) || self.controller_name
if Devise.scoped_views
begin
render :template => "#{controller_name}/#{devise_mapping.as}/#{action}"
rescue ActionView::MissingTemplate
render action, :controller => controller_name
end
else
render action, :controller => controller_name
end
# Method used by sessions controller to sign out a user. You can overwrite
# it in your ApplicationController to provide a custom hook for a custom
# scope. Notice that differently from +after_sign_in_path_for+ this method
# receives a symbol with the scope, and not the resource.
#
# By default is the root_path.
def after_sign_out_path_for(resource_or_scope)
root_path
end
# Sign in a user and tries to redirect first to the stored location and
# then to the url specified by after_sign_in_path_for. It accepts the same
# parameters as the sign_in method.
def sign_in_and_redirect(resource_or_scope, *args)
options = args.extract_options!
scope = Devise::Mapping.find_scope!(resource_or_scope)
resource = args.last || resource_or_scope
sign_in(scope, resource, options)
redirect_to redirect_location(scope, resource)
end
def redirect_location(scope, resource) #:nodoc:
stored_location_for(scope) || after_sign_in_path_for(resource)
end
# Sign out a user and tries to redirect to the url specified by
# after_sign_out_path_for.
def sign_out_and_redirect(resource_or_scope)
scope = Devise::Mapping.find_scope!(resource_or_scope)
Devise.sign_out_all_scopes ? sign_out : sign_out(scope)
redirect_to after_sign_out_path_for(scope)
end
# A hook called to expire session data after sign up/in. All keys
# stored under "devise." namespace are removed after sign in.
def expire_session_data_after_sign_in!
session.keys.grep(/^devise\./).each { |k| session.delete(k) }
end
# 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
end
end

View File

@@ -0,0 +1,148 @@
module Devise
module Controllers
# Those helpers are used only inside Devise controllers and should not be
# included in ApplicationController since they all depend on the url being
# accessed.
module InternalHelpers #:nodoc:
extend ActiveSupport::Concern
include Devise::Controllers::ScopedViews
include Devise::Controllers::SharedHelpers
included do
helper DeviseHelper
helpers = %w(resource scope_name resource_name signed_in_resource
resource_class devise_mapping devise_controller?)
hide_action *helpers
helper_method *helpers
prepend_before_filter :is_devise_resource?
respond_to *Mime::SET.map(&:to_sym) if mimes_for_respond_to.empty?
end
# Gets the actual resource stored in the instance variable
def resource
instance_variable_get(:"@#{resource_name}")
end
# Proxy to devise map name
def resource_name
devise_mapping.name
end
alias :scope_name :resource_name
# Proxy to devise map class
def resource_class
devise_mapping.to
end
# Returns a signed in resource from session (if one exists)
def signed_in_resource
warden.authenticate(:scope => resource_name)
end
# Attempt to find the mapped route for devise based on request path
def devise_mapping
@devise_mapping ||= request.env["devise.mapping"]
end
# Overwrites devise_controller? to return true
def devise_controller?
true
end
protected
# Checks whether it's a devise mapped resource or not.
def is_devise_resource? #:nodoc:
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
# 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)
logger.debug "[Devise] #{msg}" if logger
raise ActionController::UnknownAction, msg
end
# Sets the resource creating an instance variable
def resource=(new_resource)
instance_variable_set(:"@#{resource_name}", new_resource)
end
# Build a devise resource.
def build_resource(hash=nil)
hash ||= params[resource_name] || {}
self.resource = resource_class.new(hash)
end
# Helper for use in before_filters where no authentication is required.
#
# Example:
# before_filter :require_no_authentication, :only => :new
def require_no_authentication
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.
# Example (i18n locale file):
#
# en:
# devise:
# passwords:
# #default_scope_messages - only if resource_scope is not found
# user:
# #resource_scope_messages
#
# Please refer to README or en.yml locale file to check what messages are
# available.
def set_flash_message(key, kind, options={}) #:nodoc:
options[:scope] = "devise.#{controller_name}"
options[:default] = Array(options[:default]).unshift(kind.to_sym)
options[:resource_name] = resource_name
message = I18n.t("#{resource_name}.#{kind}", options)
flash[key] = message if message.present?
end
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

@@ -0,0 +1,52 @@
module Devise
module Controllers
# A module that may be optionally included in a controller in order
# to provide remember me behavior.
module Rememberable
# Return default cookie values retrieved from session options.
def self.cookie_values
Rails.configuration.session_options.slice(:path, :domain, :secure)
end
# A small warden proxy so we can remember and forget uses from hooks.
class Proxy #:nodoc:
include Devise::Controllers::Rememberable
delegate :cookies, :env, :to => :@warden
def initialize(warden)
@warden = warden
end
end
# Remembers the given resource by setting up a cookie
def remember_me(resource)
scope = Devise::Mapping.find_scope!(resource)
resource.remember_me!(resource.extend_remember_period)
cookies.signed["remember_#{scope}_token"] = remember_cookie_values(resource)
end
# Forgets the given resource by deleting a cookie
def forget_me(resource)
scope = Devise::Mapping.find_scope!(resource)
resource.forget_me!
cookies.delete("remember_#{scope}_token", forget_cookie_values(resource))
end
protected
def forget_cookie_values(resource)
Devise::Controllers::Rememberable.cookie_values.merge!(resource.cookie_options)
end
def remember_cookie_values(resource)
options = { :httponly => true }
options.merge!(forget_cookie_values(resource))
options.merge!(
:value => resource.class.serialize_into_cookie(resource),
:expires => resource.remember_expires_at
)
end
end
end
end

View File

@@ -0,0 +1,33 @@
module Devise
module Controllers
module ScopedViews
extend ActiveSupport::Concern
module ClassMethods
def scoped_views?
defined?(@scoped_views) ? @scoped_views : Devise.scoped_views
end
def scoped_views=(value)
@scoped_views = value
end
end
protected
# Render a view for the specified scope. Turned off by default.
# Accepts just :controller as option.
def render_with_scope(action, path=self.controller_path)
if self.class.scoped_views?
begin
render :template => "#{devise_mapping.scoped_path}/#{path.split("/").last}/#{action}"
rescue ActionView::MissingTemplate
render :template => "#{path}/#{action}"
end
else
render :template => "#{path}/#{action}"
end
end
end
end
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,32 +18,31 @@ module Devise
#
# Those helpers are added to your ApplicationController.
module UrlHelpers
[:session, :password, :confirmation].each do |module_name|
[:path, :url].each do |path_or_url|
actions = [ nil, :new_ ]
actions << :edit_ if module_name == :password
actions << :destroy_ if module_name == :session
actions.each do |action|
class_eval <<-URL_HELPERS
def #{action}#{module_name}_#{path_or_url}(resource, *args)
resource = case resource
when Symbol, String
resource
when Class
resource.name.underscore
else
resource.class.name.underscore
end
send("#{action}\#{resource}_#{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

@@ -4,10 +4,9 @@ module Devise
module Encryptors
# = AuthlogicSha512
# Simulates Authlogic's default encryption mechanism.
# Warning: it uses Devise's stretches configuration to port Authlogic's one. Should be set to 20 in the initializer to silumate
# Warning: it uses Devise's stretches configuration to port Authlogic's one. Should be set to 20 in the initializer to simulate
# the default behavior.
class AuthlogicSha512 < Base
# Gererates a default password digest based on salt, pepper and the
# incoming password.
def self.digest(password, stretches, salt, pepper)
@@ -15,7 +14,6 @@ module Devise
stretches.times { digest = Digest::SHA512.hexdigest(digest) }
digest
end
end
end
end

View File

@@ -12,8 +12,8 @@ module Devise
raise NotImplemented
end
def self.salt
Devise.friendly_token
def self.salt(stretches)
Devise.friendly_token[0,20]
end
end
end

View File

@@ -1,21 +0,0 @@
require "bcrypt"
module Devise
module Encryptors
# = BCrypt
# Uses the BCrypt hash algorithm to encrypt passwords.
class Bcrypt < Base
# Gererates a default password digest based on stretches, salt, pepper and the
# incoming password. We don't strech it ourselves since BCrypt does so internally.
def self.digest(password, stretches, salt, pepper)
::BCrypt::Engine.hash_secret([password, pepper].join, salt, stretches)
end
def self.salt
::BCrypt::Engine.generate_salt
end
end
end
end

View File

@@ -7,13 +7,11 @@ module Devise
# Warning: it uses Devise's pepper to port the concept of REST_AUTH_SITE_KEY
# Warning: it uses Devise's stretches configuration to port the concept of REST_AUTH_DIGEST_STRETCHES
class ClearanceSha1 < Base
# Gererates a default password digest based on salt, pepper and the
# incoming password.
def self.digest(password, stretches, salt, pepper)
Digest::SHA1.hexdigest("--#{salt}--#{password}--")
end
end
end
end

View File

@@ -5,10 +5,10 @@ module Devise
# = RestfulAuthenticationSha1
# Simulates Restful Authentication's default encryption mechanism.
# Warning: it uses Devise's pepper to port the concept of REST_AUTH_SITE_KEY
# Warning: it uses Devise's stretches configuration to port the concept of REST_AUTH_DIGEST_STRETCHES. Should be set to 10 in
# the initializer to silumate the default behavior.
# Warning: it uses Devise's stretches configuration to port the concept of REST_AUTH_DIGEST_STRETCHES. Should be set to 10 in
# the initializer to simulate the default behavior.
class RestfulAuthenticationSha1 < Base
# Gererates a default password digest based on salt, pepper and the
# incoming password.
def self.digest(password, stretches, salt, pepper)
@@ -19,4 +19,4 @@ module Devise
end
end
end
end

View File

@@ -5,7 +5,6 @@ module Devise
# = Sha1
# Uses the Sha1 hash algorithm to encrypt passwords.
class Sha1 < Base
# Gererates a default password digest based on stretches, salt, pepper and the
# incoming password.
def self.digest(password, stretches, salt, pepper)
@@ -14,14 +13,13 @@ module Devise
digest
end
private
private
# Generate a SHA1 digest joining args. Generated token is something like
# --arg1--arg2--arg3--argN--
def self.secure_digest(*tokens)
::Digest::SHA1.hexdigest('--' << tokens.flatten.join('--') << '--')
end
# Generate a SHA1 digest joining args. Generated token is something like
# --arg1--arg2--arg3--argN--
def self.secure_digest(*tokens)
::Digest::SHA1.hexdigest('--' << tokens.flatten.join('--') << '--')
end
end
end
end

View File

@@ -5,7 +5,6 @@ module Devise
# = Sha512
# Uses the Sha512 hash algorithm to encrypt passwords.
class Sha512 < Base
# Gererates a default password digest based on salt, pepper and the
# incoming password.
def self.digest(password, stretches, salt, pepper)
@@ -14,14 +13,13 @@ module Devise
digest
end
private
private
# Generate a Sha512 digest joining args. Generated token is something like
# --arg1--arg2--arg3--argN--
def self.secure_digest(*tokens)
::Digest::SHA512.hexdigest('--' << tokens.flatten.join('--') << '--')
end
# Generate a Sha512 digest joining args. Generated token is something like
# --arg1--arg2--arg3--argN--
def self.secure_digest(*tokens)
::Digest::SHA512.hexdigest('--' << tokens.flatten.join('--') << '--')
end
end
end
end

View File

@@ -1,65 +1,144 @@
require "action_controller/metal"
module Devise
# Failure application that will be called every time :warden is thrown from
# any strategy or hook. Responsible for redirect the user to the sign in
# page based on current scope and mapping. If no scope is given, redirect
# to the default_url.
class FailureApp
attr_reader :env
include Warden::Mixins::Common
class FailureApp < ActionController::Metal
include ActionController::RackDelegation
include ActionController::UrlFor
include ActionController::Redirecting
include Rails.application.routes.url_helpers
include Devise::Controllers::SharedHelpers
cattr_accessor :default_url, :default_message, :instance_writer => false
@@default_message = :unauthenticated
delegate :flash, :to => :request
def self.call(env)
new(env).respond!
action(:respond).call(env)
end
def initialize(env)
@env = env
def self.default_url_options(*args)
ApplicationController.default_url_options(*args)
end
def respond!
options = @env['warden.options']
scope = options[:scope]
redirect_path = if mapping = Devise.mappings[scope]
"#{mapping.parsed_path}/#{mapping.path_names[:sign_in]}"
def respond
if http_auth?
http_auth
elsif warden_options[:recall]
recall
else
"/#{default_url}"
redirect
end
query_string = query_string_for(options)
store_location!(scope)
headers = {}
headers["Location"] = redirect_path
headers["Location"] << "?" << query_string unless query_string.empty?
headers["Content-Type"] = 'text/plain'
[302, headers, ["You are being redirected to #{redirect_path}"]]
end
# Build the proper query string based on the given message.
def query_string_for(options)
message = @env['warden'].try(:message) || options[:message] || default_message
def http_auth
self.status = 401
self.headers["WWW-Authenticate"] = %(Basic realm=#{Devise.http_authentication_realm.inspect}) if http_auth_header?
self.content_type = request.format.to_s
self.response_body = http_auth_body
end
params = case message
when Symbol
{ message => true }
when String
{ :message => message }
else
{}
def recall
env["PATH_INFO"] = attempted_path
flash.now[:alert] = i18n_message(:invalid)
self.response = recall_app(warden_options[:recall]).call(env)
end
def redirect
store_location!
flash[:alert] = i18n_message
redirect_to redirect_url
end
protected
def i18n_message(default = nil)
message = warden.message || warden_options[:message] || default || :unauthenticated
if message.is_a?(Symbol)
I18n.t(:"#{scope}.#{message}", :resource_name => scope,
:scope => "devise.failure", :default => [message, message.to_s])
else
message.to_s
end
end
Rack::Utils.build_query(params)
def redirect_url
if skip_format?
send(:"new_#{scope}_session_path")
else
send(:"new_#{scope}_session_path", :format => request_format)
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.
#
# This method allows the user to explicitly disable http authentication
# on ajax requests in case they want to redirect on failures instead of
# handling the errors on their own. This is useful in case your ajax API
# is the same as your public API and uses a format like JSON (so you
# cannot mark JSON as a navigational format).
def http_auth?
if request.xhr?
Devise.http_authenticatable_on_xhr
else
!(request_format && is_navigational_format?)
end
end
# It does not make sense to send authenticate headers in ajax requests
# or if the user disabled them.
def http_auth_header?
Devise.mappings[scope].to.http_authenticatable && !request.xhr?
end
def http_auth_body
return i18n_message unless request_format
method = "to_#{request_format}"
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_name = ActiveSupport::Inflector.camelize(controller)
controller_klass = ActiveSupport::Inflector.constantize("#{controller_name}Controller")
controller_klass.action(action)
end
def warden
env['warden']
end
def warden_options
env['warden.options']
end
def scope
@scope ||= warden_options[:scope] || Devise.default_scope
end
def attempted_path
warden_options[:attempted_path]
end
# Stores requested uri to redirect the user after signing in. We cannot use
# scoped session provided by warden here, since the user is not authenticated
# yet, but we still need to store the uri based on scope, so different scopes
# would never use the same uri to redirect.
def store_location!(scope)
session[:"#{scope}.return_to"] ||= request.request_uri if request && request.get?
def store_location!
session["#{scope}_return_to"] = attempted_path if request.get? && !http_auth?
end
end
end

View File

@@ -1,18 +1,11 @@
# Each time the user is set we verify if it is still able to really sign in.
# This is done by checking the time frame the user is able to sign in without
# confirming it's account. If the user has not confirmed it's account during
# this time frame, he/she will not able to sign in anymore.
# Deny user access whenever his account is not active yet. All strategies that inherits from
# Devise::Strategies::Authenticatable and uses the validate already check if the user is active_for_authentication?
# before actively signing him in. However, we need this as hook to validate the user activity
# in each request and in case the user is using other strategies beside Devise ones.
Warden::Manager.after_set_user do |record, warden, options|
if record && record.respond_to?(:active?) && !record.active?
if record && record.respond_to?(:active_for_authentication?) && !record.active_for_authentication?
scope = options[:scope]
warden.logout(scope)
# If winning strategy was set, this is being called after authenticate and
# there is no need to force a redirect.
if warden.winning_strategy
warden.winning_strategy.fail!(record.inactive_message)
else
throw :warden, :scope => scope, :message => record.inactive_message
end
throw :warden, :scope => scope, :message => record.inactive_message
end
end
end

View File

@@ -0,0 +1,9 @@
# 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 not persisted.
# This avoids forgetting deleted users.
Warden::Manager.before_logout do |record, warden, options|
if record.respond_to?(:forget_me!)
Devise::Controllers::Rememberable::Proxy.new(warden).forget_me(record)
end
end

View File

@@ -0,0 +1,6 @@
Warden::Manager.after_set_user :except => :fetch do |record, warden, options|
scope = options[:scope]
if record.respond_to?(:remember_me) && record.remember_me && warden.authenticated?(scope)
Devise::Controllers::Rememberable::Proxy.new(warden).remember_me(record)
end
end

View File

@@ -1,16 +1,22 @@
# Each time a record is set we check whether it's session has already timed out
# 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]
if record && record.respond_to?(:timeout?) && warden.authenticated?(scope)
if record && record.respond_to?(:timedout?) && warden.authenticated?(scope) && options[:store] != false
last_request_at = warden.session(scope)['last_request_at']
if record.timeout?(last_request_at)
warden.logout(scope)
throw :warden, :scope => scope, :message => :timeout
if record.timedout?(last_request_at)
path_checker = Devise::PathChecker.new(warden.env, scope)
unless path_checker.signing_out?
warden.logout(scope)
throw :warden, :scope => scope, :message => :timeout
end
end
warden.session(scope)['last_request_at'] = Time.now.utc
end
end

View File

@@ -1,18 +1,9 @@
# After each sign in, update sign in time, sign in count and sign in IP.
# This is only triggered when the user is explicitly set (with set_user)
# and on authentication. Retrieving the user from session (:fetch) does
# not trigger it.
Warden::Manager.after_set_user :except => :fetch do |record, warden, options|
scope = options[:scope]
if Devise.mappings[scope].try(:trackable?) && warden.authenticated?(scope)
old_current, new_current = record.current_sign_in_at, Time.now
record.last_sign_in_at = old_current || new_current
record.current_sign_in_at = new_current
old_current, new_current = record.current_sign_in_ip, warden.request.remote_ip
record.last_sign_in_ip = old_current || new_current
record.current_sign_in_ip = new_current
record.sign_in_count ||= 0
record.sign_in_count += 1
record.save(false)
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

@@ -1,21 +0,0 @@
en:
devise:
sessions:
signed_in: 'Signed in successfully.'
signed_out: 'Signed out successfully.'
unauthenticated: 'You need to sign in or sign up before continuing.'
unconfirmed: 'You have to confirm your account before continuing.'
invalid: 'Invalid email or password.'
timeout: 'Your session expired, please sign in again to continue.'
inactive: 'Your account was not activated yet.'
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.'
confirmations:
send_instructions: '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.'
mailer:
confirmation_instructions: 'Confirmation instructions'
reset_password_instructions: 'Reset password instructions'

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

@@ -18,120 +18,130 @@ module Devise
# mapping.to #=> User
# # is the class to be loaded from routes, given in the route as :class_name.
#
# mapping.for #=> [:authenticatable]
# mapping.modules #=> [:authenticatable]
# # is the modules included in the class
#
class Mapping #:nodoc:
attr_reader :name, :as, :path_names, :path_prefix, :route_options
# Loop through all mappings looking for a map that matches with the requested
# path (ie /users/sign_in). If a path prefix is given, it's taken into account.
def self.find_by_path(path)
Devise.mappings.each_value do |mapping|
route = path.split("/")[mapping.as_position]
return mapping if route && mapping.as == route.to_sym
end
nil
end
# Find a mapping by a given class. It takes into account single table inheritance as well.
def self.find_by_class(klass)
Devise.mappings.values.find { |m| return m if klass <= m.to }
end
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,
# raises an error. If a symbol is given, it's considered to be the scope.
def self.find_scope!(duck)
if duck.is_a?(Symbol)
duck
case duck
when String, Symbol
return duck
when Class
Devise.mappings.each_value { |m| return m.name if duck <= m.to }
else
klass = duck.is_a?(Class) ? duck : duck.class
mapping = Devise::Mapping.find_by_class(klass)
raise "Could not find a valid mapping for #{duck}" unless mapping
mapping.name
Devise.mappings.each_value { |m| return m.name if duck.is_a?(m.to) }
end
raise "Could not find a valid mapping for #{duck.inspect}"
end
# Default url options which can be used as prefix.
def self.default_url_options
{}
def self.find_by_path!(path, path_type=:fullpath)
Devise.mappings.each_value { |m| return m if path.include?(m.send(path_type)) }
raise "Could not find a valid mapping for path #{path.inspect}"
end
def initialize(name, options) #:nodoc:
@as = (options.delete(:as) || name).to_sym
@klass = (options.delete(:class_name) || name.to_s.classify).to_s
@name = (options.delete(:scope) || name.to_s.singularize).to_sym
@path_names = options.delete(:path_names) || {}
@path_prefix = options.delete(:path_prefix).to_s
@path_prefix << "/" unless @path_prefix[-1] == ?/
@route_options = options || {}
@scoped_path = options[:as] ? "#{options[:as]}/#{name}" : name.to_s
@singular = (options[:singular] || @scoped_path.tr('/', '_').singularize).to_sym
setup_path_names
end
@class_name = (options[:class_name] || name.to_s.classify).to_s
@ref = Devise.ref(@class_name)
# Return modules for the mapping.
def for
@for ||= to.devise_modules
end
@path = (options[:path] || name).to_s
@path_prefix = options[:path_prefix]
# Reload mapped class each time when cache_classes is false.
def to
return @to if @to
klass = @klass.constantize
@to = klass if Rails.configuration.cache_classes
klass
end
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 }
# Check if the respective controller has a module in the mapping class.
def allows?(controller)
(self.for & CONTROLLERS[controller.to_sym]).present?
end
@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] || {})
# Return in which position in the path prefix devise should find the as mapping.
def as_position
self.path_prefix.count("/")
end
@defaults = Hash.new { |h,k| h[k] = k.to_s }
@defaults.merge!(options[:defaults] || {})
# Returns the raw path using the current relative_url_root, path_prefix and as.
def raw_path
ActionController::Base.relative_url_root.to_s + path_prefix + as.to_s
end
@sign_out_via = options[:sign_out_via] || Devise.sign_out_via
@format = options[:format]
# Returns the parsed path. If you need meta information in your path_prefix,
# you should overwrite this method to use it. The only information supported
# by default is I18n.locale.
#
def parsed_path
returning raw_path do |path|
self.class.default_url_options.each do |key, value|
path.gsub!(key.inspect, value.to_s)
end
singularizer = lambda { |s| s.to_s.singularize.to_sym }
if options.has_key?(:only)
@used_routes = self.routes & Array(options[:only]).map(&singularizer)
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.
def modules
@modules ||= to.respond_to?(:devise_modules) ? to.devise_modules : []
end
# Gives the class the mapping points to.
def to
@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
def authenticatable?
@authenticatable ||= self.modules.any? { |m| m.to_s =~ /authenticatable/ }
end
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:
#
# def confirmable?
# self.for.include?(:confirmable)
# self.modules.include?(:confirmable)
# end
#
ALL.each do |m|
class_eval <<-METHOD, __FILE__, __LINE__
def self.add_module(m)
class_eval <<-METHOD, __FILE__, __LINE__ + 1
def #{m}?
self.for.include?(:#{m})
self.modules.include?(:#{m})
end
METHOD
end
private
# Configure default path names, allowing the user overwrite defaults by
# passing a hash in :path_names.
def setup_path_names
[:sign_in, :sign_out, :password, :confirmation].each do |path_name|
@path_names[path_name] ||= path_name.to_s
end
end
end
end

View File

@@ -1,18 +1,8 @@
module Devise
module Models
autoload :Activatable, 'devise/models/activatable'
autoload :Authenticatable, 'devise/models/authenticatable'
autoload :Confirmable, 'devise/models/confirmable'
autoload :Recoverable, 'devise/models/recoverable'
autoload :Rememberable, 'devise/models/rememberable'
autoload :SessionSerializer, 'devise/models/session_serializer'
autoload :Timeoutable, 'devise/models/timeoutable'
autoload :Trackable, 'devise/models/trackable'
autoload :Validatable, 'devise/models/validatable'
# Creates configuration values for Devise and for the given module.
#
# Devise::Models.config(Devise::Authenticable, :stretches, 10)
# Devise::Models.config(Devise::Authenticatable, :stretches, 10)
#
# The line above creates:
#
@@ -27,8 +17,11 @@ 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__
mod.class_eval <<-METHOD, __FILE__, __LINE__ + 1
def #{accessor}
if defined?(@#{accessor})
@#{accessor}
@@ -46,93 +39,53 @@ module Devise
end
end
# Shortcut method for including all devise modules inside your model.
# You can give some extra options while declaring devise in your model:
# Include the chosen devise modules in your model:
#
# * except: convenient option that allows you to add all devise modules,
# removing only the modules you setup here:
# devise :database_authenticatable, :confirmable, :recoverable
#
# devise :all, :except => :rememberable
#
# You can also give the following configuration values in a hash: :pepper,
# :stretches, :confirm_within and :remember_for. Please check your Devise
# initialiazer for a complete description on those values.
#
# Examples:
#
# # include only authenticatable module
# devise :authenticatable
#
# # include authenticatable + confirmable modules
# devise :authenticatable, :confirmable
#
# # include authenticatable + recoverable modules
# devise :authenticatable, :recoverable
#
# # include authenticatable + rememberable + validatable modules
# devise :authenticatable, :rememberable, :validatable
#
# # shortcut to include all available modules
# devise :all
#
# # include all except recoverable
# devise :all, :except => :recoverable
# You can also give any of the devise configuration values in form of a hash,
# with specific values for this model. Please check your Devise initializer
# for a complete description on those values.
#
def devise(*modules)
raise "You need to give at least one Devise module" if modules.empty?
include Devise::Models::Authenticatable
options = modules.extract_options!.dup
options = modules.extract_options!
modules += Devise.all if modules.delete(:all)
modules -= Array(options.delete(:except))
modules = Devise::ALL & modules.uniq
selected_modules = modules.map(&:to_sym).uniq.sort_by do |s|
Devise::ALL.index(s) || -1 # follow Devise::ALL order
end
Devise.orm_class.included_modules_hook(self, modules) do
modules.each do |m|
devise_modules << m.to_sym
include Devise::Models.const_get(m.to_s.classify)
devise_modules_hook! do
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
# Stores all modules included inside the model, so we are able to verify
# which routes are needed.
def devise_modules
@devise_modules ||= []
end
# Find an initialize a record setting an error if it can't be found.
def find_or_initialize_with_error_by(attribute, value, error=:invalid)
if value.present?
conditions = { attribute => value }
record = find(:first, :conditions => conditions)
end
unless record
record = new
if value.present?
record.send(:"#{attribute}=", value)
else
error, skip_default = :blank, true
end
add_error_on(record, attribute, error, !skip_default)
end
record
end
# Wraps add error logic in a method that works for different frameworks.
def add_error_on(record, attribute, error, add_default=true)
options = add_default ? { :default => error.to_s.gsub("_", " ") } : {}
begin
record.errors.add(attribute, error, options)
rescue ArgumentError
record.errors.add(attribute, error.to_s.gsub("_", " "))
end
# The hook which is called inside devise. So your ORM can include devise
# compatibility stuff.
def devise_modules_hook!
yield
end
end
end
end
require 'devise/models/authenticatable'

View File

@@ -1,16 +0,0 @@
require 'devise/hooks/activatable'
module Devise
module Models
# This module implements the default API required in activatable hook.
module Activatable
def active?
raise NotImplementedError
end
def inactive_message
:inactive
end
end
end
end

View File

@@ -1,104 +1,105 @@
require 'devise/strategies/authenticatable'
require 'devise/models/session_serializer'
require 'devise/hooks/activatable'
require 'devise/models/serializable'
module Devise
module Models
# Authenticable Module, responsible for encrypting password and validating
# authenticity of a user while signing in.
# Authenticatable module. Holds common settings for authentication.
#
# Configuration:
# == Options
#
# You can overwrite configuration values by setting in globally in Devise,
# using devise method or overwriting the respective instance method.
# Authenticatable adds the following options to devise_for:
#
# pepper: encryption key used for creating encrypted password. Each time
# password changes, it's gonna be encrypted again, and this key
# is added to the password and salt to create a secure hash.
# Always use `rake secret' to generate a new key.
# * +authentication_keys+: parameters used for authentication. By default [:email].
#
# stretches: defines how many times the password will be encrypted.
# * +request_keys+: parameters from the request object used for authentication.
# By specifying a symbol (which should be a request method), it will automatically be
# passed to find_for_authentication method and considered in your model lookup.
#
# encryptor: the encryptor going to be used. By default :sha1.
# For instance, if you set :request_keys to [:subdomain], :subdomain will be considered
# as key on authentication. This can also be a hash where the value is a boolean expliciting
# if the value is required or not.
#
# authentication_keys: parameters used for authentication. By default [:email]
# * +http_authenticatable+: if this model allows http authentication. By default true.
# It also accepts an array specifying the strategies that should allow http.
#
# Examples:
# * +params_authenticatable+: if this model allows authentication through request params. By default true.
# It also accepts an array specifying the strategies that should allow params authentication.
#
# User.authenticate('email@test.com', 'password123') # returns authenticated user or nil
# User.find(1).valid_password?('password123') # returns true/false
# == active_for_authentication?
#
# Before authenticating a user and in each request, Devise checks if your model is active by
# calling model.active_for_authentication?. This method is overwriten by other devise modules. For instance,
# :confirmable overwrites .active_for_authentication? to only return true if your model was confirmed.
#
# You overwrite this method yourself, but if you do, don't forget to call super:
#
# def active_for_authentication?
# super && special_condition_is_valid?
# end
#
# Whenever active_for_authentication? returns false, Devise asks the reason why your model is inactive using
# the inactive_message method. You can overwrite it as well:
#
# def inactive_message
# special_condition_is_valid? ? super : :special_condition_is_not_valid
# end
#
module Authenticatable
def self.included(base)
base.class_eval do
extend ClassMethods
extend SessionSerializer
extend ActiveSupport::Concern
attr_reader :password, :old_password
attr_accessor :password_confirmation
end
include Devise::Models::Serializable
included do
class_attribute :devise_modules, :instance_writer => false
self.devise_modules ||= []
end
# Regenerates password salt and encrypted password each time password is set.
def password=(new_password)
@password = new_password
if @password.present?
self.password_salt = self.class.encryptor_class.salt
self.encrypted_password = password_digest(@password)
end
end
# Verifies whether an incoming_password (ie from sign in) is the user password.
def valid_password?(incoming_password)
password_digest(incoming_password) == encrypted_password
end
# Checks if a resource is valid upon authentication.
def valid_for_authentication?(attributes)
valid_password?(attributes[:password])
end
# Update record attributes when :old_password matches, otherwise returns
# error on :old_password.
def update_with_password(params={})
if valid_password?(params[:old_password])
update_attributes(params)
# Check if the current object is valid for authentication. This method and
# find_for_authentication are the methods used in a Warden::Strategy to check
# if a model should be signed in or not.
#
# However, you should not overwrite this method, you should overwrite active_for_authentication?
# and inactive_message instead.
def valid_for_authentication?
if active_for_authentication?
block_given? ? yield : true
else
self.class.add_error_on(self, :old_password, :invalid, false)
false
inactive_message
end
end
protected
def active_for_authentication?
true
end
# Digests the password using the configured encryptor.
def password_digest(password)
self.class.encryptor_class.digest(password, self.class.stretches, password_salt, self.class.pepper)
end
def inactive_message
:inactive
end
def authenticatable_salt
end
module ClassMethods
# Authenticate a user based on configured attribute keys. Returns the
# authenticated user if it's valid or nil. Attributes are by default
# :email and :password, but the latter is always required.
def authenticate(attributes={})
return unless authentication_keys.all? { |k| attributes[k].present? }
conditions = attributes.slice(*authentication_keys)
resource = find_for_authentication(conditions)
if respond_to?(:valid_for_authentication)
ActiveSupport::Deprecation.warn "valid_for_authentication class method is deprecated. " <<
"Use valid_for_authentication? in the instance instead."
valid_for_authentication(resource, attributes)
elsif resource.try(:valid_for_authentication?, attributes)
resource
end
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
# Returns the class for the configured encryptor.
def encryptor_class
@encryptor_class ||= ::Devise::Encryptors.const_get(encryptor.to_s.classify)
def serialize_from_session(key, salt)
record = to_adapter.get(key)
record if record && record.authenticatable_salt == salt
end
protected
def params_authenticatable?(strategy)
params_authenticatable.is_a?(Array) ?
params_authenticatable.include?(strategy) : params_authenticatable
end
def http_authenticatable?(strategy)
http_authenticatable.is_a?(Array) ?
http_authenticatable.include?(strategy) : http_authenticatable
end
# Find first record based on conditions given (ie by the sign in form).
# Overwrite to add customized conditions, create a join, or maybe use a
@@ -107,15 +108,68 @@ module Devise
#
# def self.find_for_authentication(conditions={})
# conditions[:active] = true
# find(:first, :conditions => conditions)
# super
# end
#
def find_for_authentication(conditions)
find(:first, :conditions => 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
Devise::Models.config(self, :pepper, :stretches, :encryptor, :authentication_keys)
# Find an initialize a record setting an error if it can't be found.
def find_or_initialize_with_error_by(attribute, value, error=:invalid) #:nodoc:
find_or_initialize_with_errors([attribute], { attribute => value }, error)
end
# 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
required_attributes.each do |key|
value = attributes[key]
record.send("#{key}=", value)
record.errors.add(key, value.present? ? error : :blank)
end
end
record
end
protected
# 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 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)
loop do
token = Devise.friendly_token
break token unless to_adapter.find_first({ column => token })
end
end
end
end
end
end
end

View File

@@ -1,107 +1,90 @@
require 'devise/models/activatable'
module Devise
module Models
# Confirmable is responsible to verify if an account is already confirmed to
# sign in, and to send emails with confirmation instructions.
# Confirmation instructions are sent to the user email after creating a
# record, after updating it's email and also when manually requested by
# a new confirmation instruction request.
# Whenever the user update it's email, his account is automatically unconfirmed,
# it means it won't be able to sign in again without confirming the account
# again through the email that was sent.
# record and when manually requested by a new confirmation instruction request.
#
# Configuration:
# == Options
#
# confirm_within: the time you want the user will have to confirm it's account
# without blocking his access. 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 7 days). By default confirm_within is
# zero, it means users always have to confirm to sign in.
# Confirmable adds the following options to devise_for:
#
# Examples:
# * +confirm_within+: the time you want to allow the user to access his account
# before confirming it. After this period, the user access is denied. 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 7 days).
# By default confirm_within is zero, it means users always have to confirm to sign in.
#
# == Examples
#
# User.find(1).confirm! # returns true unless it's already confirmed
# User.find(1).confirmed? # true/false
# User.find(1).send_confirmation_instructions # manually send instructions
# User.find(1).resend_confirmation! # generates a new token and resent it
#
module Confirmable
include Devise::Models::Activatable
extend ActiveSupport::Concern
def self.included(base)
base.class_eval do
extend ClassMethods
before_create :generate_confirmation_token, :if => :confirmation_required?
after_create :send_confirmation_instructions, :if => :confirmation_required?
end
included do
before_create :generate_confirmation_token, :if => :confirmation_required?
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
self.confirmation_token = nil
self.confirmed_at = Time.now
save(false)
save(:validate => false)
end
end
# Verifies whether a user is confirmed or not
def confirmed?
!new_record? && !confirmed_at.nil?
!!confirmed_at
end
# Send confirmation instructions by email
def send_confirmation_instructions
::DeviseMailer.deliver_confirmation_instructions(self)
generate_confirmation_token! if self.confirmation_token.nil?
::Devise.mailer.confirmation_instructions(self).deliver
end
# Remove confirmation date and send confirmation instructions, to ensure
# after sending these instructions the user won't be able to sign in without
# confirming it's account
def resend_confirmation!
unless_confirmed do
generate_confirmation_token
save(false)
send_confirmation_instructions
end
# Resend confirmation token. This method does not need to generate a new token.
def resend_confirmation_token
unless_confirmed { send_confirmation_instructions }
end
# Overwrites active? from Devise::Models::Activatable for confirmation
# by verifying whether an user is active to sign in or not. If the user
# Overwrites active_for_authentication? for confirmation
# by verifying whether a user is active to sign in or not. If the user
# is already confirmed, it should never be blocked. Otherwise we need to
# calculate if the confirm time has not expired for this user.
def active?
confirmed? || confirmation_period_valid?
def active_for_authentication?
super && (!confirmation_required? || confirmed? || confirmation_period_valid?)
end
# The message to be shown if the account is inactive.
def inactive_message
:unconfirmed
!confirmed? ? :unconfirmed : super
end
# If you don't want confirmation to be sent on create, neither a code
# to be generated, call skip_confirmation!
def skip_confirmation!
self.confirmed_at = Time.now
@skip_confirmation = true
self.confirmed_at = Time.now
end
protected
# Callback to overwrite if confirmation is required or not.
def confirmation_required?
!@skip_confirmation
!confirmed?
end
# 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,7 +110,7 @@ module Devise
unless confirmed?
yield
else
self.class.add_error_on(self, :email, :already_confirmed)
self.errors.add(:email, :already_confirmed)
false
end
end
@@ -136,32 +119,46 @@ module Devise
# this token is being generated
def generate_confirmation_token
self.confirmed_at = nil
self.confirmation_token = Devise.friendly_token
self.confirmation_token = self.class.confirmation_token
self.confirmation_sent_at = Time.now.utc
end
def generate_confirmation_token!
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
def send_confirmation_instructions(attributes={})
confirmable = find_or_initialize_with_error_by(:email, attributes[:email], :not_found)
confirmable.resend_confirmation! unless confirmable.new_record?
confirmable = find_or_initialize_with_errors(confirmation_keys, attributes, :not_found)
confirmable.resend_confirmation_token if confirmable.persisted?
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
def confirm!(attributes={})
confirmable = find_or_initialize_with_error_by(:confirmation_token, attributes[:confirmation_token])
confirmable.confirm! unless confirmable.new_record?
def confirm_by_token(confirmation_token)
confirmable = find_or_initialize_with_error_by(:confirmation_token, confirmation_token)
confirmable.confirm! if confirmable.persisted?
confirmable
end
Devise::Models.config(self, :confirm_within)
# Generate a token checking if one does not already exist in the database.
def confirmation_token
generate_token(:confirmation_token)
end
Devise::Models.config(self, :confirm_within, :confirmation_keys)
end
end
end

View File

@@ -1,21 +0,0 @@
require 'devise/serializers/cookie'
module Devise
module Models
module CookieSerializer
# Create the cookie key using the record id and remember_token
def serialize_into_cookie(record)
"#{record.id}::#{record.remember_token}"
end
# Recreate the user based on the stored cookie
def serialize_from_cookie(cookie)
record_id, record_token = cookie.split('::')
record = find(:first, :conditions => { :id => record_id }) if record_id
record if record.try(:valid_remember_token?, record_token)
end
Devise::Models.config(self, :remember_for)
end
end
end

View File

@@ -0,0 +1,123 @@
require 'devise/strategies/database_authenticatable'
require 'bcrypt'
module Devise
module Models
# Authenticatable Module, responsible for encrypting password and validating
# authenticity of a user while signing in.
#
# == Options
#
# 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
#
# User.find(1).valid_password?('password123') # returns true/false
#
module DatabaseAuthenticatable
extend ActiveSupport::Concern
included do
attr_reader :password, :current_password
attr_accessor :password_confirmation
before_validation :downcase_keys
before_validation :strip_whitespace
end
# Generates password encryption based on the given value.
def password=(new_password)
@password = new_password
self.encrypted_password = password_digest(@password) if @password.present?
end
# 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)
end
# Set password and password confirmation to nil
def clean_up_passwords
self.password = self.password_confirmation = ""
end
# Update record attributes when :current_password matches, otherwise returns
# error on :current_password. It also automatically rejects :password and
# :password_confirmation if they are blank.
def update_with_password(params={})
current_password = params.delete(:current_password)
if params[:password].blank?
params.delete(:password)
params.delete(:password_confirmation) if params[:password_confirmation].blank?
end
result = if valid_password?(current_password)
update_attributes(params)
else
self.attributes = params
self.valid?
self.errors.add(:current_password, current_password.blank? ? :blank : :invalid)
false
end
clean_up_passwords
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
# A reliable way to expose the salt regardless of the implementation.
def authenticatable_salt
self.encrypted_password[0,29] if self.encrypted_password
end
protected
# Downcase case-insensitive keys
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)
::BCrypt::Password.create("#{password}#{self.class.pepper}", :cost => self.class.stretches).to_s
end
module ClassMethods
Devise::Models.config(self, :pepper, :stretches)
# We assume this method already gets the sanitized values from the
# DatabaseAuthenticatable strategy. If you are using this method on
# your own, be sure to sanitize the conditions hash to only include
# the proper fields.
def find_for_database_authentication(conditions)
find_for_authentication(conditions)
end
end
end
end
end

View File

@@ -0,0 +1,72 @@
require 'devise/strategies/database_authenticatable'
module Devise
module Models
# Encryptable Module adds support to several encryptors.
#
# == Options
#
# Encryptable adds the following options to devise_for:
#
# * +pepper+: a random string used to provide a more secure hash.
#
# * +encryptor+: the encryptor going to be used. By default is nil.
#
# == Examples
#
# User.find(1).valid_password?('password123') # returns true/false
#
module Encryptable
extend ActiveSupport::Concern
included do
attr_reader :password, :current_password
attr_accessor :password_confirmation
end
# Generates password salt.
def password=(new_password)
self.password_salt = self.class.password_salt if new_password.present?
super
end
def authenticatable_salt
self.password_salt
end
# Verifies whether an incoming_password (ie from sign in) is the user password.
def valid_password?(incoming_password)
Devise.secure_compare(password_digest(incoming_password), self.encrypted_password)
end
protected
# Digests the password using the configured encryptor.
def password_digest(password)
if self.password_salt.present?
self.class.encryptor_class.digest(password, self.class.stretches, self.password_salt, self.class.pepper)
end
end
module ClassMethods
Devise::Models.config(self, :encryptor)
# Returns the class for the configured encryptor.
def encryptor_class
@encryptor_class ||= case encryptor
when :bcrypt
raise "In order to use bcrypt as encryptor, simply remove :encryptable from your devise model"
when nil
raise "You need to give an :encryptor as option in order to use :encryptable"
else
::Devise::Encryptors.const_get(encryptor.to_s.classify)
end
end
def password_salt
self.encryptor_class.salt(self.stretches)
end
end
end
end
end

View File

@@ -0,0 +1,173 @@
module Devise
module Models
# 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 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+:
#
# * +maximum_attempts+: how many attempts should be accepted before blocking the user.
# * +lock_strategy+: lock the user account by :failed_attempts or :none.
# * +unlock_strategy+: unlock the user account by :time, :email, :both or :none.
# * +unlock_in+: the time you want to lock the user after to lock happens. Only available when unlock_strategy is :time or :both.
# * +unlock_keys+: the keys you want to use when locking and unlocking an account
#
module Lockable
extend ActiveSupport::Concern
delegate :lock_strategy_enabled?, :unlock_strategy_enabled?, :to => "self.class"
# Lock a user setting its locked_at to actual time.
def lock_access!
self.locked_at = Time.now
if unlock_strategy_enabled?(:email)
generate_unlock_token
send_unlock_instructions
end
save(:validate => false)
end
# Unlock a user by cleaning locket_at and failed_attempts.
def unlock_access!
self.locked_at = nil
self.failed_attempts = 0 if respond_to?(:failed_attempts=)
self.unlock_token = nil if respond_to?(:unlock_token=)
save(:validate => false)
end
# Verifies whether a user is locked or not.
def access_locked?
locked_at && !lock_expired?
end
# Send unlock instructions by email
def send_unlock_instructions
::Devise.mailer.unlock_instructions(self).deliver
end
# Resend the unlock instructions if the user is locked.
def resend_unlock_token
if_access_locked { send_unlock_instructions }
end
# Overwrites active_for_authentication? from Devise::Models::Activatable for locking purposes
# by verifying whether a user is active to sign in or not based on locked?
def active_for_authentication?
super && !access_locked?
end
# Overwrites invalid_message from Devise::Models::Authenticatable to define
# the correct reason for blocking the sign in.
def inactive_message
access_locked? ? :locked : super
end
# Overwrites valid_for_authentication? from Devise::Models::Authenticatable
# for verifying whether a user is allowed to sign in or not. If the user
# is locked, it should never be allowed.
def valid_for_authentication?
return super unless persisted? && lock_strategy_enabled?(:failed_attempts)
# Unlock the user if the lock is expired, no matter
# if the user can login or not (wrong password, etc)
unlock_access! if lock_expired?
case (result = super)
when Symbol
return result
when TrueClass
self.failed_attempts = 0
save(:validate => false)
when FalseClass
# PostgreSQL uses nil as the default value for integer columns set to 0
self.failed_attempts ||= 0
self.failed_attempts += 1
if attempts_exceeded?
lock_access!
return :locked
else
save(:validate => false)
end
end
result
end
protected
def attempts_exceeded?
self.failed_attempts > self.class.maximum_attempts
end
# Generates unlock token
def generate_unlock_token
self.unlock_token = self.class.unlock_token
end
# Tells if the lock is expired if :time unlock strategy is active
def lock_expired?
if unlock_strategy_enabled?(:time)
locked_at && locked_at < self.class.unlock_in.ago
else
false
end
end
# Checks whether the record is locked or not, yielding to the block
# if it's locked, otherwise adds an error to email.
def if_access_locked
if access_locked?
yield
else
self.errors.add(:email, :not_locked)
false
end
end
module ClassMethods
# 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
def send_unlock_instructions(attributes={})
lockable = find_or_initialize_with_errors(unlock_keys, attributes, :not_found)
lockable.resend_unlock_token if lockable.persisted?
lockable
end
# 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
def unlock_access_by_token(unlock_token)
lockable = find_or_initialize_with_error_by(:unlock_token, unlock_token)
lockable.unlock_access! if lockable.persisted?
lockable
end
# Is the unlock enabled for the given unlock strategy?
def unlock_strategy_enabled?(strategy)
[:both, strategy].include?(self.unlock_strategy)
end
# Is the lock enabled for the given lock strategy?
def lock_strategy_enabled?(strategy)
self.lock_strategy == strategy
end
def unlock_token
Devise.friendly_token
end
Devise::Models.config(self, :maximum_attempts, :lock_strategy, :unlock_strategy, :unlock_in, :unlock_keys)
end
end
end
end

View File

@@ -0,0 +1,23 @@
require 'devise/omniauth'
module Devise
module Models
# Adds OmniAuth support to your model.
#
# == Options
#
# Oauthable adds the following options to devise_for:
#
# * +omniauth_providers+: Which providers are avaialble to this model. It expects an array:
#
# devise_for :database_authenticatable, :omniauthable, :omniauth_providers => [:twitter]
#
module Omniauthable
extend ActiveSupport::Concern
module ClassMethods
Devise::Models.config(self, :omniauth_providers)
end
end
end
end

View File

@@ -1,8 +1,15 @@
module Devise
module Models
# Recoverable takes care of reseting the user password and send reset instructions
# Examples:
# Recoverable takes care of reseting the user password and send reset instructions.
#
# ==Options
#
# Recoverable adds the following options to devise_for:
#
# * +reset_password_keys+: the keys you want to use when recovering the password for an account
#
# == Examples
#
# # resets the user password and save the record, true if valid passwords are given, otherwise false
# User.find(1).reset_password!('password123', 'password123')
@@ -13,67 +20,116 @@ module Devise
#
# # creates a new token and send it with instructions about how to reset the password
# User.find(1).send_reset_password_instructions
#
module Recoverable
def self.included(base)
base.class_eval do
extend ClassMethods
end
end
extend ActiveSupport::Concern
# Update password saving the record and clearing token. Returns true if
# the passwords are valid and the record was saved, false otherwise.
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!
::DeviseMailer.deliver_reset_password_instructions(self)
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 = Devise.friendly_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
# validating
def generate_reset_password_token!
generate_reset_password_token && save(false)
generate_reset_password_token && save(:validate => false)
end
# 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
def send_reset_password_instructions(attributes={})
recoverable = find_or_initialize_with_error_by(:email, attributes[:email], :not_found)
recoverable.send_reset_password_instructions unless recoverable.new_record?
recoverable = find_or_initialize_with_errors(reset_password_keys, attributes, :not_found)
recoverable.send_reset_password_instructions if recoverable.persisted?
recoverable
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
# Generate a token checking if one does not already exist in the database.
def reset_password_token
generate_token(:reset_password_token)
end
# 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!(attributes={})
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]) unless recoverable.new_record?
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, :reset_password_within)
end
end
end

View File

@@ -0,0 +1,21 @@
module Devise
module Models
# Registerable is responsible for everything related to registering a new
# resource (ie user sign up).
module Registerable
extend ActiveSupport::Concern
module ClassMethods
# A convenience method that receives both parameters and session to
# initialize a user. This can be used by OAuth, for example, to send
# in the user token and be stored on initialization.
#
# By default discards all information sent by the session by calling
# new with params.
def new_with_session(params, session)
new(params)
end
end
end
end
end

View File

@@ -1,4 +1,6 @@
require 'devise/models/cookie_serializer'
require 'devise/strategies/rememberable'
require 'devise/hooks/rememberable'
require 'devise/hooks/forgetable'
module Devise
module Models
@@ -9,16 +11,27 @@ module Devise
# You probably wouldn't use rememberable methods directly, they are used
# mostly internally for handling the remember token.
#
# Configuration:
# == Options
#
# remember_for: the time you want the user will be remembered without
# asking for credentials. After this time the user will be
# blocked and will have to enter his credentials again.
# This configuration is also used to calculate the expires
# time for the cookie created to remember the user.
# By default remember_for is 2.weeks.
# Rememberable adds the following options in devise_for:
#
# Examples:
# * +remember_for+: the time you want the user will be remembered without
# asking for credentials. After this time the user will be blocked and
# will have to enter his credentials again. This configuration is also
# used to calculate the expires time for the cookie created to remember
# the user. By default remember_for is 2.weeks.
#
# * +remember_across_browsers+: if a valid remember token can be re-used
# between multiple browsers. By default remember_across_browsers is true
# and cannot be turned off if you are using password salt instead of remember
# token.
#
# * +extend_remember_period+: if true, extends the user's remember period
# when remembered via cookie. False by default.
#
# * +cookie_options+: configuration options passed to the created cookie.
#
# == Examples
#
# User.find(1).remember_me! # regenerating the token
# User.find(1).forget_me! # clearing the token
@@ -29,47 +42,88 @@ module Devise
# # lookup the user based on the incoming cookie information
# User.serialize_from_cookie(cookie_string)
module Rememberable
extend ActiveSupport::Concern
def self.included(base)
base.class_eval do
extend CookieSerializer
attr_accessor :remember_me, :extend_remember_period
# Remember me option available in after_authentication hook.
attr_accessor :remember_me
end
# Generate a new remember token and save the record without validations
# unless remember_across_browsers is true and the user already has a valid token.
def remember_me!(extend_period=false)
self.remember_token = self.class.remember_token if respond_to?(:remember_token) && generate_remember_token?
self.remember_created_at = Time.now.utc if generate_remember_timestamp?(extend_period)
save(:validate => false)
end
# Generate a new remember token and save the record without validations.
def remember_me!
self.remember_token = Devise.friendly_token
self.remember_created_at = Time.now.utc
save(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!
if remember_token
self.remember_token = nil
if persisted?
self.remember_token = nil if respond_to?(:remember_token=)
self.remember_created_at = nil
save(false)
save(:validate => false)
end
end
# Checks whether the incoming token matches or not with the record token.
def valid_remember_token?(token)
remember_token && !remember_expired? && remember_token == token
end
# Remember token should be expired if expiration time not overpass now.
def remember_expired?
remember_expires_at <= Time.now.utc
remember_created_at.nil? || (remember_expires_at <= Time.now.utc)
end
# Remember token expires at created time + remember_for configuration
def remember_expires_at
remember_created_at + self.class.remember_for
end
def rememberable_value
if respond_to?(:remember_token)
remember_token
elsif respond_to?(:authenticatable_salt) && (salt = authenticatable_salt)
salt
else
raise "The #{self.class.name} class does not respond to remember_token and " <<
"authenticatable_salt returns nil. In order to use rememberable, you must " <<
"add a remember_token field to your model or ensure a password is always set."
end
end
def cookie_options
self.class.cookie_options
end
protected
# Generate a token unless remember_across_browsers is true and there is
# an existing remember_token or the existing remember_token has expried.
def generate_remember_token? #:nodoc:
!(self.class.remember_across_browsers && remember_token) || remember_expired?
end
# Generate a timestamp if extend_remember_period is true, if no remember_token
# exists, or if an existing remember token has expired.
def generate_remember_timestamp?(extend_period) #:nodoc:
extend_period || remember_created_at.nil? || remember_expired?
end
module ClassMethods
# Create the cookie key using the record id and remember_token
def serialize_into_cookie(record)
[record.to_key, record.rememberable_value]
end
# Recreate the user based on the stored cookie
def serialize_from_cookie(id, remember_token)
record = to_adapter.get(id)
record if record && record.rememberable_value == remember_token && !record.remember_expired?
end
# Generate a token checking if one does not already exist in the database.
def remember_token
generate_token(:remember_token)
end
Devise::Models.config(self, :remember_for, :remember_across_browsers,
:extend_remember_period, :cookie_options)
end
end
end
end

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

@@ -1,19 +0,0 @@
require 'devise/serializers/session'
module Devise
module Models
module SessionSerializer
# Hook to serialize user into session. Overwrite if you want.
def serialize_into_session(record)
[record.class, record.id]
end
# Hook to serialize user from session. Overwrite if you want.
def serialize_from_session(keys)
klass, id = keys
raise "#{self} cannot serialize from #{klass} session since it's not one of its ancestors" unless klass <= self
klass.find(:first, :conditions => { :id => id })
end
end
end
end

View File

@@ -2,25 +2,39 @@ require 'devise/hooks/timeoutable'
module Devise
module Models
# Timeoutable takes care of veryfing whether a user session has already
# expired or not. When a session expires after the configured time, the user
# will be asked for credentials again, it means, he/she will be redirected
# to the sign in page.
#
# Configuration:
# == Options
#
# Timeoutable adds the following options to devise_for:
#
# * +timeout_in+: the interval to timeout the user session without activity.
#
# == Examples
#
# user.timedout?(30.minutes.ago)
#
# timeout: the time you want to timeout the user session without activity.
module Timeoutable
def self.included(base)
base.extend ClassMethods
end
extend ActiveSupport::Concern
# Checks whether the user session has expired based on configured time.
def timeout?(last_access)
def timedout?(last_access)
return false if remember_exists_and_not_expired?
last_access && last_access <= self.class.timeout_in.ago
end
private
def remember_exists_and_not_expired?
return false unless respond_to?(:remember_expired?)
remember_created_at && !remember_expired?
end
module ClassMethods
Devise::Models.config(self, :timeout_in)
end

View File

@@ -0,0 +1,72 @@
require 'devise/strategies/token_authenticatable'
module Devise
module Models
# The TokenAuthenticatable module is responsible for generating an authentication token and
# validating the authenticity of the same while signing in.
#
# This module only provides a few helpers to help you manage the token, but it is up to you
# to choose how to use it. For example, if you want to have a new token every time the user
# saves his account, you can do the following:
#
# before_save :reset_authentication_token
#
# On the other hand, if you want to generate token unless one exists, you should use instead:
#
# before_save :ensure_authentication_token
#
# If you want to delete the token after it is used, you can do so in the
# after_token_authentication callback.
#
# == Options
#
# TokenAuthenticatable adds the following options to devise_for:
#
# * +token_authentication_key+: Defines name of the authentication token params key. E.g. /users/sign_in?some_key=...
#
# * +stateless_token+: By default, when you sign up with a token, Devise will store the user in session
# as any other authentication strategy. You can set stateless_token to true to avoid this.
#
module TokenAuthenticatable
extend ActiveSupport::Concern
# Generate new authentication token (a.k.a. "single access token").
def reset_authentication_token
self.authentication_token = self.class.authentication_token
end
# Generate new authentication token and save the record.
def reset_authentication_token!
reset_authentication_token
save(:validate => false)
end
# Generate authentication token unless already exists.
def ensure_authentication_token
reset_authentication_token if authentication_token.blank?
end
# Generate authentication token unless already exists and save the record.
def ensure_authentication_token!
reset_authentication_token! if authentication_token.blank?
end
# Hook called after token authentication.
def after_token_authentication
end
module ClassMethods
def find_for_token_authentication(conditions)
find_for_authentication(:authentication_token => conditions[token_authentication_key])
end
# Generate a token checking if one does not already exist in the database.
def authentication_token
generate_token(:authentication_token)
end
::Devise::Models.config(self, :token_authentication_key, :stateless_token)
end
end
end
end

View File

@@ -8,9 +8,23 @@ module Devise
# * current_sign_in_at - A tiemstamp 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)
old_current, new_current = self.current_sign_in_at, Time.now
self.last_sign_in_at = old_current || new_current
self.current_sign_in_at = new_current
old_current, new_current = self.current_sign_in_ip, request.remote_ip
self.last_sign_in_ip = old_current || new_current
self.current_sign_in_ip = new_current
self.sign_in_count ||= 0
self.sign_in_count += 1
save(:validate => false)
end
end
end
end

View File

@@ -1,28 +1,34 @@
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
# valid. Also tests presence of password, confirmation and length
# Automatically validate if the email is present, unique and its format is
# valid. Also tests presence of password, confirmation and length.
#
# == Options
#
# 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..128.
#
module Validatable
# All validations used by this module.
VALIDATIONS = [ :validates_presence_of, :validates_uniqueness_of, :validates_format_of,
:validates_confirmation_of, :validates_length_of ].freeze
def self.included(base)
base.extend ClassMethods
assert_validations_api!(base)
base.class_eval do
validates_presence_of :email
validates_uniqueness_of :email, :scope => authentication_keys[1..-1], :allow_blank => true
validates_format_of :email, :with => EMAIL_REGEX, :allow_blank => true
validates_presence_of :email, :if => :email_required?
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 => 6..20, :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
@@ -35,14 +41,22 @@ module Devise
end
end
protected
protected
# Checks whether a password is needed or not. For validations only.
# Passwords are always required if it's a new record, or if the password
# or confirmation are being set somewhere.
def password_required?
new_record? || !password.nil? || !password_confirmation.nil?
end
# Checks whether a password is needed or not. For validations only.
# Passwords are always required if it's a new record, or if the password
# or confirmation are being set somewhere.
def password_required?
!persisted? || !password.nil? || !password_confirmation.nil?
end
def email_required?
true
end
module ClassMethods
Devise::Models.config(self, :email_regexp, :password_length)
end
end
end
end

30
lib/devise/modules.rb Normal file
View File

@@ -0,0 +1,30 @@
require 'active_support/core_ext/object/with_options'
Devise.with_options :model => true do |d|
# Strategies first
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
s.add_module :rememberable
end
# Other authentications
d.add_module :encryptable
d.add_module :omniauthable, :controller => :omniauth_callbacks, :route => :omniauth_callback
# Misc after
routes = [nil, :new, :edit]
d.add_module :recoverable, :controller => :passwords, :route => { :password => routes }
d.add_module :registerable, :controller => :registrations, :route => { :registration => (routes << :cancel) }
d.add_module :validatable
# The ones which can sign out after
routes = [nil, :new]
d.add_module :confirmable, :controller => :confirmations, :route => { :confirmation => routes }
d.add_module :lockable, :controller => :unlocks, :route => { :unlock => routes }
d.add_module :timeoutable
# Stats for last, so we make sure the user is really signed in
d.add_module :trackable
end

27
lib/devise/omniauth.rb Normal file
View File

@@ -0,0 +1,27 @@
begin
require "omniauth/core"
rescue LoadError => e
warn "Could not load 'omniauth/core'. Please ensure you have the oa-core gem installed and listed in your Gemfile."
raise
end
unless OmniAuth.config.respond_to? :test_mode
raise "You are using an old OmniAuth version, please ensure you have 0.2.0.beta version or later installed."
end
# Clean up the default path_prefix. It will be automatically set by Devise.
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_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"
end
end

View File

@@ -0,0 +1,24 @@
module Devise
module OmniAuth
class Config
attr_accessor :strategy
attr_reader :args
def initialize(provider, args)
@provider = provider
@args = args
@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
end
end
end

View File

@@ -0,0 +1,33 @@
module Devise
module OmniAuth
module UrlHelpers
def self.define_helpers(mapping)
return unless mapping.omniauthable?
class_eval <<-URL_HELPERS, __FILE__, __LINE__ + 1
def #{mapping.name}_omniauth_authorize_path(provider, params = {})
if Devise.omniauth_configs[provider.to_sym]
script_name = request.env["SCRIPT_NAME"]
path = "\#{script_name}/#{mapping.path}/auth/\#{provider}\".squeeze("/")
path << '?' + params.to_param if params.present?
path
else
raise ArgumentError, "Could not find omniauth provider \#{provider.inspect}"
end
end
URL_HELPERS
end
def omniauth_authorize_path(resource_or_scope, *args)
scope = Devise::Mapping.find_scope!(resource_or_scope)
send("#{scope}_omniauth_authorize_path", *args)
end
def omniauth_callback_path(resource_or_scope, *args)
scope = Devise::Mapping.find_scope!(resource_or_scope)
send("#{scope}_omniauth_callback_path", *args)
end
end
end
end

View File

@@ -1,12 +1,16 @@
require 'orm_adapter/adapters/active_record'
module Devise
module Orm
# This module contains some helpers and handle schema (migrations):
#
# create_table :accounts do |t|
# t.authenticatable
# t.database_authenticatable
# t.confirmable
# t.recoverable
# t.rememberable
# t.trackable
# t.lockable
# t.timestamps
# end
#
@@ -17,22 +21,18 @@ module Devise
# add_index "accounts", ["reset_password_token"], :name => "reset_password_token", :unique => true
#
module ActiveRecord
# Required ORM hook. Just yield the given block in ActiveRecord.
def self.included_modules_hook(klass, modules)
yield
end
module Schema
include Devise::Schema
include Devise::Schema
# Tell how to apply schema methods.
def apply_schema(name, type, options={})
column name, type.to_s.downcase.to_sym, options
# Tell how to apply schema methods.
def apply_devise_schema(name, type, options={})
column name, type.to_s.downcase.to_sym, options
end
end
end
end
end
if defined?(ActiveRecord)
ActiveRecord::Base.extend Devise::Models
ActiveRecord::ConnectionAdapters::TableDefinition.send :include, Devise::Orm::ActiveRecord
end
ActiveRecord::Base.extend Devise::Models
ActiveRecord::ConnectionAdapters::Table.send :include, Devise::Orm::ActiveRecord::Schema
ActiveRecord::ConnectionAdapters::TableDefinition.send :include, Devise::Orm::ActiveRecord::Schema

View File

@@ -1,83 +0,0 @@
module Devise
module Orm
module DataMapper
module InstanceMethods
def save(flag=nil)
if flag == false
save!
else
super()
end
end
end
def self.included_modules_hook(klass, modules)
klass.send :extend, self
klass.send :include, InstanceMethods
yield
modules.each do |mod|
klass.send(mod) if klass.respond_to?(mod)
end
end
include Devise::Schema
SCHEMA_OPTIONS = {
:null => :nullable,
:limit => :length
}
# Hooks for confirmable
def before_create(*args)
wrap_hook(:before, *args)
end
def after_create(*args)
wrap_hook(:after, *args)
end
def wrap_hook(action, *args)
options = args.extract_options!
args.each do |callback|
send action, :create, callback
class_eval <<-METHOD, __FILE__, __LINE__ + 1
def #{callback}
super if #{options[:if] || true}
end
METHOD
end
end
# Add ActiveRecord like finder
def find(*args)
options = args.extract_options!
case args.first
when :first
first(options)
when :all
all(options)
else
get(*args)
end
end
# Tell how to apply schema methods. This automatically maps :limit to
# :length and :null to :nullable.
def apply_schema(name, type, options={})
return unless Devise.apply_schema
SCHEMA_OPTIONS.each do |old_key, new_key|
next unless options.key?(old_key)
options[new_key] = options.delete(old_key)
end
property name, type, options
end
end
end
end
DataMapper::Model.send(:include, Devise::Models)

View File

@@ -1,27 +0,0 @@
module Devise
module Orm
module MongoMapper
def self.included_modules_hook(klass, modules)
klass.send :extend, self
yield
modules.each do |mod|
klass.send(mod) if klass.respond_to?(mod)
end
end
include Devise::Schema
# Tell how to apply schema methods. This automatically converts DateTime
# to Time, since MongoMapper does not recognize the former.
def apply_schema(name, type, options={})
return unless Devise.apply_schema
type = Time if type == DateTime
key name, type, options
end
end
end
end
MongoMapper::Document::ClassMethods.send(:include, Devise::Models)
MongoMapper::EmbeddedDocument::ClassMethods.send(:include, Devise::Models)

31
lib/devise/orm/mongoid.rb Normal file
View File

@@ -0,0 +1,31 @@
require 'orm_adapter/adapters/mongoid'
module Devise
module Orm
module Mongoid
module Hook
def devise_modules_hook!
extend Schema
yield
return unless Devise.apply_schema
devise_modules.each { |m| send(m) if respond_to?(m, true) }
end
end
module Schema
include Devise::Schema
# Tell how to apply schema methods
def apply_devise_schema(name, type, options={})
type = Time if type == DateTime
field name, { :type => type }.merge!(options)
end
end
end
end
end
Mongoid::Document::ClassMethods.class_eval do
include Devise::Models
include Devise::Orm::Mongoid::Hook
end

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