Compare commits

...

500 Commits

Author SHA1 Message Date
Rodrigo Flores
301e24c06c Bumping to 1.5.0.rc 2011-11-10 19:18:54 -02:00
Rodrigo Flores
6b108404ba Adding me to ci notifications 2011-11-10 18:40:28 -02:00
Rodrigo Flores
0b661b6d7f Updated changelog 2011-11-10 18:40:28 -02:00
Rodrigo Flores
3ab68a6896 Some changes on config_test to make it looks like the other ones 2011-11-10 18:39:52 -02:00
José Valim
97d8e39932 Update CHANGELOG.rdoc 2011-11-10 16:18:10 -02:00
José Valim
5c71c1cf19 Improve devise generator tests. 2011-11-10 10:19:57 -02:00
José Valim
dc8aa9ef83 Move param filtering to its own object and make all finder methods pass through it, closes #1413. 2011-11-10 10:14:02 -02:00
José Valim
ab54e1f66a Update CHANGELOG: Markerb templates. 2011-11-10 09:32:13 -02:00
José Valim
0fd5493220 Merge pull request #1326 from sbounmy/master
feature added : markerb generator for mails
2011-11-10 03:27:53 -08:00
Rodrigo Flores
5c3f75d90a Merge pull request #1426 from TamiasSibiricus/omniauth-1.0.0
Support OmniAuth 1.0.0 stable
2011-11-10 03:16:53 -08:00
Paul McKellar
e8aabd4652 s/Gererates/Generates/ 2011-11-09 20:58:58 -02:00
José Valim
350bd188df Merge pull request #1435 from nashby/master
use Time.now.utc instead of Time.now, closes #1421
2011-11-09 12:31:53 -08:00
Vasiliy Ermolovich
7e9ba53d82 use Time.now.utc instead of Time.now, closes #1421 2011-11-09 23:26:48 +03:00
José Valim
16208f7ad7 Rework previous commit to clean up the instance variable dynamically. 2011-11-09 17:00:42 -02:00
José Valim
cc822e08aa Merge pull request #1433 from artemk/master
current_user still returning user after sign_out
2011-11-09 10:52:13 -08:00
artemk
c3880e52e4 #1432 current_user still returning user after sign_out 2011-11-09 20:35:19 +02:00
Hugo Baraúna
a5aa03b983 Update the Copyright year 2011-11-08 22:59:04 -02:00
Rodrigo Flores
06b7baabcc Changed travis ci url 2011-11-08 15:42:11 -02:00
Rodrigo Flores
b7cffeed8c Ops, no need for the link to have https 2011-11-08 15:39:05 -02:00
Rodrigo Flores
380df0121b Adding https to avoid caching the travis passing status img 2011-11-08 15:27:26 -02:00
José Valim
611e0335cc Temporarily remove jruby from travis because 1.6.5 has a null pointer exception bug. 2011-11-07 21:39:27 -02:00
José Valim
22136a708b Fix failure_app failing test. 2011-11-07 21:38:31 -02:00
TamiasSibiricus
2a29e87eb9 Update dependencies for OmniAuth 1.0.0 stable 2011-11-07 22:58:33 +02:00
Denis Kiselev
ea9e8c0c9b Merge remote-tracking branch 'dkastner/omniauth-1.0' into omniauth-1.0.0
Conflicts:
	test/omniauth/url_helpers_test.rb
2011-11-07 22:26:51 +02:00
José Valim
58d61c290a Update CHANGELOG. 2011-11-07 09:20:09 -02:00
José Valim
bad6049d73 Allow :failure_app as configuration in devise_for. 2011-11-07 09:20:09 -02:00
José Valim
24b26026ef Delegator now checks the mapping for the proper failure app. 2011-11-07 09:20:09 -02:00
José Valim
4629beecd7 Cache failure_app action builder and pipe call through delegator. 2011-11-07 09:20:09 -02:00
José Valim
f67793cb0d Merge pull request #1423 from plataformatec/adding-ci-status-to-readme
Added CI status to the README
2011-11-06 14:39:51 -08:00
Rodrigo Flores
538c16cd00 Added CI status to the README 2011-11-06 20:18:46 -02:00
José Valim
3a26eea0cc Support warden ~> 1.1, closes #1422 2011-11-06 18:47:55 -02:00
José Valim
f9ef2cd32e Merge pull request #1420 from nashby/master
generate migrations with new .change method for rails >= 3.1. closes #1345
2011-11-06 05:23:58 -08:00
Vasiliy Ermolovich
493ddbd99e change method should be instance method. closes #1345 2011-11-06 16:15:17 +03:00
Vasiliy Ermolovich
f00d9c5eff generate migrations with new .change method for rails >= 3.1. closes #1345 2011-11-06 15:47:34 +03:00
José Valim
95be78ac5e No need to use git repo anymore for jdbc adapter. 2011-11-06 09:42:22 -02:00
José Valim
e9c263c326 Merge pull request #1418 from locomotivecms/simple_scoped_mailer
Re-define the devise mailer inside a model
2011-11-06 01:38:08 -08:00
José Valim
1bace6df4e Be sure to expire cached devise data after sign in, closes #1411 2011-11-05 20:11:09 -02:00
José Valim
0439c35198 Simplify active_for_authentication? checking. 2011-11-05 19:54:40 -02:00
José Valim
a816e538ab Fix bug where activation messages were shown first than the credentials error message, closes #1410 2011-11-05 19:47:58 -02:00
did
bbd117bd92 implementation of a much simpler solution 2011-11-05 16:53:27 +01:00
José Valim
d448e7d841 Timeoutable also skips tracking if skip_trackable is given 2011-10-25 18:43:48 +02:00
José Valim
6fcfba229d Improve docs for update_without_password. 2011-10-25 18:43:48 +02:00
José Valim
d525636423 Merge pull request #1398 from salidux/master
Trackable don't work properly behind a proxy
2011-10-22 10:51:19 -07:00
salidux
d11402612f test for trackable behind a proxy 2011-10-22 11:57:18 -02:00
José Valim
6079a025ca Fix doc typo. 2011-10-21 13:38:39 +03:00
José Valim
81f0c203a9 Update CHANGELOG. 2011-10-20 16:50:38 +02:00
salidux
60822641cb fix to obtain user original IP in a proxyed environment 2011-10-19 22:23:04 -02:00
José Valim
fac02b58bc Another attempt to fix the misterious loading helpers bug. 2011-10-18 08:35:50 +02:00
Derek Kastner
c9902f34d1 Intelligent OmniAuth strategy loader 2011-10-17 13:42:40 -04:00
Derek Kastner
8b45c0a856 Correct test for named OmniAuth strategy 2011-10-17 10:09:47 -04:00
José Valim
2a5ad4664b Change all paranoid settings to behave as success instead of as failure, closes #1375. 2011-10-15 10:52:00 +02:00
Jim Herzberg
b98720d324 jh - reworking paranoid mode in passwords controller
Signed-off-by: José Valim <jose.valim@gmail.com>
2011-10-15 10:45:33 +02:00
Derek Kastner
3f0b5fbd71 Support for OmniAuth 1.0.0 2011-10-14 21:31:17 -04:00
José Valim
fa1034b04c Merge pull request #1384 from korobkov/master
many typos (http -> https)
2011-10-13 15:21:21 -07:00
Andrey Korobkov
13ed2183ee many typos (http -> https) 2011-10-13 19:14:10 +04:00
Rafael Mendonça França
6fae1f60fd Merge pull request #1383 from korobkov/patch-1
typo
2011-10-13 07:15:07 -07:00
Andrey Korobkov
a46144e022 typo 2011-10-13 18:14:09 +04:00
José Valim
2372823fd8 Merge pull request #1372 from avocade/readme-update
Update README with troubleshooting for heroku
2011-10-10 10:37:26 -07:00
Oskar L-B
52282a5a26 Update README with troubleshooting for heroku
Re: issue https://github.com/plataformatec/devise/
commit/96f55a7ac7a61effd03a7f43dbbdfb6af8894579
2011-10-10 19:33:46 +02:00
José Valim
96f55a7ac7 Update docs and CHANGELOG.
Conflicts:

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

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

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

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

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

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

4
.gitignore vendored
View File

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

12
.travis.yml Normal file
View File

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

View File

@@ -1,3 +1,199 @@
== 1.5.0.rc
* enhancements
* Timeoutable also skips tracking if skip_trackable is given
* devise_for now accepts :failure_app as an option
* Models can select the proper mailer via devise_mailer method (by github.com/locomotivecms)
* Migration generator now uses the change method (by github.com/nashby)
* Support to markerb templates on the mailer generator (by github.com/sbounmy)
* Support for Omniauth 1.0 (older versions are no longer supported) (by github.com/TamiasSibiricus)
* bug fix
* Allow idempotent API requests
* Fix bug where logs did not show 401 as status code
* Change paranoid settings to behave as success instead of as failure
* Fix bug where activation messages were shown first than the credentials error message
* Instance variables are expired after sign out
* deprecation
* redirect_location is deprecated, please use after_sign_in_path_for
* after_sign_in_path_for now redirects to session[scope_return_to] if any value is stored in it
== 1.4.9
* bug fix
* url helpers were not being set under some circumstances
== 1.4.8
* enhancements
* Add docs for assets pipeline and Heroku
* bug fix
* confirmation_url was not being set under some circumstances
== 1.4.7
* bug fix
* Fix backward incompatible change from 1.4.6 for those using custom controllers
== 1.4.6
* enhancements
* Allow devise_for :skip => :all
* Allow options to be passed to authenticate_user!
* Allow --skip-routes to devise generator
* Add allow_params_authentication! to make it explicit when params authentication is allowed in a controller
== 1.4.5
* bug fix
* Failure app tries the root path if a session one does not exist
* No need to finalize Devise helpers all the time (by github.com/bradleypriest)
* Reset password shows proper message if user is not active
* `clean_up_passwords` sets the accessors to nil to skip validations
== 1.4.4
* bug fix
* Do not always skip helpers, instead provide :skip_helpers as option to trigger it manually
== 1.4.3
* enhancements
* Improve Rails 3.1 compatibility
* Use serialize_into_session and serialize_from_session in Warden serialize to improve extensibility
* bug fix
* Generator properly generates a change_table migration if a model already exists
* Properly deprecate setup_mail
* Fix encoding issues with email regexp
* Only generate helpers for the used mappings
* Wrap :action constraints in the proper hash
* deprecations
* Loosened the used email regexp to simply assert the existent of "@". If someone relies on a more strict regexp, they may use https://github.com/SixArm/sixarm_ruby_email_address_validation
== 1.4.2
* bug fix
* Provide a more robust behavior to serializers and add :force_except option
== 1.4.1
* enhancements
* Add :defaults and :format support on router
* Add simple form generators
* Better localization for devise_error_messages! (by github.com/zedtux)
* bug fix
* Ensure to_xml is properly white listened
* Ensure handle_unverified_request clean up any cached signed-in user
== 1.4.0
* enhancements
* Added authenticated and unauthenticated to the router to route the used based on his status (by github.com/sj26)
* Improve e-mail regexp (by github.com/rodrigoflores)
* Add strip_whitespace_keys and default to e-mail (by github.com/swrobel)
* Do not run format and uniqueness validations on e-mail if it hasn't changed (by github.com/Thibaut)
* Added update_without_password to update models but not allowing the password to change (by github.com/fschwahn)
* Added config.paranoid, check the generator for more information (by github.com/rodrigoflores)
* bug fix
* password_required? should not affect length validation
* User cannot access sign up and similar pages if he is already signed in through a cookie or token
* Do not convert booleans to strings on finders (by github.com/xavier)
* Run validations even if current_password fails (by github.com/crx)
* Devise now honors routes constraints (by github.com/macmartine)
* Do not return the user resource when requesting instructions (by github.com/rodrigoflores)
== 1.3.4
* bug fix
* Do not add formats if html or "*/*"
== 1.3.3
* bug fix
* Explicitly mark the token as expired if so
== 1.3.2
* bug fix
* Fix another regression related to reset_password_sent_at (by github.com/alexdreher)
== 1.3.1
* enhancements
* Improve failure_app responses (by github.com/indirect)
* sessions/new and registrations/new also respond to xml and json now
* bug fix
* Fix a regression that occurred if reset_password_sent_at is not present (by github.com/stevehodgkiss)
== 1.3.0
* enhancements
* All controllers can now handle different mime types than html using Responders (by github.com/sikachu)
* Added reset_password_within as configuration option to send the token for recovery (by github.com/jdguyot)
* Bump password length to 128 characters (by github.com/k33l0r)
* Add :only as option to devise_for (by github.com/timoschilling)
* Allow to override path after sending password instructions (by github.com/irohiroki)
* require_no_authentication has its own flash message (by github.com/jackdempsey)
* bug fix
* Fix a bug where configuration options were being included too late
* Ensure Devise::TestHelpers can be used to tests Devise internal controllers (by github.com/jwilger)
* valid_password? should not choke on empty passwords (by github.com/mikel)
* Calling devise more than once does not include previously added modules anymore
* downcase_keys before validation
* backward incompatible changes
* authentication_keys are no longer considered when creating the e-mail validations, the previous behavior was buggy. You must double check if you were relying on such behavior.
== 1.2.1
* enhancements
* Improve update path messages
== 1.2.0
* bug fix
* 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
@@ -30,12 +226,26 @@
* bugfix
* after_sign_in_path_for always receives a resource
* Do not execute Warden::Callbacks on Devise::TestHelpers (by github.com/sgronblo)
* Password recovery and account unlocking takes into account authentication keys (by github.com/RStankov)
* 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

29
Gemfile
View File

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

View File

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

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

@@ -1,5 +1,7 @@
== Devise
{<img src="https://secure.travis-ci.org/plataformatec/devise.png" />}[http://travis-ci.org/plataformatec/devise]
Devise is a flexible authentication solution for Rails based on Warden. It:
* Is Rack based;
@@ -7,9 +9,9 @@ Devise is a flexible authentication solution for Rails based on Warden. It:
* Allows you to have multiple roles (or models/scopes) signed in at the same time;
* Is based on a modularity concept: use just what you really need.
It's composed of 12 modules:
It's comprised of 12 modules:
* Database Authenticatable: encrypts and stores a password in the database to validate the authenticity of an user while signing in. The authentication can be done both through POST requests or HTTP Basic Authentication.
* 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.
@@ -20,29 +22,29 @@ It's composed of 12 modules:
* 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: allows support of other authentication mechanisms besides Bcrypt (the default).
* Encryptable: adds support of other authentication mechanisms besides the built-in Bcrypt (the default).
== Information
=== The Devise Wiki
=== The Devise wiki
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:
http://wiki.github.com/plataformatec/devise
https://wiki.github.com/plataformatec/devise
=== 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
https://github.com/plataformatec/devise/wiki/Bug-reports
If you found a security bug, do *NOT* use the GitHub Issue tracker. Send private GitHub message or email to the maintainers listed in the bottom of the README.
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.
=== Google Group
=== Mailing list
If you have any questions, comments, or concerns please use the Google Group instead of the GitHub Issues tracker:
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
https://groups.google.com/group/plataformatec-devise
=== RDocs
@@ -52,23 +54,25 @@ 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
=== 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
https://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
https://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
https://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
@@ -84,10 +88,19 @@ The generator will install an initializer which describes ALL Devise's configura
rails generate devise MODEL
Replace MODEL by the class name you want to add devise, like User, Admin, etc. This will create a model (if one does not exist) and configure it with default Devise modules. The generator will also create a migration file (if your ORM support them) and configure your routes. Continue reading this file to understand exactly what the generator produces and how to use it.
Replace MODEL by the class name used for the applications users, it's frequently 'User' but could also be 'Admin'. This will create a model (if one does not exist) and configure it with default Devise modules. Next, you'll usually run db:migrate as the generator will have created a migration file (if your ORM supports them). This generator also configures your config/routes.rb file, continue reading this file to understand exactly what the generator produces and how to use it.
Support for Rails 2.3.x can be found by installing Devise 1.0.x from the v1.0 branch.
== Starting with Rails?
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:
* Michael Hartl's online book: http://railstutorial.org/chapters/modeling-and-viewing-users-two#top
* Ryan Bates' Railscast: http://railscasts.com/episodes/250-authentication-from-scratch
Once you have solidified your understanding of Rails and authentication mechanisms, we assure you Devise will be very pleasant to work with. :)
== Getting started
This is a walkthrough with all steps you need to setup a devise resource, including model, migration, route files, and optional configuration.
@@ -97,7 +110,7 @@ Devise must be set up within the model (or models) you want to use. Devise route
We're assuming here you want a User model with some Devise modules, as outlined below:
class User < ActiveRecord::Base
devise :database_authenticatable, :confirmable, :recoverable, :rememberable, :trackable, :validatable
devise :database_authenticatable, :registerable, :confirmable, :recoverable, :rememberable, :trackable, :validatable
end
After you choose which modules to use, you need to set up your migrations. Luckily, Devise has some helpers to save you from this boring work:
@@ -141,7 +154,7 @@ You can access the session for this scope:
After signing in a user, confirming the account or updating the password, Devise will look for a scoped root path to redirect. Example: For a :user resource, it will use user_root_path if it exists, otherwise default root_path will be used. This means that you need to set the root inside your routes:
root :to => "home"
root :to => "home#index"
You can also overwrite after_sign_in_path_for and after_sign_out_path_for to customize your redirect hooks.
@@ -163,7 +176,7 @@ Notice that if your devise model is not called "user" but "member", then the hel
The devise method in your models also accepts some options to configure its modules. For example, you can choose which encryptor to use in database_authenticatable:
devise :database_authenticatable, :confirmable, :recoverable, :stretches => 20
devise :database_authenticatable, :registerable, :confirmable, :recoverable, :stretches => 20
Besides :stretches, you can define :pepper, :encryptor, :confirm_within, :remember_for, :timeout_in, :unlock_in and other values. For details, see the initializer file that was created when you invoked the "devise:install" generator described above.
@@ -201,8 +214,6 @@ Since Devise is an engine, all its views are packaged inside the gem. These view
rails generate devise:views
If you are using HAML, you will need hpricot installed to convert Devise views to HAML.
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".
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:
@@ -250,7 +261,7 @@ Feel free to choose the one you prefer!
=== I18n
Devise uses flash messages with I18n with the flash keys :success and :failure. To customize your app, you can set up your locale file:
Devise uses flash messages with I18n with the flash keys :notice and :alert. To customize your app, you can set up your locale file:
en:
devise:
@@ -280,7 +291,7 @@ The Devise mailer uses a similar pattern to create subject 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:
http://github.com/plataformatec/devise/wiki/I18n
https://github.com/plataformatec/devise/wiki/I18n
=== Test helpers
@@ -304,14 +315,13 @@ If you're using RSpec and want the helpers automatically included within all +de
config.include Devise::TestHelpers, :type => :controller
end
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).
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 (https://wiki.github.com/plataformatec/devise).
=== OAuth2
=== Omniauth
Devise comes with OAuth support out of the box if you're using Devise from the git repository (for now). You can read more about OAuth2 support in the wiki:
Devise comes with Omniauth support out of the box to authenticate from other providers. You can read more about Omniauth support in the wiki:
* http://github.com/plataformatec/devise/wiki/OAuth2:-Overview
* http://github.com/plataformatec/devise/wiki/OAuth2:-Testing
* https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview
=== Other ORMs
@@ -321,25 +331,35 @@ Devise supports ActiveRecord (default) and Mongoid. To choose other ORM, you jus
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).
== Troubleshooting
=== Heroku
Using devise on Heroku with Ruby on Rails 3.1 requires setting:
config.assets.initialize_on_precompile = false
Read more about the potential issues at http://guides.rubyonrails.org/asset_pipeline.html
== 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
https://github.com/hassox/warden
=== Contributors
We have a long list of valued contributors. Check them all at:
http://github.com/plataformatec/devise/contributors
https://github.com/plataformatec/devise/contributors
=== Maintainers
* José Valim (http://github.com/josevalim)
* Carlos Antônio da Silva (http://github.com/carlosantoniodasilva)
* José Valim (https://github.com/josevalim)
* Carlos Antônio da Silva (https://github.com/carlosantoniodasilva)
== License
MIT License. Copyright 2010 Plataforma Tecnologia. http://blog.plataformatec.com.br
MIT License. Copyright 2011 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,26 +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|
root_files = FileList["README.rdoc", "MIT-LICENSE", "CHANGELOG.rdoc"]
s.name = "devise"
s.version = Devise::VERSION.dup
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 = root_files + FileList["{app,config,lib}/**/*"]
s.extra_rdoc_files = root_files
s.add_dependency("warden", "~> 1.0.2")
s.add_dependency("orm_adapter", "~> 0.0.2")
s.add_dependency("bcrypt-ruby", "~> 2.1.2")
end
Jeweler::GemcutterTasks.new
rescue LoadError
puts "Jeweler, or one of its dependencies, is not available. Install it with: gem install jeweler"
end

4
TODO
View File

@@ -1,4 +0,0 @@
* Move integration tests to Capybara
* Better ORM integration
* Add support to automatically refresh the access token for OAuth
* Add test to generators using the new Rails::Generators::TestCase

View File

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

View File

@@ -9,18 +9,18 @@ class Devise::OmniauthCallbacksController < ApplicationController
protected
def failed_strategy
env["omniauth.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.failure_key"]
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
end

View File

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

View File

@@ -5,26 +5,27 @@ class Devise::RegistrationsController < ApplicationController
# GET /resource/sign_up
def new
build_resource({})
render_with_scope :new
resource = build_resource({})
respond_with_navigational(resource){ render_with_scope :new }
end
# POST /resource/sign_up
# POST /resource
def create
build_resource
if resource.save
if resource.active?
set_flash_message :notice, :signed_up
sign_in_and_redirect(resource_name, resource)
if resource.active_for_authentication?
set_flash_message :notice, :signed_up if is_navigational_format?
sign_in(resource_name, resource)
respond_with resource, :location => after_sign_up_path_for(resource)
else
set_flash_message :notice, :inactive_signed_up, :reason => resource.inactive_message.to_s
set_flash_message :notice, :inactive_signed_up, :reason => inactive_reason(resource) if is_navigational_format?
expire_session_data_after_sign_in!
redirect_to after_inactive_sign_up_path_for(resource)
respond_with resource, :location => after_inactive_sign_up_path_for(resource)
end
else
clean_up_passwords(resource)
render_with_scope :new
respond_with_navigational(resource) { render_with_scope :new }
end
end
@@ -34,22 +35,27 @@ class Devise::RegistrationsController < ApplicationController
end
# PUT /resource
# We need to use a copy of the resource because we don't want to change
# the current user in place.
def update
self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key)
if resource.update_with_password(params[resource_name])
set_flash_message :notice, :updated
set_flash_message :notice, :updated if is_navigational_format?
sign_in resource_name, resource, :bypass => true
redirect_to after_update_path_for(resource)
respond_with resource, :location => after_update_path_for(resource)
else
clean_up_passwords(resource)
render_with_scope :edit
respond_with_navigational(resource){ render_with_scope :edit }
end
end
# DELETE /resource
def destroy
resource.destroy
sign_out_and_redirect(self.resource)
set_flash_message :notice, :destroyed
Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)
set_flash_message :notice, :destroyed if is_navigational_format?
respond_with_navigational(resource){ redirect_to after_sign_out_path_for(resource_name) }
end
# GET /resource/cancel
@@ -77,9 +83,10 @@ class Devise::RegistrationsController < ApplicationController
after_sign_in_path_for(resource)
end
# Overwrite redirect_for_sign_in so it takes uses after_sign_up_path_for.
def redirect_for_sign_in(scope, resource) #:nodoc:
redirect_to stored_location_for(scope) || after_sign_up_path_for(resource)
# 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
@@ -91,20 +98,12 @@ class Devise::RegistrationsController < ApplicationController
# 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
signed_in_root_path(resource)
end
# Authenticates the current scope and gets a copy of the current resource.
# We need to use a copy because we don't want actions like update changing
# the current user in place.
# Authenticates the current scope and gets the current resource from the session.
def authenticate_scope!
send(:"authenticate_#{resource_name}!")
self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key)
send(:"authenticate_#{resource_name}!", :force => true)
self.resource = send(:"current_#{resource_name}")
end
end

View File

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

View File

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

View File

@@ -1,11 +1,17 @@
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_name)
:resource => resource.class.model_name.human.downcase)
html = <<-HTML
<div id="error_explanation">

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,6 +1,9 @@
# Additional translations at https://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"
@@ -10,6 +13,7 @@ en:
devise:
failure:
already_authenticated: 'You are already signed in.'
unauthenticated: 'You need to sign in or sign up before continuing.'
unconfirmed: 'You have to confirm your account before continuing.'
locked: 'Your account is locked.'
@@ -23,17 +27,25 @@ en:
passwords:
send_instructions: 'You will receive an email with instructions about how to reset your password in a few minutes.'
updated: 'Your password was changed successfully. You are now signed in.'
updated_not_active: 'Your password was changed successfully.'
send_paranoid_instructions: "If your e-mail exists on our database, you will receive a password recovery link on your e-mail"
confirmations:
send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.'
send_paranoid_instructions: 'If your e-mail exists on our database, you will receive an email with instructions about how to confirm your account in a few minutes.'
confirmed: 'Your account was successfully confirmed. You are now signed in.'
registrations:
signed_up: 'Welcome! You have signed up successfully.'
inactive_signed_up: 'You have signed up successfully. However, we could not sign you in because your account is %{reason}.'
updated: 'You updated your account successfully.'
destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.'
reasons:
inactive: 'inactive'
unconfirmed: 'unconfirmed'
locked: 'locked'
unlocks:
send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.'
unlocked: 'Your account was successfully unlocked. You are now signed in.'
send_paranoid_instructions: 'If your account exists, you will receive an email with instructions about how to unlock it in a few minutes.'
omniauth_callbacks:
success: 'Successfully authorized from %{kind} account.'
failure: 'Could not authorize you from %{kind} because "%{reason}".'

View File

@@ -1,208 +1,25 @@
# Generated by jeweler
# DO NOT EDIT THIS FILE DIRECTLY
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "devise/version"
Gem::Specification.new do |s|
s.name = %q{devise}
s.version = "1.2.rc"
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.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
s.authors = ["Jos\303\251 Valim", "Carlos Ant\303\264nio"]
s.date = %q{2010-11-26}
s.description = %q{Flexible authentication solution for Rails with Warden}
s.email = %q{contact@plataformatec.com.br}
s.extra_rdoc_files = [
"CHANGELOG.rdoc",
"MIT-LICENSE",
"README.rdoc"
]
s.files = [
"CHANGELOG.rdoc",
"MIT-LICENSE",
"README.rdoc",
"app/controllers/devise/confirmations_controller.rb",
"app/controllers/devise/omniauth_callbacks_controller.rb",
"app/controllers/devise/passwords_controller.rb",
"app/controllers/devise/registrations_controller.rb",
"app/controllers/devise/sessions_controller.rb",
"app/controllers/devise/unlocks_controller.rb",
"app/helpers/devise_helper.rb",
"app/mailers/devise/mailer.rb",
"app/views/devise/confirmations/new.html.erb",
"app/views/devise/mailer/confirmation_instructions.html.erb",
"app/views/devise/mailer/reset_password_instructions.html.erb",
"app/views/devise/mailer/unlock_instructions.html.erb",
"app/views/devise/passwords/edit.html.erb",
"app/views/devise/passwords/new.html.erb",
"app/views/devise/registrations/edit.html.erb",
"app/views/devise/registrations/new.html.erb",
"app/views/devise/sessions/new.html.erb",
"app/views/devise/shared/_links.erb",
"app/views/devise/unlocks/new.html.erb",
"config/locales/en.yml",
"lib/devise.rb",
"lib/devise/controllers/helpers.rb",
"lib/devise/controllers/internal_helpers.rb",
"lib/devise/controllers/scoped_views.rb",
"lib/devise/controllers/url_helpers.rb",
"lib/devise/encryptors/authlogic_sha512.rb",
"lib/devise/encryptors/base.rb",
"lib/devise/encryptors/clearance_sha1.rb",
"lib/devise/encryptors/restful_authentication_sha1.rb",
"lib/devise/encryptors/sha1.rb",
"lib/devise/encryptors/sha512.rb",
"lib/devise/failure_app.rb",
"lib/devise/hooks/activatable.rb",
"lib/devise/hooks/forgetable.rb",
"lib/devise/hooks/rememberable.rb",
"lib/devise/hooks/timeoutable.rb",
"lib/devise/hooks/trackable.rb",
"lib/devise/mapping.rb",
"lib/devise/models.rb",
"lib/devise/models/authenticatable.rb",
"lib/devise/models/confirmable.rb",
"lib/devise/models/database_authenticatable.rb",
"lib/devise/models/encryptable.rb",
"lib/devise/models/lockable.rb",
"lib/devise/models/omniauthable.rb",
"lib/devise/models/recoverable.rb",
"lib/devise/models/registerable.rb",
"lib/devise/models/rememberable.rb",
"lib/devise/models/timeoutable.rb",
"lib/devise/models/token_authenticatable.rb",
"lib/devise/models/trackable.rb",
"lib/devise/models/validatable.rb",
"lib/devise/modules.rb",
"lib/devise/omniauth.rb",
"lib/devise/omniauth/config.rb",
"lib/devise/omniauth/test_helpers.rb",
"lib/devise/omniauth/url_helpers.rb",
"lib/devise/orm/active_record.rb",
"lib/devise/orm/mongoid.rb",
"lib/devise/path_checker.rb",
"lib/devise/rails.rb",
"lib/devise/rails/routes.rb",
"lib/devise/rails/warden_compat.rb",
"lib/devise/schema.rb",
"lib/devise/strategies/authenticatable.rb",
"lib/devise/strategies/base.rb",
"lib/devise/strategies/database_authenticatable.rb",
"lib/devise/strategies/rememberable.rb",
"lib/devise/strategies/token_authenticatable.rb",
"lib/devise/test_helpers.rb",
"lib/devise/version.rb",
"lib/generators/active_record/devise_generator.rb",
"lib/generators/active_record/templates/migration.rb",
"lib/generators/devise/devise_generator.rb",
"lib/generators/devise/install_generator.rb",
"lib/generators/devise/orm_helpers.rb",
"lib/generators/devise/views_generator.rb",
"lib/generators/mongoid/devise_generator.rb",
"lib/generators/templates/README",
"lib/generators/templates/devise.rb"
]
s.homepage = %q{http://github.com/plataformatec/devise}
s.rdoc_options = ["--charset=UTF-8"]
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.rubygems_version = %q{1.3.7}
s.summary = %q{Flexible authentication solution for Rails with Warden}
s.test_files = [
"test/controllers/helpers_test.rb",
"test/controllers/internal_helpers_test.rb",
"test/controllers/url_helpers_test.rb",
"test/devise_test.rb",
"test/encryptors_test.rb",
"test/failure_app_test.rb",
"test/generators/generators_test_helper.rb",
"test/generators/install_generator_test.rb",
"test/generators/views_generator_test.rb",
"test/integration/authenticatable_test.rb",
"test/integration/confirmable_test.rb",
"test/integration/database_authenticatable_test.rb",
"test/integration/http_authenticatable_test.rb",
"test/integration/lockable_test.rb",
"test/integration/omniauthable_test.rb",
"test/integration/recoverable_test.rb",
"test/integration/registerable_test.rb",
"test/integration/rememberable_test.rb",
"test/integration/timeoutable_test.rb",
"test/integration/token_authenticatable_test.rb",
"test/integration/trackable_test.rb",
"test/mailers/confirmation_instructions_test.rb",
"test/mailers/reset_password_instructions_test.rb",
"test/mailers/unlock_instructions_test.rb",
"test/mapping_test.rb",
"test/models/confirmable_test.rb",
"test/models/database_authenticatable_test.rb",
"test/models/encryptable_test.rb",
"test/models/lockable_test.rb",
"test/models/recoverable_test.rb",
"test/models/rememberable_test.rb",
"test/models/timeoutable_test.rb",
"test/models/token_authenticatable_test.rb",
"test/models/trackable_test.rb",
"test/models/validatable_test.rb",
"test/models_test.rb",
"test/omniauth/url_helpers_test.rb",
"test/orm/active_record.rb",
"test/orm/mongoid.rb",
"test/rails_app/app/active_record/admin.rb",
"test/rails_app/app/active_record/shim.rb",
"test/rails_app/app/active_record/user.rb",
"test/rails_app/app/controllers/admins/sessions_controller.rb",
"test/rails_app/app/controllers/admins_controller.rb",
"test/rails_app/app/controllers/application_controller.rb",
"test/rails_app/app/controllers/home_controller.rb",
"test/rails_app/app/controllers/publisher/registrations_controller.rb",
"test/rails_app/app/controllers/publisher/sessions_controller.rb",
"test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb",
"test/rails_app/app/controllers/users_controller.rb",
"test/rails_app/app/helpers/application_helper.rb",
"test/rails_app/app/mongoid/admin.rb",
"test/rails_app/app/mongoid/shim.rb",
"test/rails_app/app/mongoid/user.rb",
"test/rails_app/config/application.rb",
"test/rails_app/config/boot.rb",
"test/rails_app/config/environment.rb",
"test/rails_app/config/environments/development.rb",
"test/rails_app/config/environments/production.rb",
"test/rails_app/config/environments/test.rb",
"test/rails_app/config/initializers/backtrace_silencers.rb",
"test/rails_app/config/initializers/devise.rb",
"test/rails_app/config/initializers/inflections.rb",
"test/rails_app/config/initializers/secret_token.rb",
"test/rails_app/config/routes.rb",
"test/rails_app/db/migrate/20100401102949_create_tables.rb",
"test/rails_app/db/schema.rb",
"test/rails_app/lib/shared_admin.rb",
"test/rails_app/lib/shared_user.rb",
"test/routes_test.rb",
"test/support/assertions.rb",
"test/support/helpers.rb",
"test/support/integration.rb",
"test/support/webrat/integrations/rails.rb",
"test/test_helper.rb",
"test/test_helpers_test.rb"
]
if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 3
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<warden>, ["~> 1.0.2"])
s.add_runtime_dependency(%q<orm_adapter>, ["~> 0.0.2"])
s.add_runtime_dependency(%q<bcrypt-ruby>, ["~> 2.1.2"])
else
s.add_dependency(%q<warden>, ["~> 1.0.2"])
s.add_dependency(%q<orm_adapter>, ["~> 0.0.2"])
s.add_dependency(%q<bcrypt-ruby>, ["~> 2.1.2"])
end
else
s.add_dependency(%q<warden>, ["~> 1.0.2"])
s.add_dependency(%q<orm_adapter>, ["~> 0.0.2"])
s.add_dependency(%q<bcrypt-ruby>, ["~> 2.1.2"])
end
end
s.add_dependency("warden", "~> 1.1")
s.add_dependency("orm_adapter", "~> 0.0.3")
s.add_dependency("bcrypt-ruby", "~> 3.0")
end

View File

@@ -1,19 +1,25 @@
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 :OmniAuth, 'devise/omniauth'
autoload :Delegator, 'devise/delegator'
autoload :FailureApp, 'devise/failure_app'
autoload :OmniAuth, 'devise/omniauth'
autoload :ParamFilter, 'devise/param_filter'
autoload :PathChecker, 'devise/path_checker'
autoload :Schema, 'devise/schema'
autoload :Schema, 'devise/schema'
autoload :TestHelpers, 'devise/test_helpers'
module Controllers
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
@@ -26,6 +32,10 @@ module Devise
autoload :Sha1, 'devise/encryptors/sha1'
end
module Mailers
autoload :Helpers, 'devise/mailers/helpers'
end
module Strategies
autoload :Base, 'devise/strategies/base'
autoload :Authenticatable, 'devise/strategies/authenticatable'
@@ -39,6 +49,9 @@ module Devise
STRATEGIES = ActiveSupport::OrderedHash.new
URL_HELPERS = ActiveSupport::OrderedHash.new
# Strategies that do not require user input.
NO_INPUT = []
# True values used to check params
TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE']
@@ -68,8 +81,14 @@ module Devise
@@request_keys = []
# Keys that should be case-insensitive.
# False by default for backwards compatibility.
mattr_accessor :case_insensitive_keys
@@case_insensitive_keys = [ :email ]
@@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
@@ -87,13 +106,15 @@ module Devise
mattr_accessor :http_authentication_realm
@@http_authentication_realm = "Application"
# Email regex used to validate email formats. Adapted from authlogic.
# Email regex used to validate email formats. It simply asserts that
# an one (and only one) @ exists in the given string. This is mainly
# to give user feedback and not to assert the e-mail validity.
mattr_accessor :email_regexp
@@email_regexp = /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i
@@email_regexp = /\A[^@]+@([^@\.]+\.)+[^@\.]+\z/
# Range validation for password length
mattr_accessor :password_length
@@password_length = 6..20
@@password_length = 6..128
# The time the user will be remembered without asking for credentials again.
mattr_accessor :remember_for
@@ -116,6 +137,10 @@ module Devise
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
@@ -143,6 +168,10 @@ module Devise
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
@@ -156,6 +185,14 @@ module Devise
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
@@default_scope = nil
@@ -173,10 +210,11 @@ module Devise
@@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]
@@navigational_formats = [:"*/*", "*/*", :html]
# When set to true, signing out an user signs out all other scopes.
# When set to true, signing out a user signs out all other scopes.
mattr_accessor :sign_out_all_scopes
@@sign_out_all_scopes = true
@@ -204,20 +242,37 @@ module Devise
@@warden_config = nil
@@warden_config_block = nil
# When true, enter in paranoid mode to avoid user enumeration.
mattr_accessor :paranoid
@@paranoid = false
# Default way to setup Devise. Run rails generate devise_install to create
# a fresh initializer with all configuration values.
def self.setup
yield self
end
def self.omniauth_providers
omniauth_configs.keys
class Getter
def initialize name
@name = name
end
def get
ActiveSupport::Dependencies.constantize(@name)
end
end
def self.cookie_domain=(value)
ActiveSupport::Deprecation.warn "Devise.cookie_domain=(value) is deprecated. "
"Please use Devise.cookie_options = { :domain => value } instead."
self.cookie_options[:domain] = value
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.
@@ -227,7 +282,7 @@ module Devise
# Set the mailer reference object to access the mailer.
def self.mailer=(class_name)
@@mailer_ref = ActiveSupport::Dependencies.ref(class_name)
@@mailer_ref = ref(class_name)
end
self.mailer = "Devise::Mailer"
@@ -263,13 +318,17 @@ module Devise
options.assert_valid_keys(:strategy, :model, :controller, :route)
if strategy = options[:strategy]
STRATEGIES[module_name] = (strategy == true ? module_name : strategy)
strategy = (strategy == true ? module_name : strategy)
STRATEGIES[module_name] = strategy
end
if controller = options[:controller]
CONTROLLERS[module_name] = (controller == true ? module_name : controller)
controller = (controller == true ? module_name : controller)
CONTROLLERS[module_name] = controller
end
NO_INPUT << strategy if strategy && controller != :sessions
if route = options[:route]
case route
when TrueClass
@@ -291,7 +350,8 @@ module Devise
if options[:model]
path = (options[:model] == true ? "devise/models/#{module_name}" : options[:model])
Devise::Models.send(:autoload, module_name.to_s.camelize.to_sym, path)
camelized = ActiveSupport::Inflector.camelize(module_name.to_s)
Devise::Models.send(:autoload, camelized.to_sym, path)
end
Devise::Mapping.add_module module_name
@@ -318,7 +378,8 @@ module Devise
#
def self.omniauth(provider, *args)
@@helpers << Devise::OmniAuth::UrlHelpers
@@omniauth_configs[provider] = Devise::OmniAuth::Config.new(provider, args)
config = Devise::OmniAuth::Config.new(provider, args)
@@omniauth_configs[config.strategy_name.to_sym] = config
end
# Include helpers in the given scope to AC and AV.
@@ -338,11 +399,17 @@ module Devise
Rails::VERSION::STRING[0,3] != "3.0"
end
# Regenerates url helpers considering Devise.mapping
def self.regenerate_helpers!
Devise::Controllers::UrlHelpers.remove_helpers!
Devise::Controllers::UrlHelpers.generate_helpers!
end
# A method used internally to setup warden manager from the Rails initialize
# block.
def self.configure_warden! #:nodoc:
@@warden_configured ||= begin
warden_config.failure_app = Devise::FailureApp
warden_config.failure_app = Devise::Delegator.new
warden_config.default_scope = Devise.default_scope
warden_config.intercept_401 = false
@@ -357,7 +424,17 @@ module Devise
# Generate a friendly string randomically to be used as token.
def self.friendly_token
ActiveSupport::SecureRandom.base64(44).tr('+/=', 'xyz')
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

View File

@@ -5,7 +5,14 @@ module Devise
extend ActiveSupport::Concern
included do
helper_method :warden, :signed_in?, :devise_controller?, :anybody_signed_in?
helper_method :warden, :signed_in?, :devise_controller?
end
module ClassMethods
def log_process_action(payload)
payload[:status] ||= 401 unless payload[:exception]
super
end
end
# Define authentication filters and accessor helpers based on mappings.
@@ -21,7 +28,7 @@ module Devise
# 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
# 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
@@ -36,8 +43,9 @@ module Devise
mapping = mapping.name
class_eval <<-METHODS, __FILE__, __LINE__ + 1
def authenticate_#{mapping}!
warden.authenticate!(:scope => :#{mapping})
def authenticate_#{mapping}!(opts={})
opts[:scope] = :#{mapping}
warden.authenticate!(opts) if !devise_controller? || opts.delete(:force)
end
def #{mapping}_signed_in?
@@ -72,19 +80,20 @@ module Devise
false
end
# Check if the given scope is signed in session, without running
# authentication hooks.
def signed_in?(scope)
warden.authenticate?(:scope => scope)
# Tell warden that params authentication is allowed for that specific page.
def allow_params_authentication!
request.env["devise.allow_params_authentication"] = true
end
# Check if the any scope is signed in session, without running
# authentication hooks.
def anybody_signed_in?
Devise.mappings.keys.any? { |scope| signed_in?(scope) }
# 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
# Sign in an user that already was authenticated. This helper is useful for logging
# 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.
@@ -98,7 +107,7 @@ module Devise
# 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)
@@ -108,12 +117,15 @@ module Devise
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 an user
# Sign out a given user or scope. This helper is useful for signing out a user
# after deleting accounts.
#
# Examples:
@@ -127,13 +139,16 @@ module Devise
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)
instance_variable_set(:"@current_#{scope}", nil)
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
expire_devise_cached_variables!
end
# Returns and delete the url stored in the session for the given scope. Useful
@@ -148,12 +163,21 @@ module Devise
session.delete("#{scope}_return_to")
end
# The scope root url to be used when he's signed in. By default, it first
# tries to find a resource_root_path, otherwise it uses the root_path.
def signed_in_root_path(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 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
# By default, it first tries to find a valid resource_return_to key in the
# session, then it fallbacks to 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
@@ -162,25 +186,23 @@ module Devise
# 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
# stored_location_for(resource) ||
# if resource.is_a?(User) && resource.can_publish?
# publisher_url
# else
# signed_in_root_path(resource)
# 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
stored_location_for(resource_or_scope) || signed_in_root_path(resource_or_scope)
end
# Method used by sessions controller to sign out an user. You can overwrite
# 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.
@@ -190,43 +212,47 @@ module Devise
root_path
end
# Sign in an user and tries to redirect first to the stored location and
# 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
if warden.user(scope) == resource
expire_session_data_after_sign_in!
else
sign_in(scope, resource, options)
end
redirect_for_sign_in(scope, resource)
sign_in(scope, resource, options)
redirect_to after_sign_in_path_for(resource)
end
def redirect_for_sign_in(scope, resource) #:nodoc:
redirect_to stored_location_for(scope) || after_sign_in_path_for(resource)
def redirect_location(scope, resource) #:nodoc:
ActiveSupport::Deprecation.warn "redirect_location in Devise is deprecated. Please use after_sign_in_path_for instead.", caller
after_sign_in_path_for(resource)
end
# Sign out an user and tries to redirect to the url specified by
def expire_session_data_after_sign_in!
session.keys.grep(/^devise\./).each { |k| session.delete(k) }
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_for_sign_out(scope)
end
def redirect_for_sign_out(scope) #:nodoc:
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) }
# 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!
expire_devise_cached_variables!
super # call the default behaviour which resets the session
end
private
def expire_devise_cached_variables!
Devise.mappings.each { |_,m| instance_variable_set("@current_#{m.name}", nil) }
end
end
end

View File

@@ -6,6 +6,7 @@ module Devise
module InternalHelpers #:nodoc:
extend ActiveSupport::Concern
include Devise::Controllers::ScopedViews
include Devise::Controllers::SharedHelpers
included do
helper DeviseHelper
@@ -16,7 +17,7 @@ module Devise
helper_method *helpers
prepend_before_filter :is_devise_resource?
skip_before_filter *Devise.mappings.keys.map { |m| :"authenticate_#{m}!" }
respond_to *Mime::SET.map(&:to_sym) if mimes_for_respond_to.empty?
end
# Gets the actual resource stored in the instance variable
@@ -54,7 +55,19 @@ module Devise
# Checks whether it's a devise mapped resource or not.
def is_devise_resource? #:nodoc:
unknown_action!("Could not find devise mapping for path #{request.fullpath.inspect}") unless devise_mapping
unknown_action! <<-MESSAGE unless devise_mapping
Could not find devise mapping for path #{request.fullpath.inspect}.
Maybe you forgot to wrap your route inside the scope block? For example:
devise_scope :user do
match "/some/route" => "some_devise_controller"
end
MESSAGE
end
# 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)
@@ -78,12 +91,33 @@ module Devise
# Example:
# before_filter :require_no_authentication, :only => :new
def require_no_authentication
if warden.authenticated?(resource_name)
return unless is_navigational_format?
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 after calling send_*_instructions methods on a resource.
# If we are in paranoid mode, we always act as if the resource was valid
# and instructions were sent.
def successfully_sent?(resource)
notice = if Devise.paranoid
resource.errors.clear
:send_paranoid_instructions
elsif resource.errors.empty?
:send_instructions
end
if notice
set_flash_message :notice, notice if is_navigational_format?
true
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.
@@ -109,6 +143,12 @@ module Devise
def clean_up_passwords(object) #:nodoc:
object.clean_up_passwords if object.respond_to?(:clean_up_passwords)
end
def respond_with_navigational(*args, &block)
respond_with(*args) do |format|
format.any(*navigational_formats, &block)
end
end
end
end
end

View File

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

View File

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

16
lib/devise/delegator.rb Normal file
View File

@@ -0,0 +1,16 @@
module Devise
# Checks the scope in the given environment and returns the associated failure app.
class Delegator
def call(env)
failure_app(env).call(env)
end
def failure_app(env)
app = env["warden.options"] &&
(scope = env["warden.options"][:scope]) &&
Devise.mappings[scope].failure_app
app || Devise::FailureApp
end
end
end

View File

@@ -4,10 +4,10 @@ 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
# Generates a default password digest based on salt, pepper and the
# incoming password.
def self.digest(password, stretches, salt, pepper)
digest = [password, salt].flatten.join('')

View File

@@ -7,7 +7,7 @@ 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
# Generates a default password digest based on salt, pepper and the
# incoming password.
def self.digest(password, stretches, salt, pepper)
Digest::SHA1.hexdigest("--#{salt}--#{password}--")

View File

@@ -9,7 +9,7 @@ module Devise
# the initializer to simulate the default behavior.
class RestfulAuthenticationSha1 < Base
# Gererates a default password digest based on salt, pepper and the
# Generates a default password digest based on salt, pepper and the
# incoming password.
def self.digest(password, stretches, salt, pepper)
digest = pepper

View File

@@ -5,7 +5,7 @@ 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
# Generates a default password digest based on stretches, salt, pepper and the
# incoming password.
def self.digest(password, stretches, salt, pepper)
digest = pepper

View File

@@ -5,7 +5,7 @@ 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
# Generates a default password digest based on salt, pepper and the
# incoming password.
def self.digest(password, stretches, salt, pepper)
digest = pepper

View File

@@ -10,11 +10,13 @@ module Devise
include ActionController::UrlFor
include ActionController::Redirecting
include Rails.application.routes.url_helpers
include Devise::Controllers::SharedHelpers
delegate :flash, :to => :request
def self.call(env)
action(:respond).call(env)
@respond ||= action(:respond)
@respond.call(env)
end
def self.default_url_options(*args)
@@ -64,7 +66,19 @@ module Devise
end
def redirect_url
send(:"new_#{scope}_session_path")
opts = {}
route = :"new_#{scope}_session_path"
opts[:format] = request_format unless skip_format?
if respond_to?(route)
send(route, opts)
else
root_path(opts)
end
end
def skip_format?
%w(html */*).include? request_format.to_s
end
# Choose whether we should respond in a http authentication fashion,
@@ -79,7 +93,7 @@ module Devise
if request.xhr?
Devise.http_authenticatable_on_xhr
else
!(request.format && Devise.navigational_formats.include?(request.format.to_sym))
!(request_format && is_navigational_format?)
end
end
@@ -90,14 +104,22 @@ module Devise
end
def http_auth_body
return i18n_message unless request.format
method = "to_#{request.format.to_sym}"
{}.respond_to?(method) ? { :error => i18n_message }.send(method) : i18n_message
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.camelize}Controller".constantize.action(action)
controller_name = ActiveSupport::Inflector.camelize(controller)
controller_klass = ActiveSupport::Inflector.constantize("#{controller_name}Controller")
controller_klass.action(action)
end
def warden

View File

@@ -1,9 +1,9 @@
# 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?
# 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)
throw :warden, :scope => scope, :message => record.inactive_message

View File

@@ -1,12 +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 frozen.
# remembered again. Notice that we forget the user unless the record is not persisted.
# This avoids forgetting deleted users.
Warden::Manager.before_logout do |record, warden, options|
if record.respond_to?(:forget_me!)
record.forget_me! unless record.frozen?
cookie_options = Rails.configuration.session_options.slice(:path, :domain, :secure)
cookie_options.merge!(record.cookie_options)
warden.cookies.delete("remember_#{options[:scope]}_token", cookie_options)
Devise::Controllers::Rememberable::Proxy.new(warden).forget_me(record)
end
end

View File

@@ -1,45 +1,6 @@
module Devise
module Hooks
# Overwrite success! in authentication strategies allowing users to be remembered.
# We choose to implement this as an strategy hook instead of a warden hook to allow a specific
# strategy (like token authenticatable or facebook authenticatable) to turn off remember_me?
# cookies.
module Rememberable #:nodoc:
def success!(resource)
super
if succeeded? && resource.respond_to?(:remember_me!) && remember_me?
resource.remember_me!(extend_remember_period?)
cookies.signed["remember_#{scope}_token"] = cookie_values(resource)
end
end
protected
def cookie_values(resource)
options = Rails.configuration.session_options.slice(:path, :domain, :secure)
options.merge!(resource.cookie_options)
options.merge!(
:value => resource.class.serialize_into_cookie(resource),
:expires => resource.remember_expires_at
)
options
end
def succeeded?
@result == :success
end
def extend_remember_period?
false
end
def remember_me?
valid_params? && Devise::TRUE_VALUES.include?(params_auth_hash[:remember_me])
end
end
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
Devise::Strategies::Authenticatable.send :include, Devise::Hooks::Rememberable
end

View File

@@ -1,12 +1,12 @@
# 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?(:timedout?) && 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.timedout?(last_request_at)
@@ -17,6 +17,8 @@ Warden::Manager.after_set_user do |record, warden, options|
end
end
warden.session(scope)['last_request_at'] = Time.now.utc
unless warden.request.env['devise.skip_trackable']
warden.session(scope)['last_request_at'] = Time.now.utc
end
end
end

View File

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

View File

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

View File

@@ -22,7 +22,10 @@ module Devise
# # is the modules included in the class
#
class Mapping #:nodoc:
attr_reader :singular, :scoped_path, :path, :controllers, :path_names, :class_name, :sign_out_via
attr_reader :singular, :scoped_path, :path, :controllers, :path_names,
:class_name, :sign_out_via, :format, :used_routes, :used_helpers,
:constraints, :defaults, :failure_app
alias :name :singular
# Receives an object and find a scope for it. If a scope cannot be found,
@@ -50,20 +53,21 @@ module Devise
@singular = (options[:singular] || @scoped_path.tr('/', '_').singularize).to_sym
@class_name = (options[:class_name] || name.to_s.classify).to_s
@ref = ActiveSupport::Dependencies.ref(@class_name)
@klass = Devise.ref(@class_name)
@path = (options[:path] || name).to_s
@path_prefix = options[:path_prefix]
mod = options[:module] || "devise"
@controllers = Hash.new { |h,k| h[k] = "#{mod}/#{k}" }
@controllers.merge!(options[:controllers] || {})
@path_names = Hash.new { |h,k| h[k] = k.to_s }
@path_names.merge!(:registration => "")
@path_names.merge!(options[:path_names] || {})
@sign_out_via = options[:sign_out_via] || Devise.sign_out_via
@format = options[:format]
default_failure_app(options)
default_controllers(options)
default_path_names(options)
default_constraints(options)
default_defaults(options)
default_used_route(options)
default_used_helpers(options)
end
# Return modules for the mapping.
@@ -73,13 +77,17 @@ module Devise
# Gives the class the mapping points to.
def to
@ref.get
@klass.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
@@ -106,5 +114,62 @@ module Devise
end
METHOD
end
private
def default_failure_app(options)
@failure_app = options[:failure_app] || Devise::FailureApp
if @failure_app.is_a?(String)
ref = Devise.ref(@failure_app)
@failure_app = lambda { |env| ref.get.call(env) }
end
end
def default_controllers(options)
mod = options[:module] || "devise"
@controllers = Hash.new { |h,k| h[k] = "#{mod}/#{k}" }
@controllers.merge!(options[:controllers]) if options[:controllers]
@controllers.each { |k,v| @controllers[k] = v.to_s }
end
def default_path_names(options)
@path_names = Hash.new { |h,k| h[k] = k.to_s }
@path_names[:registration] = ""
@path_names.merge!(options[:path_names]) if options[:path_names]
end
def default_constraints(options)
@constraints = Hash.new
@constraints.merge!(options[:constraints]) if options[:constraints]
end
def default_defaults(options)
@defaults = Hash.new
@defaults.merge!(options[:defaults]) if options[:defaults]
end
def default_used_route(options)
singularizer = lambda { |s| s.to_s.singularize.to_sym }
if options.has_key?(:only)
@used_routes = self.routes & Array(options[:only]).map(&singularizer)
elsif options[:skip] == :all
@used_routes = []
else
@used_routes = self.routes - Array(options[:skip]).map(&singularizer)
end
end
def default_used_helpers(options)
singularizer = lambda { |s| s.to_s.singularize.to_sym }
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
end
end

View File

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

View File

@@ -1,8 +1,9 @@
require 'devise/hooks/activatable'
require 'devise/models/serializable'
module Devise
module Models
# Authenticable module. Holds common settings for authentication.
# Authenticatable module. Holds common settings for authentication.
#
# == Options
#
@@ -24,19 +25,19 @@ module Devise
# * +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.
#
# == Active?
# == active_for_authentication?
#
# Before authenticating an user and in each request, Devise checks if your model is active by
# calling model.active?. This method is overwriten by other devise modules. For instance,
# :confirmable overwrites .active? to only return true if your model was confirmed.
# After 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?
# def active_for_authentication?
# super && special_condition_is_valid?
# end
#
# Whenever active? returns false, Devise asks the reason why your model is inactive using
# 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
@@ -46,6 +47,8 @@ module Devise
module Authenticatable
extend ActiveSupport::Concern
include Devise::Models::Serializable
included do
class_attribute :devise_modules, :instance_writer => false
self.devise_modules ||= []
@@ -55,17 +58,13 @@ module Devise
# 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? and
# inactive_message instead.
# However, you should not overwrite this method, you should overwrite active_for_authentication?
# and inactive_message instead.
def valid_for_authentication?
if active?
block_given? ? yield : true
else
inactive_message
end
block_given? ? yield : true
end
def active?
def active_for_authentication?
true
end
@@ -76,8 +75,21 @@ module Devise
def authenticatable_salt
end
def devise_mailer
Devise.mailer
end
module ClassMethods
Devise::Models.config(self, :authentication_keys, :request_keys, :case_insensitive_keys, :http_authenticatable, :params_authenticatable)
Devise::Models.config(self, :authentication_keys, :request_keys, :strip_whitespace_keys, :case_insensitive_keys, :http_authenticatable, :params_authenticatable)
def serialize_into_session(record)
[record.to_key, record.authenticatable_salt]
end
def serialize_from_session(key, salt)
record = to_adapter.get(key)
record if record && record.authenticatable_salt == salt
end
def params_authenticatable?(strategy)
params_authenticatable.is_a?(Array) ?
@@ -100,8 +112,11 @@ module Devise
# end
#
def find_for_authentication(conditions)
case_insensitive_keys.each { |k| conditions[k].try(:downcase!) }
to_adapter.find_first(conditions)
find_first_by_auth_conditions(conditions)
end
def find_first_by_auth_conditions(conditions)
to_adapter.find_first devise_param_filter.filter(conditions)
end
# Find an initialize a record setting an error if it can't be found.
@@ -111,15 +126,13 @@ module Devise
# Find an initialize a group of attributes based on a list of required attributes.
def find_or_initialize_with_errors(required_attributes, attributes, error=:invalid) #:nodoc:
case_insensitive_keys.each { |k| attributes[k].try(:downcase!) }
attributes = attributes.slice(*required_attributes)
attributes.delete_if { |key, value| value.blank? }
if attributes.size == required_attributes.size
record = to_adapter.find_first(attributes)
record = find_first_by_auth_conditions(attributes)
end
unless record
record = new
@@ -133,6 +146,12 @@ module Devise
record
end
protected
def devise_param_filter
@devise_param_filter ||= Devise::ParamFilter.new(case_insensitive_keys, strip_whitespace_keys)
end
# Generate a token by looping and ensuring does not already exist.
def generate_token(column)
loop do

View File

@@ -29,12 +29,12 @@ module Devise
after_create :send_confirmation_instructions, :if => :confirmation_required?
end
# Confirm a user by setting it's confirmed_at to actual time. If the user
# Confirm a user by setting its confirmed_at to actual time. If the user
# is already confirmed, add en error to email field
def confirm!
unless_confirmed do
self.confirmation_token = nil
self.confirmed_at = Time.now
self.confirmed_at = Time.now.utc
save(:validate => false)
end
end
@@ -47,7 +47,7 @@ module Devise
# Send confirmation instructions by email
def send_confirmation_instructions
generate_confirmation_token! if self.confirmation_token.nil?
::Devise.mailer.confirmation_instructions(self).deliver
self.devise_mailer.confirmation_instructions(self).deliver
end
# Resend confirmation token. This method does not need to generate a new token.
@@ -55,11 +55,11 @@ module Devise
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?
def active_for_authentication?
super && (!confirmation_required? || confirmed? || confirmation_period_valid?)
end
@@ -71,7 +71,7 @@ module Devise
# 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
self.confirmed_at = Time.now.utc
end
protected
@@ -84,7 +84,7 @@ module Devise
# Checks if the confirmation for the user is within the limit time.
# We do this by calculating if the difference between today and the
# confirmation sent date does not exceed the confirm in time configured.
# Confirm_in is a model configuration, must always be an integer value.
# Confirm_within is a model configuration, must always be an integer value.
#
# Example:
#
@@ -127,18 +127,23 @@ module Devise
generate_confirmation_token && save(:validate => false)
end
def after_password_reset
super
confirm! unless confirmed?
end
module ClassMethods
# Attempt to find a user by it's email. If a record is found, send new
# Attempt to find a user by its email. If a record is found, send new
# confirmation instructions to it. If not user is found, returns a new user
# with an email not found error.
# Options must contain the user email
def send_confirmation_instructions(attributes={})
confirmable = find_or_initialize_with_error_by(:email, attributes[:email], :not_found)
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
@@ -153,7 +158,7 @@ module Devise
generate_token(:confirmation_token)
end
Devise::Models.config(self, :confirm_within)
Devise::Models.config(self, :confirm_within, :confirmation_keys)
end
end
end

View File

@@ -3,13 +3,16 @@ require 'bcrypt'
module Devise
module Models
# Authenticable Module, responsible for encrypting password and validating
# 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
@@ -22,7 +25,8 @@ module Devise
included do
attr_reader :password, :current_password
attr_accessor :password_confirmation
before_save :downcase_keys
before_validation :downcase_keys
before_validation :strip_whitespace
end
# Generates password encryption based on the given value.
@@ -31,9 +35,12 @@ module Devise
self.encrypted_password = password_digest(@password) if @password.present?
end
# Verifies whether an incoming_password (ie from sign in) is the user password.
# Verifies whether an password (ie from sign in) is the user password.
def valid_password?(password)
::BCrypt::Password.new(self.encrypted_password) == "#{password}#{self.class.pepper}"
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
@@ -55,8 +62,9 @@ module Devise
result = if valid_password?(current_password)
update_attributes(params)
else
self.errors.add(:current_password, current_password.blank? ? :blank : :invalid)
self.attributes = params
self.valid?
self.errors.add(:current_password, current_password.blank? ? :blank : :invalid)
false
end
@@ -64,6 +72,27 @@ module Devise
result
end
# Updates record attributes without asking for the current password.
# Never allows to change the current password. If you are using this
# method, you should probably override this method to protect other
# attributes you would not like to be updated without a password.
#
# Example:
#
# def update_without_password(params={})
# params.delete(:email)
# super(params)
# end
#
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
@@ -76,7 +105,11 @@ module Devise
# Downcase case-insensitive keys
def downcase_keys
self.class.case_insensitive_keys.each { |k| self[k].try(:downcase!) }
(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.

View File

@@ -36,7 +36,7 @@ module Devise
# Verifies whether an incoming_password (ie from sign in) is the user password.
def valid_password?(incoming_password)
password_digest(incoming_password) == self.encrypted_password
Devise.secure_compare(password_digest(incoming_password), self.encrypted_password)
end
protected
@@ -53,7 +53,14 @@ module Devise
# Returns the class for the configured encryptor.
def encryptor_class
@encryptor_class ||= ::Devise::Encryptors.const_get(encryptor.to_s.classify)
@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

View File

@@ -3,27 +3,28 @@ module Devise
# Handles blocking a user access after a certain number of attempts.
# Lockable accepts two different strategies to unlock a user after it's
# blocked: email and time. The former will send an email to the user when
# the lock happens, containing a link to unlock it's account. The second
# the lock happens, containing a link to unlock its account. The second
# will unlock the user automatically after some configured time (ie 2.hours).
# It's also possible to setup lockable to use both email and time strategies.
#
# == Options
#
# Lockable adds the following options to devise_for:
# Lockable adds the following options to +devise+:
#
# * +maximum_attempts+: how many attempts should be accepted before blocking the user.
# * +lock_strategy+: lock the user account by :failed_attempts or :none.
# * +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 an user setting it's locked_at to actual time.
# Lock a user setting its locked_at to actual time.
def lock_access!
self.locked_at = Time.now
self.locked_at = Time.now.utc
if unlock_strategy_enabled?(:email)
generate_unlock_token
@@ -33,14 +34,12 @@ module Devise
save(:validate => false)
end
# Unlock an user by cleaning locket_at and failed_attempts.
# Unlock a user by cleaning locket_at and failed_attempts.
def unlock_access!
if_access_locked do
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
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.
@@ -50,7 +49,7 @@ module Devise
# Send unlock instructions by email
def send_unlock_instructions
::Devise.mailer.unlock_instructions(self).deliver
self.devise_mailer.unlock_instructions(self).deliver
end
# Resend the unlock instructions if the user is locked.
@@ -58,9 +57,9 @@ module Devise
if_access_locked { send_unlock_instructions }
end
# Overwrites active? from Devise::Models::Activatable for locking purposes
# by verifying whether an user is active to sign in or not based on locked?
def active?
# 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
@@ -71,28 +70,30 @@ module Devise
end
# Overwrites valid_for_authentication? from Devise::Models::Authenticatable
# for verifying whether an user is allowed to sign in or not. If the user
# 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)
case (result = super)
when Symbol
return result
when TrueClass
# 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?
if super
self.failed_attempts = 0
when FalseClass
# PostgreSQL uses nil as the default value for integer columns set to 0
save(:validate => false)
true
else
self.failed_attempts ||= 0
self.failed_attempts += 1
if attempts_exceeded?
lock_access!
lock_access! unless access_locked?
return :locked
else
save(:validate => false)
end
false
end
save(:validate => false) if changed?
result
end
protected
@@ -127,17 +128,17 @@ module Devise
end
module ClassMethods
# Attempt to find a user by it's email. If a record is found, send new
# Attempt to find a user by its email. If a record is found, send new
# unlock instructions to it. If not user is found, returns a new user
# with an email not found error.
# Options must contain the user email
def send_unlock_instructions(attributes={})
lockable = find_or_initialize_with_errors(authentication_keys, attributes, :not_found)
lockable = find_or_initialize_with_errors(unlock_keys, attributes, :not_found)
lockable.resend_unlock_token if lockable.persisted?
lockable
end
# Find a user by it's unlock token and try to unlock it.
# Find a user by its unlock token and try to unlock it.
# If no user is found, returns a new user with an error.
# If the user is not locked, creates an error for the user
# Options must have the unlock_token
@@ -161,7 +162,7 @@ module Devise
Devise.friendly_token
end
Devise::Models.config(self, :maximum_attempts, :lock_strategy, :unlock_strategy, :unlock_in)
Devise::Models.config(self, :maximum_attempts, :lock_strategy, :unlock_strategy, :unlock_in, :unlock_keys)
end
end
end

View File

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

View File

@@ -7,7 +7,7 @@ module Devise
module ClassMethods
# A convenience method that receives both parameters and session to
# initialize an user. This can be used by OAuth, for example, to send
# 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

View File

@@ -44,10 +44,7 @@ module Devise
module Rememberable
extend ActiveSupport::Concern
included do
# Remember me option available in after_authentication hook.
attr_accessor :remember_me
end
attr_accessor :remember_me, :extend_remember_period
# 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.
@@ -57,12 +54,14 @@ module Devise
save(:validate => false)
end
# Removes the remember token only if it exists, and save the record
# without validations.
# If the record is persisted, remove the remember token (but only if
# it exists), and save the record without validations.
def forget_me!
self.remember_token = nil if respond_to?(:remember_token)
self.remember_created_at = nil
save(:validate => false)
if persisted?
self.remember_token = nil if respond_to?(:remember_token=)
self.remember_created_at = nil
save(:validate => false)
end
end
# Remember token should be expired if expiration time not overpass now.

View File

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

View File

@@ -20,7 +20,7 @@ module Devise
#
# == Options
#
# TokenAuthenticable adds the following options to devise_for:
# 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=...
#
@@ -38,17 +38,17 @@ module Devise
# Generate new authentication token and save the record.
def reset_authentication_token!
reset_authentication_token
self.save(:validate => false)
save(:validate => false)
end
# Generate authentication token unless already exists.
def ensure_authentication_token
self.reset_authentication_token if self.authentication_token.blank?
reset_authentication_token if authentication_token.blank?
end
# Generate authentication token unless already exists and save the record.
def ensure_authentication_token!
self.reset_authentication_token! if self.authentication_token.blank?
reset_authentication_token! if authentication_token.blank?
end
# Hook called after token authentication.

View File

@@ -5,18 +5,18 @@ module Devise
# Track information about your user sign in. It tracks the following columns:
#
# * sign_in_count - Increased every time a sign in is made (by form, openid, oauth)
# * current_sign_in_at - A tiemstamp updated when the user signs in
# * current_sign_in_at - A timestamp updated when the user signs in
# * last_sign_in_at - Holds the timestamp of the previous sign in
# * current_sign_in_ip - The remote ip updated when the user sign in
# * last_sign_in_at - Holds the remote ip of the previous sign in
# * last_sign_in_ip - Holds the remote ip of the previous sign in
#
module Trackable
def update_tracked_fields!(request)
old_current, new_current = self.current_sign_in_at, Time.now
old_current, new_current = self.current_sign_in_at, Time.now.utc
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
old_current, new_current = self.current_sign_in_ip, request.ip
self.last_sign_in_ip = old_current || new_current
self.current_sign_in_ip = new_current

View File

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

View File

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

View File

@@ -1,47 +1,28 @@
begin
require "omniauth/core"
require "omniauth"
require 'omniauth/version'
rescue LoadError => e
warn "Could not load 'omniauth/core'. Please ensure you have the oa-core gem installed and listed in your Gemfile."
warn "Could not load 'omniauth'. Please ensure you have the omniauth gem >= 1.0.0 installed and listed in your Gemfile."
raise
end
module OmniAuth
# TODO HAXES Backport to OmniAuth
module Strategy #:nodoc:
def initialize(app, name, *args)
@app = app
@name = name.to_sym
@options = args.last.is_a?(Hash) ? args.pop : {}
yield self if block_given?
end
def fail!(message_key, exception = nil)
self.env['omniauth.error'] = exception
self.env['omniauth.failure_key'] = message_key
self.env['omniauth.failed_strategy'] = self
OmniAuth.config.on_failure.call(self.env, message_key.to_sym)
end
end
unless OmniAuth::VERSION =~ /^1\./
raise "You are using an old OmniAuth version, please ensure you have 1.0.0.pr2 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, key|
OmniAuth.config.on_failure = Proc.new do |env|
env['devise.mapping'] = Devise::Mapping.find_by_path!(env['PATH_INFO'], :path)
controller_klass = "#{env['devise.mapping'].controllers[:omniauth_callbacks].camelize}Controller"
controller_klass.constantize.action(:failure).call(env)
controller_name = ActiveSupport::Inflector.camelize(env['devise.mapping'].controllers[:omniauth_callbacks])
controller_klass = ActiveSupport::Inflector.constantize("#{controller_name}Controller")
controller_klass.action(:failure).call(env)
end
module Devise
module OmniAuth
autoload :Config, "devise/omniauth/config"
autoload :UrlHelpers, "devise/omniauth/url_helpers"
autoload :TestHelpers, "devise/omniauth/test_helpers"
class << self
delegate :short_circuit_authorizers!, :unshort_circuit_authorizers!,
:test_mode!, :stub!, :reset_stubs!, :to => "Devise::OmniAuth::TestHelpers"
end
end
end

View File

@@ -2,29 +2,45 @@ module Devise
module OmniAuth
class Config
attr_accessor :strategy
attr_reader :args
attr_reader :args, :options, :provider
def initialize(provider, args)
@provider = provider
@args = args
@strategy = nil
@options = @args.last.is_a?(Hash) ? @args.last : {}
end
# open_id strategy can have configurable name
def strategy_name
options[:name] || @provider
end
def strategy_class
::OmniAuth::Strategies.const_get("#{::OmniAuth::Utils.camelize(@provider.to_s)}")
find_strategy || require_strategy
end
def check_if_allow_stubs!
raise "OmniAuth strategy for #{@provider} does not allow stubs, only OAuth2 ones do." unless allow_stubs?
def find_strategy
::OmniAuth.strategies.find do |strategy_class|
strategy_class.to_s =~ /#{::OmniAuth::Utils.camelize(strategy_name)}$/ ||
strategy_class.default_options[:name] == strategy_name
end
end
def allow_stubs?
defined?(::OmniAuth::Strategies::OAuth2) && strategy.is_a?(::OmniAuth::Strategies::OAuth2)
def require_strategy
if [:facebook, :github, :twitter].include?(provider.to_sym)
require "omniauth/strategies/#{provider}"
elsif options[:require]
require options[:require]
else
require "omniauth-#{provider}"
end
find_strategy || autoload_strategy
end
def build_connection(&block)
strategy.client.connection.build(&block)
def autoload_strategy
::OmniAuth::Strategies.const_get(::OmniAuth::Utils.camelize(provider.to_s))
end
end
end
end
end

View File

@@ -1,57 +0,0 @@
module Devise
module OmniAuth
module TestHelpers
def self.test_mode!
Faraday.default_adapter = :test if defined?(Faraday)
ActiveSupport.on_load(:action_controller) { include Devise::OmniAuth::TestHelpers }
ActiveSupport.on_load(:action_view) { include Devise::OmniAuth::TestHelpers }
end
def self.stub!(provider, stubs=nil, &block)
raise "You either need to pass stubs as a block or as a parameter" unless block_given? || stubs
config = Devise.omniauth_configs[provider]
raise "Could not find configuration for #{provider.to_s} omniauth provider" unless config
config.check_if_allow_stubs!
stubs ||= Faraday::Adapter::Test::Stubs.new(&block)
config.build_connection do |b|
b.adapter :test, stubs
end
end
def self.reset_stubs!(*providers)
target = providers.any? ? Devise.omniauth_configs.slice(*providers) : Devise.omniauth_configs
target.each_value do |config|
next unless config.allow_stubs?
config.build_connection { |b| b.adapter Faraday.default_adapter }
end
end
def self.short_circuit_authorizers!
module_eval <<-ALIASES, __FILE__, __LINE__ + 1
def omniauth_authorize_path(*args)
omniauth_callback_path(*args)
end
ALIASES
Devise.mappings.each_value do |m|
next unless m.omniauthable?
module_eval <<-ALIASES, __FILE__, __LINE__ + 1
def #{m.name}_omniauth_authorize_path(provider)
#{m.name}_omniauth_callback_path(provider)
end
ALIASES
end
end
def self.unshort_circuit_authorizers!
module_eval do
instance_methods.each { |m| remove_method(m) }
end
end
end
end
end

View File

@@ -7,7 +7,11 @@ module Devise
class_eval <<-URL_HELPERS, __FILE__, __LINE__ + 1
def #{mapping.name}_omniauth_authorize_path(provider, params = {})
if Devise.omniauth_configs[provider.to_sym]
"/#{mapping.path}/auth/\#{provider}\#{'?'+params.to_param if params.present?}"
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
@@ -26,4 +30,4 @@ module Devise
end
end
end
end
end

View File

@@ -0,0 +1,41 @@
module Devise
class ParamFilter
def initialize(case_insensitive_keys, strip_whitespace_keys)
@case_insensitive_keys = case_insensitive_keys || []
@strip_whitespace_keys = strip_whitespace_keys || []
end
def filter(conditions)
conditions = stringify_params(conditions.dup)
@case_insensitive_keys.each do |k|
value = conditions[k]
next unless value.respond_to?(:downcase)
conditions[k] = value.downcase
end
@strip_whitespace_keys.each do |k|
value = conditions[k]
next unless value.respond_to?(:strip)
conditions[k] = value.strip
end
conditions
end
# Force keys to be string to avoid injection on mongoid related database.
def stringify_params(conditions)
return conditions unless conditions.is_a?(Hash)
conditions.each do |k, v|
conditions[k] = v.to_s if param_requires_string_conversion?(v)
end
end
private
# Determine which values should be transformed to string or passed as-is to the query builder underneath
def param_requires_string_conversion?(value)
true unless value.is_a?(TrueClass) || value.is_a?(FalseClass) || value.is_a?(Fixnum)
end
end
end

View File

@@ -29,20 +29,16 @@ module Devise
end
end
initializer "devise.encryptor_check" do
case Devise.encryptor
when :bcrypt
puts "[DEVISE] From version 1.2, there is no need to set your encryptor to bcrypt " <<
"since encryptors are only enabled if you include :encryptable in your models. " <<
"With this change, we can integrate better with bcrypt and get rid of the " <<
"password_salt column (since bcrypt stores the salt with password). " <<
"Please comment config.encryptor in your initializer to get rid of this warning."
when nil
# Nothing to say
else
puts "[DEVISE] You are using #{Devise.encryptor} as encryptor. From version 1.2, " <<
"you need to explicitly add `devise :encryptable, :encryptor => #{Devise.encryptor.to_sym}` " <<
"to your models and comment the current value in the config/initializers/devise.rb"
initializer "devise.mongoid_version_warning" do
if defined?(Mongoid)
require 'mongoid/version'
if Mongoid::VERSION.to_f < 2.1
puts "\n[DEVISE] Please note that Mongoid versions prior to 2.1 handle dirty model " \
"object attributes in such a way that the Devise `validatable` module will not apply " \
"its usual uniqueness and format validations for the email field. It is recommended " \
"that you upgrade to Mongoid 2.1+ for this and other fixes, but if for some reason you " \
"are unable to do so, you should add these validations manually.\n"
end
end
end
end

View File

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

View File

@@ -15,21 +15,16 @@ end
class Warden::SessionSerializer
def serialize(record)
[record.class.name, record.to_key, record.authenticatable_salt]
klass = record.class
array = klass.serialize_into_session(record)
array.unshift(klass.name)
end
def deserialize(keys)
if keys.size == 2
raise "Devise changed how it stores objects in session. If you are seeing this message, " <<
"you can fix it by changing one character in your cookie secret or cleaning up your " <<
"database sessions if you are using a db store."
end
klass, id, salt = keys
klass, *args = keys
begin
record = klass.constantize.to_adapter.get(id)
record if record && record.authenticatable_salt == salt
ActiveSupport::Inflector.constantize(klass).serialize_from_session(*args)
rescue NameError => e
if e.message =~ /uninitialized constant/
Rails.logger.debug "[Devise] Trying to deserialize invalid class #{klass}"
@@ -47,6 +42,10 @@ unless Devise.rack_session?
alias_method :regular_writer, :[]= unless method_defined?(:regular_writer)
alias_method :regular_update, :update unless method_defined?(:regular_update)
def [](key)
super(convert_key(key))
end
def []=(key, value)
regular_writer(convert_key(key), value)
end
@@ -91,6 +90,7 @@ unless Devise.rack_session?
def symbolize_keys; to_hash.symbolize_keys end
def to_options!; self end
def to_hash; Hash.new.update(self) end
protected

View File

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

View File

@@ -19,13 +19,27 @@ module Devise
result = resource && resource.valid_for_authentication?(&block)
case result
when Symbol, String
when String, Symbol
fail!(result)
false
when TrueClass
decorate(resource)
true
else
result
end
end
# Get values from params and set in the resource.
def decorate(resource)
resource.remember_me = remember_me? if resource.respond_to?(:remember_me=)
end
# Should this resource be marked to be remembered?
def remember_me?
valid_params? && Devise::TRUE_VALUES.include?(params_auth_hash[:remember_me])
end
# Check if this is strategy is valid for http authentication by:
#
# * Validating if the model allows params authentication;
@@ -71,17 +85,7 @@ module Devise
# By default, a request is valid if the controller is allowed and the VERB is POST.
def valid_request?
valid_controller? && valid_verb?
end
# Check if the controller is the one registered for authentication.
def valid_controller?
mapping.controllers[:sessions] == params[:controller]
end
# Check if it was a POST request.
def valid_verb?
request.post?
!!env["devise.allow_params_authentication"]
end
# If the request is valid, finally check if params_auth_hash returns a hash.
@@ -143,7 +147,8 @@ module Devise
# becomes simply :database.
def authenticatable_name
@authenticatable_name ||=
self.class.name.split("::").last.underscore.sub("_authenticatable", "").to_sym
ActiveSupport::Inflector.underscore(self.class.name.split("::").last).
sub("_authenticatable", "").to_sym
end
end
end

View File

@@ -10,7 +10,7 @@ module Devise
if validate(resource){ resource.valid_password?(password) }
resource.after_database_authentication
success!(resource)
else
elsif !halted?
fail(:invalid)
end
end

View File

@@ -9,6 +9,7 @@ module Devise
class Rememberable < Authenticatable
# A valid strategy for rememberable needs a remember token in the cookies.
def valid?
@remember_cookie = nil
remember_cookie.present?
end
@@ -20,7 +21,7 @@ module Devise
if validate(resource)
success!(resource)
else
elsif !halted?
cookies.delete(remember_key)
pass
end
@@ -28,6 +29,11 @@ module Devise
private
def decorate(resource)
super
resource.extend_remember_period = mapping.to.extend_remember_period if resource.respond_to?(:extend_remember_period=)
end
def remember_me?
true
end
@@ -36,14 +42,10 @@ module Devise
"remember_#{scope}_token"
end
def extend_remember_period?
mapping.to.extend_remember_period
end
# Accessor for remember cookie
def remember_cookie
@remember_cookie ||= cookies.signed[remember_key]
end
end
end
end

View File

@@ -20,7 +20,7 @@ module Devise
if validate(resource)
resource.after_token_authentication
success!(resource)
else
elsif !halted?
fail(:invalid_token)
end
end
@@ -39,7 +39,11 @@ module Devise
# Try both scoped and non scoped keys.
def params_auth_hash
params[scope] || params
if params[scope].kind_of?(Hash) && params[scope].has_key?(authentication_keys.first)
params[scope]
else
params
end
end
# Overwrite authentication keys to use token_authentication_key.

View File

@@ -1,7 +1,7 @@
module Devise
# Devise::TestHelpers provides a facility to test controllers in isolation
# when using ActionController::TestCase allowing you to quickly sign_in or
# sign_out an user. Do not use Devise::TestHelpers in integration tests.
# sign_out a user. Do not use Devise::TestHelpers in integration tests.
#
# Notice you should not test Warden specific behavior (like Warden callbacks)
# using Devise::TestHelpers since it is a stub of the actual behavior. Such
@@ -13,48 +13,11 @@ module Devise
end
end
# This is a Warden::Proxy customized for functional tests. It's meant to
# some of Warden::Manager responsibilities, as retrieving configuration
# options and calling the FailureApp.
class TestWarden < Warden::Proxy #:nodoc:
attr_reader :controller
def initialize(controller)
@controller = controller
manager = Warden::Manager.new(nil) do |config|
config.merge! Devise.warden_config
end
super(controller.request.env, manager)
end
def authenticate!(*args)
catch_with_redirect { super }
end
def user(*args)
catch_with_redirect { super }
end
def catch_with_redirect(&block)
result = catch(:warden, &block)
if result.is_a?(Hash) && !custom_failure? && !@controller.send(:performed?)
result[:action] ||= :unauthenticated
env = @controller.request.env
env["PATH_INFO"] = "/#{result[:action]}"
env["warden.options"] = result
Warden::Manager._before_failure.each{ |hook| hook.call(env, result) }
status, headers, body = Devise::FailureApp.call(env).to_a
@controller.send :render, :status => status, :text => body,
:content_type => headers["Content-Type"], :location => headers["Location"]
nil
else
result
end
end
# Override process to consider warden.
def process(*)
result = nil
_catch_warden { result = super }
result
end
# We need to setup the environment variables and the response in the controller.
@@ -64,7 +27,12 @@ module Devise
# Quick access to Warden::Proxy.
def warden #:nodoc:
@warden ||= (@request.env['warden'] = TestWarden.new(@controller))
@warden ||= begin
manager = Warden::Manager.new(nil) do |config|
config.merge! Devise.warden_config
end
@request.env['warden'] = Warden::Proxy.new(@request.env, manager)
end
end
# sign_in a given resource by storing its keys in the session.
@@ -96,5 +64,27 @@ module Devise
warden.session_serializer.delete(scope, user)
end
protected
def _catch_warden(&block)
result = catch(:warden, &block)
if result.is_a?(Hash) && !warden.custom_failure? && !@controller.send(:performed?)
result[:action] ||= :unauthenticated
env = @controller.request.env
env["PATH_INFO"] = "/#{result[:action]}"
env["warden.options"] = result
Warden::Manager._run_callbacks(:before_failure, env, result)
status, headers, body = Devise.warden_config[:failure_app].call(env).to_a
@controller.send :render, :status => status, :text => body,
:content_type => headers["Content-Type"], :location => headers["Location"]
nil
else
result
end
end
end
end

View File

@@ -1,3 +1,3 @@
module Devise
VERSION = "1.2.rc".freeze
VERSION = "1.5.0.rc1".freeze
end

View File

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

View File

@@ -1,5 +1,9 @@
class DeviseCreate<%= table_name.camelize %> < ActiveRecord::Migration
<% if ::Rails::VERSION::MAJOR == 3 && ::Rails::VERSION::MINOR >= 1 -%>
def change
<% else -%>
def self.up
<% end -%>
create_table(:<%= table_name %>) do |t|
t.database_authenticatable :null => false
t.recoverable
@@ -11,7 +15,7 @@ class DeviseCreate<%= table_name.camelize %> < ActiveRecord::Migration
# t.lockable :lock_strategy => :<%= Devise.lock_strategy %>, :unlock_strategy => :<%= Devise.unlock_strategy %>
# t.token_authenticatable
<% for attribute in attributes -%>
<% attributes.each do |attribute| -%>
t.<%= attribute.type %> :<%= attribute.name %>
<% end -%>
@@ -22,9 +26,12 @@ class DeviseCreate<%= table_name.camelize %> < ActiveRecord::Migration
add_index :<%= table_name %>, :reset_password_token, :unique => true
# add_index :<%= table_name %>, :confirmation_token, :unique => true
# add_index :<%= table_name %>, :unlock_token, :unique => true
# add_index :<%= table_name %>, :authentication_token, :unique => true
end
<% unless ::Rails::VERSION::MAJOR == 3 && ::Rails::VERSION::MINOR >= 1 -%>
def self.down
drop_table :<%= table_name %>
end
<% end -%>
end

View File

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

View File

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

View File

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

View File

@@ -12,8 +12,15 @@ CONTENT
end
def model_exists?
return @model_exists if instance_variable_defined?(:@model_exists)
@model_exists = File.exists?(File.join(destination_root, model_path))
File.exists?(File.join(destination_root, model_path))
end
def migration_exists?(table_name)
Dir.glob("#{File.join(destination_root, migration_path)}/[0-9]*_*.rb").grep(/\d+_add_devise_to_#{table_name}.rb$/).first
end
def migration_path
@migration_path ||= File.join("db", "migrate")
end
def model_path

View File

@@ -1,63 +1,98 @@
module Devise
module Generators
# Include this module in your generator to generate Devise views.
# `copy_views` is the main method and by default copies all views
# with forms.
module ViewPathTemplates #:nodoc:
extend ActiveSupport::Concern
included do
argument :scope, :required => false, :default => nil,
:desc => "The scope to copy views to"
public_task :copy_views
end
def copy_views
view_directory :confirmations
view_directory :passwords
view_directory :registrations
view_directory :sessions
view_directory :unlocks
end
protected
def view_directory(name, _target_path = nil)
directory name.to_s, _target_path || "#{target_path}/#{name}"
end
def target_path
@target_path ||= "app/views/#{scope || :devise}"
end
end
class SharedViewsGenerator < Rails::Generators::Base #:nodoc:
include ViewPathTemplates
source_root File.expand_path("../../../../app/views/devise", __FILE__)
desc "Copies shared Devise views to your application."
# Override copy_views to just copy mailer and shared.
def copy_views
view_directory :shared
end
end
class FormForGenerator < Rails::Generators::Base #:nodoc:
include ViewPathTemplates
source_root File.expand_path("../../../../app/views/devise", __FILE__)
desc "Copies default Devise views to your application."
end
class SimpleFormForGenerator < Rails::Generators::Base #:nodoc:
include ViewPathTemplates
source_root File.expand_path("../../templates/simple_form_for", __FILE__)
desc "Copies simple form enabled views to your application."
end
class ErbGenerator < Rails::Generators::Base #:nodoc:
include ViewPathTemplates
source_root File.expand_path("../../../../app/views/devise", __FILE__)
desc "Copies Devise mail erb views to your application."
def copy_views
view_directory :mailer
end
end
class MarkerbGenerator < Rails::Generators::Base #:nodoc:
include ViewPathTemplates
source_root File.expand_path("../../templates", __FILE__)
desc "Copies Devise mail markerb views to your application."
def copy_views
view_directory :markerb, target_path
end
def target_path
"app/views/#{scope || :devise}/mailer"
end
end
class ViewsGenerator < Rails::Generators::Base
source_root File.expand_path("../../../../app/views", __FILE__)
desc "Copies all Devise views to your application."
desc "Copies Devise views to your application."
argument :scope, :required => false, :default => nil,
:desc => "The scope to copy views to"
class_option :template_engine, :type => :string, :aliases => "-t",
:desc => "Template engine for the views. Available options are 'erb' and 'haml'."
invoke SharedViewsGenerator
hook_for :form_builder, :aliases => "-b",
:desc => "Form builder to be used",
:default => defined?(SimpleForm) ? "simple_form_for" : "form_for"
def copy_views
case options[:template_engine].to_s
when "haml"
verify_haml_existence
verify_haml_version
create_and_copy_haml_views
else
directory "devise", "app/views/#{scope || :devise}"
end
end
protected
def verify_haml_existence
begin
require 'haml'
rescue LoadError
say "HAML is not installed, or it is not specified in your Gemfile."
exit
end
end
def verify_haml_version
unless Haml.version[:major] == 2 and Haml.version[:minor] >= 3 or Haml.version[:major] >= 3
say "To generate HAML templates, you need to install HAML 2.3 or above."
exit
end
end
def create_and_copy_haml_views
require 'tmpdir'
html_root = "#{self.class.source_root}/devise"
Dir.mktmpdir("devise-haml.") do |haml_root|
Dir["#{html_root}/**/*"].each do |path|
relative_path = path.sub(html_root, "")
source_path = (haml_root + relative_path).sub(/erb$/, "haml")
if File.directory?(path)
FileUtils.mkdir_p(source_path)
else
`html2haml -r #{path} #{source_path}`
end
end
directory haml_root, "app/views/#{scope || :devise}"
end
end
hook_for :markerb, :desc => "Generate markerb instead of erb mail views",
:default => defined?(Markerb) ? :markerb : :erb,
:type => :boolean
end
end
end
end

View File

@@ -6,11 +6,11 @@ module Mongoid
include Devise::Generators::OrmHelpers
def generate_model
invoke "mongoid:model", [name] unless model_exists?
invoke "mongoid:model", [name] unless model_exists? && behavior == :invoke
end
def inject_devise_content
inject_into_file model_path, model_contents, :after => "include Mongoid::Document\n"
inject_into_file model_path, model_contents, :after => "include Mongoid::Document\n" if model_exists?
end
end
end

View File

@@ -22,4 +22,11 @@ Some setup you must do manually if you haven't yet:
<p class="notice"><%= notice %></p>
<p class="alert"><%= alert %></p>
4. If you are deploying Rails 3.1 on Heroku, you may want to set:
config.assets.initialize_on_precompile = false
On config/application.rb forcing your application to not access the DB
or load models when precompiling your assets.
===============================================================================

View File

@@ -2,8 +2,9 @@
# four configuration values can also be set straight in your models.
Devise.setup do |config|
# ==> Mailer Configuration
# Configure the e-mail address which will be shown in DeviseMailer.
config.mailer_sender = "please-change-me@config-initializers-devise.com"
# Configure the e-mail address which will be shown in Devise::Mailer,
# note that it will be overwritten if you use your own mailer class with default "from" parameter.
config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com"
# Configure the class responsible to send e-mails.
# config.mailer = "Devise::Mailer"
@@ -34,7 +35,12 @@ Devise.setup do |config|
# Configure which authentication keys should be case-insensitive.
# These keys will be downcased upon creating or modifying a user and when used
# to authenticate or find a user. Default is :email.
# config.case_insensitive_keys = [ :email ]
config.case_insensitive_keys = [ :email ]
# Configure which authentication keys should have whitespace stripped.
# These keys will have whitespace before and after removed upon creating or
# modifying a user and when used to authenticate or find a user. Default is :email.
config.strip_whitespace_keys = [ :email ]
# Tell if authentication through request.params is enabled. True by default.
# config.params_authenticatable = true
@@ -48,20 +54,34 @@ Devise.setup do |config|
# The realm used in Http Basic Authentication. "Application" by default.
# config.http_authentication_realm = "Application"
# It will change confirmation, password recovery and other workflows
# to behave the same regardless if the e-mail provided was right or wrong.
# Does not affect registerable.
# config.paranoid = true
# ==> Configuration for :database_authenticatable
# For bcrypt, this is the cost for hashing the password and defaults to 10. If
# using other encryptors, it sets how many times you want the password re-encrypted.
config.stretches = 10
#
# Limiting the stretches to just one in testing will increase the performance of
# your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
# a value less than 10 in other environments.
config.stretches = Rails.env.test? ? 1 : 10
# Setup a pepper to generate the encrypted password.
# config.pepper = <%= SecureRandom.hex(64).inspect %>
# ==> Configuration for :confirmable
# The time you want to give your user to confirm his account. During this time
# he will be able to access your application without confirming. Default is 0.days
# When confirm_within is zero, the user won't be able to sign in without confirming.
# You can use this to let your user access some features of your application
# without confirming the account, but blocking it after a certain period
# (ie 2 days).
# A period that the user is allowed to access the website even without
# confirming his account. For instance, if set to 2.days, the user will be
# able to access the website for two days without confirming his account,
# access will be blocked just in the third day. Default is 0.days, meaning
# the user cannot access the website without confirming his account.
# config.confirm_within = 2.days
# Defines which key will be used when confirming an account
# config.confirmation_keys = [ :email ]
# ==> Configuration for :rememberable
# The time the user will be remembered without asking for credentials again.
# config.remember_for = 2.weeks
@@ -76,12 +96,18 @@ Devise.setup do |config|
# to false if you are not using database authenticatable.
config.use_salt_as_remember_token = true
# ==> Configuration for :validatable
# Range for password length. Default is 6..20.
# config.password_length = 6..20
# Options to be passed to the created cookie. For instance, you can set
# :secure => true in order to force SSL only cookies.
# config.cookie_options = {}
# Regex to use to validate the email address
# config.email_regexp = /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i
# ==> Configuration for :validatable
# Range for password length. Default is 6..128.
# config.password_length = 6..128
# Email regex used to validate email formats. It simply asserts that
# an one (and only one) @ exists in the given string. This is mainly
# to give user feedback and not to assert the e-mail validity.
# config.email_regexp = /\A[^@]+@[^@]+\z/
# ==> Configuration for :timeoutable
# The time you want to timeout the user session without activity. After this
@@ -94,6 +120,9 @@ Devise.setup do |config|
# :none = No lock strategy. You should handle locking by yourself.
# config.lock_strategy = :failed_attempts
# Defines which key will be used when locking and unlocking an account
# config.unlock_keys = [ :email ]
# Defines which strategy will be used to unlock an account.
# :email = Sends an unlock link to the user email
# :time = Re-enables login after a certain amount of time (see :unlock_in below)
@@ -108,6 +137,16 @@ Devise.setup do |config|
# Time interval to unlock the account if :time is enabled as unlock_strategy.
# config.unlock_in = 1.hour
# ==> Configuration for :recoverable
#
# Defines which key will be used when recovering the password for an account
# config.reset_password_keys = [ :email ]
# Time interval you can reset your password with a reset password key.
# Don't put a too small interval or your users won't have the time to
# change their passwords.
config.reset_password_within = 2.hours
# ==> Configuration for :encryptable
# Allow you to use another encryption algorithm besides bcrypt (default). You can use
# :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1,
@@ -116,9 +155,6 @@ Devise.setup do |config|
# REST_AUTH_SITE_KEY to pepper)
# config.encryptor = :sha512
# Setup a pepper to generate the encrypted password.
# config.pepper = <%= ActiveSupport::SecureRandom.hex(64).inspect %>
# ==> Configuration for :token_authenticatable
# Defines name of the authentication token params key
# config.token_authentication_key = :auth_token
@@ -150,11 +186,12 @@ Devise.setup do |config|
# If you have any extra navigational formats, like :iphone or :mobile, you
# should add them to the navigational formats lists.
#
# The :"*/*" format below is required to match Internet Explorer requests.
# config.navigational_formats = [:"*/*", :html]
# The :"*/*" and "*/*" formats below is required to match Internet
# Explorer requests.
# config.navigational_formats = [:"*/*", "*/*", :html]
# The default HTTP method used to sign out a resource. Default is :get.
# config.sign_out_via = :get
# The default HTTP method used to sign out a resource. Default is :delete.
config.sign_out_via = :delete
# ==> OmniAuth
# Add a new OmniAuth provider. Check the wiki for more information on setting
@@ -166,7 +203,6 @@ Devise.setup do |config|
# change the failure app, you can configure them inside the config.warden block.
#
# config.warden do |manager|
# manager.failure_app = AnotherApp
# manager.intercept_401 = false
# manager.default_strategies(:scope => :user).unshift :some_external_strategy
# end

View File

@@ -0,0 +1,5 @@
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

@@ -0,0 +1,8 @@
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

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,7 +1,7 @@
require 'test_helper'
require 'ostruct'
class ControllerAuthenticableTest < ActionController::TestCase
class ControllerAuthenticatableTest < ActionController::TestCase
tests ApplicationController
def setup
@@ -13,16 +13,16 @@ class ControllerAuthenticableTest < ActionController::TestCase
assert_equal @mock_warden, @controller.warden
end
test 'proxy signed_in? to authenticated' do
test 'proxy signed_in?(scope) to authenticate?' do
@mock_warden.expects(:authenticate?).with(:scope => :my_scope)
@controller.signed_in?(:my_scope)
end
test 'proxy anybody_signed_in? to signed_in?' do
test 'proxy signed_in?(nil) to authenticate?' do
Devise.mappings.keys.each do |scope| # :user, :admin, :manager
@controller.expects(:signed_in?).with(scope)
@mock_warden.expects(:authenticate?).with(:scope => scope)
end
@controller.anybody_signed_in?
@controller.signed_in?
end
test 'proxy current_user to authenticate with user scope' do
@@ -45,6 +45,11 @@ class ControllerAuthenticableTest < ActionController::TestCase
@controller.authenticate_user!
end
test 'proxy authenticate_user! options to authenticate with user scope' do
@mock_warden.expects(:authenticate!).with(:scope => :user, :recall => "foo")
@controller.authenticate_user!(:recall => "foo")
end
test 'proxy authenticate_admin! to authenticate with admin scope' do
@mock_warden.expects(:authenticate!).with(:scope => :admin)
@controller.authenticate_admin!
@@ -90,16 +95,32 @@ class ControllerAuthenticableTest < ActionController::TestCase
test 'sign in proxy to set_user on warden' do
user = User.new
@mock_warden.expects(:user).returns(nil)
@mock_warden.expects(:set_user).with(user, :scope => :user).returns(true)
@controller.sign_in(:user, user)
end
test 'sign in accepts a resource as argument' do
user = User.new
@mock_warden.expects(:user).returns(nil)
@mock_warden.expects(:set_user).with(user, :scope => :user).returns(true)
@controller.sign_in(user)
end
test 'does not sign in again if the user is already in' do
user = User.new
@mock_warden.expects(:user).returns(user)
@mock_warden.expects(:set_user).never
assert @controller.sign_in(user)
end
test 'sign in again when the user is already in only if force is given' do
user = User.new
@mock_warden.expects(:user).returns(user)
@mock_warden.expects(:set_user).with(user, :scope => :user).returns(true)
@controller.sign_in(user, :force => true)
end
test 'sign in accepts bypass as option' do
user = User.new
@mock_warden.expects(:session_serializer).returns(serializer = mock())
@@ -107,6 +128,26 @@ class ControllerAuthenticableTest < ActionController::TestCase
@controller.sign_in(user, :bypass => true)
end
test 'sign out clears up any signed in user from all scopes' do
user = User.new
@mock_warden.expects(:user).times(Devise.mappings.size)
@mock_warden.expects(:logout).with().returns(true)
@controller.instance_variable_set(:@current_user, user)
@controller.instance_variable_set(:@current_admin, user)
@controller.sign_out
assert_equal nil, @controller.instance_variable_get(:@current_user)
assert_equal nil, @controller.instance_variable_get(:@current_admin)
end
test 'sign out clears up any signed in user by scope' do
user = User.new
@mock_warden.expects(:user).with(:user).returns(user)
@mock_warden.expects(:logout).with(:user).returns(true)
@controller.instance_variable_set(:@current_user, user)
@controller.sign_out(:user)
assert_equal nil, @controller.instance_variable_get(:@current_user)
end
test 'sign out proxy to logout on warden' do
@mock_warden.expects(:user).with(:user).returns(true)
@mock_warden.expects(:logout).with(:user).returns(true)
@@ -120,11 +161,13 @@ class ControllerAuthenticableTest < ActionController::TestCase
end
test 'sign out without args proxy to sign out all scopes' do
@mock_warden.expects(:user).times(Devise.mappings.size)
@mock_warden.expects(:logout).with().returns(true)
@controller.sign_out
end
test 'sign out everybody proxy to logout on warden' do
@mock_warden.expects(:user).times(Devise.mappings.size)
@mock_warden.expects(:logout).with().returns(true)
@controller.sign_out_all_scopes
end
@@ -197,6 +240,7 @@ class ControllerAuthenticableTest < ActionController::TestCase
test 'sign out and redirect uses the configured after sign out path when signing out all scopes' do
swap Devise, :sign_out_all_scopes => true do
@mock_warden.expects(:user).times(Devise.mappings.size)
@mock_warden.expects(:logout).with().returns(true)
@controller.expects(:redirect_to).with(admin_root_path)
@controller.instance_eval "def after_sign_out_path_for(resource); admin_root_path; end"

View File

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

View File

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

View File

@@ -25,7 +25,7 @@ class DeviseTest < ActiveSupport::TestCase
end
test 'stores warden configuration' do
assert_equal Devise::FailureApp, Devise.warden_config.failure_app
assert_kind_of Devise::Delegator, Devise.warden_config.failure_app
assert_equal :user, Devise.warden_config.default_scope
end
@@ -58,8 +58,15 @@ class DeviseTest < ActiveSupport::TestCase
assert_equal :fruits, Devise::CONTROLLERS[:kivi]
Devise::ALL.delete(:kivi)
Devise::CONTROLLERS.delete(:kivi)
assert_nothing_raised(Exception) { Devise.add_module(:authenticatable_again, :model => 'devise/model/authenticatable') }
assert defined?(Devise::Models::AuthenticatableAgain)
end
test 'should complain when comparing empty or different sized passes' do
[nil, ""].each do |empty|
assert_not Devise.secure_compare(empty, "something")
assert_not Devise.secure_compare("something", empty)
assert_not Devise.secure_compare(empty, empty)
end
assert_not Devise.secure_compare("size_1", "size_four")
end
end

View File

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

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