Compare commits

...

151 Commits

Author SHA1 Message Date
José Valim
94e5a589b6 Update README.rdoc 2011-12-19 13:35:54 +01:00
José Valim
2dbb23f973 Update README.rdoc 2011-12-19 13:34:31 +01:00
José Valim
b71028dc73 Add a note to the README. 2011-12-19 13:33:33 +01:00
José Valim
f5aab14766 Release Devise 2.0.0.rc. 2011-12-19 13:31:24 +01:00
José Valim
273c5e99c1 Add space between messages. 2011-12-19 13:30:33 +01:00
José Valim
7ba37b5dc0 Improve messages. 2011-12-19 13:21:17 +01:00
José Valim
059d3856cf Update CHANGELOG. 2011-12-19 12:58:34 +01:00
José Valim
9dbd265fdd Update messages. 2011-12-19 12:55:41 +01:00
José Valim
09ae63f822 Update CHANGELOG.rdoc 2011-12-19 12:32:32 +01:00
José Valim
5a245b3d55 Merge pull request #1508 from spagalloco/patch-1
Fixed gemnasium link in README to link to the web page and not the image
2011-12-12 13:57:06 -08:00
Steve Agalloco
7d3b16fe73 Fixed gemnasium link in README to link to the web page and not the image 2011-12-12 15:08:13 -05:00
José Valim
fd85b25d29 PathChecker should not attempt to validate invalid routes, closes #1505 2011-12-12 11:35:41 +01:00
José Valim
5eebf74f69 Fix a bug where passing :format => false to devise_for was permanent, closes #1504 2011-12-12 09:25:19 +01:00
José Valim
5a11c6597c Usage of Devise.stateless_token= is deprecated in favor of appending :token_auth to Devise.skip_session_storage 2011-12-11 20:39:41 +01:00
José Valim
930b324c15 Usage of confirm_within was deprecated in favor allow_unconfirmed_access_for 2011-12-11 20:18:02 +01:00
José Valim
d952dea32b Remove the code that was dynamically adding columns to active record 2011-12-11 20:07:50 +01:00
José Valim
9a6ac7ab69 Add confirmable to admin. 2011-12-11 20:07:50 +01:00
José Valim
df43ee640d Add Gemfile back to repository. 2011-12-11 20:07:50 +01:00
José Valim
309b57f4ea Merge pull request #1496 from laserlemon/patch-1
Add dependency status to README
2011-12-10 14:29:36 -08:00
José Valim
cc839caba5 Update CHANGELOG, rename method. 2011-12-10 23:28:23 +01:00
Steve Richert
d734648b15 Add dependency status to README 2011-12-09 15:46:52 -05:00
José Valim
006400905b Merge pull request #1493 from nashby/fix-issue-1486
redirect users to sign in page after unlock, closes #1486
2011-12-08 11:13:24 -08:00
Vasiliy Ermolovich
1e1e964d25 redirect users to sign in page after unlock, closes #1486 2011-12-08 22:06:09 +03:00
José Valim
263e0b7692 Fix failing test. 2011-12-07 13:23:55 +01:00
José Valim
01d4d0131b Merge pull request #1489 from dmitriy-kiriyenko/fix_delegator
Fix taking associated failure app from the scope in the given env.
2011-12-07 04:12:26 -08:00
Dmitriy Kiriyenko
f41e4befde Fix taking associated failure app from the scope in the given env.
There is a delegator to get failure app, introduced in 4629bee and tuned
in 24b26026. The latter commit introduced a bit of logic, however, no
tests are included into commit. Needless to say this resulted in a
broken code.

The point is that `env["warden.options"][:scope]` returns a string.
However, `Devise.mappings` is a hash with symbol keys.

Adding tests and converting scope to symbol here.
2011-12-07 14:09:00 +02:00
Rodrigo Flores
94fca31be8 Improving the unconfirmed message 2011-12-06 09:24:06 -02:00
Rodrigo Flores
19db459fca typo 2011-12-06 08:35:02 -02:00
José Valim
7693173ecd Final tidy up on removing schema helpers. 2011-12-05 12:17:02 +01:00
José Valim
a0294cbae8 Improve fields. 2011-12-05 12:02:25 +01:00
José Valim
1cf008cbe3 Remove apply schema from mongoid as well. 2011-12-05 11:48:27 +01:00
José Valim
87b84ffded Remove schema fields from Devise. 2011-12-05 11:28:04 +01:00
José Valim
035e56215d Enable reconfirmable by default and disable apply_schema. 2011-12-05 00:03:53 +01:00
José Valim
fa4d420fdb Update CHANGELOG. 2011-12-05 00:01:25 +01:00
José Valim
bd27bf7677 Deprecate and disable old behavior accumulated with time. 2011-12-04 23:58:19 +01:00
José Valim
03d9ebb56e Merge branch 'reconfirm' 2011-12-04 22:19:07 +01:00
José Valim
113b48a2ad Update CHANGELOG. 2011-12-04 22:18:58 +01:00
José Valim
6aed8f1c87 Clean up reconfirmable behavior. 2011-12-04 22:14:44 +01:00
José Valim
6d681c5b8a Merge remote-tracking branch 'heimidal/updates' into reconfirm
Conflicts:
	lib/devise/models/confirmable.rb
	test/support/helpers.rb
2011-12-04 20:58:41 +01:00
José Valim
b3034292f2 Ensure admin is running with manual lock strategy. 2011-12-01 13:19:05 +01:00
Rodrigo Flores
4243791b47 Bumping to 1.5.2 2011-11-30 07:19:12 -02:00
Rodrigo Flores
b79c69140d Adding myself to the team! w00t! 2011-11-30 07:19:12 -02:00
José Valim
ede004169c Merge pull request #1462 from lest/timeout-in-method
implement dynamic value for timeout_in as a model method instead of a proc
2011-11-25 00:27:18 -08:00
lest
37dad2172b implement dynamic value for timeout_in as a model method instead of a proc 2011-11-25 11:01:42 +03:00
José Valim
c8c471a128 Merge pull request #1461 from lest/fix-readme-mongodb-version
fix mongodb version required to run tests in readme
2011-11-24 14:48:26 -08:00
lest
f72ff72c0c fix mongodb version required to run tests in readme 2011-11-24 22:10:42 +03:00
Rodrigo Flores
dc3bfac876 Merge pull request #1460 from lest/dynamic-timeout-in
timeout_in option can be a Proc object
2011-11-24 11:10:08 -08:00
lest
426223dda0 timeout_in option can be a Proc object 2011-11-24 21:42:58 +03:00
José Valim
5909d6a0c5 Fix up previous commit and update CHANGELOG. 2011-11-24 09:24:06 +00:00
José Valim
5570929b56 Merge pull request #1458 from kirs/update-attrubutes-as
Added support for rails 3.1 new mass assignment conventions
2011-11-24 00:59:13 -08:00
Kir
5ba6670164 Added support for rails 3.1 new mass assignment conventions 2011-11-24 12:51:03 +04:00
José Valim
589442b09b Update lib/devise/omniauth/config.rb 2011-11-24 08:32:48 +00:00
José Valim
0c67cff2a0 Merge pull request #1455 from AstonJ/readme-installation-update
Adding reminder to restart server in the installation guide
2011-11-23 00:43:48 -08:00
José Valim
9c3d5705b5 Update lib/generators/templates/devise.rb 2011-11-23 08:42:45 +00:00
AstonJ
2f2662e7a5 Adding reminder to restart server in the installation guide 2011-11-23 01:31:20 +00:00
Rodrigo Flores
99040535d7 Bumping to 1.5.1 2011-11-22 13:12:21 -02:00
José Valim
582f00ed95 Devise should not attempt to load OmniAuth strategies. Strategies should be loaded before hand by the developer or explicitly given to Devise. 2011-11-20 19:42:02 +00:00
José Valim
1d2f906af1 Tidy up Gemfile. 2011-11-20 19:22:38 +00:00
José Valim
dfb8ff372d Revert "Fixed require_strategy for google_oauth2 omniauth strategy."
This reverts commit 065963f6d3.
2011-11-20 19:21:08 +00:00
José Valim
1e37e42239 Do not use stored location for sign out. 2011-11-20 19:19:41 +00:00
José Valim
ce1bd142e2 Merge pull request #1438 from hinrik/master
Allow specifying a resource_return_to for sign out
2011-11-20 11:17:44 -08:00
Rafael Mendonça França
35015e5ceb Add me as notification recipient 2011-11-14 16:37:39 -02:00
Rafael Mendonça França
03b56ffd1f Merge pull request #1441 from buggle/master
fixed require for google_oauth2 strategy
2011-11-14 10:24:32 -08:00
Christian Buggle
065963f6d3 Fixed require_strategy for google_oauth2 omniauth strategy. 2011-11-14 19:14:28 +01:00
Rodrigo Flores
a71319a080 Bumping to 1.5.0 2011-11-13 19:17:03 -02:00
Hinrik Örn Sigurðsson
9ea7249368 Allow specifying a resource_return_to for sign out
It was impossible to accomplish this by providing a
custom #after_sign_out_path_for in ApplicationController because the
session gets destroyed before it is called. Furthermore,
resource_return_to is now used by default if it exists, so users won't
have to provide a custom #after_sign_out_path_for in that case.
2011-11-13 20:27:08 +00:00
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
Brian Rose
7f754caba3 Merge branch 'master' into updates 2011-10-12 10:56:08 -06: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
Bounmy Stephane
a629654a15 ensure that the gem markerb entry is not duplicated in the gemfile 2011-09-14 20:20:20 -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
Brian Rose
8c0f74f036 Add better message when user updates while reconfirmable is enabled. 2011-08-30 22:19:18 -06:00
Brian Rose
5a820262f9 Fix double-submit reconfirmation bug
Previously, if a user submitted their new email twice, they would bypass
the reconfirmation requirement and wind up auto-confirmed.
2011-08-30 22:19:18 -06:00
Brian Rose
3906456993 Clean up copy and use the Devise API a bit better. 2011-08-30 22:19:18 -06:00
Brian Rose
a1407565c8 Selectively add reconfirmable field in tests when necessary. 2011-08-30 22:19:18 -06:00
Brian Rose
a7c5a2e65d Fix up implementation of reconfirmable. 2011-08-30 22:19:17 -06:00
mandaryn
10ac4dbc35 reconfirmable uniqueness validations 2011-08-30 22:19:17 -06:00
mandaryn
6469cbc62a renamed confirmation_on_email_change property to reconfirmable and added reconfirmable explanations 2011-08-30 22:19:17 -06:00
mandaryn
1961de6b5d Add email confirmation when it is changed by a user 2011-08-30 22:19:17 -06:00
104 changed files with 1767 additions and 810 deletions

2
.gitignore vendored
View File

@@ -8,5 +8,3 @@ rdoc/*
pkg
log
test/tmp/*
Gemfile.lock

View File

@@ -5,8 +5,9 @@ rvm:
- ree
- rbx
- rbx-2.0
- jruby
notifications:
recipients:
- jose.valim@plataformatec.com.br
- carlos@plataformatec.com.br
- rodrigo.flores@plataformatec.com.br
- rafael.franca@plataformatec.com.br

View File

@@ -1,3 +1,76 @@
== 2.0.0.rc
Notes: https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0
* enhancements
* Add support for e-mail reconfirmation on change (by github.com/Mandaryn and github.com/heimidal)
* Redirect users to sign in page after unlock (by github.com/nashby)
* deprecation
* Devise.apply_schema is deprecated
* Devise migration helpers are deprecated
* Usage of Devise.remember_across_browsers was deprecated
* Usage of Devise.confirm_within was deprecated in favor Devise.allow_unconfirmed_access_for
* Usage of rememberable with remember_token was removed
* Usage of recoverable without reset_password_sent_at was removed
* Usage of Devise.case_insensitive_keys equals to false was removed
* Usage of Devise.stateless_token= is deprecated in favor of appending :token_auth to Devise.skip_session_storage
== 1.5.3
* bug fix
* Ensure delegator converts scope to symbol (by github.com/dmitriy-kiriyenko)
* Ensure passing :format => false to devise_for is not permanent
* Ensure path checker does not check invalid routes
== 1.5.2
* enhancements
* Add support for Rails 3.1 new mass assignment conventions (by github.com/kirs)
* Add timeout_in method to Timeoutable, it can be overridden in a model (by github.com/lest)
* bug fix
* OmniAuth error message now shows the proper option (:strategy_class instead of :klass)
== 1.5.1
* bug fix
* Devise should not attempt to load OmniAuth strategies. Strategies should be loaded before hand by the developer or explicitly given to Devise.
== 1.5.0
* 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

23
Gemfile
View File

@@ -3,26 +3,25 @@ source "http://rubygems.org"
gemspec
gem "rails", "~> 3.1.0"
gem "oa-oauth", '~> 0.2.0', :require => "omniauth/oauth"
gem "oa-openid", '~> 0.2.0', :require => "omniauth/openid"
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
platforms :mri_18 do
gem "ruby-debug", ">= 0.10.3"
end
end
platforms :jruby do
gem 'activerecord-jdbc-adapter', :git => 'https://github.com/nicksieger/activerecord-jdbc-adapter.git'
gem 'activerecord-jdbcsqlite3-adapter'
gem 'jruby-openssl'
end
platforms :mri_18 do
group :test do
gem "ruby-debug", ">= 0.10.3"
end
gem "activerecord-jdbc-adapter"
gem "activerecord-jdbcsqlite3-adapter"
gem "jruby-openssl"
end
platforms :ruby do

168
Gemfile.lock Normal file
View File

@@ -0,0 +1,168 @@
PATH
remote: .
specs:
devise (1.5.2)
bcrypt-ruby (~> 3.0)
orm_adapter (~> 0.0.3)
warden (~> 1.1)
GEM
remote: http://rubygems.org/
specs:
actionmailer (3.1.3)
actionpack (= 3.1.3)
mail (~> 2.3.0)
actionpack (3.1.3)
activemodel (= 3.1.3)
activesupport (= 3.1.3)
builder (~> 3.0.0)
erubis (~> 2.7.0)
i18n (~> 0.6)
rack (~> 1.3.5)
rack-cache (~> 1.1)
rack-mount (~> 0.8.2)
rack-test (~> 0.6.1)
sprockets (~> 2.0.3)
activemodel (3.1.3)
activesupport (= 3.1.3)
builder (~> 3.0.0)
i18n (~> 0.6)
activerecord (3.1.3)
activemodel (= 3.1.3)
activesupport (= 3.1.3)
arel (~> 2.2.1)
tzinfo (~> 0.3.29)
activeresource (3.1.3)
activemodel (= 3.1.3)
activesupport (= 3.1.3)
activesupport (3.1.3)
multi_json (~> 1.0)
addressable (2.2.6)
arel (2.2.1)
bcrypt-ruby (3.0.1)
bson (1.5.1)
bson_ext (1.3.1)
builder (3.0.0)
columnize (0.3.5)
erubis (2.7.0)
faraday (0.7.5)
addressable (~> 2.2.6)
multipart-post (~> 1.1.3)
rack (>= 1.1.0, < 2)
hashie (1.2.0)
hike (1.2.1)
i18n (0.6.0)
json (1.6.3)
linecache (0.46)
rbx-require-relative (> 0.0.4)
mail (2.3.0)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
metaclass (0.0.1)
mime-types (1.17.2)
mocha (0.10.0)
metaclass (~> 0.0.1)
mongo (1.3.1)
bson (>= 1.3.1)
mongoid (2.3.4)
activemodel (~> 3.1)
mongo (~> 1.3)
tzinfo (~> 0.3.22)
multi_json (1.0.4)
multipart-post (1.1.4)
nokogiri (1.5.0)
oauth2 (0.5.1)
faraday (~> 0.7.4)
multi_json (~> 1.0.3)
omniauth (1.0.1)
hashie (~> 1.2)
rack
omniauth-facebook (1.0.0)
omniauth-oauth2 (~> 1.0.0)
omniauth-oauth2 (1.0.0)
oauth2 (~> 0.5.0)
omniauth (~> 1.0)
omniauth-openid (1.0.1)
omniauth (~> 1.0)
rack-openid (~> 1.3.1)
orm_adapter (0.0.5)
polyglot (0.3.3)
rack (1.3.5)
rack-cache (1.1)
rack (>= 0.4)
rack-mount (0.8.3)
rack (>= 1.0.0)
rack-openid (1.3.1)
rack (>= 1.1.0)
ruby-openid (>= 2.1.8)
rack-ssl (1.3.2)
rack
rack-test (0.6.1)
rack (>= 1.0)
rails (3.1.3)
actionmailer (= 3.1.3)
actionpack (= 3.1.3)
activerecord (= 3.1.3)
activeresource (= 3.1.3)
activesupport (= 3.1.3)
bundler (~> 1.0)
railties (= 3.1.3)
railties (3.1.3)
actionpack (= 3.1.3)
activesupport (= 3.1.3)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (~> 0.14.6)
rake (0.9.2.2)
rbx-require-relative (0.0.5)
rdoc (3.11)
json (~> 1.4)
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)
sprockets (2.0.3)
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.5)
sqlite3-ruby (1.3.3)
sqlite3 (>= 1.3.3)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.31)
warden (1.1.0)
rack (>= 1.0)
webrat (0.7.2)
nokogiri (>= 1.2.0)
rack (>= 1.0)
rack-test (>= 0.5.3)
PLATFORMS
ruby
DEPENDENCIES
activerecord-jdbc-adapter
activerecord-jdbcsqlite3-adapter
bson_ext (~> 1.3.0)
devise!
jruby-openssl
mocha
mongo (~> 1.3.0)
mongoid (~> 2.0)
omniauth (~> 1.0.0)
omniauth-facebook
omniauth-oauth2 (~> 1.0.0)
omniauth-openid (~> 1.0.1)
rails (~> 3.1.0)
rdoc
ruby-debug (>= 0.10.3)
sqlite3-ruby
webrat (= 0.7.2)

View File

@@ -1,5 +1,9 @@
*IMPORTANT:* Devise 2.0.0.rc is out. If you are upgrading, please read: https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0
== 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;
@@ -28,13 +32,13 @@ It's comprised of 12 modules:
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 email or a private GitHub message to the maintainers listed at the bottom of the README.
@@ -42,7 +46,7 @@ If you found a security bug, do *NOT* use the GitHub issue tracker. Send email o
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
@@ -56,21 +60,21 @@ If you need to use Devise with Rails 2.3, you can always run `gem server` from t
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.
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 2.0 or newer) running on your system.
== Installation
@@ -86,7 +90,7 @@ The generator will install an initializer which describes ALL Devise's configura
rails generate devise MODEL
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.
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. Finally, if your server was already running, then restart it as Rails doesn't automatically load methods from a new gem.
Support for Rails 2.3.x can be found by installing Devise 1.0.x from the v1.0 branch.
@@ -289,7 +293,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
@@ -313,7 +317,7 @@ 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).
=== Omniauth
@@ -329,25 +333,36 @@ 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)
* Rodrigo Flores (https://github.com/rodrigoflores)
== 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

@@ -11,8 +11,7 @@ class Devise::ConfirmationsController < ApplicationController
def create
self.resource = resource_class.send_confirmation_instructions(params[resource_name])
if successful_and_sane?(resource)
set_flash_message(:notice, :send_instructions) if is_navigational_format?
if successfully_sent?(resource)
respond_with({}, :location => after_resending_confirmation_instructions_path_for(resource_name))
else
respond_with_navigational(resource){ render_with_scope :new }
@@ -41,7 +40,7 @@ class Devise::ConfirmationsController < ApplicationController
# The path used after confirmation.
def after_confirmation_path_for(resource_name, resource)
redirect_location(resource_name, resource)
after_sign_in_path_for(resource)
end
end

View File

@@ -12,8 +12,7 @@ class Devise::PasswordsController < ApplicationController
def create
self.resource = resource_class.send_reset_password_instructions(params[resource_name])
if successful_and_sane?(resource)
set_flash_message(:notice, :send_instructions) if is_navigational_format?
if successfully_sent?(resource)
respond_with({}, :location => after_sending_reset_password_instructions_path_for(resource_name))
else
respond_with_navigational(resource){ render_with_scope :new }
@@ -35,7 +34,7 @@ class Devise::PasswordsController < ApplicationController
flash_message = resource.active_for_authentication? ? :updated : :updated_not_active
set_flash_message(:notice, flash_message) if is_navigational_format?
sign_in(resource_name, resource)
respond_with resource, :location => redirect_location(resource_name, resource)
respond_with resource, :location => after_sign_in_path_for(resource)
else
respond_with_navigational(resource){ render_with_scope :edit }
end

View File

@@ -17,7 +17,7 @@ class Devise::RegistrationsController < ApplicationController
if resource.active_for_authentication?
set_flash_message :notice, :signed_up if is_navigational_format?
sign_in(resource_name, resource)
respond_with resource, :location => redirect_location(resource_name, resource)
respond_with resource, :location => after_sign_up_path_for(resource)
else
set_flash_message :notice, :inactive_signed_up, :reason => inactive_reason(resource) if is_navigational_format?
expire_session_data_after_sign_in!
@@ -41,7 +41,12 @@ class Devise::RegistrationsController < ApplicationController
self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key)
if resource.update_with_password(params[resource_name])
set_flash_message :notice, :updated if is_navigational_format?
if is_navigational_format?
if resource.respond_to?(:pending_reconfirmation?) && resource.pending_reconfirmation?
flash_key = :update_needs_confirmation
end
set_flash_message :notice, flash_key || :updated
end
sign_in resource_name, resource, :bypass => true
respond_with resource, :location => after_update_path_for(resource)
else
@@ -83,11 +88,6 @@ 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_location(scope, resource)
stored_location_for(scope) || after_sign_up_path_for(resource)
end
# Returns the inactive reason translated.
def inactive_reason(resource)
reason = resource.inactive_message.to_s
@@ -103,13 +103,7 @@ 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 the current resource from the session.

View File

@@ -15,19 +15,20 @@ class Devise::SessionsController < ApplicationController
resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#new")
set_flash_message(:notice, :signed_in) if is_navigational_format?
sign_in(resource_name, resource)
respond_with resource, :location => redirect_location(resource_name, resource)
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)
redirect_path = after_sign_out_path_for(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
# 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.any(*navigational_formats) { redirect_to redirect_path }
format.all do
method = "to_#{request_format}"
text = {}.respond_to?(method) ? {}.send(method) : ""

View File

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

View File

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

View File

@@ -1,4 +1,4 @@
# Additional translations at http://github.com/plataformatec/devise/wiki/I18n
# Additional translations at https://github.com/plataformatec/devise/wiki/I18n
en:
errors:
@@ -37,6 +37,7 @@ en:
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.'
update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and click on the confirm link to finalize confirming your new email address."
destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.'
reasons:
inactive: 'inactive'

View File

@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
s.add_dependency("warden", "~> 1.0.3")
s.add_dependency("warden", "~> 1.1")
s.add_dependency("orm_adapter", "~> 0.0.3")
s.add_dependency("bcrypt-ruby", "~> 3.0")
end

View File

@@ -6,10 +6,12 @@ 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
@@ -82,7 +84,7 @@ module Devise
# False by default for backwards compatibility.
mattr_accessor :case_insensitive_keys
@@case_insensitive_keys = false
# Keys that should have whitespace stripped.
# False by default for backwards compatibility.
mattr_accessor :strip_whitespace_keys
@@ -118,27 +120,23 @@ module Devise
mattr_accessor :remember_for
@@remember_for = 2.weeks
# If true, a valid remember token can be re-used between multiple browsers.
mattr_accessor :remember_across_browsers
@@remember_across_browsers = true
# If true, extends the user's remember period when remembered via cookie.
mattr_accessor :extend_remember_period
@@extend_remember_period = false
# If true, uses salt as remember token and does not create it in the database.
# By default is false for backwards compatibility.
mattr_accessor :use_salt_as_remember_token
@@use_salt_as_remember_token = false
# Time interval you can access your account before confirming your account.
mattr_accessor :confirm_within
@@confirm_within = 0.days
mattr_accessor :allow_unconfirmed_access_for
@@allow_unconfirmed_access_for = 0.days
# Defines which key will be used when confirming an account
# Defines which key will be used when confirming an account.
mattr_accessor :confirmation_keys
@@confirmation_keys = [ :email ]
# Defines if email should be reconfirmable.
# False by default for backwards compatibility.
mattr_accessor :reconfirmable
@@reconfirmable = false
# Time interval to timeout the user session without activity.
mattr_accessor :timeout_in
@@timeout_in = 30.minutes
@@ -151,11 +149,6 @@ module Devise
mattr_accessor :encryptor
@@encryptor = nil
# Tells if devise should apply the schema in ORMs where devise declaration
# and schema belongs to the same class (as Datamapper and Mongoid).
mattr_accessor :apply_schema
@@apply_schema = true
# Scoped views. Since it relies on fallbacks to render default views, it's
# turned off by default.
mattr_accessor :scoped_views
@@ -188,6 +181,7 @@ module Devise
@@reset_password_keys = [ :email ]
# Time interval you can reset your password with a reset password key
# Nil by default for backwards compatibility.
mattr_accessor :reset_password_within
@@reset_password_within = nil
@@ -203,9 +197,9 @@ module Devise
mattr_accessor :token_authentication_key
@@token_authentication_key = :auth_token
# If true, authentication through token does not store user in session
mattr_accessor :stateless_token
@@stateless_token = false
# Skip session storage for the following strategies
mattr_accessor :skip_session_storage
@@skip_session_storage = []
# Which formats should be treated as navigational.
# We need both :"*/*" and "*/*" to work on different Rails versions.
@@ -220,6 +214,33 @@ module Devise
mattr_accessor :sign_out_via
@@sign_out_via = :get
# DEPRECATED CONFIG
# If true, uses salt as remember token and does not create it in the database.
# By default is false for backwards compatibility.
mattr_accessor :use_salt_as_remember_token
@@use_salt_as_remember_token = false
# Tells if devise should apply the schema in ORMs where devise declaration
# and schema belongs to the same class (as Datamapper and Mongoid).
mattr_accessor :apply_schema
@@apply_schema = true
def self.remember_across_browsers=(value)
warn "\n[DEVISE] Devise.remember_across_browsers is deprecated and has no effect. Please remove it.\n"
end
def self.confirm_within=(value)
warn "\n[DEVISE] Devise.confirm_within= is deprecated. Please set Devise.allow_unconfirmed_access_for= instead.\n"
Devise.allow_unconfirmed_access_for = value
end
def self.stateless_token=(value)
warn "\n[DEVISE] Devise.stateless_token= is deprecated. Please append :token_auth to Devise.skip_session_storage " \
"instead, for example: Devise.skip_session_storage << :token_auth\n"
Devise.skip_session_storage << :token_auth
end
# PRIVATE CONFIGURATION
# Store scopes mappings.
@@ -359,7 +380,7 @@ module Devise
# initialization.
#
# Devise.initialize do |config|
# config.confirm_within = 2.days
# config.allow_unconfirmed_access_for = 2.days
#
# config.warden do |manager|
# # Configure warden to use other strategies, like oauth.
@@ -407,7 +428,7 @@ module Devise
# 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

View File

@@ -8,6 +8,13 @@ module Devise
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.
# These filters should be used inside the controllers as before_filters,
# so you can control the scope of the user who should be signed in to
@@ -37,11 +44,6 @@ module Devise
class_eval <<-METHODS, __FILE__, __LINE__ + 1
def authenticate_#{mapping}!(opts={})
if !opts.is_a?(Hash)
opts = { :force => opts }
ActiveSupport::Deprecation.warn "Passing a boolean to authenticate_#{mapping}! " \
"is deprecated, please use :force => \#{opts[:force]} instead", caller
end
opts[:scope] = :#{mapping}
warden.authenticate!(opts) if !devise_controller? || opts.delete(:force)
end
@@ -86,7 +88,7 @@ module Devise
# 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|
[ scope || Devise.mappings.keys ].flatten.any? do |scope|
warden.authenticate?(:scope => scope)
end
end
@@ -105,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)
@@ -137,6 +139,7 @@ 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
@@ -145,6 +148,7 @@ module Devise
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
@@ -159,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
@@ -173,22 +186,20 @@ 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 a user. You can overwrite
@@ -196,7 +207,7 @@ module Devise
# scope. Notice that differently from +after_sign_in_path_for+ this method
# receives a symbol with the scope, and not the resource.
#
# By default is the root_path.
# By default it is the root_path.
def after_sign_out_path_for(resource_or_scope)
root_path
end
@@ -209,25 +220,25 @@ module Devise
scope = Devise::Mapping.find_scope!(resource_or_scope)
resource = args.last || resource_or_scope
sign_in(scope, resource, options)
redirect_to redirect_location(scope, resource)
redirect_to after_sign_in_path_for(resource)
end
def redirect_location(scope, resource) #:nodoc:
stored_location_for(scope) || after_sign_in_path_for(resource)
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
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)
redirect_path = after_sign_out_path_for(scope)
Devise.sign_out_all_scopes ? sign_out : sign_out(scope)
redirect_to after_sign_out_path_for(scope)
end
# A hook called to expire session data after sign up/in. All keys
# stored under "devise." namespace are removed after sign in.
def expire_session_data_after_sign_in!
session.keys.grep(/^devise\./).each { |k| session.delete(k) }
redirect_to redirect_path
end
# Overwrite Rails' handle unverified request to sign out all scopes,
@@ -235,9 +246,15 @@ module Devise
def handle_unverified_request
sign_out_all_scopes
warden.clear_strategies_cache!
Devise.mappings.each { |_,m| instance_variable_set("@current_#{m.name}", nil) }
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
end

View File

@@ -91,24 +91,37 @@ MESSAGE
# Example:
# before_filter :require_no_authentication, :only => :new
def require_no_authentication
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)
authenticated = if no_input.present?
args = no_input.dup.push :scope => resource_name
warden.authenticate?(*args)
else
warden.authenticated?(resource_name)
end
if authenticated
resource = warden.user(resource_name)
flash[:alert] = I18n.t("devise.failure.already_authenticated")
redirect_to after_sign_in_path_for(resource)
end
end
# Helper for use to validate if an resource is errorless. If we are on paranoid mode, we always should assume it is
# and return false.
def successful_and_sane?(resource)
if Devise.paranoid
set_flash_message :notice, :send_paranoid_instructions if is_navigational_format?
# 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
false
else
resource.errors.empty?
:send_paranoid_instructions
elsif resource.errors.empty?
:send_instructions
end
if notice
set_flash_message :notice, notice if is_navigational_format?
true
end
end

View File

@@ -24,17 +24,20 @@ module Devise
end
end
def self.generate_helpers!
mappings = Devise.mappings.values.map(&:used_helpers).flatten.uniq
routes = Devise::URL_HELPERS.slice(*mappings)
def self.generate_helpers!(routes=nil)
routes ||= begin
mappings = Devise.mappings.values.map(&:used_helpers).flatten.uniq
Devise::URL_HELPERS.slice(*mappings)
end
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 #{action}#{module_name}_#{path_or_url}(resource_or_scope, *args)
def #{method}(resource_or_scope, *args)
scope = Devise::Mapping.find_scope!(resource_or_scope)
send("#{action}\#{scope}_#{module_name}_#{path_or_url}", *args)
end
@@ -43,6 +46,8 @@ module Devise
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.to_sym].failure_app
app || Devise::FailureApp
end
end
end

View File

@@ -7,7 +7,7 @@ module Devise
# 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

@@ -15,7 +15,8 @@ module Devise
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)

View File

@@ -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

@@ -10,11 +10,6 @@ module Devise
protected
def setup_mail(*args)
ActiveSupport::Deprecation.warn "setup_mail is deprecated, please use devise_mail instead", caller
devise_mail(*args)
end
# Configure default email options
def devise_mail(record, action)
initialize_from_record(record)

View File

@@ -23,7 +23,8 @@ module Devise
#
class Mapping #:nodoc:
attr_reader :singular, :scoped_path, :path, :controllers, :path_names,
:class_name, :sign_out_via, :format, :used_routes, :used_helpers
:class_name, :sign_out_via, :format, :used_routes, :used_helpers, :failure_app
alias :name :singular
# Receives an object and find a scope for it. If a scope cannot be found,
@@ -51,46 +52,19 @@ module Devise
@singular = (options[:singular] || @scoped_path.tr('/', '_').singularize).to_sym
@class_name = (options[:class_name] || name.to_s.classify).to_s
@ref = Devise.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] || {})
@controllers.each { |k,v| @controllers[k] = v.to_s }
@path_names = Hash.new { |h,k| h[k] = k.to_s }
@path_names.merge!(:registration => "")
@path_names.merge!(options[:path_names] || {})
@constraints = Hash.new { |h,k| h[k] = k.to_s }
@constraints.merge!(options[:constraints] || {})
@defaults = Hash.new { |h,k| h[k] = k.to_s }
@defaults.merge!(options[:defaults] || {})
@sign_out_via = options[:sign_out_via] || Devise.sign_out_via
@format = options[:format]
singularizer = lambda { |s| s.to_s.singularize.to_sym }
if options.has_key?(:only)
@used_routes = self.routes & Array(options[:only]).map(&singularizer)
elsif options[:skip] == :all
@used_routes = []
else
@used_routes = self.routes - Array(options[:skip]).map(&singularizer)
end
if options[:skip_helpers] == true
@used_helpers = @used_routes
elsif skip = options[:skip_helpers]
@used_helpers = self.routes - Array(skip).map(&singularizer)
else
@used_helpers = self.routes
end
default_failure_app(options)
default_controllers(options)
default_path_names(options)
default_used_route(options)
default_used_helpers(options)
end
# Return modules for the mapping.
@@ -100,7 +74,7 @@ module Devise
# Gives the class the mapping points to.
def to
@ref.get
@klass.get
end
def strategies
@@ -122,15 +96,7 @@ module Devise
def fullpath
"/#{@path_prefix}/#{@path}".squeeze("/")
end
def constraints
@constraints
end
def defaults
@defaults
end
# Create magic predicates for verifying what module is activated by this map.
# Example:
#
@@ -145,5 +111,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

@@ -25,9 +25,14 @@ 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.
#
# * +skip_session_storage+: By default Devise will store the user in session.
# You can skip storage for http and token auth by appending values to array:
# :skip_session_storage => [:token_auth] or :skip_session_storage => [:http_auth, :token_auth],
# by default is set to :skip_session_storage => [:http_auth].
#
# == active_for_authentication?
#
# Before authenticating a user and in each request, Devise checks if your model is active by
# 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.
#
@@ -52,6 +57,9 @@ module Devise
included do
class_attribute :devise_modules, :instance_writer => false
self.devise_modules ||= []
before_validation :downcase_keys
before_validation :strip_whitespace
end
# Check if the current object is valid for authentication. This method and
@@ -61,11 +69,7 @@ module Devise
# However, you should not overwrite this method, you should overwrite active_for_authentication?
# and inactive_message instead.
def valid_for_authentication?
if active_for_authentication?
block_given? ? yield : true
else
inactive_message
end
block_given? ? yield : true
end
def active_for_authentication?
@@ -79,8 +83,25 @@ module Devise
def authenticatable_salt
end
def devise_mailer
Devise.mailer
end
def headers_for(name)
{}
end
def downcase_keys
(self.class.case_insensitive_keys || []).each { |k| self[k].try(:downcase!) }
end
def strip_whitespace
(self.class.strip_whitespace_keys || []).each { |k| self[k].try(:strip!) }
end
module ClassMethods
Devise::Models.config(self, :authentication_keys, :request_keys, :strip_whitespace_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, :skip_session_storage)
def serialize_into_session(record)
[record.to_key, record.authenticatable_salt]
@@ -112,10 +133,11 @@ module Devise
# end
#
def find_for_authentication(conditions)
conditions = filter_auth_params(conditions.dup)
(case_insensitive_keys || []).each { |k| conditions[k].try(:downcase!) }
(strip_whitespace_keys || []).each { |k| conditions[k].try(:strip!) }
to_adapter.find_first(conditions)
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.
@@ -125,14 +147,11 @@ module Devise
# Find an initialize a group of attributes based on a list of required attributes.
def find_or_initialize_with_errors(required_attributes, attributes, error=:invalid) #:nodoc:
(case_insensitive_keys || []).each { |k| attributes[k].try(:downcase!) }
(strip_whitespace_keys || []).each { |k| attributes[k].try(:strip!) }
attributes = attributes.slice(*required_attributes)
attributes.delete_if { |key, value| value.blank? }
if attributes.size == required_attributes.size
record = to_adapter.find_first(filter_auth_params(attributes))
record = find_first_by_auth_conditions(attributes)
end
unless record
@@ -150,16 +169,8 @@ module Devise
protected
# Force keys to be string to avoid injection on mongoid related database.
def filter_auth_params(conditions)
conditions.each do |k, v|
conditions[k] = v.to_s if auth_param_requires_string_conversion?(v)
end if conditions.is_a?(Hash)
end
# Determine which values should be transformed to string or passed as-is to the query builder underneath
def auth_param_requires_string_conversion?(value)
true unless value.is_a?(TrueClass) || value.is_a?(FalseClass) || value.is_a?(Fixnum)
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.

View File

@@ -9,11 +9,16 @@ module Devise
#
# Confirmable adds the following options to devise_for:
#
# * +confirm_within+: the time you want to allow the user to access his account
# * +allow_unconfirmed_access_for+: the time you want to allow the user to access his account
# before confirming it. After this period, the user access is denied. You can
# use this to let your user access some features of your application without
# confirming the account, but blocking it after a certain period (ie 7 days).
# By default confirm_within is zero, it means users always have to confirm to sign in.
# By default allow_unconfirmed_access_for is zero, it means users always have to confirm to sign in.
# * +reconfirmable+: requires any email changes to be confirmed (exactly the same way as
# initial account confirmation) to be applied. Requires additional unconfirmed_email
# db field to be setup (t.reconfirmable in migrations). Until confirmed new email is
# stored in unconfirmed email column, and copied to email column on successful
# confirmation.
#
# == Examples
#
@@ -27,15 +32,26 @@ module Devise
included do
before_create :generate_confirmation_token, :if => :confirmation_required?
after_create :send_confirmation_instructions, :if => :confirmation_required?
before_update :postpone_email_change_until_confirmation, :if => :postpone_email_change?
after_update :send_confirmation_instructions, :if => :reconfirmation_required?
end
# Confirm a user by setting its confirmed_at to actual time. If the user
# is already confirmed, add en error to email field
# Confirm a user by setting it's confirmed_at to actual time. If the user
# is already confirmed, add an error to email field. If the user is invalid
# add errors
def confirm!
unless_confirmed do
self.confirmation_token = nil
self.confirmed_at = Time.now
save(:validate => false)
self.confirmed_at = Time.now.utc
if self.class.reconfirmable
@bypass_postpone = true
self.email = unconfirmed_email if unconfirmed_email.present?
self.unconfirmed_email = nil
save
else
save(:validate => false)
end
end
end
@@ -44,10 +60,15 @@ module Devise
!!confirmed_at
end
def pending_reconfirmation?
self.class.reconfirmable && unconfirmed_email.present?
end
# Send confirmation instructions by email
def send_confirmation_instructions
generate_confirmation_token! if self.confirmation_token.nil?
::Devise.mailer.confirmation_instructions(self).deliver
@reconfirmation_required = false
generate_confirmation_token! if self.confirmation_token.blank?
self.devise_mailer.confirmation_instructions(self).deliver
end
# Resend confirmation token. This method does not need to generate a new token.
@@ -71,7 +92,15 @@ 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
def headers_for(action)
headers = super
if action == :confirmation_instructions && pending_reconfirmation?
headers[:to] = unconfirmed_email
end
headers
end
protected
@@ -88,26 +117,26 @@ module Devise
#
# Example:
#
# # confirm_within = 1.day and confirmation_sent_at = today
# # allow_unconfirmed_access_for = 1.day and confirmation_sent_at = today
# confirmation_period_valid? # returns true
#
# # confirm_within = 5.days and confirmation_sent_at = 4.days.ago
# # allow_unconfirmed_access_for = 5.days and confirmation_sent_at = 4.days.ago
# confirmation_period_valid? # returns true
#
# # confirm_within = 5.days and confirmation_sent_at = 5.days.ago
# # allow_unconfirmed_access_for = 5.days and confirmation_sent_at = 5.days.ago
# confirmation_period_valid? # returns false
#
# # confirm_within = 0.days
# # allow_unconfirmed_access_for = 0.days
# confirmation_period_valid? # will always return false
#
def confirmation_period_valid?
confirmation_sent_at && confirmation_sent_at.utc >= self.class.confirm_within.ago
confirmation_sent_at && confirmation_sent_at.utc >= self.class.allow_unconfirmed_access_for.ago
end
# Checks whether the record is confirmed or not, yielding to the block
# Checks whether the record is confirmed or not or a new email has been added, yielding to the block
# if it's already confirmed, otherwise adds an error to email.
def unless_confirmed
unless confirmed?
unless confirmed? && !pending_reconfirmation?
yield
else
self.errors.add(:email, :already_confirmed)
@@ -118,7 +147,6 @@ module Devise
# Generates a new random token for confirmation, and stores the time
# this token is being generated
def generate_confirmation_token
self.confirmed_at = nil
self.confirmation_token = self.class.confirmation_token
self.confirmation_sent_at = Time.now.utc
end
@@ -132,13 +160,32 @@ module Devise
confirm! unless confirmed?
end
def postpone_email_change_until_confirmation
@reconfirmation_required = true
self.unconfirmed_email = self.email
self.email = self.email_was
end
def postpone_email_change?
postpone = self.class.reconfirmable && email_changed? && !@bypass_postpone
@bypass_postpone = nil
postpone
end
def reconfirmation_required?
self.class.reconfirmable && @reconfirmation_required
end
module ClassMethods
# 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.
# confirmation instructions to it. If not, try searching for a user by unconfirmed_email
# field. If no 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_errors(confirmation_keys, attributes, :not_found)
confirmable = find_by_unconfirmed_email_with_errors(attributes) if reconfirmable
unless confirmable.try(:persisted?)
confirmable = find_or_initialize_with_errors(confirmation_keys, attributes, :not_found)
end
confirmable.resend_confirmation_token if confirmable.persisted?
confirmable
end
@@ -158,7 +205,15 @@ module Devise
generate_token(:confirmation_token)
end
Devise::Models.config(self, :confirm_within, :confirmation_keys)
# Find a record for confirmation by unconfirmed email field
def find_by_unconfirmed_email_with_errors(attributes = {})
unconfirmed_required_attributes = confirmation_keys.map { |k| k == :email ? :unconfirmed_email : k }
unconfirmed_attributes = attributes.symbolize_keys
unconfirmed_attributes[:unconfirmed_email] = unconfirmed_attributes.delete(:email)
find_or_initialize_with_errors(unconfirmed_required_attributes, unconfirmed_attributes, :not_found)
end
Devise::Models.config(self, :allow_unconfirmed_access_for, :confirmation_keys, :reconfirmable)
end
end
end

View File

@@ -25,8 +25,6 @@ module Devise
included do
attr_reader :password, :current_password
attr_accessor :password_confirmation
before_validation :downcase_keys
before_validation :strip_whitespace
end
# Generates password encryption based on the given value.
@@ -51,7 +49,7 @@ module Devise
# Update record attributes when :current_password matches, otherwise returns
# error on :current_password. It also automatically rejects :password and
# :password_confirmation if they are blank.
def update_with_password(params={})
def update_with_password(params, *options)
current_password = params.delete(:current_password)
if params[:password].blank?
@@ -60,7 +58,7 @@ module Devise
end
result = if valid_password?(current_password)
update_attributes(params)
update_attributes(params, *options)
else
self.attributes = params
self.valid?
@@ -73,16 +71,26 @@ module Devise
end
# Updates record attributes without asking for the current password.
# Never allows to change the current password
def update_without_password(params={})
# 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, *options)
params.delete(:password)
params.delete(:password_confirmation)
result = update_attributes(params)
result = update_attributes(params, *options)
clean_up_passwords
result
end
def after_database_authentication
end
@@ -93,15 +101,6 @@ module Devise
protected
# Downcase case-insensitive keys
def downcase_keys
(self.class.case_insensitive_keys || []).each { |k| self[k].try(:downcase!) }
end
def strip_whitespace
(self.class.strip_whitespace_keys || []).each { |k| self[k].try(:strip!) }
end
# Digests the password using bcrypt.
def password_digest(password)
::BCrypt::Password.create("#{password}#{self.class.pepper}", :cost => self.class.stretches).to_s

View File

@@ -24,7 +24,7 @@ module Devise
# 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
@@ -49,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.
@@ -79,25 +79,21 @@ module Devise
# if the user can login or not (wrong password, etc)
unlock_access! if lock_expired?
case (result = super)
when Symbol
return result
when TrueClass
if super
self.failed_attempts = 0
save(:validate => false)
when FalseClass
# PostgreSQL uses nil as the default value for integer columns set to 0
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
result
end
protected

View File

@@ -29,6 +29,7 @@ module Devise
def reset_password!(new_password, new_password_confirmation)
self.password = new_password
self.password_confirmation = new_password_confirmation
if valid?
clear_reset_password_token
after_password_reset
@@ -39,8 +40,8 @@ module Devise
# Resets reset password token and send reset password instructions by email
def send_reset_password_instructions
generate_reset_password_token! if should_generate_token?
::Devise.mailer.reset_password_instructions(self).deliver
generate_reset_password_token! if should_generate_reset_token?
self.devise_mailer.reset_password_instructions(self).deliver
end
# Checks if the reset password token sent is within the limit time.
@@ -64,20 +65,19 @@ module Devise
# 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?
def should_generate_reset_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_sent_at = Time.now.utc
self.reset_password_token
end
@@ -90,7 +90,7 @@ 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=)
self.reset_password_sent_at = nil
end
def after_password_reset
@@ -121,7 +121,7 @@ module Devise
recoverable = find_or_initialize_with_error_by(:reset_password_token, attributes[:reset_password_token])
if recoverable.persisted?
if recoverable.reset_password_period_valid?
recoverable.reset_password!(attributes[:password], attributes[:password_confirmation])
recoverable.reset_password!(attributes[:password], attributes[:password_confirmation])
else
recoverable.errors.add(:reset_password_token, :expired)
end

View File

@@ -21,11 +21,6 @@ module Devise
# used to calculate the expires time for the cookie created to remember
# the user. By default remember_for is 2.weeks.
#
# * +remember_across_browsers+: if a valid remember token can be re-used
# between multiple browsers. By default remember_across_browsers is true
# and cannot be turned off if you are using password salt instead of remember
# token.
#
# * +extend_remember_period+: if true, extends the user's remember period
# when remembered via cookie. False by default.
#
@@ -49,7 +44,6 @@ module Devise
# Generate a new remember token and save the record without validations
# unless remember_across_browsers is true and the user already has a valid token.
def remember_me!(extend_period=false)
self.remember_token = self.class.remember_token if respond_to?(:remember_token) && generate_remember_token?
self.remember_created_at = Time.now.utc if generate_remember_timestamp?(extend_period)
save(:validate => false)
end
@@ -75,14 +69,12 @@ module Devise
end
def rememberable_value
if respond_to?(:remember_token)
remember_token
elsif respond_to?(:authenticatable_salt) && (salt = authenticatable_salt)
if salt = authenticatable_salt
salt
else
raise "The #{self.class.name} class does not respond to remember_token and " <<
"authenticatable_salt returns nil. In order to use rememberable, you must " <<
"add a remember_token field to your model or ensure a password is always set."
raise "authenticable_salt returned nil for the #{self.class.name} model. " \
"In order to use rememberable, you must ensure a password is always set " \
"or implement rememberable_value in your model with your own logic."
end
end
@@ -92,12 +84,6 @@ module Devise
protected
# Generate a token unless remember_across_browsers is true and there is
# an existing remember_token or the existing remember_token has expried.
def generate_remember_token? #:nodoc:
!(self.class.remember_across_browsers && remember_token) || remember_expired?
end
# Generate a timestamp if extend_remember_period is true, if no remember_token
# exists, or if an existing remember token has expired.
def generate_remember_timestamp?(extend_period) #:nodoc:
@@ -121,8 +107,7 @@ module Devise
generate_token(:remember_token)
end
Devise::Models.config(self, :remember_for, :remember_across_browsers,
:extend_remember_period, :cookie_options)
Devise::Models.config(self, :remember_for, :extend_remember_period, :cookie_options)
end
end
end

View File

@@ -23,18 +23,20 @@ module Devise
# Checks whether the user session has expired based on configured time.
def timedout?(last_access)
return false if remember_exists_and_not_expired?
last_access && last_access <= self.class.timeout_in.ago
!timeout_in.nil? && last_access && last_access <= timeout_in.ago
end
def timeout_in
self.class.timeout_in
end
private
def remember_exists_and_not_expired?
return false unless respond_to?(:remember_expired?)
return false unless respond_to?(:remember_created_at)
remember_created_at && !remember_expired?
end
module ClassMethods
Devise::Models.config(self, :timeout_in)
end

View File

@@ -24,9 +24,6 @@ module Devise
#
# * +token_authentication_key+: Defines name of the authentication token params key. E.g. /users/sign_in?some_key=...
#
# * +stateless_token+: By default, when you sign up with a token, Devise will store the user in session
# as any other authentication strategy. You can set stateless_token to true to avoid this.
#
module TokenAuthenticatable
extend ActiveSupport::Concern
@@ -65,7 +62,7 @@ module Devise
generate_token(:authentication_token)
end
::Devise::Models.config(self, :token_authentication_key, :stateless_token)
::Devise::Models.config(self, :token_authentication_key)
end
end
end

View File

@@ -12,11 +12,11 @@ module Devise
#
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

@@ -23,7 +23,7 @@ module Devise
base.class_eval do
validates_presence_of :email, :if => :email_required?
validates_uniqueness_of :email, :case_sensitive => (case_insensitive_keys != false), :allow_blank => true, :if => :email_changed?
validates_uniqueness_of :email, :allow_blank => true, :if => :email_changed?
validates_format_of :email, :with => email_regexp, :allow_blank => true, :if => :email_changed?
validates_presence_of :password, :if => :password_required?

View File

@@ -1,12 +1,13 @@
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
unless OmniAuth.config.respond_to? :test_mode
raise "You are using an old OmniAuth version, please ensure you have 0.2.0.beta version or later installed."
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.

View File

@@ -1,24 +1,45 @@
module Devise
module OmniAuth
class StrategyNotFound < NameError
def initialize(strategy)
@strategy = strategy
super("Could not find a strategy with name `#{strategy}'. " \
"Please ensure it is required or explicitly set it using the :strategy_class option.")
end
end
class Config
attr_accessor :strategy
attr_reader :args
attr_reader :args, :options, :provider, :strategy_name
def initialize(provider, args)
@provider = provider
@args = args
@strategy = nil
end
# open_id strategy can have configurable name
def strategy_name
options = @args.last.is_a?(Hash) && @args.last
options && options[:name] ? options[:name] : @provider
@provider = provider
@args = args
@options = @args.last.is_a?(Hash) ? @args.last : {}
@strategy = nil
@strategy_name = options[:name] || @provider
@strategy_class = options.delete(:strategy_class)
end
def strategy_class
::OmniAuth::Strategies.const_get("#{::OmniAuth::Utils.camelize(@provider.to_s)}")
@strategy_class ||= find_strategy || autoload_strategy
end
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 autoload_strategy
name = ::OmniAuth::Utils.camelize(provider.to_s)
if ::OmniAuth::Strategies.const_defined?(name)
::OmniAuth::Strategies.const_get(name)
else
raise StrategyNotFound, name
end
end
end
end
end
end

View File

@@ -26,6 +26,12 @@ module Devise
# Tell how to apply schema methods.
def apply_devise_schema(name, type, options={})
@__devise_warning_raised ||= begin
$stderr.puts "\n[DEVISE] You are using t.database_authenticatable and others in your migration " \
"and this feature is deprecated. Please simply use Rails helpers instead as mentioned here:\n" \
"https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0-migration-schema-style\n\n"
true
end
column name, type.to_s.downcase.to_sym, options
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

@@ -12,7 +12,8 @@ module Devise
end
def signing_out?
@current_path == send("destroy_#{@scope}_session_path")
route = "destroy_#{@scope}_session_path"
respond_to?(route) && @current_path == send(route)
end
end
end

View File

@@ -17,17 +17,6 @@ module Devise
Devise.include_helpers(Devise::Controllers)
end
initializer "devise.auth_keys" do
if Devise.authentication_keys.size > 1
puts "[DEVISE] You are configuring Devise to use more than one authentication key. " \
"In previous versions, we automatically added #{Devise.authentication_keys[1..-1].inspect} " \
"as scope to your e-mail validation, but this was changed now. If you were relying in such " \
"behavior, you should remove :validatable from your models and add the validations manually. " \
"To get rid of this warning, you can comment config.authentication_keys in your initializer " \
"and pass the current values as key to the devise call in your model."
end
end
initializer "devise.omniauth" do |app|
Devise.omniauth_configs.each do |provider, config|
app.middleware.use config.strategy_class, *config.args do |strategy|
@@ -52,5 +41,36 @@ module Devise
end
end
end
initializer "devise.deprecations" do
unless defined?(Rails::Generators)
if Devise.case_insensitive_keys == false
warn "\n[DEVISE] Devise.case_insensitive_keys is false which is no longer " \
"supported. If you want to continue running on this mode, please ensure " \
"you are not using validatable (you can copy the validations directly to your model) " \
"and set case_insensitive_keys to an empty array.\n"
end
if Devise.apply_schema && defined?(Mongoid)
warn "\n[DEVISE] Devise.apply_schema is true. This means Devise was " \
"automatically configuring your DB. This no longer happens. You should " \
"set Devise.apply_schema to false and manually set the fields used by Devise as shown here: " \
"https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0-migration-schema-style\n"
end
# TODO: Deprecate the true value of this option as well
if Devise.use_salt_as_remember_token == false
warn "\n[DEVISE] Devise.use_salt_as_remember_token is false which is no longer " \
"supported. Devise now only uses the salt as remember token and the remember_token " \
"column can be removed from your models.\n"
end
if Devise.reset_password_within.nil?
warn "\n[DEVISE] Devise.reset_password_within is nil. Please set this value to " \
"an interval (for example, 6.hours) and add a reset_password_sent_at field to " \
"your Devise models (if they don't have one already).\n"
end
end
end
end
end

View File

@@ -49,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' }
#
@@ -74,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:
#
@@ -182,7 +185,7 @@ module ActionDispatch::Routing
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
options[:options] = (@scope[:options] || {}).merge({:format => false}) if options[:format] == false
resources.map!(&:to_sym)
@@ -205,7 +208,7 @@ module ActionDispatch::Routing
devise_scope mapping.name do
yield if block_given?
with_devise_exclusive_scope mapping.fullpath, mapping.name, mapping.constraints, mapping.defaults do
with_devise_exclusive_scope mapping.fullpath, mapping.name, options do
routes.each { |mod| send("devise_#{mod}", mapping, mapping.controllers) }
end
end
@@ -354,7 +357,7 @@ module ActionDispatch::Routing
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
@@ -365,12 +368,15 @@ module ActionDispatch::Routing
@scope[:path] = path
end
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
def with_devise_exclusive_scope(new_path, new_as, options) #:nodoc:
old_as, old_path, old_module, old_constraints, old_defaults, old_options =
*@scope.values_at(:as, :path, :module, :constraints, :defaults, :options)
@scope[:as], @scope[:path], @scope[:module], @scope[:constraints], @scope[:defaults], @scope[:options] =
new_as, new_path, nil, *options.values_at(:constraints, :defaults, :options)
yield
ensure
@scope[:as], @scope[:path], @scope[:module], @scope[:constraints], @scope[:defaults] = old_as, old_path, old_module, old_constraints, old_defaults
@scope[:as], @scope[:path], @scope[:module], @scope[:constraints], @scope[:defaults], @scope[:options] =
old_as, old_path, old_module, old_constraints, old_defaults, old_options
end
def raise_no_devise_method_error!(klass) #:nodoc:

View File

@@ -40,6 +40,11 @@ module Devise
apply_devise_schema :confirmation_sent_at, DateTime
end
# Creates unconfirmed_email
def reconfirmable
apply_devise_schema :unconfirmed_email, String
end
# Creates reset_password_token and reset_password_sent_at.
#
# == Options

View File

@@ -6,7 +6,11 @@ module Devise
# parameters both from params or from http authorization headers. See database_authenticatable
# for an example.
class Authenticatable < Base
attr_accessor :authentication_hash, :password
attr_accessor :authentication_hash, :authentication_type, :password
def store?
!mapping.to.skip_session_storage.include?(authentication_type)
end
def valid?
valid_for_params_auth? || valid_for_http_auth?
@@ -47,7 +51,7 @@ module Devise
# * If all authentication keys are present;
#
def valid_for_http_auth?
http_authenticatable? && request.authorization && with_authentication_hash(http_auth_hash)
http_authenticatable? && request.authorization && with_authentication_hash(:http_auth, http_auth_hash)
end
# Check if this is strategy is valid for params authentication by:
@@ -58,8 +62,8 @@ module Devise
# * If all authentication keys are present;
#
def valid_for_params_auth?
params_authenticatable? && valid_request? &&
valid_params? && with_authentication_hash(params_auth_hash)
params_authenticatable? && valid_params_request? &&
valid_params? && with_authentication_hash(:params_auth, params_auth_hash)
end
# Check if the model accepts this strategy as http authenticatable.
@@ -83,19 +87,9 @@ module Devise
Hash[*keys.zip(decode_credentials).flatten]
end
# By default, a request is valid if the controller is allowed and the VERB is POST.
def valid_request?
if env["devise.allow_params_authentication"]
true
elsif request.post? && mapping.controllers[:sessions] == params[:controller]
ActiveSupport::Deprecation.warn "It seems that you are using a custom SessionsController. " \
"In order for it to work from Devise 1.4.6 forward, you need to add the following:" \
"\n\n prepend_before_filter :allow_params_authentication!, :only => :create\n\n" \
"This will ensure your controller can authenticate from params for the create action.", caller
true
else
false
end
# By default, a request is valid if the controller set the proper env variable.
def valid_params_request?
!!env["devise.allow_params_authentication"]
end
# If the request is valid, finally check if params_auth_hash returns a hash.
@@ -115,8 +109,8 @@ module Devise
end
# Sets the authentication hash and the password from params_auth_hash or http_auth_hash.
def with_authentication_hash(auth_values)
self.authentication_hash = {}
def with_authentication_hash(auth_type, auth_values)
self.authentication_hash, self.authentication_type = {}, auth_type
self.password = auth_values[:password]
parse_authentication_key_values(auth_values, authentication_keys) &&

View File

@@ -11,7 +11,7 @@ module Devise
# a password, you can pass "X" as password and it will simply be ignored.
class TokenAuthenticatable < Authenticatable
def store?
!mapping.to.stateless_token
super && !mapping.to.skip_session_storage.include?(:token_auth)
end
def authenticate!
@@ -27,8 +27,8 @@ module Devise
private
# TokenAuthenticatable request is valid for any controller and any verb.
def valid_request?
# Token Authenticatable can be authenticated with params in any controller and any verb.
def valid_params_request?
true
end

View File

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

View File

@@ -1,7 +1,6 @@
require 'rails/generators/active_record'
require 'generators/devise/orm_helpers'
module ActiveRecord
module Generators
class DeviseGenerator < ActiveRecord::Generators::Base
@@ -21,13 +20,52 @@ module ActiveRecord
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) if model_exists?
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
CONTENT
end
def migration_data
<<RUBY
## Database authenticatable
t.string :email, :null => false, :default => ""
t.string :encrypted_password, :null => false, :default => ""
## Recoverable
t.string :reset_password_token
t.datetime :reset_password_sent_at
## Rememberable
t.datetime :remember_created_at
## Trackable
t.integer :sign_in_count, :default => 0
t.datetime :current_sign_in_at
t.datetime :last_sign_in_at
t.string :current_sign_in_ip
t.string :last_sign_in_ip
## Encryptable
# t.string :password_salt
## Confirmable
# t.string :confirmation_token
# t.datetime :confirmed_at
# t.datetime :confirmation_sent_at
# t.string :unconfirmed_email # Only if using reconfirmable
## Lockable
# t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts
# t.string :unlock_token # Only if unlock strategy is :email or :both
# t.datetime :locked_at
# Token authenticatable
# t.string :authentication_token
RUBY
end
end
end
end

View File

@@ -1,17 +1,13 @@
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
t.rememberable
t.trackable
<%= migration_data -%>
# t.encryptable
# t.confirmable
# 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 -%>
@@ -25,7 +21,9 @@ class DeviseCreate<%= table_name.camelize %> < ActiveRecord::Migration
# 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

@@ -1,17 +1,9 @@
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
<%= migration_data -%>
<% for attribute in attributes -%>
<% attributes.each do |attribute| -%>
t.<%= attribute.type %> :<%= attribute.name %>
<% end -%>
@@ -29,6 +21,6 @@ class AddDeviseTo<%= table_name.camelize %> < ActiveRecord::Migration
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
raise ActiveRecord::IrreversibleMigration
end
end

View File

@@ -23,8 +23,8 @@ module Devise
protected
def view_directory(name)
directory name.to_s, "#{target_path}/#{name}"
def view_directory(name, _target_path = nil)
directory name.to_s, _target_path || "#{target_path}/#{name}"
end
def target_path
@@ -39,7 +39,6 @@ module Devise
# Override copy_views to just copy mailer and shared.
def copy_views
view_directory :mailer
view_directory :shared
end
end
@@ -56,6 +55,30 @@ module Devise
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
desc "Copies Devise views to your application."
@@ -63,10 +86,13 @@ module Devise
:desc => "The scope to copy views to"
invoke SharedViewsGenerator
hook_for :form_builder, :aliases => "-b",
:desc => "Form builder to be used",
:default => defined?(SimpleForm) ? "simple_form_for" : "form_for"
hook_for :markerb, :desc => "Generate markerb instead of erb mail views",
:default => defined?(Markerb) ? :markerb : :erb,
:type => :boolean
end
end
end

View File

@@ -9,9 +9,52 @@ module Mongoid
invoke "mongoid:model", [name] unless model_exists? && behavior == :invoke
end
def inject_field_types
inject_into_file model_path, migration_data, :after => "include Mongoid::Document\n" if model_exists?
end
def inject_devise_content
inject_into_file model_path, model_contents, :after => "include Mongoid::Document\n" if model_exists?
end
def migration_data
<<RUBY
## Database authenticatable
field :email, :type => String, :null => false, :default => ""
field :encrypted_password, :type => String, :null => false, :default => ""
## Recoverable
field :reset_password_token, :type => String
field :reset_password_sent_at, :type => Time
## Rememberable
field :remember_created_at, :type => Time
## Trackable
field :sign_in_count, :type => Integer, :default => 0
field :current_sign_in_at, :type => Time
field :last_sign_in_at, :type => Time
field :current_sign_in_ip, :type => String
field :last_sign_in_ip, :type => String
## Encryptable
# field :password_salt, :type => String
## Confirmable
# field :confirmation_token, :type => String
# field :confirmed_at, :type => Time
# field :confirmation_sent_at, :type => Time
# field :unconfirmed_email, :type => String # Only if using reconfirmable
## Lockable
# field :failed_attempts, :type => Integer, :default => 0 # Only if lock strategy is :failed_attempts
# field :unlock_token, :type => String # Only if unlock strategy is :email or :both
# field :locked_at, :type => Time
## Token authenticatable
# field :authentication_token, :type => String
RUBY
end
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

@@ -1,5 +1,5 @@
# Use this hook to configure devise mailer, warden hooks and so forth. The first
# four configuration values can also be set straight in your models.
# Use this hook to configure devise mailer, warden hooks and so forth.
# Many of these configuration options can be set straight in your model.
Devise.setup do |config|
# ==> Mailer Configuration
# Configure the e-mail address which will be shown in Devise::Mailer,
@@ -9,6 +9,9 @@ Devise.setup do |config|
# Configure the class responsible to send e-mails.
# config.mailer = "Devise::Mailer"
# Automatically apply schema changes in tableless databases
config.apply_schema = false
# ==> ORM configuration
# Load and configure the ORM. Supports :active_record (default) and
# :mongoid (bson_ext recommended) by default. Other ORMs may be
@@ -59,6 +62,10 @@ Devise.setup do |config|
# Does not affect registerable.
# config.paranoid = true
# By default Devise will store the user in session. You can skip storage for
# :http_auth and :token_auth by adding those symbols to the array below.
config.skip_session_storage = [:http_auth]
# ==> 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.
@@ -77,7 +84,13 @@ Devise.setup do |config|
# 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
# config.allow_unconfirmed_access_for = 2.days
# If true, requires any email changes to be confirmed (exctly the same way as
# initial account confirmation) to be applied. Requires additional unconfirmed_email
# db field (see migrations). Until confirmed new email is stored in
# unconfirmed email column, and copied to email column on successful confirmation.
config.reconfirmable = true
# Defines which key will be used when confirming an account
# config.confirmation_keys = [ :email ]
@@ -86,9 +99,6 @@ Devise.setup do |config|
# The time the user will be remembered without asking for credentials again.
# config.remember_for = 2.weeks
# If true, a valid remember token can be re-used between multiple browsers.
# config.remember_across_browsers = true
# If true, extends the user's remember period when remembered via cookie.
# config.extend_remember_period = false
@@ -145,7 +155,7 @@ Devise.setup do |config|
# 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
config.reset_password_within = 6.hours
# ==> Configuration for :encryptable
# Allow you to use another encryption algorithm besides bcrypt (default). You can use
@@ -159,10 +169,6 @@ Devise.setup do |config|
# Defines name of the authentication token params key
# config.token_authentication_key = :auth_token
# If true, authentication through token does not store user in session and needs
# to be supplied on each request. Useful if you are using the token as API token.
# config.stateless_token = false
# ==> Scopes configuration
# Turn scoped views on. Before rendering "sessions/new", it will first check for
# "users/sessions/new". It's turned off by default because it's slower if you
@@ -203,7 +209,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

@@ -128,6 +128,26 @@ class ControllerAuthenticatableTest < 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)
@@ -208,17 +228,6 @@ class ControllerAuthenticatableTest < ActionController::TestCase
@controller.sign_in_and_redirect(admin)
end
test 'redirect_location returns the stored location if set' do
user = User.new
@controller.session[:"user_return_to"] = "/foo.bar"
assert_equal '/foo.bar', @controller.redirect_location('user', user)
end
test 'redirect_location returns the after sign in path by default' do
user = User.new
assert_equal @controller.after_sign_in_path_for(:user), @controller.redirect_location('user', user)
end
test 'sign out and redirect uses the configured after sign out path when signing out only the current scope' do
swap Devise, :sign_out_all_scopes => false do
@mock_warden.expects(:user).with(:admin).returns(true)

View File

@@ -45,10 +45,12 @@ class HelpersTest < ActionController::TestCase
@controller.send :require_no_authentication
end
test 'require no authentication skips if no inputs are available' do
test 'require no authentication only checks if already authenticated if no inputs strategies are available' do
Devise.mappings[:user].expects(:no_input_strategies).returns([])
@mock_warden.expects(:authenticate?).never
@controller.expects(:redirect_to).never
@mock_warden.expects(:authenticated?).with(:user).once.returns(true)
@mock_warden.expects(:user).with(:user).returns(User.new)
@controller.expects(:redirect_to).with(root_path)
@controller.send :require_no_authentication
end

19
test/delegator_test.rb Normal file
View File

@@ -0,0 +1,19 @@
require 'test_helper'
class DelegatorTest < ActiveSupport::TestCase
def delegator
Devise::Delegator.new
end
test 'failure_app returns default failure app if no warden options in env' do
assert_equal Devise::FailureApp, delegator.failure_app({})
end
test 'failure_app returns default failure app if no scope in warden options' do
assert_equal Devise::FailureApp, delegator.failure_app({"warden.options" => {}})
end
test 'failure_app returns associated failure app by scope in the given environment' do
assert_kind_of Proc, delegator.failure_app({"warden.options" => {:scope => "manager"}})
end
end

View File

@@ -12,8 +12,8 @@ end
class DeviseTest < ActiveSupport::TestCase
test 'model options can be configured through Devise' do
swap Devise, :confirm_within => 113, :pepper => "foo" do
assert_equal 113, Devise.confirm_within
swap Devise, :allow_unconfirmed_access_for => 113, :pepper => "foo" do
assert_equal 113, Devise.allow_unconfirmed_access_for
assert_equal "foo", Devise.pepper
end
end
@@ -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

View File

@@ -7,20 +7,30 @@ if DEVISE_ORM == :active_record
tests ActiveRecord::Generators::DeviseGenerator
destination File.expand_path("../../tmp", __FILE__)
setup :prepare_destination
test "all files are properly created" do
run_generator %w(monster)
assert_file "app/models/monster.rb", /devise/, /attr_accessible (:[a-z_]+(, )?)+/
assert_migration "db/migrate/devise_create_monsters.rb"
with_rails_version :MAJOR => 3, :MINOR => 0 do
run_generator %w(monster)
assert_file "app/models/monster.rb", /devise/, /attr_accessible (:[a-z_]+(, )?)+/
assert_migration "db/migrate/devise_create_monsters.rb", /def self\.up/
end
end
test "all files are properly created with rails31 migration syntax" do
with_rails_version :MAJOR => 3, :MINOR => 1 do
run_generator %w(monster)
assert_file "app/models/monster.rb", /devise/, /attr_accessible (:[a-z_]+(, )?)+/
assert_migration "db/migrate/devise_create_monsters.rb", /def change/
end
end
test "update model migration when model exists" do
run_generator %w(monster)
assert_file "app/models/monster.rb"
run_generator %w(monster)
assert_migration "db/migrate/add_devise_to_monsters.rb"
end
test "all files are properly deleted" do
run_generator %w(monster)
run_generator %w(monster)

View File

@@ -28,12 +28,19 @@ class ViewsGeneratorTest < Rails::Generators::TestCase
assert_file "app/views/users/confirmations/new.html.erb", /simple_form_for/
end
def assert_files(scope = nil, template_engine = nil)
test "Assert views with markerb" do
run_generator %w(--markerb)
assert_files nil, :mail_template_engine => "markerb"
end
def assert_files(scope = nil, options={})
scope = "devise" if scope.nil?
mail_template_engine = options[:mail_template_engine] || "html.erb"
assert_file "app/views/#{scope}/confirmations/new.html.erb"
assert_file "app/views/#{scope}/mailer/confirmation_instructions.html.erb"
assert_file "app/views/#{scope}/mailer/reset_password_instructions.html.erb"
assert_file "app/views/#{scope}/mailer/unlock_instructions.html.erb"
assert_file "app/views/#{scope}/mailer/confirmation_instructions.#{mail_template_engine}"
assert_file "app/views/#{scope}/mailer/reset_password_instructions.#{mail_template_engine}"
assert_file "app/views/#{scope}/mailer/unlock_instructions.#{mail_template_engine}"
assert_file "app/views/#{scope}/passwords/edit.html.erb"
assert_file "app/views/#{scope}/passwords/new.html.erb"
assert_file "app/views/#{scope}/registrations/new.html.erb"

View File

@@ -131,7 +131,7 @@ class AuthenticationSanityTest < ActionController::IntegrationTest
end
end
test 'signed in user should not see join page' do
test 'signed in user should not see unauthenticated page' do
sign_in_as_user
assert warden.authenticated?(:user)
assert_not warden.authenticated?(:admin)
@@ -141,7 +141,7 @@ class AuthenticationSanityTest < ActionController::IntegrationTest
end
end
test 'not signed in should see join page' do
test 'not signed in users should see unautheticated page' do
get join_path
assert_response :success
@@ -200,6 +200,12 @@ class AuthenticationSanityTest < ActionController::IntegrationTest
get root_path
assert_not_contain 'Signed out successfully'
end
test 'scope uses custom failure app' do
put "/en/accounts/management"
assert_equal "Oops, not found", response.body
assert_equal 404, response.status
end
end
class AuthenticationRedirectTest < ActionController::IntegrationTest
@@ -312,7 +318,7 @@ class AuthenticationSessionTest < ActionController::IntegrationTest
end
end
class AuthenticationWithScopesTest < ActionController::IntegrationTest
class AuthenticationWithScopedViewsTest < ActionController::IntegrationTest
test 'renders the scoped view if turned on and view is available' do
swap Devise, :scoped_views => true do
assert_raise Webrat::NotFoundError do
@@ -439,6 +445,22 @@ class AuthenticationOthersTest < ActionController::IntegrationTest
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
end
test 'sign in with xml format is idempotent' do
get new_user_session_path(:format => 'xml')
assert_response :success
create_user
post user_session_path(:format => 'xml'), :user => {:email => "user@test.com", :password => '123456'}
assert_response :success
get new_user_session_path(:format => 'xml')
assert_response :success
post user_session_path(:format => 'xml'), :user => {:email => "user@test.com", :password => '123456'}
assert_response :success
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
end
test 'sign out with xml format returns ok response' do
sign_in_as_user
get destroy_user_session_path(:format => 'xml')

View File

@@ -6,7 +6,7 @@ class ConfirmationTest < ActionController::IntegrationTest
visit user_confirmation_path(:confirmation_token => confirmation_token)
end
test 'user should be able to request a new confirmation' do
def resend_confirmation
user = create_user(:confirm => false)
ActionMailer::Base.deliveries.clear
@@ -15,10 +15,23 @@ class ConfirmationTest < ActionController::IntegrationTest
fill_in 'email', :with => user.email
click_button 'Resend confirmation instructions'
end
test 'user should be able to request a new confirmation' do
resend_confirmation
assert_current_url '/users/sign_in'
assert_contain 'You will receive an email with instructions about how to confirm your account in a few minutes'
assert_equal 1, ActionMailer::Base.deliveries.size
assert_equal ['please-change-me@config-initializers-devise.com'], ActionMailer::Base.deliveries.first.from
end
test 'user should receive a confirmation from a custom mailer' do
User.any_instance.stubs(:devise_mailer).returns(Users::Mailer)
resend_confirmation
assert_equal ['custom@example.com'], ActionMailer::Base.deliveries.first.from
end
test 'user with invalid confirmation token should not be able to confirm an account' do
@@ -85,7 +98,7 @@ class ConfirmationTest < ActionController::IntegrationTest
end
test 'not confirmed user with setup to block without confirmation should not be able to sign in' do
swap Devise, :confirm_within => 0.days do
swap Devise, :allow_unconfirmed_access_for => 0.days do
sign_in_as_user(:confirm => false)
assert_contain 'You have to confirm your account before continuing'
@@ -93,8 +106,19 @@ class ConfirmationTest < ActionController::IntegrationTest
end
end
test 'not confirmed user should not see confirmation message if invalid credentials are given' do
swap Devise, :allow_unconfirmed_access_for => 0.days do
sign_in_as_user(:confirm => false) do
fill_in 'password', :with => 'invalid'
end
assert_contain 'Invalid email or password'
assert_not warden.authenticated?(:user)
end
end
test 'not confirmed user but configured with some days to confirm should be able to sign in' do
swap Devise, :confirm_within => 1.day do
swap Devise, :allow_unconfirmed_access_for => 1.day do
sign_in_as_user(:confirm => false)
assert_response :success
@@ -157,7 +181,7 @@ class ConfirmationTest < ActionController::IntegrationTest
click_button 'Resend confirmation instructions'
assert_contain "If your e-mail exists on our database, you will receive an email with instructions about how to confirm your account in a few minutes."
assert_current_url "/users/confirmation"
assert_current_url "/users/sign_in"
end
end
@@ -173,7 +197,59 @@ class ConfirmationTest < ActionController::IntegrationTest
assert_not_contain "Email not found"
assert_contain "If your e-mail exists on our database, you will receive an email with instructions about how to confirm your account in a few minutes."
assert_current_url "/users/confirmation"
assert_current_url "/users/sign_in"
end
end
end
class ConfirmationOnChangeTest < ActionController::IntegrationTest
def create_second_admin(options={})
@admin = nil
create_admin(options)
end
def visit_admin_confirmation_with_token(confirmation_token)
visit admin_confirmation_path(:confirmation_token => confirmation_token)
end
test 'admin should be able to request a new confirmation after email changed' do
admin = create_admin
admin.update_attributes(:email => 'new_test@example.com')
visit new_admin_session_path
click_link "Didn't receive confirmation instructions?"
fill_in 'email', :with => admin.unconfirmed_email
assert_difference "ActionMailer::Base.deliveries.size" do
click_button 'Resend confirmation instructions'
end
assert_current_url '/admin_area/sign_in'
assert_contain 'You will receive an email with instructions about how to confirm your account in a few minutes'
end
test 'admin with valid confirmation token should be able to confirm email after email changed' do
admin = create_admin
admin.update_attributes(:email => 'new_test@example.com')
assert_equal 'new_test@example.com', admin.unconfirmed_email
visit_admin_confirmation_with_token(admin.confirmation_token)
assert_contain 'Your account was successfully confirmed.'
assert_current_url '/admin_area/home'
assert admin.reload.confirmed?
assert_not admin.reload.pending_reconfirmation?
end
test 'admin email should be unique also within unconfirmed_email' do
admin = create_admin
admin.update_attributes(:email => 'new_admin_test@example.com')
assert_equal 'new_admin_test@example.com', admin.unconfirmed_email
create_second_admin(:email => "new_admin_test@example.com")
visit_admin_confirmation_with_token(admin.confirmation_token)
assert_have_selector '#error_explanation'
assert_contain /Email.*already.*taken/
assert admin.reload.pending_reconfirmation?
end
end

View File

@@ -12,9 +12,24 @@ class HttpAuthenticationTest < ActionController::IntegrationTest
test 'sign in should authenticate with http' do
sign_in_as_new_user_with_http
assert_response :success
assert_response 200
assert_match '<email>user@test.com</email>', response.body
assert warden.authenticated?(:user)
get users_path(:format => :xml)
assert_response 200
end
test 'sign in should authenticate with http but not emit a cookie if skipping session storage' do
swap Devise, :skip_session_storage => [:http_auth] do
sign_in_as_new_user_with_http
assert_response 200
assert_match '<email>user@test.com</email>', response.body
assert warden.authenticated?(:user)
get users_path(:format => :xml)
assert_response 401
end
end
test 'returns a custom response with www-authenticate header on failures' do

View File

@@ -6,7 +6,7 @@ class LockTest < ActionController::IntegrationTest
visit user_unlock_path(:unlock_token => unlock_token)
end
test 'user should be able to request a new unlock token' do
def send_unlock_request
user = create_user(:locked => true)
ActionMailer::Base.deliveries.clear
@@ -15,10 +15,23 @@ class LockTest < ActionController::IntegrationTest
fill_in 'email', :with => user.email
click_button 'Resend unlock instructions'
end
test 'user should be able to request a new unlock token' do
send_unlock_request
assert_template 'sessions/new'
assert_contain 'You will receive an email with instructions about how to unlock your account in a few minutes'
assert_equal 1, ActionMailer::Base.deliveries.size
assert_equal ['please-change-me@config-initializers-devise.com'], ActionMailer::Base.deliveries.first.from
end
test 'user should receive the instructions from a custom mailer' do
User.any_instance.stubs(:devise_mailer).returns(Users::Mailer)
send_unlock_request
assert_equal ['custom@example.com'], ActionMailer::Base.deliveries.first.from
end
test 'unlocked user should not be able to request a unlock token' do
@@ -67,16 +80,16 @@ class LockTest < ActionController::IntegrationTest
visit_user_unlock_with_token(user.unlock_token)
assert_current_url '/'
assert_current_url "/users/sign_in"
assert_contain 'Your account was successfully unlocked.'
assert_not user.reload.access_locked?
end
test "sign in user automatically after unlocking its account" do
test "redirect user to sign in page after unlocking its account" do
user = create_user(:locked => true)
visit_user_unlock_with_token(user.unlock_token)
assert warden.authenticated?(:user)
assert_not warden.authenticated?(:user)
end
test "user should not be able to sign in when locked" do
@@ -159,8 +172,7 @@ class LockTest < ActionController::IntegrationTest
fill_in 'email', :with => user.email
click_button 'Resend unlock instructions'
assert_current_url "/users/unlock"
assert_current_url "/users/sign_in"
assert_contain "If your account exists, you will receive an email with instructions about how to unlock it in a few minutes."
end
end
@@ -175,8 +187,7 @@ class LockTest < ActionController::IntegrationTest
fill_in 'email', :with => user.email
click_button 'Resend unlock instructions'
assert_current_url "/users/unlock"
assert_current_url "/users/sign_in"
assert_contain "If your account exists, you will receive an email with instructions about how to unlock it in a few minutes."
end
end
@@ -191,7 +202,7 @@ class LockTest < ActionController::IntegrationTest
assert_not_contain "1 error prohibited this user from being saved:"
assert_not_contain "Email not found"
assert_current_url "/users/unlock"
assert_current_url "/users/sign_in"
assert_contain "If your account exists, you will receive an email with instructions about how to unlock it in a few minutes."

View File

@@ -1,5 +1,6 @@
require 'test_helper'
class OmniauthableIntegrationTest < ActionController::IntegrationTest
FACEBOOK_INFO = {
"id" => '12345',
@@ -12,14 +13,6 @@ class OmniauthableIntegrationTest < ActionController::IntegrationTest
setup do
OmniAuth.config.test_mode = true
stub_facebook!
end
teardown do
OmniAuth.config.test_mode = false
end
def stub_facebook!
OmniAuth.config.mock_auth[:facebook] = {
"uid" => '12345',
"provider" => 'facebook',
@@ -29,6 +22,10 @@ class OmniauthableIntegrationTest < ActionController::IntegrationTest
}
end
teardown do
OmniAuth.config.test_mode = false
end
def stub_action!(name)
Users::OmniauthCallbacksController.class_eval do
alias_method :__old_facebook, :facebook
@@ -128,7 +125,7 @@ class OmniauthableIntegrationTest < ActionController::IntegrationTest
OmniAuth.config.mock_auth[:facebook] = :invalid_credentials
visit "/users/sign_in"
click_link "Sign in with facebook"
click_link "Sign in with Facebook"
assert_current_url "/users/sign_in"
assert_contain 'Could not authorize you from Facebook because "Invalid credentials".'

View File

@@ -38,6 +38,16 @@ class PasswordTest < ActionController::IntegrationTest
assert_contain 'You will receive an email with instructions about how to reset your password in a few minutes.'
end
test 'reset password with email should send an email from a custom mailer' do
create_user(:email => 'Foo@Bar.com')
User.any_instance.stubs(:devise_mailer).returns(Users::Mailer)
request_forgot_password do
fill_in 'email', :with => 'foo@bar.com'
end
assert_equal ['custom@example.com'], ActionMailer::Base.deliveries.last.from
end
test 'reset password with email of different case should fail when email is NOT the list of case insensitive keys' do
swap Devise, :case_insensitive_keys => [] do
create_user(:email => 'Foo@Bar.com')
@@ -208,6 +218,15 @@ class PasswordTest < ActionController::IntegrationTest
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
end
test 'reset password request with invalid E-Mail in XML format should return empty and valid response' do
swap Devise, :paranoid => true do
create_user
post user_password_path(:format => 'xml'), :user => {:email => "invalid@test.com"}
assert_response :success
assert_equal response.body, { }.to_xml
end
end
test 'change password with valid parameters in XML format should return valid response' do
user = create_user
request_forgot_password
@@ -250,7 +269,7 @@ class PasswordTest < ActionController::IntegrationTest
assert_not_contain "1 error prohibited this user from being saved:"
assert_not_contain "Email not found"
assert_contain "If your e-mail exists on our database, you will receive a password recovery link on your e-mail"
assert_current_url "/users/password"
assert_current_url "/users/sign_in"
end
end
@@ -262,7 +281,7 @@ class PasswordTest < ActionController::IntegrationTest
click_button 'Send me reset password instructions'
assert_contain "If your e-mail exists on our database, you will receive a password recovery link on your e-mail"
assert_current_url "/users/password"
assert_current_url "/users/sign_in"
end
end
end

View File

@@ -13,7 +13,7 @@ class RegistrationTest < ActionController::IntegrationTest
fill_in 'password confirmation', :with => 'new_user123'
click_button 'Sign up'
assert_contain 'Welcome! You have signed up successfully.'
assert_contain 'You have signed up successfully'
assert warden.authenticated?(:admin)
assert_current_url "/admin_area/home"
@@ -36,13 +36,19 @@ class RegistrationTest < ActionController::IntegrationTest
assert_current_url "/?custom=1"
end
test 'a guest user should be able to sign up successfully and be blocked by confirmation' do
def user_sign_up
ActionMailer::Base.deliveries.clear
get new_user_registration_path
fill_in 'email', :with => 'new_user@test.com'
fill_in 'password', :with => 'new_user123'
fill_in 'password confirmation', :with => 'new_user123'
click_button 'Sign up'
end
test 'a guest user should be able to sign up successfully and be blocked by confirmation' do
user_sign_up
assert_contain 'You have signed up successfully. However, we could not sign you in because your account is unconfirmed.'
assert_not_contain 'You have to confirm your account before continuing'
@@ -55,6 +61,17 @@ class RegistrationTest < ActionController::IntegrationTest
assert_not user.confirmed?
end
test 'a guest user should receive the confirmation instructions from the default mailer' do
user_sign_up
assert_equal ['please-change-me@config-initializers-devise.com'], ActionMailer::Base.deliveries.first.from
end
test 'a guest user should receive the confirmation instructions from a custom mailer' do
User.any_instance.stubs(:devise_mailer).returns(Users::Mailer)
user_sign_up
assert_equal ['custom@example.com'], ActionMailer::Base.deliveries.first.from
end
test 'a guest user should be blocked by confirmation and redirected to a custom path' do
Devise::RegistrationsController.any_instance.stubs(:after_inactive_sign_up_path_for).returns("/?custom=1")
get new_user_registration_path
@@ -274,3 +291,34 @@ class RegistrationTest < ActionController::IntegrationTest
assert_equal User.count, 0
end
end
class ReconfirmableRegistrationTest < ActionController::IntegrationTest
test 'a signed in admin should see a more appropriate flash message when editing his account if reconfirmable is enabled' do
sign_in_as_admin
get edit_admin_registration_path
fill_in 'email', :with => 'admin.new@example.com'
fill_in 'current password', :with => '123456'
click_button 'Update'
assert_current_url '/admin_area/home'
assert_contain 'but we need to verify your new email address'
assert_equal "admin.new@example.com", Admin.first.unconfirmed_email
end
test 'a signed in admin should not see a reconfirmation message if they did not change their password' do
sign_in_as_admin
get edit_admin_registration_path
fill_in 'password', :with => 'pas123'
fill_in 'password confirmation', :with => 'pas123'
fill_in 'current password', :with => '123456'
click_button 'Update'
assert_current_url '/admin_area/home'
assert_contain 'You updated your account successfully.'
assert Admin.first.valid_password?('pas123')
end
end

View File

@@ -9,14 +9,6 @@ class RememberMeTest < ActionController::IntegrationTest
user
end
def create_admin_and_remember
admin = create_admin
admin.remember_me!
raw_cookie = Admin.serialize_into_cookie(admin)
cookies['remember_admin_token'] = generate_signed_cookie(raw_cookie)
admin
end
def generate_signed_cookie(raw_cookie)
request = ActionDispatch::TestRequest.new
request.cookie_jar.signed['raw_cookie'] = raw_cookie
@@ -117,34 +109,6 @@ class RememberMeTest < ActionController::IntegrationTest
end
end
test 'if both extend_remember_period and remember_across_browsers are true, sends the same token with a new expire date' do
swap Devise, :remember_across_browsers => true, :extend_remember_period => true, :remember_for => 1.year do
admin = create_admin_and_remember
token = admin.remember_token
admin.remember_created_at = old = 10.minutes.ago
admin.save!
get root_path
assert (cookie_expires("remember_admin_token") - 1.year) > (old + 5.minutes)
assert_equal token, signed_cookie("remember_admin_token").last
end
end
test 'if both extend_remember_period and remember_across_browsers are false, sends a new token with old expire date' do
swap Devise, :remember_across_browsers => false, :extend_remember_period => false, :remember_for => 1.year do
admin = create_admin_and_remember
token = admin.remember_token
admin.remember_created_at = old = 10.minutes.ago
admin.save!
get root_path
assert (cookie_expires("remember_admin_token") - 1.year) < (old + 5.minutes)
assert_not_equal token, signed_cookie("remember_admin_token").last
end
end
test 'do not remember other scopes' do
user = create_user_and_remember
get root_path
@@ -182,20 +146,6 @@ class RememberMeTest < ActionController::IntegrationTest
assert_not warden.authenticated?(:user)
end
test 'do not remember the admin anymore after forget' do
admin = create_admin_and_remember
get root_path
assert warden.authenticated?(:admin)
get destroy_admin_session_path
assert_not warden.authenticated?(:admin)
assert_nil admin.reload.remember_token
assert_nil warden.cookies['remember_admin_token']
get root_path
assert_not warden.authenticated?(:admin)
end
test 'changing user password expires remember me token' do
user = create_user_and_remember
user.password = "another_password"

View File

@@ -16,6 +16,15 @@ class SessionTimeoutTest < ActionController::IntegrationTest
assert_not_equal old_last_request, last_request_at
end
test 'set last request at in user session after each request is skipped if tracking is disabled' do
sign_in_as_user
old_last_request = last_request_at
assert_not_nil last_request_at
get users_path, {}, 'devise.skip_trackable' => true
assert_equal old_last_request, last_request_at
end
test 'not time out user session before default limit time' do
sign_in_as_user
assert_response :success

View File

@@ -25,7 +25,7 @@ class TokenAuthenticationTest < ActionController::IntegrationTest
end
test 'authenticate with valid authentication token key but does not store if stateless' do
swap Devise, :token_authentication_key => :secret_token, :stateless_token => true do
swap Devise, :token_authentication_key => :secret_token, :skip_session_storage => [:token_auth] do
sign_in_as_new_user_with_token
assert warden.authenticated?(:user)
@@ -88,7 +88,7 @@ class TokenAuthenticationTest < ActionController::IntegrationTest
end
test 'authenticate with valid authentication token key and do not store if stateless and timeoutable are enabled' do
swap Devise, :token_authentication_key => :secret_token, :stateless_token => true, :timeout_in => (0.1).second do
swap Devise, :token_authentication_key => :secret_token, :skip_session_storage => [:token_auth], :timeout_in => (0.1).second do
user = sign_in_as_new_user_with_token
assert warden.authenticated?(:user)

View File

@@ -36,6 +36,17 @@ class TrackableHooksTest < ActionController::IntegrationTest
assert_equal "127.0.0.1", user.current_sign_in_ip
assert_equal "127.0.0.1", user.last_sign_in_ip
end
test "current remote ip returns original ip behind a non transparent proxy" do
user = create_user
arbitrary_ip = '192.168.1.69'
sign_in_as_user do
header 'HTTP_X_FORWARDED_FOR', arbitrary_ip
end
user.reload
assert_equal arbitrary_ip, user.current_sign_in_ip
end
test "increase sign in count" do
user = create_user
@@ -52,7 +63,7 @@ class TrackableHooksTest < ActionController::IntegrationTest
end
test "does not update anything if user has signed out along the way" do
swap Devise, :confirm_within => 0 do
swap Devise, :allow_unconfirmed_access_for => 0 do
user = create_user(:confirm => false)
sign_in_as_user

View File

@@ -8,6 +8,11 @@ class ConfirmationInstructionsTest < ActionMailer::TestCase
Devise.mailer_sender = 'test@example.com'
end
def teardown
Devise.mailer = 'Devise::Mailer'
Devise.mailer_sender = 'please-change-me@config-initializers-devise.com'
end
def user
@user ||= create_user
end

View File

@@ -8,6 +8,11 @@ class ResetPasswordInstructionsTest < ActionMailer::TestCase
Devise.mailer_sender = 'test@example.com'
end
def teardown
Devise.mailer = 'Devise::Mailer'
Devise.mailer_sender = 'please-change-me@config-initializers-devise.com'
end
def user
@user ||= begin
user = create_user

View File

@@ -8,6 +8,11 @@ class UnlockInstructionsTest < ActionMailer::TestCase
Devise.mailer_sender = 'test@example.com'
end
def teardown
Devise.mailer = 'Devise::Mailer'
Devise.mailer_sender = 'please-change-me@config-initializers-devise.com'
end
def user
@user ||= begin
user = create_user

View File

@@ -51,12 +51,12 @@ class MappingTest < ActiveSupport::TestCase
test 'has strategies depending on the model declaration' do
assert_equal [:rememberable, :token_authenticatable, :database_authenticatable], Devise.mappings[:user].strategies
assert_equal [:rememberable, :database_authenticatable], Devise.mappings[:admin].strategies
assert_equal [:database_authenticatable], Devise.mappings[:admin].strategies
end
test 'has no input strategies depending on the model declaration' do
assert_equal [:rememberable, :token_authenticatable], Devise.mappings[:user].no_input_strategies
assert_equal [:rememberable], Devise.mappings[:admin].no_input_strategies
assert_equal [], Devise.mappings[:admin].no_input_strategies
end
test 'find scope for a given object' do
@@ -108,7 +108,6 @@ class MappingTest < ActiveSupport::TestCase
assert mapping.authenticatable?
assert mapping.recoverable?
assert mapping.lockable?
assert_not mapping.confirmable?
assert_not mapping.omniauthable?
end

View File

@@ -80,8 +80,8 @@ class ConfirmableTest < ActiveSupport::TestCase
end
test 'should send confirmation instructions by email' do
assert_email_sent do
create_user
assert_email_sent "mynewuser@example.com" do
create_user :email => "mynewuser@example.com"
end
end
@@ -123,7 +123,7 @@ class ConfirmableTest < ActiveSupport::TestCase
test 'should send email instructions for the user confirm its email' do
user = create_user
assert_email_sent do
assert_email_sent user.email do
User.send_confirmation_instructions(:email => user.email)
end
end
@@ -164,19 +164,19 @@ class ConfirmableTest < ActiveSupport::TestCase
end
test 'confirm time should fallback to devise confirm in default configuration' do
swap Devise, :confirm_within => 1.day do
swap Devise, :allow_unconfirmed_access_for => 1.day do
user = new_user
user.confirmation_sent_at = 2.days.ago
assert_not user.active_for_authentication?
Devise.confirm_within = 3.days
Devise.allow_unconfirmed_access_for = 3.days
assert user.active_for_authentication?
end
end
test 'should be active when confirmation sent at is not overpast' do
swap Devise, :confirm_within => 5.days do
Devise.confirm_within = 5.days
swap Devise, :allow_unconfirmed_access_for => 5.days do
Devise.allow_unconfirmed_access_for = 5.days
user = create_user
user.confirmation_sent_at = 4.days.ago
@@ -198,7 +198,7 @@ class ConfirmableTest < ActiveSupport::TestCase
end
test 'should not be active when confirm in is zero' do
Devise.confirm_within = 0.days
Devise.allow_unconfirmed_access_for = 0.days
user = create_user
user.confirmation_sent_at = Date.today
assert_not user.active_for_authentication?
@@ -236,3 +236,81 @@ class ConfirmableTest < ActiveSupport::TestCase
end
end
end
class ReconfirmableTest < ActiveSupport::TestCase
test 'should generate confirmation token after changing email' do
admin = create_admin
assert admin.confirm!
assert_nil admin.confirmation_token
assert admin.update_attributes(:email => 'new_test@example.com')
assert_not_nil admin.confirmation_token
end
test 'should send confirmation instructions by email after changing email' do
admin = create_admin
assert admin.confirm!
assert_email_sent "new_test@example.com" do
assert admin.update_attributes(:email => 'new_test@example.com')
end
end
test 'should not send confirmation by email after changing password' do
admin = create_admin
assert admin.confirm!
assert_email_not_sent do
assert admin.update_attributes(:password => 'newpass', :password_confirmation => 'newpass')
end
end
test 'should stay confirmed when email is changed' do
admin = create_admin
assert admin.confirm!
assert admin.update_attributes(:email => 'new_test@example.com')
assert admin.confirmed?
end
test 'should update email only when it is confirmed' do
admin = create_admin
assert admin.confirm!
assert admin.update_attributes(:email => 'new_test@example.com')
assert_not_equal 'new_test@example.com', admin.email
assert admin.confirm!
assert_equal 'new_test@example.com', admin.email
end
test 'should not allow admin to get past confirmation email by resubmitting their new address' do
admin = create_admin
assert admin.confirm!
assert admin.update_attributes(:email => 'new_test@example.com')
assert_not_equal 'new_test@example.com', admin.email
assert admin.update_attributes(:email => 'new_test@example.com')
assert_not_equal 'new_test@example.com', admin.email
end
test 'should find a admin by send confirmation instructions with unconfirmed_email' do
admin = create_admin
assert admin.confirm!
assert admin.update_attributes(:email => 'new_test@example.com')
confirmation_admin = Admin.send_confirmation_instructions(:email => admin.unconfirmed_email)
assert_equal confirmation_admin, admin
end
test 'should return a new admin if no email or unconfirmed_email was found' do
confirmation_admin = Admin.send_confirmation_instructions(:email => "invalid@email.com")
assert_not confirmation_admin.persisted?
end
test 'should add error to new admin email if no email or unconfirmed_email was found' do
confirmation_admin = Admin.send_confirmation_instructions(:email => "invalid@email.com")
assert confirmation_admin.errors[:email]
assert_equal "not found", confirmation_admin.errors[:email].join
end
test 'should find admin with email in unconfirmed_emails' do
admin = create_admin
admin.unconfirmed_email = "new_test@email.com"
assert admin.save
admin = Admin.find_by_unconfirmed_email_with_errors(:email => "new_test@email.com")
assert admin.persisted?
end
end

View File

@@ -22,26 +22,9 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
assert_equal email.strip, user.email
end
test 'find_for_authentication and filter_auth_params should not modify the conditions hash' do
FilterAuthUser = Class.new(User) do
def self.filter_auth_params(conditions)
if conditions.is_a?(Hash) && login = conditions.delete('login')
key = login.include?('@') ? :email : :username
conditions[key] = login
end
super(conditions)
end
end
conditions = { 'login' => 'foo@bar.com' }
FilterAuthUser.find_for_authentication(conditions)
assert_equal({ 'login' => 'foo@bar.com' }, conditions)
end
test "filter_auth_params should not convert booleans and integer to strings" do
test "param filter should not convert booleans and integer to strings" do
conditions = { 'login' => 'foo@bar.com', "bool1" => true, "bool2" => false, "fixnum" => 123, "will_be_converted" => (1..10) }
conditions = User.__send__(:filter_auth_params, conditions)
conditions = Devise::ParamFilter.new([], []).filter(conditions)
assert_equal( { 'login' => 'foo@bar.com', "bool1" => true, "bool2" => false, "fixnum" => 123, "will_be_converted" => "1..10" }, conditions)
end
@@ -104,6 +87,13 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
assert user.reload.valid_password?('pass321')
end
test 'should update password with valid current password and :as option' do
user = create_user
assert user.update_with_password(:current_password => '123456',
:password => 'pass321', :password_confirmation => 'pass321', :as => :admin)
assert user.reload.valid_password?('pass321')
end
test 'should add an error to current password when it is invalid' do
user = create_user
assert_not user.update_with_password(:current_password => 'other',
@@ -155,6 +145,12 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
user.update_without_password(:email => 'new@example.com')
assert_equal 'new@example.com', user.email
end
test 'should update the user without password with :as option' do
user = create_user
user.update_without_password(:email => 'new@example.com', :as => :admin)
assert_equal 'new@example.com', user.email
end
test 'should not update password without password' do
user = create_user

View File

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

View File

@@ -195,31 +195,4 @@ class RecoverableTest < ActiveSupport::TestCase
assert_equal "has expired, please request a new one", reset_password_user.errors[:reset_password_token].join
end
end
test 'should save the model when the reset_password_sent_at doesnt exist' do
user = create_user
def user.respond_to?(meth, *)
if meth == :reset_password_sent_at=
false
else
super
end
end
user.send_reset_password_instructions
user.reload
assert_not_nil user.reset_password_token
end
test 'should have valid period if does not respond to reset_password_sent_at' do
user = create_user
def user.respond_to?(meth, *)
if meth == :reset_password_sent_at
false
else
super
end
end
assert user.reset_password_period_valid?
end
end

View File

@@ -1,7 +1,46 @@
require 'test_helper'
module SharedRememberableTest
extend ActiveSupport::Testing::Declarative
class RememberableTest < ActiveSupport::TestCase
def resource_class
User
end
def create_resource
create_user
end
test 'remember_me should not generate a new token if using salt' do
user = create_user
user.expects(:valid?).never
user.remember_me!
end
test 'forget_me should not clear remember token if using salt' do
user = create_user
user.remember_me!
user.expects(:valid?).never
user.forget_me!
end
test 'serialize into cookie' do
user = create_user
user.remember_me!
assert_equal [user.to_key, user.authenticatable_salt], User.serialize_into_cookie(user)
end
test 'serialize from cookie' do
user = create_user
user.remember_me!
assert_equal user, User.serialize_from_cookie(user.to_key, user.authenticatable_salt)
end
test 'raises a RuntimeError if authenticatable_salt is nil' do
user = User.new
user.encrypted_password = nil
assert_raise RuntimeError do
user.rememberable_value
end
end
test 'should respond to remember_me attribute' do
assert resource_class.new.respond_to?(:remember_me)
@@ -127,161 +166,3 @@ module SharedRememberableTest
end
end
end
class RememberableTest < ActiveSupport::TestCase
include SharedRememberableTest
def resource_class
Admin
end
def create_resource
create_admin
end
test 'remember_me should generate a new token and save the record without validating' do
admin = create_admin
admin.expects(:valid?).never
token = admin.remember_token
admin.remember_me!
assert_not_equal token, admin.remember_token
assert_not admin.changed?
end
test 'forget_me should clear remember token and save the record without validating' do
admin = create_admin
admin.remember_me!
assert_not admin.remember_token.nil?
admin.expects(:valid?).never
admin.forget_me!
assert admin.remember_token.nil?
assert_not admin.changed?
end
test 'serialize into cookie' do
admin = create_admin
admin.remember_me!
assert_equal [admin.to_key, admin.remember_token], Admin.serialize_into_cookie(admin)
end
test 'serialize from cookie' do
admin = create_admin
admin.remember_me!
assert_equal admin, Admin.serialize_from_cookie(admin.to_key, admin.remember_token)
end
test 'if remember_across_browsers is true, remember_me! should create a new token if no token exists' do
swap Devise, :remember_across_browsers => true, :remember_for => 1.year do
admin = create_admin
assert_equal nil, admin.remember_token
admin.remember_me!
assert_not_equal nil, admin.remember_token
end
end
test 'if remember_across_browsers is true, remember_me! should create a new token if a token exists but has expired' do
swap Devise, :remember_across_browsers => true, :remember_for => 1.day do
admin = create_admin
admin.remember_me!
admin.remember_created_at = 2.days.ago
admin.save
token = admin.remember_token
admin.remember_me!
assert_not_equal token, admin.remember_token
end
end
test 'if remember_across_browsers is true, remember_me! should not create a new token if a token exists and has not expired' do
swap Devise, :remember_across_browsers => true, :remember_for => 2.days do
admin = create_admin
admin.remember_me!
admin.remember_created_at = 1.day.ago
admin.save
token = admin.remember_token
admin.remember_me!
assert_equal token, admin.remember_token
end
end
test 'if remember_across_browsers is false, remember_me! should create a new token if no token exists' do
swap Devise, :remember_across_browsers => false do
admin = create_admin
assert_equal nil, admin.remember_token
admin.remember_me!
assert_not_equal nil, admin.remember_token
end
end
test 'if remember_across_browsers is false, remember_me! should create a new token if a token exists but has expired' do
swap Devise, :remember_across_browsers => false, :remember_for => 1.day do
admin = create_admin
admin.remember_me!
admin.remember_created_at = 2.days.ago
admin.save
token = admin.remember_token
admin.remember_me!
assert_not_equal token, admin.remember_token
end
end
test 'if remember_across_browsers is false, remember_me! should create a new token if a token exists and has not expired' do
swap Devise, :remember_across_browsers => false, :remember_for => 2.days do
admin = create_admin
admin.remember_me!
admin.remember_created_at = 1.day.ago
admin.save
token = admin.remember_token
admin.remember_me!
assert_not_equal token, admin.remember_token
end
end
end
class WithSaltRememberableTest < ActiveSupport::TestCase
include SharedRememberableTest
setup do
assert_not User.new.respond_to?(:remember_token)
end
def resource_class
User
end
def create_resource
create_user
end
test 'remember_me should not generate a new token if using salt' do
user = create_user
user.expects(:valid?).never
user.remember_me!
end
test 'forget_me should not clear remember token if using salt' do
user = create_user
user.remember_me!
user.expects(:valid?).never
user.forget_me!
end
test 'serialize into cookie' do
user = create_user
user.remember_me!
assert_equal [user.to_key, user.authenticatable_salt], User.serialize_into_cookie(user)
end
test 'serialize from cookie' do
user = create_user
user.remember_me!
assert_equal user, User.serialize_from_cookie(user.to_key, user.authenticatable_salt)
end
test 'raises a RuntimeError if authenticatable_salt is nil' do
user = User.new
user.encrypted_password = nil
assert_raise RuntimeError do
user.rememberable_value
end
end
end

View File

@@ -16,7 +16,7 @@ class SerializableTest < ActiveSupport::TestCase
end
test 'should include unsafe keys on XML if a force_except is provided' do
assert_no_match /email/, @user.to_xml(:force_except => :email)
assert_no_match /<email/, @user.to_xml(:force_except => :email)
assert_match /confirmation-token/, @user.to_xml(:force_except => :email)
end

View File

@@ -14,6 +14,20 @@ class TimeoutableTest < ActiveSupport::TestCase
assert_not new_user.timedout?(nil)
end
test 'should use timeout_in method' do
user = new_user
user.instance_eval { def timeout_in; 10.minutes end }
assert user.timedout?(12.minutes.ago)
assert_not user.timedout?(8.minutes.ago)
end
test 'should not be expired when timeout_in method returns nil' do
user = new_user
user.instance_eval { def timeout_in; nil end }
assert_not user.timedout?(10.hours.ago)
end
test 'fallback to Devise config option' do
swap Devise, :timeout_in => 1.minute do
user = new_user

View File

@@ -2,7 +2,7 @@ require 'test_helper'
class Configurable < User
devise :database_authenticatable, :encryptable, :confirmable, :rememberable, :timeoutable, :lockable,
:stretches => 15, :pepper => 'abcdef', :confirm_within => 5.days,
:stretches => 15, :pepper => 'abcdef', :allow_unconfirmed_access_for => 5.days,
:remember_for => 7.days, :timeout_in => 15.minutes, :unlock_in => 10.days
end
@@ -39,7 +39,7 @@ class ActiveRecordTest < ActiveSupport::TestCase
end
test 'can cherry pick modules' do
assert_include_modules Admin, :database_authenticatable, :registerable, :timeoutable, :recoverable, :lockable, :rememberable, :encryptable
assert_include_modules Admin, :database_authenticatable, :registerable, :timeoutable, :recoverable, :lockable, :encryptable, :confirmable
end
test 'validations options are not applied too late' do
@@ -55,12 +55,12 @@ class ActiveRecordTest < ActiveSupport::TestCase
end
test 'chosen modules are inheritable' do
assert_include_modules Inheritable, :database_authenticatable, :registerable, :timeoutable, :recoverable, :lockable, :rememberable, :encryptable
assert_include_modules Inheritable, :database_authenticatable, :registerable, :timeoutable, :recoverable, :lockable, :encryptable, :confirmable
end
test 'order of module inclusion' do
correct_module_order = [:database_authenticatable, :rememberable, :encryptable, :recoverable, :registerable, :lockable, :timeoutable]
incorrect_module_order = [:database_authenticatable, :timeoutable, :registerable, :recoverable, :lockable, :encryptable, :rememberable]
correct_module_order = [:database_authenticatable, :encryptable, :recoverable, :registerable, :confirmable, :lockable, :timeoutable]
incorrect_module_order = [:database_authenticatable, :timeoutable, :registerable, :recoverable, :lockable, :encryptable, :confirmable]
assert_include_modules Admin, *incorrect_module_order
@@ -87,8 +87,8 @@ class ActiveRecordTest < ActiveSupport::TestCase
assert_equal 'abcdef', Configurable.pepper
end
test 'set a default value for confirm_within' do
assert_equal 5.days, Configurable.confirm_within
test 'set a default value for allow_unconfirmed_access_for' do
assert_equal 5.days, Configurable.allow_unconfirmed_access_for
end
test 'set a default value for remember_for' do

View File

@@ -0,0 +1,57 @@
require 'test_helper'
class OmniAuthConfigTest < ActiveSupport::TestCase
class MyStrategy
include OmniAuth::Strategy
end
test 'strategy_name returns provider if no options given' do
config = Devise::OmniAuth::Config.new :facebook, [{}]
assert_equal :facebook, config.strategy_name
end
test 'strategy_name returns provider if no name option are given' do
config = Devise::OmniAuth::Config.new :facebook, [{ :other => :option }]
assert_equal :facebook, config.strategy_name
end
test 'returns name option when have a name' do
config = Devise::OmniAuth::Config.new :facebook, [{ :name => :github }]
assert_equal :github, config.strategy_name
end
test "finds contrib strategies" do
config = Devise::OmniAuth::Config.new :facebook, [{}]
assert_equal OmniAuth::Strategies::Facebook, config.strategy_class
end
test "finds the strategy in OmniAuth's list by name" do
NamedTestStrategy = Class.new
NamedTestStrategy.send :include, OmniAuth::Strategy
NamedTestStrategy.option :name, :the_one
config = Devise::OmniAuth::Config.new :the_one, [{}]
assert_equal NamedTestStrategy, config.strategy_class
end
test "finds the strategy in OmniAuth's list by class name" do
UnNamedTestStrategy = Class.new
UnNamedTestStrategy.send :include, OmniAuth::Strategy
config = Devise::OmniAuth::Config.new :un_named_test_strategy, [{}]
assert_equal UnNamedTestStrategy, config.strategy_class
end
test 'raises an error if strategy cannot be found' do
config = Devise::OmniAuth::Config.new :my_other_strategy, [{}]
assert_raise Devise::OmniAuth::StrategyNotFound do
config.strategy_class
end
end
test 'allows the user to define a custom require path' do
config = Devise::OmniAuth::Config.new :my_strategy, [{:strategy_class => MyStrategy}]
config_class = config.strategy_class
assert_equal MyStrategy, config_class
end
end

View File

@@ -40,13 +40,13 @@ class OmniAuthRoutesTest < ActionController::TestCase
end
test 'should generate authorization path with params' do
assert_match "/users/auth/open_id?openid_url=http%3A%2F%2Fyahoo.com",
@controller.omniauth_authorize_path(:user, :open_id, :openid_url => "http://yahoo.com")
assert_match "/users/auth/openid?openid_url=http%3A%2F%2Fyahoo.com",
@controller.omniauth_authorize_path(:user, :openid, :openid_url => "http://yahoo.com")
end
test 'should not add a "?" if no param was sent' do
assert_equal "/users/auth/open_id",
@controller.omniauth_authorize_path(:user, :open_id)
assert_equal "/users/auth/openid",
@controller.omniauth_authorize_path(:user, :openid)
end
test 'should set script name in the path if present' do

21
test/path_checker_test.rb Normal file
View File

@@ -0,0 +1,21 @@
require 'test_helper'
class PathCheckerTest < ActiveSupport::TestCase
test 'check if sign out path matches' do
path_checker = Devise::PathChecker.new({"PATH_INFO" => "/users/sign_out"}, :user)
assert path_checker.signing_out?
path_checker = Devise::PathChecker.new({"PATH_INFO" => "/users/sign_in"}, :user)
assert_not path_checker.signing_out?
end
test 'considers script name' do
path_checker = Devise::PathChecker.new({"SCRIPT_NAME" => "/users", "PATH_INFO" => "/sign_out"}, :user)
assert path_checker.signing_out?
end
test 'ignores invalid routes' do
path_checker = Devise::PathChecker.new({"PATH_INFO" => "/users/sign_in"}, :omg)
assert_not path_checker.signing_out?
end
end

View File

@@ -5,5 +5,26 @@ class Admin
include Shim
include SharedAdmin
field :remember_token, :type => String
## Database authenticatable
field :email, :type => String, :null => true
field :encrypted_password, :type => String, :null => true
## Recoverable
field :reset_password_token, :type => String
field :reset_password_sent_at, :type => Time
## Rememberable
field :remember_created_at, :type => Time
## Confirmable
field :confirmation_token, :type => String
field :confirmed_at, :type => Time
field :confirmation_sent_at, :type => Time
field :unconfirmed_email, :type => String # Only if using reconfirmable
## Encryptable
field :password_salt, :type => String
## Lockable
field :locked_at, :type => Time
end

View File

@@ -7,4 +7,39 @@ class User
field :username, :type => String
field :facebook_token, :type => String
## Database authenticatable
field :email, :type => String, :null => false, :default => ""
field :encrypted_password, :type => String, :null => false, :default => ""
## Recoverable
field :reset_password_token, :type => String
field :reset_password_sent_at, :type => Time
## Rememberable
field :remember_created_at, :type => Time
## Trackable
field :sign_in_count, :type => Integer, :default => 0
field :current_sign_in_at, :type => Time
field :last_sign_in_at, :type => Time
field :current_sign_in_ip, :type => String
field :last_sign_in_ip, :type => String
## Encryptable
# field :password_salt, :type => String
## Confirmable
field :confirmation_token, :type => String
field :confirmed_at, :type => Time
field :confirmation_sent_at, :type => Time
# field :unconfirmed_email, :type => String # Only if using reconfirmable
## Lockable
field :failed_attempts, :type => Integer, :default => 0 # Only if lock strategy is :failed_attempts
field :unlock_token, :type => String # Only if unlock strategy is :email or :both
field :locked_at, :type => Time
# Token authenticatable
field :authentication_token, :type => String
end

View File

@@ -11,7 +11,6 @@ RailsApp::Application.configure do
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_view.debug_rjs = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send

View File

@@ -1,3 +1,6 @@
require "omniauth-facebook"
require "omniauth-openid"
# Use this hook to configure devise mailer, warden hooks and so forth. The first
# four configuration values can also be set straight in your models.
Devise.setup do |config|
@@ -9,6 +12,9 @@ Devise.setup do |config|
# Configure the class responsible to send e-mails.
# config.mailer = "Devise::Mailer"
# Disable apply schema
config.apply_schema = false
# ==> ORM configuration
# Load and configure the ORM. Supports :active_record (default) and
# :mongoid (bson_ext recommended) by default. Other ORMs may be
@@ -57,16 +63,16 @@ Devise.setup do |config|
# ==> 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
config.stretches = Rails.env.test? ? 1 : 10
# ==> 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 nil.
# When confirm_within is zero, the user won't be able to sign in without confirming.
# When allow_unconfirmed_access_for 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).
# config.confirm_within = 2.days
# config.allow_unconfirmed_access_for = 2.days
# Defines which key will be used when confirming an account
# config.confirmation_keys = [ :email ]
@@ -145,10 +151,6 @@ Devise.setup do |config|
# Defines name of the authentication token params key
# config.token_authentication_key = :auth_token
# If true, authentication through token does not store user in session and needs
# to be supplied on each request. Useful if you are using the token as API token.
# config.stateless_token = false
# ==> Scopes configuration
# Turn scoped views on. Before rendering "sessions/new", it will first check for
# "users/sessions/new". It's turned off by default because it's slower if you
@@ -177,8 +179,8 @@ Devise.setup do |config|
# ==> OmniAuth
config.omniauth :facebook, 'APP_ID', 'APP_SECRET', :scope => 'email,offline_access'
config.omniauth :open_id
config.omniauth :open_id, :name => 'google', :identifier => 'https://www.google.com/accounts/o8/id'
config.omniauth :openid
config.omniauth :openid, :name => 'google', :identifier => 'https://www.google.com/accounts/o8/id'
# ==> Warden configuration
# If you want to use other strategies, that are not supported by Devise, or

View File

@@ -46,17 +46,17 @@ Rails.application.routes.draw do
# Routes for constraints testing
devise_for :headquarters_admin, :class_name => "Admin", :path => "headquarters", :constraints => {:host => /192\.168\.1\.\d\d\d/}
constraints(:host => /192\.168\.1\.\d\d\d/) do
devise_for :homebase_admin, :class_name => "Admin", :path => "homebase"
end
devise_for :skip_admin, :class_name => "Admin", :skip => :all
# Routes for format=false testing
devise_for :htmlonly_admin, :class_name => "Admin", :skip => [:confirmations, :unlocks], :path => "htmlonly_admin", :format => false, :skip_helpers => [:confirmations, :unlocks]
devise_for :htmlonly_users, :class_name => "User", :only => [:confirmations, :unlocks], :path => "htmlonly_users", :format => false, :skip_helpers => true
# Other routes for routing_test.rb
devise_for :reader, :class_name => "User", :only => :passwords
@@ -71,7 +71,7 @@ Rails.application.routes.draw do
:password => "secret", :confirmation => "verification",
:unlock => "unblock", :sign_up => "register",
:registration => "management", :cancel => "giveup"
}
}, :failure_app => lambda { |env| [404, {"Content-Type" => "text/plain"}, ["Oops, not found"]] }
end
namespace :sign_out_via, :module => "devise" do

View File

@@ -4,22 +4,68 @@ class CreateTables < ActiveRecord::Migration
t.string :username
t.string :facebook_token
t.database_authenticatable :null => false
t.confirmable
t.recoverable
t.rememberable
t.trackable
t.lockable
t.token_authenticatable
## Database authenticatable
t.string :email, :null => false, :default => ""
t.string :encrypted_password, :null => false, :default => ""
## Recoverable
t.string :reset_password_token
t.datetime :reset_password_sent_at
## Rememberable
t.datetime :remember_created_at
## Trackable
t.integer :sign_in_count, :default => 0
t.datetime :current_sign_in_at
t.datetime :last_sign_in_at
t.string :current_sign_in_ip
t.string :last_sign_in_ip
## Encryptable
# t.string :password_salt
## Confirmable
t.string :confirmation_token
t.datetime :confirmed_at
t.datetime :confirmation_sent_at
# t.string :unconfirmed_email # Only if using reconfirmable
## Lockable
t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts
t.string :unlock_token # Only if unlock strategy is :email or :both
t.datetime :locked_at
# Token authenticatable
t.string :authentication_token
t.timestamps
end
create_table :admins do |t|
t.database_authenticatable :null => true
t.encryptable
t.rememberable :use_salt => false
t.recoverable
t.lockable
## Database authenticatable
t.string :email, :null => true
t.string :encrypted_password, :null => true
## Recoverable
t.string :reset_password_token
t.datetime :reset_password_sent_at
## Rememberable
t.datetime :remember_created_at
## Confirmable
t.string :confirmation_token
t.datetime :confirmed_at
t.datetime :confirmation_sent_at
t.string :unconfirmed_email # Only if using reconfirmable
## Encryptable
t.string :password_salt
## Lockable
t.datetime :locked_at
t.timestamps
end
end

View File

@@ -3,7 +3,11 @@ module SharedAdmin
included do
devise :database_authenticatable, :encryptable, :registerable,
:timeoutable, :recoverable, :rememberable, :lockable,
:unlock_strategy => :time
:timeoutable, :recoverable, :lockable, :confirmable,
:unlock_strategy => :time, :lock_strategy => :none,
:allow_unconfirmed_access_for => 2.weeks, :reconfirmable => true
validates_uniqueness_of :email, :allow_blank => true, :if => :email_changed?
end
end

View File

@@ -225,6 +225,10 @@ class CustomizedRoutingTest < ActionController::TestCase
assert_recognizes({:controller => 'devise/unlocks', :action => 'show'}, {:path => '/htmlonly_users/unlock.xml', :method => :get})
end
end
test 'map with format false is not permanent' do
assert_equal "/set.xml", @routes.url_helpers.set_path(:xml)
end
end
class ScopedRoutingTest < ActionController::TestCase

View File

@@ -1,33 +0,0 @@
if DEVISE_ORM == :mongoid
require 'test_helper'
class User2
include Mongoid::Document
devise :database_authenticatable
end
class User3
include Mongoid::Document
devise :database_authenticatable, :authentication_keys => [:username, :email]
end
class User4
include Mongoid::Document
devise :database_authenticatable, :authentication_keys => [:username]
end
class SchemaTest < ActiveSupport::TestCase
test 'should create an email field if there are no custom authentication keys' do
assert_not_equal User2.fields['email'], nil
end
test 'should create an email field if there are custom authentication keys and they include email' do
assert_not_equal User3.fields['email'], nil
end
test 'should not create an email field if there are custom authentication keys they don\'t include email' do
assert_equal User4.fields['email'], nil
end
end
end

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