Compare commits

...

168 Commits

Author SHA1 Message Date
José Valim
6c2f51e35e Release 2.2.2 2013-01-15 21:03:15 +01:00
Lucas Mazza
47db984f52 Apply the changes on 0c4615e33 to the simple_form template too. 2013-01-14 18:53:34 -02:00
José Valim
0c4615e337 Properly check if reconfirmable is available 2013-01-13 09:53:26 +01:00
Carlos Antonio da Silva
85e46f0163 Merge pull request #2211 from nashby/fix-build
uUe click_button for canceling account in integration specs
2013-01-12 03:16:12 -08:00
Vasiliy Ermolovich
9913fde749 use click_button for canceling account in integration specs 2013-01-12 14:12:05 +03:00
José Valim
1f940f61c6 Merge pull request #2210 from steverob/master
Changed link_to to button_to for cancel registration link in edit registration view
2013-01-11 14:25:55 -08:00
Steve Robinson
70e38fe66d Changed link_to to button_to for delete user
It is advisable to use link_to for mostly GET operations. Actions like DESTROY when presented as a link can cause severe vulnerabilities.
Hence using a button is advisable.
2013-01-12 01:53:09 +05:30
José Valim
872ef2b97f Release 2.2.1 with fixes for 2.2.0 regressions 2013-01-11 19:15:54 +01:00
José Valim
33fb89340a Revert "update_with_password doesn't change encrypted password when it is invalid"
This reverts commit 10235f9d72.
2013-01-11 19:12:53 +01:00
José Valim
bd9bf326c0 Merge pull request #2206 from tigris/mailer_subject_rename
Rename Devise::Mailer.translate() to something more inline with what it does
2013-01-10 04:19:57 -08:00
Danial Pearce
d48414b0a5 Rename Devise::Mailer.translate() to something more inline with what it does. 2013-01-10 15:26:06 +11:00
José Valim
b6a7d11e5a Merge pull request #2205 from latortuga/2204-regression-with-db-authenticatable
2204 regression with db authenticatable
2013-01-09 09:52:14 -08:00
Drew Ulmer
75ce916be9 Call respond_to?(attr) before applying strip or downcase
This avoids calling strip and downcase on globally configured keys that may
not exist on all devise models. Fixes #2204, a regression introduced by
PR #2135. Also included a note about the intentional use of respond_to.
2013-01-09 11:42:54 -06:00
Drew Ulmer
c768366240 Add failing tests for Issue #2204
For a point release upgrade, Devise should not throw an exception when trying
to downcase or strip globally configured keys. This would be a breaking
change in functionality and this test demonstrates the issue.
2013-01-09 11:41:20 -06:00
Lucas Mazza
ca7d479e90 Install mongoid only on 1.9 2013-01-09 11:51:15 -02:00
Rafael Mendonça França
5bfbc264b7 Invalid YAML 💣 2013-01-09 10:14:01 -02:00
Rafael Mendonça França
9f8d3db2b4 Notify on campfire 2013-01-09 10:11:24 -02:00
Lucas Mazza
4b0d161f95 Update Gemfile.locks to latest patch releases of Rails and fix mocha to 0.10.0.t 2013-01-09 10:01:25 -02:00
José Valim
b2b8b5bf9a Release v2.2.0 2013-01-08 21:30:43 +01:00
Carlos Antonio da Silva
beda0fe9bd Update copyright [ci skip]
Or as @rafaelfranca says: Happy New Year 🎆
2013-01-08 09:22:26 -02:00
José Valim
8fa3951bea Update app/controllers/devise/sessions_controller.rb 2013-01-06 11:07:51 +01:00
José Valim
9724e386c3 Merge pull request #2201 from al/bugfix-non_navigational_session_destroy
Fix bug with non-navigational requests being treated as navigational ones in XHR to SessionsController#destroy.
2013-01-06 02:07:16 -08:00
Alan Larkin
f2de7bf84c Fixed bug in SessionsController#destroy which caused all XHR requests, regardless of `Accept' header, to be treated as 'text/html'. 2013-01-06 03:50:26 +00:00
Alan Larkin
84b8188db9 Added failing integration test for XHR invocation of SessionsController#destroy with */*' in the Accept' header. 2013-01-06 03:49:59 +00:00
José Valim
19b5bcbe0f Accept mail options in Devise::Mailer and deprecate headers_for 2013-01-04 18:52:49 +01:00
José Valim
7c8f636b98 Merge pull request #2178 from gwagener/master
Improved grammar of reset password e-mail
2012-12-13 22:49:30 -08:00
Graham Wagener
5745d97232 Improved grammar of reset password e-mail. 2012-12-14 15:08:55 +13:00
José Valim
86f0bff332 Apparently Rails 3.1 does not like @headers as ivar 2012-12-13 09:59:36 +01:00
José Valim
30ab6f923d Release 2.2.0.rc 2012-12-13 09:20:46 +01:00
José Valim
839e8fc8ac Show if there is an e-mail waiting for confirmation, closes #2060 2012-12-13 09:13:33 +01:00
José Valim
4c83743263 unconfirmed_email now uses the proper e-mail on salutation, related to #2060 2012-12-13 09:02:59 +01:00
José Valim
e1fde192f2 Update CHANGELOG 2012-12-13 08:43:43 +01:00
José Valim
73389ea491 Merge pull request #2174 from rykov/master
Adding the Gem Version badge to README
2012-12-11 10:44:32 -08:00
Michael Rykov
eeb6a30752 Add 'Gem Version' badge to README.md 2012-12-11 10:39:47 -08:00
Lucas Mazza
01669c7374 Display the build status just for the master branch [ci skip]. 2012-12-10 10:59:50 -02:00
Carlos Antonio da Silva
ac3a25bf2e Remove nothing raised assertion
Let the test raise if that is the case, no need for assert that nothing
was raised.

Hopefully fix the build 
2012-12-04 17:49:26 -02:00
Carlos Antonio da Silva
0652117c79 Bundle update 2012-12-04 17:37:32 -02:00
Carlos Antonio da Silva
2261005ed5 Refactor a bit to avoid two model attributes lookup
Tidy up tests a bit.
2012-12-04 17:37:12 -02:00
José Valim
e80e0c9a89 Merge pull request #2135 from latortuga/2129-make-validatable-affect-virtual-attributes
Make validatable callbacks affect virtual attributes
2012-12-02 01:43:48 -08:00
Drew Ulmer
79e9d6e564 Allow validation callbacks to apply to virtual attributes 2012-12-01 21:06:33 -06:00
Drew Ulmer
0c6f2adf14 Add failing test for #2129 2012-12-01 21:06:11 -06:00
Drew Ulmer
77ec1b08cd Move test models into their own file so they can be used elsewhere 2012-12-01 21:06:03 -06:00
Carlos Antonio da Silva
2be9fb292e Merge pull request #2165 from asanghi/master
Reverting part of #2164 which was a mistake [ci skip]
2012-12-01 10:58:39 -08:00
Aditya Sanghi
88dba417ef reverting part of #2164 which was a mistake 2012-12-02 00:24:09 +05:30
José Valim
b98f021d0f Merge pull request #2164 from asanghi/master
Minor grammar updates
2012-11-30 03:25:51 -08:00
Aditya Sanghi
c026b5a3f6 minor documentation grammar update 2012-11-30 16:42:18 +05:30
José Valim
3696cbf33e Merge pull request #2148 from kukula/master
Fix default email_regexp config to not allow spaces
2012-11-21 02:58:30 -08:00
José Valim
cbfdcbeaed Merge pull request #2147 from gabetax/signin_nonexistent_error
Support alternate sign in error message when email record does not exist
2012-11-19 15:56:18 -08:00
Gabe Martin-Dempesy
130d684198 Change failure key for missing database resource to :invalid_email 2012-11-19 15:49:21 -08:00
Anatoliy Kukul
f0f3e15c08 add test for Devise.email_regexp 2012-11-19 17:38:22 +02:00
José Valim
19a1ea5211 Update README.md 2012-11-19 14:02:43 +01:00
José Valim
6c2c808478 Merge pull request #2143 from luisico/display-invalid-confirmation-token-error
Invalid confirmation token message not shown with simple_form
2012-11-19 05:02:06 -08:00
Anatoliy Kukul
adc9a45f05 Used other regxp 2012-11-19 13:58:19 +02:00
Anatoliy Kukul
50186474d4 Fix default email_regexp config to not allow spaces
Default email_regexp config accepted emails with spaces. e.g.: "test user@test server.com" http://rubular.com/r/jXGS8pmumd
Changed regexp to not allow spaces in email. e.g.:  http://rubular.com/r/tTD9PytGEp
2012-11-19 13:40:54 +02:00
Gabe Martin-Dempesy
ffab77c35e Fix typo on nonexistent error 2012-11-18 15:19:15 -08:00
Gabe Martin-Dempesy
cde2229e59 Support alternate sign in error message when email record does not exist
By default, the nonexistent error is still identical to the :invalid
message, and must be customized by the developer to implement.
2012-11-18 15:08:57 -08:00
José Valim
397fce1f9d Merge pull request #2144 from jm81/master
Use correct current_password in RegistrationTest of invalid confirmation
2012-11-15 10:56:49 -08:00
Jared Morgan
f044916f94 Use correct current_password in RegistrationTest of invalid confirmation
In DatabaseAuthenticatable#update_with_password, password is now deleted if
the current_password is invalid. dm-validations will not check the
confirmation in that case, so this test was failing in dm-devise.
2012-11-15 12:21:11 -06:00
Luis Gracia
0415564a7d Show invalid unlock token message
Attribute unlock token is not present in the simple_form template,
therefore not being displayed by #error_notification.
This fix explicitily call #full_error on :unlock_token.
2012-11-13 15:01:32 -05:00
Luis Gracia
ed6f2abc23 Show invalid confirmation token message
fixes #2143

Attribute confirmation token is not present in the simple_form template,
therefore not being displayed by #error_notification.
This fix explicitily call #full_error on :confirmation_token.
2012-11-12 20:05:42 -05:00
Lucas Mazza
96a0477555 Remove 1.9.2 + Mongoid from the build matrix.
http://mongoid.org/en/mongoid/docs/tips.html#ruby
2012-11-12 15:07:29 -02:00
Lucas Mazza
da5464acf6 Update Travis CI configuration:
* `DEVISE_ORM=mongoid` is part of the build matrix, except
  for 1.8.7 and REE rubies;
* `language` key added (Thanks to travis-lint).
2012-11-12 09:12:17 -02:00
Lucas Mazza
1c8fc18fad Update Gemfile.rails-3.1.x. 2012-11-12 09:11:55 -02:00
José Valim
fbf667e009 Update CHANGELOG 2012-11-10 21:07:34 +01:00
José Valim
071ba358a9 Update README.md 2012-11-10 20:51:20 +01:00
José Valim
ef4db2e93d Merge pull request #2138 from nashby/patch-1
update README
2012-11-10 11:49:15 -08:00
José Valim
6a2ef52aa0 Merge pull request #2139 from durran/mongoid-3-test-fixes
Fix spec failures for Mongoid 3.
2012-11-10 11:49:05 -08:00
Durran Jordan
d821275588 Fix spec failures for Mongoid 3.
This has no actual changes to Devise itself, just fixes the failing
tests when running against Mongoid 3 instead of Mongoid 2.

Mocha has been locked at 0.10.0 since 0.12.0 raises an error when trying
to set an expectation on a frozen object.

Tests were updated to work with both AR and Mongoid, some cases the XML
serialization was slightly different but both were outputting correct
and valid XML, and the id/_id field mismatch is now handled.

An active field was missing from the test models for Mongoid, and the
invalid :null => true options in field were removed.
2012-11-10 20:02:58 +01:00
Vasiliy Ermolovich
59966e817c update README
closes #2128
2012-11-10 20:35:43 +03:00
José Valim
b1df686a2e Merge pull request #2137 from nashby/indifferent
remove useless test
2012-11-08 11:25:08 -08:00
Vasiliy Ermolovich
ae426dcc1c remove useless test 2012-11-08 22:22:03 +03:00
José Valim
1646684af9 Merge pull request #2134 from marcinb/master
unlock user after password re-set
2012-11-07 14:15:00 -08:00
Marcin Balinski
ac58c28617 Unlock user when re-setting password and unlock strategy is :email or :both 2012-11-07 10:45:46 +01:00
José Valim
7d72121bd7 Merge pull request #2132 from nashby/issue-2130
update_with_password doesn't change encrypted password when it is invalid
2012-11-06 13:13:50 -08:00
Vasiliy Ermolovich
10235f9d72 update_with_password doesn't change encrypted password when it is invalid
closes #2130
2012-11-06 21:05:17 +03:00
José Valim
5d311e7557 Merge pull request #2126 from nashby/issue-2122
don't delete the return to url from session if the requested format is not navigational
2012-11-04 23:49:42 -08:00
Vasiliy Ermolovich
5d86327e4d move is_navigational_format? and request_format methods to helpers 2012-11-05 09:54:22 +03:00
Vasiliy Ermolovich
61903b534a don't delete the return to url from session if the requested format is not navigational
closes #2122
2012-11-04 23:42:38 +03:00
José Valim
ee61d86546 Update CONTRIBUTING.md 2012-10-30 20:09:10 +01:00
José Valim
06a2cff140 Merge pull request #2117 from nashby/fix-issue-2043
handle namespaced models in AR generator
2012-10-27 15:25:32 -07:00
Vasiliy Ermolovich
2f36d0dd32 handle namespaced models in AR generator
closes #2043
2012-10-28 00:59:33 +03:00
José Valim
d5a2a9b2da Update CHANGELOG 2012-10-26 11:24:56 +02:00
José Valim
8ee1591868 Merge pull request #2115 from latortuga/1994-paranoid-locking
Add failing test for Issue #1994
2012-10-26 02:22:49 -07:00
José Valim
18c377e0d7 Merge pull request #2112 from latortuga/patch-1
Make #set_flash_message respect i18n-set resource_name
2012-10-26 02:05:42 -07:00
Drew Ulmer
00a01c2bc4 Fix #1994 Lockable no longer leaks account existence 2012-10-25 16:51:56 -05:00
Drew Ulmer
00e8841e93 Unit test for Lockable#unauthenticated_message not leaking account existence
This is another failing test for #1994, a unit test for Lockable. Lockable's
#uanauthenticated_message should not return :locked if paranoid mode is on
and instead should return the generic :invalid response.
2012-10-25 16:51:02 -05:00
Drew Ulmer
f79bb31ee6 Add failing test for Issue #1994
Lockable should not leak information about account existence if paranoid
mode is on.
2012-10-25 16:20:21 -05:00
Drew Ulmer
d6449d014e Add test for #devise_i18n_options allowing resource_name override 2012-10-24 12:13:07 -05:00
Drew Ulmer
b853871667 Make #set_flash_message respect i18n-set resource_name
Using #devise_i18n_options allows overriding any i18n keys but the
resulting call to I18n.t does not respect an override of resource_name.
2012-10-24 11:50:26 -05:00
José Valim
f796439cf2 Merge pull request #2111 from rubynortheast/signup_hook
Separates sign_up and sign_in on Registration
2012-10-23 12:53:52 -07:00
Philip Poots
692175b897 Moves sign_up from helpers to controller 2012-10-23 20:29:41 +01:00
Philip Poots
68dc20cba2 Separates sign_up and sign_in on Registration
See #2104

Completed with the help of @rubynortheast
2012-10-23 20:05:45 +01:00
José Valim
90dbae4c7a Merge pull request #2096 from adammcnamara/bugfix/assign-self-dot-resource
Assigns object to self.resource, changing variable scope.
2012-10-10 07:10:22 -07:00
Adam McNamara
564e588f5e Assigns object to self.resource, changing variable scope. 2012-10-10 10:01:35 -04:00
José Valim
8f4b06542e Merge pull request #2088 from dyba/contributing-fix
Missing https:// in Google Group link
2012-10-04 08:44:20 -07:00
Daniel Dyba
7513512000 Missing https:// in Google Group link 2012-10-04 08:38:16 -07:00
José Valim
7b04ecdddb Update CONTRIBUTING.md 2012-10-04 08:20:50 -07:00
José Valim
50338b34f9 Merge pull request #2074 from diminish7/failure_app_test_helper
Test helper was incorrectly returning failure body
2012-09-28 07:45:49 -07:00
José Valim
75268bed5c Merge pull request #2077 from floehopper/use-number-of-for-countable-noun
Use "number of" instead of "amount of" for countable nouns.
2012-09-28 07:45:03 -07:00
James Mead
e873e2aeed Use "number of" instead of "amount of" for countable nouns. 2012-09-28 10:52:37 +01:00
Jason Rush
b27491061e Test helper was incorrectly returning failure body
The _process_unauthenticated method in test_helper was returning
the response as the body. When setting rendering the text, it was
calling to_s on the response which would render something like
this: #<ActionDispatch::Response:0x007fb9e1efea00>. This change
renders the body of the response instead of the response itself
2012-09-27 18:44:31 -06:00
José Valim
9e096a4113 Update README.md 2012-09-18 14:30:04 +03:00
José Valim
8c7bf7dd15 Merge pull request #2042 from igor04/master
Deleted unnecessary validation in generator mongoid model
2012-09-13 05:10:18 -07:00
José Valim
f7dd59839c Update lib/generators/templates/README 2012-09-06 17:26:20 +03:00
José Valim
84c4759f58 Merge pull request #2045 from mtoledo/patch-1
Minor typo fix
2012-08-28 04:17:53 -07:00
Marcos Toledo
e345d3940c Minor typo fix 2012-08-27 23:41:47 -03:00
igor04
d59301ed2a Deleted unnecessary validation in generator mongoid model 2012-08-26 14:54:08 +03:00
José Valim
48751783a7 Merge pull request #2040 from RudyOnRails/master
Corrected routes.rb comment for destroy_user_session HTTP method. From GET to DELETE.
2012-08-23 09:24:39 -07:00
Kevin Musiorski
691172d01f Changed HTTP method for route destroy_user_session from GET to DELETE. Cleaned up indentations to keep tidy. 2012-08-23 10:26:45 -05:00
José Valim
eb51d0365f Merge pull request #2037 from Radagaisus/master
HTML5 Autofocus, to make things nicer
2012-08-22 05:38:38 -07:00
Radagaisus
422bf89182 autofocus for simple_form_for 2012-08-22 15:28:25 +03:00
Radagaisus
4962fbcb51 no need for {} they said 2012-08-22 02:15:48 +03:00
Radagaisus
be2b481385 fixed for 1.8.7 syntax 2012-08-22 02:13:38 +03:00
Radagaisus
d169ef3641 extra whitespace 2012-08-22 02:01:01 +03:00
Radagaisus
2a64972321 html5 autofocus for a better ux from the get go 2012-08-22 01:58:26 +03:00
Rafael Mendonça França
33fac7f765 Merge pull request #2027 from nashby/patch-1
Update lib/devise/rails/routes.rb comments
2012-08-17 07:09:49 -07:00
Vasiliy Ermolovich
5c2e3e1a12 Update lib/devise/rails/routes.rb 2012-08-17 17:05:47 +03:00
José Valim
4a24667e80 Revert "Rails 3.2.7 deprecates update_attribute in favor of update_column"
Rails 3.2.8 is rolling back the deprecations.

This reverts commit 7d41072c0e.
2012-08-05 09:24:10 -03:00
José Valim
c3d9dc3007 Merge pull request #2007 from willrax/patch-1
fixed typo in readme.md
2012-08-05 04:48:35 -07:00
willrax
df0a9401b1 fixed typo in readme.md 2012-08-05 19:27:11 +10:00
Carlos Antonio da Silva
f7f086faae Fix README [ci skip] 2012-07-31 23:32:10 -03:00
Rafael Mendonça França
6ae64b1723 Merge pull request #1998 from fabiokr/update_attribute
Replaces update_attribute with update_column
2012-07-27 13:31:20 -07:00
Fabio Kreusch
7d41072c0e Rails 3.2.7 deprecates update_attribute in favor of update_column. Updated projects using Devise output lots of warnings because Devise uses the deprecated version in some places. This commit replaces update_attribute with update_column to fix that. 2012-07-27 17:25:21 -03:00
José Valim
2f75b12add Merge pull request #1993 from ahmeij/master
Add message about :timedout flash to the Readme (resolved #1777)
2012-07-25 07:25:37 -07:00
Andre Meij
352dd1f2fc Update README.md include :timedout notice
Resolves #1777
2012-07-25 16:47:40 +03:00
José Valim
bdf0bc7b1e Revert "Revert "New password default minimum length is now 8""
This reverts commit b1f490a2f8.
Actually, the implementation was good!
2012-07-24 23:41:17 +02:00
José Valim
b1f490a2f8 Revert "New password default minimum length is now 8"
This reverts commit 2950434ed3.
It is backwards incompatible, we need a better migration plan.
2012-07-24 22:41:13 +02:00
Víctor Manuel Cruz Dueñas
73f617db7b Checking if unconfirmed_email has changed before to set update_needs_confirmation flash message.
Conflicts:

	test/integration/registerable_test.rb

Signed-off-by: José Valim <jose.valim@plataformatec.com.br>
2012-07-23 16:20:51 +02:00
José Valim
1da8490dbc Add a note about APIs in token authenticatable, closes #1959 2012-07-23 16:12:38 +02:00
José Valim
6e79c5c242 Ensure a new token is generated if the previous one expired 2012-07-23 16:05:51 +02:00
José Valim
f4db03d31c Do not add ActionView::Helpers::DateHelper to all models 2012-07-23 15:59:17 +02:00
Rodrigo Flores
8bc1096099 Minor correction on changelog 2012-07-23 10:39:39 -03:00
Rodrigo Flores
a23247d431 Changelog 2012-07-22 17:17:50 -03:00
Rodrigo Flores
6a37945025 Merge pull request #1975 from promisedlandt/email-token-expiration
Email token expiration
2012-07-22 13:10:27 -07:00
Nils Landt
dcada8fe75 Refactor according to line notes from josevalim
- rename reset_password_within to confirm_within
- confirmation_period_valid? is back and memoized
- fix hash syntax to hashrocket
2012-07-22 14:02:27 +02:00
Nils Landt
f80cecc864 Remove unnecessary include 2012-07-16 11:50:46 +02:00
Nils Landt
1d6ee13aae Refactor according to rodrigoflores
- Favor using update_attribute instead of constructor parameters in user
  factory for tests
- Test for accurate error message when confirmation token is expired
- Don't check twice whether the confirmation period is expired
2012-07-16 11:20:01 +02:00
José Valim
01d3ed7172 Merge pull request #1976 from benknowles/master
Patch for Trackable IP
2012-07-12 12:15:36 -07:00
Ben Knowles
a1411c885f Trackable should use the remote IP address, not the gateway's 2012-07-12 13:34:31 -05:00
Nils Landt
6e48fcee76 Fix tests for email token expiration
The tests work now, but are a bit wonky because User.create does things
I don't understand.
2012-07-11 18:30:36 +02:00
Nils Landt
42a0c30139 Refactored according to line notes by rodrigoflores 2012-07-11 15:49:41 +02:00
Nils Landt
87f2fa9767 Add options to expire confirmation tokens
With this patch, functionality is added to expire the confirmation
tokens that are being sent by email.
For example, if a token is valid for 3 days only, it cannot be used for
confirmation on the 4th day.
2012-07-09 14:43:12 +02:00
José Valim
8463c6dce4 Merge pull request #1963 from shime/master
update CONTRIBUTING.md
2012-07-07 11:38:41 -07:00
Hrvoje Šimić
9b77ac0cab update CONTRIBUTING.md 2012-07-07 19:57:59 +02:00
Rodrigo Flores
0afae74386 Update CONTRIBUTING.md 2012-07-06 16:52:53 -03:00
José Valim
56c1ab0824 Update CONTRIBUTING.md 2012-07-06 20:39:39 +02:00
José Valim
1ec23994f2 Try CONTRIBUTING.md 2012-07-06 20:23:58 +02:00
Rodrigo Flores
2950434ed3 New password default minimum length is now 8 2012-07-06 13:41:28 -03:00
Rodrigo Flores
1aca139c65 Changelog update 2012-07-06 12:03:25 -03:00
Rodrigo Flores
fa451306fc Merge pull request #1961 from carlosgaldino/change-min-password-length
Change the minimum password length to 8
2012-07-06 08:01:41 -07:00
Carlos Galdino
c179cef365 Change the minimum password length to 8 2012-07-06 11:46:46 -03:00
José Valim
1579ec9a87 Update CHANGELOG 2012-06-28 12:13:42 +02:00
José Valim
cbc6926e3d Fix issue #1928, thanks to @ejfinneran for a test case 2012-06-28 12:05:20 +02:00
José Valim
9678b422ff Merge pull request #1954 from mrchrisadams/d1bf31729d10fbb65f1b7ce158f3926aa946b3ad
Allow setting of default reply_to fields on mailer mails - #1936
2012-06-27 03:19:52 -07:00
Chris Adams
d1bf31729d Address issue #1936
Update mailer to accept reply_to as a default param as well, as discussed in 

https://github.com/plataformatec/devise/issues/1936#issuecomment-6583637
2012-06-26 23:11:35 +01:00
José Valim
a89a2052b8 Depend on latest warden 2012-06-26 21:16:00 +03:00
José Valim
6c80839e7b Merge pull request #1953 from ka8725/master
Use request_format method instead of direct code
2012-06-26 11:12:18 -07:00
Andrey Koleshko
972ac3b5f0 refactor is_navigational_format? method 2012-06-26 17:58:50 +03:00
Rodrigo Flores
caa8961938 Merge pull request #1949 from dblock/reconfirmation_token_reset
Test that confirms that #1948 is not an issue.
2012-06-25 15:37:05 -07:00
dblock
619826fbc8 Test that confirms that #1948 is not an issue. 2012-06-25 18:33:48 -04:00
José Valim
fe62d1bf6a Merge pull request #1943 from mathieul/patch-1
Allow to destroy a session using JSON format
2012-06-24 07:25:25 -07:00
mathieul
95f20587ef test that destroying a session doesn't set the flash if the requested format is not navigational 2012-06-23 14:43:35 -07:00
Mathieu Lajugie
8171ad39e0 Allow to destroy a session using JSON format (or any non navigational format) when Rails flash feature is not enabled (i.e.: when using rails-api). 2012-06-23 10:49:33 -07:00
Carlos Antonio da Silva
0c9b79947d Fix locked_at column in lockable required fields logic
See a7658f9d75 (commitcomment-1493199)

Thanks @nickhoffman
2012-06-22 22:31:57 -03:00
Carlos Antonio da Silva
4c9680787d Merge pull request #1941 from saizai/patch-1
Camelize correctly - e.g. omniauth-paypal sets this via OmniAuth.config.add_camelization
2012-06-22 18:21:14 -07:00
Sai
6eeb9e4b7d Update patch-1 2012-06-22 14:03:56 -03:00
Sai
80b2240ef0 Camelize correctly - e.g. omniauth-paypal sets this via OmniAuth.config.add_camelization 2012-06-22 10:55:23 -03:00
José Valim
2f142724c5 Update master 2012-06-19 19:33:30 +03:00
84 changed files with 933 additions and 457 deletions

View File

@@ -1,15 +1,42 @@
language: ruby
script: "bundle exec rake test"
rvm:
- 1.8.7
- 1.9.2
- 1.9.3
- ree
env:
- DEVISE_ORM=mongoid
- DEVISE_ORM=active_record
matrix:
exclude:
- rvm: ree
env: DEVISE_ORM=mongoid
gemfile: Gemfile
- rvm: ree
env: DEVISE_ORM=mongoid
gemfile: gemfiles/Gemfile.rails-3.1.x
- rvm: 1.8.7
env: DEVISE_ORM=mongoid
gemfile: Gemfile
- rvm: 1.8.7
env: DEVISE_ORM=mongoid
gemfile: gemfiles/Gemfile.rails-3.1.x
- rvm: 1.9.2
env: DEVISE_ORM=mongoid
gemfile: Gemfile
- rvm: 1.9.2
env: DEVISE_ORM=mongoid
gemfile: gemfiles/Gemfile.rails-3.1.x
gemfile:
- gemfiles/Gemfile.rails-3.1.x
- Gemfile
services:
- mongodb
notifications:
recipients:
- jose.valim@plataformatec.com.br
- carlos@plataformatec.com.br
- rodrigo.flores@plataformatec.com.br
- rafael.franca@plataformatec.com.br
email: false
campfire:
on_success: change
on_failure: always
rooms:
- secure: "TRiqvuM4i/QmRDWjUSNitE5/P91BOzDkNl53+bZjjtxcISCswZtmECWBR7n9\n3xwqCOU1o2lfohxZ32OHOj/Nj7o+90zWJfWxcv+if0hIXRiil62M5pg0lZUd\nyJ4M5VQ0lSWo5he1OUrXhSabPJeaK3B8yT/tdh+qO5yzR+vb/jc="

View File

@@ -1,6 +1,48 @@
== 2.2.2
* bug fix
* Fix bug when checking for reconfirmable in templates
== 2.2.1
* bug fix
* Fix regression with case_insensitive_keys
* Fix regression when password is blank when it is invalid
== 2.2.0
* backwards incompatible changes
* `headers_for` is deprecated, customize the mailer directly instead
* All mailer methods now expect a second argument with delivery options
* Default minimum password length is now 8 (by @carlosgaldino)
* Support alternate sign in error message when email record does not exist (this adds a new I18n key to the locale file) (by @gabetax)
* DeviseController responds only to HTML requests by default (call `DeviseController.respond_to` or `ApplicationController.respond_to` to add new formats)
* Support Mongoid 3 onwards (by @durran)
* enhancements
* Fix unlockable which could leak account existence on paranoid mode (by @latortuga)
* Confirmable now has a confirm_within option to set a period while the confirmation token is still valid (by @promisedlandt)
* Flash messages in controller now respects `resource_name` (by @latortuga)
* Separate `sign_in` and `sign_up` on RegistrationsController (by @rubynortheast)
* Add autofocus to default views (by @Radagaisus)
* Unlock user on password reset (by @marcinb)
* Allow validation callbacks to apply to virtual attributes (by @latortuga)
* bug fix
* unconfirmed_email now uses the proper e-mail on salutation
* Fix default email_regexp config to not allow spaces (by @kukula)
* Fix a regression introduced on warden 1.2.1 (by @ejfinneran)
* Properly camelize omniauth strategies (by @saizai)
* Do not set flash messages for non navigational requests on session sign out (by @mathieul)
* Set the proper fields as required on the lockable module (by @nickhoffman)
* Respects Devise mailer default's reply_to (by @mrchrisadams)
* Properly assign resource on `sign_in` related action (by @adammcnamara)
* `update_with_password` doesn't change encrypted password when it is invalid (by @nashby)
* Properly handle namespaced models on Active Record generator (by @nashby)
== 2.1.2
* Enhancements
* enhancements
* Handle backwards incompatibility between Rails 3.2.6 and Thor 0.15.x
* bug fix

14
CONTRIBUTING.md Normal file
View File

@@ -0,0 +1,14 @@
### Please read before contributing
1) Do not post questions in the issues tracker. If you have any questions about Devise, search the [Wiki](https://github.com/plataformatec/devise/wiki) or use the [Mailing List](https://groups.google.com/group/plataformatec-devise) or [Stack Overflow](http://stackoverflow.com/questions/tagged/devise).
2) If you find a security bug, **DO NOT** submit an issue here. Please send an e-mail to [developers@plataformatec.com.br](mailto:developers@plataformatec.com.br) instead.
3) Do a small search on the issues tracker before submitting your issue to see if it was already reported / fixed.
4) When reporting an issue, include Rails, Devise and Warden versions. If you are getting exceptions, please include the full backtrace.
That's it! The more information you give, the easier it becomes for us to track it down and fix it.
Ideally, you should provide an application that reproduces the error or a test case to Devise's suite.
Thanks!

19
Gemfile
View File

@@ -11,11 +11,7 @@ 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
gem "mocha", "0.10.0", :require => false
end
platforms :jruby do
@@ -26,10 +22,11 @@ end
platforms :ruby do
gem "sqlite3"
group :mongoid do
gem "mongo", "~> 1.3.0"
gem "mongoid", "~> 2.0"
gem "bson_ext", "~> 1.3.0"
end
end
platforms :mri_19 do
group :mongoid do
gem "mongoid", "~> 3.0"
end
end

View File

@@ -1,7 +1,7 @@
PATH
remote: .
specs:
devise (2.1.2)
devise (2.2.1)
bcrypt-ruby (~> 3.0)
orm_adapter (~> 0.1)
railties (~> 3.1)
@@ -10,86 +10,85 @@ PATH
GEM
remote: http://rubygems.org/
specs:
actionmailer (3.2.6)
actionpack (= 3.2.6)
actionmailer (3.2.11)
actionpack (= 3.2.11)
mail (~> 2.4.4)
actionpack (3.2.6)
activemodel (= 3.2.6)
activesupport (= 3.2.6)
actionpack (3.2.11)
activemodel (= 3.2.11)
activesupport (= 3.2.11)
builder (~> 3.0.0)
erubis (~> 2.7.0)
journey (~> 1.0.1)
journey (~> 1.0.4)
rack (~> 1.4.0)
rack-cache (~> 1.2)
rack-test (~> 0.6.1)
sprockets (~> 2.1.3)
activemodel (3.2.6)
activesupport (= 3.2.6)
sprockets (~> 2.2.1)
activemodel (3.2.11)
activesupport (= 3.2.11)
builder (~> 3.0.0)
activerecord (3.2.6)
activemodel (= 3.2.6)
activesupport (= 3.2.6)
activerecord (3.2.11)
activemodel (= 3.2.11)
activesupport (= 3.2.11)
arel (~> 3.0.2)
tzinfo (~> 0.3.29)
activeresource (3.2.6)
activemodel (= 3.2.6)
activesupport (= 3.2.6)
activesupport (3.2.6)
activeresource (3.2.11)
activemodel (= 3.2.11)
activesupport (= 3.2.11)
activesupport (3.2.11)
i18n (~> 0.6)
multi_json (~> 1.0)
addressable (2.2.6)
arel (3.0.2)
bcrypt-ruby (3.0.1)
bson (1.5.1)
bson_ext (1.3.1)
builder (3.0.0)
columnize (0.3.5)
builder (3.0.4)
erubis (2.7.0)
faraday (0.7.5)
addressable (~> 2.2.6)
multipart-post (~> 1.1.3)
rack (>= 1.1.0, < 2)
faraday (0.8.4)
multipart-post (~> 1.1)
hashie (1.2.0)
hike (1.2.1)
i18n (0.6.0)
httpauth (0.2.0)
i18n (0.6.1)
journey (1.0.4)
json (1.7.3)
linecache (0.46)
rbx-require-relative (> 0.0.4)
json (1.7.6)
jwt (0.1.5)
multi_json (>= 1.0)
mail (2.4.4)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
metaclass (0.0.1)
mime-types (1.18)
mime-types (1.19)
mocha (0.10.0)
metaclass (~> 0.0.1)
mongo (1.3.1)
bson (>= 1.3.1)
mongoid (2.3.4)
mongoid (3.0.16)
activemodel (~> 3.1)
mongo (~> 1.3)
moped (~> 1.1)
origin (~> 1.0)
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)
moped (1.3.2)
multi_json (1.5.0)
multipart-post (1.1.5)
nokogiri (1.5.5)
oauth2 (0.8.0)
faraday (~> 0.8)
httpauth (~> 0.1)
jwt (~> 0.1.4)
multi_json (~> 1.0)
rack (~> 1.2)
omniauth (1.0.3)
hashie (~> 1.2)
rack
omniauth-facebook (1.0.0)
omniauth-oauth2 (~> 1.0.0)
omniauth-oauth2 (1.0.0)
oauth2 (~> 0.5.0)
omniauth-facebook (1.4.0)
omniauth-oauth2 (~> 1.0.2)
omniauth-oauth2 (1.0.3)
oauth2 (~> 0.8.0)
omniauth (~> 1.0)
omniauth-openid (1.0.1)
omniauth (~> 1.0)
rack-openid (~> 1.3.1)
orm_adapter (0.1.0)
origin (1.0.11)
orm_adapter (0.4.0)
polyglot (0.3.3)
rack (1.4.1)
rack (1.4.3)
rack-cache (1.2)
rack (>= 0.4)
rack-openid (1.3.1)
@@ -97,44 +96,39 @@ GEM
ruby-openid (>= 2.1.8)
rack-ssl (1.3.2)
rack
rack-test (0.6.1)
rack-test (0.6.2)
rack (>= 1.0)
rails (3.2.6)
actionmailer (= 3.2.6)
actionpack (= 3.2.6)
activerecord (= 3.2.6)
activeresource (= 3.2.6)
activesupport (= 3.2.6)
rails (3.2.11)
actionmailer (= 3.2.11)
actionpack (= 3.2.11)
activerecord (= 3.2.11)
activeresource (= 3.2.11)
activesupport (= 3.2.11)
bundler (~> 1.0)
railties (= 3.2.6)
railties (3.2.6)
actionpack (= 3.2.6)
activesupport (= 3.2.6)
railties (= 3.2.11)
railties (3.2.11)
actionpack (= 3.2.11)
activesupport (= 3.2.11)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (>= 0.14.6, < 2.0)
rake (0.9.2.2)
rbx-require-relative (0.0.5)
rake (10.0.3)
rdoc (3.12)
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.1.3)
ruby-openid (2.2.2)
sprockets (2.2.2)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.5)
thor (0.15.2)
sqlite3 (1.3.6)
thor (0.16.0)
tilt (1.3.3)
treetop (1.4.10)
treetop (1.4.12)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.33)
tzinfo (0.3.35)
warden (1.2.1)
rack (>= 1.0)
webrat (0.7.2)
@@ -148,18 +142,15 @@ PLATFORMS
DEPENDENCIES
activerecord-jdbc-adapter
activerecord-jdbcsqlite3-adapter
bson_ext (~> 1.3.0)
devise!
jruby-openssl
mocha
mongo (~> 1.3.0)
mongoid (~> 2.0)
mocha (= 0.10.0)
mongoid (~> 3.0)
omniauth (~> 1.0.0)
omniauth-facebook
omniauth-oauth2 (~> 1.0.0)
omniauth-openid (~> 1.0.1)
rails (~> 3.2.6)
rdoc
ruby-debug (>= 0.10.3)
sqlite3
webrat (= 0.7.2)

View File

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

View File

@@ -1,10 +1,10 @@
*IMPORTANT:* Devise 2.1 is out. If you are upgrading, please read: https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.1
## Devise
INFO: This README is [also available in a friendly navigable format](http://devise.plataformatec.com.br/).
[![Build Status](https://secure.travis-ci.org/plataformatec/devise.png?branch=master)](http://travis-ci.org/plataformatec/devise)
[![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/plataformatec/devise)
[![Gem Version](https://fury-badge.herokuapp.com/rb/devise.png)](http://badge.fury.io/rb/devise)
[![Build Status](https://secure.travis-ci.org/plataformatec/devise.png)](http://travis-ci.org/plataformatec/devise) [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/plataformatec/devise)
This README is [also available in a friendly navigable format](http://devise.plataformatec.com.br/).
Devise is a flexible authentication solution for Rails based on Warden. It:
@@ -108,7 +108,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 "rake 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 to point to Devise controller.
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 "rake 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 to point to the Devise controller.
Note that you should re-start your app here if you've already started it. Otherwise you'll run into strange errors like users being unable to login and the route helpers being undefined.
@@ -240,14 +240,14 @@ devise_for :admins, :controllers => { :sessions => "admins/sessions" }
3) And since we changed the controller, it won't use the "devise/sessions" views, so remember to copy "devise/sessions" to "admin/sessions".
Remember that Devise uses flash messages to let users know if sign in was successful or failed. Devise expects your application to call "flash[:notice]" and "flash[:alert]" as appropriate.
Remember that Devise uses flash messages to let users know if sign in was successful or failed. Devise expects your application to call "flash[:notice]" and "flash[:alert]" as appropriate. Do not print the entire flash hash, print specific keys or at least remove the `:timedout` key from the hash as Devise adds this key in some circumstances, this key is not meant for display.
### Configuring routes
Devise also ships with default routes. If you need to customize them, you should probably be able to do it through the devise_for method. It accepts several options like :class_name, :path_prefix and so on, including the possibility to change path names for I18n:
```ruby
devise_for :users, :path => "usuarios", :path_names => { :sign_in => 'login', :sign_out => 'logout', :password => 'secret', :confirmation => 'verification', :unlock => 'unblock', :registration => 'register', :sign_up => 'cmon_let_me_in' }
devise_for :users, :path => "auth", :path_names => { :sign_in => 'login', :sign_out => 'logout', :password => 'secret', :confirmation => 'verification', :unlock => 'unblock', :registration => 'register', :sign_up => 'cmon_let_me_in' }
```
Be sure to check `devise_for` documentation for details.
@@ -304,7 +304,7 @@ https://github.com/plataformatec/devise/wiki/I18n
### Test helpers
Devise includes some tests helpers for functional specs. In other to use them, you need to include Devise in your functional tests by adding the following to the bottom of your `test/test_helper.rb` file:
Devise includes some tests helpers for functional specs. In order to use them, you need to include Devise in your functional tests by adding the following to the bottom of your `test/test_helper.rb` file:
```ruby
class ActionController::TestCase
@@ -341,7 +341,13 @@ There are two things that is important to keep in mind:
### Omniauth
Devise comes with Omniauth support out of the box to authenticate from other providers. You can read more about Omniauth support in the wiki:
Devise comes with Omniauth support out of the box to authenticate with other providers. To use it, just specify your omniauth configuration in `config/initializers/devise.rb`:
```ruby
config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo'
```
You can read more about Omniauth support in the wiki:
* https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview
@@ -387,4 +393,4 @@ https://github.com/plataformatec/devise/contributors
## License
MIT License. Copyright 2012 Plataformatec. http://plataformatec.com.br
MIT License. Copyright 2009-2013 Plataformatec. http://plataformatec.com.br

View File

@@ -6,7 +6,7 @@ class Devise::OmniauthCallbacksController < DeviseController
end
def failure
set_flash_message :alert, :failure, :kind => failed_strategy.name.to_s.humanize, :reason => failure_message
set_flash_message :alert, :failure, :kind => OmniAuth::Utils.camelize(failed_strategy.name), :reason => failure_message
redirect_to after_omniauth_failure_path_for(resource_name)
end

View File

@@ -30,6 +30,7 @@ class Devise::PasswordsController < DeviseController
self.resource = resource_class.reset_password_by_token(resource_params)
if resource.errors.empty?
resource.unlock_access! if unlockable?(resource)
flash_message = resource.active_for_authentication? ? :updated : :updated_not_active
set_flash_message(:notice, flash_message) if is_navigational_format?
sign_in(resource_name, resource)
@@ -53,4 +54,12 @@ class Devise::PasswordsController < DeviseController
redirect_to new_session_path(resource_name)
end
end
# Check if proper Lockable module methods are present & unlock strategy
# allows to unlock resource on password reset
def unlockable?(resource)
resource.respond_to?(:unlock_access!) &&
resource.respond_to?(:unlock_strategy_enabled?) &&
resource.unlock_strategy_enabled?(:email)
end
end

View File

@@ -15,7 +15,7 @@ class Devise::RegistrationsController < DeviseController
if resource.save
if resource.active_for_authentication?
set_flash_message :notice, :signed_up if is_navigational_format?
sign_in(resource_name, resource)
sign_up(resource_name, resource)
respond_with resource, :location => after_sign_up_path_for(resource)
else
set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format?
@@ -38,13 +38,13 @@ class Devise::RegistrationsController < DeviseController
# the current user in place.
def update
self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key)
prev_unconfirmed_email = resource.unconfirmed_email if resource.respond_to?(:unconfirmed_email)
if resource.update_with_password(resource_params)
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
flash_key = update_needs_confirmation?(resource, prev_unconfirmed_email) ?
:update_needs_confirmation : :updated
set_flash_message :notice, flash_key
end
sign_in resource_name, resource, :bypass => true
respond_with resource, :location => after_update_path_for(resource)
@@ -74,6 +74,12 @@ class Devise::RegistrationsController < DeviseController
protected
def update_needs_confirmation?(resource, previous)
resource.respond_to?(:pending_reconfirmation?) &&
resource.pending_reconfirmation? &&
previous != resource.unconfirmed_email
end
# Build a devise resource passing in the session. Useful to move
# temporary session data to the newly created user.
def build_resource(hash=nil)
@@ -81,6 +87,12 @@ class Devise::RegistrationsController < DeviseController
self.resource = resource_class.new_with_session(hash, session)
end
# Signs in a user on sign up. You can overwrite this method in your own
# RegistrationsController.
def sign_up(resource_name, resource)
sign_in(resource_name, resource)
end
# The path used after sign up. You need to overwrite this method
# in your own RegistrationsController.
def after_sign_up_path_for(resource)

View File

@@ -5,14 +5,14 @@ class Devise::SessionsController < DeviseController
# GET /resource/sign_in
def new
resource = build_resource(nil, :unsafe => true)
self.resource = build_resource(nil, :unsafe => true)
clean_up_passwords(resource)
respond_with(resource, serialize_options(resource))
end
# POST /resource/sign_in
def create
resource = warden.authenticate!(auth_options)
self.resource = warden.authenticate!(auth_options)
set_flash_message(:notice, :signed_in) if is_navigational_format?
sign_in(resource_name, resource)
respond_with resource, :location => after_sign_in_path_for(resource)
@@ -22,15 +22,13 @@ class Devise::SessionsController < DeviseController
def destroy
redirect_path = after_sign_out_path_for(resource_name)
signed_out = (Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name))
set_flash_message :notice, :signed_out if signed_out
set_flash_message :notice, :signed_out if signed_out && is_navigational_format?
# We actually need to hardcode this as Rails default responder doesn't
# support returning empty response on GET request
respond_to do |format|
format.all { head :no_content }
format.any(*navigational_formats) { redirect_to redirect_path }
format.all do
head :no_content
end
end
end

View File

@@ -10,7 +10,7 @@ class DeviseController < Devise.parent_controller.constantize
helper_method *helpers
prepend_before_filter :assert_is_devise_resource!
respond_to *Mime::SET.map(&:to_sym) if mimes_for_respond_to.empty?
respond_to :html if mimes_for_respond_to.empty?
# Gets the actual resource stored in the instance variable
def resource
@@ -72,7 +72,7 @@ This may happen for two reasons:
2) You are testing a Devise controller bypassing the router.
If so, you can explicitly tell Devise which mapping to use:
@request.env["devise.mapping"] = Devise.mappings[:user]
MESSAGE
@@ -168,7 +168,7 @@ MESSAGE
options[:default] = Array(options[:default]).unshift(kind.to_sym)
options[:resource_name] = resource_name
options = devise_i18n_options(options) if respond_to?(:devise_i18n_options, true)
message = I18n.t("#{resource_name}.#{kind}", options)
message = I18n.t("#{options[:resource_name]}.#{kind}", options)
flash[key] = message if message.present?
end
@@ -181,12 +181,4 @@ MESSAGE
format.any(*navigational_formats, &block)
end
end
def request_format
@request_format ||= request.format.try(:ref)
end
def is_navigational_format?
Devise.navigational_formats.include?(request.format.try(:ref))
end
end

View File

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

View File

@@ -4,7 +4,7 @@
<%= devise_error_messages! %>
<div><%= f.label :email %><br />
<%= f.email_field :email %></div>
<%= f.email_field :email, :autofocus => true %></div>
<div><%= f.submit "Resend confirmation instructions" %></div>
<% end %>

View File

@@ -1,4 +1,4 @@
<p>Welcome <%= @resource.email %>!</p>
<p>Welcome <%= @email %>!</p>
<p>You can confirm your account email through the link below:</p>

View File

@@ -1,6 +1,6 @@
<p>Hello <%= @resource.email %>!</p>
<p>Someone has requested a link to change your password, and you can do this through the link below.</p>
<p>Someone has requested a link to change your password. You can do this through the link below.</p>
<p><%= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @resource.reset_password_token) %></p>

View File

@@ -1,6 +1,6 @@
<p>Hello <%= @resource.email %>!</p>
<p>Your account has been locked due to an excessive amount of unsuccessful sign in attempts.</p>
<p>Your account has been locked due to an excessive number of unsuccessful sign in attempts.</p>
<p>Click the link below to unlock your account:</p>

View File

@@ -5,7 +5,7 @@
<%= f.hidden_field :reset_password_token %>
<div><%= f.label :password, "New password" %><br />
<%= f.password_field :password %></div>
<%= f.password_field :password, :autofocus => true %></div>
<div><%= f.label :password_confirmation, "Confirm new password" %><br />
<%= f.password_field :password_confirmation %></div>

View File

@@ -4,7 +4,7 @@
<%= devise_error_messages! %>
<div><%= f.label :email %><br />
<%= f.email_field :email %></div>
<%= f.email_field :email, :autofocus => true %></div>
<div><%= f.submit "Send me reset password instructions" %></div>
<% end %>

View File

@@ -4,7 +4,11 @@
<%= devise_error_messages! %>
<div><%= f.label :email %><br />
<%= f.email_field :email %></div>
<%= f.email_field :email, :autofocus => true %></div>
<% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
<div>Currently waiting confirmation for: <%= resource.unconfirmed_email %></div>
<% end %>
<div><%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
<%= f.password_field :password, :autocomplete => "off" %></div>
@@ -20,6 +24,6 @@
<h3>Cancel my account</h3>
<p>Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), :data => { :confirm => "Are you sure?" }, :method => :delete %>.</p>
<p>Unhappy? <%= button_to "Cancel my account", registration_path(resource_name), :data => { :confirm => "Are you sure?" }, :method => :delete %>.</p>
<%= link_to "Back", :back %>

View File

@@ -4,7 +4,7 @@
<%= devise_error_messages! %>
<div><%= f.label :email %><br />
<%= f.email_field :email %></div>
<%= f.email_field :email, :autofocus => true %></div>
<div><%= f.label :password %><br />
<%= f.password_field :password %></div>

View File

@@ -2,7 +2,7 @@
<%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
<div><%= f.label :email %><br />
<%= f.email_field :email %></div>
<%= f.email_field :email, :autofocus => true %></div>
<div><%= f.label :password %><br />
<%= f.password_field :password %></div>

View File

@@ -4,7 +4,7 @@
<%= devise_error_messages! %>
<div><%= f.label :email %><br />
<%= f.email_field :email %></div>
<%= f.email_field :email, :autofocus => true %></div>
<div><%= f.submit "Resend unlock instructions" %></div>
<% end %>

View File

@@ -10,6 +10,7 @@ en:
not_saved:
one: "1 error prohibited this %{resource} from being saved:"
other: "%{count} errors prohibited this %{resource} from being saved:"
confirmation_period_expired: "needs to be confirmed within %{period}, please request a new one"
devise:
failure:
@@ -17,6 +18,7 @@ en:
unauthenticated: 'You need to sign in or sign up before continuing.'
unconfirmed: 'You have to confirm your account before continuing.'
locked: 'Your account is locked.'
not_found_in_database: 'Invalid email or password.'
invalid: 'Invalid email or password.'
invalid_token: 'Invalid authentication token.'
timeout: 'Your session expired, please sign in again to continue.'

View File

@@ -11,7 +11,7 @@ group :test do
gem "omniauth-facebook"
gem "omniauth-openid", "~> 1.0.1"
gem "webrat", "0.7.2", :require => false
gem "mocha", :require => false
gem "mocha", "0.10.0", :require => false
platforms :mri_18 do
gem "ruby-debug", ">= 0.10.3"
@@ -26,10 +26,10 @@ end
platforms :ruby do
gem "sqlite3"
group :mongoid do
gem "mongo", "~> 1.3.0"
gem "mongoid", "~> 2.0"
gem "bson_ext", "~> 1.3.0"
end
end
platforms :mri_19 do
group :mongoid do
gem "mongoid", "~> 3.0"
end
end

View File

@@ -1,59 +1,57 @@
PATH
remote: ..
specs:
devise (2.1.0.rc2)
devise (2.2.0)
bcrypt-ruby (~> 3.0)
orm_adapter (~> 0.0.7)
orm_adapter (~> 0.1)
railties (~> 3.1)
warden (~> 1.1.1)
warden (~> 1.2.1)
GEM
remote: http://rubygems.org/
specs:
actionmailer (3.1.4)
actionpack (= 3.1.4)
mail (~> 2.3.0)
actionpack (3.1.4)
activemodel (= 3.1.4)
activesupport (= 3.1.4)
actionmailer (3.1.10)
actionpack (= 3.1.10)
mail (~> 2.3.3)
actionpack (3.1.10)
activemodel (= 3.1.10)
activesupport (= 3.1.10)
builder (~> 3.0.0)
erubis (~> 2.7.0)
i18n (~> 0.6)
rack (~> 1.3.6)
rack-cache (~> 1.1)
rack-cache (~> 1.2)
rack-mount (~> 0.8.2)
rack-test (~> 0.6.1)
sprockets (~> 2.0.3)
activemodel (3.1.4)
activesupport (= 3.1.4)
sprockets (~> 2.0.4)
activemodel (3.1.10)
activesupport (= 3.1.10)
builder (~> 3.0.0)
i18n (~> 0.6)
activerecord (3.1.4)
activemodel (= 3.1.4)
activesupport (= 3.1.4)
activerecord (3.1.10)
activemodel (= 3.1.10)
activesupport (= 3.1.10)
arel (~> 2.2.3)
tzinfo (~> 0.3.29)
activeresource (3.1.4)
activemodel (= 3.1.4)
activesupport (= 3.1.4)
activesupport (3.1.4)
multi_json (~> 1.0)
addressable (2.2.7)
activeresource (3.1.10)
activemodel (= 3.1.10)
activesupport (= 3.1.10)
activesupport (3.1.10)
multi_json (>= 1.0, < 1.3)
arel (2.2.3)
bcrypt-ruby (3.0.1)
bson (1.5.2)
bson_ext (1.3.1)
builder (3.0.0)
builder (3.0.4)
columnize (0.3.6)
erubis (2.7.0)
faraday (0.7.6)
addressable (~> 2.2)
faraday (0.8.4)
multipart-post (~> 1.1)
rack (~> 1.1)
hashie (1.2.0)
hike (1.2.1)
i18n (0.6.0)
json (1.7.0)
httpauth (0.2.0)
i18n (0.6.1)
json (1.7.6)
jwt (0.1.5)
multi_json (>= 1.0)
linecache (0.46)
rbx-require-relative (> 0.0.4)
mail (2.3.3)
@@ -61,35 +59,39 @@ GEM
mime-types (~> 1.16)
treetop (~> 1.4.8)
metaclass (0.0.1)
mime-types (1.18)
mocha (0.10.4)
mime-types (1.19)
mocha (0.10.0)
metaclass (~> 0.0.1)
mongo (1.3.1)
bson (>= 1.3.1)
mongoid (2.4.4)
mongoid (3.0.16)
activemodel (~> 3.1)
mongo (~> 1.3)
moped (~> 1.1)
origin (~> 1.0)
tzinfo (~> 0.3.22)
multi_json (1.3.4)
moped (1.3.2)
multi_json (1.2.0)
multipart-post (1.1.5)
nokogiri (1.5.0)
oauth2 (0.5.2)
faraday (~> 0.7)
nokogiri (1.5.6)
oauth2 (0.8.0)
faraday (~> 0.8)
httpauth (~> 0.1)
jwt (~> 0.1.4)
multi_json (~> 1.0)
omniauth (1.0.2)
rack (~> 1.2)
omniauth (1.0.3)
hashie (~> 1.2)
rack
omniauth-facebook (1.2.0)
omniauth-oauth2 (~> 1.0.0)
omniauth-oauth2 (1.0.0)
oauth2 (~> 0.5.0)
omniauth-facebook (1.4.0)
omniauth-oauth2 (~> 1.0.2)
omniauth-oauth2 (1.0.3)
oauth2 (~> 0.8.0)
omniauth (~> 1.0)
omniauth-openid (1.0.1)
omniauth (~> 1.0)
rack-openid (~> 1.3.1)
orm_adapter (0.0.7)
origin (1.0.11)
orm_adapter (0.4.0)
polyglot (0.3.3)
rack (1.3.6)
rack (1.3.8)
rack-cache (1.2)
rack (>= 0.4)
rack-mount (0.8.3)
@@ -99,25 +101,25 @@ GEM
ruby-openid (>= 2.1.8)
rack-ssl (1.3.2)
rack
rack-test (0.6.1)
rack-test (0.6.2)
rack (>= 1.0)
rails (3.1.4)
actionmailer (= 3.1.4)
actionpack (= 3.1.4)
activerecord (= 3.1.4)
activeresource (= 3.1.4)
activesupport (= 3.1.4)
rails (3.1.10)
actionmailer (= 3.1.10)
actionpack (= 3.1.10)
activerecord (= 3.1.10)
activeresource (= 3.1.10)
activesupport (= 3.1.10)
bundler (~> 1.0)
railties (= 3.1.4)
railties (3.1.4)
actionpack (= 3.1.4)
activesupport (= 3.1.4)
railties (= 3.1.10)
railties (3.1.10)
actionpack (= 3.1.10)
activesupport (= 3.1.10)
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)
rake (10.0.3)
rbx-require-relative (0.0.9)
rdoc (3.12)
json (~> 1.4)
ruby-debug (0.10.4)
@@ -125,19 +127,19 @@ GEM
ruby-debug-base (~> 0.10.4.0)
ruby-debug-base (0.10.4)
linecache (>= 0.3)
ruby-openid (2.1.8)
ruby-openid (2.2.2)
sprockets (2.0.4)
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.5)
sqlite3 (1.3.6)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
treetop (1.4.12)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.33)
warden (1.1.1)
tzinfo (0.3.35)
warden (1.2.1)
rack (>= 1.0)
webrat (0.7.2)
nokogiri (>= 1.2.0)
@@ -150,12 +152,10 @@ PLATFORMS
DEPENDENCIES
activerecord-jdbc-adapter
activerecord-jdbcsqlite3-adapter
bson_ext (~> 1.3.0)
devise!
jruby-openssl
mocha
mongo (~> 1.3.0)
mongoid (~> 2.0)
mocha (= 0.10.0)
mongoid (~> 3.0)
omniauth (~> 1.0.0)
omniauth-facebook
omniauth-oauth2 (~> 1.0.0)

View File

@@ -6,11 +6,12 @@ require 'set'
require 'securerandom'
module Devise
autoload :Delegator, 'devise/delegator'
autoload :FailureApp, 'devise/failure_app'
autoload :OmniAuth, 'devise/omniauth'
autoload :ParamFilter, 'devise/param_filter'
autoload :TestHelpers, 'devise/test_helpers'
autoload :Delegator, 'devise/delegator'
autoload :FailureApp, 'devise/failure_app'
autoload :OmniAuth, 'devise/omniauth'
autoload :ParamFilter, 'devise/param_filter'
autoload :TestHelpers, 'devise/test_helpers'
autoload :TimeInflector, 'devise/time_inflector'
module Controllers
autoload :Helpers, 'devise/controllers/helpers'
@@ -86,7 +87,7 @@ module Devise
# an one (and only one) @ exists in the given string. This is mainly
# to give user feedback and not to assert the e-mail validity.
mattr_accessor :email_regexp
@@email_regexp = /\A[^@]+@([^@\.]+\.)+[^@\.]+\z/
@@email_regexp = /\A[^@\s]+@([^@\s]+\.)+[^@\s]+\z/
# Range validation for password length
mattr_accessor :password_length
@@ -104,6 +105,10 @@ module Devise
mattr_accessor :allow_unconfirmed_access_for
@@allow_unconfirmed_access_for = 0.days
# Time interval the confirmation token is valid. nil = unlimited
mattr_accessor :confirm_within
@@confirm_within = nil
# Defines which key will be used when confirming an account.
mattr_accessor :confirmation_keys
@@confirmation_keys = [ :email ]
@@ -199,7 +204,7 @@ module Devise
# to provide custom routes.
mattr_accessor :router_name
@@router_name = nil
# Set the omniauth path prefix so it can be overriden when
# Devise is used in a mountable engine
mattr_accessor :omniauth_path_prefix

View File

@@ -162,8 +162,8 @@ module Devise
users.any?
end
# Returns and delete the url stored in the session for the given scope. Useful
# for giving redirect backs after sign up:
# Returns and delete (if it's navigational format) the url stored in the session for
# the given scope. Useful for giving redirect backs after sign up:
#
# Example:
#
@@ -171,7 +171,12 @@ module Devise
#
def stored_location_for(resource_or_scope)
scope = Devise::Mapping.find_scope!(resource_or_scope)
session.delete("#{scope}_return_to")
if is_navigational_format?
session.delete("#{scope}_return_to")
else
session["#{scope}_return_to"]
end
end
# The scope root url to be used when he's signed in. By default, it first
@@ -262,6 +267,14 @@ module Devise
super # call the default behaviour which resets the session
end
def request_format
@request_format ||= request.format.try(:ref)
end
def is_navigational_format?
Devise.navigational_formats.include?(request_format)
end
private
def expire_devise_cached_variables!

View File

@@ -11,9 +11,9 @@ module Devise
protected
# Configure default email options
def devise_mail(record, action)
def devise_mail(record, action, opts={})
initialize_from_record(record)
mail headers_for(action)
mail headers_for(action, opts)
end
def initialize_from_record(record)
@@ -25,28 +25,37 @@ module Devise
@devise_mapping ||= Devise.mappings[scope_name]
end
def headers_for(action)
def headers_for(action, opts)
headers = {
:subject => translate(devise_mapping, action),
:from => mailer_sender(devise_mapping),
:subject => subject_for(action),
:to => resource.email,
:template_path => template_paths
}
:from => mailer_sender(devise_mapping),
:reply_to => mailer_reply_to(devise_mapping),
:template_path => template_paths,
:template_name => action
}.merge(opts)
if resource.respond_to?(:headers_for)
ActiveSupport::Deprecation.warn "Calling headers_for in the model is no longer supported. " <<
"Please customize your mailer instead."
headers.merge!(resource.headers_for(action))
end
unless headers.key?(:reply_to)
headers[:reply_to] = headers[:from]
end
@email = headers[:to]
headers
end
def mailer_sender(mapping)
if default_params[:from].present?
default_params[:from]
def mailer_reply_to(mapping)
mailer_sender(mapping, :reply_to)
end
def mailer_from(mapping)
mailer_sender(mapping, :from)
end
def mailer_sender(mapping, sender = :from)
if default_params[sender].present?
default_params[sender]
elsif Devise.mailer_sender.is_a?(Proc)
Devise.mailer_sender.call(mapping.name)
else
@@ -77,8 +86,8 @@ module Devise
# confirmation_instructions:
# subject: '...'
#
def translate(mapping, key)
I18n.t(:"#{mapping.name}_subject", :scope => [:devise, :mailer, key],
def subject_for(key)
I18n.t(:"#{devise_mapping.name}_subject", :scope => [:devise, :mailer, key],
:default => [:subject, key.to_s.humanize])
end
end

View File

@@ -93,10 +93,6 @@ module Devise
def authenticatable_salt
end
def headers_for(name)
{}
end
array = %w(serializable_hash)
# to_xml does not call serializable_hash on 3.1
array << "to_xml" if Rails::VERSION::STRING[0,3] == "3.1"
@@ -159,16 +155,29 @@ module Devise
# end
# end
#
def send_devise_notification(notification)
devise_mailer.send(notification, self).deliver
def send_devise_notification(notification, opts={})
devise_mailer.send(notification, self, opts).deliver
end
def downcase_keys
self.class.case_insensitive_keys.each { |k| self[k].try(:downcase!) }
self.class.case_insensitive_keys.each { |k| apply_to_attribute_or_variable(k, :downcase!) }
end
def strip_whitespace
self.class.strip_whitespace_keys.each { |k| self[k].try(:strip!) }
self.class.strip_whitespace_keys.each { |k| apply_to_attribute_or_variable(k, :strip!) }
end
def apply_to_attribute_or_variable(attr, method)
if self[attr]
self[attr].try(method)
# Use respond_to? here to avoid a regression where globally
# configured strip_whitespace_keys or case_insensitive_keys were
# attempting to strip! or downcase! when a model didn't have the
# globally configured key.
elsif respond_to?(attr)
send(attr).try(method)
end
end
module ClassMethods
@@ -199,7 +208,7 @@ module Devise
# it may be wrapped as well. For instance, database authenticatable
# provides a `find_for_database_authentication` that wraps a call to
# this method. This allows you to customize both database authenticatable
# or the whole authenticate stack by customize `find_for_authentication.`
# or the whole authenticate stack by customize `find_for_authentication.`
#
# Overwrite to add customized conditions, create a join, or maybe use a
# namedscope to filter records while authenticating.

View File

@@ -19,6 +19,8 @@ module Devise
# 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.
# * +confirm_within+: the time before a sent confirmation token becomes invalid.
# You can use this to force the user to confirm within a set period of time.
#
# == Examples
#
@@ -28,6 +30,7 @@ module Devise
#
module Confirmable
extend ActiveSupport::Concern
include ActionView::Helpers::DateHelper
included do
before_create :generate_confirmation_token, :if => :confirmation_required?
@@ -47,6 +50,12 @@ module Devise
# add errors
def confirm!
pending_any_confirmation do
if confirmation_period_expired?
self.errors.add(:email, :confirmation_period_expired,
:period => Devise::TimeInflector.time_ago_in_words(self.class.confirm_within.ago))
return false
end
self.confirmation_token = nil
self.confirmed_at = Time.now.utc
@@ -78,12 +87,17 @@ module Devise
@reconfirmation_required = false
generate_confirmation_token! if self.confirmation_token.blank?
send_devise_notification(:confirmation_instructions)
opts = pending_reconfirmation? ? { :to => unconfirmed_email } : { }
send_devise_notification(:confirmation_instructions, opts)
end
# Resend confirmation token. This method does not need to generate a new token.
def resend_confirmation_token
pending_any_confirmation { send_confirmation_instructions }
pending_any_confirmation do
self.confirmation_token = nil if confirmation_period_expired?
send_confirmation_instructions
end
end
# Overwrites active_for_authentication? for confirmation
@@ -111,14 +125,6 @@ module Devise
@bypass_postpone = true
end
def headers_for(action)
headers = super
if action == :confirmation_instructions && pending_reconfirmation?
headers[:to] = unconfirmed_email
end
headers
end
protected
# A callback method used to deliver confirmation
@@ -156,9 +162,25 @@ module Devise
confirmation_sent_at && confirmation_sent_at.utc >= self.class.allow_unconfirmed_access_for.ago
end
# Checks if the user confirmation happens before the token becomes invalid
# Examples:
#
# # confirm_within = 3.days and confirmation_sent_at = 2.days.ago
# confirmation_period_expired? # returns false
#
# # confirm_within = 3.days and confirmation_sent_at = 4.days.ago
# confirmation_period_expired? # returns true
#
# # confirm_within = nil
# confirmation_period_expired? # will always return false
#
def confirmation_period_expired?
self.class.confirm_within && (Time.now > self.confirmation_sent_at + self.class.confirm_within )
end
# Checks whether the record requires any confirmation.
def pending_any_confirmation
if !confirmed? || pending_reconfirmation?
if (!confirmed? || pending_reconfirmation?)
yield
else
self.errors.add(:email, :already_confirmed)
@@ -235,7 +257,7 @@ module Devise
find_or_initialize_with_errors(unconfirmed_required_attributes, unconfirmed_attributes, :not_found)
end
Devise::Models.config(self, :allow_unconfirmed_access_for, :confirmation_keys, :reconfirmable)
Devise::Models.config(self, :allow_unconfirmed_access_for, :confirmation_keys, :reconfirmable, :confirm_within)
end
end
end

View File

@@ -75,7 +75,7 @@ module Devise
end
# Updates record attributes without asking for the current password.
# Never allows to change the current password. If you are using this
# Never allows a change to 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.
#

View File

@@ -27,7 +27,7 @@ module Devise
def self.required_fields(klass)
attributes = []
attributes << :failed_attempts if klass.lock_strategy_enabled?(:failed_attempts)
attributes << :unlock_at if klass.unlock_strategy_enabled?(:time)
attributes << :locked_at if klass.unlock_strategy_enabled?(:time)
attributes << :unlock_token if klass.unlock_strategy_enabled?(:email)
attributes
@@ -105,7 +105,11 @@ module Devise
end
def unauthenticated_message
if lock_strategy_enabled?(:failed_attempts) && attempts_exceeded?
# If set to paranoid mode, do not show the locked message because it
# leaks the existence of an account.
if Devise.paranoid
super
elsif lock_strategy_enabled?(:failed_attempts) && attempts_exceeded?
:locked
else
super

View File

@@ -102,9 +102,9 @@ module Devise
module ClassMethods
# Attempt to find a user by its email. If a record is found, send new
# password instructions to it. If not user is found, returns a new user
# password instructions to it. If user is not found, returns a new user
# with an email not found error.
# Attributes must contain the user email
# Attributes must contain the user's email
def send_reset_password_instructions(attributes={})
recoverable = find_or_initialize_with_errors(reset_password_keys, attributes, :not_found)
recoverable.send_reset_password_instructions if recoverable.persisted?

View File

@@ -18,6 +18,18 @@ module Devise
# If you want to delete the token after it is used, you can do so in the
# after_token_authentication callback.
#
# == APIs
#
# If you are using token authentication with APIs and using trackable. Every
# request will be considered as a new sign in (since there is no session in
# APIs). You can disable this by creating a before filter as follow:
#
# before_filter :skip_trackable
#
# def skip_trackable
# request.env['devise.skip_trackable'] = true
# end
#
# == Options
#
# TokenAuthenticatable adds the following options to devise_for:

View File

@@ -20,7 +20,7 @@ module Devise
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.ip
old_current, new_current = self.current_sign_in_ip, request.remote_ip
self.last_sign_in_ip = old_current || new_current
self.current_sign_in_ip = new_current

View File

@@ -10,7 +10,7 @@ module Devise
# Validatable adds the following options to devise_for:
#
# * +email_regexp+: the regular expression used to validate e-mails;
# * +password_length+: a range expressing password length. Defaults to 6..128.
# * +password_length+: a range expressing password length. Defaults to 8..128.
#
module Validatable
# All validations used by this module.

View File

@@ -43,20 +43,20 @@ module ActionDispatch::Routing
# needed routes:
#
# # Session routes for Authenticatable (default)
# new_user_session GET /users/sign_in {:controller=>"devise/sessions", :action=>"new"}
# user_session POST /users/sign_in {:controller=>"devise/sessions", :action=>"create"}
# destroy_user_session GET /users/sign_out {:controller=>"devise/sessions", :action=>"destroy"}
# new_user_session GET /users/sign_in {:controller=>"devise/sessions", :action=>"new"}
# user_session POST /users/sign_in {:controller=>"devise/sessions", :action=>"create"}
# destroy_user_session DELETE /users/sign_out {:controller=>"devise/sessions", :action=>"destroy"}
#
# # Password routes for Recoverable, if User model has :recoverable configured
# new_user_password GET /users/password/new(.:format) {:controller=>"devise/passwords", :action=>"new"}
# edit_user_password GET /users/password/edit(.:format) {:controller=>"devise/passwords", :action=>"edit"}
# user_password PUT /users/password(.:format) {:controller=>"devise/passwords", :action=>"update"}
# POST /users/password(.:format) {:controller=>"devise/passwords", :action=>"create"}
# new_user_password GET /users/password/new(.:format) {:controller=>"devise/passwords", :action=>"new"}
# edit_user_password GET /users/password/edit(.:format) {:controller=>"devise/passwords", :action=>"edit"}
# user_password PUT /users/password(.:format) {:controller=>"devise/passwords", :action=>"update"}
# POST /users/password(.:format) {:controller=>"devise/passwords", :action=>"create"}
#
# # Confirmation routes for Confirmable, if User model has :confirmable configured
# new_user_confirmation GET /users/confirmation/new(.:format) {:controller=>"devise/confirmations", :action=>"new"}
# user_confirmation GET /users/confirmation(.:format) {:controller=>"devise/confirmations", :action=>"show"}
# POST /users/confirmation(.:format) {:controller=>"devise/confirmations", :action=>"create"}
# new_user_confirmation GET /users/confirmation/new(.:format) {:controller=>"devise/confirmations", :action=>"new"}
# user_confirmation GET /users/confirmation(.:format) {:controller=>"devise/confirmations", :action=>"show"}
# POST /users/confirmation(.:format) {:controller=>"devise/confirmations", :action=>"create"}
#
# ==== Options
#
@@ -183,7 +183,7 @@ module ActionDispatch::Routing
# end
# end
#
# In order to get Devise to recognize the deactivate action, your devise_for entry should look like this,
# In order to get Devise to recognize the deactivate action, your devise_scope entry should look like this:
#
# devise_scope :owner do
# post "deactivate", :to => "registrations#deactivate", :as => "deactivate_registration"

View File

@@ -6,7 +6,7 @@ module Devise
class DatabaseAuthenticatable < Authenticatable
def authenticate!
resource = valid_password? && mapping.to.find_for_database_authentication(authentication_hash)
return fail(:invalid) unless resource
return fail(:not_found_in_database) unless resource
if validate(resource){ resource.valid_password?(password) }
resource.after_database_authentication

View File

@@ -45,6 +45,7 @@ module Devise
def sign_in(resource_or_scope, resource=nil)
scope ||= Devise::Mapping.find_scope!(resource_or_scope)
resource ||= resource_or_scope
warden.instance_variable_get(:@users).delete(scope)
warden.session_serializer.store(resource, scope)
end
@@ -106,8 +107,8 @@ module Devise
env["warden.options"] = options
Warden::Manager._run_callbacks(:before_failure, env, options)
status, headers, body = Devise.warden_config[:failure_app].call(env).to_a
@controller.send :render, :status => status, :text => body,
status, headers, response = Devise.warden_config[:failure_app].call(env).to_a
@controller.send :render, :status => status, :text => response.body,
:content_type => headers["Content-Type"], :location => headers["Location"]
nil # causes process return @response
end

View File

@@ -0,0 +1,14 @@
require "active_support/core_ext/module/delegation"
module Devise
class TimeInflector
include ActionView::Helpers::DateHelper
class << self
attr_reader :instance
delegate :time_ago_in_words, :to => :instance
end
@instance = new
end
end

View File

@@ -1,3 +1,3 @@
module Devise
VERSION = "2.1.2".freeze
VERSION = "2.2.2".freeze
end

View File

@@ -27,7 +27,11 @@ module ActiveRecord
attr_accessible :email, :password, :password_confirmation, :remember_me
CONTENT
class_path = class_name.to_s.split("::")
class_path = if namespaced?
class_name.to_s.split("::")
else
[class_name]
end
indent_depth = class_path.size - 1
content = content.split("\n").map { |line| " " * indent_depth + line } .join("\n") << "\n"

View File

@@ -22,9 +22,6 @@ module Mongoid
## Database authenticatable
field :email, :type => String, :default => ""
field :encrypted_password, :type => String, :default => ""
validates_presence_of :email
validates_presence_of :encrypted_password
## Recoverable
field :reset_password_token, :type => String

View File

@@ -21,11 +21,15 @@ 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:
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.
5. You can copy Devise views (for customization) to your app by running:
rails g devise:views
===============================================================================

View File

@@ -92,6 +92,14 @@ Devise.setup do |config|
# the user cannot access the website without confirming his account.
# config.allow_unconfirmed_access_for = 2.days
# A period that the user is allowed to confirm their account before their
# token becomes invalid. For example, if set to 3.days, the user can confirm
# their account within 3 days after the mail was sent, but on the fourth day
# their account can't be confirmed with the token any more.
# Default is nil, meaning there is no restriction on how long a user can take
# before confirming their account.
# config.confirm_within = 3.days
# If true, requires any email changes to be confirmed (exactly 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
@@ -113,8 +121,8 @@ Devise.setup do |config|
# config.rememberable_options = {}
# ==> Configuration for :validatable
# Range for password length. Default is 6..128.
# config.password_length = 6..128
# Range for password length. Default is 8..128.
config.password_length = 8..128
# Email regex used to validate email formats. It simply asserts that
# an one (and only one) @ exists in the given string. This is mainly
@@ -125,7 +133,7 @@ Devise.setup do |config|
# The time you want to timeout the user session without activity. After this
# time the user will be asked for credentials again. Default is 30 minutes.
# config.timeout_in = 30.minutes
# If true, expires auth token on session timeout.
# config.expire_auth_token_on_timeout = false
@@ -229,4 +237,4 @@ Devise.setup do |config|
# When using omniauth, Devise cannot automatically set Omniauth path,
# so you need to do it manually. For the users scope, it would be:
# config.omniauth_path_prefix = "/my_engine/users/auth"
end
end

View File

@@ -1,4 +1,4 @@
Welcome <%= @resource.email %>!
Welcome <%= @email %>!
You can confirm your account through the link below:

View File

@@ -1,6 +1,6 @@
Hello <%= @resource.email %>!
Your account has been locked due to an excessive amount of unsuccessful sign in attempts.
Your account has been locked due to an excessive number of unsuccessful sign in attempts.
Click the link below to unlock your account:

View File

@@ -2,9 +2,10 @@
<%= simple_form_for(resource, :as => resource_name, :url => confirmation_path(resource_name), :html => { :method => :post }) do |f| %>
<%= f.error_notification %>
<%= f.full_error :confirmation_token %>
<div class="form-inputs">
<%= f.input :email, :required => true %>
<%= f.input :email, :required => true, :autofocus => true %>
</div>
<div class="form-actions">

View File

@@ -7,7 +7,7 @@
<%= f.full_error :reset_password_token %>
<div class="form-inputs">
<%= f.input :password, :label => "New password", :required => true %>
<%= f.input :password, :label => "New password", :required => true, :autofocus => true %>
<%= f.input :password_confirmation, :label => "Confirm your new password", :required => true %>
</div>

View File

@@ -4,7 +4,7 @@
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :email, :required => true %>
<%= f.input :email, :required => true, :autofocus => true %>
</div>
<div class="form-actions">

View File

@@ -5,6 +5,11 @@
<div class="form-inputs">
<%= f.input :email, :required => true, :autofocus => true %>
<% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
<p>Currently waiting confirmation for: <%= resource.unconfirmed_email %></p>
<% end %>
<%= f.input :password, :autocomplete => "off", :hint => "leave it blank if you don't want to change it", :required => false %>
<%= f.input :password_confirmation, :required => false %>
<%= f.input :current_password, :hint => "we need your current password to confirm your changes", :required => true %>

View File

@@ -2,9 +2,10 @@
<%= simple_form_for(resource, :as => resource_name, :url => unlock_path(resource_name), :html => { :method => :post }) do |f| %>
<%= f.error_notification %>
<%= f.full_error :unlock_token %>
<div class="form-inputs">
<%= f.input :email, :required => true %>
<%= f.input :email, :required => true, :autofocus => true %>
</div>
<div class="form-actions">

View File

@@ -95,6 +95,12 @@ class HelpersTest < ActionController::TestCase
assert_equal 'devise custom options', flash[:notice]
end
test 'allows custom i18n options to override resource_name' do
I18n.expects(:t).with("custom_resource_name.confirmed", anything)
@controller.stubs(:devise_i18n_options).returns(:resource_name => "custom_resource_name")
@controller.send :set_flash_message, :notice, :confirmed
end
test 'navigational_formats not returning a wild card' do
MyController.send(:public, :navigational_formats)
Devise.navigational_formats = [:"*/*", :html]

View File

@@ -13,6 +13,34 @@ class SessionsControllerTest < ActionController::TestCase
end
end
test "#create delete the url stored in the session if the requested format is navigational" do
request.env["devise.mapping"] = Devise.mappings[:user]
request.session["user_return_to"] = 'foo.bar'
user = create_user
user.confirm!
post :create, :user => {
:email => user.email,
:password => user.password
}
assert_nil request.session["user_return_to"]
end
test "#create doesn't delete the url stored in the session if the requested format is not navigational" do
request.env["devise.mapping"] = Devise.mappings[:user]
request.session["user_return_to"] = 'foo.bar'
user = create_user
user.confirm!
post :create, :format => 'json', :user => {
:email => user.email,
:password => user.password
}
assert_equal 'foo.bar', request.session["user_return_to"]
end
test "#create doesn't raise exception after Warden authentication fails when TestHelpers included" do
request.env["devise.mapping"] = Devise.mappings[:user]
post :create, :user => {
@@ -23,6 +51,20 @@ class SessionsControllerTest < ActionController::TestCase
assert_template "devise/sessions/new"
end
test "#destroy doesn't set the flash if the requested format is not navigational" do
request.env["devise.mapping"] = Devise.mappings[:user]
user = create_user
user.confirm!
post :create, :format => 'json', :user => {
:email => user.email,
:password => user.password
}
delete :destroy, :format => 'json'
assert flash[:notice].blank?, "flash[:notice] should be blank, not #{flash[:notice].inspect}"
assert_equal 204, @response.status
end
if defined?(ActiveRecord) && ActiveRecord::Base.respond_to?(:mass_assignment_sanitizer)
test "#new doesn't raise mass-assignment exception even if sign-in key is attr_protected" do
request.env["devise.mapping"] = Devise.mappings[:user]
@@ -40,4 +82,4 @@ class SessionsControllerTest < ActionController::TestCase
end
end
end
end
end

View File

@@ -68,5 +68,16 @@ class DeviseTest < ActiveSupport::TestCase
end
assert_not Devise.secure_compare("size_1", "size_four")
end
test 'Devise.email_regexp should match valid email addresses' do
valid_emails = ["test@example.com", "jo@jo.co", "f4$_m@you.com", "testing.example@example.com.ua"]
non_valid_emails = ["rex", "test@go,com", "test user@example.com", "test_user@example server.com"]
valid_emails.each do |email|
assert_match Devise.email_regexp, email
end
non_valid_emails.each do |email|
assert_no_match Devise.email_regexp, email
end
end
end

View File

@@ -14,6 +14,12 @@ if DEVISE_ORM == :active_record
assert_migration "db/migrate/devise_create_monsters.rb", /def change/
end
test "all files for namespaced model are properly created" do
run_generator %w(admin/monster)
assert_file "app/models/admin/monster.rb", /devise/, /attr_accessible (:[a-z_]+(, )?)+/
assert_migration "db/migrate/devise_create_admin_monsters.rb", /def change/
end
test "update model migration when model exists" do
run_generator %w(monster)
assert_file "app/models/monster.rb"
@@ -66,4 +72,4 @@ if DEVISE_ORM == :active_record
end
end
end
end
end

View File

@@ -1,33 +0,0 @@
require 'test_helper'
class IndifferentHashTest < ActiveSupport::TestCase
setup do
@hash = Devise::IndifferentHash.new
end
test "it overwrites getter and setter" do
@hash[:foo] = "bar"
assert_equal "bar", @hash["foo"]
assert_equal "bar", @hash[:foo]
@hash["foo"] = "baz"
assert_equal "baz", @hash["foo"]
assert_equal "baz", @hash[:foo]
end
test "it overwrites update" do
@hash.update :foo => "bar"
assert_equal "bar", @hash["foo"]
assert_equal "bar", @hash[:foo]
@hash.update "foo" => "baz"
assert_equal "baz", @hash["foo"]
assert_equal "baz", @hash[:foo]
end
test "it returns a Hash on to_hash" do
@hash[:foo] = "bar"
assert_equal Hash["foo", "bar"], @hash.to_hash
assert_kind_of Hash, @hash.to_hash
end
end if defined?(Devise::IndifferentHash)

View File

@@ -456,7 +456,7 @@ class AuthenticationOthersTest < ActionController::IntegrationTest
assert_match '<?xml version="1.0" encoding="UTF-8"?>', response.body
assert_match /<user>.*<\/user>/m, response.body
assert_match '<email></email>', response.body
assert_match '<password nil="true"></password>', response.body
assert_match '<password nil="true"', response.body
end
test 'sign in stub in json format' do
@@ -483,7 +483,7 @@ class AuthenticationOthersTest < ActionController::IntegrationTest
test 'sign in with xml format returns xml response' do
create_user
post user_session_path(:format => 'xml'), :user => {:email => "user@test.com", :password => '123456'}
post user_session_path(:format => 'xml'), :user => {:email => "user@test.com", :password => '12345678'}
assert_response :success
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
end
@@ -493,13 +493,13 @@ class AuthenticationOthersTest < ActionController::IntegrationTest
assert_response :success
create_user
post user_session_path(:format => 'xml'), :user => {:email => "user@test.com", :password => '123456'}
post user_session_path(:format => 'xml'), :user => {:email => "user@test.com", :password => '12345678'}
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'}
post user_session_path(:format => 'xml'), :user => {:email => "user@test.com", :password => '12345678'}
assert_response :success
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
end
@@ -517,6 +517,25 @@ class AuthenticationOthersTest < ActionController::IntegrationTest
assert_response :no_content
assert_not warden.authenticated?(:user)
end
test 'sign out with non-navigational format via XHR does not redirect' do
swap Devise, :navigational_formats => ['*/*', :html] do
sign_in_as_user
xml_http_request :get, destroy_user_session_path, {}, { "HTTP_ACCEPT" => "application/json,text/javascript,*/*" } # NOTE: Bug is triggered by combination of XHR and */*.
assert_response :no_content
assert_not warden.authenticated?(:user)
end
end
# Belt and braces ... Perhaps this test is not necessary?
test 'sign out with navigational format via XHR does redirect' do
swap Devise, :navigational_formats => ['*/*', :html] do
sign_in_as_user
xml_http_request :get, destroy_user_session_path, {}, { "HTTP_ACCEPT" => "text/html,*/*" }
assert_response :redirect
assert_not warden.authenticated?(:user)
end
end
end
class AuthenticationKeysTest < ActionController::IntegrationTest

View File

@@ -50,6 +50,30 @@ class ConfirmationTest < ActionController::IntegrationTest
assert user.reload.confirmed?
end
test 'user with valid confirmation token should not be able to confirm an account after the token has expired' do
swap Devise, :confirm_within => 3.days do
user = create_user(:confirm => false, :confirmation_sent_at => 4.days.ago)
assert_not user.confirmed?
visit_user_confirmation_with_token(user.confirmation_token)
assert_have_selector '#error_explanation'
assert_contain /needs to be confirmed within 3 days/
assert_not user.reload.confirmed?
end
end
test 'user with valid confirmation token should be able to confirm an account before the token has expired' do
swap Devise, :confirm_within => 3.days do
user = create_user(:confirm => false, :confirmation_sent_at => 2.days.ago)
assert_not user.confirmed?
visit_user_confirmation_with_token(user.confirmation_token)
assert_contain 'Your account was successfully confirmed.'
assert_current_url '/'
assert user.reload.confirmed?
end
end
test 'user should be redirected to a custom path after confirmation' do
Devise::ConfirmationsController.any_instance.stubs(:after_confirmation_path_for).returns("/?custom=1")
@@ -240,6 +264,26 @@ class ConfirmationOnChangeTest < ActionController::IntegrationTest
assert_not admin.reload.pending_reconfirmation?
end
test 'admin with previously valid confirmation token should not be able to confirm email after email changed again' do
admin = create_admin
admin.update_attributes(:email => 'first_test@example.com')
assert_equal 'first_test@example.com', admin.unconfirmed_email
confirmation_token = admin.confirmation_token
admin.update_attributes(:email => 'second_test@example.com')
assert_equal 'second_test@example.com', admin.unconfirmed_email
visit_admin_confirmation_with_token(confirmation_token)
assert_have_selector '#error_explanation'
assert_contain /Confirmation token(.*)invalid/
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')

View File

@@ -3,44 +3,44 @@ require 'test_helper'
class DatabaseAuthenticationTest < ActionController::IntegrationTest
test 'sign in with email of different case should succeed when email is in the list of case insensitive keys' do
create_user(:email => 'Foo@Bar.com')
sign_in_as_user do
fill_in 'email', :with => 'foo@bar.com'
end
assert warden.authenticated?(:user)
end
test 'sign in with email 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')
sign_in_as_user do
fill_in 'email', :with => 'foo@bar.com'
end
assert_not warden.authenticated?(:user)
end
end
test 'sign in with email including extra spaces should succeed when email is in the list of strip whitespace keys' do
create_user(:email => ' foo@bar.com ')
sign_in_as_user do
fill_in 'email', :with => 'foo@bar.com'
end
assert warden.authenticated?(:user)
end
test 'sign in with email including extra spaces should fail when email is NOT the list of strip whitespace keys' do
swap Devise, :strip_whitespace_keys => [] do
create_user(:email => 'foo@bar.com')
sign_in_as_user do
fill_in 'email', :with => ' foo@bar.com '
end
assert_not warden.authenticated?(:user)
end
end
@@ -53,12 +53,14 @@ class DatabaseAuthenticationTest < ActionController::IntegrationTest
end
test 'sign in with invalid email should return to sign in form with error message' do
sign_in_as_admin do
fill_in 'email', :with => 'wrongemail@test.com'
end
store_translations :en, :devise => { :failure => { :admin => { :not_found_in_database => 'Invalid email address' } } } do
sign_in_as_admin do
fill_in 'email', :with => 'wrongemail@test.com'
end
assert_contain 'Invalid email or password'
assert_not warden.authenticated?(:admin)
assert_contain 'Invalid email address'
assert_not warden.authenticated?(:admin)
end
end
test 'sign in with invalid pasword should return to sign in form with error message' do
@@ -79,4 +81,4 @@ class DatabaseAuthenticationTest < ActionController::IntegrationTest
assert_contain 'Invalid credentials'
end
end
end
end

View File

@@ -4,7 +4,7 @@ class HttpAuthenticationTest < ActionController::IntegrationTest
test 'handles unverified requests gets rid of caches but continues signed in' do
swap UsersController, :allow_forgery_protection => true do
create_user
post exhibit_user_url(1), {}, "HTTP_AUTHORIZATION" => "Basic #{Base64.encode64("user@test.com:123456")}"
post exhibit_user_url(1), {}, "HTTP_AUTHORIZATION" => "Basic #{Base64.encode64("user@test.com:12345678")}"
assert warden.authenticated?(:user)
assert_equal "User is authenticated", response.body
end
@@ -82,7 +82,7 @@ class HttpAuthenticationTest < ActionController::IntegrationTest
private
def sign_in_as_new_user_with_http(username="user@test.com", password="123456")
def sign_in_as_new_user_with_http(username="user@test.com", password="12345678")
user = create_user
get users_path(:format => :xml), {}, "HTTP_AUTHORIZATION" => "Basic #{Base64.encode64("#{username}:#{password}")}"
user
@@ -91,7 +91,7 @@ class HttpAuthenticationTest < ActionController::IntegrationTest
# Sign in with oauth2 token. This is just to test that it isn't misinterpreted as basic authentication
def add_oauth2_header
user = create_user
get users_path(:format => :xml), {}, "HTTP_AUTHORIZATION" => "OAuth #{Base64.encode64("#{user.email}:123456")}"
get users_path(:format => :xml), {}, "HTTP_AUTHORIZATION" => "OAuth #{Base64.encode64("#{user.email}:12345678")}"
end
end

View File

@@ -221,4 +221,22 @@ class LockTest < ActionController::IntegrationTest
end
end
test "in paranoid mode, when locking a user that exists it should not say that the user was locked" do
swap Devise, :paranoid => true, :maximum_attempts => 1 do
user = create_user(:locked => false)
visit new_user_session_path
fill_in 'email', :with => user.email
fill_in 'password', :with => "abadpassword"
click_button 'Sign in'
fill_in 'email', :with => user.email
fill_in 'password', :with => "abadpassword"
click_button 'Sign in'
assert_current_url "/users/sign_in"
assert_not_contain "locked"
end
end
end

View File

@@ -61,8 +61,8 @@ class OmniauthableIntegrationTest < ActionController::IntegrationTest
assert_difference "User.count" do
visit "/users/sign_up"
fill_in "Password", :with => "123456"
fill_in "Password confirmation", :with => "123456"
fill_in "Password", :with => "12345678"
fill_in "Password confirmation", :with => "12345678"
click_button "Sign up"
end

View File

@@ -190,15 +190,43 @@ class PasswordTest < ActionController::IntegrationTest
assert warden.authenticated?(:user)
end
test 'does not sign in user automatically after changing its password if it\'s locked' do
user = create_user(:locked => true)
request_forgot_password
reset_password :reset_password_token => user.reload.reset_password_token
test 'does not sign in user automatically after changing its password if it\'s locked and unlock strategy is :none or :time' do
[:none, :time].each do |strategy|
swap Devise, :unlock_strategy => strategy do
user = create_user(:locked => true)
request_forgot_password
reset_password :reset_password_token => user.reload.reset_password_token
assert_contain 'Your password was changed successfully.'
assert_not_contain 'You are now signed in.'
assert_equal new_user_session_path, @request.path
assert !warden.authenticated?(:user)
assert_contain 'Your password was changed successfully.'
assert_not_contain 'You are now signed in.'
assert_equal new_user_session_path, @request.path
assert !warden.authenticated?(:user)
end
end
end
test 'unlocks and signs in locked user automatically after changing it\'s password if unlock strategy is :email' do
swap Devise, :unlock_strategy => :email do
user = create_user(:locked => true)
request_forgot_password
reset_password :reset_password_token => user.reload.reset_password_token
assert_contain 'Your password was changed successfully.'
assert !user.reload.access_locked?
assert warden.authenticated?(:user)
end
end
test 'unlocks and signs in locked user automatically after changing it\'s password if unlock strategy is :both' do
swap Devise, :unlock_strategy => :both do
user = create_user(:locked => true)
request_forgot_password
reset_password :reset_password_token => user.reload.reset_password_token
assert_contain 'Your password was changed successfully.'
assert !user.reload.access_locked?
assert warden.authenticated?(:user)
end
end
test 'sign in user automatically and confirm after changing its password if it\'s not confirmed' do

View File

@@ -144,7 +144,7 @@ class RegistrationTest < ActionController::IntegrationTest
get edit_user_registration_path
fill_in 'email', :with => 'user.new@example.com'
fill_in 'current password', :with => '123456'
fill_in 'current password', :with => '12345678'
click_button 'Update'
assert_current_url '/'
@@ -157,9 +157,9 @@ class RegistrationTest < ActionController::IntegrationTest
sign_in_as_user
get edit_user_registration_path
fill_in 'password', :with => '12345678'
fill_in 'password confirmation', :with => '12345678'
fill_in 'current password', :with => '123456'
fill_in 'password', :with => '1234567890'
fill_in 'password confirmation', :with => '1234567890'
fill_in 'current password', :with => '12345678'
click_button 'Update'
assert_contain 'You updated your account successfully.'
@@ -186,15 +186,15 @@ class RegistrationTest < ActionController::IntegrationTest
sign_in_as_user
get edit_user_registration_path
fill_in 'password', :with => 'pas123'
fill_in 'password confirmation', :with => 'pas123'
fill_in 'current password', :with => '123456'
fill_in 'password', :with => 'pass1234'
fill_in 'password confirmation', :with => 'pass1234'
fill_in 'current password', :with => '12345678'
click_button 'Update'
assert_current_url '/'
assert_contain 'You updated your account successfully.'
assert User.first.valid_password?('pas123')
assert User.first.valid_password?('pass1234')
end
test 'a signed in user should not be able to edit his password with invalid confirmation' do
@@ -203,7 +203,7 @@ class RegistrationTest < ActionController::IntegrationTest
fill_in 'password', :with => 'pas123'
fill_in 'password confirmation', :with => ''
fill_in 'current password', :with => '123456'
fill_in 'current password', :with => '12345678'
click_button 'Update'
assert_contain "Password doesn't match confirmation"
@@ -214,7 +214,7 @@ class RegistrationTest < ActionController::IntegrationTest
sign_in_as_user
get edit_user_registration_path
click_link "Cancel my account", :method => :delete
click_button "Cancel my account"
assert_contain "Bye! Your account was successfully cancelled. We hope to see you again soon."
assert User.all.empty?
@@ -272,7 +272,7 @@ class RegistrationTest < ActionController::IntegrationTest
test 'a user update information with valid data in XML format should return valid response' do
user = sign_in_as_user
put user_registration_path(:format => 'xml'), :user => { :current_password => '123456', :email => 'user.new@test.com' }
put user_registration_path(:format => 'xml'), :user => { :current_password => '12345678', :email => 'user.new@test.com' }
assert_response :success
assert_equal user.reload.email, 'user.new@test.com'
end
@@ -303,8 +303,10 @@ class ReconfirmableRegistrationTest < ActionController::IntegrationTest
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
assert_equal "admin.new@example.com", Admin.first.unconfirmed_email
get edit_admin_registration_path
assert_contain 'Currently waiting confirmation for: admin.new@example.com'
end
test 'a signed in admin should not see a reconfirmation message if they did not change their password' do
@@ -321,4 +323,25 @@ class ReconfirmableRegistrationTest < ActionController::IntegrationTest
assert Admin.first.valid_password?('pas123')
end
end
test 'a signed in admin should not see a reconfirmation message if he did not change his email, despite having an unconfirmed email' 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'
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_equal "admin.new@example.com", Admin.first.unconfirmed_email
assert Admin.first.valid_password?('pas123')
end
end

View File

@@ -50,6 +50,13 @@ class ConfirmationInstructionsTest < ActionMailer::TestCase
assert_equal ['test@example.com'], mail.reply_to
end
test 'setup reply to as different if set in defaults' do
Devise.mailer = 'Users::ReplyToMailer'
assert_equal ['custom@example.com'], mail.from
assert_equal ['custom_reply_to@example.com'], mail.reply_to
end
test 'setup subject from I18n' do
store_translations :en, :devise => { :mailer => { :confirmation_instructions => { :subject => 'Account Confirmation' } } } do
assert_equal 'Account Confirmation', mail.subject

View File

@@ -235,6 +235,40 @@ class ConfirmableTest < ActiveSupport::TestCase
assert_equal "can't be blank", confirm_user.errors[:username].join
end
end
def confirm_user_by_token_with_confirmation_sent_at(confirmation_sent_at)
user = create_user
user.update_attribute(:confirmation_sent_at, confirmation_sent_at)
confirmed_user = User.confirm_by_token(user.confirmation_token)
assert_equal confirmed_user, user
user.reload.confirmed?
end
test 'should accept confirmation email token even after 5 years when no expiration is set' do
assert confirm_user_by_token_with_confirmation_sent_at(5.years.ago)
end
test 'should accept confirmation email token after 2 days when expiration is set to 3 days' do
swap Devise, :confirm_within => 3.days do
assert confirm_user_by_token_with_confirmation_sent_at(2.days.ago)
end
end
test 'should not accept confirmation email token after 4 days when expiration is set to 3 days' do
swap Devise, :confirm_within => 3.days do
assert_not confirm_user_by_token_with_confirmation_sent_at(4.days.ago)
end
end
test 'should generate a new token if the previous one has expired' do
swap Devise, :confirm_within => 3.days do
user = create_user
user.update_attribute(:confirmation_sent_at, 4.days.ago)
old = user.confirmation_token
user.resend_confirmation_token
assert_not_equal user.confirmation_token, old
end
end
end
class ReconfirmableTest < ActiveSupport::TestCase
@@ -260,7 +294,6 @@ class ReconfirmableTest < ActiveSupport::TestCase
assert_nil admin.confirmation_token
end
test 'should regenerate confirmation token after changing email' do
admin = create_admin
assert admin.confirm!
@@ -276,6 +309,7 @@ class ReconfirmableTest < ActiveSupport::TestCase
assert_email_sent "new_test@example.com" do
assert admin.update_attributes(:email => 'new_test@example.com')
end
assert_match "new_test@example.com", ActionMailer::Base.deliveries.last.body.encoded
end
test 'should not send confirmation by email after changing password' do

View File

@@ -1,4 +1,5 @@
require 'test_helper'
require 'test_models'
require 'digest/sha1'
class DatabaseAuthenticatableTest < ActiveSupport::TestCase
@@ -12,6 +13,17 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
assert_equal email.downcase, user.email
end
test 'should downcase case insensitive keys that refer to virtual attributes when saving' do
email = 'Foo@Bar1.com'
confirmation = 'Foo@Bar1.com'
attributes = valid_attributes(:email => email, :email_confirmation => confirmation)
user = UserWithVirtualAttributes.new(attributes)
assert_equal confirmation, user.email_confirmation
user.save!
assert_equal confirmation.downcase, user.email_confirmation
end
test 'should remove whitespace from strip whitespace keys when saving' do
# strip_whitespace_keys is set to :email by default.
email = ' foo@bar.com '
@@ -22,6 +34,18 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
assert_equal email.strip, user.email
end
test "doesn't throw exception when globally configured strip_whitespace_keys are not present on a model" do
swap Devise, :strip_whitespace_keys => [:fake_key] do
assert_nothing_raised { create_user }
end
end
test "doesn't throw exception when globally configured case_insensitive_keys are not present on a model" do
swap Devise, :case_insensitive_keys => [:fake_key] do
assert_nothing_raised { create_user }
end
end
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 = Devise::ParamFilter.new([], []).filter(conditions)
@@ -66,14 +90,14 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
test 'should test for a valid password' do
user = create_user
assert user.valid_password?('123456')
assert user.valid_password?('12345678')
assert_not user.valid_password?('654321')
end
test 'should not raise error with an empty password' do
user = create_user
user.encrypted_password = ''
assert_nothing_raised { user.valid_password?('123456') }
assert_nothing_raised { user.valid_password?('12345678') }
end
test 'should be an invalid password if the user has an empty password' do
@@ -88,31 +112,31 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
test 'should update password with valid current password' do
user = create_user
assert user.update_with_password(:current_password => '123456',
:password => 'pass321', :password_confirmation => 'pass321')
assert user.reload.valid_password?('pass321')
assert user.update_with_password(:current_password => '12345678',
:password => 'pass4321', :password_confirmation => 'pass4321')
assert user.reload.valid_password?('pass4321')
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')
assert user.update_with_password(:current_password => '12345678',
:password => 'pass4321', :password_confirmation => 'pass4321', :as => :admin)
assert user.reload.valid_password?('pass4321')
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',
:password => 'pass321', :password_confirmation => 'pass321')
assert user.reload.valid_password?('123456')
:password => 'pass4321', :password_confirmation => 'pass4321')
assert user.reload.valid_password?('12345678')
assert_match "is invalid", user.errors[:current_password].join
end
test 'should add an error to current password when it is blank' do
user = create_user
assert_not user.update_with_password(:password => 'pass321',
:password_confirmation => 'pass321')
assert user.reload.valid_password?('123456')
assert_not user.update_with_password(:password => 'pass4321',
:password_confirmation => 'pass4321')
assert user.reload.valid_password?('12345678')
assert_match "can't be blank", user.errors[:current_password].join
end
@@ -127,21 +151,21 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
test 'should ignore password and its confirmation if they are blank' do
user = create_user
assert user.update_with_password(:current_password => '123456', :email => "new@example.com")
assert user.update_with_password(:current_password => '12345678', :email => "new@example.com")
assert_equal "new@example.com", user.email
end
test 'should not update password with invalid confirmation' do
user = create_user
assert_not user.update_with_password(:current_password => '123456',
:password => 'pass321', :password_confirmation => 'other')
assert user.reload.valid_password?('123456')
assert_not user.update_with_password(:current_password => '12345678',
:password => 'pass4321', :password_confirmation => 'other')
assert user.reload.valid_password?('12345678')
end
test 'should clean up password fields on failure' do
user = create_user
assert_not user.update_with_password(:current_password => '123456',
:password => 'pass321', :password_confirmation => 'other')
assert_not user.update_with_password(:current_password => '12345678',
:password => 'pass4321', :password_confirmation => 'other')
assert user.password.blank?
assert user.password_confirmation.blank?
end
@@ -160,9 +184,9 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
test 'should not update password without password' do
user = create_user
user.update_without_password(:password => 'pass321', :password_confirmation => 'pass321')
assert !user.reload.valid_password?('pass321')
assert user.valid_password?('123456')
user.update_without_password(:password => 'pass4321', :password_confirmation => 'pass4321')
assert !user.reload.valid_password?('pass4321')
assert user.valid_password?('12345678')
end
test 'downcase_keys with validation' do
@@ -186,4 +210,4 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
]
end
end
end
end

View File

@@ -232,19 +232,19 @@ class LockableTest < ActiveSupport::TestCase
swap Devise, :lock_strategy => :failed_attempts do
assert_same_content Devise::Models::Lockable.required_fields(User), [
:failed_attempts,
:unlock_at,
:locked_at,
:unlock_token
]
end
end
end
test 'required_fields should contain only failed_attempts and unlock_at when the strategies are time and failed_attempts are enabled' do
test 'required_fields should contain only failed_attempts and locked_at when the strategies are time and failed_attempts are enabled' do
swap Devise, :unlock_strategy => :time do
swap Devise, :lock_strategy => :failed_attempts do
assert_same_content Devise::Models::Lockable.required_fields(User), [
:failed_attempts,
:unlock_at
:locked_at
]
end
end
@@ -260,4 +260,14 @@ class LockableTest < ActiveSupport::TestCase
end
end
end
test 'should not return a locked unauthenticated message if in paranoid mode' do
swap Devise, :paranoid => :true do
user = create_user
user.failed_attempts = Devise.maximum_attempts + 1
user.lock_access!
assert_equal :invalid, user.unauthenticated_message
end
end
end

View File

@@ -21,7 +21,8 @@ class SerializableTest < ActiveSupport::TestCase
end
test 'should not include unsafe keys on JSON' do
assert_equal %w(created_at email facebook_token id updated_at username), from_json().keys.sort
keys = from_json().keys.select{ |key| !key.include?("id") }
assert_equal %w(created_at email facebook_token updated_at username), keys.sort
end
test 'should not include unsafe keys on JSON even if a new except is provided' do

View File

@@ -1,26 +1,5 @@
require 'test_helper'
class Configurable < User
devise :database_authenticatable, :confirmable, :rememberable, :timeoutable, :lockable,
:stretches => 15, :pepper => 'abcdef', :allow_unconfirmed_access_for => 5.days,
:remember_for => 7.days, :timeout_in => 15.minutes, :unlock_in => 10.days
end
class WithValidation < Admin
devise :database_authenticatable, :validatable, :password_length => 2..6
end
class UserWithValidation < User
validates_presence_of :username
end
class Several < Admin
devise :validatable
devise :lockable
end
class Inheritable < Admin
end
require 'test_models'
class ActiveRecordTest < ActiveSupport::TestCase
def include_module?(klass, mod)

View File

@@ -1,14 +1,13 @@
require 'mongoid/version'
Mongoid.configure do |config|
config.master = Mongo::Connection.new('127.0.0.1', 27017).db("devise-test-suite")
config.connect_to("devise-test-suite")
config.use_utc = true
config.include_root_in_json = true
end
class ActiveSupport::TestCase
setup do
User.delete_all
Admin.delete_all
Mongoid.purge!
end
end

View File

@@ -5,4 +5,5 @@ class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :current_user, :unless => :devise_controller?
before_filter :authenticate_user!, :if => :devise_controller?
respond_to *Mime::SET.map(&:to_sym)
end

View File

@@ -1,3 +1,8 @@
class Users::Mailer < Devise::Mailer
default :from => 'custom@example.com'
default :from => 'custom@example.com'
end
class Users::ReplyToMailer < Devise::Mailer
default :from => 'custom@example.com'
default :reply_to => 'custom_reply_to@example.com'
end

View File

@@ -6,8 +6,8 @@ class Admin
include SharedAdmin
## Database authenticatable
field :email, :type => String, :null => true
field :encrypted_password, :type => String, :null => true
field :email, :type => String
field :encrypted_password, :type => String
## Recoverable
field :reset_password_token, :type => String
@@ -24,4 +24,6 @@ class Admin
## Lockable
field :locked_at, :type => Time
field :active, :type => Boolean, :default => false
end

View File

@@ -7,13 +7,13 @@ module Shim
end
module ClassMethods
def last(options={})
def last(options = {})
options.delete(:order) if options[:order] == "id"
super(options)
where(options).last
end
def find_by_email(email)
first(:conditions => { :email => email })
find_by(:email => email)
end
end

View File

@@ -9,8 +9,8 @@ class User
field :facebook_token, :type => String
## Database authenticatable
field :email, :type => String, :null => false, :default => ""
field :encrypted_password, :type => String, :null => false, :default => ""
field :email, :type => String, :default => ""
field :encrypted_password, :type => String, :default => ""
## Recoverable
field :reset_password_token, :type => String

View File

@@ -85,8 +85,8 @@ Devise.setup do |config|
# config.extend_remember_period = false
# ==> Configuration for :validatable
# Range for password length. Default is 6..128.
# config.password_length = 6..128
# Range for password length. Default is 8..128.
# config.password_length = 8..128
# Regex to use to validate the email address
# config.email_regexp = /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i

View File

@@ -7,7 +7,7 @@ module SharedUser
:trackable, :validatable, :omniauthable
attr_accessor :other_key
attr_accessible :username, :email, :password, :password_confirmation, :remember_me
attr_accessible :username, :email, :password, :password_confirmation, :remember_me, :confirmation_sent_at
# They need to be included after Devise is called.
extend ExtendMethods

View File

@@ -25,8 +25,8 @@ class ActiveSupport::TestCase
def valid_attributes(attributes={})
{ :username => "usertest",
:email => generate_unique_email,
:password => '123456',
:password_confirmation => '123456' }.update(attributes)
:password => '12345678',
:password_confirmation => '12345678' }.update(attributes)
end
def new_user(attributes={})

View File

@@ -10,10 +10,11 @@ class ActionDispatch::IntegrationTest
user = User.create!(
:username => 'usertest',
:email => options[:email] || 'user@test.com',
:password => options[:password] || '123456',
:password_confirmation => options[:password] || '123456',
:password => options[:password] || '12345678',
:password_confirmation => options[:password] || '12345678',
:created_at => Time.now.utc
)
user.update_attribute(:confirmation_sent_at, options[:confirmation_sent_at]) if options[:confirmation_sent_at]
user.confirm! unless options[:confirm] == false
user.lock_access! if options[:locked] == true
user
@@ -36,7 +37,7 @@ class ActionDispatch::IntegrationTest
user = create_user(options)
visit_with_option options[:visit], new_user_session_path
fill_in 'email', :with => options[:email] || 'user@test.com'
fill_in 'password', :with => options[:password] || '123456'
fill_in 'password', :with => options[:password] || '12345678'
check 'remember me' if options[:remember_me] == true
yield if block_given?
click_button 'Sign In'

View File

@@ -9,7 +9,7 @@ class TestHelpersTest < ActionController::TestCase
self.status = 306
end
end
test "redirects if attempting to access a page unauthenticated" do
get :index
assert_redirected_to new_user_session_path
@@ -47,6 +47,18 @@ class TestHelpersTest < ActionController::TestCase
assert_response :success
end
test "does not redirect with valid user after failed first attempt" do
get :index
assert_response :redirect
user = create_user
user.confirm!
sign_in user
get :index
assert_response :success
end
test "redirects if valid user signed out" do
user = create_user
user.confirm!
@@ -58,7 +70,7 @@ class TestHelpersTest < ActionController::TestCase
get :index
assert_redirected_to new_user_session_path
end
test "respects custom failure app" do
begin
Devise.warden_config.failure_app = CustomFailureApp
@@ -69,6 +81,11 @@ class TestHelpersTest < ActionController::TestCase
end
end
test "returns the body of a failure app" do
get :index
assert_equal response.body, "<html><body>You are being <a href=\"http://test.host/users/sign_in\">redirected</a>.</body></html>"
end
test "defined Warden after_authentication callback should not be called when sign_in is called" do
begin
Warden::Manager.after_authentication do |user, auth, opts|

27
test/test_models.rb Normal file
View File

@@ -0,0 +1,27 @@
class Configurable < User
devise :database_authenticatable, :confirmable, :rememberable, :timeoutable, :lockable,
:stretches => 15, :pepper => 'abcdef', :allow_unconfirmed_access_for => 5.days,
:remember_for => 7.days, :timeout_in => 15.minutes, :unlock_in => 10.days
end
class WithValidation < Admin
devise :database_authenticatable, :validatable, :password_length => 2..6
end
class UserWithValidation < User
validates_presence_of :username
end
class UserWithVirtualAttributes < User
devise :case_insensitive_keys => [ :email, :email_confirmation ]
validates :email, :presence => true, :confirmation => {:on => :create}
attr_accessible :email, :email_confirmation
end
class Several < Admin
devise :validatable
devise :lockable
end
class Inheritable < Admin
end