mirror of
https://github.com/heartcombo/devise.git
synced 2026-01-09 23:58:06 -05:00
Compare commits
389 Commits
v3.5.1
...
drv-improv
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ab79083696 | ||
|
|
88724e10ad | ||
|
|
30405943b5 | ||
|
|
9c0dccfec1 | ||
|
|
9fe7040db9 | ||
|
|
4c3838bb75 | ||
|
|
48aa20897f | ||
|
|
2a5f8b6688 | ||
|
|
8ee01fc10b | ||
|
|
d7985e7ddb | ||
|
|
ae8b0914a9 | ||
|
|
6720f93d2c | ||
|
|
13d4fd4088 | ||
|
|
bbd614a725 | ||
|
|
eb0540e028 | ||
|
|
08374f1d33 | ||
|
|
a5f8cd9d32 | ||
|
|
54e7a3b9d9 | ||
|
|
e761a8df2b | ||
|
|
65d8e94ed9 | ||
|
|
83b88353b5 | ||
|
|
39227bd494 | ||
|
|
e841c4c5ef | ||
|
|
e90ba2fbcb | ||
|
|
e6b5f5f31a | ||
|
|
245b1f9de0 | ||
|
|
e05523f767 | ||
|
|
2c8727ad42 | ||
|
|
b1508e93e1 | ||
|
|
5b57aa0b85 | ||
|
|
768656deb9 | ||
|
|
fe10a5b17a | ||
|
|
22784cb55a | ||
|
|
656720583f | ||
|
|
a20cca6873 | ||
|
|
8d78dc072f | ||
|
|
b2a2e85412 | ||
|
|
c2c74b0a39 | ||
|
|
92bb772d36 | ||
|
|
783234c72a | ||
|
|
2671f19cb1 | ||
|
|
72ea8392a8 | ||
|
|
bb44d422d6 | ||
|
|
5d304ae63a | ||
|
|
0c991af985 | ||
|
|
ac702843dd | ||
|
|
4015488b90 | ||
|
|
cccc137714 | ||
|
|
3fa0afad67 | ||
|
|
29142418ba | ||
|
|
c3b54dc0c2 | ||
|
|
a0232cf763 | ||
|
|
57980ba82a | ||
|
|
bcdd54cc5e | ||
|
|
83d5d3142d | ||
|
|
cbbe932ee2 | ||
|
|
593ae41f9d | ||
|
|
e9770fd434 | ||
|
|
53f6785e11 | ||
|
|
1b48fd0abe | ||
|
|
b835059baf | ||
|
|
f7359d6d96 | ||
|
|
4924dd68ae | ||
|
|
02ed166f51 | ||
|
|
9a11586a72 | ||
|
|
b5a5bae09c | ||
|
|
e757543323 | ||
|
|
7b000390a0 | ||
|
|
3f3ec236bb | ||
|
|
22dd3b489d | ||
|
|
0d45142845 | ||
|
|
62d6b5afb7 | ||
|
|
934fe45cfe | ||
|
|
675ae4d802 | ||
|
|
48251f236f | ||
|
|
8e6e70eaa7 | ||
|
|
4925ffda31 | ||
|
|
f89921e153 | ||
|
|
863b811167 | ||
|
|
d1f8884ee6 | ||
|
|
9caf07dd4f | ||
|
|
2044fffa25 | ||
|
|
2e442d81f7 | ||
|
|
28f0e3281a | ||
|
|
6a0d881554 | ||
|
|
4a9eee5a1c | ||
|
|
a4d3b9f14a | ||
|
|
1beac93961 | ||
|
|
8286325fd0 | ||
|
|
228f24c491 | ||
|
|
cff78eec23 | ||
|
|
20d786d7ca | ||
|
|
0c1b1a896f | ||
|
|
db8e247aa5 | ||
|
|
e01fdba557 | ||
|
|
0a1e55f11c | ||
|
|
85bcbdf18b | ||
|
|
a45c4c0ac4 | ||
|
|
d293e00ef5 | ||
|
|
201a4f92c2 | ||
|
|
71f90c0d6e | ||
|
|
26e22d8e95 | ||
|
|
9805728964 | ||
|
|
f64022a57b | ||
|
|
e79201aef8 | ||
|
|
a2498074f1 | ||
|
|
536279b05b | ||
|
|
031351224a | ||
|
|
74ab3e9a05 | ||
|
|
1bc9ebd7de | ||
|
|
81869de9c5 | ||
|
|
f6301c08f6 | ||
|
|
d66d9297fb | ||
|
|
78bbf6dcc4 | ||
|
|
1ff64fbbd3 | ||
|
|
3226ab16c1 | ||
|
|
13285d7ef3 | ||
|
|
7346ce709a | ||
|
|
8ac32f14b1 | ||
|
|
91ef42dc0a | ||
|
|
1ddca80cee | ||
|
|
896521be73 | ||
|
|
6e419ce821 | ||
|
|
93df02f601 | ||
|
|
fdd9337b64 | ||
|
|
2040b021e1 | ||
|
|
d122faf410 | ||
|
|
eaa4713e22 | ||
|
|
0c1a14e8f2 | ||
|
|
357ce9c3b5 | ||
|
|
830d3e86ee | ||
|
|
209b97d86b | ||
|
|
4da955d9cd | ||
|
|
bff701758a | ||
|
|
90acc6fc23 | ||
|
|
eba2527b8e | ||
|
|
48220f087b | ||
|
|
26b17abb01 | ||
|
|
22468f3756 | ||
|
|
9696d83e7d | ||
|
|
940ca4f2b8 | ||
|
|
f38250245f | ||
|
|
4c7c27f73e | ||
|
|
7a235849cf | ||
|
|
846ba80480 | ||
|
|
93d98b6450 | ||
|
|
7d10019d2a | ||
|
|
274f8f2f87 | ||
|
|
3360b10c2f | ||
|
|
6f9561e64f | ||
|
|
016b216d95 | ||
|
|
164134c78a | ||
|
|
4a4b5ba196 | ||
|
|
c87d8fda82 | ||
|
|
48af3e8249 | ||
|
|
57d150e535 | ||
|
|
d9f97fc9a4 | ||
|
|
9cdf7860d5 | ||
|
|
0f11c0f6b3 | ||
|
|
9914ff32ec | ||
|
|
728bf0c956 | ||
|
|
c520e93733 | ||
|
|
b397d33246 | ||
|
|
aa25e2080e | ||
|
|
2b3799e6ce | ||
|
|
2af3a83ef4 | ||
|
|
c3c2438c9c | ||
|
|
69bee06cee | ||
|
|
c70eb0a5a8 | ||
|
|
db901399f2 | ||
|
|
d0e5a1d252 | ||
|
|
ccda4692b4 | ||
|
|
e6563bc4cb | ||
|
|
1c2328bb90 | ||
|
|
9ec126bd8b | ||
|
|
b3cc3db49e | ||
|
|
5b1182460c | ||
|
|
76f76249e7 | ||
|
|
353b14f473 | ||
|
|
ec07bdb315 | ||
|
|
9ece7da447 | ||
|
|
b214333760 | ||
|
|
3423043759 | ||
|
|
8c636ef08a | ||
|
|
a9b94f5eb9 | ||
|
|
c228227bc1 | ||
|
|
0c46373c20 | ||
|
|
648ed3b412 | ||
|
|
cecb3ee45b | ||
|
|
4585281da4 | ||
|
|
014859ecff | ||
|
|
1f36946f43 | ||
|
|
9efc601c73 | ||
|
|
dc7e7d66c9 | ||
|
|
18528650c3 | ||
|
|
a371f03c51 | ||
|
|
f173040222 | ||
|
|
b74235d4a1 | ||
|
|
4b8ea5d0f0 | ||
|
|
79e861b52b | ||
|
|
c4b4411513 | ||
|
|
7b33a8ef57 | ||
|
|
1dd315ce1d | ||
|
|
7c75ebe672 | ||
|
|
d9481ff9b8 | ||
|
|
f0c39e08ca | ||
|
|
d3fa53151a | ||
|
|
f2d7b8f740 | ||
|
|
beb8cc8e0b | ||
|
|
17d6a74909 | ||
|
|
aab7610808 | ||
|
|
8edee143e8 | ||
|
|
49cf804c62 | ||
|
|
8ab738307e | ||
|
|
9d9adc73cd | ||
|
|
91f93b38ee | ||
|
|
7bff3be869 | ||
|
|
475599d4ab | ||
|
|
7d81731d4f | ||
|
|
ffe9d6d406 | ||
|
|
cf7c9be6b4 | ||
|
|
3e80c9a80f | ||
|
|
c6cf035037 | ||
|
|
6008885152 | ||
|
|
0c7f8764c9 | ||
|
|
d1d8c2f03d | ||
|
|
b97b3e6e3b | ||
|
|
cc02d06c58 | ||
|
|
b91bbb1590 | ||
|
|
52b1ca2d80 | ||
|
|
4ec7dc0f27 | ||
|
|
0a4da78b22 | ||
|
|
aa3f64976f | ||
|
|
260fa1a2e2 | ||
|
|
a321282ccc | ||
|
|
6f91baf99c | ||
|
|
1a7f2195a2 | ||
|
|
e5797001a7 | ||
|
|
f0b937c538 | ||
|
|
9639bf8cc1 | ||
|
|
27e1588685 | ||
|
|
42fac75e8e | ||
|
|
37b7e9b850 | ||
|
|
48e26c5d0a | ||
|
|
1d77099861 | ||
|
|
924a989f37 | ||
|
|
6431445846 | ||
|
|
8d57a54b2d | ||
|
|
280d12b81c | ||
|
|
00a0b8e516 | ||
|
|
238ccb15b5 | ||
|
|
ace7b55a1a | ||
|
|
97ab41728e | ||
|
|
acd9f84802 | ||
|
|
a24ecc65f5 | ||
|
|
4e45a5fde4 | ||
|
|
9499736593 | ||
|
|
df8b48646b | ||
|
|
b4904a4ba2 | ||
|
|
2006f87b58 | ||
|
|
5d9f6d892f | ||
|
|
1ac4bdd090 | ||
|
|
302c4e43bd | ||
|
|
f5926f6514 | ||
|
|
330e0f7165 | ||
|
|
42376db763 | ||
|
|
1147badf7c | ||
|
|
7b000390ac | ||
|
|
dd5de829c9 | ||
|
|
2f7834245b | ||
|
|
78d2654fb4 | ||
|
|
934dbd1f5a | ||
|
|
23933d2fb0 | ||
|
|
76bbbb8ed5 | ||
|
|
8701a88c94 | ||
|
|
2024fca4df | ||
|
|
032eb145df | ||
|
|
0d941b7ba5 | ||
|
|
f71d843f93 | ||
|
|
7d825c93b6 | ||
|
|
19b1e2a6bc | ||
|
|
901919f25f | ||
|
|
15c38d918f | ||
|
|
508c3418f9 | ||
|
|
d98e98fe77 | ||
|
|
4a45eb9899 | ||
|
|
45fc964470 | ||
|
|
56fed052f8 | ||
|
|
a0cd4655ba | ||
|
|
d3f521925e | ||
|
|
8a8887ea82 | ||
|
|
d22ac4a4fb | ||
|
|
8426b12550 | ||
|
|
57bf362b55 | ||
|
|
18a8260535 | ||
|
|
9f32f421a5 | ||
|
|
df6a83b27b | ||
|
|
4477bab1aa | ||
|
|
54bb30a1a4 | ||
|
|
5ae6360e75 | ||
|
|
d6dc93ca3d | ||
|
|
005d514adf | ||
|
|
9568e28d66 | ||
|
|
4f2571a408 | ||
|
|
e33d285e4a | ||
|
|
619128cb9b | ||
|
|
9f37b6eff7 | ||
|
|
2380612b6e | ||
|
|
c334179c95 | ||
|
|
827d009b3c | ||
|
|
56edeec958 | ||
|
|
7df57d5081 | ||
|
|
2ccffc80b0 | ||
|
|
797a19352c | ||
|
|
7025f968c6 | ||
|
|
04e01f49a9 | ||
|
|
a3da40a701 | ||
|
|
40258bf100 | ||
|
|
d3baff221d | ||
|
|
f5e984c151 | ||
|
|
6ed6e09bf3 | ||
|
|
05ccdfbacd | ||
|
|
9bcc2d1c5f | ||
|
|
211159f2eb | ||
|
|
ab141a8779 | ||
|
|
e9c82472ff | ||
|
|
48ed2fd1aa | ||
|
|
0fa74d863d | ||
|
|
c744dcf07a | ||
|
|
eb091b867f | ||
|
|
fb3568308e | ||
|
|
93b8f01583 | ||
|
|
068da8045b | ||
|
|
b12658782f | ||
|
|
3e87489c5b | ||
|
|
8aa0e2655e | ||
|
|
155e23a73e | ||
|
|
359fba970e | ||
|
|
3a056f6d10 | ||
|
|
213aa51126 | ||
|
|
8588387fad | ||
|
|
8c6de852c6 | ||
|
|
52e35f69c5 | ||
|
|
d9939d1ea0 | ||
|
|
703a0e0240 | ||
|
|
48d8285344 | ||
|
|
710496b6a8 | ||
|
|
2f45755e6c | ||
|
|
021f2da1e4 | ||
|
|
bc6361ab9b | ||
|
|
eb640ed344 | ||
|
|
5c244d9e2b | ||
|
|
e538f02f30 | ||
|
|
4064641967 | ||
|
|
c72be1531c | ||
|
|
f0a168da5a | ||
|
|
4d89c709a5 | ||
|
|
737a55f9e1 | ||
|
|
fe5b7db6ab | ||
|
|
b23f5223dd | ||
|
|
aa675f7f66 | ||
|
|
181920886e | ||
|
|
4d8bec435d | ||
|
|
89dbbfd0fd | ||
|
|
0164f5862c | ||
|
|
e966ba72b1 | ||
|
|
464edd5e5f | ||
|
|
5ba8f36958 | ||
|
|
e2041d02e8 | ||
|
|
d49533bedc | ||
|
|
3dc15c03a7 | ||
|
|
954767d456 | ||
|
|
6c993beb22 | ||
|
|
cc9a4e3edc | ||
|
|
0d59781ea8 | ||
|
|
1aaf6345a4 | ||
|
|
15b99977a2 | ||
|
|
055f67e414 | ||
|
|
099aee5c5b | ||
|
|
65dc208ad7 | ||
|
|
e3244b2c31 | ||
|
|
aa49dd53b5 | ||
|
|
916c0fc60b | ||
|
|
4acb504324 | ||
|
|
3207c73d4b | ||
|
|
2510c949e5 | ||
|
|
29e257e8ba | ||
|
|
1a0192201b | ||
|
|
8db50f4377 |
31
.travis.yml
31
.travis.yml
@@ -1,23 +1,24 @@
|
||||
language: ruby
|
||||
|
||||
rvm:
|
||||
- 1.9.3
|
||||
- 2.0.0
|
||||
- 2.1
|
||||
- 2.2
|
||||
- 2.1.9
|
||||
- 2.2.5
|
||||
- 2.3.1
|
||||
- ruby-head
|
||||
|
||||
gemfile:
|
||||
- Gemfile
|
||||
- gemfiles/Gemfile.rails-4.2-stable
|
||||
- gemfiles/Gemfile.rails-4.1-stable
|
||||
- gemfiles/Gemfile.rails-4.0-stable
|
||||
- gemfiles/Gemfile.rails-3.2-stable
|
||||
- Gemfile
|
||||
|
||||
matrix:
|
||||
exclude:
|
||||
- rvm: 2.2
|
||||
gemfile: gemfiles/Gemfile.rails-3.2-stable
|
||||
|
||||
- rvm: 2.1.9
|
||||
gemfile: Gemfile
|
||||
- env: DEVISE_ORM=mongoid
|
||||
gemfile: Gemfile
|
||||
allow_failures:
|
||||
- rvm: ruby-head
|
||||
services:
|
||||
- mongodb
|
||||
|
||||
@@ -27,19 +28,19 @@ cache: bundler
|
||||
|
||||
env:
|
||||
matrix:
|
||||
- DEVISE_ORM=mongoid
|
||||
- DEVISE_ORM=active_record
|
||||
- DEVISE_ORM=mongoid
|
||||
|
||||
before_install: "rm ${BUNDLE_GEMFILE}.lock"
|
||||
|
||||
before_script: "bundle update"
|
||||
|
||||
script: "bundle exec rake test"
|
||||
script: "bin/test"
|
||||
|
||||
notifications:
|
||||
email: false
|
||||
campfire:
|
||||
slack:
|
||||
on_pull_requests: false
|
||||
on_success: change
|
||||
on_failure: always
|
||||
rooms:
|
||||
- secure: "TRiqvuM4i/QmRDWjUSNitE5/P91BOzDkNl53+bZjjtxcISCswZtmECWBR7n9\n3xwqCOU1o2lfohxZ32OHOj/Nj7o+90zWJfWxcv+if0hIXRiil62M5pg0lZUd\nyJ4M5VQ0lSWo5he1OUrXhSabPJeaK3B8yT/tdh+qO5yzR+vb/jc="
|
||||
secure: Q3M+kmude3FjisibEeeGe0wSMXgvwLH+vL7Zrx9//q4QtkfnrQ/BBMvY9KXxPEsNF+eys4YopYjTkJ8uRmeboUATW/oQ4Jrv3+u3zkIHK2sFn/Q2cQWpK5w+CbgEnHPjKYnUu34b09njXTgDlr/mqtbPqrKeZ1dLlpKXCB/q4GY=
|
||||
|
||||
1279
CHANGELOG.md
1279
CHANGELOG.md
File diff suppressed because it is too large
Load Diff
22
CODE_OF_CONDUCT.md
Normal file
22
CODE_OF_CONDUCT.md
Normal file
@@ -0,0 +1,22 @@
|
||||
# Contributor Code of Conduct
|
||||
|
||||
As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
||||
|
||||
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality.
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery
|
||||
* Personal attacks
|
||||
* Trolling or insulting/derogatory comments
|
||||
* Public or private harassment
|
||||
* Publishing other's private information, such as physical or electronic addresses, without explicit permission
|
||||
* Other unethical or unprofessional conduct.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team.
|
||||
|
||||
This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community.
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by sending an email to [conduct@plataformatec.com.br](conduct@plataformatec.com.br) or contacting one or more of the project maintainers.
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.2.0, available at [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/)
|
||||
@@ -1,14 +1,79 @@
|
||||
### Please read before contributing
|
||||
# How to contribute to Devise
|
||||
|
||||
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).
|
||||
Thanks for your interest on contributing to Devise! Here are a few general
|
||||
guidelines on contributing and reporting bugs to Devise that we ask you to
|
||||
take a look first. Notice that all of your interactions in the project are
|
||||
expected to follow our [Code of Conduct](CODE_OF_CONDUCT.md).
|
||||
|
||||
2) If you find a security bug, **DO NOT** submit an issue here. Please send an e-mail to [opensource@plataformatec.com.br](mailto:opensource@plataformatec.com.br) instead.
|
||||
## Reporting Issues
|
||||
|
||||
3) Do a small search on the issues tracker before submitting your issue to see if it was already reported / fixed.
|
||||
Before reporting a new issue, please be sure that the issue wasn't already
|
||||
reported or fixed by searching on GitHub through our [issues](https://github.com/plataformatec/devise/issues).
|
||||
|
||||
4) When reporting an issue, include Rails, Devise and Warden versions. If you are getting exceptions, please include the full backtrace.
|
||||
When creating a new issue, be sure to include a **title and clear description**,
|
||||
as much relevant information as possible, and either a test case example or
|
||||
even better a **sample Rails app that replicates the issue** - Devise has a lot
|
||||
of moving parts and it's functionality can be affected by third party gems, so
|
||||
we need as much context and details as possible to identify what might be broken
|
||||
for you. We have a [test case template](guides/bug_report_templates/integration_test.rb)
|
||||
that can be used to replicate issues with minimal setup.
|
||||
|
||||
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.
|
||||
Please do not attempt to translate Devise built in views. The views are meant
|
||||
to be a starting point for fresh apps and not production material - eventually
|
||||
all applications will require custom views where you can write your own copy and
|
||||
translate it if the application requires it . For historical references, please look into closed
|
||||
[Issues/Pull Requests](https://github.com/plataformatec/devise/issues?q=i18n) regarding
|
||||
internationalization.
|
||||
|
||||
Thanks!
|
||||
Avoid opening new issues to ask questions in our issues tracker. Please go through
|
||||
the project wiki, documentation and source code first, or try to ask your question
|
||||
on [Stack Overflow](http://stackoverflow.com/questions/tagged/devise).
|
||||
|
||||
**If you find a security bug, do not report it through GitHub. Please send an
|
||||
e-mail to [opensource@plataformatec.com.br](mailto:opensource@plataformatec.com.br)
|
||||
instead.**
|
||||
|
||||
## Sending Pull Requests
|
||||
|
||||
Before sending a new Pull Request, take a look on existing Pull Requests and Issues
|
||||
to see if the proposed change or fix has been discussed in the past, or if the
|
||||
change was already implemented but not yet released.
|
||||
|
||||
We expect new Pull Requests to include enough tests for new or changed behavior,
|
||||
and we aim to maintain everything as most backwards compatible as possible,
|
||||
reserving breaking changes to be ship in major releases when necessary - you
|
||||
can wrap the new code path with a setting toggle from the `Devise` module defined
|
||||
as `false` by default to require developers to opt-in for the new behavior.
|
||||
|
||||
If your Pull Request includes new or changed behavior, be sure that the changes
|
||||
are beneficial to a wide range of use cases or it's an application specific change
|
||||
that might not be so valuable to other applications. Some changes can be introduced
|
||||
as a new `devise-something` gem instead of belonging to the main codebase.
|
||||
|
||||
When adding new settings, you can take advantage of the [`Devise::Models.config`](https://github.com/plataformatec/devise/blob/245b1f9de0b3386b7913e14b60ea24f43b77feb0/lib/devise/models.rb#L13-L50) method to add class and instance level fallbacks
|
||||
to the new setting.
|
||||
|
||||
We also welcome Pull Requests that improve our existing documentation (both our
|
||||
`README.md` and the RDoc sections in the source code) or improve existing rough
|
||||
edges in our API that might be blocking existing integrations or 3rd party gems.
|
||||
|
||||
## Other ways to contribute
|
||||
|
||||
We welcome anyone that wants to contribute to Devise to triage and reply to
|
||||
open issues to help troubleshoot and fix existing bugs on Devise. Here is what
|
||||
you can do:
|
||||
|
||||
* Help ensure that existing issues follows the recommendations from the
|
||||
_[Reporting Issues](#reporting-issues)_ section, providing feeback to the issue's
|
||||
author on what might be missing.
|
||||
* Review and update the existing content of our [Wiki](https://github.com/plataformatec/devise/wiki)
|
||||
with up to date instructions and code samples - the wiki was grown with several
|
||||
different tutorials and references that we can't keep track of everything, so if
|
||||
there is a page that showcases an integration or customization that you are
|
||||
familiar with feel free to update it as necessary.
|
||||
* Review existing Pull Requests, and testing patches against real existing
|
||||
applications that use Devise.
|
||||
|
||||
Thanks again for your interest on contributing to the project!
|
||||
|
||||
:heart:
|
||||
|
||||
22
Gemfile
22
Gemfile
@@ -2,14 +2,21 @@ source "https://rubygems.org"
|
||||
|
||||
gemspec
|
||||
|
||||
gem "rails", "4.2.1"
|
||||
gem "omniauth", "~> 1.2.0"
|
||||
gem "omniauth-oauth2", "~> 1.1.0"
|
||||
gem "rails", "~> 5.0.0"
|
||||
gem "omniauth", "~> 1.3"
|
||||
gem "oauth2"
|
||||
gem "omniauth-oauth2"
|
||||
gem "rdoc"
|
||||
|
||||
gem "activemodel-serializers-xml", github: "rails/activemodel-serializers-xml"
|
||||
|
||||
gem "rails-controller-testing"
|
||||
|
||||
gem "responders", "~> 2.1"
|
||||
|
||||
group :test do
|
||||
gem "omniauth-facebook"
|
||||
gem "omniauth-openid", "~> 1.0.1"
|
||||
gem "omniauth-openid"
|
||||
gem "webrat", "0.7.3", require: false
|
||||
gem "mocha", "~> 1.1", require: false
|
||||
end
|
||||
@@ -24,6 +31,7 @@ platforms :ruby do
|
||||
gem "sqlite3"
|
||||
end
|
||||
|
||||
group :mongoid do
|
||||
gem "mongoid", github: "mongoid/mongoid", branch: "master"
|
||||
end
|
||||
# TODO:
|
||||
# group :mongoid do
|
||||
# gem "mongoid", "~> 4.0.0"
|
||||
# end
|
||||
|
||||
244
Gemfile.lock
244
Gemfile.lock
@@ -1,191 +1,197 @@
|
||||
GIT
|
||||
remote: git://github.com/rails/activemodel-serializers-xml.git
|
||||
revision: 570ee7ed33d60e44ca1f3ccbec3d1fbf61d52cbf
|
||||
specs:
|
||||
activemodel-serializers-xml (1.0.1)
|
||||
activemodel (> 5.x)
|
||||
activerecord (> 5.x)
|
||||
activesupport (> 5.x)
|
||||
builder (~> 3.1)
|
||||
|
||||
PATH
|
||||
remote: .
|
||||
specs:
|
||||
devise (3.5.1)
|
||||
devise (4.2.0)
|
||||
bcrypt (~> 3.0)
|
||||
orm_adapter (~> 0.1)
|
||||
railties (>= 3.2.6, < 5)
|
||||
railties (>= 4.1.0, < 5.1)
|
||||
responders
|
||||
thread_safe (~> 0.1)
|
||||
warden (~> 1.2.3)
|
||||
|
||||
GIT
|
||||
remote: git://github.com/mongoid/mongoid.git
|
||||
revision: a4365d7ecfa8221bfcf36a4e7ce7993142fc5940
|
||||
branch: master
|
||||
specs:
|
||||
mongoid (4.0.0)
|
||||
activemodel (~> 4.0)
|
||||
moped (~> 2.0.0)
|
||||
origin (~> 2.1)
|
||||
tzinfo (>= 0.3.37)
|
||||
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
actionmailer (4.2.1)
|
||||
actionpack (= 4.2.1)
|
||||
actionview (= 4.2.1)
|
||||
activejob (= 4.2.1)
|
||||
actioncable (5.0.0)
|
||||
actionpack (= 5.0.0)
|
||||
nio4r (~> 1.2)
|
||||
websocket-driver (~> 0.6.1)
|
||||
actionmailer (5.0.0)
|
||||
actionpack (= 5.0.0)
|
||||
actionview (= 5.0.0)
|
||||
activejob (= 5.0.0)
|
||||
mail (~> 2.5, >= 2.5.4)
|
||||
rails-dom-testing (~> 1.0, >= 1.0.5)
|
||||
actionpack (4.2.1)
|
||||
actionview (= 4.2.1)
|
||||
activesupport (= 4.2.1)
|
||||
rack (~> 1.6)
|
||||
rack-test (~> 0.6.2)
|
||||
rails-dom-testing (~> 1.0, >= 1.0.5)
|
||||
rails-html-sanitizer (~> 1.0, >= 1.0.1)
|
||||
actionview (4.2.1)
|
||||
activesupport (= 4.2.1)
|
||||
rails-dom-testing (~> 2.0)
|
||||
actionpack (5.0.0)
|
||||
actionview (= 5.0.0)
|
||||
activesupport (= 5.0.0)
|
||||
rack (~> 2.0)
|
||||
rack-test (~> 0.6.3)
|
||||
rails-dom-testing (~> 2.0)
|
||||
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
||||
actionview (5.0.0)
|
||||
activesupport (= 5.0.0)
|
||||
builder (~> 3.1)
|
||||
erubis (~> 2.7.0)
|
||||
rails-dom-testing (~> 1.0, >= 1.0.5)
|
||||
rails-html-sanitizer (~> 1.0, >= 1.0.1)
|
||||
activejob (4.2.1)
|
||||
activesupport (= 4.2.1)
|
||||
globalid (>= 0.3.0)
|
||||
activemodel (4.2.1)
|
||||
activesupport (= 4.2.1)
|
||||
builder (~> 3.1)
|
||||
activerecord (4.2.1)
|
||||
activemodel (= 4.2.1)
|
||||
activesupport (= 4.2.1)
|
||||
arel (~> 6.0)
|
||||
activesupport (4.2.1)
|
||||
rails-dom-testing (~> 2.0)
|
||||
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
||||
activejob (5.0.0)
|
||||
activesupport (= 5.0.0)
|
||||
globalid (>= 0.3.6)
|
||||
activemodel (5.0.0)
|
||||
activesupport (= 5.0.0)
|
||||
activerecord (5.0.0)
|
||||
activemodel (= 5.0.0)
|
||||
activesupport (= 5.0.0)
|
||||
arel (~> 7.0)
|
||||
activesupport (5.0.0)
|
||||
concurrent-ruby (~> 1.0, >= 1.0.2)
|
||||
i18n (~> 0.7)
|
||||
json (~> 1.7, >= 1.7.7)
|
||||
minitest (~> 5.1)
|
||||
thread_safe (~> 0.3, >= 0.3.4)
|
||||
tzinfo (~> 1.1)
|
||||
arel (6.0.0)
|
||||
bcrypt (3.1.10)
|
||||
bson (2.3.0)
|
||||
arel (7.0.0)
|
||||
bcrypt (3.1.11)
|
||||
builder (3.2.2)
|
||||
connection_pool (2.1.3)
|
||||
concurrent-ruby (1.0.2)
|
||||
erubis (2.7.0)
|
||||
faraday (0.9.1)
|
||||
faraday (0.9.2)
|
||||
multipart-post (>= 1.2, < 3)
|
||||
globalid (0.3.3)
|
||||
globalid (0.3.6)
|
||||
activesupport (>= 4.1.0)
|
||||
hashie (3.4.0)
|
||||
hike (1.2.3)
|
||||
hashie (3.4.4)
|
||||
i18n (0.7.0)
|
||||
json (1.8.2)
|
||||
jwt (1.4.1)
|
||||
loofah (2.0.1)
|
||||
json (1.8.3)
|
||||
jwt (1.5.4)
|
||||
loofah (2.0.3)
|
||||
nokogiri (>= 1.5.9)
|
||||
mail (2.6.3)
|
||||
mime-types (>= 1.16, < 3)
|
||||
mail (2.6.4)
|
||||
mime-types (>= 1.16, < 4)
|
||||
metaclass (0.0.4)
|
||||
mime-types (2.4.3)
|
||||
mini_portile (0.6.2)
|
||||
minitest (5.5.1)
|
||||
method_source (0.8.2)
|
||||
mime-types (3.1)
|
||||
mime-types-data (~> 3.2015)
|
||||
mime-types-data (3.2016.0521)
|
||||
mini_portile2 (2.1.0)
|
||||
minitest (5.9.0)
|
||||
mocha (1.1.0)
|
||||
metaclass (~> 0.0.1)
|
||||
moped (2.0.4)
|
||||
bson (~> 2.2)
|
||||
connection_pool (~> 2.0)
|
||||
optionable (~> 0.2.0)
|
||||
multi_json (1.11.0)
|
||||
multi_json (1.12.1)
|
||||
multi_xml (0.5.5)
|
||||
multipart-post (2.0.0)
|
||||
nokogiri (1.6.6.2)
|
||||
mini_portile (~> 0.6.0)
|
||||
oauth2 (0.9.4)
|
||||
nio4r (1.2.1)
|
||||
nokogiri (1.6.8)
|
||||
mini_portile2 (~> 2.1.0)
|
||||
pkg-config (~> 1.1.7)
|
||||
oauth2 (1.2.0)
|
||||
faraday (>= 0.8, < 0.10)
|
||||
jwt (~> 1.0)
|
||||
multi_json (~> 1.3)
|
||||
multi_xml (~> 0.5)
|
||||
rack (~> 1.2)
|
||||
omniauth (1.2.2)
|
||||
rack (>= 1.2, < 3)
|
||||
omniauth (1.3.1)
|
||||
hashie (>= 1.2, < 4)
|
||||
rack (~> 1.0)
|
||||
omniauth-facebook (1.6.0)
|
||||
omniauth-oauth2 (~> 1.1)
|
||||
omniauth-oauth2 (1.1.2)
|
||||
faraday (>= 0.8, < 0.10)
|
||||
multi_json (~> 1.3)
|
||||
oauth2 (~> 0.9.3)
|
||||
rack (>= 1.0, < 3)
|
||||
omniauth-facebook (3.0.0)
|
||||
omniauth-oauth2 (~> 1.2)
|
||||
omniauth-oauth2 (1.4.0)
|
||||
oauth2 (~> 1.0)
|
||||
omniauth (~> 1.2)
|
||||
omniauth-openid (1.0.1)
|
||||
omniauth (~> 1.0)
|
||||
rack-openid (~> 1.3.1)
|
||||
optionable (0.2.0)
|
||||
origin (2.1.1)
|
||||
orm_adapter (0.5.0)
|
||||
rack (1.6.0)
|
||||
pkg-config (1.1.7)
|
||||
rack (2.0.1)
|
||||
rack-openid (1.3.1)
|
||||
rack (>= 1.1.0)
|
||||
ruby-openid (>= 2.1.8)
|
||||
rack-test (0.6.3)
|
||||
rack (>= 1.0)
|
||||
rails (4.2.1)
|
||||
actionmailer (= 4.2.1)
|
||||
actionpack (= 4.2.1)
|
||||
actionview (= 4.2.1)
|
||||
activejob (= 4.2.1)
|
||||
activemodel (= 4.2.1)
|
||||
activerecord (= 4.2.1)
|
||||
activesupport (= 4.2.1)
|
||||
rails (5.0.0)
|
||||
actioncable (= 5.0.0)
|
||||
actionmailer (= 5.0.0)
|
||||
actionpack (= 5.0.0)
|
||||
actionview (= 5.0.0)
|
||||
activejob (= 5.0.0)
|
||||
activemodel (= 5.0.0)
|
||||
activerecord (= 5.0.0)
|
||||
activesupport (= 5.0.0)
|
||||
bundler (>= 1.3.0, < 2.0)
|
||||
railties (= 4.2.1)
|
||||
sprockets-rails
|
||||
rails-deprecated_sanitizer (1.0.3)
|
||||
activesupport (>= 4.2.0.alpha)
|
||||
rails-dom-testing (1.0.6)
|
||||
activesupport (>= 4.2.0.beta, < 5.0)
|
||||
railties (= 5.0.0)
|
||||
sprockets-rails (>= 2.0.0)
|
||||
rails-controller-testing (0.1.1)
|
||||
actionpack (~> 5.x)
|
||||
actionview (~> 5.x)
|
||||
activesupport (~> 5.x)
|
||||
rails-dom-testing (2.0.1)
|
||||
activesupport (>= 4.2.0, < 6.0)
|
||||
nokogiri (~> 1.6.0)
|
||||
rails-deprecated_sanitizer (>= 1.0.1)
|
||||
rails-html-sanitizer (1.0.2)
|
||||
rails-html-sanitizer (1.0.3)
|
||||
loofah (~> 2.0)
|
||||
railties (4.2.1)
|
||||
actionpack (= 4.2.1)
|
||||
activesupport (= 4.2.1)
|
||||
railties (5.0.0)
|
||||
actionpack (= 5.0.0)
|
||||
activesupport (= 5.0.0)
|
||||
method_source
|
||||
rake (>= 0.8.7)
|
||||
thor (>= 0.18.1, < 2.0)
|
||||
rake (10.4.2)
|
||||
rdoc (4.2.0)
|
||||
responders (2.1.0)
|
||||
railties (>= 4.2.0, < 5)
|
||||
rake (11.2.2)
|
||||
rdoc (4.2.2)
|
||||
json (~> 1.4)
|
||||
responders (2.2.0)
|
||||
railties (>= 4.2.0, < 5.1)
|
||||
ruby-openid (2.7.0)
|
||||
sprockets (2.12.3)
|
||||
hike (~> 1.2)
|
||||
multi_json (~> 1.0)
|
||||
rack (~> 1.0)
|
||||
tilt (~> 1.1, != 1.3.0)
|
||||
sprockets-rails (2.2.4)
|
||||
actionpack (>= 3.0)
|
||||
activesupport (>= 3.0)
|
||||
sprockets (>= 2.8, < 4.0)
|
||||
sqlite3 (1.3.10)
|
||||
sprockets (3.6.2)
|
||||
concurrent-ruby (~> 1.0)
|
||||
rack (> 1, < 3)
|
||||
sprockets-rails (3.1.1)
|
||||
actionpack (>= 4.0)
|
||||
activesupport (>= 4.0)
|
||||
sprockets (>= 3.0.0)
|
||||
sqlite3 (1.3.11)
|
||||
thor (0.19.1)
|
||||
thread_safe (0.3.5)
|
||||
tilt (1.4.1)
|
||||
tzinfo (1.2.2)
|
||||
thread_safe (~> 0.1)
|
||||
warden (1.2.3)
|
||||
warden (1.2.6)
|
||||
rack (>= 1.0)
|
||||
webrat (0.7.3)
|
||||
nokogiri (>= 1.2.0)
|
||||
rack (>= 1.0)
|
||||
rack-test (>= 0.5.3)
|
||||
websocket-driver (0.6.4)
|
||||
websocket-extensions (>= 0.1.0)
|
||||
websocket-extensions (0.1.2)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
activemodel-serializers-xml!
|
||||
activerecord-jdbc-adapter
|
||||
activerecord-jdbcsqlite3-adapter
|
||||
devise!
|
||||
jruby-openssl
|
||||
mocha (~> 1.1)
|
||||
mongoid!
|
||||
omniauth (~> 1.2.0)
|
||||
oauth2
|
||||
omniauth (~> 1.3)
|
||||
omniauth-facebook
|
||||
omniauth-oauth2 (~> 1.1.0)
|
||||
omniauth-openid (~> 1.0.1)
|
||||
rails (= 4.2.1)
|
||||
omniauth-oauth2
|
||||
omniauth-openid
|
||||
rails (~> 5.0.0)
|
||||
rails-controller-testing
|
||||
rdoc
|
||||
responders (~> 2.1)
|
||||
sqlite3
|
||||
webrat (= 0.7.3)
|
||||
|
||||
BUNDLED WITH
|
||||
1.12.5
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Copyright 2009-2015 Plataformatec. http://plataformatec.com.br
|
||||
Copyright 2009-2016 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
|
||||
|
||||
176
README.md
176
README.md
@@ -4,7 +4,6 @@ By [Plataformatec](http://plataformatec.com.br/).
|
||||
|
||||
[](http://travis-ci.org/plataformatec/devise)
|
||||
[](https://codeclimate.com/github/plataformatec/devise)
|
||||
[](https://hakiri.io/github/plataformatec/devise/master)
|
||||
|
||||
This README is [also available in a friendly navigable format](http://devise.plataformatec.com.br/).
|
||||
|
||||
@@ -17,8 +16,8 @@ Devise is a flexible authentication solution for Rails based on Warden. It:
|
||||
|
||||
It's composed of 10 modules:
|
||||
|
||||
* [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.
|
||||
* [Omniauthable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Omniauthable): adds OmniAuth (https://github.com/intridea/omniauth) support.
|
||||
* [Database Authenticatable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/DatabaseAuthenticatable): hashes 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.
|
||||
* [Omniauthable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Omniauthable): adds OmniAuth (https://github.com/omniauth/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.
|
||||
@@ -28,8 +27,6 @@ It's composed of 10 modules:
|
||||
* [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.
|
||||
|
||||
Devise is guaranteed to be thread-safe on YARV. Thread-safety support on JRuby is in progress.
|
||||
|
||||
## Information
|
||||
|
||||
### The Devise wiki
|
||||
@@ -82,16 +79,17 @@ You will usually want to write tests for your changes. To run the test suite, g
|
||||
|
||||
## Starting with Rails?
|
||||
|
||||
If you are building your first Rails application, we recommend you *do not* use Devise. Devise requires a good understanding of the Rails Framework. In such cases, we advise you to start a simple authentication system from scratch. Today we have two resources that should help you get started:
|
||||
If you are building your first Rails application, we recommend you *do not* use Devise. Devise requires a good understanding of the Rails Framework. In such cases, we advise you to start a simple authentication system from scratch. Today, we have three resources that should help you get started:
|
||||
|
||||
* Michael Hartl's online book: https://www.railstutorial.org/book/modeling_users
|
||||
* Ryan Bates' Railscast: http://railscasts.com/episodes/250-authentication-from-scratch
|
||||
* Codecademy's Ruby on Rails: Authentication and Authorization: http://www.codecademy.com/en/learn/rails-auth
|
||||
|
||||
Once you have solidified your understanding of Rails and authentication mechanisms, we assure you Devise will be very pleasant to work with. :smiley:
|
||||
|
||||
## Getting started
|
||||
|
||||
Devise 3.0 works with Rails 3.2 onwards. You can add it to your Gemfile with:
|
||||
Devise 4.0 works with Rails 4.1 onwards. You can add it to your Gemfile with:
|
||||
|
||||
```ruby
|
||||
gem 'devise'
|
||||
@@ -99,28 +97,31 @@ gem 'devise'
|
||||
|
||||
Run the bundle command to install it.
|
||||
|
||||
After you install Devise and add it to your Gemfile, you need to run the generator:
|
||||
Next, you need to run the generator:
|
||||
|
||||
```console
|
||||
rails generate devise:install
|
||||
$ rails generate devise:install
|
||||
```
|
||||
|
||||
The generator will install an initializer which describes ALL of Devise's configuration options. It is *imperative* that you take a look at it. When you are done, you are ready to add Devise to any of your models using the generator:
|
||||
|
||||
```console
|
||||
rails generate devise MODEL
|
||||
```
|
||||
|
||||
Replace MODEL with the class name used for the application’s 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. The generator also configures your `config/routes.rb` file to point to the Devise controller.
|
||||
|
||||
Next, check the MODEL for any additional configuration options you might want to add, such as confirmable or lockable. If you add an option, be sure to inspect the migration file (created by the generator if your ORM supports them) and uncomment the appropriate section. For example, if you add the confirmable option in the model, you'll need to uncomment the Confirmable section in the migration. Then run `rake db:migrate`
|
||||
|
||||
Next, you need to set up the default URL options for the Devise mailer in each environment. Here is a possible configuration for `config/environments/development.rb`:
|
||||
At this point, a number of instructions will appear in the console. Among these instructions, you'll need to set up the default URL options for the Devise mailer in each environment. Here is a possible configuration for `config/environments/development.rb`:
|
||||
|
||||
```ruby
|
||||
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
|
||||
```
|
||||
|
||||
The generator will install an initializer which describes ALL of Devise's configuration options. It is *imperative* that you take a look at it. When you are done, you are ready to add Devise to any of your models using the generator.
|
||||
|
||||
|
||||
In the following command you will replace `MODEL` with the class name used for the application’s users (it’s frequently `User` but could also be `Admin`). This will create a model (if one does not exist) and configure it with the default Devise modules. The generator also configures your `config/routes.rb` file to point to the Devise controller.
|
||||
|
||||
```console
|
||||
$ rails generate devise MODEL
|
||||
```
|
||||
|
||||
Next, check the MODEL for any additional configuration options you might want to add, such as confirmable or lockable. If you add an option, be sure to inspect the migration file (created by the generator if your ORM supports them) and uncomment the appropriate section. For example, if you add the confirmable option in the model, you'll need to uncomment the Confirmable section in the migration.
|
||||
|
||||
Then run `rake db:migrate`
|
||||
|
||||
You should restart your application after changing Devise's configuration options. Otherwise, you will run into strange errors, for example, users being unable to login and route helpers being undefined.
|
||||
|
||||
### Controller filters and helpers
|
||||
@@ -131,6 +132,8 @@ Devise will create some helpers to use inside your controllers and views. To set
|
||||
before_action :authenticate_user!
|
||||
```
|
||||
|
||||
For Rails 5, note that `protect_from_forgery` is no longer prepended to the `before_action` chain, so if you have set `authenticate_user` before `protect_from_forgery`, your request will result in "Can't verify CSRF token authenticity." To resolve this, either change the order in which you call them, or use `protect_from_forgery prepend: true`.
|
||||
|
||||
If your devise model is something other than User, replace "_user" with "_yourmodel". The same logic applies to the instructions below.
|
||||
|
||||
To verify if a user is signed in, use the following helper:
|
||||
@@ -154,7 +157,7 @@ user_session
|
||||
After signing in a user, confirming the account or updating the password, Devise will look for a scoped root path to redirect to. For instance, when using a `:user` resource, the `user_root_path` will be used if it exists; otherwise, the default `root_path` will be used. This means that you need to set the root inside your routes:
|
||||
|
||||
```ruby
|
||||
root to: "home#index"
|
||||
root to: 'home#index'
|
||||
```
|
||||
|
||||
You can also override `after_sign_in_path_for` and `after_sign_out_path_for` to customize your redirect hooks.
|
||||
@@ -173,7 +176,7 @@ member_session
|
||||
|
||||
### Configuring Models
|
||||
|
||||
The Devise method in your models also accepts some options to configure its modules. For example, you can choose the cost of the encryption algorithm with:
|
||||
The Devise method in your models also accepts some options to configure its modules. For example, you can choose the cost of the hashing algorithm with:
|
||||
|
||||
```ruby
|
||||
devise :database_authenticatable, :registerable, :confirmable, :recoverable, stretches: 20
|
||||
@@ -183,9 +186,13 @@ Besides `:stretches`, you can define `:pepper`, `:encryptor`, `:confirm_within`,
|
||||
|
||||
### Strong Parameters
|
||||
|
||||

|
||||
|
||||
*For previous Devise versions see https://github.com/plataformatec/devise/tree/3-stable#strong-parameters*
|
||||
|
||||
When you customize your own views, you may end up adding new attributes to forms. Rails 4 moved the parameter sanitization from the model to the controller, causing Devise to handle this concern at the controller as well.
|
||||
|
||||
There are just three actions in Devise that allows any set of parameters to be passed down to the model, therefore requiring sanitization. Their names and the permitted parameters by default are:
|
||||
There are just three actions in Devise that allow any set of parameters to be passed down to the model, therefore requiring sanitization. Their names and default permitted parameters are:
|
||||
|
||||
* `sign_in` (`Devise::SessionsController#create`) - Permits only the authentication keys (like `email`)
|
||||
* `sign_up` (`Devise::RegistrationsController#create`) - Permits authentication keys plus `password` and `password_confirmation`
|
||||
@@ -200,7 +207,7 @@ class ApplicationController < ActionController::Base
|
||||
protected
|
||||
|
||||
def configure_permitted_parameters
|
||||
devise_parameter_sanitizer.for(:sign_up) << :username
|
||||
devise_parameter_sanitizer.permit(:sign_up, keys: [:username])
|
||||
end
|
||||
end
|
||||
```
|
||||
@@ -211,7 +218,9 @@ To permit simple scalar values for username and email, use this
|
||||
|
||||
```ruby
|
||||
def configure_permitted_parameters
|
||||
devise_parameter_sanitizer.for(:sign_in) { |u| u.permit(:username, :email) }
|
||||
devise_parameter_sanitizer.permit(:sign_in) do |user_params|
|
||||
user_params.permit(:username, :email)
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
@@ -219,7 +228,9 @@ If you have some checkboxes that express the roles a user may take on registrati
|
||||
|
||||
```ruby
|
||||
def configure_permitted_parameters
|
||||
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit({ roles: [] }, :email, :password, :password_confirmation) }
|
||||
devise_parameter_sanitizer.permit(:sign_up) do |user_params|
|
||||
user_params.permit({ roles: [] }, :email, :password, :password_confirmation)
|
||||
end
|
||||
end
|
||||
```
|
||||
For the list of permitted scalars, and how to declare permitted keys in nested hashes and arrays, see
|
||||
@@ -230,8 +241,9 @@ If you have multiple Devise models, you may want to set up a different parameter
|
||||
|
||||
```ruby
|
||||
class User::ParameterSanitizer < Devise::ParameterSanitizer
|
||||
def sign_in
|
||||
default_params.permit(:username, :email)
|
||||
def initialize(*)
|
||||
super
|
||||
permit(:sign_up, keys: [:username, :email])
|
||||
end
|
||||
end
|
||||
```
|
||||
@@ -261,7 +273,7 @@ We built Devise to help you quickly develop an application that uses authenticat
|
||||
Since Devise is an engine, all its views are packaged inside the gem. These views will help you get started, but after some time you may want to change them. If this is the case, you just need to invoke the following generator, and it will copy all views to your application:
|
||||
|
||||
```console
|
||||
rails generate devise:views
|
||||
$ rails generate devise:views
|
||||
```
|
||||
|
||||
If you have more than one Devise model in your application (such as `User` and `Admin`), you will notice that Devise uses the same views for all models. Fortunately, Devise offers an easy way to customize views. All you need to do is set `config.scoped_views = true` inside the `config/initializers/devise.rb` file.
|
||||
@@ -269,14 +281,14 @@ If you have more than one Devise model in your application (such as `User` and `
|
||||
After doing so, you will be able to have views based on the role like `users/sessions/new` and `admins/sessions/new`. If no view is found within the scope, Devise will use the default view at `devise/sessions/new`. You can also use the generator to generate scoped views:
|
||||
|
||||
```console
|
||||
rails generate devise:views users
|
||||
$ rails generate devise:views users
|
||||
```
|
||||
|
||||
If you would like to generate only a few sets of views, like the ones for the `registerable` and `confirmable` module,
|
||||
you can pass a list of modules to the generator with the `-v` flag.
|
||||
|
||||
```console
|
||||
rails generate devise:views -v registrations confirmations
|
||||
$ rails generate devise:views -v registrations confirmations
|
||||
```
|
||||
|
||||
### Configuring controllers
|
||||
@@ -286,7 +298,7 @@ If the customization at the views level is not enough, you can customize each co
|
||||
1. Create your custom controllers using the generator which requires a scope:
|
||||
|
||||
```console
|
||||
rails generate devise:controllers [scope]
|
||||
$ rails generate devise:controllers [scope]
|
||||
```
|
||||
|
||||
If you specify `users` as the scope, controllers will be created in `app/controllers/users/`.
|
||||
@@ -305,7 +317,7 @@ If the customization at the views level is not enough, you can customize each co
|
||||
2. Tell the router to use this controller:
|
||||
|
||||
```ruby
|
||||
devise_for :users, controllers: { sessions: "users/sessions" }
|
||||
devise_for :users, controllers: { sessions: 'users/sessions' }
|
||||
```
|
||||
|
||||
3. Copy the views from `devise/sessions` to `users/sessions`. Since the controller was changed, it won't use the default views located in `devise/sessions`.
|
||||
@@ -343,16 +355,16 @@ Remember that Devise uses flash messages to let users know if sign in was succes
|
||||
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: "auth", 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.
|
||||
Be sure to check `devise_for` [documentation](http://www.rubydoc.info/github/plataformatec/devise/master/ActionDispatch/Routing/Mapper%3Adevise_for) for details.
|
||||
|
||||
If you have the need for more deep customization, for instance to also allow "/sign_in" besides "/users/sign_in", all you need to do is to create your routes normally and wrap them in a `devise_scope` block in the router:
|
||||
If you have the need for more deep customization, for instance to also allow "/sign_in" besides "/users/sign_in", all you need to do is create your routes normally and wrap them in a `devise_scope` block in the router:
|
||||
|
||||
```ruby
|
||||
devise_scope :user do
|
||||
get "sign_in", to: "devise/sessions#new"
|
||||
get 'sign_in', to: 'devise/sessions#new'
|
||||
end
|
||||
```
|
||||
|
||||
@@ -402,44 +414,94 @@ Caution: Devise Controllers inherit from ApplicationController. If your app uses
|
||||
|
||||
### Test helpers
|
||||
|
||||
Devise includes some test 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:
|
||||
Devise includes some test helpers for controller and integration tests.
|
||||
In order to use them, you need to include the respective module in your test
|
||||
cases/specs.
|
||||
|
||||
### Controller tests
|
||||
|
||||
Controller tests require that you include `Devise::Test::ControllerHelpers` on
|
||||
your test case or its parent `ActionController::TestCase` superclass.
|
||||
|
||||
```ruby
|
||||
class ActionController::TestCase
|
||||
include Devise::TestHelpers
|
||||
class PostsControllerTest < ActionController::TestCase
|
||||
include Devise::Test::ControllerHelpers
|
||||
end
|
||||
```
|
||||
|
||||
If you're using RSpec, you can put the following inside a file named `spec/support/devise.rb` or in your `spec/spec_helper.rb` (or `spec/rails_helper.rb` if you are using rspec-rails):
|
||||
If you're using RSpec, you can put the following inside a file named
|
||||
`spec/support/devise.rb` or in your `spec/spec_helper.rb` (or
|
||||
`spec/rails_helper.rb` if you are using `rspec-rails`):
|
||||
|
||||
```ruby
|
||||
RSpec.configure do |config|
|
||||
config.include Devise::TestHelpers, type: :controller
|
||||
config.include Devise::Test::ControllerHelpers, type: :controller
|
||||
config.include Devise::Test::ControllerHelpers, type: :view
|
||||
end
|
||||
```
|
||||
|
||||
Just be sure that this inclusion is made *after* the `require 'rspec/rails'` directive.
|
||||
|
||||
Now you are ready to use the `sign_in` and `sign_out` methods. Such methods have the same signature as in controllers:
|
||||
Now you are ready to use the `sign_in` and `sign_out` methods on your controller
|
||||
tests:
|
||||
|
||||
```ruby
|
||||
sign_in :user, @user # sign_in(scope, resource)
|
||||
sign_in @user # sign_in(resource)
|
||||
|
||||
sign_out :user # sign_out(scope)
|
||||
sign_out @user # sign_out(resource)
|
||||
sign_in @user
|
||||
sign_in @user, scope: :admin
|
||||
```
|
||||
|
||||
There are two things that are important to keep in mind:
|
||||
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 the router,
|
||||
but since controller tests do not pass through the router, it needs to be stated
|
||||
explicitly. For example, if you are testing the user scope, simply use:
|
||||
|
||||
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;
|
||||
```ruby
|
||||
test 'GET new' do
|
||||
# Mimic the router behavior of setting the Devise scope through the env.
|
||||
@request.env['devise.mapping'] = Devise.mappings[:user]
|
||||
|
||||
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 the router, but since functional tests do not pass through the router, it needs to be stated explicitly. For example, if you are testing the user scope, simply use:
|
||||
# Use the sign_in helper to sign in a fixture `User` record.
|
||||
sign_in users(:alice)
|
||||
|
||||
```ruby
|
||||
@request.env["devise.mapping"] = Devise.mappings[:user]
|
||||
get :new
|
||||
```
|
||||
get :new
|
||||
|
||||
# assert something
|
||||
end
|
||||
```
|
||||
|
||||
### Integration tests
|
||||
|
||||
Integration test helpers are available by including the
|
||||
`Devise::Test::IntegrationHelpers` module.
|
||||
|
||||
```ruby
|
||||
class PostsTests < ActionDispatch::IntegrationTest
|
||||
include Devise::Test::IntegrationHelpers
|
||||
end
|
||||
```
|
||||
|
||||
Now you can use the following `sign_in` and `sign_out` methods in your integration
|
||||
tests:
|
||||
|
||||
```ruby
|
||||
sign_in users(:bob)
|
||||
sign_in users(:bob), scope: :admin
|
||||
|
||||
sign_out :user
|
||||
```
|
||||
|
||||
RSpec users can include the `IntegrationHelpers` module on their `:feature` specs.
|
||||
|
||||
```ruby
|
||||
RSpec.configure do |config|
|
||||
config.include Devise::Test::IntegrationHelpers, type: :feature
|
||||
end
|
||||
```
|
||||
|
||||
Unlike controller tests, integration tests do not need to supply the
|
||||
`devise.mapping` `env` value, as the mapping can be inferred by the routes that
|
||||
are executed in your tests.
|
||||
|
||||
You can read more about testing your Rails 3 - Rails 4 controllers with RSpec in the wiki:
|
||||
|
||||
@@ -476,7 +538,7 @@ devise :database_authenticatable, :timeoutable
|
||||
devise_for :admins
|
||||
|
||||
# Inside your protected controller
|
||||
before_filter :authenticate_admin!
|
||||
before_action :authenticate_admin!
|
||||
|
||||
# Inside your controllers and views
|
||||
admin_signed_in?
|
||||
@@ -544,6 +606,6 @@ https://github.com/plataformatec/devise/graphs/contributors
|
||||
|
||||
## License
|
||||
|
||||
MIT License. Copyright 2009-2015 Plataformatec. http://plataformatec.com.br
|
||||
MIT License. Copyright 2009-2016 Plataformatec. http://plataformatec.com.br
|
||||
|
||||
You are not granted rights or licenses to the trademarks of Plataformatec, including without limitation the Devise name or logo.
|
||||
|
||||
@@ -22,7 +22,7 @@ class Devise::ConfirmationsController < DeviseController
|
||||
yield resource if block_given?
|
||||
|
||||
if resource.errors.empty?
|
||||
set_flash_message(:notice, :confirmed) if is_flashing_format?
|
||||
set_flash_message!(:notice, :confirmed)
|
||||
respond_with_navigational(resource){ redirect_to after_confirmation_path_for(resource_name, resource) }
|
||||
else
|
||||
respond_with_navigational(resource.errors, status: :unprocessable_entity){ render :new }
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class Devise::OmniauthCallbacksController < DeviseController
|
||||
prepend_before_filter { request.env["devise.skip_timeout"] = true }
|
||||
prepend_before_action { request.env["devise.skip_timeout"] = true }
|
||||
|
||||
def passthru
|
||||
render status: 404, text: "Not found. Authentication passthru."
|
||||
@@ -13,14 +13,14 @@ class Devise::OmniauthCallbacksController < DeviseController
|
||||
protected
|
||||
|
||||
def failed_strategy
|
||||
env["omniauth.error.strategy"]
|
||||
request.respond_to?(:get_header) ? request.get_header("omniauth.error.strategy") : request.env["omniauth.error.strategy"]
|
||||
end
|
||||
|
||||
def failure_message
|
||||
exception = env["omniauth.error"]
|
||||
exception = request.respond_to?(:get_header) ? request.get_header("omniauth.error") : request.env["omniauth.error"]
|
||||
error = exception.error_reason if exception.respond_to?(:error_reason)
|
||||
error ||= exception.error if exception.respond_to?(:error)
|
||||
error ||= env["omniauth.error.type"].to_s
|
||||
error ||= (request.respond_to?(:get_header) ? request.get_header("omniauth.error.type") : request.env["omniauth.error.type"]).to_s
|
||||
error.to_s.humanize if error
|
||||
end
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
class Devise::PasswordsController < DeviseController
|
||||
prepend_before_filter :require_no_authentication
|
||||
prepend_before_action :require_no_authentication
|
||||
# Render the #edit only if coming from a reset password email link
|
||||
append_before_filter :assert_reset_token_passed, only: :edit
|
||||
append_before_action :assert_reset_token_passed, only: :edit
|
||||
|
||||
# GET /resource/password/new
|
||||
def new
|
||||
@@ -24,7 +24,13 @@ class Devise::PasswordsController < DeviseController
|
||||
def edit
|
||||
self.resource = resource_class.new
|
||||
set_minimum_password_length
|
||||
resource.reset_password_token = params[:reset_password_token]
|
||||
|
||||
if params[:reset_password_token]
|
||||
session[:reset_password_token] = params[:reset_password_token]
|
||||
redirect_to edit_user_password_url
|
||||
end
|
||||
|
||||
resource.reset_password_token = session[:reset_password_token]
|
||||
end
|
||||
|
||||
# PUT /resource/password
|
||||
@@ -36,21 +42,22 @@ class Devise::PasswordsController < DeviseController
|
||||
resource.unlock_access! if unlockable?(resource)
|
||||
if Devise.sign_in_after_reset_password
|
||||
flash_message = resource.active_for_authentication? ? :updated : :updated_not_active
|
||||
set_flash_message(:notice, flash_message) if is_flashing_format?
|
||||
set_flash_message!(:notice, flash_message)
|
||||
sign_in(resource_name, resource)
|
||||
respond_with resource, location: after_resetting_password_path_for(resource)
|
||||
else
|
||||
set_flash_message(:notice, :updated_not_active) if is_flashing_format?
|
||||
respond_with resource, location: new_session_path(resource_name)
|
||||
set_flash_message!(:notice, :updated_not_active)
|
||||
end
|
||||
session[:reset_password_token] = nil
|
||||
respond_with resource, location: after_resetting_password_path_for(resource)
|
||||
else
|
||||
set_minimum_password_length
|
||||
respond_with resource
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
def after_resetting_password_path_for(resource)
|
||||
after_sign_in_path_for(resource)
|
||||
Devise.sign_in_after_reset_password ? after_sign_in_path_for(resource) : new_session_path(resource_name)
|
||||
end
|
||||
|
||||
# The path used after sending reset password instructions
|
||||
@@ -60,7 +67,9 @@ class Devise::PasswordsController < DeviseController
|
||||
|
||||
# Check if a reset_password_token is provided in the request
|
||||
def assert_reset_token_passed
|
||||
if params[:reset_password_token].blank?
|
||||
reset_token = session[:reset_password_token] || params[:reset_password_token]
|
||||
|
||||
if reset_token.blank?
|
||||
set_flash_message(:alert, :no_token)
|
||||
redirect_to new_session_path(resource_name)
|
||||
end
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
class Devise::RegistrationsController < DeviseController
|
||||
prepend_before_filter :require_no_authentication, only: [:new, :create, :cancel]
|
||||
prepend_before_filter :authenticate_scope!, only: [:edit, :update, :destroy]
|
||||
prepend_before_action :require_no_authentication, only: [:new, :create, :cancel]
|
||||
prepend_before_action :authenticate_scope!, only: [:edit, :update, :destroy]
|
||||
prepend_before_action :set_minimum_password_length, only: [:new, :edit]
|
||||
|
||||
# GET /resource/sign_up
|
||||
def new
|
||||
build_resource({})
|
||||
set_minimum_password_length
|
||||
yield resource if block_given?
|
||||
respond_with self.resource
|
||||
respond_with resource
|
||||
end
|
||||
|
||||
# POST /resource
|
||||
@@ -18,11 +18,11 @@ class Devise::RegistrationsController < DeviseController
|
||||
yield resource if block_given?
|
||||
if resource.persisted?
|
||||
if resource.active_for_authentication?
|
||||
set_flash_message :notice, :signed_up if is_flashing_format?
|
||||
set_flash_message! :notice, :signed_up
|
||||
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_flashing_format?
|
||||
set_flash_message! :notice, :"signed_up_but_#{resource.inactive_message}"
|
||||
expire_data_after_sign_in!
|
||||
respond_with resource, location: after_inactive_sign_up_path_for(resource)
|
||||
end
|
||||
@@ -53,7 +53,7 @@ class Devise::RegistrationsController < DeviseController
|
||||
:update_needs_confirmation : :updated
|
||||
set_flash_message :notice, flash_key
|
||||
end
|
||||
sign_in resource_name, resource, bypass: true
|
||||
bypass_sign_in resource, scope: resource_name
|
||||
respond_with resource, location: after_update_path_for(resource)
|
||||
else
|
||||
clean_up_passwords resource
|
||||
@@ -65,7 +65,7 @@ class Devise::RegistrationsController < DeviseController
|
||||
def destroy
|
||||
resource.destroy
|
||||
Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)
|
||||
set_flash_message :notice, :destroyed if is_flashing_format?
|
||||
set_flash_message! :notice, :destroyed
|
||||
yield resource if block_given?
|
||||
respond_with_navigational(resource){ redirect_to after_sign_out_path_for(resource_name) }
|
||||
end
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
class Devise::SessionsController < DeviseController
|
||||
prepend_before_filter :require_no_authentication, only: [:new, :create]
|
||||
prepend_before_filter :allow_params_authentication!, only: :create
|
||||
prepend_before_filter :verify_signed_out_user, only: :destroy
|
||||
prepend_before_filter only: [:create, :destroy] { request.env["devise.skip_timeout"] = true }
|
||||
prepend_before_action :require_no_authentication, only: [:new, :create]
|
||||
prepend_before_action :allow_params_authentication!, only: :create
|
||||
prepend_before_action :verify_signed_out_user, only: :destroy
|
||||
prepend_before_action only: [:create, :destroy] { request.env["devise.skip_timeout"] = true }
|
||||
|
||||
# GET /resource/sign_in
|
||||
def new
|
||||
@@ -15,7 +15,7 @@ class Devise::SessionsController < DeviseController
|
||||
# POST /resource/sign_in
|
||||
def create
|
||||
self.resource = warden.authenticate!(auth_options)
|
||||
set_flash_message(:notice, :signed_in) if is_flashing_format?
|
||||
set_flash_message!(:notice, :signed_in)
|
||||
sign_in(resource_name, resource)
|
||||
yield resource if block_given?
|
||||
respond_with resource, location: after_sign_in_path_for(resource)
|
||||
@@ -24,7 +24,7 @@ class Devise::SessionsController < DeviseController
|
||||
# DELETE /resource/sign_out
|
||||
def destroy
|
||||
signed_out = (Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name))
|
||||
set_flash_message :notice, :signed_out if signed_out && is_flashing_format?
|
||||
set_flash_message! :notice, :signed_out if signed_out
|
||||
yield if block_given?
|
||||
respond_to_on_destroy
|
||||
end
|
||||
@@ -58,7 +58,7 @@ class Devise::SessionsController < DeviseController
|
||||
# to the after_sign_out path.
|
||||
def verify_signed_out_user
|
||||
if all_signed_out?
|
||||
set_flash_message :notice, :already_signed_out if is_flashing_format?
|
||||
set_flash_message! :notice, :already_signed_out
|
||||
|
||||
respond_to_on_destroy
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class Devise::UnlocksController < DeviseController
|
||||
prepend_before_filter :require_no_authentication
|
||||
prepend_before_action :require_no_authentication
|
||||
|
||||
# GET /resource/unlock/new
|
||||
def new
|
||||
@@ -24,7 +24,7 @@ class Devise::UnlocksController < DeviseController
|
||||
yield resource if block_given?
|
||||
|
||||
if resource.errors.empty?
|
||||
set_flash_message :notice, :unlocked if is_flashing_format?
|
||||
set_flash_message! :notice, :unlocked
|
||||
respond_with_navigational(resource){ redirect_to after_unlock_path_for(resource) }
|
||||
else
|
||||
respond_with_navigational(resource.errors, status: :unprocessable_entity){ render :new }
|
||||
|
||||
@@ -2,13 +2,17 @@
|
||||
class DeviseController < Devise.parent_controller.constantize
|
||||
include Devise::Controllers::ScopedViews
|
||||
|
||||
helper DeviseHelper
|
||||
if respond_to?(:helper)
|
||||
helper DeviseHelper
|
||||
end
|
||||
|
||||
helpers = %w(resource scope_name resource_name signed_in_resource
|
||||
resource_class resource_params devise_mapping)
|
||||
helper_method(*helpers)
|
||||
if respond_to?(:helper_method)
|
||||
helpers = %w(resource scope_name resource_name signed_in_resource
|
||||
resource_class resource_params devise_mapping)
|
||||
helper_method(*helpers)
|
||||
end
|
||||
|
||||
prepend_before_filter :assert_is_devise_resource!
|
||||
prepend_before_action :assert_is_devise_resource!
|
||||
respond_to :html if mimes_for_respond_to.empty?
|
||||
|
||||
# Override prefixes to consider the scoped view.
|
||||
@@ -89,10 +93,10 @@ MESSAGE
|
||||
instance_variable_set(:"@#{resource_name}", new_resource)
|
||||
end
|
||||
|
||||
# Helper for use in before_filters where no authentication is required.
|
||||
# Helper for use in before_actions where no authentication is required.
|
||||
#
|
||||
# Example:
|
||||
# before_filter :require_no_authentication, only: :new
|
||||
# before_action :require_no_authentication, only: :new
|
||||
def require_no_authentication
|
||||
assert_is_devise_resource!
|
||||
return unless is_navigational_format?
|
||||
@@ -123,13 +127,13 @@ MESSAGE
|
||||
end
|
||||
|
||||
if notice
|
||||
set_flash_message :notice, notice if is_flashing_format?
|
||||
set_flash_message! :notice, notice
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
# Sets the flash message with :key, using I18n. By default you are able
|
||||
# to setup your messages using specific resource scope, and if no message is
|
||||
# to set up your messages using specific resource scope, and if no message is
|
||||
# found we look to the default scope. Set the "now" options key to a true
|
||||
# value to populate the flash.now hash in lieu of the default flash hash (so
|
||||
# the flash message will be available to the current action instead of the
|
||||
@@ -154,6 +158,13 @@ MESSAGE
|
||||
end
|
||||
end
|
||||
|
||||
# Sets flash message if is_flashing_format? equals true
|
||||
def set_flash_message!(key, kind, options = {})
|
||||
if is_flashing_format?
|
||||
set_flash_message(key, kind, options)
|
||||
end
|
||||
end
|
||||
|
||||
# Sets minimum password length to show to user
|
||||
def set_minimum_password_length
|
||||
if devise_mapping.validatable?
|
||||
|
||||
@@ -16,5 +16,9 @@ if defined?(ActionMailer)
|
||||
@token = token
|
||||
devise_mail(record, :unlock_instructions, opts)
|
||||
end
|
||||
|
||||
def password_change(record, opts={})
|
||||
devise_mail(record, :password_change, opts)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
<div class="field">
|
||||
<%= f.label :email %><br />
|
||||
<%= f.email_field :email, autofocus: true, value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) %>
|
||||
<%= f.email_field :email, autofocus: true, value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) %>
|
||||
</div>
|
||||
|
||||
<div class="actions">
|
||||
|
||||
3
app/views/devise/mailer/password_change.html.erb
Normal file
3
app/views/devise/mailer/password_change.html.erb
Normal file
@@ -0,0 +1,3 @@
|
||||
<p>Hello <%= @resource.email %>!</p>
|
||||
|
||||
<p>We're contacting you to notify you that your password has been changed.</p>
|
||||
@@ -7,8 +7,8 @@
|
||||
<div class="field">
|
||||
<%= f.label :password, "New password" %><br />
|
||||
<% if @minimum_password_length %>
|
||||
<em>(<%= @minimum_password_length %> characters minimum)</em>
|
||||
<% end %><br />
|
||||
<em>(<%= @minimum_password_length %> characters minimum)</em><br />
|
||||
<% end %>
|
||||
<%= f.password_field :password, autofocus: true, autocomplete: "off" %>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -15,6 +15,10 @@
|
||||
<div class="field">
|
||||
<%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
|
||||
<%= f.password_field :password, autocomplete: "off" %>
|
||||
<% if @minimum_password_length %>
|
||||
<br />
|
||||
<em><%= @minimum_password_length %> characters minimum</em>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
|
||||
@@ -20,6 +20,6 @@
|
||||
|
||||
<%- if devise_mapping.omniauthable? %>
|
||||
<%- resource_class.omniauth_providers.each do |provider| %>
|
||||
<%= link_to "Sign in with #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider) %><br />
|
||||
<%= link_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(resource_name, provider) %><br />
|
||||
<% end -%>
|
||||
<% end -%>
|
||||
|
||||
13
bin/test
Executable file
13
bin/test
Executable file
@@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env ruby
|
||||
$: << File.expand_path(File.expand_path('../../test', __FILE__))
|
||||
|
||||
require 'bundler/setup'
|
||||
begin
|
||||
require 'rails/test_unit/minitest_plugin'
|
||||
rescue LoadError
|
||||
exec 'rake'
|
||||
end
|
||||
|
||||
Rails::TestUnitReporter.executable = 'bin/test'
|
||||
|
||||
exit Minitest.run(ARGV)
|
||||
@@ -23,6 +23,8 @@ en:
|
||||
subject: "Reset password instructions"
|
||||
unlock_instructions:
|
||||
subject: "Unlock instructions"
|
||||
password_change:
|
||||
subject: "Password Changed"
|
||||
omniauth_callbacks:
|
||||
failure: "Could not authenticate you from %{kind} because \"%{reason}\"."
|
||||
success: "Successfully authenticated from %{kind} account."
|
||||
|
||||
@@ -13,17 +13,14 @@ Gem::Specification.new do |s|
|
||||
s.description = "Flexible authentication solution for Rails with Warden"
|
||||
s.authors = ['José Valim', 'Carlos Antônio']
|
||||
|
||||
s.rubyforge_project = "devise"
|
||||
|
||||
s.files = `git ls-files`.split("\n")
|
||||
s.test_files = `git ls-files -- test/*`.split("\n")
|
||||
s.require_paths = ["lib"]
|
||||
s.required_ruby_version = '>= 1.9.3'
|
||||
s.required_ruby_version = '>= 2.1.0'
|
||||
|
||||
s.add_dependency("warden", "~> 1.2.3")
|
||||
s.add_dependency("orm_adapter", "~> 0.1")
|
||||
s.add_dependency("bcrypt", "~> 3.0")
|
||||
s.add_dependency("thread_safe", "~> 0.1")
|
||||
s.add_dependency("railties", ">= 3.2.6", "< 5")
|
||||
s.add_dependency("railties", ">= 4.1.0", "< 5.1")
|
||||
s.add_dependency("responders")
|
||||
end
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
source "https://rubygems.org"
|
||||
|
||||
gemspec path: '..'
|
||||
|
||||
gem "rails", github: 'rails/rails', branch: '3-2-stable'
|
||||
gem "omniauth", "~> 1.2.0"
|
||||
gem "omniauth-oauth2", "~> 1.1.0"
|
||||
gem "rdoc"
|
||||
|
||||
group :test do
|
||||
gem "omniauth-facebook"
|
||||
gem "omniauth-openid", "~> 1.0.1"
|
||||
gem "webrat", "0.7.3", require: false
|
||||
gem "mocha", "~> 1.1", require: false
|
||||
end
|
||||
|
||||
platforms :jruby do
|
||||
gem "activerecord-jdbc-adapter"
|
||||
gem "activerecord-jdbcsqlite3-adapter"
|
||||
gem "jruby-openssl"
|
||||
end
|
||||
|
||||
platforms :ruby do
|
||||
gem "sqlite3"
|
||||
end
|
||||
|
||||
group :mongoid do
|
||||
gem "mongoid", "~> 3.0"
|
||||
end
|
||||
@@ -1,169 +0,0 @@
|
||||
GIT
|
||||
remote: git://github.com/rails/rails.git
|
||||
revision: b344986bc3d94ca7821fc5e0eef1874882ac6cbb
|
||||
branch: 3-2-stable
|
||||
specs:
|
||||
actionmailer (3.2.21)
|
||||
actionpack (= 3.2.21)
|
||||
mail (~> 2.5.4)
|
||||
actionpack (3.2.21)
|
||||
activemodel (= 3.2.21)
|
||||
activesupport (= 3.2.21)
|
||||
builder (~> 3.0.0)
|
||||
erubis (~> 2.7.0)
|
||||
journey (~> 1.0.4)
|
||||
rack (~> 1.4.5)
|
||||
rack-cache (~> 1.2)
|
||||
rack-test (~> 0.6.1)
|
||||
sprockets (~> 2.2.1)
|
||||
activemodel (3.2.21)
|
||||
activesupport (= 3.2.21)
|
||||
builder (~> 3.0.0)
|
||||
activerecord (3.2.21)
|
||||
activemodel (= 3.2.21)
|
||||
activesupport (= 3.2.21)
|
||||
arel (~> 3.0.2)
|
||||
tzinfo (~> 0.3.29)
|
||||
activeresource (3.2.21)
|
||||
activemodel (= 3.2.21)
|
||||
activesupport (= 3.2.21)
|
||||
activesupport (3.2.21)
|
||||
i18n (~> 0.6, >= 0.6.4)
|
||||
multi_json (~> 1.0)
|
||||
rails (3.2.21)
|
||||
actionmailer (= 3.2.21)
|
||||
actionpack (= 3.2.21)
|
||||
activerecord (= 3.2.21)
|
||||
activeresource (= 3.2.21)
|
||||
activesupport (= 3.2.21)
|
||||
bundler (~> 1.0)
|
||||
railties (= 3.2.21)
|
||||
railties (3.2.21)
|
||||
actionpack (= 3.2.21)
|
||||
activesupport (= 3.2.21)
|
||||
rack-ssl (~> 1.3.2)
|
||||
rake (>= 0.8.7)
|
||||
rdoc (~> 3.4)
|
||||
thor (>= 0.14.6, < 2.0)
|
||||
|
||||
PATH
|
||||
remote: ..
|
||||
specs:
|
||||
devise (3.4.1)
|
||||
bcrypt (~> 3.0)
|
||||
orm_adapter (~> 0.1)
|
||||
railties (>= 3.2.6, < 5)
|
||||
responders
|
||||
thread_safe (~> 0.1)
|
||||
warden (~> 1.2.3)
|
||||
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
arel (3.0.3)
|
||||
bcrypt (3.1.10)
|
||||
builder (3.0.4)
|
||||
erubis (2.7.0)
|
||||
faraday (0.9.1)
|
||||
multipart-post (>= 1.2, < 3)
|
||||
hashie (3.4.0)
|
||||
hike (1.2.3)
|
||||
i18n (0.7.0)
|
||||
journey (1.0.4)
|
||||
json (1.8.2)
|
||||
jwt (1.4.1)
|
||||
mail (2.5.4)
|
||||
mime-types (~> 1.16)
|
||||
treetop (~> 1.4.8)
|
||||
metaclass (0.0.4)
|
||||
mime-types (1.25.1)
|
||||
mini_portile (0.6.2)
|
||||
mocha (1.1.0)
|
||||
metaclass (~> 0.0.1)
|
||||
mongoid (3.1.6)
|
||||
activemodel (~> 3.2)
|
||||
moped (~> 1.4)
|
||||
origin (~> 1.0)
|
||||
tzinfo (~> 0.3.29)
|
||||
moped (1.5.2)
|
||||
multi_json (1.11.0)
|
||||
multi_xml (0.5.5)
|
||||
multipart-post (2.0.0)
|
||||
nokogiri (1.6.6.2)
|
||||
mini_portile (~> 0.6.0)
|
||||
oauth2 (0.9.4)
|
||||
faraday (>= 0.8, < 0.10)
|
||||
jwt (~> 1.0)
|
||||
multi_json (~> 1.3)
|
||||
multi_xml (~> 0.5)
|
||||
rack (~> 1.2)
|
||||
omniauth (1.2.2)
|
||||
hashie (>= 1.2, < 4)
|
||||
rack (~> 1.0)
|
||||
omniauth-facebook (1.6.0)
|
||||
omniauth-oauth2 (~> 1.1)
|
||||
omniauth-oauth2 (1.1.2)
|
||||
faraday (>= 0.8, < 0.10)
|
||||
multi_json (~> 1.3)
|
||||
oauth2 (~> 0.9.3)
|
||||
omniauth (~> 1.2)
|
||||
omniauth-openid (1.0.1)
|
||||
omniauth (~> 1.0)
|
||||
rack-openid (~> 1.3.1)
|
||||
origin (1.1.0)
|
||||
orm_adapter (0.5.0)
|
||||
polyglot (0.3.5)
|
||||
rack (1.4.5)
|
||||
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.4)
|
||||
rack
|
||||
rack-test (0.6.3)
|
||||
rack (>= 1.0)
|
||||
rake (10.4.2)
|
||||
rdoc (3.12.2)
|
||||
json (~> 1.4)
|
||||
responders (1.1.2)
|
||||
railties (>= 3.2, < 4.2)
|
||||
ruby-openid (2.7.0)
|
||||
sprockets (2.2.3)
|
||||
hike (~> 1.2)
|
||||
multi_json (~> 1.0)
|
||||
rack (~> 1.0)
|
||||
tilt (~> 1.1, != 1.3.0)
|
||||
sqlite3 (1.3.10)
|
||||
thor (0.19.1)
|
||||
thread_safe (0.3.5)
|
||||
tilt (1.4.1)
|
||||
treetop (1.4.15)
|
||||
polyglot
|
||||
polyglot (>= 0.3.1)
|
||||
tzinfo (0.3.43)
|
||||
warden (1.2.3)
|
||||
rack (>= 1.0)
|
||||
webrat (0.7.3)
|
||||
nokogiri (>= 1.2.0)
|
||||
rack (>= 1.0)
|
||||
rack-test (>= 0.5.3)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
activerecord-jdbc-adapter
|
||||
activerecord-jdbcsqlite3-adapter
|
||||
devise!
|
||||
jruby-openssl
|
||||
mocha (~> 1.1)
|
||||
mongoid (~> 3.0)
|
||||
omniauth (~> 1.2.0)
|
||||
omniauth-facebook
|
||||
omniauth-oauth2 (~> 1.1.0)
|
||||
omniauth-openid (~> 1.0.1)
|
||||
rails!
|
||||
rdoc
|
||||
sqlite3
|
||||
webrat (= 0.7.3)
|
||||
@@ -1,29 +0,0 @@
|
||||
source "https://rubygems.org"
|
||||
|
||||
gemspec path: '..'
|
||||
|
||||
gem "rails", github: 'rails/rails', branch: '4-0-stable'
|
||||
gem "omniauth", "~> 1.2.0"
|
||||
gem "omniauth-oauth2", "~> 1.1.0"
|
||||
gem "rdoc"
|
||||
|
||||
group :test do
|
||||
gem "omniauth-facebook"
|
||||
gem "omniauth-openid", "~> 1.0.1"
|
||||
gem "webrat", "0.7.3", require: false
|
||||
gem "mocha", "~> 1.1", require: false
|
||||
end
|
||||
|
||||
platforms :jruby do
|
||||
gem "activerecord-jdbc-adapter"
|
||||
gem "activerecord-jdbcsqlite3-adapter"
|
||||
gem "jruby-openssl"
|
||||
end
|
||||
|
||||
platforms :ruby do
|
||||
gem "sqlite3"
|
||||
end
|
||||
|
||||
group :mongoid do
|
||||
gem "mongoid", "~> 4.0.0"
|
||||
end
|
||||
@@ -1,163 +0,0 @@
|
||||
GIT
|
||||
remote: git://github.com/rails/rails.git
|
||||
revision: 7ec9c9635bf4d57009135ed11e89d8bf32306d73
|
||||
branch: 4-0-stable
|
||||
specs:
|
||||
actionmailer (4.0.13)
|
||||
actionpack (= 4.0.13)
|
||||
mail (~> 2.5, >= 2.5.4)
|
||||
actionpack (4.0.13)
|
||||
activesupport (= 4.0.13)
|
||||
builder (~> 3.1.0)
|
||||
erubis (~> 2.7.0)
|
||||
rack (~> 1.5.2)
|
||||
rack-test (~> 0.6.2)
|
||||
activemodel (4.0.13)
|
||||
activesupport (= 4.0.13)
|
||||
builder (~> 3.1.0)
|
||||
activerecord (4.0.13)
|
||||
activemodel (= 4.0.13)
|
||||
activerecord-deprecated_finders (~> 1.0.2)
|
||||
activesupport (= 4.0.13)
|
||||
arel (~> 4.0.0)
|
||||
activesupport (4.0.13)
|
||||
i18n (~> 0.6, >= 0.6.9)
|
||||
minitest (~> 4.2)
|
||||
multi_json (~> 1.3)
|
||||
thread_safe (~> 0.1)
|
||||
tzinfo (~> 0.3.37)
|
||||
rails (4.0.13)
|
||||
actionmailer (= 4.0.13)
|
||||
actionpack (= 4.0.13)
|
||||
activerecord (= 4.0.13)
|
||||
activesupport (= 4.0.13)
|
||||
bundler (>= 1.3.0, < 2.0)
|
||||
railties (= 4.0.13)
|
||||
sprockets-rails (~> 2.0)
|
||||
railties (4.0.13)
|
||||
actionpack (= 4.0.13)
|
||||
activesupport (= 4.0.13)
|
||||
rake (>= 0.8.7)
|
||||
thor (>= 0.18.1, < 2.0)
|
||||
|
||||
PATH
|
||||
remote: ..
|
||||
specs:
|
||||
devise (3.4.1)
|
||||
bcrypt (~> 3.0)
|
||||
orm_adapter (~> 0.1)
|
||||
railties (>= 3.2.6, < 5)
|
||||
responders
|
||||
thread_safe (~> 0.1)
|
||||
warden (~> 1.2.3)
|
||||
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
activerecord-deprecated_finders (1.0.3)
|
||||
arel (4.0.2)
|
||||
bcrypt (3.1.10)
|
||||
bson (2.3.0)
|
||||
builder (3.1.4)
|
||||
connection_pool (2.1.3)
|
||||
erubis (2.7.0)
|
||||
faraday (0.9.1)
|
||||
multipart-post (>= 1.2, < 3)
|
||||
hashie (3.4.0)
|
||||
hike (1.2.3)
|
||||
i18n (0.7.0)
|
||||
jwt (1.4.1)
|
||||
mail (2.6.3)
|
||||
mime-types (>= 1.16, < 3)
|
||||
metaclass (0.0.4)
|
||||
mime-types (2.4.3)
|
||||
mini_portile (0.6.2)
|
||||
minitest (4.7.5)
|
||||
mocha (1.1.0)
|
||||
metaclass (~> 0.0.1)
|
||||
mongoid (4.0.2)
|
||||
activemodel (~> 4.0)
|
||||
moped (~> 2.0.0)
|
||||
origin (~> 2.1)
|
||||
tzinfo (>= 0.3.37)
|
||||
moped (2.0.4)
|
||||
bson (~> 2.2)
|
||||
connection_pool (~> 2.0)
|
||||
optionable (~> 0.2.0)
|
||||
multi_json (1.11.0)
|
||||
multi_xml (0.5.5)
|
||||
multipart-post (2.0.0)
|
||||
nokogiri (1.6.6.2)
|
||||
mini_portile (~> 0.6.0)
|
||||
oauth2 (0.9.4)
|
||||
faraday (>= 0.8, < 0.10)
|
||||
jwt (~> 1.0)
|
||||
multi_json (~> 1.3)
|
||||
multi_xml (~> 0.5)
|
||||
rack (~> 1.2)
|
||||
omniauth (1.2.2)
|
||||
hashie (>= 1.2, < 4)
|
||||
rack (~> 1.0)
|
||||
omniauth-facebook (1.6.0)
|
||||
omniauth-oauth2 (~> 1.1)
|
||||
omniauth-oauth2 (1.1.2)
|
||||
faraday (>= 0.8, < 0.10)
|
||||
multi_json (~> 1.3)
|
||||
oauth2 (~> 0.9.3)
|
||||
omniauth (~> 1.2)
|
||||
omniauth-openid (1.0.1)
|
||||
omniauth (~> 1.0)
|
||||
rack-openid (~> 1.3.1)
|
||||
optionable (0.2.0)
|
||||
origin (2.1.1)
|
||||
orm_adapter (0.5.0)
|
||||
rack (1.5.2)
|
||||
rack-openid (1.3.1)
|
||||
rack (>= 1.1.0)
|
||||
ruby-openid (>= 2.1.8)
|
||||
rack-test (0.6.3)
|
||||
rack (>= 1.0)
|
||||
rake (10.4.2)
|
||||
rdoc (4.2.0)
|
||||
responders (1.1.2)
|
||||
railties (>= 3.2, < 4.2)
|
||||
ruby-openid (2.7.0)
|
||||
sprockets (2.12.3)
|
||||
hike (~> 1.2)
|
||||
multi_json (~> 1.0)
|
||||
rack (~> 1.0)
|
||||
tilt (~> 1.1, != 1.3.0)
|
||||
sprockets-rails (2.2.4)
|
||||
actionpack (>= 3.0)
|
||||
activesupport (>= 3.0)
|
||||
sprockets (>= 2.8, < 4.0)
|
||||
sqlite3 (1.3.10)
|
||||
thor (0.19.1)
|
||||
thread_safe (0.3.5)
|
||||
tilt (1.4.1)
|
||||
tzinfo (0.3.43)
|
||||
warden (1.2.3)
|
||||
rack (>= 1.0)
|
||||
webrat (0.7.3)
|
||||
nokogiri (>= 1.2.0)
|
||||
rack (>= 1.0)
|
||||
rack-test (>= 0.5.3)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
activerecord-jdbc-adapter
|
||||
activerecord-jdbcsqlite3-adapter
|
||||
devise!
|
||||
jruby-openssl
|
||||
mocha (~> 1.1)
|
||||
mongoid (~> 4.0.0)
|
||||
omniauth (~> 1.2.0)
|
||||
omniauth-facebook
|
||||
omniauth-oauth2 (~> 1.1.0)
|
||||
omniauth-openid (~> 1.0.1)
|
||||
rails!
|
||||
rdoc
|
||||
sqlite3
|
||||
webrat (= 0.7.3)
|
||||
@@ -1,17 +1,18 @@
|
||||
source "https://rubygems.org"
|
||||
|
||||
gemspec path: '..'
|
||||
gemspec path: ".."
|
||||
|
||||
gem "rails", github: 'rails/rails', branch: '4-1-stable'
|
||||
gem "omniauth", "~> 1.2.0"
|
||||
gem "omniauth-oauth2", "~> 1.1.0"
|
||||
gem "rails", github: "rails/rails", branch: "4-1-stable"
|
||||
gem "omniauth"
|
||||
gem "omniauth-oauth2"
|
||||
gem "rdoc"
|
||||
|
||||
group :test do
|
||||
gem "omniauth-facebook"
|
||||
gem "omniauth-openid", "~> 1.0.1"
|
||||
gem "omniauth-openid"
|
||||
gem "webrat", "0.7.3", require: false
|
||||
gem "mocha", "~> 1.1", require: false
|
||||
gem 'test_after_commit', require: false
|
||||
end
|
||||
|
||||
platforms :jruby do
|
||||
@@ -25,5 +26,5 @@ platforms :ruby do
|
||||
end
|
||||
|
||||
group :mongoid do
|
||||
gem "mongoid", "~> 4.0.0"
|
||||
gem "mongoid", "~> 4.0"
|
||||
end
|
||||
|
||||
@@ -1,83 +1,84 @@
|
||||
GIT
|
||||
remote: git://github.com/rails/rails.git
|
||||
revision: bf32ec7b8611e6b4c7e9398f7d297a1f0221e9b9
|
||||
revision: 9f5cbe613c8a80282970c73b0f00095788d54e34
|
||||
branch: 4-1-stable
|
||||
specs:
|
||||
actionmailer (4.1.10)
|
||||
actionpack (= 4.1.10)
|
||||
actionview (= 4.1.10)
|
||||
actionmailer (4.1.15)
|
||||
actionpack (= 4.1.15)
|
||||
actionview (= 4.1.15)
|
||||
mail (~> 2.5, >= 2.5.4)
|
||||
actionpack (4.1.10)
|
||||
actionview (= 4.1.10)
|
||||
activesupport (= 4.1.10)
|
||||
actionpack (4.1.15)
|
||||
actionview (= 4.1.15)
|
||||
activesupport (= 4.1.15)
|
||||
rack (~> 1.5.2)
|
||||
rack-test (~> 0.6.2)
|
||||
actionview (4.1.10)
|
||||
activesupport (= 4.1.10)
|
||||
actionview (4.1.15)
|
||||
activesupport (= 4.1.15)
|
||||
builder (~> 3.1)
|
||||
erubis (~> 2.7.0)
|
||||
activemodel (4.1.10)
|
||||
activesupport (= 4.1.10)
|
||||
activemodel (4.1.15)
|
||||
activesupport (= 4.1.15)
|
||||
builder (~> 3.1)
|
||||
activerecord (4.1.10)
|
||||
activemodel (= 4.1.10)
|
||||
activesupport (= 4.1.10)
|
||||
activerecord (4.1.15)
|
||||
activemodel (= 4.1.15)
|
||||
activesupport (= 4.1.15)
|
||||
arel (~> 5.0.0)
|
||||
activesupport (4.1.10)
|
||||
activesupport (4.1.15)
|
||||
i18n (~> 0.6, >= 0.6.9)
|
||||
json (~> 1.7, >= 1.7.7)
|
||||
minitest (~> 5.1)
|
||||
thread_safe (~> 0.1)
|
||||
tzinfo (~> 1.1)
|
||||
rails (4.1.10)
|
||||
actionmailer (= 4.1.10)
|
||||
actionpack (= 4.1.10)
|
||||
actionview (= 4.1.10)
|
||||
activemodel (= 4.1.10)
|
||||
activerecord (= 4.1.10)
|
||||
activesupport (= 4.1.10)
|
||||
rails (4.1.15)
|
||||
actionmailer (= 4.1.15)
|
||||
actionpack (= 4.1.15)
|
||||
actionview (= 4.1.15)
|
||||
activemodel (= 4.1.15)
|
||||
activerecord (= 4.1.15)
|
||||
activesupport (= 4.1.15)
|
||||
bundler (>= 1.3.0, < 2.0)
|
||||
railties (= 4.1.10)
|
||||
railties (= 4.1.15)
|
||||
sprockets-rails (~> 2.0)
|
||||
railties (4.1.10)
|
||||
actionpack (= 4.1.10)
|
||||
activesupport (= 4.1.10)
|
||||
railties (4.1.15)
|
||||
actionpack (= 4.1.15)
|
||||
activesupport (= 4.1.15)
|
||||
rake (>= 0.8.7)
|
||||
thor (>= 0.18.1, < 2.0)
|
||||
|
||||
PATH
|
||||
remote: ..
|
||||
specs:
|
||||
devise (3.4.1)
|
||||
devise (4.2.0)
|
||||
bcrypt (~> 3.0)
|
||||
orm_adapter (~> 0.1)
|
||||
railties (>= 3.2.6, < 5)
|
||||
railties (>= 4.1.0, < 5.1)
|
||||
responders
|
||||
thread_safe (~> 0.1)
|
||||
warden (~> 1.2.3)
|
||||
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
arel (5.0.1.20140414130214)
|
||||
bcrypt (3.1.10)
|
||||
bson (2.3.0)
|
||||
bcrypt (3.1.11)
|
||||
bson (3.2.6)
|
||||
builder (3.2.2)
|
||||
connection_pool (2.1.3)
|
||||
concurrent-ruby (1.0.2)
|
||||
connection_pool (2.2.0)
|
||||
erubis (2.7.0)
|
||||
faraday (0.9.1)
|
||||
faraday (0.9.2)
|
||||
multipart-post (>= 1.2, < 3)
|
||||
hashie (3.4.0)
|
||||
hike (1.2.3)
|
||||
hashie (3.4.4)
|
||||
i18n (0.7.0)
|
||||
json (1.8.2)
|
||||
jwt (1.4.1)
|
||||
mail (2.6.3)
|
||||
mime-types (>= 1.16, < 3)
|
||||
json (1.8.3)
|
||||
jwt (1.5.4)
|
||||
mail (2.6.4)
|
||||
mime-types (>= 1.16, < 4)
|
||||
metaclass (0.0.4)
|
||||
mime-types (2.4.3)
|
||||
mini_portile (0.6.2)
|
||||
minitest (5.5.1)
|
||||
mime-types (3.1)
|
||||
mime-types-data (~> 3.2015)
|
||||
mime-types-data (3.2016.0521)
|
||||
mini_portile2 (2.1.0)
|
||||
minitest (5.9.0)
|
||||
mocha (1.1.0)
|
||||
metaclass (~> 0.0.1)
|
||||
mongoid (4.0.2)
|
||||
@@ -85,64 +86,64 @@ GEM
|
||||
moped (~> 2.0.0)
|
||||
origin (~> 2.1)
|
||||
tzinfo (>= 0.3.37)
|
||||
moped (2.0.4)
|
||||
bson (~> 2.2)
|
||||
moped (2.0.7)
|
||||
bson (~> 3.0)
|
||||
connection_pool (~> 2.0)
|
||||
optionable (~> 0.2.0)
|
||||
multi_json (1.11.0)
|
||||
multi_json (1.12.1)
|
||||
multi_xml (0.5.5)
|
||||
multipart-post (2.0.0)
|
||||
nokogiri (1.6.6.2)
|
||||
mini_portile (~> 0.6.0)
|
||||
oauth2 (0.9.4)
|
||||
nokogiri (1.6.8)
|
||||
mini_portile2 (~> 2.1.0)
|
||||
pkg-config (~> 1.1.7)
|
||||
oauth2 (1.2.0)
|
||||
faraday (>= 0.8, < 0.10)
|
||||
jwt (~> 1.0)
|
||||
multi_json (~> 1.3)
|
||||
multi_xml (~> 0.5)
|
||||
rack (~> 1.2)
|
||||
omniauth (1.2.2)
|
||||
rack (>= 1.2, < 3)
|
||||
omniauth (1.3.1)
|
||||
hashie (>= 1.2, < 4)
|
||||
rack (~> 1.0)
|
||||
omniauth-facebook (1.6.0)
|
||||
omniauth-oauth2 (~> 1.1)
|
||||
omniauth-oauth2 (1.1.2)
|
||||
faraday (>= 0.8, < 0.10)
|
||||
multi_json (~> 1.3)
|
||||
oauth2 (~> 0.9.3)
|
||||
rack (>= 1.0, < 3)
|
||||
omniauth-facebook (3.0.0)
|
||||
omniauth-oauth2 (~> 1.2)
|
||||
omniauth-oauth2 (1.4.0)
|
||||
oauth2 (~> 1.0)
|
||||
omniauth (~> 1.2)
|
||||
omniauth-openid (1.0.1)
|
||||
omniauth (~> 1.0)
|
||||
rack-openid (~> 1.3.1)
|
||||
optionable (0.2.0)
|
||||
origin (2.1.1)
|
||||
origin (2.2.0)
|
||||
orm_adapter (0.5.0)
|
||||
rack (1.5.2)
|
||||
pkg-config (1.1.7)
|
||||
rack (1.5.5)
|
||||
rack-openid (1.3.1)
|
||||
rack (>= 1.1.0)
|
||||
ruby-openid (>= 2.1.8)
|
||||
rack-test (0.6.3)
|
||||
rack (>= 1.0)
|
||||
rake (10.4.2)
|
||||
rdoc (4.2.0)
|
||||
rake (11.2.2)
|
||||
rdoc (4.2.2)
|
||||
json (~> 1.4)
|
||||
responders (1.1.2)
|
||||
railties (>= 3.2, < 4.2)
|
||||
ruby-openid (2.7.0)
|
||||
sprockets (2.12.3)
|
||||
hike (~> 1.2)
|
||||
multi_json (~> 1.0)
|
||||
rack (~> 1.0)
|
||||
tilt (~> 1.1, != 1.3.0)
|
||||
sprockets-rails (2.2.4)
|
||||
sprockets (3.6.2)
|
||||
concurrent-ruby (~> 1.0)
|
||||
rack (> 1, < 3)
|
||||
sprockets-rails (2.3.3)
|
||||
actionpack (>= 3.0)
|
||||
activesupport (>= 3.0)
|
||||
sprockets (>= 2.8, < 4.0)
|
||||
sqlite3 (1.3.10)
|
||||
sqlite3 (1.3.11)
|
||||
test_after_commit (1.1.0)
|
||||
activerecord (>= 3.2)
|
||||
thor (0.19.1)
|
||||
thread_safe (0.3.5)
|
||||
tilt (1.4.1)
|
||||
tzinfo (1.2.2)
|
||||
thread_safe (~> 0.1)
|
||||
warden (1.2.3)
|
||||
warden (1.2.6)
|
||||
rack (>= 1.0)
|
||||
webrat (0.7.3)
|
||||
nokogiri (>= 1.2.0)
|
||||
@@ -158,12 +159,16 @@ DEPENDENCIES
|
||||
devise!
|
||||
jruby-openssl
|
||||
mocha (~> 1.1)
|
||||
mongoid (~> 4.0.0)
|
||||
omniauth (~> 1.2.0)
|
||||
mongoid (~> 4.0)
|
||||
omniauth
|
||||
omniauth-facebook
|
||||
omniauth-oauth2 (~> 1.1.0)
|
||||
omniauth-openid (~> 1.0.1)
|
||||
omniauth-oauth2
|
||||
omniauth-openid
|
||||
rails!
|
||||
rdoc
|
||||
sqlite3
|
||||
test_after_commit
|
||||
webrat (= 0.7.3)
|
||||
|
||||
BUNDLED WITH
|
||||
1.12.5
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
source "https://rubygems.org"
|
||||
|
||||
gemspec path: '..'
|
||||
gemspec path: ".."
|
||||
|
||||
gem "rails", github: 'rails/rails', branch: '4-2-stable'
|
||||
gem "omniauth", "~> 1.2.2"
|
||||
gem "omniauth-oauth2", "~> 1.2.0"
|
||||
gem "rails", github: "rails/rails", branch: "4-2-stable"
|
||||
gem "omniauth"
|
||||
gem "omniauth-oauth2"
|
||||
gem "rdoc"
|
||||
|
||||
group :test do
|
||||
gem "omniauth-facebook"
|
||||
gem "omniauth-openid", "~> 1.0.1"
|
||||
gem "omniauth-openid"
|
||||
gem "webrat", "0.7.3", require: false
|
||||
gem "mocha", "~> 1.1", require: false
|
||||
gem 'test_after_commit', require: false
|
||||
end
|
||||
|
||||
platforms :jruby do
|
||||
@@ -25,5 +26,5 @@ platforms :ruby do
|
||||
end
|
||||
|
||||
group :mongoid do
|
||||
gem "mongoid", "~> 4.0.0"
|
||||
gem "mongoid", "~> 4.0"
|
||||
end
|
||||
|
||||
@@ -1,97 +1,98 @@
|
||||
GIT
|
||||
remote: git://github.com/rails/rails.git
|
||||
revision: f12ff8ddab7b199707ec36d72bd72f206f142c8b
|
||||
revision: 5a85938418285ab81e3db52ea102d19f95ed7a94
|
||||
branch: 4-2-stable
|
||||
specs:
|
||||
actionmailer (4.2.1)
|
||||
actionpack (= 4.2.1)
|
||||
actionview (= 4.2.1)
|
||||
activejob (= 4.2.1)
|
||||
actionmailer (4.2.7.rc1)
|
||||
actionpack (= 4.2.7.rc1)
|
||||
actionview (= 4.2.7.rc1)
|
||||
activejob (= 4.2.7.rc1)
|
||||
mail (~> 2.5, >= 2.5.4)
|
||||
rails-dom-testing (~> 1.0, >= 1.0.5)
|
||||
actionpack (4.2.1)
|
||||
actionview (= 4.2.1)
|
||||
activesupport (= 4.2.1)
|
||||
actionpack (4.2.7.rc1)
|
||||
actionview (= 4.2.7.rc1)
|
||||
activesupport (= 4.2.7.rc1)
|
||||
rack (~> 1.6)
|
||||
rack-test (~> 0.6.2)
|
||||
rails-dom-testing (~> 1.0, >= 1.0.5)
|
||||
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
||||
actionview (4.2.1)
|
||||
activesupport (= 4.2.1)
|
||||
actionview (4.2.7.rc1)
|
||||
activesupport (= 4.2.7.rc1)
|
||||
builder (~> 3.1)
|
||||
erubis (~> 2.7.0)
|
||||
rails-dom-testing (~> 1.0, >= 1.0.5)
|
||||
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
||||
activejob (4.2.1)
|
||||
activesupport (= 4.2.1)
|
||||
activejob (4.2.7.rc1)
|
||||
activesupport (= 4.2.7.rc1)
|
||||
globalid (>= 0.3.0)
|
||||
activemodel (4.2.1)
|
||||
activesupport (= 4.2.1)
|
||||
activemodel (4.2.7.rc1)
|
||||
activesupport (= 4.2.7.rc1)
|
||||
builder (~> 3.1)
|
||||
activerecord (4.2.1)
|
||||
activemodel (= 4.2.1)
|
||||
activesupport (= 4.2.1)
|
||||
activerecord (4.2.7.rc1)
|
||||
activemodel (= 4.2.7.rc1)
|
||||
activesupport (= 4.2.7.rc1)
|
||||
arel (~> 6.0)
|
||||
activesupport (4.2.1)
|
||||
activesupport (4.2.7.rc1)
|
||||
i18n (~> 0.7)
|
||||
json (~> 1.7, >= 1.7.7)
|
||||
minitest (~> 5.1)
|
||||
thread_safe (~> 0.3, >= 0.3.4)
|
||||
tzinfo (~> 1.1)
|
||||
rails (4.2.1)
|
||||
actionmailer (= 4.2.1)
|
||||
actionpack (= 4.2.1)
|
||||
actionview (= 4.2.1)
|
||||
activejob (= 4.2.1)
|
||||
activemodel (= 4.2.1)
|
||||
activerecord (= 4.2.1)
|
||||
activesupport (= 4.2.1)
|
||||
rails (4.2.7.rc1)
|
||||
actionmailer (= 4.2.7.rc1)
|
||||
actionpack (= 4.2.7.rc1)
|
||||
actionview (= 4.2.7.rc1)
|
||||
activejob (= 4.2.7.rc1)
|
||||
activemodel (= 4.2.7.rc1)
|
||||
activerecord (= 4.2.7.rc1)
|
||||
activesupport (= 4.2.7.rc1)
|
||||
bundler (>= 1.3.0, < 2.0)
|
||||
railties (= 4.2.1)
|
||||
railties (= 4.2.7.rc1)
|
||||
sprockets-rails
|
||||
railties (4.2.1)
|
||||
actionpack (= 4.2.1)
|
||||
activesupport (= 4.2.1)
|
||||
railties (4.2.7.rc1)
|
||||
actionpack (= 4.2.7.rc1)
|
||||
activesupport (= 4.2.7.rc1)
|
||||
rake (>= 0.8.7)
|
||||
thor (>= 0.18.1, < 2.0)
|
||||
|
||||
PATH
|
||||
remote: ..
|
||||
specs:
|
||||
devise (3.4.1)
|
||||
devise (4.2.0)
|
||||
bcrypt (~> 3.0)
|
||||
orm_adapter (~> 0.1)
|
||||
railties (>= 3.2.6, < 5)
|
||||
railties (>= 4.1.0, < 5.1)
|
||||
responders
|
||||
thread_safe (~> 0.1)
|
||||
warden (~> 1.2.3)
|
||||
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
arel (6.0.0)
|
||||
bcrypt (3.1.10)
|
||||
bson (2.3.0)
|
||||
arel (6.0.3)
|
||||
bcrypt (3.1.11)
|
||||
bson (3.2.6)
|
||||
builder (3.2.2)
|
||||
connection_pool (2.1.3)
|
||||
concurrent-ruby (1.0.2)
|
||||
connection_pool (2.2.0)
|
||||
erubis (2.7.0)
|
||||
faraday (0.9.1)
|
||||
faraday (0.9.2)
|
||||
multipart-post (>= 1.2, < 3)
|
||||
globalid (0.3.3)
|
||||
globalid (0.3.6)
|
||||
activesupport (>= 4.1.0)
|
||||
hashie (3.4.0)
|
||||
hike (1.2.3)
|
||||
hashie (3.4.4)
|
||||
i18n (0.7.0)
|
||||
json (1.8.2)
|
||||
jwt (1.4.1)
|
||||
loofah (2.0.1)
|
||||
json (1.8.3)
|
||||
jwt (1.5.4)
|
||||
loofah (2.0.3)
|
||||
nokogiri (>= 1.5.9)
|
||||
mail (2.6.3)
|
||||
mime-types (>= 1.16, < 3)
|
||||
mail (2.6.4)
|
||||
mime-types (>= 1.16, < 4)
|
||||
metaclass (0.0.4)
|
||||
mime-types (2.4.3)
|
||||
mini_portile (0.6.2)
|
||||
minitest (5.5.1)
|
||||
mime-types (3.1)
|
||||
mime-types-data (~> 3.2015)
|
||||
mime-types-data (3.2016.0521)
|
||||
mini_portile2 (2.1.0)
|
||||
minitest (5.9.0)
|
||||
mocha (1.1.0)
|
||||
metaclass (~> 0.0.1)
|
||||
mongoid (4.0.2)
|
||||
@@ -99,38 +100,38 @@ GEM
|
||||
moped (~> 2.0.0)
|
||||
origin (~> 2.1)
|
||||
tzinfo (>= 0.3.37)
|
||||
moped (2.0.4)
|
||||
bson (~> 2.2)
|
||||
moped (2.0.7)
|
||||
bson (~> 3.0)
|
||||
connection_pool (~> 2.0)
|
||||
optionable (~> 0.2.0)
|
||||
multi_json (1.11.0)
|
||||
multi_json (1.12.1)
|
||||
multi_xml (0.5.5)
|
||||
multipart-post (2.0.0)
|
||||
nokogiri (1.6.6.2)
|
||||
mini_portile (~> 0.6.0)
|
||||
oauth2 (1.0.0)
|
||||
nokogiri (1.6.8)
|
||||
mini_portile2 (~> 2.1.0)
|
||||
pkg-config (~> 1.1.7)
|
||||
oauth2 (1.2.0)
|
||||
faraday (>= 0.8, < 0.10)
|
||||
jwt (~> 1.0)
|
||||
multi_json (~> 1.3)
|
||||
multi_xml (~> 0.5)
|
||||
rack (~> 1.2)
|
||||
omniauth (1.2.2)
|
||||
rack (>= 1.2, < 3)
|
||||
omniauth (1.3.1)
|
||||
hashie (>= 1.2, < 4)
|
||||
rack (~> 1.0)
|
||||
omniauth-facebook (2.0.1)
|
||||
rack (>= 1.0, < 3)
|
||||
omniauth-facebook (3.0.0)
|
||||
omniauth-oauth2 (~> 1.2)
|
||||
omniauth-oauth2 (1.2.0)
|
||||
faraday (>= 0.8, < 0.10)
|
||||
multi_json (~> 1.3)
|
||||
omniauth-oauth2 (1.4.0)
|
||||
oauth2 (~> 1.0)
|
||||
omniauth (~> 1.2)
|
||||
omniauth-openid (1.0.1)
|
||||
omniauth (~> 1.0)
|
||||
rack-openid (~> 1.3.1)
|
||||
optionable (0.2.0)
|
||||
origin (2.1.1)
|
||||
origin (2.2.0)
|
||||
orm_adapter (0.5.0)
|
||||
rack (1.6.0)
|
||||
pkg-config (1.1.7)
|
||||
rack (1.6.4)
|
||||
rack-openid (1.3.1)
|
||||
rack (>= 1.1.0)
|
||||
ruby-openid (>= 2.1.8)
|
||||
@@ -138,33 +139,33 @@ GEM
|
||||
rack (>= 1.0)
|
||||
rails-deprecated_sanitizer (1.0.3)
|
||||
activesupport (>= 4.2.0.alpha)
|
||||
rails-dom-testing (1.0.6)
|
||||
rails-dom-testing (1.0.7)
|
||||
activesupport (>= 4.2.0.beta, < 5.0)
|
||||
nokogiri (~> 1.6.0)
|
||||
rails-deprecated_sanitizer (>= 1.0.1)
|
||||
rails-html-sanitizer (1.0.2)
|
||||
rails-html-sanitizer (1.0.3)
|
||||
loofah (~> 2.0)
|
||||
rake (10.4.2)
|
||||
rdoc (4.2.0)
|
||||
responders (2.1.0)
|
||||
railties (>= 4.2.0, < 5)
|
||||
rake (11.2.2)
|
||||
rdoc (4.2.2)
|
||||
json (~> 1.4)
|
||||
responders (2.2.0)
|
||||
railties (>= 4.2.0, < 5.1)
|
||||
ruby-openid (2.7.0)
|
||||
sprockets (2.12.3)
|
||||
hike (~> 1.2)
|
||||
multi_json (~> 1.0)
|
||||
rack (~> 1.0)
|
||||
tilt (~> 1.1, != 1.3.0)
|
||||
sprockets-rails (2.2.4)
|
||||
actionpack (>= 3.0)
|
||||
activesupport (>= 3.0)
|
||||
sprockets (>= 2.8, < 4.0)
|
||||
sqlite3 (1.3.10)
|
||||
sprockets (3.6.2)
|
||||
concurrent-ruby (~> 1.0)
|
||||
rack (> 1, < 3)
|
||||
sprockets-rails (3.1.1)
|
||||
actionpack (>= 4.0)
|
||||
activesupport (>= 4.0)
|
||||
sprockets (>= 3.0.0)
|
||||
sqlite3 (1.3.11)
|
||||
test_after_commit (1.1.0)
|
||||
activerecord (>= 3.2)
|
||||
thor (0.19.1)
|
||||
thread_safe (0.3.5)
|
||||
tilt (1.4.1)
|
||||
tzinfo (1.2.2)
|
||||
thread_safe (~> 0.1)
|
||||
warden (1.2.3)
|
||||
warden (1.2.6)
|
||||
rack (>= 1.0)
|
||||
webrat (0.7.3)
|
||||
nokogiri (>= 1.2.0)
|
||||
@@ -180,12 +181,16 @@ DEPENDENCIES
|
||||
devise!
|
||||
jruby-openssl
|
||||
mocha (~> 1.1)
|
||||
mongoid (~> 4.0.0)
|
||||
omniauth (~> 1.2.2)
|
||||
mongoid (~> 4.0)
|
||||
omniauth
|
||||
omniauth-facebook
|
||||
omniauth-oauth2 (~> 1.2.0)
|
||||
omniauth-openid (~> 1.0.1)
|
||||
omniauth-oauth2
|
||||
omniauth-openid
|
||||
rails!
|
||||
rdoc
|
||||
sqlite3
|
||||
test_after_commit
|
||||
webrat (= 0.7.3)
|
||||
|
||||
BUNDLED WITH
|
||||
1.12.5
|
||||
|
||||
104
guides/bug_report_templates/integration_test.rb
Normal file
104
guides/bug_report_templates/integration_test.rb
Normal file
@@ -0,0 +1,104 @@
|
||||
begin
|
||||
require 'bundler/inline'
|
||||
rescue LoadError => e
|
||||
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
|
||||
raise e
|
||||
end
|
||||
|
||||
gemfile(true) do
|
||||
source 'https://rubygems.org'
|
||||
# Activate the gem you are reporting the issue against.
|
||||
gem 'rails', '~> 4.2.0'
|
||||
gem 'devise', '~> 4.0'
|
||||
gem 'sqlite3'
|
||||
gem 'byebug'
|
||||
end
|
||||
|
||||
require 'rack/test'
|
||||
require 'action_controller/railtie'
|
||||
require 'active_record'
|
||||
require 'devise/rails/routes'
|
||||
require 'devise/rails/warden_compat'
|
||||
|
||||
ActiveRecord::Base.establish_connection( adapter: :sqlite3, database: ':memory:')
|
||||
|
||||
class DeviseCreateUsers < ActiveRecord::Migration
|
||||
def change
|
||||
create_table(:users) do |t|
|
||||
t.string :email, null: false
|
||||
t.string :encrypted_password, null: true
|
||||
t.timestamps null: false
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
Devise.setup do |config|
|
||||
require 'devise/orm/active_record'
|
||||
config.secret_key = 'secret_key_base'
|
||||
end
|
||||
|
||||
class TestApp < Rails::Application
|
||||
config.root = File.dirname(__FILE__)
|
||||
config.session_store :cookie_store, key: 'cookie_store_key'
|
||||
secrets.secret_token = 'secret_token'
|
||||
secrets.secret_key_base = 'secret_key_base'
|
||||
config.eager_load = false
|
||||
|
||||
config.middleware.use Warden::Manager do |config|
|
||||
Devise.warden_config = config
|
||||
end
|
||||
|
||||
config.logger = Logger.new($stdout)
|
||||
Rails.logger = config.logger
|
||||
|
||||
end
|
||||
|
||||
Rails.application.initialize!
|
||||
|
||||
DeviseCreateUsers.migrate(:up)
|
||||
|
||||
class User < ActiveRecord::Base
|
||||
devise :database_authenticatable
|
||||
end
|
||||
|
||||
Rails.application.routes.draw do
|
||||
devise_for :users
|
||||
|
||||
get '/' => 'test#index'
|
||||
end
|
||||
|
||||
class ApplicationController < ActionController::Base
|
||||
end
|
||||
|
||||
class TestController < ApplicationController
|
||||
include Rails.application.routes.url_helpers
|
||||
|
||||
before_filter :authenticate_user!
|
||||
|
||||
def index
|
||||
render plain: 'Home'
|
||||
end
|
||||
end
|
||||
|
||||
require 'minitest/autorun'
|
||||
|
||||
class BugTest < ActionDispatch::IntegrationTest
|
||||
include Rack::Test::Methods
|
||||
include Warden::Test::Helpers
|
||||
|
||||
def test_returns_success
|
||||
Warden.test_mode!
|
||||
|
||||
login_as User.create!(email: 'test@test.com', password: 'test123456', password_confirmation: 'test123456')
|
||||
|
||||
get '/'
|
||||
assert last_response.ok?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def app
|
||||
Rails.application
|
||||
end
|
||||
end
|
||||
100
lib/devise.rb
Normal file → Executable file
100
lib/devise.rb
Normal file → Executable file
@@ -8,22 +8,22 @@ require 'responders'
|
||||
|
||||
module Devise
|
||||
autoload :Delegator, 'devise/delegator'
|
||||
autoload :Encryptor, 'devise/encryptor'
|
||||
autoload :FailureApp, 'devise/failure_app'
|
||||
autoload :OmniAuth, 'devise/omniauth'
|
||||
autoload :ParameterFilter, 'devise/parameter_filter'
|
||||
autoload :BaseSanitizer, 'devise/parameter_sanitizer'
|
||||
autoload :ParameterSanitizer, 'devise/parameter_sanitizer'
|
||||
autoload :TestHelpers, 'devise/test_helpers'
|
||||
autoload :TimeInflector, 'devise/time_inflector'
|
||||
autoload :TokenGenerator, 'devise/token_generator'
|
||||
|
||||
module Controllers
|
||||
autoload :Helpers, 'devise/controllers/helpers'
|
||||
autoload :Rememberable, 'devise/controllers/rememberable'
|
||||
autoload :ScopedViews, 'devise/controllers/scoped_views'
|
||||
autoload :SignInOut, 'devise/controllers/sign_in_out'
|
||||
autoload :StoreLocation, 'devise/controllers/store_location'
|
||||
autoload :UrlHelpers, 'devise/controllers/url_helpers'
|
||||
autoload :Helpers, 'devise/controllers/helpers'
|
||||
autoload :Rememberable, 'devise/controllers/rememberable'
|
||||
autoload :ScopedViews, 'devise/controllers/scoped_views'
|
||||
autoload :SignInOut, 'devise/controllers/sign_in_out'
|
||||
autoload :StoreLocation, 'devise/controllers/store_location'
|
||||
autoload :UrlHelpers, 'devise/controllers/url_helpers'
|
||||
end
|
||||
|
||||
module Hooks
|
||||
@@ -35,17 +35,22 @@ module Devise
|
||||
end
|
||||
|
||||
module Strategies
|
||||
autoload :Base, 'devise/strategies/base'
|
||||
autoload :Base, 'devise/strategies/base'
|
||||
autoload :Authenticatable, 'devise/strategies/authenticatable'
|
||||
end
|
||||
|
||||
module Test
|
||||
autoload :ControllerHelpers, 'devise/test/controller_helpers'
|
||||
autoload :IntegrationHelpers, 'devise/test/integration_helpers'
|
||||
end
|
||||
|
||||
# Constants which holds devise configuration for extensions. Those should
|
||||
# not be modified by the "end user" (this is why they are constants).
|
||||
ALL = []
|
||||
CONTROLLERS = ActiveSupport::OrderedHash.new
|
||||
ROUTES = ActiveSupport::OrderedHash.new
|
||||
STRATEGIES = ActiveSupport::OrderedHash.new
|
||||
URL_HELPERS = ActiveSupport::OrderedHash.new
|
||||
CONTROLLERS = {}
|
||||
ROUTES = {}
|
||||
STRATEGIES = {}
|
||||
URL_HELPERS = {}
|
||||
|
||||
# Strategies that do not require user input.
|
||||
NO_INPUT = []
|
||||
@@ -61,9 +66,9 @@ module Devise
|
||||
mattr_accessor :rememberable_options
|
||||
@@rememberable_options = {}
|
||||
|
||||
# The number of times to encrypt password.
|
||||
# The number of times to hash the password.
|
||||
mattr_accessor :stretches
|
||||
@@stretches = 10
|
||||
@@stretches = 11
|
||||
|
||||
# The default key used when authenticating over http auth.
|
||||
mattr_accessor :http_authentication_key
|
||||
@@ -83,7 +88,7 @@ module Devise
|
||||
|
||||
# Keys that should have whitespace stripped.
|
||||
mattr_accessor :strip_whitespace_keys
|
||||
@@strip_whitespace_keys = []
|
||||
@@strip_whitespace_keys = [:email]
|
||||
|
||||
# If http authentication is enabled by default.
|
||||
mattr_accessor :http_authenticatable
|
||||
@@ -101,11 +106,11 @@ module Devise
|
||||
mattr_accessor :http_authentication_realm
|
||||
@@http_authentication_realm = "Application"
|
||||
|
||||
# Email regex used to validate email formats. It simply asserts that
|
||||
# an one (and only one) @ exists in the given string. This is mainly
|
||||
# to give user feedback and not to assert the e-mail validity.
|
||||
# Email regex used to validate email formats. It asserts that there are no
|
||||
# @ symbols or whitespaces in either the localpart or the domain, and that
|
||||
# there is a single @ symbol separating the localpart and the domain.
|
||||
mattr_accessor :email_regexp
|
||||
@@email_regexp = /\A[^@\s]+@([^@\s]+\.)+[^@\s]+\z/
|
||||
@@email_regexp = /\A[^@\s]+@[^@\s]+\z/
|
||||
|
||||
# Range validation for password length
|
||||
mattr_accessor :password_length
|
||||
@@ -137,22 +142,21 @@ module Devise
|
||||
@@confirmation_keys = [:email]
|
||||
|
||||
# Defines if email should be reconfirmable.
|
||||
# False by default for backwards compatibility.
|
||||
mattr_accessor :reconfirmable
|
||||
@@reconfirmable = false
|
||||
@@reconfirmable = true
|
||||
|
||||
# Time interval to timeout the user session without activity.
|
||||
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.
|
||||
# Used to hash the password. Please generate one with rake secret.
|
||||
mattr_accessor :pepper
|
||||
@@pepper = nil
|
||||
|
||||
# Used to enable sending notification to user when their password is changed
|
||||
mattr_accessor :send_password_change_notification
|
||||
@@send_password_change_notification = false
|
||||
|
||||
# Scoped views. Since it relies on fallbacks to render default views, it's
|
||||
# turned off by default.
|
||||
mattr_accessor :scoped_views
|
||||
@@ -202,7 +206,7 @@ module Devise
|
||||
|
||||
# Skip session storage for the following strategies
|
||||
mattr_accessor :skip_session_storage
|
||||
@@skip_session_storage = []
|
||||
@@skip_session_storage = [:http_auth]
|
||||
|
||||
# Which formats should be treated as navigational.
|
||||
mattr_accessor :navigational_formats
|
||||
@@ -214,7 +218,7 @@ module Devise
|
||||
|
||||
# The default method used while signing out
|
||||
mattr_accessor :sign_out_via
|
||||
@@sign_out_via = :get
|
||||
@@sign_out_via = :delete
|
||||
|
||||
# The parent controller all Devise controllers inherits from.
|
||||
# Defaults to ApplicationController. This should be set early
|
||||
@@ -243,15 +247,22 @@ module Devise
|
||||
mattr_accessor :clean_up_csrf_token_on_authentication
|
||||
@@clean_up_csrf_token_on_authentication = true
|
||||
|
||||
# When false, Devise will not attempt to reload routes on eager load.
|
||||
# This can reduce the time taken to boot the app but if your application
|
||||
# requires the Devise mappings to be loaded during boot time the application
|
||||
# won't boot properly.
|
||||
mattr_accessor :reload_routes
|
||||
@@reload_routes = true
|
||||
|
||||
# PRIVATE CONFIGURATION
|
||||
|
||||
# Store scopes mappings.
|
||||
mattr_reader :mappings
|
||||
@@mappings = ActiveSupport::OrderedHash.new
|
||||
@@mappings = {}
|
||||
|
||||
# OmniAuth configurations.
|
||||
mattr_reader :omniauth_configs
|
||||
@@omniauth_configs = ActiveSupport::OrderedHash.new
|
||||
@@omniauth_configs = {}
|
||||
|
||||
# Define a set of modules that are called when a mapping is added.
|
||||
mattr_reader :helpers
|
||||
@@ -275,14 +286,14 @@ module Devise
|
||||
mattr_accessor :token_generator
|
||||
@@token_generator = nil
|
||||
|
||||
# Default way to setup Devise. Run rails generate devise_install to create
|
||||
# Default way to set up Devise. Run rails generate devise_install to create
|
||||
# a fresh initializer with all configuration values.
|
||||
def self.setup
|
||||
yield self
|
||||
end
|
||||
|
||||
class Getter
|
||||
def initialize name
|
||||
def initialize(name)
|
||||
@name = name
|
||||
end
|
||||
|
||||
@@ -292,12 +303,8 @@ module Devise
|
||||
end
|
||||
|
||||
def self.ref(arg)
|
||||
if defined?(ActiveSupport::Dependencies::ClassCache)
|
||||
ActiveSupport::Dependencies::reference(arg)
|
||||
Getter.new(arg)
|
||||
else
|
||||
ActiveSupport::Dependencies.ref(arg)
|
||||
end
|
||||
ActiveSupport::Dependencies.reference(arg)
|
||||
Getter.new(arg)
|
||||
end
|
||||
|
||||
def self.available_router_name
|
||||
@@ -328,7 +335,12 @@ module Devise
|
||||
mapping
|
||||
end
|
||||
|
||||
# Make Devise aware of an 3rd party Devise-module (like invitable). For convenience.
|
||||
# Register available devise modules. For the standard modules that Devise provides, this method is
|
||||
# called from lib/devise/modules.rb. Third-party modules need to be added explicitly using this method.
|
||||
#
|
||||
# Note that adding a module using this method does not cause it to be used in the authentication
|
||||
# process. That requires that the module be listed in the arguments passed to the 'devise' method
|
||||
# in the model class definition.
|
||||
#
|
||||
# == Options:
|
||||
#
|
||||
@@ -413,7 +425,6 @@ module Devise
|
||||
# config.omniauth :github, APP_ID, APP_SECRET
|
||||
#
|
||||
def self.omniauth(provider, *args)
|
||||
@@helpers << Devise::OmniAuth::UrlHelpers
|
||||
config = Devise::OmniAuth::Config.new(provider, args)
|
||||
@@omniauth_configs[config.strategy_name.to_sym] = config
|
||||
end
|
||||
@@ -436,8 +447,8 @@ module Devise
|
||||
Devise::Controllers::UrlHelpers.generate_helpers!
|
||||
end
|
||||
|
||||
# A method used internally to setup warden manager from the Rails initialize
|
||||
# block.
|
||||
# A method used internally to complete the setup of warden manager after routes are loaded.
|
||||
# See lib/devise/rails/routes.rb - ActionDispatch::Routing::RouteSet#finalize_with_devise!
|
||||
def self.configure_warden! #:nodoc:
|
||||
@@warden_configured ||= begin
|
||||
warden_config.failure_app = Devise::Delegator.new
|
||||
@@ -451,10 +462,7 @@ module Devise
|
||||
mapping.to.serialize_into_session(record)
|
||||
end
|
||||
|
||||
warden_config.serialize_from_session(mapping.name) do |key|
|
||||
# Previous versions contained an additional entry at the beginning of
|
||||
# key with the record's class name.
|
||||
args = key[-2, 2]
|
||||
warden_config.serialize_from_session(mapping.name) do |args|
|
||||
mapping.to.serialize_from_session(*args)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,7 +7,9 @@ module Devise
|
||||
include Devise::Controllers::StoreLocation
|
||||
|
||||
included do
|
||||
helper_method :warden, :signed_in?, :devise_controller?
|
||||
if respond_to?(:helper_method)
|
||||
helper_method :warden, :signed_in?, :devise_controller?
|
||||
end
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
@@ -28,8 +30,8 @@ module Devise
|
||||
# current_bloggers # Currently signed in user and admin
|
||||
#
|
||||
# Use:
|
||||
# before_filter :authenticate_blogger! # Redirects unless either a user or an admin are authenticated
|
||||
# before_filter ->{ authenticate_blogger! :admin } # Redirects to the admin login page
|
||||
# before_action :authenticate_blogger! # Redirects unless either a user or an admin are authenticated
|
||||
# before_action ->{ authenticate_blogger! :admin } # Redirects to the admin login page
|
||||
# current_blogger :user # Preferably returns a User if one is signed in
|
||||
#
|
||||
def devise_group(group_name, opts={})
|
||||
@@ -69,7 +71,9 @@ module Devise
|
||||
end.compact
|
||||
end
|
||||
|
||||
helper_method "current_#{group_name}", "current_#{group_name.to_s.pluralize}", "#{group_name}_signed_in?"
|
||||
if respond_to?(:helper_method)
|
||||
helper_method "current_#{group_name}", "current_#{group_name.to_s.pluralize}", "#{group_name}_signed_in?"
|
||||
end
|
||||
METHODS
|
||||
end
|
||||
|
||||
@@ -80,7 +84,7 @@ module Devise
|
||||
end
|
||||
|
||||
# Define authentication filters and accessor helpers based on mappings.
|
||||
# These filters should be used inside the controllers as before_filters,
|
||||
# These filters should be used inside the controllers as before_actions,
|
||||
# so you can control the scope of the user who should be signed in to
|
||||
# access that specific controller/action.
|
||||
# Example:
|
||||
@@ -100,8 +104,8 @@ module Devise
|
||||
# admin_session # Session data available only to the admin scope
|
||||
#
|
||||
# Use:
|
||||
# before_filter :authenticate_user! # Tell devise to use :user map
|
||||
# before_filter :authenticate_admin! # Tell devise to use :admin map
|
||||
# before_action :authenticate_user! # Tell devise to use :user map
|
||||
# before_action :authenticate_admin! # Tell devise to use :admin map
|
||||
#
|
||||
def self.define_helpers(mapping) #:nodoc:
|
||||
mapping = mapping.name
|
||||
@@ -126,33 +130,31 @@ module Devise
|
||||
METHODS
|
||||
|
||||
ActiveSupport.on_load(:action_controller) do
|
||||
helper_method "current_#{mapping}", "#{mapping}_signed_in?", "#{mapping}_session"
|
||||
if respond_to?(:helper_method)
|
||||
helper_method "current_#{mapping}", "#{mapping}_signed_in?", "#{mapping}_session"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# The main accessor for the warden proxy instance
|
||||
def warden
|
||||
request.env['warden']
|
||||
request.env['warden'] or raise MissingWarden
|
||||
end
|
||||
|
||||
# Return true if it's a devise_controller. false to all controllers unless
|
||||
# the controllers defined inside devise. Useful if you want to apply a before
|
||||
# filter to all controllers, except the ones in devise:
|
||||
#
|
||||
# before_filter :my_filter, unless: :devise_controller?
|
||||
# before_action :my_filter, unless: :devise_controller?
|
||||
def devise_controller?
|
||||
is_a?(::DeviseController)
|
||||
end
|
||||
|
||||
# Setup a param sanitizer to filter parameters using strong_parameters. See
|
||||
# Set up a param sanitizer to filter parameters using strong_parameters. See
|
||||
# lib/devise/parameter_sanitizer.rb for more info. Override this
|
||||
# method in your application controller to use your own parameter sanitizer.
|
||||
def devise_parameter_sanitizer
|
||||
@devise_parameter_sanitizer ||= if defined?(ActionController::StrongParameters)
|
||||
Devise::ParameterSanitizer.new(resource_class, resource_name, params)
|
||||
else
|
||||
Devise::BaseSanitizer.new(resource_class, resource_name, params)
|
||||
end
|
||||
@devise_parameter_sanitizer ||= Devise::ParameterSanitizer.new(resource_class, resource_name, params)
|
||||
end
|
||||
|
||||
# Tell warden that params authentication is allowed for that specific page.
|
||||
@@ -190,10 +192,10 @@ module Devise
|
||||
# root path. For a user scope, you can define the default url in
|
||||
# the following way:
|
||||
#
|
||||
# map.user_root '/users', controller: 'users' # creates user_root_path
|
||||
# get '/users' => 'users#index', as: :user_root # creates user_root_path
|
||||
#
|
||||
# map.namespace :user do |user|
|
||||
# user.root controller: 'users' # creates user_root_path
|
||||
# namespace :user do
|
||||
# root 'users#index' # creates user_root_path
|
||||
# end
|
||||
#
|
||||
# If the resource root path is not defined, root_path is used. However,
|
||||
@@ -269,16 +271,21 @@ module Devise
|
||||
|
||||
private
|
||||
|
||||
def expire_session_data_after_sign_in!
|
||||
ActiveSupport::Deprecation.warn "expire_session_data_after_sign_in! is deprecated " \
|
||||
"in favor of expire_data_after_sign_in!"
|
||||
expire_data_after_sign_in!
|
||||
end
|
||||
|
||||
def expire_data_after_sign_out!
|
||||
Devise.mappings.each { |_,m| instance_variable_set("@current_#{m.name}", nil) }
|
||||
super
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class MissingWarden < StandardError
|
||||
def initialize
|
||||
super "Devise could not find the `Warden::Proxy` instance on your request environment.\n" + \
|
||||
"Make sure that your application is loading Devise and Warden as expected and that " + \
|
||||
"the `Warden::Manager` middleware is present in your middleware stack.\n" + \
|
||||
"If you are seeing this on one of your tests, ensure that your tests are either " + \
|
||||
"executing the Rails middleware stack or that your tests are using the `Devise::Test::ControllerHelpers` " + \
|
||||
"module to inject the `request.env['warden']` object for you."
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -9,11 +9,18 @@ module Devise
|
||||
Rails.configuration.session_options.slice(:path, :domain, :secure)
|
||||
end
|
||||
|
||||
def remember_me_is_active?(resource)
|
||||
return false unless resource.respond_to?(:remember_me)
|
||||
scope = Devise::Mapping.find_scope!(resource)
|
||||
_, token, generated_at = cookies.signed[remember_key(resource, scope)]
|
||||
resource.remember_me?(token, generated_at)
|
||||
end
|
||||
|
||||
# Remembers the given resource by setting up a cookie
|
||||
def remember_me(resource)
|
||||
return if env["devise.skip_storage"]
|
||||
return if request.env["devise.skip_storage"]
|
||||
scope = Devise::Mapping.find_scope!(resource)
|
||||
resource.remember_me!(resource.extend_remember_period)
|
||||
resource.remember_me!
|
||||
cookies.signed[remember_key(resource, scope)] = remember_cookie_values(resource)
|
||||
end
|
||||
|
||||
|
||||
@@ -12,20 +12,15 @@ module Devise
|
||||
end
|
||||
|
||||
# Sign in a user that already was authenticated. This helper is useful for logging
|
||||
# users in after sign up.
|
||||
#
|
||||
# All options given to sign_in is passed forward to the set_user method in warden.
|
||||
# The only exception is the :bypass option, which bypass warden callbacks and stores
|
||||
# the user straight in session. This option is useful in cases the user is already
|
||||
# signed in, but we want to refresh the credentials in session.
|
||||
# users in after sign up. All options given to sign_in is passed forward
|
||||
# to the set_user method in warden.
|
||||
#
|
||||
# Examples:
|
||||
#
|
||||
# sign_in :user, @user # sign_in(scope, resource)
|
||||
# sign_in @user # sign_in(resource)
|
||||
# sign_in @user, event: :authentication # sign_in(resource, options)
|
||||
# sign_in @user, store: false # sign_in(resource, options)
|
||||
# sign_in @user, bypass: true # sign_in(resource, options)
|
||||
# sign_in @user, event: :authentication # sign_in(resource, options)
|
||||
# sign_in @user, store: false # sign_in(resource, options)
|
||||
#
|
||||
def sign_in(resource_or_scope, *args)
|
||||
options = args.extract_options!
|
||||
@@ -35,6 +30,13 @@ module Devise
|
||||
expire_data_after_sign_in!
|
||||
|
||||
if options[:bypass]
|
||||
ActiveSupport::Deprecation.warn(<<-DEPRECATION.strip_heredoc, caller)
|
||||
[Devise] bypass option is deprecated and it will be removed in future version of Devise.
|
||||
Please use bypass_sign_in method instead.
|
||||
Example:
|
||||
|
||||
bypass_sign_in(user)
|
||||
DEPRECATION
|
||||
warden.session_serializer.store(resource, scope)
|
||||
elsif warden.user(scope) == resource && !options.delete(:force)
|
||||
# Do nothing. User already signed in and we are not forcing it.
|
||||
@@ -44,6 +46,20 @@ module Devise
|
||||
end
|
||||
end
|
||||
|
||||
# Sign in a user bypassing the warden callbacks and stores the user
|
||||
# straight in session. This option is useful in cases the user is already
|
||||
# signed in, but we want to refresh the credentials in session.
|
||||
#
|
||||
# Examples:
|
||||
#
|
||||
# bypass_sign_in @user, scope: :user
|
||||
# bypass_sign_in @user
|
||||
def bypass_sign_in(resource, scope: nil)
|
||||
scope ||= Devise::Mapping.find_scope!(resource)
|
||||
expire_data_after_sign_in!
|
||||
warden.session_serializer.store(resource, scope)
|
||||
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
|
||||
@@ -58,7 +74,6 @@ module Devise
|
||||
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
||||
user = warden.user(scope: scope, run_callbacks: false) # If there is no user
|
||||
|
||||
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)
|
||||
@@ -90,13 +105,7 @@ module Devise
|
||||
session.keys.grep(/^devise\./).each { |k| session.delete(k) }
|
||||
end
|
||||
|
||||
def expire_data_after_sign_out!
|
||||
# session.keys will return an empty array if the session is not yet loaded.
|
||||
# This is a bug in both Rack and Rails.
|
||||
# A call to #empty? forces the session to be loaded.
|
||||
session.empty?
|
||||
session.keys.grep(/^devise\./).each { |k| session.delete(k) }
|
||||
end
|
||||
alias :expire_data_after_sign_out! :expire_data_after_sign_in!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -29,7 +29,7 @@ module Devise
|
||||
# Example:
|
||||
#
|
||||
# store_location_for(:user, dashboard_path)
|
||||
# redirect_to user_omniauth_authorize_path(:facebook)
|
||||
# redirect_to user_facebook_omniauth_authorize_path
|
||||
#
|
||||
def store_location_for(resource_or_scope, location)
|
||||
session_key = stored_location_key_for(resource_or_scope)
|
||||
|
||||
@@ -9,14 +9,14 @@ module Devise
|
||||
::BCrypt::Password.create(password, cost: klass.stretches).to_s
|
||||
end
|
||||
|
||||
def self.compare(klass, encrypted_password, password)
|
||||
return false if encrypted_password.blank?
|
||||
bcrypt = ::BCrypt::Password.new(encrypted_password)
|
||||
def self.compare(klass, hashed_password, password)
|
||||
return false if hashed_password.blank?
|
||||
bcrypt = ::BCrypt::Password.new(hashed_password)
|
||||
if klass.pepper.present?
|
||||
password = "#{password}#{klass.pepper}"
|
||||
end
|
||||
password = ::BCrypt::Engine.hash_secret(password, bcrypt.salt)
|
||||
Devise.secure_compare(password, encrypted_password)
|
||||
Devise.secure_compare(password, hashed_password)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,11 +2,10 @@ require "action_controller/metal"
|
||||
|
||||
module Devise
|
||||
# Failure application that will be called every time :warden is thrown from
|
||||
# any strategy or hook. Responsible for redirect the user to the sign in
|
||||
# page based on current scope and mapping. If no scope is given, redirect
|
||||
# to the default_url.
|
||||
# any strategy or hook. It is responsible for redirecting the user to the sign
|
||||
# in page based on current scope and mapping. If no scope is given, it
|
||||
# redirects to the default_url.
|
||||
class FailureApp < ActionController::Metal
|
||||
include ActionController::RackDelegation
|
||||
include ActionController::UrlFor
|
||||
include ActionController::Redirecting
|
||||
|
||||
@@ -22,9 +21,12 @@ module Devise
|
||||
@respond.call(env)
|
||||
end
|
||||
|
||||
# Try retrieving the URL options from the parent controller (usually
|
||||
# ApplicationController). Instance methods are not supported at the moment,
|
||||
# so only the class-level attribute is used.
|
||||
def self.default_url_options(*args)
|
||||
if defined?(ApplicationController)
|
||||
ApplicationController.default_url_options(*args)
|
||||
if defined?(Devise.parent_controller.constantize)
|
||||
Devise.parent_controller.constantize.try(:default_url_options) || {}
|
||||
else
|
||||
{}
|
||||
end
|
||||
@@ -48,9 +50,27 @@ module Devise
|
||||
end
|
||||
|
||||
def recall
|
||||
env["PATH_INFO"] = attempted_path
|
||||
header_info = if relative_url_root?
|
||||
base_path = Pathname.new(relative_url_root)
|
||||
full_path = Pathname.new(attempted_path)
|
||||
|
||||
{ "SCRIPT_NAME" => relative_url_root,
|
||||
"PATH_INFO" => '/' + full_path.relative_path_from(base_path).to_s }
|
||||
else
|
||||
{ "PATH_INFO" => attempted_path }
|
||||
end
|
||||
|
||||
header_info.each do | var, value|
|
||||
if request.respond_to?(:set_header)
|
||||
request.set_header(var, value)
|
||||
else
|
||||
request.env[var] = value
|
||||
end
|
||||
end
|
||||
|
||||
flash.now[:alert] = i18n_message(:invalid) if is_flashing_format?
|
||||
self.response = recall_app(warden_options[:recall]).call(env)
|
||||
# self.response = recall_app(warden_options[:recall]).call(env)
|
||||
self.response = recall_app(warden_options[:recall]).call(request.env)
|
||||
end
|
||||
|
||||
def redirect
|
||||
@@ -81,7 +101,7 @@ module Devise
|
||||
options[:scope] = "devise.failure"
|
||||
options[:default] = [message]
|
||||
auth_keys = scope_class.authentication_keys
|
||||
keys = auth_keys.respond_to?(:keys) ? auth_keys.keys : auth_keys
|
||||
keys = (auth_keys.respond_to?(:keys) ? auth_keys.keys : auth_keys).map { |key| scope_class.human_attribute_name(key) }
|
||||
options[:authentication_keys] = keys.join(I18n.translate(:"support.array.words_connector"))
|
||||
options = i18n_options(options)
|
||||
|
||||
@@ -113,14 +133,16 @@ module Devise
|
||||
|
||||
def scope_url
|
||||
opts = {}
|
||||
|
||||
# Initialize script_name with nil to prevent infinite loops in
|
||||
# authenticated mounted engines in rails 4.2 and 5.0
|
||||
opts[:script_name] = nil
|
||||
|
||||
route = route(scope)
|
||||
|
||||
opts[:format] = request_format unless skip_format?
|
||||
|
||||
config = Rails.application.config
|
||||
|
||||
if config.respond_to?(:relative_url_root) && config.relative_url_root.present?
|
||||
opts[:script_name] = config.relative_url_root
|
||||
end
|
||||
opts[:script_name] = relative_url_root if relative_url_root?
|
||||
|
||||
router_name = Devise.mappings[scope].router_name || Devise.available_router_name
|
||||
context = send(router_name)
|
||||
@@ -138,12 +160,12 @@ module Devise
|
||||
%w(html */*).include? request_format.to_s
|
||||
end
|
||||
|
||||
# Choose whether we should respond in a http authentication fashion,
|
||||
# Choose whether we should respond in an HTTP authentication fashion,
|
||||
# including 401 and optional headers.
|
||||
#
|
||||
# This method allows the user to explicitly disable http authentication
|
||||
# on ajax requests in case they want to redirect on failures instead of
|
||||
# handling the errors on their own. This is useful in case your ajax API
|
||||
# This method allows the user to explicitly disable HTTP authentication
|
||||
# on AJAX requests in case they want to redirect on failures instead of
|
||||
# handling the errors on their own. This is useful in case your AJAX API
|
||||
# is the same as your public API and uses a format like JSON (so you
|
||||
# cannot mark JSON as a navigational format).
|
||||
def http_auth?
|
||||
@@ -154,7 +176,7 @@ module Devise
|
||||
end
|
||||
end
|
||||
|
||||
# It does not make sense to send authenticate headers in ajax requests
|
||||
# It doesn't make sense to send authenticate headers in AJAX requests
|
||||
# or if the user disabled them.
|
||||
def http_auth_header?
|
||||
scope_class.http_authenticatable && !request.xhr?
|
||||
@@ -180,11 +202,11 @@ module Devise
|
||||
end
|
||||
|
||||
def warden
|
||||
env['warden']
|
||||
request.respond_to?(:get_header) ? request.get_header("warden") : request.env["warden"]
|
||||
end
|
||||
|
||||
def warden_options
|
||||
env['warden.options']
|
||||
request.respond_to?(:get_header) ? request.get_header("warden.options") : request.env["warden.options"]
|
||||
end
|
||||
|
||||
def warden_message
|
||||
@@ -203,10 +225,10 @@ module Devise
|
||||
warden_options[:attempted_path]
|
||||
end
|
||||
|
||||
# Stores requested uri to redirect the user after signing in. We cannot use
|
||||
# scoped session provided by warden here, since the user is not authenticated
|
||||
# yet, but we still need to store the uri based on scope, so different scopes
|
||||
# would never use the same uri to redirect.
|
||||
# Stores requested URI to redirect the user after signing in. We can't use
|
||||
# the scoped session provided by warden here, since the user is not
|
||||
# authenticated yet, but we still need to store the URI based on scope, so
|
||||
# different scopes would never use the same URI to redirect.
|
||||
def store_location!
|
||||
store_location_for(scope, attempted_path) if request.get? && !http_auth?
|
||||
end
|
||||
@@ -224,5 +246,17 @@ module Devise
|
||||
def request_format
|
||||
@request_format ||= request.format.try(:ref)
|
||||
end
|
||||
|
||||
def relative_url_root
|
||||
@relative_url_root ||= begin
|
||||
config = Rails.application.config
|
||||
|
||||
config.try(:relative_url_root) || config.action_controller.try(:relative_url_root)
|
||||
end
|
||||
end
|
||||
|
||||
def relative_url_root?
|
||||
relative_url_root.present?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
# 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) unless record.failed_attempts.to_i.zero?
|
||||
unless record.failed_attempts.to_i.zero?
|
||||
record.failed_attempts = 0
|
||||
record.save(validate: false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,7 +7,7 @@ module Devise
|
||||
include Devise::Controllers::SignInOut
|
||||
|
||||
attr_reader :warden
|
||||
delegate :cookies, :env, to: :warden
|
||||
delegate :cookies, :request, to: :warden
|
||||
|
||||
def initialize(warden)
|
||||
@warden = warden
|
||||
|
||||
@@ -7,7 +7,8 @@ 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
|
||||
if record && record.respond_to?(:timedout?) && warden.authenticated?(scope) &&
|
||||
options[:store] != false && !env['devise.skip_timeoutable']
|
||||
last_request_at = warden.session(scope)['last_request_at']
|
||||
|
||||
if last_request_at.is_a? Integer
|
||||
@@ -18,13 +19,10 @@ Warden::Manager.after_set_user do |record, warden, options|
|
||||
|
||||
proxy = Devise::Hooks::Proxy.new(warden)
|
||||
|
||||
if record.timedout?(last_request_at) && !env['devise.skip_timeout']
|
||||
if record.timedout?(last_request_at) &&
|
||||
!env['devise.skip_timeout'] &&
|
||||
!proxy.remember_me_is_active?(record)
|
||||
Devise.sign_out_all_scopes ? proxy.sign_out : proxy.sign_out(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
|
||||
|
||||
|
||||
@@ -5,15 +5,16 @@ module Devise
|
||||
|
||||
included do
|
||||
include Devise::Controllers::ScopedViews
|
||||
attr_reader :scope_name, :resource
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
attr_reader :scope_name, :resource
|
||||
|
||||
# Configure default email options
|
||||
def devise_mail(record, action, opts={})
|
||||
def devise_mail(record, action, opts = {}, &block)
|
||||
initialize_from_record(record)
|
||||
mail headers_for(action, opts)
|
||||
mail headers_for(action, opts), &block
|
||||
end
|
||||
|
||||
def initialize_from_record(record)
|
||||
@@ -64,7 +65,7 @@ module Devise
|
||||
template_path
|
||||
end
|
||||
|
||||
# Setup a subject doing an I18n lookup. At first, it attempts to set a subject
|
||||
# Set up a subject doing an I18n lookup. At first, it attempts to set a subject
|
||||
# based on the current mapping:
|
||||
#
|
||||
# en:
|
||||
|
||||
@@ -12,7 +12,7 @@ module Devise
|
||||
|
||||
# Creates configuration values for Devise and for the given module.
|
||||
#
|
||||
# Devise::Models.config(Devise::Authenticatable, :stretches, 10)
|
||||
# Devise::Models.config(Devise::DatabaseAuthenticatable, :stretches)
|
||||
#
|
||||
# The line above creates:
|
||||
#
|
||||
|
||||
@@ -114,6 +114,15 @@ module Devise
|
||||
super(options)
|
||||
end
|
||||
|
||||
# Redefine inspect using serializable_hash, to ensure we don't accidentally
|
||||
# leak passwords into exceptions.
|
||||
def inspect
|
||||
inspection = serializable_hash.collect do |k,v|
|
||||
"#{k}: #{respond_to?(:attribute_for_inspect) ? attribute_for_inspect(k) : v.inspect}"
|
||||
end
|
||||
"#<#{self.class} #{inspection.join(", ")}>"
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def devise_mailer
|
||||
@@ -143,13 +152,25 @@ module Devise
|
||||
# if new_record? || changed?
|
||||
# pending_notifications << [notification, args]
|
||||
# else
|
||||
# devise_mailer.send(notification, self, *args).deliver
|
||||
# message = devise_mailer.send(notification, self, *args)
|
||||
# Remove once we move to Rails 4.2+ only.
|
||||
# if message.respond_to?(:deliver_now)
|
||||
# message.deliver_now
|
||||
# else
|
||||
# message.deliver
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# def send_pending_notifications
|
||||
# pending_notifications.each do |notification, args|
|
||||
# devise_mailer.send(notification, self, *args).deliver
|
||||
# message = devise_mailer.send(notification, self, *args)
|
||||
# Remove once we move to Rails 4.2+ only.
|
||||
# if message.respond_to?(:deliver_now)
|
||||
# message.deliver_now
|
||||
# else
|
||||
# message.deliver
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# # Empty the pending notifications array because the
|
||||
@@ -253,7 +274,11 @@ module Devise
|
||||
|
||||
# Find or initialize a record with group of attributes based on a list of required attributes.
|
||||
def find_or_initialize_with_errors(required_attributes, attributes, error=:invalid) #:nodoc:
|
||||
attributes = attributes.slice(*required_attributes).with_indifferent_access
|
||||
attributes = if attributes.respond_to? :permit!
|
||||
attributes.slice(*required_attributes).permit!.to_h.with_indifferent_access
|
||||
else
|
||||
attributes.with_indifferent_access.slice(*required_attributes)
|
||||
end
|
||||
attributes.delete_if { |key, value| value.blank? }
|
||||
|
||||
if attributes.size == required_attributes.size
|
||||
|
||||
@@ -7,7 +7,7 @@ module Devise
|
||||
#
|
||||
# Confirmable tracks the following columns:
|
||||
#
|
||||
# * confirmation_token - An OpenSSL::HMAC.hexdigest of @raw_confirmation_token
|
||||
# * confirmation_token - A unique random token
|
||||
# * confirmed_at - A timestamp when the user clicked the confirmation link
|
||||
# * confirmation_sent_at - A timestamp when the confirmation_token was generated (not sent)
|
||||
# * unconfirmed_email - An email address copied from the email attr. After confirmation
|
||||
@@ -24,11 +24,13 @@ module Devise
|
||||
# By default allow_unconfirmed_access_for is zero, it means users always have to confirm to sign in.
|
||||
# * +reconfirmable+: requires any email changes to be confirmed (exactly the same way as
|
||||
# initial account confirmation) to be applied. Requires additional unconfirmed_email
|
||||
# db field to be setup (t.reconfirmable in migrations). Until confirmed new email is
|
||||
# db field to be set up (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.
|
||||
# Confirmable will not generate a new token if a repeat confirmation is requested
|
||||
# during this time frame, unless the user's email changed too.
|
||||
#
|
||||
# == Examples
|
||||
#
|
||||
@@ -38,17 +40,23 @@ 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: :send_confirmation_notification?
|
||||
after_create :skip_reconfirmation_in_callback!, if: :send_confirmation_notification?
|
||||
if respond_to?(:after_commit) # ActiveRecord
|
||||
after_commit :send_on_create_confirmation_instructions, on: :create, if: :send_confirmation_notification?
|
||||
after_commit :send_reconfirmation_instructions, on: :update, if: :reconfirmation_required?
|
||||
else # Mongoid
|
||||
after_create :send_on_create_confirmation_instructions, if: :send_confirmation_notification?
|
||||
after_update :send_reconfirmation_instructions, if: :reconfirmation_required?
|
||||
end
|
||||
before_update :postpone_email_change_until_confirmation_and_regenerate_confirmation_token, if: :postpone_email_change?
|
||||
after_update :send_reconfirmation_instructions, if: :reconfirmation_required?
|
||||
end
|
||||
|
||||
def initialize(*args, &block)
|
||||
@bypass_confirmation_postpone = false
|
||||
@skip_reconfirmation_in_callback = false
|
||||
@reconfirmation_required = false
|
||||
@skip_confirmation_notification = false
|
||||
@raw_confirmation_token = nil
|
||||
@@ -74,7 +82,7 @@ module Devise
|
||||
|
||||
self.confirmed_at = Time.now.utc
|
||||
|
||||
saved = if self.class.reconfirmable && unconfirmed_email.present?
|
||||
saved = if pending_reconfirmation?
|
||||
skip_reconfirmation!
|
||||
self.email = unconfirmed_email
|
||||
self.unconfirmed_email = nil
|
||||
@@ -90,11 +98,6 @@ module Devise
|
||||
end
|
||||
end
|
||||
|
||||
def confirm!(args={})
|
||||
ActiveSupport::Deprecation.warn "confirm! is deprecated in favor of confirm"
|
||||
confirm(args)
|
||||
end
|
||||
|
||||
# Verifies whether a user is confirmed or not
|
||||
def confirmed?
|
||||
!!confirmed_at
|
||||
@@ -163,6 +166,12 @@ module Devise
|
||||
|
||||
protected
|
||||
|
||||
# To not require reconfirmation after creating with #save called in a
|
||||
# callback call skip_create_confirmation!
|
||||
def skip_reconfirmation_in_callback!
|
||||
@skip_reconfirmation_in_callback = true
|
||||
end
|
||||
|
||||
# A callback method used to deliver confirmation
|
||||
# instructions on creation. This can be overridden
|
||||
# in models to map to a nice sign up e-mail.
|
||||
@@ -178,7 +187,7 @@ module Devise
|
||||
# Checks if the confirmation for the user is within the limit time.
|
||||
# We do this by calculating if the difference between today and the
|
||||
# confirmation sent date does not exceed the confirm in time configured.
|
||||
# Confirm_within is a model configuration, must always be an integer value.
|
||||
# allow_unconfirmed_access_for is a model configuration, must always be an integer value.
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
@@ -214,7 +223,7 @@ module Devise
|
||||
# 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)
|
||||
self.class.confirm_within && self.confirmation_sent_at && (Time.now > self.confirmation_sent_at + self.class.confirm_within)
|
||||
end
|
||||
|
||||
# Checks whether the record requires any confirmation.
|
||||
@@ -230,10 +239,12 @@ module Devise
|
||||
# Generates a new random token for confirmation, and stores
|
||||
# the time this token is being generated in confirmation_sent_at
|
||||
def generate_confirmation_token
|
||||
raw, enc = Devise.token_generator.generate(self.class, :confirmation_token)
|
||||
@raw_confirmation_token = raw
|
||||
self.confirmation_token = enc
|
||||
self.confirmation_sent_at = Time.now.utc
|
||||
if self.confirmation_token && !confirmation_period_expired?
|
||||
@raw_confirmation_token = self.confirmation_token
|
||||
else
|
||||
self.confirmation_token = @raw_confirmation_token = Devise.friendly_token
|
||||
self.confirmation_sent_at = Time.now.utc
|
||||
end
|
||||
end
|
||||
|
||||
def generate_confirmation_token!
|
||||
@@ -244,17 +255,22 @@ module Devise
|
||||
@reconfirmation_required = true
|
||||
self.unconfirmed_email = self.email
|
||||
self.email = self.email_was
|
||||
self.confirmation_token = nil
|
||||
generate_confirmation_token
|
||||
end
|
||||
|
||||
def postpone_email_change?
|
||||
postpone = self.class.reconfirmable && email_changed? && !@bypass_confirmation_postpone && self.email.present?
|
||||
postpone = self.class.reconfirmable &&
|
||||
email_changed? &&
|
||||
!@bypass_confirmation_postpone &&
|
||||
self.email.present? &&
|
||||
(!@skip_reconfirmation_in_callback || !self.email_was.nil?)
|
||||
@bypass_confirmation_postpone = false
|
||||
postpone
|
||||
end
|
||||
|
||||
def reconfirmation_required?
|
||||
self.class.reconfirmable && @reconfirmation_required && self.email.present?
|
||||
self.class.reconfirmable && @reconfirmation_required && (self.email.present? || self.unconfirmed_email.present?)
|
||||
end
|
||||
|
||||
def send_confirmation_notification?
|
||||
@@ -293,17 +309,23 @@ module Devise
|
||||
# If the user is already confirmed, create an error for the user
|
||||
# Options must have the confirmation_token
|
||||
def confirm_by_token(confirmation_token)
|
||||
original_token = confirmation_token
|
||||
confirmation_token = Devise.token_generator.digest(self, :confirmation_token, confirmation_token)
|
||||
confirmable = find_first_by_auth_conditions(confirmation_token: confirmation_token)
|
||||
unless confirmable
|
||||
confirmation_digest = Devise.token_generator.digest(self, :confirmation_token, confirmation_token)
|
||||
confirmable = find_or_initialize_with_error_by(:confirmation_token, confirmation_digest)
|
||||
end
|
||||
|
||||
# TODO: replace above lines with
|
||||
# confirmable = find_or_initialize_with_error_by(:confirmation_token, confirmation_token)
|
||||
# after enough time has passed that Devise clients do not use digested tokens
|
||||
|
||||
confirmable = find_or_initialize_with_error_by(:confirmation_token, confirmation_token)
|
||||
confirmable.confirm if confirmable.persisted?
|
||||
confirmable.confirmation_token = original_token
|
||||
confirmable
|
||||
end
|
||||
|
||||
# Find a record for confirmation by unconfirmed email field
|
||||
def find_by_unconfirmed_email_with_errors(attributes = {})
|
||||
attributes = attributes.slice(*confirmation_keys).permit!.to_h if attributes.respond_to? :permit
|
||||
unconfirmed_required_attributes = confirmation_keys.map { |k| k == :email ? :unconfirmed_email : k }
|
||||
unconfirmed_attributes = attributes.symbolize_keys
|
||||
unconfirmed_attributes[:unconfirmed_email] = unconfirmed_attributes.delete(:email)
|
||||
|
||||
@@ -1,19 +1,13 @@
|
||||
require 'devise/strategies/database_authenticatable'
|
||||
require 'devise/encryptor'
|
||||
|
||||
module Devise
|
||||
def self.bcrypt(klass, password)
|
||||
ActiveSupport::Deprecation.warn "Devise.bcrypt is deprecated; use Devise::Encryptor.digest instead"
|
||||
Devise::Encryptor.digest(klass, password)
|
||||
end
|
||||
|
||||
module Models
|
||||
# Authenticatable Module, responsible for encrypting password and validating
|
||||
# authenticity of a user while signing in.
|
||||
# Authenticatable Module, responsible for hashing the password and
|
||||
# validating the authenticity of a user while signing in.
|
||||
#
|
||||
# == Options
|
||||
#
|
||||
# DatabaseAuthenticable adds the following options to devise_for:
|
||||
# DatabaseAuthenticatable adds the following options to devise_for:
|
||||
#
|
||||
# * +pepper+: a random string used to provide a more secure hash. Use
|
||||
# `rake secret` to generate new keys.
|
||||
@@ -28,6 +22,8 @@ module Devise
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
after_update :send_password_change_notification, if: :send_password_change_notification?
|
||||
|
||||
attr_reader :password, :current_password
|
||||
attr_accessor :password_confirmation
|
||||
end
|
||||
@@ -36,7 +32,9 @@ module Devise
|
||||
[:encrypted_password] + klass.authentication_keys
|
||||
end
|
||||
|
||||
# Generates password encryption based on the given value.
|
||||
# Generates a hashed password based on the given value.
|
||||
# For legacy reasons, we use `encrypted_password` to store
|
||||
# the hashed password.
|
||||
def password=(new_password)
|
||||
@password = new_password
|
||||
self.encrypted_password = password_digest(@password) if @password.present?
|
||||
@@ -134,19 +132,27 @@ module Devise
|
||||
encrypted_password[0,29] if encrypted_password
|
||||
end
|
||||
|
||||
def send_password_change_notification
|
||||
send_devise_notification(:password_change)
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
# Digests the password using bcrypt. Custom encryption should override
|
||||
# Hashes the password using bcrypt. Custom hash functions should override
|
||||
# this method to apply their own algorithm.
|
||||
#
|
||||
# See https://github.com/plataformatec/devise-encryptable for examples
|
||||
# of other encryption engines.
|
||||
# of other hashing engines.
|
||||
def password_digest(password)
|
||||
Devise::Encryptor.digest(self.class, password)
|
||||
end
|
||||
|
||||
def send_password_change_notification?
|
||||
self.class.send_password_change_notification && encrypted_password_changed?
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
Devise::Models.config(self, :pepper, :stretches)
|
||||
Devise::Models.config(self, :pepper, :stretches, :send_password_change_notification)
|
||||
|
||||
# We assume this method already gets the sanitized values from the
|
||||
# DatabaseAuthenticatable strategy. If you are using this method on
|
||||
|
||||
@@ -7,7 +7,7 @@ module Devise
|
||||
# blocked: email and time. The former will send an email to the user when
|
||||
# the lock happens, containing a link to unlock its account. The second
|
||||
# will unlock the user automatically after some configured time (ie 2.hours).
|
||||
# It's also possible to setup lockable to use both email and time strategies.
|
||||
# It's also possible to set up lockable to use both email and time strategies.
|
||||
#
|
||||
# == Options
|
||||
#
|
||||
@@ -64,7 +64,7 @@ module Devise
|
||||
def send_unlock_instructions
|
||||
raw, enc = Devise.token_generator.generate(self.class, :unlock_token)
|
||||
self.unlock_token = enc
|
||||
self.save(validate: false)
|
||||
save(validate: false)
|
||||
send_devise_notification(:unlock_instructions, raw, {})
|
||||
raw
|
||||
end
|
||||
@@ -155,6 +155,9 @@ module Devise
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
# List of strategies that are enabled/supported if :both is used.
|
||||
BOTH_STRATEGIES = [:time, :email]
|
||||
|
||||
# Attempt to find a user by its unlock keys. If a record is found, send new
|
||||
# unlock instructions to it. If not user is found, returns a new user
|
||||
# with an email not found error.
|
||||
@@ -181,7 +184,8 @@ module Devise
|
||||
|
||||
# Is the unlock enabled for the given unlock strategy?
|
||||
def unlock_strategy_enabled?(strategy)
|
||||
[:both, strategy].include?(self.unlock_strategy)
|
||||
self.unlock_strategy == strategy ||
|
||||
(self.unlock_strategy == :both && BOTH_STRATEGIES.include?(strategy))
|
||||
end
|
||||
|
||||
# Is the lock enabled for the given lock strategy?
|
||||
|
||||
@@ -16,10 +16,6 @@ module Devise
|
||||
# # resets the user password and save the record, true if valid passwords are given, otherwise false
|
||||
# User.find(1).reset_password('password123', 'password123')
|
||||
#
|
||||
# # only resets the user password, without saving the record
|
||||
# user = User.find(1)
|
||||
# user.reset_password('password123', 'password123')
|
||||
#
|
||||
# # creates a new token and send it with instructions about how to reset the password
|
||||
# User.find(1).send_reset_password_instructions
|
||||
#
|
||||
@@ -31,11 +27,7 @@ module Devise
|
||||
end
|
||||
|
||||
included do
|
||||
before_save do
|
||||
if email_changed? || encrypted_password_changed?
|
||||
clear_reset_password_token
|
||||
end
|
||||
end
|
||||
before_update :clear_reset_password_token, if: :clear_reset_password_token?
|
||||
end
|
||||
|
||||
# Update password saving the record and clearing token. Returns true if
|
||||
@@ -44,19 +36,9 @@ module Devise
|
||||
self.password = new_password
|
||||
self.password_confirmation = new_password_confirmation
|
||||
|
||||
if respond_to?(:after_password_reset) && valid?
|
||||
ActiveSupport::Deprecation.warn "after_password_reset is deprecated"
|
||||
after_password_reset
|
||||
end
|
||||
|
||||
save
|
||||
end
|
||||
|
||||
def reset_password!(new_password, new_password_confirmation)
|
||||
ActiveSupport::Deprecation.warn "reset_password! is deprecated in favor of reset_password"
|
||||
reset_password(new_password, new_password_confirmation)
|
||||
end
|
||||
|
||||
# Resets reset password token and send reset password instructions by email.
|
||||
# Returns the token sent in the e-mail.
|
||||
def send_reset_password_instructions
|
||||
@@ -87,7 +69,7 @@ module Devise
|
||||
# reset_password_period_valid? # will always return false
|
||||
#
|
||||
def reset_password_period_valid?
|
||||
reset_password_sent_at && reset_password_sent_at.utc >= self.class.reset_password_within.ago
|
||||
reset_password_sent_at && reset_password_sent_at.utc >= self.class.reset_password_within.ago.utc
|
||||
end
|
||||
|
||||
protected
|
||||
@@ -103,7 +85,7 @@ module Devise
|
||||
|
||||
self.reset_password_token = enc
|
||||
self.reset_password_sent_at = Time.now.utc
|
||||
self.save(validate: false)
|
||||
save(validate: false)
|
||||
raw
|
||||
end
|
||||
|
||||
@@ -111,6 +93,15 @@ module Devise
|
||||
send_devise_notification(:reset_password_instructions, token, {})
|
||||
end
|
||||
|
||||
def clear_reset_password_token?
|
||||
encrypted_password_changed = respond_to?(:encrypted_password_changed?) && encrypted_password_changed?
|
||||
authentication_keys_changed = self.class.authentication_keys.any? do |attribute|
|
||||
respond_to?("#{attribute}_changed?") && send("#{attribute}_changed?")
|
||||
end
|
||||
|
||||
authentication_keys_changed || encrypted_password_changed
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
# Attempt to find a user by password reset token. If a user is found, return it
|
||||
# If a user is not found, return nil
|
||||
|
||||
@@ -39,17 +39,15 @@ module Devise
|
||||
module Rememberable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
attr_accessor :remember_me, :extend_remember_period
|
||||
attr_accessor :remember_me
|
||||
|
||||
def self.required_fields(klass)
|
||||
[:remember_created_at]
|
||||
end
|
||||
|
||||
# Generate a new remember token and save the record without validations
|
||||
# if remember expired (token is no longer valid) or extend_remember_period is true
|
||||
def remember_me!(extend_period=false)
|
||||
self.remember_token = self.class.remember_token if generate_remember_token?
|
||||
self.remember_created_at = Time.now.utc if generate_remember_timestamp?(extend_period)
|
||||
def remember_me!
|
||||
self.remember_token ||= self.class.remember_token if respond_to?(:remember_token)
|
||||
self.remember_created_at ||= Time.now.utc
|
||||
save(validate: false) if self.changed?
|
||||
end
|
||||
|
||||
@@ -57,19 +55,17 @@ module Devise
|
||||
# it exists), and save the record without validations.
|
||||
def forget_me!
|
||||
return unless persisted?
|
||||
self.remember_token = nil if respond_to?(:remember_token=)
|
||||
self.remember_token = nil if respond_to?(:remember_token)
|
||||
self.remember_created_at = nil if self.class.expire_all_remember_me_on_sign_out
|
||||
save(validate: false)
|
||||
end
|
||||
|
||||
# Remember token should be expired if expiration time not overpass now.
|
||||
def remember_expired?
|
||||
remember_created_at.nil? || (remember_expires_at <= Time.now.utc)
|
||||
def remember_expires_at
|
||||
self.class.remember_for.from_now
|
||||
end
|
||||
|
||||
# Remember token expires at created time + remember_for configuration
|
||||
def remember_expires_at
|
||||
remember_created_at + self.class.remember_for
|
||||
def extend_remember_period
|
||||
self.class.extend_remember_period
|
||||
end
|
||||
|
||||
def rememberable_value
|
||||
@@ -102,29 +98,47 @@ module Devise
|
||||
def after_remembered
|
||||
end
|
||||
|
||||
protected
|
||||
def remember_me?(token, generated_at)
|
||||
# TODO: Normalize the JSON type coercion along with the Timeoutable hook
|
||||
# in a single place https://github.com/plataformatec/devise/blob/ffe9d6d406e79108cf32a2c6a1d0b3828849c40b/lib/devise/hooks/timeoutable.rb#L14-L18
|
||||
if generated_at.is_a?(String)
|
||||
generated_at = time_from_json(generated_at)
|
||||
end
|
||||
|
||||
def generate_remember_token? #:nodoc:
|
||||
respond_to?(:remember_token) && remember_expired?
|
||||
# The token is only valid if:
|
||||
# 1. we have a date
|
||||
# 2. the current time does not pass the expiry period
|
||||
# 3. the record has a remember_created_at date
|
||||
# 4. the token date is bigger than the remember_created_at
|
||||
# 5. the token matches
|
||||
generated_at.is_a?(Time) &&
|
||||
(self.class.remember_for.ago < generated_at) &&
|
||||
(generated_at > (remember_created_at || Time.now).utc) &&
|
||||
Devise.secure_compare(rememberable_value, token)
|
||||
end
|
||||
|
||||
# Generate a timestamp if extend_remember_period is true, if no remember_token
|
||||
# exists, or if an existing remember token has expired.
|
||||
def generate_remember_timestamp?(extend_period) #:nodoc:
|
||||
extend_period || remember_expired?
|
||||
private
|
||||
|
||||
def time_from_json(value)
|
||||
if value =~ /\A\d+\.\d+\Z/
|
||||
Time.at(value.to_f)
|
||||
else
|
||||
Time.parse(value) rescue nil
|
||||
end
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
# Create the cookie key using the record id and remember_token
|
||||
def serialize_into_cookie(record)
|
||||
[record.to_key, record.rememberable_value]
|
||||
[record.to_key, record.rememberable_value, Time.now.utc.to_f.to_s]
|
||||
end
|
||||
|
||||
# Recreate the user based on the stored cookie
|
||||
def serialize_from_cookie(id, remember_token)
|
||||
def serialize_from_cookie(*args)
|
||||
id, token, generated_at = *args
|
||||
|
||||
record = to_adapter.get(id)
|
||||
record if record && !record.remember_expired? &&
|
||||
Devise.secure_compare(record.rememberable_value, remember_token)
|
||||
record if record && record.remember_me?(token, generated_at)
|
||||
end
|
||||
|
||||
# Generate a token checking if one does not already exist in the database.
|
||||
|
||||
@@ -26,7 +26,6 @@ module Devise
|
||||
|
||||
# Checks whether the user session has expired based on configured time.
|
||||
def timedout?(last_access)
|
||||
return false if remember_exists_and_not_expired?
|
||||
!timeout_in.nil? && last_access && last_access <= timeout_in.ago
|
||||
end
|
||||
|
||||
@@ -36,11 +35,6 @@ module Devise
|
||||
|
||||
private
|
||||
|
||||
def remember_exists_and_not_expired?
|
||||
return false unless respond_to?(:remember_created_at) && respond_to?(:remember_expired?)
|
||||
remember_created_at && !remember_expired?
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
Devise::Models.config(self, :timeout_in)
|
||||
end
|
||||
|
||||
@@ -1,17 +1,24 @@
|
||||
module Devise
|
||||
module OmniAuth
|
||||
module UrlHelpers
|
||||
def self.define_helpers(mapping)
|
||||
def omniauth_authorize_path(resource_or_scope, provider, *args)
|
||||
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
||||
_devise_route_context.send("#{scope}_#{provider}_omniauth_authorize_path", *args)
|
||||
end
|
||||
|
||||
def omniauth_authorize_path(resource_or_scope, *args)
|
||||
def omniauth_authorize_url(resource_or_scope, provider, *args)
|
||||
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
||||
_devise_route_context.send("#{scope}_omniauth_authorize_path", *args)
|
||||
_devise_route_context.send("#{scope}_#{provider}_omniauth_authorize_url", *args)
|
||||
end
|
||||
|
||||
def omniauth_callback_path(resource_or_scope, *args)
|
||||
def omniauth_callback_path(resource_or_scope, provider, *args)
|
||||
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
||||
_devise_route_context.send("#{scope}_omniauth_callback_path", *args)
|
||||
_devise_route_context.send("#{scope}_#{provider}_omniauth_callback_path", *args)
|
||||
end
|
||||
|
||||
def omniauth_callback_url(resource_or_scope, provider, *args)
|
||||
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
||||
_devise_route_context.send("#{scope}_#{provider}_omniauth_callback_url", *args)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
require 'orm_adapter/adapters/active_record'
|
||||
|
||||
ActiveRecord::Base.extend Devise::Models
|
||||
ActiveSupport.on_load(:active_record) do
|
||||
extend Devise::Models
|
||||
end
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
require 'orm_adapter/adapters/mongoid'
|
||||
ActiveSupport.on_load(:mongoid) do
|
||||
require 'orm_adapter/adapters/mongoid'
|
||||
|
||||
Mongoid::Document::ClassMethods.send :include, Devise::Models
|
||||
Mongoid::Document::ClassMethods.send :include, Devise::Models
|
||||
end
|
||||
|
||||
@@ -1,99 +1,159 @@
|
||||
module Devise
|
||||
class BaseSanitizer
|
||||
attr_reader :params, :resource_name, :resource_class
|
||||
# The +ParameterSanitizer+ deals with permitting specific parameters values
|
||||
# for each +Devise+ scope in the application.
|
||||
#
|
||||
# The sanitizer knows about Devise default parameters (like +password+ and
|
||||
# +password_confirmation+ for the `RegistrationsController`), and you can
|
||||
# extend or change the permitted parameters list on your controllers.
|
||||
#
|
||||
# === Permitting new parameters
|
||||
#
|
||||
# You can add new parameters to the permitted list using the +permit+ method
|
||||
# in a +before_action+ method, for instance.
|
||||
#
|
||||
# class ApplicationController < ActionController::Base
|
||||
# before_action :configure_permitted_parameters, if: :devise_controller?
|
||||
#
|
||||
# protected
|
||||
#
|
||||
# def configure_permitted_parameters
|
||||
# # Permit the `subscribe_newsletter` parameter along with the other
|
||||
# # sign up parameters.
|
||||
# devise_parameter_sanitizer.permit(:sign_up, keys: [:subscribe_newsletter])
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# Using a block yields an +ActionController::Parameters+ object so you can
|
||||
# permit nested parameters and have more control over how the parameters are
|
||||
# permitted in your controller.
|
||||
#
|
||||
# def configure_permitted_parameters
|
||||
# devise_parameter_sanitizer.permit(:sign_up) do |user|
|
||||
# user.permit(newsletter_preferences: [])
|
||||
# end
|
||||
# end
|
||||
class ParameterSanitizer
|
||||
DEFAULT_PERMITTED_ATTRIBUTES = {
|
||||
sign_in: [:password, :remember_me],
|
||||
sign_up: [:password, :password_confirmation],
|
||||
account_update: [:password, :password_confirmation, :current_password]
|
||||
}
|
||||
|
||||
def initialize(resource_class, resource_name, params)
|
||||
@resource_class = resource_class
|
||||
@resource_name = resource_name
|
||||
@auth_keys = extract_auth_keys(resource_class)
|
||||
@params = params
|
||||
@blocks = Hash.new
|
||||
end
|
||||
@resource_name = resource_name
|
||||
@permitted = {}
|
||||
|
||||
def for(kind, &block)
|
||||
if block_given?
|
||||
@blocks[kind] = block
|
||||
else
|
||||
default_for(kind)
|
||||
DEFAULT_PERMITTED_ATTRIBUTES.each_pair do |action, keys|
|
||||
permit(action, keys: keys)
|
||||
end
|
||||
end
|
||||
|
||||
def sanitize(kind)
|
||||
if block = @blocks[kind]
|
||||
block.call(default_params)
|
||||
# Sanitize the parameters for a specific +action+.
|
||||
#
|
||||
# === Arguments
|
||||
#
|
||||
# * +action+ - A +Symbol+ with the action that the controller is
|
||||
# performing, like +sign_up+, +sign_in+, etc.
|
||||
#
|
||||
# === Examples
|
||||
#
|
||||
# # Inside the `RegistrationsController#create` action.
|
||||
# resource = build_resource(devise_parameter_sanitizer.sanitize(:sign_up))
|
||||
# resource.save
|
||||
#
|
||||
# Returns an +ActiveSupport::HashWithIndifferentAccess+ with the permitted
|
||||
# attributes.
|
||||
def sanitize(action)
|
||||
permissions = @permitted[action]
|
||||
|
||||
if permissions.respond_to?(:call)
|
||||
cast_to_hash permissions.call(default_params)
|
||||
elsif permissions.present?
|
||||
cast_to_hash permit_keys(default_params, permissions)
|
||||
else
|
||||
default_sanitize(kind)
|
||||
unknown_action!(action)
|
||||
end
|
||||
end
|
||||
|
||||
# Add or remove new parameters to the permitted list of an +action+.
|
||||
#
|
||||
# === Arguments
|
||||
#
|
||||
# * +action+ - A +Symbol+ with the action that the controller is
|
||||
# performing, like +sign_up+, +sign_in+, etc.
|
||||
# * +keys:+ - An +Array+ of keys that also should be permitted.
|
||||
# * +except:+ - An +Array+ of keys that shouldn't be permitted.
|
||||
# * +block+ - A block that should be used to permit the action
|
||||
# parameters instead of the +Array+ based approach. The block will be
|
||||
# called with an +ActionController::Parameters+ instance.
|
||||
#
|
||||
# === Examples
|
||||
#
|
||||
# # Adding new parameters to be permitted in the `sign_up` action.
|
||||
# devise_parameter_sanitizer.permit(:sign_up, keys: [:subscribe_newsletter])
|
||||
#
|
||||
# # Removing the `password` parameter from the `account_update` action.
|
||||
# devise_parameter_sanitizer.permit(:account_update, except: [:password])
|
||||
#
|
||||
# # Using the block form to completely override how we permit the
|
||||
# # parameters for the `sign_up` action.
|
||||
# devise_parameter_sanitizer.permit(:sign_up) do |user|
|
||||
# user.permit(:email, :password, :password_confirmation)
|
||||
# end
|
||||
#
|
||||
#
|
||||
# Returns nothing.
|
||||
def permit(action, keys: nil, except: nil, &block)
|
||||
if block_given?
|
||||
@permitted[action] = block
|
||||
end
|
||||
|
||||
if keys.present?
|
||||
@permitted[action] ||= @auth_keys.dup
|
||||
@permitted[action].concat(keys)
|
||||
end
|
||||
|
||||
if except.present?
|
||||
@permitted[action] ||= @auth_keys.dup
|
||||
@permitted[action] = @permitted[action] - except
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def default_for(kind)
|
||||
raise ArgumentError, "a block is expected in Devise base sanitizer"
|
||||
end
|
||||
|
||||
def default_sanitize(kind)
|
||||
default_params
|
||||
# Cast a sanitized +ActionController::Parameters+ to a +HashWithIndifferentAccess+
|
||||
# that can be used elsewhere.
|
||||
#
|
||||
# Returns an +ActiveSupport::HashWithIndifferentAccess+.
|
||||
def cast_to_hash(params)
|
||||
# TODO: Remove the `with_indifferent_access` method call when we only support Rails 5+.
|
||||
params && params.to_h.with_indifferent_access
|
||||
end
|
||||
|
||||
def default_params
|
||||
params.fetch(resource_name, {})
|
||||
end
|
||||
end
|
||||
|
||||
class ParameterSanitizer < BaseSanitizer
|
||||
def initialize(*)
|
||||
super
|
||||
@permitted = Hash.new { |h,k| h[k] = attributes_for(k) }
|
||||
@params.fetch(@resource_name, {})
|
||||
end
|
||||
|
||||
def sign_in
|
||||
permit self.for(:sign_in)
|
||||
def permit_keys(parameters, keys)
|
||||
parameters.permit(*keys)
|
||||
end
|
||||
|
||||
def sign_up
|
||||
permit self.for(:sign_up)
|
||||
def extract_auth_keys(klass)
|
||||
auth_keys = klass.authentication_keys
|
||||
|
||||
auth_keys.respond_to?(:keys) ? auth_keys.keys : auth_keys
|
||||
end
|
||||
|
||||
def account_update
|
||||
permit self.for(:account_update)
|
||||
end
|
||||
def unknown_action!(action)
|
||||
raise NotImplementedError, <<-MESSAGE.strip_heredoc
|
||||
"Devise doesn't know how to sanitize parameters for '#{action}'".
|
||||
If you want to define a new set of parameters to be sanitized use the
|
||||
`permit` method first:
|
||||
|
||||
private
|
||||
|
||||
# TODO: We do need to flatten so it works with strong_parameters
|
||||
# gem. We should drop it once we move to Rails 4 only support.
|
||||
def permit(keys)
|
||||
default_params.permit(*Array(keys))
|
||||
end
|
||||
|
||||
# Change for(kind) to return the values in the @permitted
|
||||
# hash, allowing the developer to customize at runtime.
|
||||
def default_for(kind)
|
||||
@permitted[kind] || raise("No sanitizer provided for #{kind}")
|
||||
end
|
||||
|
||||
def default_sanitize(kind)
|
||||
if respond_to?(kind, true)
|
||||
send(kind)
|
||||
else
|
||||
raise NotImplementedError, "Devise doesn't know how to sanitize parameters for #{kind}"
|
||||
end
|
||||
end
|
||||
|
||||
def attributes_for(kind)
|
||||
case kind
|
||||
when :sign_in
|
||||
auth_keys + [:password, :remember_me]
|
||||
when :sign_up
|
||||
auth_keys + [:password, :password_confirmation]
|
||||
when :account_update
|
||||
auth_keys + [:password, :password_confirmation, :current_password]
|
||||
end
|
||||
end
|
||||
|
||||
def auth_keys
|
||||
@auth_keys ||= @resource_class.authentication_keys.respond_to?(:keys) ?
|
||||
@resource_class.authentication_keys.keys : @resource_class.authentication_keys
|
||||
devise_parameter_sanitizer.permit(:#{action}, keys: [:param1, :param2, :param3])
|
||||
MESSAGE
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -11,7 +11,9 @@ module Devise
|
||||
end
|
||||
|
||||
# Force routes to be loaded if we are doing any eager load.
|
||||
config.before_eager_load { |app| app.reload_routes! }
|
||||
config.before_eager_load do |app|
|
||||
app.reload_routes! if Devise.reload_routes
|
||||
end
|
||||
|
||||
initializer "devise.url_helpers" do
|
||||
Devise.include_helpers(Devise::Controllers)
|
||||
@@ -39,18 +41,9 @@ module Devise
|
||||
Devise.token_generator ||=
|
||||
if secret_key = Devise.secret_key
|
||||
Devise::TokenGenerator.new(
|
||||
Devise::CachingKeyGenerator.new(Devise::KeyGenerator.new(secret_key))
|
||||
ActiveSupport::CachingKeyGenerator.new(ActiveSupport::KeyGenerator.new(secret_key))
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
initializer "devise.fix_routes_proxy_missing_respond_to_bug" do
|
||||
# Deprecate: Remove once we move to Rails 4 only.
|
||||
ActionDispatch::Routing::RoutesProxy.class_eval do
|
||||
def respond_to?(method, include_private = false)
|
||||
super || routes.url_helpers.respond_to?(method)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
require "active_support/core_ext/object/try"
|
||||
require "active_support/core_ext/hash/slice"
|
||||
|
||||
module ActionDispatch::Routing
|
||||
class RouteSet #:nodoc:
|
||||
# Ensure Devise modules are included only after loading routes, because we
|
||||
# need devise_for mappings already declared to create filters and helpers.
|
||||
def finalize_with_devise!
|
||||
result = finalize_without_devise!
|
||||
|
||||
module Devise
|
||||
module RouteSet
|
||||
def finalize!
|
||||
result = super
|
||||
@devise_finalized ||= begin
|
||||
if Devise.router_name.nil? && defined?(@devise_finalized) && self != Rails.application.try(:routes)
|
||||
warn "[DEVISE] We have detected that you are using devise_for inside engine routes. " \
|
||||
@@ -21,10 +18,16 @@ module ActionDispatch::Routing
|
||||
Devise.regenerate_helpers!
|
||||
true
|
||||
end
|
||||
|
||||
result
|
||||
end
|
||||
alias_method_chain :finalize!, :devise
|
||||
end
|
||||
end
|
||||
|
||||
module ActionDispatch::Routing
|
||||
class RouteSet #:nodoc:
|
||||
# Ensure Devise modules are included only after loading routes, because we
|
||||
# need devise_for mappings already declared to create filters and helpers.
|
||||
prepend Devise::RouteSet
|
||||
end
|
||||
|
||||
class Mapper
|
||||
@@ -84,20 +87,34 @@ module ActionDispatch::Routing
|
||||
#
|
||||
# You can configure your routes with some options:
|
||||
#
|
||||
# * class_name: setup a different class to be looked up by devise, if it cannot be
|
||||
# * class_name: set up a different class to be looked up by devise, if it cannot be
|
||||
# properly found by the route name.
|
||||
#
|
||||
# devise_for :users, class_name: 'Account'
|
||||
#
|
||||
# * path: allows you to setup path name that will be used, as rails routes does.
|
||||
# The following route configuration would setup your route as /accounts instead of /users:
|
||||
# * path: allows you to set up path name that will be used, as rails routes does.
|
||||
# The following route configuration would set up your route as /accounts instead of /users:
|
||||
#
|
||||
# devise_for :users, path: 'accounts'
|
||||
#
|
||||
# * singular: setup the singular name for the given resource. This is used as the instance variable
|
||||
# name in controller, as the name in routes and the scope given to warden.
|
||||
# * singular: set up the singular name for the given resource. This is used as the helper methods
|
||||
# names in controller ("authenticate_#{singular}!", "#{singular}_signed_in?", "current_#{singular}"
|
||||
# and "#{singular}_session"), as the scope name in routes and as the scope given to warden.
|
||||
#
|
||||
# devise_for :users, singular: :user
|
||||
# devise_for :admins, singular: :manager
|
||||
#
|
||||
# devise_scope :manager do
|
||||
# ...
|
||||
# end
|
||||
#
|
||||
# class ManagerController < ApplicationController
|
||||
# before_action authenticate_manager!
|
||||
#
|
||||
# def show
|
||||
# @manager = current_manager
|
||||
# ...
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# * path_names: configure different path names to overwrite defaults :sign_in, :sign_out, :sign_up,
|
||||
# :password, :confirmation, :unlock.
|
||||
@@ -321,7 +338,7 @@ module ActionDispatch::Routing
|
||||
|
||||
# Sets the devise scope to be used in the controller. If you have custom routes,
|
||||
# you are required to call this method (also aliased as :as) in order to specify
|
||||
# to which controller it is targetted.
|
||||
# to which controller it is targeted.
|
||||
#
|
||||
# as :user do
|
||||
# get "sign_in", to: "devise/sessions#new"
|
||||
@@ -404,42 +421,39 @@ module ActionDispatch::Routing
|
||||
raise <<-ERROR
|
||||
Devise does not support scoping OmniAuth callbacks under a dynamic segment
|
||||
and you have set #{mapping.fullpath.inspect}. You can work around by passing
|
||||
`skip: :omniauth_callbacks` and manually defining the routes. Here is an example:
|
||||
`skip: :omniauth_callbacks` to the `devise_for` call and extract omniauth
|
||||
options to another `devise_for` call outside the scope. Here is an example:
|
||||
|
||||
match "/users/auth/:provider",
|
||||
constraints: { provider: /google|facebook/ },
|
||||
to: "devise/omniauth_callbacks#passthru",
|
||||
as: :omniauth_authorize,
|
||||
via: [:get, :post]
|
||||
devise_for :users, only: :omniauth_callbacks, controllers: {omniauth_callbacks: 'users/omniauth_callbacks'}
|
||||
|
||||
match "/users/auth/:action/callback",
|
||||
constraints: { action: /google|facebook/ },
|
||||
to: "devise/omniauth_callbacks#:action",
|
||||
as: :omniauth_callback,
|
||||
via: [:get, :post]
|
||||
scope '/(:locale)', locale: /ru|en/ do
|
||||
devise_for :users, skip: :omniauth_callbacks
|
||||
end
|
||||
ERROR
|
||||
end
|
||||
|
||||
path, @scope[:path] = @scope[:path], nil
|
||||
current_scope = @scope.dup
|
||||
if @scope.respond_to? :new
|
||||
@scope = @scope.new path: nil
|
||||
else
|
||||
@scope[:path] = nil
|
||||
end
|
||||
path_prefix = Devise.omniauth_path_prefix || "/#{mapping.fullpath}/auth".squeeze("/")
|
||||
|
||||
set_omniauth_path_prefix!(path_prefix)
|
||||
|
||||
providers = Regexp.union(mapping.to.omniauth_providers.map(&:to_s))
|
||||
mapping.to.omniauth_providers.each do |provider|
|
||||
match "#{path_prefix}/#{provider}",
|
||||
to: "#{controllers[:omniauth_callbacks]}#passthru",
|
||||
as: "#{provider}_omniauth_authorize",
|
||||
via: [:get, :post]
|
||||
|
||||
match "#{path_prefix}/:provider",
|
||||
constraints: { provider: providers },
|
||||
to: "#{controllers[:omniauth_callbacks]}#passthru",
|
||||
as: :omniauth_authorize,
|
||||
via: [:get, :post]
|
||||
|
||||
match "#{path_prefix}/:action/callback",
|
||||
constraints: { action: providers },
|
||||
to: "#{controllers[:omniauth_callbacks]}#:action",
|
||||
as: :omniauth_callback,
|
||||
via: [:get, :post]
|
||||
match "#{path_prefix}/#{provider}/callback",
|
||||
to: "#{controllers[:omniauth_callbacks]}##{provider}",
|
||||
as: "#{provider}_omniauth_callback",
|
||||
via: [:get, :post]
|
||||
end
|
||||
ensure
|
||||
@scope[:path] = path
|
||||
@scope = current_scope
|
||||
end
|
||||
|
||||
def with_devise_exclusive_scope(new_path, new_as, options) #:nodoc:
|
||||
@@ -448,7 +462,11 @@ ERROR
|
||||
exclusive = { as: new_as, path: new_path, module: nil }
|
||||
exclusive.merge!(options.slice(:constraints, :defaults, :options))
|
||||
|
||||
exclusive.each_pair { |key, value| @scope[key] = value }
|
||||
if @scope.respond_to? :new
|
||||
@scope = @scope.new exclusive
|
||||
else
|
||||
exclusive.each_pair { |key, value| @scope[key] = value }
|
||||
end
|
||||
yield
|
||||
ensure
|
||||
@scope = current_scope
|
||||
|
||||
@@ -3,17 +3,8 @@ module Warden::Mixins::Common
|
||||
@request ||= ActionDispatch::Request.new(env)
|
||||
end
|
||||
|
||||
# Deprecate: Remove this check once we move to Rails 4 only.
|
||||
NULL_STORE =
|
||||
defined?(ActionController::RequestForgeryProtection::ProtectionMethods::NullSession::NullSessionHash) ?
|
||||
ActionController::RequestForgeryProtection::ProtectionMethods::NullSession::NullSessionHash : nil
|
||||
|
||||
def reset_session!
|
||||
# Calling reset_session on NULL_STORE causes it fail.
|
||||
# This is a bug that needs to be fixed in Rails.
|
||||
unless NULL_STORE && request.session.is_a?(NULL_STORE)
|
||||
request.reset_session
|
||||
end
|
||||
request.reset_session
|
||||
end
|
||||
|
||||
def cookies
|
||||
|
||||
@@ -27,7 +27,7 @@ module Devise
|
||||
|
||||
# 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?
|
||||
# given as parameter. Check Devise::Models::Authenticatable.valid_for_authentication?
|
||||
# for more information.
|
||||
#
|
||||
# In case the resource can't be validated, it will fail with the given
|
||||
@@ -118,7 +118,7 @@ module Devise
|
||||
|
||||
# Helper to decode credentials from HTTP.
|
||||
def decode_credentials
|
||||
return [] unless request.authorization && request.authorization =~ /^Basic (.*)/m
|
||||
return [] unless request.authorization && request.authorization =~ /^Basic (.*)/mi
|
||||
Base64.decode64($1).split(/:/, 2)
|
||||
end
|
||||
|
||||
|
||||
@@ -6,15 +6,15 @@ module Devise
|
||||
class DatabaseAuthenticatable < Authenticatable
|
||||
def authenticate!
|
||||
resource = password.present? && mapping.to.find_for_database_authentication(authentication_hash)
|
||||
encrypted = false
|
||||
hashed = false
|
||||
|
||||
if validate(resource){ encrypted = true; resource.valid_password?(password) }
|
||||
if validate(resource){ hashed = true; resource.valid_password?(password) }
|
||||
remember_me(resource)
|
||||
resource.after_database_authentication
|
||||
success!(resource)
|
||||
end
|
||||
|
||||
mapping.to.new.password = password if !encrypted && Devise.paranoid
|
||||
mapping.to.new.password = password if !hashed && Devise.paranoid
|
||||
fail(:not_found_in_database) unless resource
|
||||
end
|
||||
end
|
||||
|
||||
@@ -25,8 +25,7 @@ module Devise
|
||||
end
|
||||
|
||||
if validate(resource)
|
||||
remember_me(resource)
|
||||
extend_remember_me_period(resource)
|
||||
remember_me(resource) if extend_remember_me?(resource)
|
||||
resource.after_remembered
|
||||
success!(resource)
|
||||
end
|
||||
@@ -43,10 +42,8 @@ module Devise
|
||||
|
||||
private
|
||||
|
||||
def extend_remember_me_period(resource)
|
||||
if resource.respond_to?(:extend_remember_period=)
|
||||
resource.extend_remember_period = mapping.to.extend_remember_period
|
||||
end
|
||||
def extend_remember_me?(resource)
|
||||
resource.respond_to?(:extend_remember_period) && resource.extend_remember_period
|
||||
end
|
||||
|
||||
def remember_me?
|
||||
|
||||
162
lib/devise/test/controller_helpers.rb
Normal file
162
lib/devise/test/controller_helpers.rb
Normal file
@@ -0,0 +1,162 @@
|
||||
module Devise
|
||||
module Test
|
||||
# `Devise::Test::ControllerHelpers` provides a facility to test controllers
|
||||
# in isolation when using `ActionController::TestCase` allowing you to
|
||||
# quickly sign_in or sign_out a user. Do not use
|
||||
# `Devise::Test::ControllerHelpers` in integration tests.
|
||||
#
|
||||
# Examples
|
||||
#
|
||||
# class PostsTest < ActionController::TestCase
|
||||
# include Devise::Test::ControllerHelpers
|
||||
#
|
||||
# test 'authenticated users can GET index' do
|
||||
# sign_in users(:bob)
|
||||
#
|
||||
# get :index
|
||||
# assert_response :success
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# Important: you should not test Warden specific behavior (like callbacks)
|
||||
# using `Devise::Test::ControllerHelpers` since it is a stub of the actual
|
||||
# behavior. Such callbacks should be tested in your integration suite instead.
|
||||
module ControllerHelpers
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
setup :setup_controller_for_warden, :warden
|
||||
end
|
||||
|
||||
# Override process to consider warden.
|
||||
def process(*)
|
||||
_catch_warden { super }
|
||||
|
||||
@response
|
||||
end
|
||||
|
||||
# We need to set up the environment variables and the response in the controller.
|
||||
def setup_controller_for_warden #:nodoc:
|
||||
@request.env['action_controller.instance'] = @controller
|
||||
end
|
||||
|
||||
# Quick access to Warden::Proxy.
|
||||
def warden #:nodoc:
|
||||
@request.env['warden'] ||= begin
|
||||
manager = Warden::Manager.new(nil) do |config|
|
||||
config.merge! Devise.warden_config
|
||||
end
|
||||
Warden::Proxy.new(@request.env, manager)
|
||||
end
|
||||
end
|
||||
|
||||
# sign_in a given resource by storing its keys in the session.
|
||||
# This method bypass any warden authentication callback.
|
||||
#
|
||||
# * +resource+ - The resource that should be authenticated
|
||||
# * +scope+ - An optional +Symbol+ with the scope where the resource
|
||||
# should be signed in with.
|
||||
# Examples:
|
||||
#
|
||||
# sign_in users(:alice)
|
||||
# sign_in users(:alice), scope: :admin
|
||||
def sign_in(resource, deprecated = nil, scope: nil)
|
||||
if deprecated.present?
|
||||
scope = resource
|
||||
resource = deprecated
|
||||
|
||||
ActiveSupport::Deprecation.warn <<-DEPRECATION.strip_heredoc
|
||||
[Devise] sign_in(:#{scope}, resource) on controller tests is deprecated and will be removed from Devise.
|
||||
Please use sign_in(resource, scope: :#{scope}) instead.
|
||||
DEPRECATION
|
||||
end
|
||||
|
||||
scope ||= Devise::Mapping.find_scope!(resource)
|
||||
|
||||
warden.instance_variable_get(:@users).delete(scope)
|
||||
warden.session_serializer.store(resource, scope)
|
||||
end
|
||||
|
||||
# Sign out a given resource or scope by calling logout on Warden.
|
||||
# This method bypass any warden logout callback.
|
||||
#
|
||||
# Examples:
|
||||
#
|
||||
# sign_out :user # sign_out(scope)
|
||||
# sign_out @user # sign_out(resource)
|
||||
#
|
||||
def sign_out(resource_or_scope)
|
||||
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
||||
@controller.instance_variable_set(:"@current_#{scope}", nil)
|
||||
user = warden.instance_variable_get(:@users).delete(scope)
|
||||
warden.session_serializer.delete(scope, user)
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
# Catch warden continuations and handle like the middleware would.
|
||||
# Returns nil when interrupted, otherwise the normal result of the block.
|
||||
def _catch_warden(&block)
|
||||
result = catch(:warden, &block)
|
||||
|
||||
env = @controller.request.env
|
||||
|
||||
result ||= {}
|
||||
|
||||
# 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 = request.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
|
||||
request.env["PATH_INFO"] = "/#{options[:action]}"
|
||||
request.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.response.headers.merge!(headers)
|
||||
@controller.status = status
|
||||
@controller.response.body = response.body
|
||||
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)
|
||||
status, headers, body = *ret
|
||||
# ensure the controller response is set to our response.
|
||||
@controller.response ||= @response
|
||||
@response.status = status
|
||||
@response.headers.merge!(headers)
|
||||
@response.body = body
|
||||
end
|
||||
|
||||
ret
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
61
lib/devise/test/integration_helpers.rb
Normal file
61
lib/devise/test/integration_helpers.rb
Normal file
@@ -0,0 +1,61 @@
|
||||
module Devise
|
||||
# Devise::Test::IntegrationHelpers is a helper module for facilitating
|
||||
# authentication on Rails integration tests to bypass the required steps for
|
||||
# signin in or signin out a record.
|
||||
#
|
||||
# Examples
|
||||
#
|
||||
# class PostsTest < ActionDispatch::IntegrationTest
|
||||
# include Devise::Test::IntegrationHelpers
|
||||
#
|
||||
# test 'authenticated users can see posts' do
|
||||
# sign_in users(:bob)
|
||||
#
|
||||
# get '/posts'
|
||||
# assert_response :success
|
||||
# end
|
||||
# end
|
||||
module Test
|
||||
module IntegrationHelpers
|
||||
def self.included(base)
|
||||
base.class_eval do
|
||||
include Warden::Test::Helpers
|
||||
|
||||
setup :setup_integration_for_devise
|
||||
teardown :teardown_integration_for_devise
|
||||
end
|
||||
end
|
||||
|
||||
# Signs in a specific resource, mimicking a successfull sign in
|
||||
# operation through +Devise::SessionsController#create+.
|
||||
#
|
||||
# * +resource+ - The resource that should be authenticated
|
||||
# * +scope+ - An optional +Symbol+ with the scope where the resource
|
||||
# should be signed in with.
|
||||
def sign_in(resource, scope: nil)
|
||||
scope ||= Devise::Mapping.find_scope!(resource)
|
||||
|
||||
login_as(resource, scope: scope)
|
||||
end
|
||||
|
||||
# Signs out a specific scope from the session.
|
||||
#
|
||||
# * +resource_or_scope+ - The resource or scope that should be signed out.
|
||||
def sign_out(resource_or_scope)
|
||||
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
||||
|
||||
logout scope
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def setup_integration_for_devise
|
||||
Warden.test_mode!
|
||||
end
|
||||
|
||||
def teardown_integration_for_devise
|
||||
Warden.test_reset!
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,132 +1,13 @@
|
||||
module Devise
|
||||
# Devise::TestHelpers provides a facility to test controllers in isolation
|
||||
# when using ActionController::TestCase allowing you to quickly sign_in or
|
||||
# sign_out a user. Do not use Devise::TestHelpers in integration tests.
|
||||
#
|
||||
# Notice you should not test Warden specific behavior (like Warden callbacks)
|
||||
# using Devise::TestHelpers since it is a stub of the actual behavior. Such
|
||||
# callbacks should be tested in your integration suite instead.
|
||||
module TestHelpers
|
||||
def self.included(base)
|
||||
base.class_eval do
|
||||
setup :setup_controller_for_warden, :warden if respond_to?(:setup)
|
||||
ActiveSupport::Deprecation.warn <<-DEPRECATION.strip_heredoc
|
||||
[Devise] including `Devise::TestHelpers` is deprecated and will be removed from Devise.
|
||||
For controller tests, please include `Devise::Test::ControllerHelpers` instead.
|
||||
DEPRECATION
|
||||
include Devise::Test::ControllerHelpers
|
||||
end
|
||||
end
|
||||
|
||||
# Override process to consider warden.
|
||||
def process(*)
|
||||
# Make sure we always return @response, a la ActionController::TestCase::Behaviour#process, even if warden interrupts
|
||||
_catch_warden { super } || @response
|
||||
end
|
||||
|
||||
# We need to setup the environment variables and the response in the controller.
|
||||
def setup_controller_for_warden #:nodoc:
|
||||
@request.env['action_controller.instance'] = @controller
|
||||
end
|
||||
|
||||
# Quick access to Warden::Proxy.
|
||||
def warden #:nodoc:
|
||||
@request.env['warden'] ||= begin
|
||||
manager = Warden::Manager.new(nil) do |config|
|
||||
config.merge! Devise.warden_config
|
||||
end
|
||||
Warden::Proxy.new(@request.env, manager)
|
||||
end
|
||||
end
|
||||
|
||||
# sign_in a given resource by storing its keys in the session.
|
||||
# This method bypass any warden authentication callback.
|
||||
#
|
||||
# Examples:
|
||||
#
|
||||
# sign_in :user, @user # sign_in(scope, resource)
|
||||
# sign_in @user # sign_in(resource)
|
||||
#
|
||||
def sign_in(resource_or_scope, resource=nil)
|
||||
scope ||= Devise::Mapping.find_scope!(resource_or_scope)
|
||||
resource ||= resource_or_scope
|
||||
warden.instance_variable_get(:@users).delete(scope)
|
||||
warden.session_serializer.store(resource, scope)
|
||||
end
|
||||
|
||||
# Sign out a given resource or scope by calling logout on Warden.
|
||||
# This method bypass any warden logout callback.
|
||||
#
|
||||
# Examples:
|
||||
#
|
||||
# sign_out :user # sign_out(scope)
|
||||
# sign_out @user # sign_out(resource)
|
||||
#
|
||||
def sign_out(resource_or_scope)
|
||||
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
||||
@controller.instance_variable_set(:"@current_#{scope}", nil)
|
||||
user = warden.instance_variable_get(:@users).delete(scope)
|
||||
warden.session_serializer.delete(scope, user)
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
# Catch warden continuations and handle like the middleware would.
|
||||
# Returns nil when interrupted, otherwise the normal result of the block.
|
||||
def _catch_warden(&block)
|
||||
result = catch(:warden, &block)
|
||||
|
||||
env = @controller.request.env
|
||||
|
||||
result ||= {}
|
||||
|
||||
# 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.response.headers.merge!(headers)
|
||||
@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
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
# Deprecate: Copied verbatim from Rails source, remove once we move to Rails 4 only.
|
||||
require 'thread_safe'
|
||||
require 'openssl'
|
||||
require 'securerandom'
|
||||
|
||||
module Devise
|
||||
class TokenGenerator
|
||||
def initialize(key_generator, digest="SHA256")
|
||||
def initialize(key_generator, digest = "SHA256")
|
||||
@key_generator = key_generator
|
||||
@digest = digest
|
||||
end
|
||||
@@ -30,41 +27,4 @@ module Devise
|
||||
@key_generator.generate_key("Devise #{column}")
|
||||
end
|
||||
end
|
||||
|
||||
# KeyGenerator is a simple wrapper around OpenSSL's implementation of PBKDF2
|
||||
# It can be used to derive a number of keys for various purposes from a given secret.
|
||||
# This lets Rails applications have a single secure secret, but avoid reusing that
|
||||
# key in multiple incompatible contexts.
|
||||
class KeyGenerator
|
||||
def initialize(secret, options = {})
|
||||
@secret = secret
|
||||
# The default iterations are higher than required for our key derivation uses
|
||||
# on the off chance someone uses this for password storage
|
||||
@iterations = options[:iterations] || 2**16
|
||||
end
|
||||
|
||||
# Returns a derived key suitable for use. The default key_size is chosen
|
||||
# to be compatible with the default settings of ActiveSupport::MessageVerifier.
|
||||
# i.e. OpenSSL::Digest::SHA1#block_length
|
||||
def generate_key(salt, key_size=64)
|
||||
OpenSSL::PKCS5.pbkdf2_hmac_sha1(@secret, salt, @iterations, key_size)
|
||||
end
|
||||
end
|
||||
|
||||
# CachingKeyGenerator is a wrapper around KeyGenerator which allows users to avoid
|
||||
# re-executing the key generation process when it's called using the same salt and
|
||||
# key_size
|
||||
class CachingKeyGenerator
|
||||
def initialize(key_generator)
|
||||
@key_generator = key_generator
|
||||
@cache_keys = ThreadSafe::Cache.new
|
||||
end
|
||||
|
||||
# Returns a derived key suitable for use. The default key_size is chosen
|
||||
# to be compatible with the default settings of ActiveSupport::MessageVerifier.
|
||||
# i.e. OpenSSL::Digest::SHA1#block_length
|
||||
def generate_key(salt, key_size=64)
|
||||
@cache_keys["#{salt}#{key_size}"] ||= @key_generator.generate_key(salt, key_size)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
module Devise
|
||||
VERSION = "3.5.1".freeze
|
||||
VERSION = "4.2.0".freeze
|
||||
end
|
||||
|
||||
@@ -11,9 +11,9 @@ module ActiveRecord
|
||||
|
||||
def copy_devise_migration
|
||||
if (behavior == :invoke && model_exists?) || (behavior == :revoke && migration_exists?(table_name))
|
||||
migration_template "migration_existing.rb", "db/migrate/add_devise_to_#{table_name}.rb"
|
||||
migration_template "migration_existing.rb", "db/migrate/add_devise_to_#{table_name}.rb", migration_version: migration_version
|
||||
else
|
||||
migration_template "migration.rb", "db/migrate/devise_create_#{table_name}.rb"
|
||||
migration_template "migration.rb", "db/migrate/devise_create_#{table_name}.rb", migration_version: migration_version
|
||||
end
|
||||
end
|
||||
|
||||
@@ -75,17 +75,23 @@ RUBY
|
||||
end
|
||||
|
||||
def inet?
|
||||
rails4? && postgresql?
|
||||
postgresql?
|
||||
end
|
||||
|
||||
def rails4?
|
||||
Rails.version.start_with? '4'
|
||||
def rails5?
|
||||
Rails.version.start_with? '5'
|
||||
end
|
||||
|
||||
def postgresql?
|
||||
config = ActiveRecord::Base.configurations[Rails.env]
|
||||
config && config['adapter'] == 'postgresql'
|
||||
end
|
||||
|
||||
def migration_version
|
||||
if rails5?
|
||||
"[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class DeviseCreate<%= table_name.camelize %> < ActiveRecord::Migration
|
||||
class DeviseCreate<%= table_name.camelize %> < ActiveRecord::Migration<%= migration_version %>
|
||||
def change
|
||||
create_table(:<%= table_name %>) do |t|
|
||||
create_table :<%= table_name %> do |t|
|
||||
<%= migration_data -%>
|
||||
|
||||
<% attributes.each do |attribute| -%>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class AddDeviseTo<%= table_name.camelize %> < ActiveRecord::Migration
|
||||
class AddDeviseTo<%= table_name.camelize %> < ActiveRecord::Migration<%= migration_version %>
|
||||
def self.up
|
||||
change_table(:<%= table_name %>) do |t|
|
||||
change_table :<%= table_name %> do |t|
|
||||
<%= migration_data -%>
|
||||
|
||||
<% attributes.each do |attribute| -%>
|
||||
|
||||
@@ -3,6 +3,8 @@ require 'securerandom'
|
||||
|
||||
module Devise
|
||||
module Generators
|
||||
MissingORMError = Class.new(Thor::Error)
|
||||
|
||||
class InstallGenerator < Rails::Generators::Base
|
||||
source_root File.expand_path("../../templates", __FILE__)
|
||||
|
||||
@@ -10,6 +12,19 @@ module Devise
|
||||
class_option :orm
|
||||
|
||||
def copy_initializer
|
||||
unless options[:orm]
|
||||
raise MissingORMError, <<-ERROR.strip_heredoc
|
||||
An ORM must be set to install Devise in your application.
|
||||
|
||||
Be sure to have an ORM like Active Record or Mongoid loaded in your
|
||||
app or configure your own at `config/application.rb`.
|
||||
|
||||
config.generators do |g|
|
||||
g.orm :your_orm_gem
|
||||
end
|
||||
ERROR
|
||||
end
|
||||
|
||||
template "devise.rb", "config/initializers/devise.rb"
|
||||
end
|
||||
|
||||
|
||||
@@ -8,31 +8,14 @@ module Devise
|
||||
devise :database_authenticatable, :registerable,
|
||||
:recoverable, :rememberable, :trackable, :validatable
|
||||
|
||||
CONTENT
|
||||
buffer += <<-CONTENT if needs_attr_accessible?
|
||||
# Setup accessible (or protected) attributes for your model
|
||||
attr_accessible :email, :password, :password_confirmation, :remember_me
|
||||
|
||||
CONTENT
|
||||
buffer
|
||||
end
|
||||
|
||||
def needs_attr_accessible?
|
||||
rails_3? && !strong_parameters_enabled?
|
||||
end
|
||||
|
||||
def rails_3?
|
||||
Rails::VERSION::MAJOR == 3
|
||||
end
|
||||
|
||||
def strong_parameters_enabled?
|
||||
defined?(ActionController::StrongParameters)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def model_exists?
|
||||
File.exists?(File.join(destination_root, model_path))
|
||||
File.exist?(File.join(destination_root, model_path))
|
||||
end
|
||||
|
||||
def migration_exists?(table_name)
|
||||
|
||||
@@ -47,7 +47,7 @@ module Devise
|
||||
def view_directory(name, _target_path = nil)
|
||||
directory name.to_s, _target_path || "#{target_path}/#{name}" do |content|
|
||||
if scope
|
||||
content.gsub "devise/shared/links", "#{scope}/shared/links"
|
||||
content.gsub "devise/shared/links", "#{plural_scope}/shared/links"
|
||||
else
|
||||
content
|
||||
end
|
||||
@@ -55,7 +55,11 @@ module Devise
|
||||
end
|
||||
|
||||
def target_path
|
||||
@target_path ||= "app/views/#{scope || :devise}"
|
||||
@target_path ||= "app/views/#{plural_scope || :devise}"
|
||||
end
|
||||
|
||||
def plural_scope
|
||||
@plural_scope ||= scope.presence && scope.underscore.pluralize
|
||||
end
|
||||
end
|
||||
|
||||
@@ -83,6 +87,13 @@ module Devise
|
||||
source_root File.expand_path("../../templates/simple_form_for", __FILE__)
|
||||
desc "Copies simple form enabled views to your application."
|
||||
hide!
|
||||
|
||||
def copy_views
|
||||
if options[:views]
|
||||
options[:views].delete('mailer')
|
||||
end
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
class ErbGenerator < Rails::Generators::Base #:nodoc:
|
||||
@@ -111,7 +122,7 @@ module Devise
|
||||
end
|
||||
|
||||
def target_path
|
||||
"app/views/#{scope || :devise}/mailer"
|
||||
"app/views/#{plural_scope || :devise}/mailer"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -21,14 +21,7 @@ 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 on Heroku with Rails 3.2 only, 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:
|
||||
4. You can copy Devise views (for customization) to your app by running:
|
||||
|
||||
rails g devise:views
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
Some setup you must do manually if you haven't yet:
|
||||
|
||||
Ensure you have overridden routes for generated controllers in your route.rb.
|
||||
Ensure you have overridden routes for generated controllers in your routes.rb.
|
||||
For example:
|
||||
|
||||
Rails.application.routes.draw do
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class <%= @scope_prefix %>RegistrationsController < Devise::RegistrationsController
|
||||
# before_filter :configure_sign_up_params, only: [:create]
|
||||
# before_filter :configure_account_update_params, only: [:update]
|
||||
# before_action :configure_sign_up_params, only: [:create]
|
||||
# before_action :configure_account_update_params, only: [:update]
|
||||
|
||||
# GET /resource/sign_up
|
||||
# def new
|
||||
@@ -40,12 +40,12 @@ class <%= @scope_prefix %>RegistrationsController < Devise::RegistrationsControl
|
||||
|
||||
# If you have extra params to permit, append them to the sanitizer.
|
||||
# def configure_sign_up_params
|
||||
# devise_parameter_sanitizer.for(:sign_up) << :attribute
|
||||
# devise_parameter_sanitizer.permit(:sign_up, keys: [:attribute])
|
||||
# end
|
||||
|
||||
# If you have extra params to permit, append them to the sanitizer.
|
||||
# def configure_account_update_params
|
||||
# devise_parameter_sanitizer.for(:account_update) << :attribute
|
||||
# devise_parameter_sanitizer.permit(:account_update, keys: [:attribute])
|
||||
# end
|
||||
|
||||
# The path used after sign up.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class <%= @scope_prefix %>SessionsController < Devise::SessionsController
|
||||
# before_filter :configure_sign_in_params, only: [:create]
|
||||
# before_action :configure_sign_in_params, only: [:create]
|
||||
|
||||
# GET /resource/sign_in
|
||||
# def new
|
||||
@@ -20,6 +20,6 @@ class <%= @scope_prefix %>SessionsController < Devise::SessionsController
|
||||
|
||||
# If you have extra params to permit, append them to the sanitizer.
|
||||
# def configure_sign_in_params
|
||||
# devise_parameter_sanitizer.for(:sign_in) << :attribute
|
||||
# devise_parameter_sanitizer.permit(:sign_in, keys: [:attribute])
|
||||
# end
|
||||
end
|
||||
|
||||
45
lib/generators/templates/devise.rb
Normal file → Executable file
45
lib/generators/templates/devise.rb
Normal file → Executable file
@@ -4,13 +4,9 @@ Devise.setup do |config|
|
||||
# The secret key used by Devise. Devise uses this key to generate
|
||||
# random tokens. Changing this key will render invalid all existing
|
||||
# confirmation, reset password and unlock tokens in the database.
|
||||
# Devise will use the `secret_key_base` on Rails 4+ applications as its `secret_key`
|
||||
# Devise will use the `secret_key_base` as its `secret_key`
|
||||
# by default. You can change it below and use your own secret key.
|
||||
<% if rails_4? -%>
|
||||
# config.secret_key = '<%= SecureRandom.hex(64) %>'
|
||||
<% else -%>
|
||||
config.secret_key = '<%= SecureRandom.hex(64) %>'
|
||||
<% end -%>
|
||||
|
||||
# ==> Mailer Configuration
|
||||
# Configure the e-mail address which will be shown in Devise::Mailer,
|
||||
@@ -21,6 +17,9 @@ Devise.setup do |config|
|
||||
# Configure the class responsible to send e-mails.
|
||||
# config.mailer = 'Devise::Mailer'
|
||||
|
||||
# Configure the parent class responsible to send e-mails.
|
||||
# config.parent_mailer = 'ActionMailer::Base'
|
||||
|
||||
# ==> ORM configuration
|
||||
# Load and configure the ORM. Supports :active_record (default) and
|
||||
# :mongoid (bson_ext recommended) by default. Other ORMs may be
|
||||
@@ -91,20 +90,29 @@ Devise.setup do |config|
|
||||
# from the server. You can disable this option at your own risk.
|
||||
# config.clean_up_csrf_token_on_authentication = true
|
||||
|
||||
# When false, Devise will not attempt to reload routes on eager load.
|
||||
# This can reduce the time taken to boot the app but if your application
|
||||
# requires the Devise mappings to be loaded during boot time the application
|
||||
# won't boot properly.
|
||||
# config.reload_routes = true
|
||||
|
||||
# ==> Configuration for :database_authenticatable
|
||||
# For bcrypt, this is the cost for hashing the password and defaults to 10. If
|
||||
# using other encryptors, it sets how many times you want the password re-encrypted.
|
||||
# For bcrypt, this is the cost for hashing the password and defaults to 11. If
|
||||
# using other algorithms, it sets how many times you want the password to be hashed.
|
||||
#
|
||||
# Limiting the stretches to just one in testing will increase the performance of
|
||||
# your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
|
||||
# a value less than 10 in other environments. Note that, for bcrypt (the default
|
||||
# encryptor), the cost increases exponentially with the number of stretches (e.g.
|
||||
# algorithm), the cost increases exponentially with the number of stretches (e.g.
|
||||
# a value of 20 is already extremely slow: approx. 60 seconds for 1 calculation).
|
||||
config.stretches = Rails.env.test? ? 1 : 10
|
||||
config.stretches = Rails.env.test? ? 1 : 11
|
||||
|
||||
# Setup a pepper to generate the encrypted password.
|
||||
# Set up a pepper to generate the hashed password.
|
||||
# config.pepper = '<%= SecureRandom.hex(64) %>'
|
||||
|
||||
# Send a notification email when the user's password is changed
|
||||
# config.send_password_change_notification = false
|
||||
|
||||
# ==> Configuration for :confirmable
|
||||
# A period that the user is allowed to access the website even without
|
||||
# confirming their account. For instance, if set to 2.days, the user will be
|
||||
@@ -146,21 +154,18 @@ Devise.setup do |config|
|
||||
|
||||
# ==> Configuration for :validatable
|
||||
# Range for password length.
|
||||
config.password_length = 8..72
|
||||
config.password_length = 6..128
|
||||
|
||||
# Email regex used to validate email formats. It simply asserts that
|
||||
# one (and only one) @ exists in the given string. This is mainly
|
||||
# to give user feedback and not to assert the e-mail validity.
|
||||
# config.email_regexp = /\A[^@]+@[^@]+\z/
|
||||
config.email_regexp = /\A[^@\s]+@[^@\s]+\z/
|
||||
|
||||
# ==> Configuration for :timeoutable
|
||||
# The time you want to timeout the user session without activity. After this
|
||||
# time the user will be asked for credentials again. Default is 30 minutes.
|
||||
# config.timeout_in = 30.minutes
|
||||
|
||||
# If true, expires auth token on session timeout.
|
||||
# config.expire_auth_token_on_timeout = false
|
||||
|
||||
# ==> 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.
|
||||
@@ -202,11 +207,11 @@ Devise.setup do |config|
|
||||
# config.sign_in_after_reset_password = true
|
||||
|
||||
# ==> Configuration for :encryptable
|
||||
# Allow you to use another encryption algorithm besides bcrypt (default). You can use
|
||||
# :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1,
|
||||
# :authlogic_sha512 (then you should set stretches above to 20 for default behavior)
|
||||
# and :restful_authentication_sha1 (then you should set stretches to 10, and copy
|
||||
# REST_AUTH_SITE_KEY to pepper).
|
||||
# Allow you to use another hashing or encryption algorithm besides bcrypt (default).
|
||||
# You can use :sha1, :sha512 or algorithms from others authentication tools as
|
||||
# :clearance_sha1, :authlogic_sha512 (then you should set stretches above to 20
|
||||
# for default behavior) and :restful_authentication_sha1 (then you should set
|
||||
# stretches to 10, and copy REST_AUTH_SITE_KEY to pepper).
|
||||
#
|
||||
# Require the `devise-encryptable` gem when using anything other than bcrypt
|
||||
# config.encryptor = :sha512
|
||||
|
||||
@@ -2,4 +2,4 @@ Welcome <%= @email %>!
|
||||
|
||||
You can confirm your account through the link below:
|
||||
|
||||
<%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %>
|
||||
[Confirm my account](<%= confirmation_url(@resource, confirmation_token: @token) %>)
|
||||
|
||||
3
lib/generators/templates/markerb/password_change.markerb
Normal file
3
lib/generators/templates/markerb/password_change.markerb
Normal file
@@ -0,0 +1,3 @@
|
||||
<p>Hello <%= @resource.email %>!</p>
|
||||
|
||||
<p>We're contacting you to notify you that your password has been changed.</p>
|
||||
@@ -2,7 +2,7 @@ Hello <%= @resource.email %>!
|
||||
|
||||
Someone has requested a link to change your password, and you can do this through the link below.
|
||||
|
||||
<%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %>
|
||||
[Change my password](<%= edit_password_url(@resource, reset_password_token: @token) %>)
|
||||
|
||||
If you didn't request this, please ignore this email.
|
||||
Your password won't change until you access the link above and create a new one.
|
||||
|
||||
@@ -4,4 +4,4 @@ Your account has been locked due to an excessive number of unsuccessful sign in
|
||||
|
||||
Click the link below to unlock your account:
|
||||
|
||||
<%= link_to 'Unlock my account', unlock_url(@resource, unlock_token: @token) %>
|
||||
[Unlock my account](<%= unlock_url(@resource, unlock_token: @token) %>)
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Usage: cached-bundle install --deployment
|
||||
#
|
||||
# After running `bundle`, caches the `vendor/bundle` directory to S3.
|
||||
# On the next run, restores the cached directory before running `bundle`.
|
||||
# When `Gemfile.lock` changes, the cache gets rebuilt.
|
||||
#
|
||||
# Requirements:
|
||||
# - Gemfile.lock
|
||||
# - TRAVIS_REPO_SLUG
|
||||
# - TRAVIS_RUBY_VERSION
|
||||
# - AMAZON_S3_BUCKET
|
||||
# - script/s3-put
|
||||
# - bundle
|
||||
# - curl
|
||||
#
|
||||
# Author: Mislav Marohnić
|
||||
|
||||
set -e
|
||||
|
||||
compute_md5() {
|
||||
local output="$(openssl md5)"
|
||||
echo "${output##* }"
|
||||
}
|
||||
|
||||
download() {
|
||||
curl --tcp-nodelay -qsfL "$1" -o "$2"
|
||||
}
|
||||
|
||||
|
||||
gemfile="${BUNDLE_GEMFILE:-Gemfile}"
|
||||
bundle_fullpath="$(dirname $gemfile)/vendor/bundle"
|
||||
bundle_path=${bundle_fullpath#$PWD/}
|
||||
gemfile_hash="$(compute_md5 <"${gemfile}.lock")"
|
||||
cache_name="${TRAVIS_RUBY_VERSION}-${gemfile_hash}.tgz"
|
||||
fetch_url="http://${AMAZON_S3_BUCKET}.s3.amazonaws.com/${TRAVIS_REPO_SLUG}/${cache_name}"
|
||||
|
||||
if download "$fetch_url" "$cache_name"; then
|
||||
echo "Reusing cached bundle ${cache_name}"
|
||||
tar xzf "$cache_name"
|
||||
fi
|
||||
|
||||
bundle "$@"
|
||||
|
||||
if [ ! -f "$cache_name" ] && [ -n "$AMAZON_SECRET_ACCESS_KEY" ]; then
|
||||
echo "Caching \`${bundle_path}' to S3"
|
||||
tar czf "$cache_name" "$bundle_path"
|
||||
script/s3-put "$cache_name" "${AMAZON_S3_BUCKET}:${TRAVIS_REPO_SLUG}/${cache_name}"
|
||||
fi
|
||||
@@ -1,71 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Usage: s3-put <FILE> <S3_BUCKET>[:<PATH>] [<CONTENT_TYPE>]
|
||||
#
|
||||
# Uploads a file to the Amazon S3 service.
|
||||
# Outputs the URL for the newly uploaded file.
|
||||
#
|
||||
# Requirements:
|
||||
# - AMAZON_ACCESS_KEY_ID
|
||||
# - AMAZON_SECRET_ACCESS_KEY
|
||||
# - openssl
|
||||
# - curl
|
||||
#
|
||||
# Author: Mislav Marohnić
|
||||
|
||||
set -e
|
||||
|
||||
authorization() {
|
||||
local signature="$(string_to_sign | hmac_sha1 | base64)"
|
||||
echo "AWS ${AMAZON_ACCESS_KEY_ID?}:${signature}"
|
||||
}
|
||||
|
||||
hmac_sha1() {
|
||||
openssl dgst -binary -sha1 -hmac "${AMAZON_SECRET_ACCESS_KEY?}"
|
||||
}
|
||||
|
||||
base64() {
|
||||
openssl enc -base64
|
||||
}
|
||||
|
||||
bin_md5() {
|
||||
openssl dgst -binary -md5
|
||||
}
|
||||
|
||||
string_to_sign() {
|
||||
echo "$http_method"
|
||||
echo "$content_md5"
|
||||
echo "$content_type"
|
||||
echo "$date"
|
||||
echo "x-amz-acl:$acl"
|
||||
printf "/$bucket/$remote_path"
|
||||
}
|
||||
|
||||
date_string() {
|
||||
LC_TIME=C date "+%a, %d %h %Y %T %z"
|
||||
}
|
||||
|
||||
file="$1"
|
||||
bucket="${2%%:*}"
|
||||
remote_path="${2#*:}"
|
||||
content_type="$3"
|
||||
|
||||
if [ -z "$remote_path" ] || [ "$remote_path" = "$bucket" ]; then
|
||||
remote_path="${file##*/}"
|
||||
fi
|
||||
|
||||
http_method=PUT
|
||||
acl="public-read"
|
||||
content_md5="$(bin_md5 < "$file" | base64)"
|
||||
date="$(date_string)"
|
||||
|
||||
url="https://$bucket.s3.amazonaws.com/$remote_path"
|
||||
|
||||
curl -qsSf -T "$file" \
|
||||
-H "Authorization: $(authorization)" \
|
||||
-H "x-amz-acl: $acl" \
|
||||
-H "Date: $date" \
|
||||
-H "Content-MD5: $content_md5" \
|
||||
-H "Content-Type: $content_type" \
|
||||
"$url"
|
||||
|
||||
echo "$url"
|
||||
@@ -1,9 +1,9 @@
|
||||
require 'test_helper'
|
||||
|
||||
class CustomRegistrationsControllerTest < ActionController::TestCase
|
||||
class CustomRegistrationsControllerTest < Devise::ControllerTestCase
|
||||
tests Custom::RegistrationsController
|
||||
|
||||
include Devise::TestHelpers
|
||||
include Devise::Test::ControllerHelpers
|
||||
|
||||
setup do
|
||||
request.env["devise.mapping"] = Devise.mappings[:user]
|
||||
@@ -12,24 +12,24 @@ class CustomRegistrationsControllerTest < ActionController::TestCase
|
||||
end
|
||||
|
||||
test "yield resource to block on create success" do
|
||||
post :create, { user: { email: "user@example.org", password: "password", password_confirmation: "password" } }
|
||||
post :create, params: { user: { email: "user@example.org", password: "password", password_confirmation: "password" } }
|
||||
assert @controller.create_block_called?, "create failed to yield resource to provided block"
|
||||
end
|
||||
|
||||
test "yield resource to block on create failure" do
|
||||
post :create, { user: { } }
|
||||
post :create, params: { user: { } }
|
||||
assert @controller.create_block_called?, "create failed to yield resource to provided block"
|
||||
end
|
||||
|
||||
test "yield resource to block on update success" do
|
||||
sign_in @user
|
||||
put :update, { user: { current_password: @password } }
|
||||
put :update, params: { user: { current_password: @password } }
|
||||
assert @controller.update_block_called?, "update failed to yield resource to provided block"
|
||||
end
|
||||
|
||||
test "yield resource to block on update failure" do
|
||||
sign_in @user
|
||||
put :update, { user: { } }
|
||||
put :update, params: { user: { } }
|
||||
assert @controller.update_block_called?, "update failed to yield resource to provided block"
|
||||
end
|
||||
|
||||
|
||||
@@ -24,10 +24,10 @@ class CustomStrategy < Warden::Strategies::Base
|
||||
end
|
||||
end
|
||||
|
||||
class CustomStrategyTest < ActionController::TestCase
|
||||
class CustomStrategyTest < Devise::ControllerTestCase
|
||||
tests CustomStrategyController
|
||||
|
||||
include Devise::TestHelpers
|
||||
include Devise::Test::ControllerHelpers
|
||||
|
||||
setup do
|
||||
Warden::Strategies.add(:custom_strategy, CustomStrategy)
|
||||
@@ -41,8 +41,9 @@ class CustomStrategyTest < ActionController::TestCase
|
||||
ret = get :new
|
||||
|
||||
# check the returned rack array
|
||||
assert ret.is_a?(Array)
|
||||
assert_equal 400, ret.first
|
||||
# assert ret.is_a?(Array)
|
||||
# assert_equal 400, ret.first
|
||||
assert ret.is_a?(ActionDispatch::TestResponse)
|
||||
|
||||
# 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.
|
||||
@@ -53,8 +54,9 @@ class CustomStrategyTest < ActionController::TestCase
|
||||
ret = get :new
|
||||
|
||||
# check the returned rack array
|
||||
assert ret.is_a?(Array)
|
||||
assert_equal ret.third['X-FOO'], 'BAR'
|
||||
# assert ret.is_a?(Array)
|
||||
# assert_equal ret.third['X-FOO'], 'BAR'
|
||||
assert ret.is_a?(ActionDispatch::TestResponse)
|
||||
|
||||
# check the saved response headers as well.
|
||||
assert_equal response.headers['X-FOO'], 'BAR'
|
||||
|
||||
22
test/controllers/helper_methods_test.rb
Normal file
22
test/controllers/helper_methods_test.rb
Normal file
@@ -0,0 +1,22 @@
|
||||
require 'test_helper'
|
||||
|
||||
class ApiController < ActionController::Metal
|
||||
include Devise::Controllers::Helpers
|
||||
end
|
||||
|
||||
class HelperMethodsTest < Devise::ControllerTestCase
|
||||
tests ApiController
|
||||
|
||||
test 'includes Devise::Controllers::Helpers' do
|
||||
assert_includes @controller.class.ancestors, Devise::Controllers::Helpers
|
||||
end
|
||||
|
||||
test 'does not respond_to helper or helper_method' do
|
||||
refute_respond_to @controller.class, :helper
|
||||
refute_respond_to @controller.class, :helper_method
|
||||
end
|
||||
|
||||
test 'defines methods like current_user' do
|
||||
assert_respond_to @controller, :current_user
|
||||
end
|
||||
end
|
||||
@@ -1,7 +1,7 @@
|
||||
require 'test_helper'
|
||||
require 'ostruct'
|
||||
|
||||
class ControllerAuthenticatableTest < ActionController::TestCase
|
||||
class ControllerAuthenticatableTest < Devise::ControllerTestCase
|
||||
tests ApplicationController
|
||||
|
||||
def setup
|
||||
@@ -96,7 +96,7 @@ class ControllerAuthenticatableTest < ActionController::TestCase
|
||||
|
||||
test 'proxy admin_signed_in? to authenticatewith admin scope' do
|
||||
@mock_warden.expects(:authenticate).with(scope: :admin)
|
||||
assert_not @controller.admin_signed_in?
|
||||
refute @controller.admin_signed_in?
|
||||
end
|
||||
|
||||
test 'proxy publisher_account_signed_in? to authenticate with namespaced publisher account scope' do
|
||||
@@ -150,11 +150,11 @@ class ControllerAuthenticatableTest < ActionController::TestCase
|
||||
@controller.sign_in(user, force: true)
|
||||
end
|
||||
|
||||
test 'sign in accepts bypass as option' do
|
||||
test 'bypass the sign in' do
|
||||
user = User.new
|
||||
@mock_warden.expects(:session_serializer).returns(serializer = mock())
|
||||
serializer.expects(:store).with(user, :user)
|
||||
@controller.sign_in(user, bypass: true)
|
||||
@controller.bypass_sign_in(user)
|
||||
end
|
||||
|
||||
test 'sign out clears up any signed in user from all scopes' do
|
||||
@@ -311,6 +311,6 @@ class ControllerAuthenticatableTest < ActionController::TestCase
|
||||
end
|
||||
|
||||
test 'is not a devise controller' do
|
||||
assert_not @controller.devise_controller?
|
||||
refute @controller.devise_controller?
|
||||
end
|
||||
end
|
||||
|
||||
@@ -14,7 +14,7 @@ class AnotherInheritedController < SessionsInheritedController
|
||||
end
|
||||
end
|
||||
|
||||
class InheritedControllerTest < ActionController::TestCase
|
||||
class InheritedControllerTest < Devise::ControllerTestCase
|
||||
tests SessionsInheritedController
|
||||
|
||||
def setup
|
||||
@@ -32,7 +32,7 @@ class InheritedControllerTest < ActionController::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
class AnotherInheritedControllerTest < ActionController::TestCase
|
||||
class AnotherInheritedControllerTest < Devise::ControllerTestCase
|
||||
tests AnotherInheritedController
|
||||
|
||||
def setup
|
||||
|
||||
@@ -3,7 +3,7 @@ require 'test_helper'
|
||||
class MyController < DeviseController
|
||||
end
|
||||
|
||||
class HelpersTest < ActionController::TestCase
|
||||
class HelpersTest < Devise::ControllerTestCase
|
||||
tests MyController
|
||||
|
||||
def setup
|
||||
@@ -36,18 +36,16 @@ class HelpersTest < ActionController::TestCase
|
||||
test 'get resource params from request params using resource name as key' do
|
||||
user_params = {'email' => 'shirley@templar.com'}
|
||||
|
||||
params = if Devise.rails4?
|
||||
# Stub controller name so strong parameters can filter properly.
|
||||
# DeviseController does not allow any parameters by default.
|
||||
@controller.stubs(:controller_name).returns(:sessions_controller)
|
||||
# Stub controller name so strong parameters can filter properly.
|
||||
# DeviseController does not allow any parameters by default.
|
||||
@controller.stubs(:controller_name).returns(:sessions_controller)
|
||||
|
||||
params = ActionController::Parameters.new({'user' => user_params})
|
||||
|
||||
ActionController::Parameters.new({'user' => user_params})
|
||||
else
|
||||
HashWithIndifferentAccess.new({'user' => user_params})
|
||||
end
|
||||
@controller.stubs(:params).returns(params)
|
||||
|
||||
assert_equal user_params, @controller.send(:resource_params)
|
||||
res_params = @controller.send(:resource_params).permit!.to_h
|
||||
assert_equal user_params, res_params
|
||||
end
|
||||
|
||||
test 'resources methods are not controller actions' do
|
||||
@@ -121,7 +119,7 @@ class HelpersTest < ActionController::TestCase
|
||||
MyController.send(:public, :navigational_formats)
|
||||
|
||||
swap Devise, navigational_formats: ['*/*', :html] do
|
||||
assert_not @controller.navigational_formats.include?("*/*")
|
||||
refute @controller.navigational_formats.include?("*/*")
|
||||
end
|
||||
|
||||
MyController.send(:protected, :navigational_formats)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require 'test_helper'
|
||||
|
||||
class LoadHooksControllerTest < ActionController::TestCase
|
||||
class LoadHooksControllerTest < Devise::ControllerTestCase
|
||||
setup do
|
||||
ActiveSupport.on_load(:devise_controller) do
|
||||
define_method :defined_by_load_hook do
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
require 'test_helper'
|
||||
|
||||
class PasswordsControllerTest < ActionController::TestCase
|
||||
class PasswordsControllerTest < Devise::ControllerTestCase
|
||||
tests Devise::PasswordsController
|
||||
include Devise::TestHelpers
|
||||
include Devise::Test::ControllerHelpers
|
||||
|
||||
setup do
|
||||
request.env["devise.mapping"] = Devise.mappings[:user]
|
||||
@@ -11,8 +11,9 @@ class PasswordsControllerTest < ActionController::TestCase
|
||||
end
|
||||
|
||||
def put_update_with_params
|
||||
put :update, "user" => {
|
||||
"reset_password_token" => @raw, "password" => "1234567", "password_confirmation" => "1234567"
|
||||
put :update, params: { "user" => {
|
||||
"reset_password_token" => @raw, "password" => "1234567", "password_confirmation" => "1234567"
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
@@ -1,20 +1,21 @@
|
||||
require 'test_helper'
|
||||
|
||||
class SessionsControllerTest < ActionController::TestCase
|
||||
class SessionsControllerTest < Devise::ControllerTestCase
|
||||
tests Devise::SessionsController
|
||||
include Devise::TestHelpers
|
||||
include Devise::Test::ControllerHelpers
|
||||
|
||||
test "#create doesn't raise unpermitted params when sign in fails" do
|
||||
begin
|
||||
subscriber = ActiveSupport::Notifications.subscribe /unpermitted_parameters/ do |name, start, finish, id, payload|
|
||||
subscriber = ActiveSupport::Notifications.subscribe %r{unpermitted_parameters} do |name, start, finish, id, payload|
|
||||
flunk "Unpermitted params: #{payload}"
|
||||
end
|
||||
request.env["devise.mapping"] = Devise.mappings[:user]
|
||||
request.session["user_return_to"] = 'foo.bar'
|
||||
create_user
|
||||
post :create, user: {
|
||||
email: "wrong@email.com",
|
||||
password: "wrongpassword"
|
||||
post :create, params: { user: {
|
||||
email: "wrong@email.com",
|
||||
password: "wrongpassword"
|
||||
}
|
||||
}
|
||||
assert_equal 200, @response.status
|
||||
ensure
|
||||
@@ -37,11 +38,11 @@ class SessionsControllerTest < ActionController::TestCase
|
||||
|
||||
user = create_user
|
||||
user.confirm
|
||||
post :create, user: {
|
||||
email: user.email,
|
||||
password: user.password
|
||||
post :create, params: { user: {
|
||||
email: user.email,
|
||||
password: user.password
|
||||
}
|
||||
}
|
||||
|
||||
assert_nil request.session["user_return_to"]
|
||||
end
|
||||
|
||||
@@ -51,9 +52,10 @@ class SessionsControllerTest < ActionController::TestCase
|
||||
|
||||
user = create_user
|
||||
user.confirm
|
||||
post :create, format: 'json', user: {
|
||||
email: user.email,
|
||||
password: user.password
|
||||
post :create, params: { format: 'json', user: {
|
||||
email: user.email,
|
||||
password: user.password
|
||||
}
|
||||
}
|
||||
|
||||
assert_equal 'foo.bar', request.session["user_return_to"]
|
||||
@@ -61,9 +63,10 @@ class SessionsControllerTest < ActionController::TestCase
|
||||
|
||||
test "#create doesn't raise exception after Warden authentication fails when TestHelpers included" do
|
||||
request.env["devise.mapping"] = Devise.mappings[:user]
|
||||
post :create, user: {
|
||||
email: "nosuchuser@example.com",
|
||||
password: "wevdude"
|
||||
post :create, params: { user: {
|
||||
email: "nosuchuser@example.com",
|
||||
password: "wevdude"
|
||||
}
|
||||
}
|
||||
assert_equal 200, @response.status
|
||||
assert_template "devise/sessions/new"
|
||||
@@ -73,11 +76,11 @@ class SessionsControllerTest < ActionController::TestCase
|
||||
request.env["devise.mapping"] = Devise.mappings[:user]
|
||||
user = create_user
|
||||
user.confirm
|
||||
post :create, format: 'json', user: {
|
||||
email: user.email,
|
||||
password: user.password
|
||||
post :create, params: { 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
|
||||
@@ -91,7 +94,7 @@ class SessionsControllerTest < ActionController::TestCase
|
||||
User.class_eval { attr_protected :email }
|
||||
|
||||
begin
|
||||
assert_nothing_raised ActiveModel::MassAssignmentSecurity::Error do
|
||||
assert_nothing_raised do
|
||||
get :new, user: { email: "allez viens!" }
|
||||
end
|
||||
ensure
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require 'test_helper'
|
||||
|
||||
class RoutesTest < ActionController::TestCase
|
||||
class RoutesTest < Devise::ControllerTestCase
|
||||
tests ApplicationController
|
||||
|
||||
def assert_path_and_url(name, prepend_path=nil)
|
||||
|
||||
22
test/devise_test.rb
Normal file → Executable file
22
test/devise_test.rb
Normal file → Executable file
@@ -67,18 +67,18 @@ class DeviseTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
test 'add new module using the helper method' do
|
||||
assert_nothing_raised(Exception) { Devise.add_module(:coconut) }
|
||||
Devise.add_module(:coconut)
|
||||
assert_equal 1, Devise::ALL.select { |v| v == :coconut }.size
|
||||
assert_not Devise::STRATEGIES.include?(:coconut)
|
||||
assert_not defined?(Devise::Models::Coconut)
|
||||
refute Devise::STRATEGIES.include?(:coconut)
|
||||
refute defined?(Devise::Models::Coconut)
|
||||
Devise::ALL.delete(:coconut)
|
||||
|
||||
assert_nothing_raised(Exception) { Devise.add_module(:banana, strategy: :fruits) }
|
||||
Devise.add_module(:banana, strategy: :fruits)
|
||||
assert_equal :fruits, Devise::STRATEGIES[:banana]
|
||||
Devise::ALL.delete(:banana)
|
||||
Devise::STRATEGIES.delete(:banana)
|
||||
|
||||
assert_nothing_raised(Exception) { Devise.add_module(:kivi, controller: :fruits) }
|
||||
Devise.add_module(:kivi, controller: :fruits)
|
||||
assert_equal :fruits, Devise::CONTROLLERS[:kivi]
|
||||
Devise::ALL.delete(:kivi)
|
||||
Devise::CONTROLLERS.delete(:kivi)
|
||||
@@ -86,16 +86,16 @@ class DeviseTest < ActiveSupport::TestCase
|
||||
|
||||
test 'should complain when comparing empty or different sized passes' do
|
||||
[nil, ""].each do |empty|
|
||||
assert_not Devise.secure_compare(empty, "something")
|
||||
assert_not Devise.secure_compare("something", empty)
|
||||
assert_not Devise.secure_compare(empty, empty)
|
||||
refute Devise.secure_compare(empty, "something")
|
||||
refute Devise.secure_compare("something", empty)
|
||||
refute Devise.secure_compare(empty, empty)
|
||||
end
|
||||
assert_not Devise.secure_compare("size_1", "size_four")
|
||||
refute 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 = ["test@example.com", "jo@jo.co", "f4$_m@you.com", "testing.example@example.com.ua", "test@tt", "test@valid---domain.com"]
|
||||
non_valid_emails = ["rex", "test user@example.com", "test_user@example server.com"]
|
||||
|
||||
valid_emails.each do |email|
|
||||
assert_match Devise.email_regexp, email
|
||||
|
||||
@@ -53,11 +53,16 @@ class FailureTest < ActiveSupport::TestCase
|
||||
'REQUEST_METHOD' => 'GET',
|
||||
'warden.options' => { scope: :user },
|
||||
'rack.session' => {},
|
||||
'action_dispatch.request.formats' => Array(env_params.delete('formats') || Mime::HTML),
|
||||
'action_dispatch.request.formats' => Array(env_params.delete('formats') || Mime[:html]),
|
||||
'rack.input' => "",
|
||||
'warden' => OpenStruct.new(message: nil)
|
||||
}.merge!(env_params)
|
||||
|
||||
# Passing nil for action_dispatch.request.formats prevents the default from being used in Rails 5, need to remove it
|
||||
if env.has_key?('action_dispatch.request.formats') && env['action_dispatch.request.formats'].nil?
|
||||
env.delete 'action_dispatch.request.formats' unless env['action_dispatch.request.formats']
|
||||
end
|
||||
|
||||
@response = (env.delete(:app) || Devise::FailureApp).call(env).to_a
|
||||
@request = ActionDispatch::Request.new(env)
|
||||
end
|
||||
@@ -126,16 +131,34 @@ class FailureTest < ActiveSupport::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
if Rails.application.config.action_controller.respond_to?(:relative_url_root)
|
||||
test "returns to the default redirect location considering action_controller's relative url root" do
|
||||
swap Rails.application.config.action_controller, 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
|
||||
|
||||
test "returns to the default redirect location considering action_controller's relative url root and subdomain" do
|
||||
swap Rails.application.config.action_controller, relative_url_root: "/sample" do
|
||||
call_failure('warden.options' => { scope: :subdomain_user })
|
||||
assert_equal 302, @response.first
|
||||
assert_equal 'http://sub.test.host/sample/subdomain_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]
|
||||
assert_equal 'Invalid Email or password.', @request.flash[:alert]
|
||||
assert_equal 'http://test.host/users/sign_in', @response.second["Location"]
|
||||
end
|
||||
|
||||
test 'supports authentication_keys as a Hash for the flash message' do
|
||||
swap Devise, authentication_keys: { email: true, login: true } do
|
||||
call_failure('warden' => OpenStruct.new(message: :invalid))
|
||||
assert_equal 'Invalid email, login or password.', @request.flash[:alert]
|
||||
assert_equal 'Invalid Email, Login or password.', @request.flash[:alert]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -155,7 +178,7 @@ class FailureTest < ActiveSupport::TestCase
|
||||
assert_equal 'text/html; charset=utf-8', @response.second['Content-Type']
|
||||
end
|
||||
|
||||
test 'setup a default message' do
|
||||
test 'set up a default message' do
|
||||
call_failure
|
||||
assert_match(/You are being/, @response.last.body)
|
||||
assert_match(/redirected/, @response.last.body)
|
||||
@@ -164,14 +187,14 @@ class FailureTest < ActiveSupport::TestCase
|
||||
|
||||
test 'works for any navigational format' do
|
||||
swap Devise, navigational_formats: [:xml] do
|
||||
call_failure('formats' => Mime::XML)
|
||||
call_failure('formats' => Mime[:xml])
|
||||
assert_equal 302, @response.first
|
||||
end
|
||||
end
|
||||
|
||||
test 'redirects the correct format if it is a non-html format request' do
|
||||
swap Devise, navigational_formats: [:js] do
|
||||
call_failure('formats' => Mime::JS)
|
||||
call_failure('formats' => Mime[:js])
|
||||
assert_equal 'http://test.host/users/sign_in.js', @response.second["Location"]
|
||||
end
|
||||
end
|
||||
@@ -179,18 +202,18 @@ class FailureTest < ActiveSupport::TestCase
|
||||
|
||||
context 'For HTTP request' do
|
||||
test 'return 401 status' do
|
||||
call_failure('formats' => Mime::XML)
|
||||
call_failure('formats' => Mime[:xml])
|
||||
assert_equal 401, @response.first
|
||||
end
|
||||
|
||||
test 'return appropriate body for xml' do
|
||||
call_failure('formats' => Mime::XML)
|
||||
call_failure('formats' => Mime[:xml])
|
||||
result = %(<?xml version="1.0" encoding="UTF-8"?>\n<errors>\n <error>You need to sign in or sign up before continuing.</error>\n</errors>\n)
|
||||
assert_equal result, @response.last.body
|
||||
end
|
||||
|
||||
test 'return appropriate body for json' do
|
||||
call_failure('formats' => Mime::JSON)
|
||||
call_failure('formats' => Mime[:json])
|
||||
result = %({"error":"You need to sign in or sign up before continuing."})
|
||||
assert_equal result, @response.last.body
|
||||
end
|
||||
@@ -201,34 +224,34 @@ class FailureTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
test 'return WWW-authenticate headers if model allows' do
|
||||
call_failure('formats' => Mime::XML)
|
||||
call_failure('formats' => Mime[:xml])
|
||||
assert_equal 'Basic realm="Application"', @response.second["WWW-Authenticate"]
|
||||
end
|
||||
|
||||
test 'does not return WWW-authenticate headers if model does not allow' do
|
||||
swap Devise, http_authenticatable: false do
|
||||
call_failure('formats' => Mime::XML)
|
||||
call_failure('formats' => Mime[:xml])
|
||||
assert_nil @response.second["WWW-Authenticate"]
|
||||
end
|
||||
end
|
||||
|
||||
test 'works for any non navigational format' do
|
||||
swap Devise, navigational_formats: [] do
|
||||
call_failure('formats' => Mime::HTML)
|
||||
call_failure('formats' => Mime[:html])
|
||||
assert_equal 401, @response.first
|
||||
end
|
||||
end
|
||||
|
||||
test 'uses the failure message as response body' do
|
||||
call_failure('formats' => Mime::XML, 'warden' => OpenStruct.new(message: :invalid))
|
||||
assert_match '<error>Invalid email or password.</error>', @response.third.body
|
||||
call_failure('formats' => Mime[:xml], 'warden' => OpenStruct.new(message: :invalid))
|
||||
assert_match '<error>Invalid Email or password.</error>', @response.third.body
|
||||
end
|
||||
|
||||
context 'on ajax call' do
|
||||
context 'when http_authenticatable_on_xhr is false' do
|
||||
test 'dont return 401 with navigational formats' do
|
||||
swap Devise, http_authenticatable_on_xhr: false do
|
||||
call_failure('formats' => Mime::HTML, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
|
||||
call_failure('formats' => Mime[:html], 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
|
||||
assert_equal 302, @response.first
|
||||
assert_equal 'http://test.host/users/sign_in', @response.second["Location"]
|
||||
end
|
||||
@@ -236,7 +259,7 @@ class FailureTest < ActiveSupport::TestCase
|
||||
|
||||
test 'dont return 401 with non navigational formats' do
|
||||
swap Devise, http_authenticatable_on_xhr: false do
|
||||
call_failure('formats' => Mime::JSON, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
|
||||
call_failure('formats' => Mime[:json], 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
|
||||
assert_equal 302, @response.first
|
||||
assert_equal 'http://test.host/users/sign_in.json', @response.second["Location"]
|
||||
end
|
||||
@@ -246,14 +269,14 @@ class FailureTest < ActiveSupport::TestCase
|
||||
context 'when http_authenticatable_on_xhr is true' do
|
||||
test 'return 401' do
|
||||
swap Devise, http_authenticatable_on_xhr: true do
|
||||
call_failure('formats' => Mime::HTML, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
|
||||
call_failure('formats' => Mime[:html], 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
|
||||
assert_equal 401, @response.first
|
||||
end
|
||||
end
|
||||
|
||||
test 'skip WWW-Authenticate header' do
|
||||
swap Devise, http_authenticatable_on_xhr: true do
|
||||
call_failure('formats' => Mime::HTML, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
|
||||
call_failure('formats' => Mime[:html], 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
|
||||
assert_nil @response.second['WWW-Authenticate']
|
||||
end
|
||||
end
|
||||
@@ -270,7 +293,7 @@ class FailureTest < ActiveSupport::TestCase
|
||||
}
|
||||
call_failure(env)
|
||||
assert @response.third.body.include?('<h2>Log in</h2>')
|
||||
assert @response.third.body.include?('Invalid email or password.')
|
||||
assert @response.third.body.include?('Invalid Email or password.')
|
||||
end
|
||||
|
||||
test 'calls the original controller if not confirmed email' do
|
||||
@@ -294,5 +317,22 @@ class FailureTest < ActiveSupport::TestCase
|
||||
assert @response.third.body.include?('<h2>Log in</h2>')
|
||||
assert @response.third.body.include?('Your account is not activated yet.')
|
||||
end
|
||||
|
||||
if Rails.application.config.respond_to?(:relative_url_root)
|
||||
test 'calls the original controller with the proper environment considering the relative url root' do
|
||||
swap Rails.application.config, relative_url_root: "/sample" do
|
||||
env = {
|
||||
"warden.options" => { recall: "devise/sessions#new", attempted_path: "/sample/users/sign_in"},
|
||||
"devise.mapping" => Devise.mappings[:user],
|
||||
"warden" => stub_everything
|
||||
}
|
||||
call_failure(env)
|
||||
assert @response.third.body.include?('<h2>Log in</h2>')
|
||||
assert @response.third.body.include?('Invalid Email or password.')
|
||||
assert_equal @request.env["SCRIPT_NAME"], '/sample'
|
||||
assert_equal @request.env["PATH_INFO"], '/users/sign_in'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -69,41 +69,15 @@ if DEVISE_ORM == :active_record
|
||||
setup :prepare_destination
|
||||
|
||||
test "all files are properly created in rails 4.0" do
|
||||
ActiveRecord::Generators::DeviseGenerator.any_instance.stubs(:rails_3?).returns(false)
|
||||
simulate_inside_engine(RailsEngine::Engine, RailsEngine) do
|
||||
run_generator ["monster"]
|
||||
|
||||
assert_file "app/models/rails_engine/monster.rb", /devise/
|
||||
assert_file "app/models/rails_engine/monster.rb" do |content|
|
||||
assert_no_match /attr_accessible :email/, content
|
||||
assert_no_match %r{attr_accessible :email}, content
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
test "all files are properly created in rails 3.2 when strong_parameters gem is not installed" do
|
||||
ActiveRecord::Generators::DeviseGenerator.any_instance.stubs(:rails_3?).returns(true)
|
||||
ActiveRecord::Generators::DeviseGenerator.any_instance.stubs(:strong_parameters_enabled?).returns(false)
|
||||
simulate_inside_engine(RailsEngine::Engine, RailsEngine) do
|
||||
run_generator ["monster"]
|
||||
|
||||
assert_file "app/models/rails_engine/monster.rb", /devise/
|
||||
assert_file "app/models/rails_engine/monster.rb" do |content|
|
||||
assert_match /attr_accessible :email/, content
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
test "all files are properly created in rails 3.2 when strong_parameters gem is installed" do
|
||||
ActiveRecord::Generators::DeviseGenerator.any_instance.stubs(:rails_3?).returns(true)
|
||||
ActiveRecord::Generators::DeviseGenerator.any_instance.stubs(:strong_parameters_enabled?).returns(true)
|
||||
simulate_inside_engine(RailsEngine::Engine, RailsEngine) do
|
||||
run_generator ["monster"]
|
||||
|
||||
assert_file "app/models/rails_engine/monster.rb", /devise/
|
||||
assert_file "app/models/rails_engine/monster.rb" do |content|
|
||||
assert_no_match /attr_accessible :email/, content
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,9 +5,20 @@ class InstallGeneratorTest < Rails::Generators::TestCase
|
||||
destination File.expand_path("../../tmp", __FILE__)
|
||||
setup :prepare_destination
|
||||
|
||||
test "Assert all files are properly created" do
|
||||
run_generator
|
||||
assert_file "config/initializers/devise.rb"
|
||||
test "assert all files are properly created" do
|
||||
run_generator(["--orm=active_record"])
|
||||
assert_file "config/initializers/devise.rb", /devise\/orm\/active_record/
|
||||
assert_file "config/locales/devise.en.yml"
|
||||
end
|
||||
|
||||
test "fails if no ORM is specified" do
|
||||
stderr = capture(:stderr) do
|
||||
run_generator
|
||||
end
|
||||
|
||||
assert_match %r{An ORM must be set to install Devise}, stderr
|
||||
|
||||
assert_no_file "config/initializers/devise.rb"
|
||||
assert_no_file "config/locales/devise.en.yml"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -46,6 +46,13 @@ class ViewsGeneratorTest < Rails::Generators::TestCase
|
||||
assert_no_file "app/views/devise/mailer/confirmation_instructions.html.erb"
|
||||
end
|
||||
|
||||
test "Assert mailer specific directory with simple form" do
|
||||
run_generator %w(-v mailer -b simple_form_for)
|
||||
assert_file "app/views/devise/mailer/confirmation_instructions.html.erb"
|
||||
assert_file "app/views/devise/mailer/reset_password_instructions.html.erb"
|
||||
assert_file "app/views/devise/mailer/unlock_instructions.html.erb"
|
||||
end
|
||||
|
||||
test "Assert specified directories with scope" do
|
||||
run_generator %w(users -v sessions)
|
||||
assert_file "app/views/users/sessions/new.html.erb"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require 'test_helper'
|
||||
|
||||
class DeviseHelperTest < ActionDispatch::IntegrationTest
|
||||
class DeviseHelperTest < Devise::IntegrationTest
|
||||
setup do
|
||||
model_labels = { models: { user: "the user" } }
|
||||
translations = {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user