Compare commits

...

337 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
José Valim
174c2903d7 Release 2.1.2 2012-06-19 11:27:30 +02:00
José Valim
1f4c8e39f8 Revert "Thor fixes were sent upstream"
Actually, we need to wait for a new rails release, le sigh.

This reverts commit 3caab6d2ea.
2012-06-18 15:18:33 +02:00
José Valim
3caab6d2ea Thor fixes were sent upstream 2012-06-18 15:06:06 +02:00
José Valim
4e5a9bd600 Workaround thor bug /cc @wycats 2012-06-18 13:44:43 +02:00
José Valim
fef34d360b Merge pull request #1924 from calmyournerves/patch-1
fixed typo "Depreation" -> "Deprecation"
2012-06-16 11:00:38 -07:00
calmyournerves
05ddd9c204 fixed typo "Depreation" -> "Deprecation" 2012-06-16 20:51:56 +03:00
José Valim
ba2e44c6a4 Release 2.1.1 2012-06-16 15:57:17 +02:00
José Valim
4f07ed42e3 Lock warden on sign out 2012-06-16 15:21:48 +02:00
José Valim
66716023e4 Disable storage on CSRF 2012-06-16 14:51:37 +02:00
José Valim
4bc2ff997a Timeout does not explode when reset_authentication_token! is accidentally defined by Active Model 2012-06-16 14:04:34 +02:00
José Valim
b1633f2454 Delegate omniauth_authorize_path to the router, closes #1843 2012-06-16 13:43:11 +02:00
José Valim
41a91188f5 Do not trigger timeout on sign in related actions 2012-06-16 13:24:07 +02:00
José Valim
4def600076 Mark some methods as private 2012-06-16 13:06:52 +02:00
José Valim
18a18e4c72 Provide a send_devise_notification hook 2012-06-16 13:00:51 +02:00
José Valim
85c90671bc Update CHANGELOG 2012-06-16 12:38:02 +02:00
José Valim
16b688eced Merge pull request #1922 from excid3/master
Flexible routing scopes
2012-06-15 11:21:21 -07:00
Chris Oliver
37c55eb192 Added tests for flexible routing constraints 2012-06-15 13:06:29 -05:00
Chris Oliver
2d7dc3e82d Merge branch 'master' of git://github.com/plataformatec/devise 2012-06-15 11:05:58 -05:00
Chris Oliver
e7a8a7247c Switch and, or to &&, || 2012-06-15 08:45:44 -05:00
José Valim
c4818a9fb2 Reorganize tests slightly 2012-06-15 11:15:03 +02:00
Chris Oliver
8c2a7146df Add scope into warden user access 2012-06-15 02:10:42 -05:00
Chris Oliver
311e3206c9 Added block to authenticate route as well 2012-06-15 00:12:09 -05:00
Chris Oliver
6ad6b3d2a6 Allow passing a block to the authenticated route 2012-06-14 23:54:12 -05:00
Carlos Galdino
471a05fd59 Merge pull request #1921 from nashby/data-confirm
use data-confirm option as :confirm was deprecated in rails 3.2.6
2012-06-14 12:50:02 -07:00
Vasiliy Ermolovich
7a12655111 use data-confirm option as :confirm was deprecated in rails 3.2.6
SimpleForm templates
2012-06-14 22:48:37 +03:00
Rafael Mendonça França
1b26869b74 Merge pull request #1920 from nashby/data-confirm
use data-confirm option as :confirm was deprecated in rails 3.2.6
2012-06-14 12:35:30 -07:00
Vasiliy Ermolovich
13f35d80a9 use data-confirm option as :confirm was deprecated in rails 3.2.6 2012-06-14 22:27:40 +03:00
José Valim
1c4faa7d8a Depend on latest orm adapter 2012-06-13 15:07:24 +02:00
José Valim
c26ed53927 Merge pull request #1908 from mhfs/lockable_async_fix
Persist unlock token before triggering mailer
2012-06-11 14:09:24 -07:00
Marcelo Silveira
fe0f6e96b3 Persist unlock token before triggering mailer 2012-06-11 17:52:10 -03:00
José Valim
6dd7ccee68 Add more docs, remove 3.0 related code, update CHANGELOG 2012-06-08 19:22:14 +02:00
José Valim
9327cf8af5 Merge pull request #1903 from zamith/master
Routes for engines
2012-06-08 10:05:56 -07:00
Zamith
512b52e23a Adding option to change omniauth path prefix 2012-06-08 17:50:33 +01:00
José Valim
5df7105301 Merge pull request #1902 from gbataille/master
Redirect to sign_in page when trying to access password#edit without a reset password token
2012-06-08 01:19:05 -07:00
Gregory Bataille
a84fdb771f Merge branches 'master' and 'no_token' 2012-06-08 10:08:50 +02:00
Gregory Bataille
ff75341c75 Redirect to sign in page when trying to access password#edit without a
reset_password_token (i.e. not coming from a reset password email)
2012-06-08 10:08:35 +02:00
Carlos Antonio da Silva
f0d48a96ca Fix rdoc rake task [ci skip] 2012-06-07 22:48:15 -03:00
José Valim
215fdf119e Better error message when mapping can't be found 2012-06-07 14:34:13 +03:00
José Valim
985b646ee1 Update README.md, closes #1895 2012-06-07 14:31:43 +03:00
José Valim
622e480c4b Merge pull request #1892 from clody69/master
Fixed User model generation for Mongoid
2012-06-07 01:09:54 -07:00
José Valim
2e78a46c52 Merge pull request #1896 from Antiarchitect/patch-1
In addition to #1722. expire_auth_token_on_timeout added to Timeoutable configuration block.
2012-06-07 01:09:05 -07:00
Andrey Voronkov
b1b6e53d6f In addition to #1722. expire_auth_token_on_timeout added to Timeoutable configuration block. 2012-06-07 09:32:44 +04:00
José Valim
65325f7f81 Merge pull request #1894 from wtn/master
#update_with_password should use mass assignment options when password is not valid
2012-06-05 01:15:51 -07:00
William T Nelson
9bd82e5a24 use mass assignment options when password is not valid 2012-06-04 22:52:09 -05:00
Claudio Riva
0689b4558e Update master 2012-06-03 22:24:31 +03:00
Rafael Mendonça França
dbea934701 Update README.md [ci skip] 2012-05-29 17:28:57 -03:00
Rafael Mendonça França
8e4d5fb38f Merge pull request #1882 from GeekOnCoffee/patch-1
URLs that aren't links aren't nice
2012-05-29 13:26:56 -07:00
Andrew Hooker
e324ee9823 URLs that aren't links aren't nice 2012-05-29 15:24:34 -05:00
José Valim
54e9cabf5d Update README.md 2012-05-29 16:46:58 +03:00
José Valim
7a3f6fb53d Merge pull request #1880 from brynary/codeclimate-badge
Add Code Climate badge to README
2012-05-29 05:54:49 -07:00
Bryan Helmkamp
59a9576498 Add Code Climate badge to README 2012-05-29 08:46:48 -04:00
José Valim
57eb3886ba Refactor router.rb a bit based on Code Climate feedback: https://codeclimate.com/github/plataformatec/devise/Devise 2012-05-29 11:29:09 +02:00
Rafael Mendonça França
fe9e6db0e2 Merge pull request #1876 from shaliko/master
Remove not used variables
2012-05-26 09:36:30 -07:00
Shaliko Usubov
db8eeb6c6e Remove not used variables 2012-05-26 20:31:42 +04:00
José Valim
2b7328535d Check for the request before checking for the mapping, closes #1859 2012-05-25 09:39:50 +02:00
José Valim
d4e5424360 Simplify validation logic inside strategies 2012-05-22 14:10:06 +02:00
José Valim
d67d992749 Merge pull request #1865 from nirvdrum/patch-1
Simple compose VS comprise grammar fix.
2012-05-21 03:33:57 -07:00
Kevin Menard
b6c7aafe55 Simple compose VS comprise grammar fix. 2012-05-20 23:04:53 -03:00
José Valim
9829384829 Merge pull request #1864 from nashby/update-views
use implicit partials rendering and update simple_form templates
2012-05-20 12:17:19 -07:00
Vasiliy Ermolovich
1d79c1982a use implicit partials rendering
make simple_form templates consistent with templates
that generates by simple_form itself

612c0067cf
2012-05-20 22:01:11 +03:00
José Valim
f6259531c3 Update CHANGELOG.rdoc 2012-05-17 13:25:07 +03:00
José Valim
ed03039d19 Merge pull request #1857 from pomnikita/master
Remove devise/schema from autoloads
2012-05-17 02:27:30 -07:00
Nikita Pomyashchiy
b6abc4623b Remove autoload of deprecated devise/schema 2012-05-17 13:13:19 +04:00
Carlos Antonio da Silva
d1949b7b42 Fix indent, remove not used variable 2012-05-15 17:22:52 -03:00
Carlos Antonio da Silva
b6e30427a3 Pass the block argument straight to the assertion methods in test helpers 2012-05-15 17:19:21 -03:00
Carlos Antonio da Silva
96e0dcf5d5 Remove not used variable, fix indent 2012-05-15 17:14:05 -03:00
Carlos Antonio da Silva
ab48435211 Remove warning with shadowing variable 2012-05-15 15:27:46 -03:00
Carlos Antonio da Silva
8bcb05d6c0 Cache constant on check fields 2012-05-15 15:20:01 -03:00
Carlos Antonio da Silva
6b363d6af9 Build only one model instance for checking fields 2012-05-15 15:12:18 -03:00
Carlos Antonio da Silva
2fd2a8662d Define the accessor right away instead of open + send 2012-05-15 15:05:21 -03:00
Rodrigo Flores
f1db0809b1 Bumping to 2.1.0 2012-05-15 14:14:41 -03:00
Rodrigo Flores
30ca072f50 Fixing README to reflect 2.1.0 release 2012-05-15 14:14:40 -03:00
José Valim
85ea53198a Merge pull request #1853 from adzap/master
Add resource_params controller method as helper to allow overriding params used to build resource
2012-05-15 01:21:18 -07:00
Adam Meehan
7ec4c1424d Add resource_params internal helper to param filtering
In light of recent discussions around mass assignment security and
the alternate solution of using the controller to filter params, not the model,
a hook/helper is needed to be able to override how the params are filtered
before they are used to build the resource.
2012-05-15 18:07:02 +10:00
Rodrigo Flores
f95513e86b Merge branch 'asanghi-fixes' 2012-05-14 17:53:52 -03:00
Rodrigo Flores
8baacecdcf Fixing tests 2012-05-14 17:53:34 -03:00
Aditya Sanghi
ff6e30cec4 Minor updates suggested to default language in locales. Be consistent with "email" and "e-mail"; email address exists "in" our database not "on" our database. 2012-05-14 17:44:51 -03:00
Rodrigo Flores
308275c8a8 Fixing a phrase on README 2012-05-14 10:37:30 -03:00
Rodrigo Flores
5ed6534aa3 Adding a line break on resource generator after attr_accessible
Fixes issue #1851
2012-05-14 10:26:30 -03:00
Rodrigo Flores
120ca0e3a5 Merge branch 'fork-readme-rdoc-links' 2012-05-10 10:40:38 -03:00
Hosam Aly
d193802613 Added links to module RDocs, except for Encryptable which I couldn't find. 2012-05-10 10:40:27 -03:00
Rodrigo Flores
50b4d2eb6b Removing mentioning encryptable on README 2012-05-10 10:29:34 -03:00
Rodrigo Flores
36db032ca0 Updated Gemfile.lock 2012-05-09 19:54:09 -03:00
Rodrigo Flores
afbcc31c6a Bumping version to 2.1.0.rc2 2012-05-09 19:53:38 -03:00
Rodrigo Flores
52c35b18da Updating README 2012-05-09 19:52:56 -03:00
José Valim
454a5ad1ec Try to fix the build for rails 3.1 2012-05-09 23:41:05 +02:00
Rodrigo Flores
1698f0f57c Merge branch 'removing_encryptable' 2012-05-09 18:05:14 -03:00
Rodrigo Flores
bb6d7334d0 Fixing gem name 2012-05-09 18:04:40 -03:00
Rodrigo Flores
659ec4d6ea Using bundler's awesome way to release the gem! 2012-05-09 14:59:42 -03:00
Rodrigo Flores
2e50204700 Changelog 2012-05-09 14:52:47 -03:00
Rodrigo Flores
39dc9a7ba6 Removed encryptable references on rails_app 2012-05-09 14:49:55 -03:00
José Valim
65ef2592f6 Add a test case to previous commit 2012-05-09 18:27:44 +02:00
José Valim
ad0aed3ba5 Alternative solution to failure app's script name handling (tests upcoming) 2012-05-09 18:03:23 +02:00
Rodrigo Flores
0d868b9ec1 Removed ENCRYPTORS_LENGTH 2012-05-09 08:42:37 -03:00
Rodrigo Flores
5f440dfe13 Removing encryptors and its autoloads 2012-05-07 16:50:35 -03:00
Rodrigo Flores
768f8832b9 Removing encryptable module 2012-05-07 16:37:16 -03:00
José Valim
32f20dddd6 Get rid of deprecated code 2012-05-06 13:13:53 +02:00
José Valim
7aa93a3ecb Update CHANGELOG 2012-05-06 12:53:27 +02:00
José Valim
b07dd76453 Remove faux bcrypt encryptor from Devise (it was never released and it wont be until we solve the encryptable issue 2012-05-06 12:49:53 +02:00
José Valim
4600b4ab22 Speed up bcrypt handling 2012-05-06 12:29:03 +02:00
José Valim
a8d2dce563 Merge branch 'test_helpers' 2012-05-06 12:19:36 +02:00
José Valim
5e845ee265 Do not reproduce warden behavior, simply rely on the controller calling it 2012-05-06 12:09:53 +02:00
Matt Connolly
a9b7a4a1de Reinstating tests for the controller test's response object. This does need to be set so the strategy's custom response can be tested. 2012-05-06 19:24:57 +10:00
Matt Connolly
32d2f78239 Updating process unauthenticated to set the response so it can be tested. 2012-05-06 18:41:43 +10:00
Matt Connolly
2a3a8b8008 Changing test to not bother with saved response, since it wasn't set by the test. 2012-05-06 17:08:00 +10:00
Matt Connolly
90a63d4d89 Completing test and functionality for TestHelper to correctly return a custom response from a warden strategy. 2012-05-06 16:48:39 +10:00
Matt Connolly
66f74ed579 Adding a test for a warden strategy retuning a custom response. 2012-05-06 13:35:24 +10:00
José Valim
d376d11d42 Merge pull request #1825 from julianvargasalvarez/master
Use 'head :no_content' in sessions_controller#destroy
2012-05-03 00:27:21 -07:00
Julian Vargas
6664acd27f Use 'head :no_content' in sessions_controller#destroy
Code cleanup for returning headers instead of an empty string
when destroying sessions.

Lines 464 and 471 on test/integration/autenticatable_test.rb
were adjusted to assert on :no_content
2012-05-02 22:40:53 -05:00
Rodrigo Flores
525bcd4e2d Refactoring simulation inside engine to decide based on the api 2012-05-02 14:53:14 -03:00
Rodrigo Flores
34a64070ca Cached the class_path and changed a variable name (kudos to @britto!) 2012-05-02 14:52:55 -03:00
José Valim
67f2074c81 Merge pull request #1805 from rosenfeld/deserialization-handling
Better handling of previously enabled Devise model deserialization
2012-05-02 10:34:28 -07:00
José Valim
e6717e3d68 Merge pull request #1823 from plataformatec/bugfix-engine-generator
Fixes generator on engine
2012-05-02 10:33:54 -07:00
Rodrigo Flores
271eac7381 Testes passing on 3.1 \o/ 2012-05-02 14:15:42 -03:00
Rodrigo Flores
4bf4036bf7 Upgrading Rails 3.1 to 3.1.4 2012-05-02 14:15:42 -03:00
Rodrigo Flores
22c210c8b9 Changelog 2012-05-02 14:15:42 -03:00
Rodrigo Flores
afc3888391 Generators on engine fix 2012-05-02 14:15:42 -03:00
Rodrigo Rosenfeld Rosas
411b565cca Better handling of previously enabled Devise model deserialization 2012-05-02 13:03:34 -03:00
Carlos Antonio da Silva
f6c06ac786 Use sqlite3 gem for 3.1 Gemfile 2012-04-27 18:42:03 -03:00
Rodrigo Flores
852a6ff175 Merge pull request #1813 from Agis-/patch-1
Break the line so it doesn't exceed 80-chars limit
2012-04-27 07:55:58 -07:00
Agis Anastasopoulos
d6f4d936ee Apply the 80 chars per-line rule 2012-04-27 17:51:07 +03:00
Carlos Antonio da Silva
cba1820168 Change Copyright also in license file [ci skip]
See d435118 for the readme change.
2012-04-24 08:54:01 -03:00
Carlos Antonio da Silva
0cfc88d2ee Merge pull request #1804 from rosenfeld/sqlite
sqlite3-ruby was renamed to sqlite3
2012-04-22 06:12:35 -07:00
Carlos Antonio da Silva
ec3eed5d2a Change method name 2012-04-22 10:07:44 -03:00
Carlos Antonio da Silva
49873f4fea Merge pull request #1796 from mkremer/feature/devise_redirects
Added after_sending_reset_unlock_instructions_path_for
2012-04-22 05:44:50 -07:00
Rodrigo Rosenfeld Rosas
ee29bf8d42 sqlite3-ruby was renamed to sqlite3 2012-04-18 15:31:25 -03:00
Mark Kremer
0e0bfe6686 Added after_unlock_path_for to allow override of redirect after account
unlock
2012-04-17 13:38:50 +02:00
Mark Kremer
fafea15fa8 Added after_sending_reset_unlock_instructions_path_for which can be overridden in extensions to modify the redirect path 2012-04-17 10:04:06 +02:00
José Valim
3752981cfa Merge pull request #1794 from aderyabin/master
Clean up global namespaces
2012-04-16 09:14:36 -07:00
Andrey Deryabin
9ec1003f1e removed global namespaces 2012-04-16 21:27:16 +07:00
Rodrigo Flores
64c99bcfd4 Updated changelog to include the removal of render_with_scope
Closes #1737
2012-04-09 16:42:30 -03:00
George Guimarães
d4351183d9 Changes link in copyright notice to Plataformatec's site 2012-04-09 09:37:35 -03:00
José Valim
cef5c93bca Merge pull request #1780 from cmeiklejohn/master
Verify AR constant is defined in test suite.
2012-04-08 08:59:39 -07:00
Christopher Meiklejohn
eb4e23274d Ensure ActiveRecord is defined, which is not true when running Mongoid tests. 2012-04-07 15:54:00 -03:00
José Valim
dacdc72581 Do not accidently mark _prefixes as private. 2012-04-05 09:18:59 -03:00
José Valim
6846014def Do not make _prefixes private. 2012-04-05 09:15:48 -03:00
Rodrigo Flores
07ef99a8f0 Changelog and a minor change on the test title 2012-04-04 17:27:41 -03:00
Rodrigo Flores
857af600f7 Merge pull request #1722 from Antiarchitect/master
Token regeneration on session timeout.
2012-04-04 13:23:27 -07:00
Carlos Antonio da Silva
3cbced4e4e Merge pull request #1776 from bloudermilk/patch-1
Fixes syntax highlighting in the "Getting started" section of the README
2012-04-04 11:09:03 -07:00
Brendan Loudermilk
85e4a0e6ec Fixes syntax highlighting in the "Getting started" section of the README 2012-04-04 11:03:24 -07:00
Rodrigo Flores
45aca40f6c Updating the README since we won't have more private messages on Github 2012-04-04 08:12:12 -03:00
Andrey Voronkov
7ecbba089f Authentication token expiration on session timeout 2012-04-02 20:48:23 +04:00
José Valim
205ddfb7c9 Merge pull request #1761 from rosenfeld/patch-7
Fix require for rememberable strategy
2012-03-31 04:21:19 -07:00
Rodrigo Rosenfeld Rosas
8a50b207eb Fix require for rememberable strategy 2012-03-31 08:17:16 -03:00
José Valim
9f99ccdca3 Merge pull request #1759 from rosenfeld/patch-6
Fix typo
2012-03-30 12:38:58 -07:00
Rodrigo Rosenfeld Rosas
f49b605514 Fix typo 2012-03-30 16:37:23 -03:00
José Valim
52b4bab461 Fix failing test. 2012-03-30 09:13:28 +02:00
José Valim
f1ccaf86a4 Remember token is not required. 2012-03-30 09:08:00 +02:00
José Valim
b59ce51760 Wording. 2012-03-30 09:05:52 +02:00
José Valim
60d2c6fddb Update docs to make find_for_authentication purpose more clear. 2012-03-30 09:00:03 +02:00
José Valim
25a563119b Revert "Merge pull request #1754 from pivotalhalogen/master"
find_for_authentication should be called during only during
an authentication process.

This reverts commit a4c9d5826d, reversing
changes made to f94b71038e.
2012-03-30 08:53:35 +02:00
Rodrigo Flores
a4c9d5826d Merge pull request #1754 from pivotalhalogen/master
Shiny new pull request for #1752
2012-03-29 19:34:55 -07:00
Josh Knox & Ken Mayer
1d3b89458e Fix Authenticatable, call find_for_authentication 2012-03-29 16:27:41 -07:00
José Valim
f94b71038e Merge pull request #1749 from rosenfeld/patch-5
config.use_salt_as_remember_token is no longer supported
2012-03-28 23:47:42 -07:00
Rodrigo Rosenfeld Rosas
076f4b4db1 config.use_salt_as_remember_token is no longer supported 2012-03-28 19:29:41 -03:00
José Valim
18829a56e4 Merge pull request #1745 from rosenfeld/patch-3
Fix minor typo on settings template
2012-03-28 13:05:03 -07:00
Rodrigo Rosenfeld Rosas
ac7b1b3c1f Fix minor typo on settings template 2012-03-28 16:58:21 -03:00
José Valim
b74f71fbed Fix build so it works with Rails 3.1. 2012-03-26 18:50:39 +03:00
José Valim
c3c0f4bd89 Update CHANGELOG.rdoc 2012-03-26 18:01:21 +03:00
José Valim
e860ade718 Merge pull request #1730 from Paymium/issue-1729
Fix for #1729
2012-03-26 07:59:17 -07:00
José Valim
e9a8c6cb62 Merge pull request #1738 from parndt/patch-1
Bumped orm_adapter requirement up to ~> 0.0.7 per ianwhite/orm_adapter#10
2012-03-25 04:41:22 -07:00
Philip Arndt
473a68dbf9 Bumped orm_adapter requirement up to ~> 0.0.7 per ianwhite/orm_adapter#10 2012-03-26 00:16:01 +13:00
David FRANCOIS
885d8836d1 Ability to use attr_protected attributes as sign-in keys without triggering ActiveModel::MassAssignmentSecurity::Error when ActiveRecord::Base.mass_assignment_sanitizer is set to :strict. Fixes #1729. 2012-03-21 11:48:00 +01:00
José Valim
e92ae37dc3 Merge pull request #1726 from plataformatec/failed_attempts
Setting failed_attempts to 0 after sign in
2012-03-19 14:09:23 -07:00
Rodrigo Flores
e6af9763fd Hook should be on lockable not recoverable and removed an useless comment 2012-03-19 18:06:20 -03:00
Rodrigo Flores
ca73dae1f0 Changelog 2012-03-19 17:15:32 -03:00
Rodrigo Flores
3623215b8c failed_attempts is set to 0 on sign in 2012-03-19 17:09:22 -03:00
Rodrigo Flores
a1376ac8ea Indentation + Typo 2012-03-16 22:06:43 -03:00
Rodrigo Flores
9d724cb72a OMG Forgot to update the Changelog 2012-03-15 11:23:01 -03:00
132 changed files with 1853 additions and 1499 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,15 +1,95 @@
== 2.1.0.dev
== 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
* Add check_fields! method on Devise::Models to check if the model includes the fields that Devise uses
* 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
* Handle backwards incompatibility between Rails 3.2.6 and Thor 0.15.x
* bug fix
* Fix regression on strategy validation on previous release
== 2.1.1 (yanked)
* enhancements
* `sign_out_all_scopes` now locks warden and does not allow new logins in the same action
* `Devise.omniauth_path_prefix` is available to configure omniauth path prefix
* Redirect to sign in page when trying to access password#edit without a token (by @gbataille)
* Allow a lambda in authenticate(d) routes helpers to further select the scope
* Removed warnings on Rails 3.2.6 (by @nashby)
* bug fix
* `update_with_password` now relies on assign_attributes and forwards the :as option (by @wtn)
* Do not trigger timeout on sign in related actions
* Timeout does not explode when reset_authentication_token! is accidentally defined by Active Model (by @remomueller)
* deprecations
* Strategy#validate() no longer validates nil resources
== 2.1.0
* enhancements
* Add `check_fields!(model_class)` method on Devise::Models to check if the model includes the fields that Devise uses
* Add `skip_reconfirmation!` to skip reconfirmation
* Devise model generator now works with engines
* Devise encryptable was moved to its new gem (http://github.com/plataformatec/devise-encryptable)
* deprecations
* Deprecations warnings added on Devise 2.0 are now removed with their features
* All devise modules should now have a `required_fields(klass)` module method to help gathering missing attributes
* `use_salt_as_remember_token` and `apply_schema` does not have any effect since 2.0 and are now deprecated
* `valid_for_authentication?` must now return a boolean
* bug fix
* Ensure after sign in hook is not called without a resource
* Fix a term: now on Omniauth related flash messages, we say that we're authenticating from an omniauth provider instead of authorizing
* deprecation
* All devise modules should have a required_fields(klass) module method to help gathering missing attributes
* Fixed redirect when authenticated mounted apps (by @hakanensari)
* Ensure the failure app still respects config.relative_url_root
* `/users/sign_in` doesn't choke on protected attributes used to select sign in scope (by @Paymium)
* `failed_attempts` is set to zero after any sign in (including via reset password) (by @rodrigoflores)
* Added token expiration on timeout (by @antiarchitect)
* Do not accidentally mark `_prefixes` as private
* Better support for custom strategies on test helpers (by @mattconnolly)
* Return `head :no_content` in SessionsController now that most JS libraries handle it (by @julianvargasalvarez)
== 2.0.4
@@ -72,6 +152,7 @@ Notes: https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.
* Move devise/shared/_links.erb to devise/_links.erb
* Deprecated support of nested devise_for blocks
* Deprecated support to devise.registrations.reasons and devise.registrations.inactive_signed_up in favor of devise.registrations.signed_up_but_*
* Protected method render_with_scope was removed.
== 1.5.3

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!

23
Gemfile
View File

@@ -2,7 +2,7 @@ source "http://rubygems.org"
gemspec
gem "rails", "~> 3.2.0"
gem "rails", "~> 3.2.6"
gem "omniauth", "~> 1.0.0"
gem "omniauth-oauth2", "~> 1.0.0"
gem "rdoc"
@@ -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
@@ -25,11 +21,12 @@ platforms :jruby do
end
platforms :ruby do
gem "sqlite3-ruby"
group :mongoid do
gem "mongo", "~> 1.3.0"
gem "mongoid", "~> 2.0"
gem "bson_ext", "~> 1.3.0"
end
gem "sqlite3"
end
platforms :mri_19 do
group :mongoid do
gem "mongoid", "~> 3.0"
end
end

View File

@@ -1,143 +1,135 @@
PATH
remote: .
specs:
devise (2.0.4)
devise (2.2.1)
bcrypt-ruby (~> 3.0)
orm_adapter (~> 0.0.3)
orm_adapter (~> 0.1)
railties (~> 3.1)
warden (~> 1.1.1)
warden (~> 1.2.1)
GEM
remote: http://rubygems.org/
specs:
actionmailer (3.2.0)
actionpack (= 3.2.0)
mail (~> 2.4.0)
actionpack (3.2.0)
activemodel (= 3.2.0)
activesupport (= 3.2.0)
actionmailer (3.2.11)
actionpack (= 3.2.11)
mail (~> 2.4.4)
actionpack (3.2.11)
activemodel (= 3.2.11)
activesupport (= 3.2.11)
builder (~> 3.0.0)
erubis (~> 2.7.0)
journey (~> 1.0.0)
journey (~> 1.0.4)
rack (~> 1.4.0)
rack-cache (~> 1.1)
rack-cache (~> 1.2)
rack-test (~> 0.6.1)
sprockets (~> 2.1.2)
activemodel (3.2.0)
activesupport (= 3.2.0)
sprockets (~> 2.2.1)
activemodel (3.2.11)
activesupport (= 3.2.11)
builder (~> 3.0.0)
activerecord (3.2.0)
activemodel (= 3.2.0)
activesupport (= 3.2.0)
arel (~> 3.0.0)
activerecord (3.2.11)
activemodel (= 3.2.11)
activesupport (= 3.2.11)
arel (~> 3.0.2)
tzinfo (~> 0.3.29)
activeresource (3.2.0)
activemodel (= 3.2.0)
activesupport (= 3.2.0)
activesupport (3.2.0)
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.0)
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)
journey (1.0.0)
json (1.6.5)
linecache (0.46)
rbx-require-relative (> 0.0.4)
mail (2.4.1)
httpauth (0.2.0)
i18n (0.6.1)
journey (1.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.17.2)
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.0.6)
origin (1.0.11)
orm_adapter (0.4.0)
polyglot (0.3.3)
rack (1.4.1)
rack-cache (1.1)
rack (1.4.3)
rack-cache (1.2)
rack (>= 0.4)
rack-openid (1.3.1)
rack (>= 1.1.0)
ruby-openid (>= 2.1.8)
rack-ssl (1.3.2)
rack
rack-test (0.6.1)
rack-test (0.6.2)
rack (>= 1.0)
rails (3.2.0)
actionmailer (= 3.2.0)
actionpack (= 3.2.0)
activerecord (= 3.2.0)
activeresource (= 3.2.0)
activesupport (= 3.2.0)
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.0)
railties (3.2.0)
actionpack (= 3.2.0)
activesupport (= 3.2.0)
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)
rake (0.9.2.2)
rbx-require-relative (0.0.5)
thor (>= 0.14.6, < 2.0)
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.2)
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)
sqlite3-ruby (1.3.3)
sqlite3 (>= 1.3.3)
thor (0.14.6)
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.31)
warden (1.1.1)
tzinfo (0.3.35)
warden (1.2.1)
rack (>= 1.0)
webrat (0.7.2)
nokogiri (>= 1.2.0)
@@ -150,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.0)
rails (~> 3.2.6)
rdoc
ruby-debug (>= 0.10.3)
sqlite3-ruby
sqlite3
webrat (= 0.7.2)

View File

@@ -1,4 +1,4 @@
Copyright 2009-2012 Plataforma Tecnologia. http://blog.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.0 is out. If you are upgrading, please read: https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0
## 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)
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:
@@ -13,20 +13,19 @@ Devise is a flexible authentication solution for Rails based on Warden. It:
* Allows you to have multiple roles (or models/scopes) signed in at the same time;
* Is based on a modularity concept: use just what you really need.
It's comprised of 12 modules:
It's composed of 12 modules:
* Database Authenticatable: encrypts and stores a password in the database to validate the authenticity of a user while signing in. The authentication can be done both through POST requests or HTTP Basic Authentication.
* Token Authenticatable: signs in a user based on an authentication token (also known as "single access token"). The token can be given both through query string or HTTP Basic Authentication.
* Omniauthable: adds Omniauth (github.com/intridea/omniauth) support;
* Confirmable: sends emails with confirmation instructions and verifies whether an account is already confirmed during sign in.
* Recoverable: resets the user password and sends reset instructions.
* Registerable: handles signing up users through a registration process, also allowing them to edit and destroy their account.
* Rememberable: manages generating and clearing a token for remembering the user from a saved cookie.
* Trackable: tracks sign in count, timestamps and IP address.
* Timeoutable: expires sessions that have no activity in a specified period of time.
* Validatable: provides validations of email and password. It's optional and can be customized, so you're able to define your own validations.
* Lockable: locks an account after a specified number of failed sign-in attempts. Can unlock via email or after a specified time period.
* Encryptable: adds support of other authentication mechanisms besides the built-in Bcrypt (the default).
* [Database Authenticatable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/DatabaseAuthenticatable): encrypts and stores a password in the database to validate the authenticity of a user while signing in. The authentication can be done both through POST requests or HTTP Basic Authentication.
* [Token Authenticatable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/TokenAuthenticatable): signs in a user based on an authentication token (also known as "single access token"). The token can be given both through query string or HTTP Basic Authentication.
* [Omniauthable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Omniauthable): adds Omniauth (https://github.com/intridea/omniauth) support;
* [Confirmable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Confirmable): sends emails with confirmation instructions and verifies whether an account is already confirmed during sign in.
* [Recoverable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Recoverable): resets the user password and sends reset instructions.
* [Registerable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Registerable): handles signing up users through a registration process, also allowing them to edit and destroy their account.
* [Rememberable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Rememberable): manages generating and clearing a token for remembering the user from a saved cookie.
* [Trackable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Trackable): tracks sign in count, timestamps and IP address.
* [Timeoutable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Timeoutable): expires sessions that have no activity in a specified period of time.
* [Validatable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Validatable): provides validations of email and password. It's optional and can be customized, so you're able to define your own validations.
* [Lockable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Lockable): locks an account after a specified number of failed sign-in attempts. Can unlock via email or after a specified time period.
## Information
@@ -42,7 +41,7 @@ If you discover a problem with Devise, we would like to know about it. However,
https://github.com/plataformatec/devise/wiki/Bug-reports
If you found a security bug, do *NOT* use the GitHub issue tracker. Send email or a private GitHub message to the maintainers listed at the bottom of the README.
If you found a security bug, do *NOT* use the GitHub issue tracker. Send an email to the maintainers listed at the bottom of the README.
### Mailing list
@@ -91,7 +90,9 @@ Once you have solidified your understanding of Rails and authentication mechanis
Devise 2.0 works with Rails 3.1 onwards. You can add it to your Gemfile with:
gem 'devise'
```ruby
gem 'devise'
```
Run the bundle command to install it.
@@ -107,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.
@@ -239,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.
@@ -303,7 +304,23 @@ https://github.com/plataformatec/devise/wiki/I18n
### Test helpers
Devise includes some tests helpers for functional specs. To use them, you just need to include Devise::TestHelpers in your test class and use the sign_in and sign_out method. Such methods have the same signature as in controllers:
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
include Devise::TestHelpers
end
```
If you're using RSpec, you can put the following inside a file named `spec/support/devise.rb`:
```ruby
RSpec.configure do |config|
config.include Devise::TestHelpers, :type => :controller
end
```
Now you are ready to use the `sign_in` and `sign_out` methods. Such methods have the same signature as in controllers:
```ruby
sign_in :user, @user # sign_in(scope, resource)
@@ -313,27 +330,24 @@ sign_out :user # sign_out(scope)
sign_out @user # sign_out(resource)
```
You can include the Devise Test Helpers in all of your tests by adding the following to the bottom of your test/test_helper.rb file:
There are two things that is important to keep in mind:
```ruby
class ActionController::TestCase
include Devise::TestHelpers
end
```
1) These helpers are not going to work for integration tests driven by Capybara or Webrat. They are meant to be used with functional tests only. Instead, fill in the form or explicitly set the user in session;
If you're using RSpec and want the helpers automatically included within all `describe` blocks, add a file called spec/support/devise.rb with the following contents:
2) If you are testing Devise internal controllers or a controller that inherits from Devise's, you need to tell Devise which mapping should be used before a request. This is necessary because Devise gets this information from router, but since functional tests do not pass through the router, it needs to be told explicitly. For example, if you are testing the user scope, simply do:
```ruby
RSpec.configure do |config|
config.include Devise::TestHelpers, :type => :controller
end
```
Do not use such helpers for integration tests such as Cucumber or Webrat. Instead, fill in the form or explicitly set the user in session. For more tips, check the wiki (https://wiki.github.com/plataformatec/devise).
@request.env["devise.mapping"] = Devise.mappings[:user]
get :new
### 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
@@ -379,4 +393,4 @@ https://github.com/plataformatec/devise/contributors
## License
MIT License. Copyright 2012 Plataforma Tecnologia. http://blog.plataformatec.com.br
MIT License. Copyright 2009-2013 Plataformatec. http://plataformatec.com.br

View File

@@ -1,5 +1,5 @@
# encoding: UTF-8
require "bundler/gem_tasks"
require 'rake/testtask'
require 'rdoc/task'
@@ -29,6 +29,6 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'Devise'
rdoc.options << '--line-numbers' << '--inline-source'
rdoc.rdoc_files.include('README.rdoc')
rdoc.rdoc_files.include('README.md')
rdoc.rdoc_files.include('lib/**/*.rb')
end

View File

@@ -6,7 +6,7 @@ class Devise::ConfirmationsController < DeviseController
# POST /resource/confirmation
def create
self.resource = resource_class.send_confirmation_instructions(params[resource_name])
self.resource = resource_class.send_confirmation_instructions(resource_params)
if successfully_sent?(resource)
respond_with({}, :location => after_resending_confirmation_instructions_path_for(resource_name))

View File

@@ -1,6 +1,12 @@
class Devise::OmniauthCallbacksController < DeviseController
prepend_before_filter { request.env["devise.skip_timeout"] = true }
def passthru
render :status => 404, :text => "Not found. Authentication passthru."
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

@@ -1,5 +1,7 @@
class Devise::PasswordsController < DeviseController
prepend_before_filter :require_no_authentication
# Render the #edit only if coming from a reset password email link
append_before_filter :assert_reset_token_passed, :only => :edit
# GET /resource/password/new
def new
@@ -8,7 +10,7 @@ class Devise::PasswordsController < DeviseController
# POST /resource/password
def create
self.resource = resource_class.send_reset_password_instructions(params[resource_name])
self.resource = resource_class.send_reset_password_instructions(resource_params)
if successfully_sent?(resource)
respond_with({}, :location => after_sending_reset_password_instructions_path_for(resource_name))
@@ -25,9 +27,10 @@ class Devise::PasswordsController < DeviseController
# PUT /resource/password
def update
self.resource = resource_class.reset_password_by_token(params[resource_name])
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)
@@ -44,4 +47,19 @@ class Devise::PasswordsController < DeviseController
new_session_path(resource_name)
end
# Check if a reset_password_token is provided in the request
def assert_reset_token_passed
if params[:reset_password_token].blank?
set_flash_message(:error, :no_token)
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(params[resource_name])
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,13 +74,25 @@ 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)
hash ||= params[resource_name] || {}
hash ||= resource_params || {}
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

@@ -1,17 +1,18 @@
class Devise::SessionsController < DeviseController
prepend_before_filter :require_no_authentication, :only => [ :new, :create ]
prepend_before_filter :allow_params_authentication!, :only => :create
prepend_before_filter { request.env["devise.skip_timeout"] = true }
# GET /resource/sign_in
def new
resource = build_resource
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)
@@ -21,17 +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
method = "to_#{request_format}"
text = {}.respond_to?(method) ? {}.send(method) : ""
render :text => text, :status => :ok
end
end
end

View File

@@ -8,10 +8,10 @@ class Devise::UnlocksController < DeviseController
# POST /resource/unlock
def create
self.resource = resource_class.send_unlock_instructions(params[resource_name])
self.resource = resource_class.send_unlock_instructions(resource_params)
if successfully_sent?(resource)
respond_with({}, :location => new_session_path(resource_name))
respond_with({}, :location => after_sending_unlock_instructions_path_for(resource))
else
respond_with(resource)
end
@@ -23,9 +23,22 @@ class Devise::UnlocksController < DeviseController
if resource.errors.empty?
set_flash_message :notice, :unlocked if is_navigational_format?
respond_with_navigational(resource){ redirect_to new_session_path(resource) }
respond_with_navigational(resource){ redirect_to after_unlock_path_for(resource) }
else
respond_with_navigational(resource.errors, :status => :unprocessable_entity){ render :new }
end
end
protected
# The path used after sending unlock password instructions
def after_sending_unlock_instructions_path_for(resource)
new_session_path(resource)
end
# The path used after unlocking the resource
def after_unlock_path_for(resource)
new_session_path(resource)
end
end

View File

@@ -5,12 +5,12 @@ class DeviseController < Devise.parent_controller.constantize
helper DeviseHelper
helpers = %w(resource scope_name resource_name signed_in_resource
resource_class devise_mapping)
resource_class resource_params devise_mapping)
hide_action *helpers
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
@@ -28,6 +28,10 @@ class DeviseController < Devise.parent_controller.constantize
devise_mapping.to
end
def resource_params
params[resource_name]
end
# Returns a signed in resource from session (if one exists)
def signed_in_resource
warden.authenticate(:scope => resource_name)
@@ -38,17 +42,39 @@ class DeviseController < Devise.parent_controller.constantize
@devise_mapping ||= request.env["devise.mapping"]
end
# Override prefixes to consider the scoped view.
# Notice we need to check for the request due to a bug in
# Action Controller tests that forces _prefixes to be
# loaded before even having a request object.
def _prefixes #:nodoc:
@_prefixes ||= if self.class.scoped_views? && request && devise_mapping
super.unshift("#{devise_mapping.scoped_path}/#{controller_name}")
else
super
end
end
hide_action :_prefixes
protected
# Checks whether it's a devise mapped resource or not.
def assert_is_devise_resource! #:nodoc:
unknown_action! <<-MESSAGE unless devise_mapping
Could not find devise mapping for path #{request.fullpath.inspect}.
Maybe you forgot to wrap your route inside the scope block? For example:
This may happen for two reasons:
1) You forgot to wrap your route inside the scope block. For example:
devise_scope :user do
match "/some/route" => "some_devise_controller"
end
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]
devise_scope :user do
match "/some/route" => "some_devise_controller"
end
MESSAGE
end
@@ -68,9 +94,20 @@ MESSAGE
end
# Build a devise resource.
def build_resource(hash=nil)
hash ||= params[resource_name] || {}
self.resource = resource_class.new(hash)
# Assignment bypasses attribute protection when :unsafe option is passed
def build_resource(hash = nil, options = {})
hash ||= resource_params || {}
if options[:unsafe]
self.resource = resource_class.new.tap do |resource|
hash.each do |key, value|
setter = :"#{key}="
resource.send(setter, value) if resource.respond_to?(setter)
end
end
else
self.resource = resource_class.new(hash)
end
end
# Helper for use in before_filters where no authentication is required.
@@ -131,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
@@ -144,21 +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
# Override prefixes to consider the scoped view.
def _prefixes #:nodoc:
@_prefixes ||= if self.class.scoped_views? && devise_mapping
super.unshift("#{devise_mapping.scoped_path}/#{controller_name}")
else
super
end
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,9 +4,9 @@
<%= 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 %>
<%= render :partial => "devise/shared/links" %>
<%= render "devise/shared/links" %>

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>
@@ -13,4 +13,4 @@
<div><%= f.submit "Change my password" %></div>
<% end %>
<%= render :partial => "devise/shared/links" %>
<%= render "devise/shared/links" %>

View File

@@ -4,9 +4,9 @@
<%= 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 %>
<%= render :partial => "devise/shared/links" %>
<%= render "devise/shared/links" %>

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), :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>
@@ -15,4 +15,4 @@
<div><%= f.submit "Sign up" %></div>
<% end %>
<%= render :partial => "devise/shared/links" %>
<%= render "devise/shared/links" %>

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>
@@ -14,4 +14,4 @@
<div><%= f.submit "Sign in" %></div>
<% end %>
<%= render :partial => "devise/shared/links" %>
<%= render "devise/shared/links" %>

View File

@@ -4,9 +4,9 @@
<%= 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 %>
<%= render :partial => "devise/shared/links" %>
<%= render "devise/shared/links" %>

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.'
@@ -28,10 +30,11 @@ en:
send_instructions: 'You will receive an email with instructions about how to reset your password in a few minutes.'
updated: 'Your password was changed successfully. You are now signed in.'
updated_not_active: 'Your password was changed successfully.'
send_paranoid_instructions: "If your e-mail exists on our database, you will receive a password recovery link on your e-mail"
send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes."
no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided."
confirmations:
send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.'
send_paranoid_instructions: 'If your e-mail exists on our database, you will receive an email with instructions about how to confirm your account in a few minutes.'
send_paranoid_instructions: 'If your email address exists in our database, you will receive an email with instructions about how to confirm your account in a few minutes.'
confirmed: 'Your account was successfully confirmed. You are now signed in.'
registrations:
signed_up: 'Welcome! You have signed up successfully.'

View File

@@ -18,8 +18,8 @@ Gem::Specification.new do |s|
s.test_files = `git ls-files -- test/*`.split("\n")
s.require_paths = ["lib"]
s.add_dependency("warden", "~> 1.1.1")
s.add_dependency("orm_adapter", "~> 0.0.3")
s.add_dependency("warden", "~> 1.2.1")
s.add_dependency("orm_adapter", "~> 0.1")
s.add_dependency("bcrypt-ruby", "~> 3.0")
s.add_dependency("railties", "~> 3.1")
end

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"
@@ -25,11 +25,11 @@ platforms :jruby do
end
platforms :ruby do
gem "sqlite3-ruby"
group :mongoid do
gem "mongo", "~> 1.3.0"
gem "mongoid", "~> 2.0"
gem "bson_ext", "~> 1.3.0"
end
gem "sqlite3"
end
platforms :mri_19 do
group :mongoid do
gem "mongoid", "~> 3.0"
end
end

View File

@@ -1,96 +1,98 @@
PATH
remote: ..
specs:
devise (2.0.2)
devise (2.2.0)
bcrypt-ruby (~> 3.0)
orm_adapter (~> 0.0.3)
orm_adapter (~> 0.1)
railties (~> 3.1)
warden (~> 1.1.1)
warden (~> 1.2.1)
GEM
remote: http://rubygems.org/
specs:
actionmailer (3.1.3)
actionpack (= 3.1.3)
mail (~> 2.3.0)
actionpack (3.1.3)
activemodel (= 3.1.3)
activesupport (= 3.1.3)
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.5)
rack-cache (~> 1.1)
rack (~> 1.3.6)
rack-cache (~> 1.2)
rack-mount (~> 0.8.2)
rack-test (~> 0.6.1)
sprockets (~> 2.0.3)
activemodel (3.1.3)
activesupport (= 3.1.3)
sprockets (~> 2.0.4)
activemodel (3.1.10)
activesupport (= 3.1.10)
builder (~> 3.0.0)
i18n (~> 0.6)
activerecord (3.1.3)
activemodel (= 3.1.3)
activesupport (= 3.1.3)
arel (~> 2.2.1)
activerecord (3.1.10)
activemodel (= 3.1.10)
activesupport (= 3.1.10)
arel (~> 2.2.3)
tzinfo (~> 0.3.29)
activeresource (3.1.3)
activemodel (= 3.1.3)
activesupport (= 3.1.3)
activesupport (3.1.3)
multi_json (~> 1.0)
addressable (2.2.7)
arel (2.2.1)
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.6.5)
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.0)
mail (2.3.3)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
metaclass (0.0.1)
mime-types (1.17.2)
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.0.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.6)
origin (1.0.11)
orm_adapter (0.4.0)
polyglot (0.3.3)
rack (1.3.6)
rack-cache (1.1)
rack (1.3.8)
rack-cache (1.2)
rack (>= 0.4)
rack-mount (0.8.3)
rack (>= 1.0.0)
@@ -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.3)
actionmailer (= 3.1.3)
actionpack (= 3.1.3)
activerecord (= 3.1.3)
activeresource (= 3.1.3)
activesupport (= 3.1.3)
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.3)
railties (3.1.3)
actionpack (= 3.1.3)
activesupport (= 3.1.3)
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,21 +127,19 @@ GEM
ruby-debug-base (~> 0.10.4.0)
ruby-debug-base (0.10.4)
linecache (>= 0.3)
ruby-openid (2.1.8)
sprockets (2.0.3)
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-ruby (1.3.3)
sqlite3 (>= 1.3.3)
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.31)
warden (1.1.1)
tzinfo (0.3.35)
warden (1.2.1)
rack (>= 1.0)
webrat (0.7.2)
nokogiri (>= 1.2.0)
@@ -152,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)
@@ -165,5 +163,5 @@ DEPENDENCIES
rails (~> 3.1.0)
rdoc
ruby-debug (>= 0.10.3)
sqlite3-ruby
sqlite3
webrat (= 0.7.2)

View File

@@ -6,12 +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 :Schema, 'devise/schema'
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'
@@ -20,16 +20,6 @@ module Devise
autoload :UrlHelpers, 'devise/controllers/url_helpers'
end
module Encryptors
autoload :Base, 'devise/encryptors/base'
autoload :AuthlogicSha512, 'devise/encryptors/authlogic_sha512'
autoload :BCrypt, 'devise/encryptors/bcrypt'
autoload :ClearanceSha1, 'devise/encryptors/clearance_sha1'
autoload :RestfulAuthenticationSha1, 'devise/encryptors/restful_authentication_sha1'
autoload :Sha512, 'devise/encryptors/sha512'
autoload :Sha1, 'devise/encryptors/sha1'
end
module Mailers
autoload :Helpers, 'devise/mailers/helpers'
end
@@ -53,15 +43,6 @@ module Devise
# True values used to check params
TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE']
# Declare encryptors length which are used in migrations.
ENCRYPTORS_LENGTH = {
:sha1 => 40,
:sha512 => 128,
:clearance_sha1 => 40,
:restful_authentication_sha1 => 40,
:authlogic_sha512 => 128
}
# Custom domain for cookies. Not set by default
mattr_accessor :rememberable_options
@@rememberable_options = {}
@@ -79,14 +60,12 @@ module Devise
@@request_keys = []
# Keys that should be case-insensitive.
# False by default for backwards compatibility.
mattr_accessor :case_insensitive_keys
@@case_insensitive_keys = false
@@case_insensitive_keys = [ :email ]
# Keys that should have whitespace stripped.
# False by default for backwards compatibility.
mattr_accessor :strip_whitespace_keys
@@strip_whitespace_keys = false
@@strip_whitespace_keys = []
# If http authentication is enabled by default.
mattr_accessor :http_authenticatable
@@ -108,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
@@ -126,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 ]
@@ -139,14 +122,14 @@ module Devise
mattr_accessor :timeout_in
@@timeout_in = 30.minutes
# Authentication token expiration on timeout
mattr_accessor :expire_auth_token_on_timeout
@@expire_auth_token_on_timeout = false
# Used to encrypt password. Please generate one with rake secret.
mattr_accessor :pepper
@@pepper = nil
# Used to define the password encryption algorithm.
mattr_accessor :encryptor
@@encryptor = nil
# Scoped views. Since it relies on fallbacks to render default views, it's
# turned off by default.
mattr_accessor :scoped_views
@@ -179,9 +162,8 @@ module Devise
@@reset_password_keys = [ :email ]
# Time interval you can reset your password with a reset password key
# Nil by default for backwards compatibility.
mattr_accessor :reset_password_within
@@reset_password_within = nil
@@reset_password_within = 6.hours
# The default scope which is used by warden.
mattr_accessor :default_scope
@@ -223,36 +205,21 @@ module Devise
mattr_accessor :router_name
@@router_name = nil
# DEPRECATED CONFIG
# Set the omniauth path prefix so it can be overriden when
# Devise is used in a mountable engine
mattr_accessor :omniauth_path_prefix
@@omniauth_path_prefix = nil
# If true, uses salt as remember token and does not create it in the database.
# By default is false for backwards compatibility.
mattr_accessor :use_salt_as_remember_token
@@use_salt_as_remember_token = false
# Tells if devise should apply the schema in ORMs where devise declaration
# and schema belongs to the same class (as Datamapper and Mongoid).
mattr_accessor :apply_schema
@@apply_schema = true
def self.remember_across_browsers=(value)
warn "\n[DEVISE] Devise.remember_across_browsers is deprecated and has no effect. Please remove it.\n"
def self.encryptor=(value)
warn "\n[DEVISE] To select a encryption which isn't bcrypt, you should use devise-encryptable gem.\n"
end
def self.confirm_within=(value)
warn "\n[DEVISE] Devise.confirm_within= is deprecated. Please set Devise.allow_unconfirmed_access_for= instead.\n"
Devise.allow_unconfirmed_access_for = value
def self.use_salt_as_remember_token=(value)
warn "\n[DEVISE] Devise.use_salt_as_remember_token is deprecated and has no effect. Please remove it.\n"
end
def self.cookie_options=(value)
warn "\n[DEVISE] Devise.cookie_options= is deprecated. Please set Devise.rememberable_options= instead.\n"
Devise.rememberable_options = value
end
def self.stateless_token=(value)
warn "\n[DEVISE] Devise.stateless_token= is deprecated. Please append :token_auth to Devise.skip_session_storage " \
"instead, for example: Devise.skip_session_storage << :token_auth\n"
Devise.skip_session_storage << :token_auth
def self.apply_schema=(value)
warn "\n[DEVISE] Devise.apply_schema is deprecated and has no effect. Please remove it.\n"
end
# PRIVATE CONFIGURATION

View File

@@ -88,8 +88,8 @@ module Devise
# Return true if the given scope is signed in session. If no scope given, return
# true if any scope is signed in. Does not run authentication hooks.
def signed_in?(scope=nil)
[ scope || Devise.mappings.keys ].flatten.any? do |scope|
warden.authenticate?(:scope => scope)
[ scope || Devise.mappings.keys ].flatten.any? do |_scope|
warden.authenticate?(:scope => _scope)
end
end
@@ -126,8 +126,8 @@ module Devise
end
# Sign out a given user or scope. This helper is useful for signing out a user
# after deleting accounts. Returns true if there was a logout and false if there is no user logged in
# on the referred scope
# after deleting accounts. Returns true if there was a logout and false if there
# is no user logged in on the referred scope
#
# Examples:
#
@@ -141,6 +141,7 @@ module Devise
warden.raw_session.inspect # Without this inspect here. The session does not clear.
warden.logout(scope)
warden.clear_strategies_cache!(:scope => scope)
instance_variable_set(:"@current_#{scope}", nil)
!!user
@@ -149,18 +150,20 @@ module Devise
# Sign out all active users or scopes. This helper is useful for signing out all roles
# in one click. This signs out ALL scopes in warden. Returns true if there was at least one logout
# and false if there was no user logged in on all scopes.
def sign_out_all_scopes
def sign_out_all_scopes(lock=true)
users = Devise.mappings.keys.map { |s| warden.user(:scope => s, :run_callbacks => false) }
warden.raw_session.inspect
warden.logout
expire_devise_cached_variables!
warden.clear_strategies_cache!
warden.lock! if lock
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:
#
@@ -168,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
@@ -237,11 +245,6 @@ module Devise
redirect_to after_sign_in_path_for(resource)
end
def redirect_location(scope, resource) #:nodoc:
ActiveSupport::Deprecation.warn "redirect_location in Devise is deprecated. Please use after_sign_in_path_for instead.", caller
after_sign_in_path_for(resource)
end
def expire_session_data_after_sign_in!
session.keys.grep(/^devise\./).each { |k| session.delete(k) }
end
@@ -258,12 +261,20 @@ module Devise
# Overwrite Rails' handle unverified request to sign out all scopes,
# clear run strategies and remove cached variables.
def handle_unverified_request
sign_out_all_scopes
warden.clear_strategies_cache!
sign_out_all_scopes(false)
request.env["devise.skip_storage"] = true
expire_devise_cached_variables!
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

@@ -1,19 +0,0 @@
require "digest/sha2"
module Devise
module Encryptors
# = AuthlogicSha512
# Simulates Authlogic's default encryption mechanism.
# Warning: it uses Devise's stretches configuration to port Authlogic's one. Should be set to 20 in the initializer to simulate
# the default behavior.
class AuthlogicSha512 < Base
# Generates a default password digest based on salt, pepper and the
# incoming password.
def self.digest(password, stretches, salt, pepper)
digest = [password, salt].flatten.join('')
stretches.times { digest = Digest::SHA512.hexdigest(digest) }
digest
end
end
end
end

View File

@@ -1,24 +0,0 @@
module Devise
# Implements a way of adding different encryptions.
# The class should implement a self.digest method that taks the following params:
# - password
# - stretches: the number of times the encryption will be applied
# - salt: the password salt as defined by devise
# - pepper: Devise config option
#
module Encryptors
class Base
def self.digest
raise NotImplemented
end
def self.salt(stretches)
Devise.friendly_token[0,20]
end
def self.compare(encrypted_password, password, stretches, salt, pepper)
Devise.secure_compare(encrypted_password, digest(password, stretches, salt, pepper))
end
end
end
end

View File

@@ -1,14 +0,0 @@
module Devise
module Encryptors
class BCrypt < Base
def self.digest(password, stretches, salt, pepper)
::BCrypt::Engine.hash_secret("#{password}#{pepper}",salt, stretches)
end
def self.compare(encrypted_password, password, stretches, salt, pepper)
salt = ::BCrypt::Password.new(encrypted_password).salt
Devise.secure_compare(encrypted_password, digest(password, stretches, salt, pepper))
end
end
end
end

View File

@@ -1,17 +0,0 @@
require "digest/sha1"
module Devise
module Encryptors
# = ClearanceSha1
# Simulates Clearance's default encryption mechanism.
# Warning: it uses Devise's pepper to port the concept of REST_AUTH_SITE_KEY
# Warning: it uses Devise's stretches configuration to port the concept of REST_AUTH_DIGEST_STRETCHES
class ClearanceSha1 < Base
# Generates a default password digest based on salt, pepper and the
# incoming password.
def self.digest(password, stretches, salt, pepper)
Digest::SHA1.hexdigest("--#{salt}--#{password}--")
end
end
end
end

View File

@@ -1,22 +0,0 @@
require "digest/sha1"
module Devise
module Encryptors
# = RestfulAuthenticationSha1
# Simulates Restful Authentication's default encryption mechanism.
# Warning: it uses Devise's pepper to port the concept of REST_AUTH_SITE_KEY
# Warning: it uses Devise's stretches configuration to port the concept of REST_AUTH_DIGEST_STRETCHES. Should be set to 10 in
# the initializer to simulate the default behavior.
class RestfulAuthenticationSha1 < Base
# Generates a default password digest based on salt, pepper and the
# incoming password.
def self.digest(password, stretches, salt, pepper)
digest = pepper
stretches.times { digest = Digest::SHA1.hexdigest([digest, salt, password, pepper].flatten.join('--')) }
digest
end
end
end
end

View File

@@ -1,25 +0,0 @@
require "digest/sha1"
module Devise
module Encryptors
# = Sha1
# Uses the Sha1 hash algorithm to encrypt passwords.
class Sha1 < Base
# Generates a default password digest based on stretches, salt, pepper and the
# incoming password.
def self.digest(password, stretches, salt, pepper)
digest = pepper
stretches.times { digest = self.secure_digest(salt, digest, password, pepper) }
digest
end
private
# Generate a SHA1 digest joining args. Generated token is something like
# --arg1--arg2--arg3--argN--
def self.secure_digest(*tokens)
::Digest::SHA1.hexdigest('--' << tokens.flatten.join('--') << '--')
end
end
end
end

View File

@@ -1,25 +0,0 @@
require "digest/sha2"
module Devise
module Encryptors
# = Sha512
# Uses the Sha512 hash algorithm to encrypt passwords.
class Sha512 < Base
# Generates a default password digest based on salt, pepper and the
# incoming password.
def self.digest(password, stretches, salt, pepper)
digest = pepper
stretches.times { digest = self.secure_digest(salt, digest, password, pepper) }
digest
end
private
# Generate a Sha512 digest joining args. Generated token is something like
# --arg1--arg2--arg3--argN--
def self.secure_digest(*tokens)
::Digest::SHA512.hexdigest('--' << tokens.flatten.join('--') << '--')
end
end
end
end

View File

@@ -88,7 +88,9 @@ module Devise
opts = {}
route = :"new_#{scope}_session_path"
opts[:format] = request_format unless skip_format?
opts[:script_name] = nil
config = Rails.application.config
opts[:script_name] = (config.relative_url_root if config.respond_to?(:relative_url_root))
context = send(Devise.available_router_name)

View File

@@ -0,0 +1,7 @@
# After each sign in, if resource responds to failed_attempts, sets it to 0
# This is only triggered when the user is explicitly set (with set_user)
Warden::Manager.after_set_user :except => :fetch do |record, warden, options|
if record.respond_to?(:failed_attempts) && warden.authenticated?(options[:scope])
record.update_attribute(:failed_attempts, 0)
end
end

View File

@@ -5,16 +5,20 @@
# verify timeout in the following request.
Warden::Manager.after_set_user do |record, warden, options|
scope = options[:scope]
env = warden.request.env
if record && record.respond_to?(:timedout?) && warden.authenticated?(scope) && options[:store] != false
last_request_at = warden.session(scope)['last_request_at']
if record.timedout?(last_request_at)
if record.timedout?(last_request_at) && !env['devise.skip_timeout']
warden.logout(scope)
if record.respond_to?(:expire_auth_token_on_timeout) && record.expire_auth_token_on_timeout
record.reset_authentication_token!
end
throw :warden, :scope => scope, :message => :timeout
end
unless warden.request.env['devise.skip_trackable']
unless env['devise.skip_trackable']
warden.session(scope)['last_request_at'] = Time.now.utc
end
end

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

@@ -27,7 +27,7 @@ module Devise
# inside the given class.
#
def self.config(mod, *accessors) #:nodoc:
(class << mod; self; end).send :attr_accessor, :available_configs
class << mod; attr_accessor :available_configs; end
mod.available_configs = accessors
accessors.each do |accessor|
@@ -51,16 +51,19 @@ module Devise
def self.check_fields!(klass)
failed_attributes = []
instance = klass.new
klass.devise_modules.each do |mod|
instance = klass.new
constant = const_get(mod.to_s.classify)
if const_get(mod.to_s.classify).respond_to?(:required_fields)
const_get(mod.to_s.classify).required_fields(klass).each do |field|
if constant.respond_to?(:required_fields)
constant.required_fields(klass).each do |field|
failed_attributes << field unless instance.respond_to?(field)
end
else
ActiveSupport::Deprecation.warn "The module #{mod} doesn't implement self.required_fields(klass). Devise uses required_fields to warn developers of any missing fields in their models. Please implement #{mod}.required_fields(klass) that returns an array of symbols with the required fields."
ActiveSupport::Deprecation.warn "The module #{mod} doesn't implement self.required_fields(klass). " \
"Devise uses required_fields to warn developers of any missing fields in their models. " \
"Please implement #{mod}.required_fields(klass) that returns an array of symbols with the required fields."
end
end
@@ -87,6 +90,10 @@ module Devise
devise_modules_hook! do
include Devise::Models::Authenticatable
selected_modules.each do |m|
if m == :encryptable && !(defined?(Devise::Models::Encryptable))
warn "[DEVISE] You're trying to include :encryptable in your model but it is not bundled with the Devise gem anymore. Please add `devise-encryptable` to your Gemfile to proceed.\n"
end
mod = Devise::Models.const_get(m.to_s.classify)
if mod.const_defined?("ClassMethods")
@@ -110,8 +117,8 @@ module Devise
end
end
# The hook which is called inside devise. So your ORM can include devise
# compatibility stuff.
# The hook which is called inside devise.
# So your ORM can include devise compatibility stuff.
def devise_modules_hook!
yield
end

View File

@@ -54,7 +54,7 @@ module Devise
BLACKLIST_FOR_SERIALIZATION = [:encrypted_password, :reset_password_token, :reset_password_sent_at,
:remember_created_at, :sign_in_count, :current_sign_in_at, :last_sign_in_at, :current_sign_in_ip,
:last_sign_in_ip, :password_salt, :confirmation_token, :confirmed_at, :confirmation_sent_at,
:unconfirmed_email, :failed_attempts, :unlock_token, :locked_at, :authentication_token]
:remember_token, :unconfirmed_email, :failed_attempts, :unlock_token, :locked_at, :authentication_token]
included do
class_attribute :devise_modules, :instance_writer => false
@@ -93,22 +93,6 @@ module Devise
def authenticatable_salt
end
def devise_mailer
Devise.mailer
end
def headers_for(name)
{}
end
def downcase_keys
(self.class.case_insensitive_keys || []).each { |k| self[k].try(:downcase!) }
end
def strip_whitespace
(self.class.strip_whitespace_keys || []).each { |k| self[k].try(:strip!) }
end
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"
@@ -134,6 +118,68 @@ module Devise
RUBY
end
protected
def devise_mailer
Devise.mailer
end
# This is an internal method called every time Devise needs
# to send a notification/mail. This can be overriden if you
# need to customize the e-mail delivery logic. For instance,
# if you are using a queue to deliver e-mails (delayed job,
# sidekiq, resque, etc), you must add the delivery to the queue
# just after the transaction was committed. To achieve this,
# you can override send_devise_notification to store the
# deliveries until the after_commit callback is triggered:
#
# class User
# devise :database_authenticatable, :confirmable
#
# after_commit :send_pending_notifications
#
# protected
#
# def send_devise_notification(notification)
# pending_notifications << notification
# end
#
# def send_pending_notifications
# pending_notifications.each do |n|
# devise_mailer.send(n, self).deliver
# end
# end
#
# def pending_notifications
# @pending_notifications ||= []
# end
# end
#
def send_devise_notification(notification, opts={})
devise_mailer.send(notification, self, opts).deliver
end
def downcase_keys
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| 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
Devise::Models.config(self, :authentication_keys, :request_keys, :strip_whitespace_keys,
:case_insensitive_keys, :http_authenticatable, :params_authenticatable, :skip_session_storage)
@@ -158,6 +204,12 @@ module Devise
end
# Find first record based on conditions given (ie by the sign in form).
# This method is always called during an authentication process but
# 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.`
#
# Overwrite to add customized conditions, create a join, or maybe use a
# namedscope to filter records while authenticating.
# Example:
@@ -167,6 +219,10 @@ module Devise
# super
# end
#
# Finally, notice that Devise also queries for users in other scenarios
# besides authentication, for example when retrieving an user to send
# an e-mail for password reset. In such cases, find_for_authentication
# is not called.
def find_for_authentication(conditions)
find_first_by_auth_conditions(conditions)
end

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,20 +30,18 @@ module Devise
#
module Confirmable
extend ActiveSupport::Concern
include ActionView::Helpers::DateHelper
included do
before_create :generate_confirmation_token, :if => :confirmation_required?
after_create :send_on_create_confirmation_instructions, :if => :confirmation_required?
before_update :postpone_email_change_until_confirmation, :if => :postpone_email_change?
after_update :send_confirmation_instructions, :if => :reconfirmation_required?
after_update :send_confirmation_instructions, :if => :reconfirmation_required?
end
def self.required_fields(klass)
required_methods = [:confirmation_token, :confirmed_at, :confirmation_sent_at]
if klass.reconfirmable
required_methods << :unconfirmed_email
end
required_methods << :unconfirmed_email if klass.reconfirmable
required_methods
end
@@ -50,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
@@ -81,12 +87,17 @@ module Devise
@reconfirmation_required = false
generate_confirmation_token! if self.confirmation_token.blank?
self.devise_mailer.confirmation_instructions(self).deliver
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
@@ -114,21 +125,13 @@ 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
# instructions on creation. This can be overriden
# in models to map to a nice sign up e-mail.
def send_on_create_confirmation_instructions
self.devise_mailer.confirmation_instructions(self).deliver
send_devise_notification(:confirmation_instructions)
end
# Callback to overwrite if confirmation is required or not.
@@ -159,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)
@@ -238,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

@@ -40,7 +40,9 @@ module Devise
# Verifies whether an password (ie from sign in) is the user password.
def valid_password?(password)
return false if encrypted_password.blank?
encryptor_class.compare(encrypted_password, password, self.class.stretches, authenticatable_salt, self.class.pepper)
bcrypt = ::BCrypt::Password.new(encrypted_password)
password = ::BCrypt::Engine.hash_secret("#{password}#{self.class.pepper}", bcrypt.salt)
Devise.secure_compare(password, encrypted_password)
end
# Set password and password confirmation to nil
@@ -62,7 +64,7 @@ module Devise
result = if valid_password?(current_password)
update_attributes(params, *options)
else
self.attributes = params
self.assign_attributes(params, *options)
self.valid?
self.errors.add(:current_password, current_password.blank? ? :blank : :invalid)
false
@@ -73,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.
#
@@ -105,11 +107,7 @@ module Devise
# Digests the password using bcrypt.
def password_digest(password)
encryptor_class.digest(password, self.class.stretches, ::BCrypt::Engine.generate_salt, self.class.pepper)
end
def encryptor_class
Devise::Encryptors::BCrypt
::BCrypt::Password.create("#{password}#{self.class.pepper}", :cost => self.class.stretches).to_s
end
module ClassMethods

View File

@@ -1,80 +0,0 @@
require 'devise/strategies/database_authenticatable'
module Devise
module Models
# Encryptable module adds support to several encryptors wrapping
# them in a salt and pepper mechanism to increase security.
#
# == Options
#
# Encryptable adds the following options to devise_for:
#
# * +pepper+: a random string used to provide a more secure hash.
#
# * +encryptor+: the encryptor going to be used. By default is nil.
#
# == Examples
#
# User.find(1).valid_password?('password123') # returns true/false
#
module Encryptable
extend ActiveSupport::Concern
included do
attr_reader :password, :current_password
attr_accessor :password_confirmation
end
def self.required_fields(klass)
[:password_salt]
end
# Generates password salt when setting the password.
def password=(new_password)
self.password_salt = self.class.password_salt if new_password.present?
super
end
# Overrides authenticatable salt to use the new password_salt
# column. authenticatable_salt is used by `valid_password?`
# and by other modules whenever there is a need for a random
# token based on the user password.
def authenticatable_salt
self.password_salt
end
protected
# Digests the password using the configured encryptor.
def password_digest(password)
if password_salt.present?
encryptor_class.digest(password, self.class.stretches, authenticatable_salt, self.class.pepper)
end
end
def encryptor_class
self.class.encryptor_class
end
module ClassMethods
Devise::Models.config(self, :encryptor)
# Returns the class for the configured encryptor.
def encryptor_class
@encryptor_class ||= case encryptor
when :bcrypt
raise "In order to use bcrypt as encryptor, simply remove :encryptable from your devise model"
when nil
raise "You need to give an :encryptor as option in order to use :encryptable"
else
::Devise::Encryptors.const_get(encryptor.to_s.classify)
end
end
def password_salt
self.encryptor_class.salt(self.stretches)
end
end
end
end
end

View File

@@ -1,3 +1,5 @@
require "devise/hooks/lockable"
module Devise
module Models
# Handles blocking a user access after a certain number of attempts.
@@ -25,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
@@ -36,14 +38,14 @@ module Devise
self.locked_at = Time.now.utc
if unlock_strategy_enabled?(:email)
generate_unlock_token
generate_unlock_token!
send_unlock_instructions
else
save(:validate => false)
end
save(:validate => false)
end
# Unlock a user by cleaning locket_at and failed_attempts.
# Unlock a user by cleaning locked_at and failed_attempts.
def unlock_access!
self.locked_at = nil
self.failed_attempts = 0 if respond_to?(:failed_attempts=)
@@ -58,7 +60,7 @@ module Devise
# Send unlock instructions by email
def send_unlock_instructions
self.devise_mailer.unlock_instructions(self).deliver
send_devise_notification(:unlock_instructions)
end
# Resend the unlock instructions if the user is locked.
@@ -89,8 +91,6 @@ module Devise
unlock_access! if lock_expired?
if super && !access_locked?
self.failed_attempts = 0
save(:validate => false)
true
else
self.failed_attempts ||= 0
@@ -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
@@ -123,6 +127,10 @@ module Devise
self.unlock_token = self.class.unlock_token
end
def generate_unlock_token!
generate_unlock_token && save(:validate => false)
end
# Tells if the lock is expired if :time unlock strategy is active
def lock_expired?
if unlock_strategy_enabled?(:time)
@@ -149,9 +157,9 @@ module Devise
# with an email not found error.
# Options must contain the user email
def send_unlock_instructions(attributes={})
lockable = find_or_initialize_with_errors(unlock_keys, attributes, :not_found)
lockable.resend_unlock_token if lockable.persisted?
lockable
lockable = find_or_initialize_with_errors(unlock_keys, attributes, :not_found)
lockable.resend_unlock_token if lockable.persisted?
lockable
end
# Find a user by its unlock token and try to unlock it.

View File

@@ -45,7 +45,7 @@ module Devise
# Resets reset password token and send reset password instructions by email
def send_reset_password_instructions
generate_reset_password_token! if should_generate_reset_token?
self.devise_mailer.reset_password_instructions(self).deliver
send_devise_notification(:reset_password_instructions)
end
# Checks if the reset password token sent is within the limit time.
@@ -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

@@ -42,7 +42,7 @@ module Devise
attr_accessor :remember_me, :extend_remember_period
def self.required_fields(klass)
[:remember_created_at, :remember_token]
[:remember_created_at]
end
# Generate a new remember token and save the record without validations
@@ -91,7 +91,7 @@ module Devise
protected
def generate_remember_token?
def generate_remember_token? #:nodoc:
respond_to?(:remember_token) && remember_expired?
end
@@ -114,7 +114,7 @@ module Devise
end
# Generate a token checking if one does not already exist in the database.
def remember_token
def remember_token #:nodoc:
generate_token(:remember_token)
end

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:
@@ -56,6 +68,9 @@ module Devise
def after_token_authentication
end
def expire_auth_token_on_timeout
self.class.expire_auth_token_on_timeout
end
module ClassMethods
def find_for_token_authentication(conditions)
@@ -67,7 +82,7 @@ module Devise
generate_token(:authentication_token)
end
::Devise::Models.config(self, :token_authentication_key)
Devise::Models.config(self, :token_authentication_key, :expire_auth_token_on_timeout)
end
end
end

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

@@ -10,7 +10,6 @@ Devise.with_options :model => true do |d|
end
# Other authentications
d.add_module :encryptable
d.add_module :omniauthable, :controller => :omniauth_callbacks, :route => :omniauth_callback
# Misc after

View File

@@ -1,7 +1,7 @@
begin
require "omniauth"
require "omniauth/version"
rescue LoadError => e
rescue LoadError
warn "Could not load 'omniauth'. Please ensure you have the omniauth gem >= 1.0.0 installed and listed in your Gemfile."
raise
end

View File

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

View File

@@ -1,44 +1,3 @@
require 'orm_adapter/adapters/active_record'
module Devise
module Orm
# This module contains some helpers and handle schema (migrations):
#
# create_table :accounts do |t|
# t.database_authenticatable
# t.confirmable
# t.recoverable
# t.rememberable
# t.trackable
# t.lockable
# t.timestamps
# end
#
# However this method does not add indexes. If you need them, here is the declaration:
#
# add_index "accounts", ["email"], :name => "email", :unique => true
# add_index "accounts", ["confirmation_token"], :name => "confirmation_token", :unique => true
# add_index "accounts", ["reset_password_token"], :name => "reset_password_token", :unique => true
#
module ActiveRecord
module Schema
include Devise::Schema
# Tell how to apply schema methods.
def apply_devise_schema(name, type, options={})
@__devise_warning_raised ||= begin
$stderr.puts "\n[DEVISE] You are using t.database_authenticatable and others in your migration " \
"and this feature is deprecated. Please simply use Rails helpers instead as mentioned here:\n" \
"https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0-migration-schema-style\n\n"
true
end
column name, type.to_s.downcase.to_sym, options
end
end
end
end
end
ActiveRecord::Base.extend Devise::Models
ActiveRecord::ConnectionAdapters::Table.send :include, Devise::Orm::ActiveRecord::Schema
ActiveRecord::ConnectionAdapters::TableDefinition.send :include, Devise::Orm::ActiveRecord::Schema
ActiveRecord::Base.extend Devise::Models

View File

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

View File

@@ -43,69 +43,12 @@ module Devise
end
initializer "devise.fix_routes_proxy_missing_respond_to_bug" do
# We can get rid of this once we support Rails > 3.2
# We can get rid of this once we support only Rails > 3.2
ActionDispatch::Routing::RoutesProxy.class_eval do
def respond_to?(method, include_private = false)
super || routes.url_helpers.respond_to?(method)
end
end
end
initializer "devise.deprecations" do
unless defined?(Rails::Generators)
if Devise.case_insensitive_keys == false
warn "\n[DEVISE] Devise.case_insensitive_keys is false which is no longer " \
"supported. Recent Devise versions automatically downcase the e-mail before " \
"saving it to the database but your app isn't using this feature. You can solve " \
"this issue by either:\n\n" \
"1) Setting config.case_insensitive_keys = [:email] in your Devise initializer and " \
"running a migration that will downcase all emails already in the database;\n\n" \
"2) Setting config.case_insensitive_keys = [] (so nothing will be downcased) and " \
"making sure you are not using Devise :validatable (since validatable assumes case" \
"insensitivity)\n"
end
if Devise.apply_schema && defined?(Mongoid)
warn "\n[DEVISE] Devise.apply_schema is true. This means Devise was " \
"automatically configuring your DB. This no longer happens. You should " \
"set Devise.apply_schema to false and manually set the fields used by Devise as shown here: " \
"https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0-migration-schema-style\n"
end
# TODO: Deprecate the true value of this option as well
if Devise.use_salt_as_remember_token == false
warn "\n[DEVISE] Devise.use_salt_as_remember_token is false which is no longer " \
"supported. Devise now only uses the salt as remember token and the remember_token " \
"column can be removed from your models.\n"
end
if Devise.reset_password_within.nil?
warn "\n[DEVISE] Devise.reset_password_within is nil. Please set this value to " \
"an interval (for example, 6.hours) and add a reset_password_sent_at field to " \
"your Devise models (if they don't have one already).\n"
end
end
config.after_initialize do
example = <<-YAML
en:
devise:
registrations:
signed_up_but_unconfirmed: 'A message with a confirmation link has been sent to your email address. Please open the link to activate your account.'
signed_up_but_inactive: 'You have signed up successfully. However, we could not sign you in because your account is not yet activated.'
signed_up_but_locked: 'You have signed up successfully. However, we could not sign you in because your account is locked.'
YAML
if I18n.t(:"devise.registrations.reasons", :default => {}).present?
warn "\n[DEVISE] devise.registrations.reasons in yml files is deprecated, " \
"please use devise.registrations.signed_up_but_REASON instead. The default values are:\n\n#{example}\n"
end
if I18n.t(:"devise.registrations.inactive_signed_up", :default => "").present?
warn "\n[DEVISE] devise.registrations.inactive_signed_up in yml files is deprecated, " \
"please use devise.registrations.signed_up_but_REASON instead. The default values are:\n\n#{example}\n"
end
end
end
end
end

View File

@@ -1,4 +1,5 @@
require "active_support/core_ext/object/try"
require "active_support/core_ext/hash/slice"
module ActionDispatch::Routing
class RouteSet #:nodoc:
@@ -42,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
#
@@ -136,7 +137,7 @@ module ActionDispatch::Routing
#
# devise_for :users, :format => false
#
# * :constraints => works the same as Rails' contraints
# * :constraints => works the same as Rails' constraints
#
# * :defaults => works the same as Rails' defaults
#
@@ -182,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"
@@ -236,7 +237,9 @@ module ActionDispatch::Routing
end
end
# Allow you to add authentication request from the router:
# Allow you to add authentication request from the router.
# Takes an optional scope and block to provide constraints
# on the model instance itself.
#
# authenticate do
# resources :post
@@ -246,9 +249,13 @@ module ActionDispatch::Routing
# resources :users
# end
#
def authenticate(scope=nil)
# authenticate :user, lambda {|u| u.role == "admin"} do
# root :to => "admin/dashboard#show"
# end
#
def authenticate(scope=nil, block=nil)
constraint = lambda do |request|
request.env["warden"].authenticate!(:scope => scope)
request.env["warden"].authenticate!(:scope => scope) && (block.nil? || block.call(request.env["warden"].user(scope)))
end
constraints(constraint) do
@@ -257,7 +264,8 @@ module ActionDispatch::Routing
end
# Allow you to route based on whether a scope is authenticated. You
# can optionally specify which scope.
# can optionally specify which scope and a block. The block accepts
# a model and allows extra constraints to be done on the instance.
#
# authenticated :admin do
# root :to => 'admin/dashboard#show'
@@ -267,11 +275,15 @@ module ActionDispatch::Routing
# root :to => 'dashboard#show'
# end
#
# authenticated :user, lambda {|u| u.role == "admin"} do
# root :to => "admin/dashboard#show"
# end
#
# root :to => 'landing#show'
#
def authenticated(scope=nil)
def authenticated(scope=nil, block=nil)
constraint = lambda do |request|
request.env["warden"].authenticate? :scope => scope
request.env["warden"].authenticate?(:scope => scope) && (block.nil? || block.call(request.env["warden"].user(scope)))
end
constraints(constraint) do
@@ -367,16 +379,54 @@ module ActionDispatch::Routing
:cancel => mapping.path_names[:cancel]
}
resource :registration, :only => [:new, :create, :edit, :update, :destroy], :path => mapping.path_names[:registration],
:path_names => path_names, :controller => controllers[:registrations] do
options = {
:only => [:new, :create, :edit, :update, :destroy],
:path => mapping.path_names[:registration],
:path_names => path_names,
:controller => controllers[:registrations]
}
resource :registration, options do
get :cancel
end
end
def devise_omniauth_callback(mapping, controllers) #:nodoc:
path, @scope[:path] = @scope[:path], nil
path_prefix = "/#{mapping.path}/auth".squeeze("/")
path_prefix = Devise.omniauth_path_prefix || "/#{mapping.path}/auth".squeeze("/")
set_omniauth_path_prefix!(path_prefix)
providers = Regexp.union(mapping.to.omniauth_providers.map(&:to_s))
match "#{path_prefix}/:provider",
:constraints => { :provider => providers },
:to => "#{controllers[:omniauth_callbacks]}#passthru",
:as => :omniauth_authorize
match "#{path_prefix}/:action/callback",
:constraints => { :action => providers },
:to => controllers[:omniauth_callbacks],
:as => :omniauth_callback
ensure
@scope[:path] = path
end
DEVISE_SCOPE_KEYS = [:as, :path, :module, :constraints, :defaults, :options]
def with_devise_exclusive_scope(new_path, new_as, options) #:nodoc:
old = {}
DEVISE_SCOPE_KEYS.each { |k| old[k] = @scope[k] }
new = { :as => new_as, :path => new_path, :module => nil }
new.merge!(options.slice(:constraints, :defaults, :options))
@scope.merge!(new)
yield
ensure
@scope.merge!(old)
end
def set_omniauth_path_prefix!(path_prefix) #:nodoc:
if ::OmniAuth.config.path_prefix && ::OmniAuth.config.path_prefix != path_prefix
raise "Wrong OmniAuth configuration. If you are getting this exception, it means that either:\n\n" \
"1) You are manually setting OmniAuth.config.path_prefix and it doesn't match the Devise one\n" \
@@ -385,22 +435,6 @@ module ActionDispatch::Routing
else
::OmniAuth.config.path_prefix = path_prefix
end
match "#{path_prefix}/:action/callback", :constraints => { :action => Regexp.union(mapping.to.omniauth_providers.map(&:to_s)) },
:to => controllers[:omniauth_callbacks], :as => :omniauth_callback
ensure
@scope[:path] = path
end
def with_devise_exclusive_scope(new_path, new_as, options) #:nodoc:
old_as, old_path, old_module, old_constraints, old_defaults, old_options =
*@scope.values_at(:as, :path, :module, :constraints, :defaults, :options)
@scope[:as], @scope[:path], @scope[:module], @scope[:constraints], @scope[:defaults], @scope[:options] =
new_as, new_path, nil, *options.values_at(:constraints, :defaults, :options)
yield
ensure
@scope[:as], @scope[:path], @scope[:module], @scope[:constraints], @scope[:defaults], @scope[:options] =
old_as, old_path, old_module, old_constraints, old_defaults, old_options
end
def raise_no_devise_method_error!(klass) #:nodoc:

View File

@@ -21,17 +21,23 @@ class Warden::SessionSerializer
end
def deserialize(keys)
klass, *args = keys
klass_name, *args = keys
begin
ActiveSupport::Inflector.constantize(klass).serialize_from_session(*args)
klass = ActiveSupport::Inflector.constantize(klass_name)
if klass.respond_to? :serialize_from_session
klass.serialize_from_session(*args)
else
Rails.logger.warn "[Devise] Stored serialized class #{klass_name} seems not to be Devise enabled anymore. Did you do that on purpose?"
nil
end
rescue NameError => e
if e.message =~ /uninitialized constant/
Rails.logger.debug "[Devise] Trying to deserialize invalid class #{klass}"
Rails.logger.debug "[Devise] Trying to deserialize invalid class #{klass_name}"
nil
else
raise
end
end
end
end
end

View File

@@ -1,109 +0,0 @@
module Devise
# Holds devise schema information. To use it, just include its methods
# and overwrite the apply_schema method.
module Schema
# Creates encrypted_password, and email when it is used as an authentication
# key (default).
#
# == Options
# * :null - When true, allow columns to be null.
# * :default - Set to "" when :null is false, unless overridden.
#
# == Notes
# For Datamapper compatibility, we explicitly hardcode the limit for the
# encrypter password field in 128 characters.
def database_authenticatable(options={})
null = options[:null] || false
default = options.key?(:default) ? options[:default] : ("" if null == false)
include_email = !respond_to?(:authentication_keys) || self.authentication_keys.include?(:email)
apply_devise_schema :email, String, :null => null, :default => default if include_email
apply_devise_schema :encrypted_password, String, :null => null, :default => default, :limit => 128
end
# Creates password salt for encryption support when using encryptors other
# than the database_authenticable default of bcrypt.
def encryptable
apply_devise_schema :password_salt, String
end
# Creates authentication_token.
def token_authenticatable
apply_devise_schema :authentication_token, String
end
# Creates confirmation_token, confirmed_at and confirmation_sent_at.
def confirmable
apply_devise_schema :confirmation_token, String
apply_devise_schema :confirmed_at, DateTime
apply_devise_schema :confirmation_sent_at, DateTime
end
# Creates unconfirmed_email
def reconfirmable
apply_devise_schema :unconfirmed_email, String
end
# Creates reset_password_token and reset_password_sent_at.
#
# == Options
# * :reset_within - When true, adds a column that reset passwords within some date
def recoverable(options={})
use_within = options.fetch(:reset_within, Devise.reset_password_within.present?)
apply_devise_schema :reset_password_token, String
apply_devise_schema :reset_password_sent_at, DateTime if use_within
end
# Creates remember_token and remember_created_at.
#
# == Options
# * :use_salt - When true, does not create a remember_token and use password_salt instead.
def rememberable(options={})
use_salt = options.fetch(:use_salt, Devise.use_salt_as_remember_token)
apply_devise_schema :remember_token, String unless use_salt
apply_devise_schema :remember_created_at, DateTime
end
# Creates sign_in_count, current_sign_in_at, last_sign_in_at,
# current_sign_in_ip, last_sign_in_ip.
def trackable
apply_devise_schema :sign_in_count, Integer, :default => 0
apply_devise_schema :current_sign_in_at, DateTime
apply_devise_schema :last_sign_in_at, DateTime
apply_devise_schema :current_sign_in_ip, String
apply_devise_schema :last_sign_in_ip, String
end
# Creates failed_attempts, unlock_token and locked_at depending on the options given.
#
# == Options
# * :unlock_strategy - The strategy used for unlock. Can be :time, :email, :both (default), :none.
# If :email or :both, creates a unlock_token field.
# * :lock_strategy - The strategy used for locking. Can be :failed_attempts (default) or :none.
def lockable(options={})
unlock_strategy = options[:unlock_strategy]
unlock_strategy ||= self.unlock_strategy if respond_to?(:unlock_strategy)
unlock_strategy ||= :both
lock_strategy = options[:lock_strategy]
lock_strategy ||= self.lock_strategy if respond_to?(:lock_strategy)
lock_strategy ||= :failed_attempts
if lock_strategy == :failed_attempts
apply_devise_schema :failed_attempts, Integer, :default => 0
end
if [:both, :email].include?(unlock_strategy)
apply_devise_schema :unlock_token, String
end
apply_devise_schema :locked_at, DateTime
end
# Overwrite with specific modification to create your own schema.
def apply_devise_schema(name, type, options={})
raise NotImplementedError
end
end
end

View File

@@ -9,7 +9,7 @@ module Devise
attr_accessor :authentication_hash, :authentication_type, :password
def store?
!mapping.to.skip_session_storage.include?(authentication_type)
super && !mapping.to.skip_session_storage.include?(authentication_type)
end
def valid?
@@ -18,13 +18,24 @@ module Devise
private
# Simply invokes valid_for_authentication? with the given block and deal with the result.
# Receives a resource and check if it is valid by calling valid_for_authentication?
# An optional block that will be triggered while validating can be optionally
# given as parameter. Check Devise::Models::Authenticable.valid_for_authentication?
# for more information.
#
# In case the resource can't be validated, it will fail with the given
# unauthenticated_message.
def validate(resource, &block)
unless resource
ActiveSupport::Deprecation.warn "an empty resource was given to #{self.class.name}#validate. " \
"Please ensure the resource is not nil", caller
end
result = resource && resource.valid_for_authentication?(&block)
case result
when Symbol, String
ActiveSupport::Deprecation.warn "valid_for_authentication should return a boolean value"
ActiveSupport::Deprecation.warn "valid_for_authentication? should return a boolean value"
fail!(result)
return false
end
@@ -84,8 +95,8 @@ module Devise
# Extract the appropriate subhash for authentication from params.
def params_auth_hash
params[scope]
end
params[scope]
end
# Extract a hash with attributes:values from the http params.
def http_auth_hash

View File

@@ -2,6 +2,11 @@ module Devise
module Strategies
# Base strategy for Devise. Responsible for verifying correct scope and mapping.
class Base < ::Warden::Strategies::Base
# Whenever CSRF cannot be verified, we turn off any kind of storage
def store?
!env["devise.skip_storage"]
end
# Checks if a valid scope was given for devise and find mapping based on this scope.
def mapping
@mapping ||= begin

View File

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

View File

@@ -1,4 +1,4 @@
require 'devise/strategies/base'
require 'devise/strategies/authenticatable'
module Devise
module Strategies
@@ -19,11 +19,13 @@ module Devise
def authenticate!
resource = mapping.to.serialize_from_cookie(*remember_cookie)
unless resource
cookies.delete(remember_key)
return pass
end
if validate(resource)
success!(resource)
elsif !halted?
cookies.delete(remember_key)
pass
end
end

View File

@@ -16,12 +16,11 @@ module Devise
def authenticate!
resource = mapping.to.find_for_token_authentication(authentication_hash)
return fail(:invalid_token) unless resource
if validate(resource)
resource.after_token_authentication
success!(resource)
elsif !halted?
fail(:invalid_token)
end
end

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
@@ -70,22 +71,61 @@ module Devise
def _catch_warden(&block)
result = catch(:warden, &block)
if result.is_a?(Hash) && !warden.custom_failure? && !@controller.send(:performed?)
result[:action] ||= :unauthenticated
env = @controller.request.env
env = @controller.request.env
env["PATH_INFO"] = "/#{result[:action]}"
env["warden.options"] = result
Warden::Manager._run_callbacks(:before_failure, env, result)
result ||= {}
status, headers, body = Devise.warden_config[:failure_app].call(env).to_a
@controller.send :render, :status => status, :text => body,
:content_type => headers["Content-Type"], :location => headers["Location"]
nil
# Set the response. In production, the rack result is returned
# from Warden::Manager#call, which the following is modelled on.
case result
when Array
if result.first == 401 && intercept_401?(env) # does this happen during testing?
_process_unauthenticated(env)
else
result
end
when Hash
_process_unauthenticated(env, result)
else
result
end
end
def _process_unauthenticated(env, options = {})
options[:action] ||= :unauthenticated
proxy = env['warden']
result = options[:result] || proxy.result
ret = case result
when :redirect
body = proxy.message || "You are being redirected to #{proxy.headers['Location']}"
[proxy.status, proxy.headers, [body]]
when :custom
proxy.custom_response
else
env["PATH_INFO"] = "/#{options[:action]}"
env["warden.options"] = options
Warden::Manager._run_callbacks(:before_failure, env, options)
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
# ensure that the controller response is set up. In production, this is
# not necessary since warden returns the results to rack. However, at
# testing time, we want the response to be available to the testing
# framework to verify what would be returned to rack.
if ret.is_a?(Array)
# ensure the controller response is set to our response.
@controller.response ||= @response
@response.status = ret.first
@response.headers = ret.second
@response.body = ret.third
end
ret
end
end
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.0.rc".freeze
VERSION = "2.2.2".freeze
end

View File

@@ -22,10 +22,21 @@ module ActiveRecord
end
def inject_devise_content
inject_into_class(model_path, class_name, model_contents + <<CONTENT) if model_exists?
content = model_contents + <<CONTENT
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
CONTENT
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"
inject_into_class(model_path, class_path.last, content) if model_exists?
end
def migration_data
@@ -48,9 +59,6 @@ CONTENT
t.string :current_sign_in_ip
t.string :last_sign_in_ip
## Encryptable
# t.string :password_salt
## Confirmable
# t.string :confirmation_token
# t.datetime :confirmed_at

View File

@@ -4,7 +4,8 @@ module Devise
def model_contents
<<-CONTENT
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable

View File

@@ -10,6 +10,11 @@ module Devise
argument :scope, :required => false, :default => nil,
:desc => "The scope to copy views to"
# Le sigh, ensure Thor won't handle opts as args
# It should be fixed in future Rails releases
class_option :form_builder, :aliases => "-b"
class_option :markerb
public_task :copy_views
end
@@ -98,6 +103,7 @@ module Devise
:desc => "The scope to copy views to"
invoke SharedViewsGenerator
hook_for :form_builder, :aliases => "-b",
:desc => "Form builder to be used",
:default => defined?(SimpleForm) ? "simple_form_for" : "form_for"

View File

@@ -20,9 +20,9 @@ module Mongoid
def migration_data
<<RUBY
## 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
field :reset_password_sent_at, :type => Time
@@ -37,9 +37,6 @@ module Mongoid
field :current_sign_in_ip, :type => String
field :last_sign_in_ip, :type => String
## Encryptable
# field :password_salt, :type => String
## Confirmable
# field :confirmation_token, :type => String
# field :confirmed_at, :type => Time

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

@@ -9,9 +9,6 @@ Devise.setup do |config|
# Configure the class responsible to send e-mails.
# config.mailer = "Devise::Mailer"
# Automatically apply schema changes in tableless databases
config.apply_schema = false
# ==> ORM configuration
# Load and configure the ORM. Supports :active_record (default) and
# :mongoid (bson_ext recommended) by default. Other ORMs may be
@@ -95,7 +92,15 @@ Devise.setup do |config|
# the user cannot access the website without confirming his account.
# config.allow_unconfirmed_access_for = 2.days
# If true, requires any email changes to be confirmed (exctly the same way as
# 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
# unconfirmed email column, and copied to email column on successful confirmation.
@@ -111,17 +116,13 @@ Devise.setup do |config|
# If true, extends the user's remember period when remembered via cookie.
# config.extend_remember_period = false
# If true, uses the password salt as remember token. This should be turned
# to false if you are not using database authenticatable.
config.use_salt_as_remember_token = true
# Options to be passed to the created cookie. For instance, you can set
# :secure => true in order to force SSL only cookies.
# 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
@@ -133,6 +134,9 @@ Devise.setup do |config|
# 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
# ==> Configuration for :lockable
# Defines which strategy will be used to lock an account.
# :failed_attempts = Locks an account after a number of failed attempts to sign in.
@@ -188,9 +192,8 @@ Devise.setup do |config|
# devise role declared in your routes (usually :user).
# config.default_scope = :user
# Configure sign_out behavior.
# Sign_out action can be scoped (i.e. /users/sign_out affects only :user scope).
# The default is true, which means any logout action will sign out all active scopes.
# Set this configuration to false if you want /users/sign_out to sign out
# only the current scope. By default, Devise signs out all scopes.
# config.sign_out_all_scopes = true
# ==> Navigation configuration
@@ -220,4 +223,18 @@ Devise.setup do |config|
# manager.intercept_401 = false
# manager.default_strategies(:scope => :user).unshift :some_external_strategy
# end
# ==> Mountable engine configurations
# When using Devise inside an engine, let's call it `MyEngine`, and this engine
# is mountable, there are some extra configurations to be taken into account.
# The following options are available, assuming the engine is mounted as:
#
# mount MyEngine, at: "/my_engine"
#
# The router that invoked `devise_for`, in the example above, would be:
# config.router_name = :my_engine
#
# 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

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,14 +2,15 @@
<%= 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="inputs">
<%= f.input :email, :required => true %>
<div class="form-inputs">
<%= f.input :email, :required => true, :autofocus => true %>
</div>
<div class="actions">
<div class="form-actions">
<%= f.button :submit, "Resend confirmation instructions" %>
</div>
<% end %>
<%= render :partial => "devise/shared/links" %>
<%= render "devise/shared/links" %>

View File

@@ -6,14 +6,14 @@
<%= f.input :reset_password_token, :as => :hidden %>
<%= f.full_error :reset_password_token %>
<div class="inputs">
<%= f.input :password, :label => "New password", :required => true %>
<div class="form-inputs">
<%= f.input :password, :label => "New password", :required => true, :autofocus => true %>
<%= f.input :password_confirmation, :label => "Confirm your new password", :required => true %>
</div>
<div class="actions">
<div class="form-actions">
<%= f.button :submit, "Change my password" %>
</div>
<% end %>
<%= render :partial => "devise/shared/links" %>
<%= render "devise/shared/links" %>

View File

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

View File

@@ -3,20 +3,25 @@
<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %>
<%= f.error_notification %>
<div class="inputs">
<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 %>
</div>
<div class="actions">
<div class="form-actions">
<%= f.button :submit, "Update" %>
</div>
<% end %>
<h3>Cancel my account</h3>
<p>Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), :confirm => "Are you sure?", :method => :delete %>.</p>
<p>Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), :data => { :confirm => "Are you sure?" }, :method => :delete %>.</p>
<%= link_to "Back", :back %>

View File

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

View File

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

View File

@@ -2,14 +2,15 @@
<%= 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="inputs">
<%= f.input :email, :required => true %>
<div class="form-inputs">
<%= f.input :email, :required => true, :autofocus => true %>
</div>
<div class="actions">
<div class="form-actions">
<%= f.button :submit, "Resend unlock instructions" %>
</div>
<% end %>
<%= render :partial => "devise/shared/links" %>
<%= render "devise/shared/links" %>

View File

@@ -0,0 +1,62 @@
require 'test_helper'
require 'ostruct'
require 'warden/strategies/base'
require 'devise/test_helpers'
class CustomStrategyController < ActionController::Base
def new
warden.authenticate!(:custom_strategy)
end
end
# These tests are to prove that a warden strategy can successfully
# return a custom response, including a specific status code and
# custom http response headers. This does work in production,
# however, at the time of writing this, the Devise test helpers do
# not recognise the custom response and proceed to calling the
# Failure App. This makes it impossible to write tests for a
# strategy that return a custom response with Devise.
class CustomStrategy < Warden::Strategies::Base
def authenticate!
custom_headers = { "X-FOO" => "BAR" }
response = Rack::Response.new("BAD REQUEST", 400, custom_headers)
custom! response.finish
end
end
class CustomStrategyTest < ActionController::TestCase
tests CustomStrategyController
include Devise::TestHelpers
setup do
Warden::Strategies.add(:custom_strategy, CustomStrategy)
end
teardown do
Warden::Strategies._strategies.delete(:custom_strategy)
end
test "custom strategy can return its own status code" do
ret = get :new
# check the returned rack array
assert ret.is_a?(Array)
assert_equal 400, ret.first
# check the saved response as well. This is purely so that the response is available to the testing framework
# for verification. In production, the above array would be delivered directly to Rack.
assert_response 400
end
test "custom strategy can return custom headers" do
ret = get :new
# check the returned rack array
assert ret.is_a?(Array)
assert_equal ret.third['X-FOO'], 'BAR'
# check the saved response headers as well.
assert_equal response.headers['X-FOO'], 'BAR'
end
end

View File

@@ -139,30 +139,27 @@ class ControllerAuthenticatableTest < ActionController::TestCase
assert_equal nil, @controller.instance_variable_get(:@current_admin)
end
test 'sign out clears up any signed in user by scope' do
test 'sign out logs out and clears up any signed in user by scope' do
user = User.new
@mock_warden.expects(:user).with(:scope => :user, :run_callbacks => false).returns(user)
@mock_warden.expects(:logout).with(:user).returns(true)
@mock_warden.expects(:clear_strategies_cache!).with(:scope => :user).returns(true)
@controller.instance_variable_set(:@current_user, user)
@controller.sign_out(:user)
assert_equal nil, @controller.instance_variable_get(:@current_user)
end
test 'sign out proxy to logout on warden' do
@mock_warden.expects(:user).with(:scope => :user, :run_callbacks => false).returns(true)
@mock_warden.expects(:logout).with(:user).returns(true)
@controller.sign_out(:user)
end
test 'sign out accepts a resource as argument' do
@mock_warden.expects(:user).with(:scope => :user, :run_callbacks => false).returns(true)
@mock_warden.expects(:logout).with(:user).returns(true)
@mock_warden.expects(:clear_strategies_cache!).with(:scope => :user).returns(true)
@controller.sign_out(User.new)
end
test 'sign out without args proxy to sign out all scopes' do
@mock_warden.expects(:user).times(Devise.mappings.size)
@mock_warden.expects(:logout).with().returns(true)
@mock_warden.expects(:clear_strategies_cache!).with().returns(true)
@controller.sign_out
end
@@ -232,6 +229,7 @@ class ControllerAuthenticatableTest < ActionController::TestCase
swap Devise, :sign_out_all_scopes => false do
@mock_warden.expects(:user).with(:scope => :admin, :run_callbacks => false).returns(true)
@mock_warden.expects(:logout).with(:admin).returns(true)
@mock_warden.expects(:clear_strategies_cache!).with(:scope => :admin).returns(true)
@controller.expects(:redirect_to).with(admin_root_path)
@controller.instance_eval "def after_sign_out_path_for(resource); admin_root_path; end"
@controller.sign_out_and_redirect(:admin)
@@ -242,6 +240,7 @@ class ControllerAuthenticatableTest < ActionController::TestCase
swap Devise, :sign_out_all_scopes => true do
@mock_warden.expects(:user).times(Devise.mappings.size)
@mock_warden.expects(:logout).with().returns(true)
@mock_warden.expects(:clear_strategies_cache!).with().returns(true)
@controller.expects(:redirect_to).with(admin_root_path)
@controller.instance_eval "def after_sign_out_path_for(resource); admin_root_path; end"
@controller.sign_out_and_redirect(:admin)

View File

@@ -33,6 +33,13 @@ class HelpersTest < ActionController::TestCase
assert_equal user, @controller.instance_variable_get(:@user)
end
test 'get resource params from request params using resource name as key' do
user_params = {'name' => 'Shirley Templar'}
@controller.stubs(:params).returns(HashWithIndifferentAccess.new({'user' => user_params}))
assert_equal user_params, @controller.resource_params
end
test 'resources methods are not controller actions' do
assert @controller.class.action_methods.empty?
end
@@ -88,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

@@ -4,6 +4,43 @@ class SessionsControllerTest < ActionController::TestCase
tests Devise::SessionsController
include Devise::TestHelpers
test "#create works even with scoped views" do
swap Devise, :scoped_views => true do
request.env["devise.mapping"] = Devise.mappings[:user]
post :create
assert_equal 200, @response.status
assert_template "users/sessions/new"
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 => {
@@ -13,4 +50,36 @@ class SessionsControllerTest < ActionController::TestCase
assert_equal 200, @response.status
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]
ActiveRecord::Base.mass_assignment_sanitizer = :strict
User.class_eval { attr_protected :email }
begin
assert_nothing_raised ActiveModel::MassAssignmentSecurity::Error do
get :new, :user => { :email => "allez viens!" }
end
ensure
ActiveRecord::Base.mass_assignment_sanitizer = :logger
User.class_eval { attr_accessible :email }
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

@@ -1,30 +0,0 @@
require 'test_helper'
class Encryptors < ActiveSupport::TestCase
test 'should match a password created by authlogic' do
authlogic = "b623c3bc9c775b0eb8edb218a382453396fec4146422853e66ecc4b6bc32d7162ee42074dcb5f180a770dc38b5df15812f09bbf497a4a1b95fe5e7d2b8eb7eb4"
encryptor = Devise::Encryptors::AuthlogicSha512.digest('123mudar', 20, 'usZK_z_EAaF61Gwkw-ed', '')
assert_equal authlogic, encryptor
end
test 'should match a password created by restful_authentication' do
restful_authentication = "93110f71309ce91366375ea44e2a6f5cc73fa8d4"
encryptor = Devise::Encryptors::RestfulAuthenticationSha1.digest('123mudar', 10, '48901d2b247a54088acb7f8ea3e695e50fe6791b', 'fee9a51ec0a28d11be380ca6dee6b4b760c1a3bf')
assert_equal restful_authentication, encryptor
end
test 'should match a password created by clearance' do
clearance = "0f40bbae18ddefd7066276c3ef209d40729b0378"
encryptor = Devise::Encryptors::ClearanceSha1.digest('123mudar', nil, '65c58472c207c829f28c68619d3e3aefed18ab3f', nil)
assert_equal clearance, encryptor
end
Devise::ENCRYPTORS_LENGTH.each do |key, value|
test "should have length #{value} for #{key.inspect}" do
swap Devise, :encryptor => key do
encryptor = Devise::Encryptors.const_get(key.to_s.classify)
assert_equal value, encryptor.digest('a', 4, encryptor.salt(4), nil).size
end
end
end
end

View File

@@ -29,20 +29,20 @@ class FailureTest < ActiveSupport::TestCase
end
context 'When redirecting' do
test 'return to the default redirect location' do
test 'returns to the default redirect location' do
call_failure
assert_equal 302, @response.first
assert_equal 'You need to sign in or sign up before continuing.', @request.flash[:alert]
assert_equal 'http://test.host/users/sign_in', @response.second['Location']
end
test 'return to the default redirect location for wildcard requests' do
test 'returns to the default redirect location for wildcard requests' do
call_failure 'action_dispatch.request.formats' => nil, 'HTTP_ACCEPT' => '*/*'
assert_equal 302, @response.first
assert_equal 'http://test.host/users/sign_in', @response.second['Location']
end
test 'return to the root path if no session path is available' do
test 'returns to the root path if no session path is available' do
swap Devise, :router_name => :fake_app do
call_failure :app => RootFailureApp
assert_equal 302, @response.first
@@ -51,6 +51,16 @@ class FailureTest < ActiveSupport::TestCase
end
end
if Rails.application.config.respond_to?(:relative_url_root)
test 'returns to the default redirect location considering the relative url root' do
swap Rails.application.config, :relative_url_root => "/sample" do
call_failure
assert_equal 302, @response.first
assert_equal 'http://test.host/sample/users/sign_in', @response.second['Location']
end
end
end
test 'uses the proxy failure message as symbol' do
call_failure('warden' => OpenStruct.new(:message => :invalid))
assert_equal 'Invalid email or password.', @request.flash[:alert]

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"
@@ -34,4 +40,36 @@ if DEVISE_ORM == :active_record
assert_no_migration "db/migrate/devise_create_monsters.rb"
end
end
end
module RailsEngine
class Engine < Rails::Engine
isolate_namespace RailsEngine
end
end
def simulate_inside_engine(engine, namespace)
if Rails::Generators.respond_to?(:namespace=)
swap Rails::Generators, :namespace => namespace do
yield
end
else
swap Rails, :application => engine.instance do
yield
end
end
end
class ActiveRecordEngineGeneratorTest < Rails::Generators::TestCase
tests ActiveRecord::Generators::DeviseGenerator
destination File.expand_path("../../tmp", __FILE__)
setup :prepare_destination
test "all files are properly created" do
simulate_inside_engine(RailsEngine::Engine, RailsEngine) do
run_generator ["monster"]
assert_file "app/models/rails_engine/monster.rb", /devise/,/attr_accessible (:[a-z_]+(, )?)+/
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

@@ -75,80 +75,6 @@ class AuthenticationSanityTest < ActionController::IntegrationTest
assert_not warden.authenticated?(:admin)
end
test 'not signed in as admin should not be able to access private route restricted to admins' do
get private_path
assert_redirected_to new_admin_session_path
assert_not warden.authenticated?(:admin)
end
test 'signed in as user should not be able to access private route restricted to admins' do
sign_in_as_user
assert warden.authenticated?(:user)
assert_not warden.authenticated?(:admin)
get private_path
assert_redirected_to new_admin_session_path
end
test 'signed in as admin should be able to access private route restricted to admins' do
sign_in_as_admin
assert warden.authenticated?(:admin)
assert_not warden.authenticated?(:user)
get private_path
assert_response :success
assert_template 'home/private'
assert_contain 'Private!'
end
test 'signed in as admin should get admin dashboard' do
sign_in_as_admin
assert warden.authenticated?(:admin)
assert_not warden.authenticated?(:user)
get dashboard_path
assert_response :success
assert_template 'home/admin'
assert_contain 'Admin dashboard'
end
test 'signed in as user should get user dashboard' do
sign_in_as_user
assert warden.authenticated?(:user)
assert_not warden.authenticated?(:admin)
get dashboard_path
assert_response :success
assert_template 'home/user'
assert_contain 'User dashboard'
end
test 'not signed in should get no dashboard' do
assert_raises ActionController::RoutingError do
get dashboard_path
end
end
test 'signed in user should not see unauthenticated page' do
sign_in_as_user
assert warden.authenticated?(:user)
assert_not warden.authenticated?(:admin)
assert_raises ActionController::RoutingError do
get join_path
end
end
test 'not signed in users should see unautheticated page' do
get join_path
assert_response :success
assert_template 'home/join'
assert_contain 'Join'
end
test 'signed in as user should not be able to access admins actions' do
sign_in_as_user
assert warden.authenticated?(:user)
@@ -208,6 +134,126 @@ class AuthenticationSanityTest < ActionController::IntegrationTest
end
end
class AuthenticationRoutesRestrictions < ActionController::IntegrationTest
test 'not signed in should not be able to access private route (authenticate denied)' do
get private_path
assert_redirected_to new_admin_session_path
assert_not warden.authenticated?(:admin)
end
test 'signed in as user should not be able to access private route restricted to admins (authenticate denied)' do
sign_in_as_user
assert warden.authenticated?(:user)
assert_not warden.authenticated?(:admin)
get private_path
assert_redirected_to new_admin_session_path
end
test 'signed in as admin should be able to access private route restricted to admins (authenticate accepted)' do
sign_in_as_admin
assert warden.authenticated?(:admin)
assert_not warden.authenticated?(:user)
get private_path
assert_response :success
assert_template 'home/private'
assert_contain 'Private!'
end
test 'signed in as inactive admin should not be able to access private/active route restricted to active admins (authenticate denied)' do
sign_in_as_admin(:active => false)
assert warden.authenticated?(:admin)
assert_not warden.authenticated?(:user)
assert_raises ActionController::RoutingError do
get "/private/active"
end
end
test 'signed in as active admin should be able to access private/active route restricted to active admins (authenticate accepted)' do
sign_in_as_admin(:active => true)
assert warden.authenticated?(:admin)
assert_not warden.authenticated?(:user)
get private_active_path
assert_response :success
assert_template 'home/private'
assert_contain 'Private!'
end
test 'signed in as admin should get admin dashboard (authenticated accepted)' do
sign_in_as_admin
assert warden.authenticated?(:admin)
assert_not warden.authenticated?(:user)
get dashboard_path
assert_response :success
assert_template 'home/admin'
assert_contain 'Admin dashboard'
end
test 'signed in as user should get user dashboard (authenticated accepted)' do
sign_in_as_user
assert warden.authenticated?(:user)
assert_not warden.authenticated?(:admin)
get dashboard_path
assert_response :success
assert_template 'home/user'
assert_contain 'User dashboard'
end
test 'not signed in should get no dashboard (authenticated denied)' do
assert_raises ActionController::RoutingError do
get dashboard_path
end
end
test 'signed in as inactive admin should not be able to access dashboard/active route restricted to active admins (authenticated denied)' do
sign_in_as_admin(:active => false)
assert warden.authenticated?(:admin)
assert_not warden.authenticated?(:user)
assert_raises ActionController::RoutingError do
get "/dashboard/active"
end
end
test 'signed in as active admin should be able to access dashboard/active route restricted to active admins (authenticated accepted)' do
sign_in_as_admin(:active => true)
assert warden.authenticated?(:admin)
assert_not warden.authenticated?(:user)
get dashboard_active_path
assert_response :success
assert_template 'home/admin_dashboard'
assert_contain 'Admin dashboard'
end
test 'signed in user should not see unauthenticated page (unauthenticated denied)' do
sign_in_as_user
assert warden.authenticated?(:user)
assert_not warden.authenticated?(:admin)
assert_raises ActionController::RoutingError do
get join_path
end
end
test 'not signed in users should see unautheticated page (unauthenticated accepted)' do
get join_path
assert_response :success
assert_template 'home/join'
assert_contain 'Join'
end
end
class AuthenticationRedirectTest < ActionController::IntegrationTest
test 'redirect from warden shows sign in or sign up message' do
get admins_path
@@ -410,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
@@ -437,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
@@ -447,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
@@ -461,16 +507,35 @@ class AuthenticationOthersTest < ActionController::IntegrationTest
test 'sign out with xml format returns ok response' do
sign_in_as_user
get destroy_user_session_path(:format => 'xml')
assert_response :ok
assert_response :no_content
assert_not warden.authenticated?(:user)
end
test 'sign out with json format returns empty json response' do
sign_in_as_user
get destroy_user_session_path(:format => 'json')
assert_response :ok
assert_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")
@@ -180,7 +204,7 @@ class ConfirmationTest < ActionController::IntegrationTest
fill_in 'email', :with => user.email
click_button 'Resend confirmation instructions'
assert_contain "If your e-mail exists on our database, you will receive an email with instructions about how to confirm your account in a few minutes."
assert_contain "If your email address exists in our database, you will receive an email with instructions about how to confirm your account in a few minutes."
assert_current_url "/users/sign_in"
end
end
@@ -196,7 +220,7 @@ class ConfirmationTest < ActionController::IntegrationTest
assert_not_contain "1 error prohibited this user from being saved:"
assert_not_contain "Email not found"
assert_contain "If your e-mail exists on our database, you will receive an email with instructions about how to confirm your account in a few minutes."
assert_contain "If your email address exists in our database, you will receive an email with instructions about how to confirm your account in a few minutes."
assert_current_url "/users/sign_in"
end
end
@@ -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

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