mirror of
https://github.com/heartcombo/devise.git
synced 2026-01-09 23:58:06 -05:00
Compare commits
531 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f1a27b8f33 | ||
|
|
86c8e5455a | ||
|
|
dc37b82298 | ||
|
|
7d09b84ded | ||
|
|
53894e1e2b | ||
|
|
7e3ccbe835 | ||
|
|
8b8b6a866d | ||
|
|
222e606f89 | ||
|
|
83c47552e8 | ||
|
|
03851cab90 | ||
|
|
bb6d89bbc3 | ||
|
|
b061f985cf | ||
|
|
ecd7c17ffd | ||
|
|
a71a352822 | ||
|
|
c08c921b3f | ||
|
|
95399f1286 | ||
|
|
b5fd15c2e1 | ||
|
|
85e9dab370 | ||
|
|
8c9cf7d671 | ||
|
|
82da877863 | ||
|
|
275c480f89 | ||
|
|
477d9fbcba | ||
|
|
b88524027c | ||
|
|
55be93d5c4 | ||
|
|
c78c196423 | ||
|
|
d8656427fd | ||
|
|
41b1e87105 | ||
|
|
37678ac5ec | ||
|
|
7832d90077 | ||
|
|
3bd78cabd8 | ||
|
|
fff75b1904 | ||
|
|
97c0339f66 | ||
|
|
5b3f14df3b | ||
|
|
07cdba349d | ||
|
|
197e837e5b | ||
|
|
13bd4ce46a | ||
|
|
a43d1af23e | ||
|
|
cbf483143f | ||
|
|
cf5fbb9d65 | ||
|
|
d699b80254 | ||
|
|
ead414d0a7 | ||
|
|
cfdabf874a | ||
|
|
e954254abb | ||
|
|
93d4bb8361 | ||
|
|
edb0aac091 | ||
|
|
9549a32500 | ||
|
|
a949f9eca2 | ||
|
|
f4bbad6323 | ||
|
|
8a4d4864ea | ||
|
|
a8de38d0b0 | ||
|
|
18dc82c6b6 | ||
|
|
897c1c684e | ||
|
|
1ebcb09fc1 | ||
|
|
0f11226ced | ||
|
|
dada404a6b | ||
|
|
e4a37d6a5e | ||
|
|
66b93e8fd2 | ||
|
|
d9df632671 | ||
|
|
aa2d15aa33 | ||
|
|
0b55ebb150 | ||
|
|
7c11564613 | ||
|
|
c3f864f2b6 | ||
|
|
a29a30effc | ||
|
|
0af2722926 | ||
|
|
78efec09d5 | ||
|
|
1fdeadd113 | ||
|
|
a1464dbad7 | ||
|
|
dd2a66d00c | ||
|
|
1152fda687 | ||
|
|
fd0e929087 | ||
|
|
8b3e0e52f1 | ||
|
|
8ff080fb99 | ||
|
|
6bca228888 | ||
|
|
fd1e588645 | ||
|
|
024d9e6df7 | ||
|
|
aca8d3f34c | ||
|
|
e2030a740d | ||
|
|
27b745d04f | ||
|
|
f712d07b23 | ||
|
|
f8ea5e0942 | ||
|
|
89db0dd44d | ||
|
|
94e5a589b6 | ||
|
|
2dbb23f973 | ||
|
|
b71028dc73 | ||
|
|
f5aab14766 | ||
|
|
273c5e99c1 | ||
|
|
7ba37b5dc0 | ||
|
|
059d3856cf | ||
|
|
9dbd265fdd | ||
|
|
09ae63f822 | ||
|
|
c9becd3ea1 | ||
|
|
5a245b3d55 | ||
|
|
7d3b16fe73 | ||
|
|
fd85b25d29 | ||
|
|
5eebf74f69 | ||
|
|
5a11c6597c | ||
|
|
930b324c15 | ||
|
|
d952dea32b | ||
|
|
9a6ac7ab69 | ||
|
|
df43ee640d | ||
|
|
309b57f4ea | ||
|
|
cc839caba5 | ||
|
|
d734648b15 | ||
|
|
006400905b | ||
|
|
1e1e964d25 | ||
|
|
263e0b7692 | ||
|
|
01d4d0131b | ||
|
|
f41e4befde | ||
|
|
94fca31be8 | ||
|
|
19db459fca | ||
|
|
7693173ecd | ||
|
|
a0294cbae8 | ||
|
|
1cf008cbe3 | ||
|
|
87b84ffded | ||
|
|
035e56215d | ||
|
|
fa4d420fdb | ||
|
|
bd27bf7677 | ||
|
|
03d9ebb56e | ||
|
|
113b48a2ad | ||
|
|
6aed8f1c87 | ||
|
|
6d681c5b8a | ||
|
|
b3034292f2 | ||
|
|
4243791b47 | ||
|
|
b79c69140d | ||
|
|
ede004169c | ||
|
|
37dad2172b | ||
|
|
c8c471a128 | ||
|
|
f72ff72c0c | ||
|
|
dc3bfac876 | ||
|
|
426223dda0 | ||
|
|
5909d6a0c5 | ||
|
|
5570929b56 | ||
|
|
5ba6670164 | ||
|
|
589442b09b | ||
|
|
0c67cff2a0 | ||
|
|
9c3d5705b5 | ||
|
|
2f2662e7a5 | ||
|
|
99040535d7 | ||
|
|
582f00ed95 | ||
|
|
1d2f906af1 | ||
|
|
dfb8ff372d | ||
|
|
1e37e42239 | ||
|
|
ce1bd142e2 | ||
|
|
35015e5ceb | ||
|
|
03b56ffd1f | ||
|
|
065963f6d3 | ||
|
|
a71319a080 | ||
|
|
9ea7249368 | ||
|
|
301e24c06c | ||
|
|
6b108404ba | ||
|
|
0b661b6d7f | ||
|
|
3ab68a6896 | ||
|
|
97d8e39932 | ||
|
|
5c71c1cf19 | ||
|
|
dc8aa9ef83 | ||
|
|
ab54e1f66a | ||
|
|
0fd5493220 | ||
|
|
5c3f75d90a | ||
|
|
e8aabd4652 | ||
|
|
350bd188df | ||
|
|
7e9ba53d82 | ||
|
|
16208f7ad7 | ||
|
|
cc822e08aa | ||
|
|
c3880e52e4 | ||
|
|
a5aa03b983 | ||
|
|
06b7baabcc | ||
|
|
b7cffeed8c | ||
|
|
380df0121b | ||
|
|
611e0335cc | ||
|
|
22136a708b | ||
|
|
2a29e87eb9 | ||
|
|
ea9e8c0c9b | ||
|
|
58d61c290a | ||
|
|
bad6049d73 | ||
|
|
24b26026ef | ||
|
|
4629beecd7 | ||
|
|
f67793cb0d | ||
|
|
538c16cd00 | ||
|
|
3a26eea0cc | ||
|
|
f9ef2cd32e | ||
|
|
493ddbd99e | ||
|
|
f00d9c5eff | ||
|
|
95be78ac5e | ||
|
|
e9c263c326 | ||
|
|
1bace6df4e | ||
|
|
0439c35198 | ||
|
|
a816e538ab | ||
|
|
bbd117bd92 | ||
|
|
d448e7d841 | ||
|
|
6fcfba229d | ||
|
|
d525636423 | ||
|
|
d11402612f | ||
|
|
6079a025ca | ||
|
|
81f0c203a9 | ||
|
|
60822641cb | ||
|
|
fac02b58bc | ||
|
|
c9902f34d1 | ||
|
|
8b45c0a856 | ||
|
|
2a5ad4664b | ||
|
|
b98720d324 | ||
|
|
3f0b5fbd71 | ||
|
|
fa1034b04c | ||
|
|
13ed2183ee | ||
|
|
6fae1f60fd | ||
|
|
a46144e022 | ||
|
|
7f754caba3 | ||
|
|
2372823fd8 | ||
|
|
52282a5a26 | ||
|
|
96f55a7ac7 | ||
|
|
990dcc8eef | ||
|
|
76bff0d4de | ||
|
|
59f2767345 | ||
|
|
bba6562dcc | ||
|
|
f3aa5e40fb | ||
|
|
1e2dab3c0c | ||
|
|
bc8fc2d4e4 | ||
|
|
15b76e93d1 | ||
|
|
bc2a311a38 | ||
|
|
f19955705f | ||
|
|
e4902af15a | ||
|
|
ab9d856568 | ||
|
|
dd1d128333 | ||
|
|
a629654a15 | ||
|
|
08a8d7bf51 | ||
|
|
335d36088f | ||
|
|
0b9a95e294 | ||
|
|
98acc84111 | ||
|
|
261c01dfa3 | ||
|
|
dbda19f658 | ||
|
|
8067022d98 | ||
|
|
72ba56b071 | ||
|
|
30046f35d7 | ||
|
|
10451e9e38 | ||
|
|
ea7f15917f | ||
|
|
df3e711ee0 | ||
|
|
263e903046 | ||
|
|
f7bbac0ab9 | ||
|
|
9ebcb691b0 | ||
|
|
601e1d3dc9 | ||
|
|
7b0a8f9bdc | ||
|
|
dd36324756 | ||
|
|
1b5d0af824 | ||
|
|
edcca8cd3f | ||
|
|
c95ca15b49 | ||
|
|
055117e07a | ||
|
|
ebbabaea5b | ||
|
|
eba53f8f94 | ||
|
|
071f54ac59 | ||
|
|
8796c1c601 | ||
|
|
8c0f74f036 | ||
|
|
5a820262f9 | ||
|
|
3906456993 | ||
|
|
a1407565c8 | ||
|
|
a7c5a2e65d | ||
|
|
10ac4dbc35 | ||
|
|
6469cbc62a | ||
|
|
1961de6b5d | ||
|
|
ef4eb47d50 | ||
|
|
295088f9e8 | ||
|
|
4222afe3c7 | ||
|
|
79d89a3c20 | ||
|
|
8ad414b217 | ||
|
|
7b1418be3b | ||
|
|
7396c6911d | ||
|
|
673c707085 | ||
|
|
f21d05a235 | ||
|
|
1dd19c1a72 | ||
|
|
a8d9695324 | ||
|
|
99d539b9a7 | ||
|
|
179cb2c88a | ||
|
|
9629da863d | ||
|
|
4f76e6f577 | ||
|
|
0f3cef4091 | ||
|
|
7665cbf21d | ||
|
|
b9413ab316 | ||
|
|
a3bff7d6a2 | ||
|
|
7e54dc7903 | ||
|
|
fb1220af97 | ||
|
|
282c7e85ec | ||
|
|
bc15bb53dc | ||
|
|
a729e059de | ||
|
|
7c628f7689 | ||
|
|
6d65c28f1f | ||
|
|
31e4ef5e4b | ||
|
|
d38341b5e0 | ||
|
|
ff90d9da9c | ||
|
|
84c62ed034 | ||
|
|
e76ba05516 | ||
|
|
90d99b16f1 | ||
|
|
3cedba1de8 | ||
|
|
ccbf26be0a | ||
|
|
6448490de5 | ||
|
|
98651dae9d | ||
|
|
bf57ef400d | ||
|
|
27cae04446 | ||
|
|
430eadc1b2 | ||
|
|
e954737a92 | ||
|
|
191d5222e7 | ||
|
|
e77af4b40f | ||
|
|
da3c47259d | ||
|
|
c95575b284 | ||
|
|
7a5086a2be | ||
|
|
c3a665320e | ||
|
|
372dfecf05 | ||
|
|
68bd6809a7 | ||
|
|
7bfdd07a71 | ||
|
|
6bc93173f1 | ||
|
|
55af9f8a40 | ||
|
|
866b35d27c | ||
|
|
5374119f18 | ||
|
|
919404df53 | ||
|
|
fd07c74578 | ||
|
|
560961e3fc | ||
|
|
873e49ab66 | ||
|
|
0f8f786f9f | ||
|
|
7b3e267729 | ||
|
|
7264bb55b2 | ||
|
|
ed6dfed67f | ||
|
|
3488066031 | ||
|
|
bc9ea93f50 | ||
|
|
1920b79a0d | ||
|
|
9131570703 | ||
|
|
770c1a973f | ||
|
|
b7b21a0b72 | ||
|
|
4d91fb4910 | ||
|
|
4ce9d6f29a | ||
|
|
d2a4c503f7 | ||
|
|
a2700bc17f | ||
|
|
0a04d73883 | ||
|
|
502dae3c1f | ||
|
|
e9c766277d | ||
|
|
762f3907fa | ||
|
|
3698b64a10 | ||
|
|
2a6c160d39 | ||
|
|
795754cd60 | ||
|
|
517343ddb5 | ||
|
|
90a5e2f9af | ||
|
|
93180fbb6d | ||
|
|
04cb78947a | ||
|
|
5423f2d5cb | ||
|
|
51d15b7293 | ||
|
|
7a2e018df8 | ||
|
|
1fd4beb18a | ||
|
|
33d7644b4f | ||
|
|
5a98e4f4e8 | ||
|
|
82ae53dd75 | ||
|
|
07db04e773 | ||
|
|
6a8ee475fd | ||
|
|
767a7a7c21 | ||
|
|
a3b56f7eb1 | ||
|
|
5e1a998cde | ||
|
|
219fbc0056 | ||
|
|
dcee6413f4 | ||
|
|
e2895239d8 | ||
|
|
c8077c8d9f | ||
|
|
46c2d5a8f2 | ||
|
|
adb127bb3e | ||
|
|
42f0285278 | ||
|
|
13ef23f517 | ||
|
|
0bf28b19ab | ||
|
|
29a0af78bc | ||
|
|
cf487c771e | ||
|
|
7e711089a8 | ||
|
|
1c81a40a76 | ||
|
|
2b64c6d951 | ||
|
|
dba8f91f99 | ||
|
|
8e70e71143 | ||
|
|
f43a7c4f24 | ||
|
|
4e56d92ed8 | ||
|
|
5645d733ba | ||
|
|
42b07f1f47 | ||
|
|
e75354b3b0 | ||
|
|
80122856c4 | ||
|
|
308238ab42 | ||
|
|
e937cf78cf | ||
|
|
2ae2fdc9f8 | ||
|
|
3184834d72 | ||
|
|
8ef5534d92 | ||
|
|
41bb96be5d | ||
|
|
b37055fa47 | ||
|
|
515b727f52 | ||
|
|
77d6d1e8c2 | ||
|
|
04b614ce10 | ||
|
|
62e11ddbe4 | ||
|
|
8e3ab5921f | ||
|
|
1d87997647 | ||
|
|
b58e0ef991 | ||
|
|
db959da247 | ||
|
|
6199252011 | ||
|
|
40c0a7b50b | ||
|
|
422bc4aaa6 | ||
|
|
225c89fbf1 | ||
|
|
76281ff15c | ||
|
|
8b54ff699f | ||
|
|
7d160650b8 | ||
|
|
803e46cda7 | ||
|
|
004fe2ad12 | ||
|
|
09baf2091e | ||
|
|
135a94b4f7 | ||
|
|
a41d185768 | ||
|
|
c3432e57b1 | ||
|
|
a8d88d193e | ||
|
|
471e4d6e72 | ||
|
|
14fec4cfb3 | ||
|
|
4bcd1c6fcd | ||
|
|
84e1a89c44 | ||
|
|
e0162df465 | ||
|
|
7631456047 | ||
|
|
2bc51ab2bd | ||
|
|
d23ecef831 | ||
|
|
c0017ce76d | ||
|
|
30f9da9d71 | ||
|
|
e242ca0937 | ||
|
|
17596b0dc6 | ||
|
|
8e87a2d80d | ||
|
|
4964f53a42 | ||
|
|
6250fa8529 | ||
|
|
944e1c0378 | ||
|
|
4f446241a4 | ||
|
|
97659a1193 | ||
|
|
0bcf71f8df | ||
|
|
ab3bb9cf4d | ||
|
|
69126a31db | ||
|
|
03e3803cff | ||
|
|
58f8c7c613 | ||
|
|
acd1c76c3b | ||
|
|
4c8cc5e3f3 | ||
|
|
72bb33f962 | ||
|
|
2e61e52520 | ||
|
|
75490d0375 | ||
|
|
0fbe4cb6b9 | ||
|
|
d2b3f49384 | ||
|
|
136992b8df | ||
|
|
a130f848f2 | ||
|
|
e10bc9e3c0 | ||
|
|
d56741ca4f | ||
|
|
92c9ed2d6c | ||
|
|
50a5ad54ce | ||
|
|
9dcb44ba61 | ||
|
|
8bdc4b544f | ||
|
|
e763f843c4 | ||
|
|
b5732e31c6 | ||
|
|
ea24ffdd51 | ||
|
|
56f7fbf2d1 | ||
|
|
89b53ea39c | ||
|
|
9cc69277bc | ||
|
|
7e79ed6d4e | ||
|
|
b5190d8df2 | ||
|
|
b03c93c4fe | ||
|
|
8e12ddf7ed | ||
|
|
4fd866d113 | ||
|
|
a59410a254 | ||
|
|
b1a27ad633 | ||
|
|
4a3ad7f348 | ||
|
|
89e4ab8a45 | ||
|
|
fd8e34650e | ||
|
|
e26c8ce499 | ||
|
|
64cf8a4534 | ||
|
|
ae976f60ca | ||
|
|
f152860bc5 | ||
|
|
40153b7422 | ||
|
|
fdfe6a8340 | ||
|
|
79c100008a | ||
|
|
f132c7891b | ||
|
|
bdad984ace | ||
|
|
a229627a54 | ||
|
|
0b598cf132 | ||
|
|
0e657eece1 | ||
|
|
b6cf1df659 | ||
|
|
29afe2d21c | ||
|
|
a722c6236c | ||
|
|
14aedc416a | ||
|
|
9fe0cb4954 | ||
|
|
2a5669967f | ||
|
|
13376d22de | ||
|
|
6b21531916 | ||
|
|
4a4dcb30ef | ||
|
|
2cfa58b433 | ||
|
|
c6dd846718 | ||
|
|
7a2d76d002 | ||
|
|
e5a8febe3b | ||
|
|
60809719b8 | ||
|
|
ee6a8ab93a | ||
|
|
c3d92095f8 | ||
|
|
460beae671 | ||
|
|
fa6c8ab321 | ||
|
|
d02f86bef5 | ||
|
|
0d74c1b4f0 | ||
|
|
8f3539c14f | ||
|
|
3d5e692c2c | ||
|
|
cb622e99d8 | ||
|
|
567d59e48a | ||
|
|
f89f71262d | ||
|
|
5e2ee5eb6a | ||
|
|
34a54dac2d | ||
|
|
e329930a82 | ||
|
|
3940846d79 | ||
|
|
c608fbe89e | ||
|
|
8db00eedea | ||
|
|
0e904dda79 | ||
|
|
e4af6adaf7 | ||
|
|
e1c7c49a0c | ||
|
|
bd9f148d24 | ||
|
|
f009011179 | ||
|
|
5adb854aa5 | ||
|
|
1f51524bae | ||
|
|
23f8dbed80 | ||
|
|
140acfe4cc | ||
|
|
cb2cb2cff7 | ||
|
|
30300fc6b9 | ||
|
|
de8982563a | ||
|
|
e7154b3af9 | ||
|
|
39360dc419 | ||
|
|
eeb61929ac | ||
|
|
56fd7031e5 | ||
|
|
425fe7f22d | ||
|
|
ed51fc7636 | ||
|
|
d23a7ca8d5 | ||
|
|
1b1dc2a429 | ||
|
|
be2aeee70f | ||
|
|
8a3deb98cd | ||
|
|
e4902143f8 | ||
|
|
d3a374777b | ||
|
|
5b94d9b803 | ||
|
|
b6652abc7c | ||
|
|
97f0bacfa0 | ||
|
|
210bc6aa66 | ||
|
|
8170d5e340 | ||
|
|
6225902034 | ||
|
|
0487e9eafe | ||
|
|
73669e09c8 |
6
.gitignore
vendored
6
.gitignore
vendored
@@ -1,5 +1,5 @@
|
||||
**/*/log/*
|
||||
**/*/tmp/*
|
||||
test/rails_app/log/*
|
||||
test/rails_app/tmp/*
|
||||
*~
|
||||
coverage/*
|
||||
*.sqlite3
|
||||
@@ -7,4 +7,4 @@ coverage/*
|
||||
rdoc/*
|
||||
pkg
|
||||
log
|
||||
test/tmp/*
|
||||
test/tmp/*
|
||||
|
||||
17
.travis.yml
17
.travis.yml
@@ -1 +1,16 @@
|
||||
script: "rake test"
|
||||
script: "bundle exec rake test"
|
||||
before_install: gem update --system
|
||||
rvm:
|
||||
- 1.8.7
|
||||
- 1.9.2
|
||||
- 1.9.3
|
||||
- ree
|
||||
gemfile:
|
||||
- gemfiles/Gemfile.rails-3.1.x
|
||||
- Gemfile
|
||||
notifications:
|
||||
recipients:
|
||||
- jose.valim@plataformatec.com.br
|
||||
- carlos@plataformatec.com.br
|
||||
- rodrigo.flores@plataformatec.com.br
|
||||
- rafael.franca@plataformatec.com.br
|
||||
|
||||
298
CHANGELOG.rdoc
298
CHANGELOG.rdoc
@@ -1,3 +1,219 @@
|
||||
== 2.0.1
|
||||
|
||||
Notes: https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0
|
||||
|
||||
* enhancements
|
||||
* Improved error messages on deprecation warnings
|
||||
* Hide Devise's internal generators from `rails g` command
|
||||
|
||||
* bug fix
|
||||
* Removed tmp and log files from gem
|
||||
|
||||
== 2.0.0
|
||||
|
||||
* enhancements
|
||||
* Add support for e-mail reconfirmation on change (by @Mandaryn and @heimidal)
|
||||
* Redirect users to sign in page after unlock (by @nashby)
|
||||
* Redirect to the previous URL on timeout
|
||||
* Inherit from the same Devise parent controller (by @sj26)
|
||||
* Allow parent_controller to be customizable via Devise.parent_controller, useful for engines
|
||||
* Allow router_name to be customizable via Devise.router_name, useful for engines
|
||||
* Allow alternate ORMs to run compatibility setup code before Authenticatable is included (by @jm81)
|
||||
|
||||
* deprecation
|
||||
* Devise now only supports Rails 3.1 forward
|
||||
* Devise.confirm_within was deprecated in favor Devise.allow_unconfirmed_access_for
|
||||
* Devise.stateless_token= is deprecated in favor of appending :token_auth to Devise.skip_session_storage
|
||||
* Usage of Devise.apply_schema is deprecated
|
||||
* Usage of Devise migration helpers are deprecated
|
||||
* Usage of Devise.remember_across_browsers was deprecated
|
||||
* Usage of rememberable with remember_token was removed
|
||||
* Usage of recoverable without reset_password_sent_at was removed
|
||||
* Usage of Devise.case_insensitive_keys equals to false was removed
|
||||
* Move devise/shared/_links.erb to devise/_links.erb
|
||||
* Deprecated support of nested devise_for blocks
|
||||
* Deprecated support to devise.registrations.reasons and devise.registrations.inactive_signed_up in favor of devise.registrations.signed_up_but_*
|
||||
|
||||
== 1.5.3
|
||||
|
||||
* bug fix
|
||||
* Ensure delegator converts scope to symbol (by @dmitriy-kiriyenko)
|
||||
* Ensure passing :format => false to devise_for is not permanent
|
||||
* Ensure path checker does not check invalid routes
|
||||
|
||||
== 1.5.2
|
||||
|
||||
* enhancements
|
||||
* Add support for Rails 3.1 new mass assignment conventions (by @kirs)
|
||||
* Add timeout_in method to Timeoutable, it can be overridden in a model (by @lest)
|
||||
|
||||
* bug fix
|
||||
* OmniAuth error message now shows the proper option (:strategy_class instead of :klass)
|
||||
|
||||
== 1.5.1
|
||||
|
||||
* bug fix
|
||||
* Devise should not attempt to load OmniAuth strategies. Strategies should be loaded before hand by the developer or explicitly given to Devise.
|
||||
|
||||
== 1.5.0
|
||||
|
||||
* enhancements
|
||||
* Timeoutable also skips tracking if skip_trackable is given
|
||||
* devise_for now accepts :failure_app as an option
|
||||
* Models can select the proper mailer via devise_mailer method (by @locomotivecms)
|
||||
* Migration generator now uses the change method (by @nashby)
|
||||
* Support to markerb templates on the mailer generator (by @sbounmy)
|
||||
* Support for Omniauth 1.0 (older versions are no longer supported) (by @TamiasSibiricus)
|
||||
|
||||
* bug fix
|
||||
* Allow idempotent API requests
|
||||
* Fix bug where logs did not show 401 as status code
|
||||
* Change paranoid settings to behave as success instead of as failure
|
||||
* Fix bug where activation messages were shown first than the credentials error message
|
||||
* Instance variables are expired after sign out
|
||||
|
||||
* deprecation
|
||||
* redirect_location is deprecated, please use after_sign_in_path_for
|
||||
* after_sign_in_path_for now redirects to session[scope_return_to] if any value is stored in it
|
||||
|
||||
== 1.4.9
|
||||
|
||||
* bug fix
|
||||
* url helpers were not being set under some circumstances
|
||||
|
||||
== 1.4.8
|
||||
|
||||
* enhancements
|
||||
* Add docs for assets pipeline and Heroku
|
||||
|
||||
* bug fix
|
||||
* confirmation_url was not being set under some circumstances
|
||||
|
||||
== 1.4.7
|
||||
|
||||
* bug fix
|
||||
* Fix backward incompatible change from 1.4.6 for those using custom controllers
|
||||
|
||||
== 1.4.6
|
||||
|
||||
* enhancements
|
||||
* Allow devise_for :skip => :all
|
||||
* Allow options to be passed to authenticate_user!
|
||||
* Allow --skip-routes to devise generator
|
||||
* Add allow_params_authentication! to make it explicit when params authentication is allowed in a controller
|
||||
|
||||
== 1.4.5
|
||||
|
||||
* bug fix
|
||||
* Failure app tries the root path if a session one does not exist
|
||||
* No need to finalize Devise helpers all the time (by @bradleypriest)
|
||||
* Reset password shows proper message if user is not active
|
||||
* `clean_up_passwords` sets the accessors to nil to skip validations
|
||||
|
||||
== 1.4.4
|
||||
|
||||
* bug fix
|
||||
* Do not always skip helpers, instead provide :skip_helpers as option to trigger it manually
|
||||
|
||||
== 1.4.3
|
||||
|
||||
* enhancements
|
||||
* Improve Rails 3.1 compatibility
|
||||
* Use serialize_into_session and serialize_from_session in Warden serialize to improve extensibility
|
||||
|
||||
* bug fix
|
||||
* Generator properly generates a change_table migration if a model already exists
|
||||
* Properly deprecate setup_mail
|
||||
* Fix encoding issues with email regexp
|
||||
* Only generate helpers for the used mappings
|
||||
* Wrap :action constraints in the proper hash
|
||||
|
||||
* deprecations
|
||||
* Loosened the used email regexp to simply assert the existent of "@". If someone relies on a more strict regexp, they may use https://github.com/SixArm/sixarm_ruby_email_address_validation
|
||||
|
||||
== 1.4.2
|
||||
|
||||
* bug fix
|
||||
* Provide a more robust behavior to serializers and add :force_except option
|
||||
|
||||
== 1.4.1
|
||||
|
||||
* enhancements
|
||||
* Add :defaults and :format support on router
|
||||
* Add simple form generators
|
||||
* Better localization for devise_error_messages! (by @zedtux)
|
||||
|
||||
* bug fix
|
||||
* Ensure to_xml is properly white listened
|
||||
* Ensure handle_unverified_request clean up any cached signed-in user
|
||||
|
||||
== 1.4.0
|
||||
|
||||
* enhancements
|
||||
* Added authenticated and unauthenticated to the router to route the used based on his status (by @sj26)
|
||||
* Improve e-mail regexp (by @rodrigoflores)
|
||||
* Add strip_whitespace_keys and default to e-mail (by @swrobel)
|
||||
* Do not run format and uniqueness validations on e-mail if it hasn't changed (by @Thibaut)
|
||||
* Added update_without_password to update models but not allowing the password to change (by @fschwahn)
|
||||
* Added config.paranoid, check the generator for more information (by @rodrigoflores)
|
||||
|
||||
* bug fix
|
||||
* password_required? should not affect length validation
|
||||
* User cannot access sign up and similar pages if he is already signed in through a cookie or token
|
||||
* Do not convert booleans to strings on finders (by @xavier)
|
||||
* Run validations even if current_password fails (by @crx)
|
||||
* Devise now honors routes constraints (by @macmartine)
|
||||
* Do not return the user resource when requesting instructions (by @rodrigoflores)
|
||||
|
||||
== 1.3.4
|
||||
|
||||
* bug fix
|
||||
* Do not add formats if html or "*/*"
|
||||
|
||||
== 1.3.3
|
||||
|
||||
* bug fix
|
||||
* Explicitly mark the token as expired if so
|
||||
|
||||
== 1.3.2
|
||||
|
||||
* bug fix
|
||||
* Fix another regression related to reset_password_sent_at (by @alexdreher)
|
||||
|
||||
== 1.3.1
|
||||
|
||||
* enhancements
|
||||
* Improve failure_app responses (by @indirect)
|
||||
* sessions/new and registrations/new also respond to xml and json now
|
||||
|
||||
* bug fix
|
||||
* Fix a regression that occurred if reset_password_sent_at is not present (by @stevehodgkiss)
|
||||
|
||||
== 1.3.0
|
||||
|
||||
* enhancements
|
||||
* All controllers can now handle different mime types than html using Responders (by @sikachu)
|
||||
* Added reset_password_within as configuration option to send the token for recovery (by @jdguyot)
|
||||
* Bump password length to 128 characters (by @k33l0r)
|
||||
* Add :only as option to devise_for (by @timoschilling)
|
||||
* Allow to override path after sending password instructions (by @irohiroki)
|
||||
* require_no_authentication has its own flash message (by @jackdempsey)
|
||||
|
||||
* bug fix
|
||||
* Fix a bug where configuration options were being included too late
|
||||
* Ensure Devise::TestHelpers can be used to tests Devise internal controllers (by @jwilger)
|
||||
* valid_password? should not choke on empty passwords (by @mikel)
|
||||
* Calling devise more than once does not include previously added modules anymore
|
||||
* downcase_keys before validation
|
||||
|
||||
* backward incompatible changes
|
||||
* authentication_keys are no longer considered when creating the e-mail validations, the previous behavior was buggy. You must double check if you were relying on such behavior.
|
||||
|
||||
== 1.2.1
|
||||
|
||||
* enhancements
|
||||
* Improve update path messages
|
||||
|
||||
== 1.2.0
|
||||
|
||||
* bug fix
|
||||
@@ -13,16 +229,16 @@
|
||||
|
||||
* bug fix
|
||||
* Fix an issue causing infinite redirects in production
|
||||
* rails g destroy works properly with devise generators (by github.com/andmej)
|
||||
* before_failure callbacks should work on test helpers (by github.com/twinge)
|
||||
* rememberable cookie now is httponly by default (by github.com/JamesFerguson)
|
||||
* Add missing confirmation_keys (by github.com/JohnPlummer)
|
||||
* rails g destroy works properly with devise generators (by @andmej)
|
||||
* before_failure callbacks should work on test helpers (by @twinge)
|
||||
* rememberable cookie now is httponly by default (by @JamesFerguson)
|
||||
* Add missing confirmation_keys (by @JohnPlummer)
|
||||
* Ensure after_* hooks are called on RegistrationsController
|
||||
* When using database_authenticatable Devise will now only create an email field when appropriate (if using default authentication_keys or custom authentication_keys with email included)
|
||||
* Ensure stateless token does not trigger timeout (by github.com/pixelauthority)
|
||||
* Ensure stateless token does not trigger timeout (by @pixelauthority)
|
||||
* Implement handle_unverified_request for Rails 3.0.4 compatibility and improve FailureApp reliance on symbols
|
||||
* Consider namespaces while generating routes
|
||||
* Custom failure apps no longer ignored in test mode (by github.com/jaghion)
|
||||
* Custom failure apps no longer ignored in test mode (by @jaghion)
|
||||
* Do not depend on ActiveModel::Dirty
|
||||
* Manual sign_in now triggers remember token
|
||||
* Be sure to halt strategies on failures
|
||||
@@ -31,7 +247,7 @@
|
||||
* Ensure there is no Mongoid injection
|
||||
|
||||
* deprecations
|
||||
* Deprecated anybody_signed_in? in favor of signed_in? (by github.com/gavinhughes)
|
||||
* Deprecated anybody_signed_in? in favor of signed_in? (by @gavinhughes)
|
||||
* Removed --haml and --slim view templates
|
||||
* Devise::OmniAuth helpers were deprecated and removed in favor of Omniauth.config.test_mode
|
||||
|
||||
@@ -44,11 +260,11 @@
|
||||
* enhancements
|
||||
* Added OmniAuth support
|
||||
* Added ORM adapter to abstract ORM iteraction
|
||||
* sign_out_via is available in the router to configure the method used for sign out (by github.com/martinrehfeld)
|
||||
* Improved Ajax requests handling in failure app (by github.com/spastorino)
|
||||
* sign_out_via is available in the router to configure the method used for sign out (by @martinrehfeld)
|
||||
* Improved Ajax requests handling in failure app (by @spastorino)
|
||||
* Added request_keys to easily use request specific values (like subdomain) in authentication
|
||||
* Increased the size of friendly_token to 60 characters (reduces the chances of a successful brute attack)
|
||||
* Ensure the friendly token does not include "_" or "-" since some e-mails may not autolink it properly (by github.com/rymai)
|
||||
* Ensure the friendly token does not include "_" or "-" since some e-mails may not autolink it properly (by @rymai)
|
||||
* Extracted encryptors into :encryptable for better bcrypt support
|
||||
* :rememberable is now able to use salt as token if no remember_token is provided
|
||||
* Store the salt in session and expire the session if the user changes his password
|
||||
@@ -57,7 +273,7 @@
|
||||
* Sign up now check if the user is active or not and redirect him accordingly setting the inactive_signed_up message
|
||||
* Use ActiveModel#to_key instead of #id
|
||||
* sign_out_all_scopes now destroys the whole session
|
||||
* Added case_insensitive_keys that automatically downcases the given keys, by default downcases only e-mail (by github.com/adahl)
|
||||
* Added case_insensitive_keys that automatically downcases the given keys, by default downcases only e-mail (by @adahl)
|
||||
|
||||
* default behavior changes
|
||||
* sign_out_all_scopes defaults to true as security measure
|
||||
@@ -66,12 +282,12 @@
|
||||
|
||||
* bugfix
|
||||
* after_sign_in_path_for always receives a resource
|
||||
* Do not execute Warden::Callbacks on Devise::TestHelpers (by github.com/sgronblo)
|
||||
* Allow password recovery and account unlocking to change used keys (by github.com/RStankov)
|
||||
* Do not execute Warden::Callbacks on Devise::TestHelpers (by @sgronblo)
|
||||
* Allow password recovery and account unlocking to change used keys (by @RStankov)
|
||||
* FailureApp now properly handles nil request.format
|
||||
* Fix a bug causing FailureApp to return with HTTP Auth Headers for IE7
|
||||
* Ensure namespaces has proper scoped views
|
||||
* Ensure Devise does not set empty flash messages (by github.com/sxross)
|
||||
* Ensure Devise does not set empty flash messages (by @sxross)
|
||||
|
||||
== 1.1.6
|
||||
|
||||
@@ -96,11 +312,11 @@
|
||||
|
||||
* bugfix
|
||||
* Add reply-to to e-mail headers by default
|
||||
* Updated the views generator to respect the rails :template_engine option (by github.com/fredwu)
|
||||
* Updated the views generator to respect the rails :template_engine option (by @fredwu)
|
||||
* Check the type of HTTP Authentication before using Basic headers
|
||||
* Avoid invalid_salt errors by checking salt presence (by github.com/thibaudgg)
|
||||
* Forget user deletes the right cookie before logout, not remembering the user anymore (by github.com/emtrane)
|
||||
* Fix for failed first-ever logins on PostgreSQL where column default is nil (by github.com/bensie)
|
||||
* Avoid invalid_salt errors by checking salt presence (by @thibaudgg)
|
||||
* Forget user deletes the right cookie before logout, not remembering the user anymore (by @emtrane)
|
||||
* Fix for failed first-ever logins on PostgreSQL where column default is nil (by @bensie)
|
||||
* :default options is now honored in migrations
|
||||
|
||||
== 1.1.2
|
||||
@@ -116,16 +332,16 @@
|
||||
== 1.1.0
|
||||
|
||||
* enhancements
|
||||
* Rememberable module allows user to be remembered across browsers and is enabled by default (by github.com/trevorturk)
|
||||
* Rememberable module allows you to activate the period the remember me token is extended (by github.com/trevorturk)
|
||||
* Rememberable module allows user to be remembered across browsers and is enabled by default (by @trevorturk)
|
||||
* Rememberable module allows you to activate the period the remember me token is extended (by @trevorturk)
|
||||
* devise_for can now be used together with scope method in routes but with a few limitations (check the documentation)
|
||||
* Support `as` or `devise_scope` in the router to specify controller access scope
|
||||
* HTTP Basic Auth can now be disabled/enabled for xhr(ajax) requests using http_authenticatable_on_xhr option (by github.com/pellja)
|
||||
* HTTP Basic Auth can now be disabled/enabled for xhr(ajax) requests using http_authenticatable_on_xhr option (by @pellja)
|
||||
|
||||
* bug fix
|
||||
* Fix a bug in Devise::TestHelpers where current_user was returning a Response object for non active accounts
|
||||
* Devise should respect script_name and path_info contracts
|
||||
* Fix a bug when accessing a path with (.:format) (by github.com/klacointe)
|
||||
* Fix a bug when accessing a path with (.:format) (by @klacointe)
|
||||
* Do not add unlock routes unless unlock strategy is email or both
|
||||
* Email should be case insensitive
|
||||
* Store classes as string in session, to avoid serialization and stale data issues
|
||||
@@ -136,10 +352,10 @@
|
||||
== 1.1.rc2
|
||||
|
||||
* enhancements
|
||||
* Allow to set cookie domain for the remember token. (by github.com/mantas)
|
||||
* Allow to set cookie domain for the remember token. (by @mantas)
|
||||
* Added navigational formats to specify when it should return a 302 and when a 401.
|
||||
* Added authenticate(scope) support in routes (by github.com/wildchild)
|
||||
* Added after_update_path_for to registrations controller (by github.com/thedelchop)
|
||||
* Added authenticate(scope) support in routes (by @wildchild)
|
||||
* Added after_update_path_for to registrations controller (by @thedelchop)
|
||||
* Allow the mailer object to be replaced through config.mailer = "MyOwnMailer"
|
||||
|
||||
* bug fix
|
||||
@@ -187,10 +403,10 @@
|
||||
|
||||
* enhancements
|
||||
* Support for latest MongoMapper
|
||||
* Added anybody_signed_in? helper (by github.com/SSDany)
|
||||
* Added anybody_signed_in? helper (by @SSDany)
|
||||
|
||||
* bug fix
|
||||
* confirmation_required? is properly honored on active? calls. (by github.com/paulrosania)
|
||||
* confirmation_required? is properly honored on active? calls. (by @paulrosania)
|
||||
|
||||
== 1.0.7
|
||||
|
||||
@@ -231,7 +447,7 @@
|
||||
== 1.0.2
|
||||
|
||||
* enhancements
|
||||
* Allows you set mailer content type (by github.com/glennr)
|
||||
* Allows you set mailer content type (by @glennr)
|
||||
|
||||
* bug fix
|
||||
* Uses the same content type as request on http authenticatable 401 responses
|
||||
@@ -264,12 +480,12 @@
|
||||
|
||||
* enhancements
|
||||
* Added gemspec to repo
|
||||
* Added token authenticatable (by github.com/grimen)
|
||||
* Added token authenticatable (by @grimen)
|
||||
|
||||
== 0.9.1
|
||||
|
||||
* bug fix
|
||||
* Allow bigger salt size (by github.com/jgeiger)
|
||||
* Allow bigger salt size (by @jgeiger)
|
||||
* Fix relative url root
|
||||
|
||||
== 0.9.0
|
||||
@@ -279,11 +495,11 @@
|
||||
* :success and :failure flash messages are now :notice and :alert
|
||||
|
||||
* enhancements
|
||||
* Added devise lockable (by github.com/mhfs)
|
||||
* Added devise lockable (by @mhfs)
|
||||
* Warden 0.9.0 compatibility
|
||||
* Mongomapper 0.6.10 compatibility
|
||||
* Added Devise.add_module as hooks for extensions (by github.com/grimen)
|
||||
* Ruby 1.9.1 compatibility (by github.com/grimen)
|
||||
* Added Devise.add_module as hooks for extensions (by @grimen)
|
||||
* Ruby 1.9.1 compatibility (by @grimen)
|
||||
|
||||
* bug fix
|
||||
* Accept path prefix not starting with slash
|
||||
@@ -292,10 +508,10 @@
|
||||
== 0.8.2
|
||||
|
||||
* enhancements
|
||||
* Allow Devise.mailer_sender to be a proc (by github.com/grimen)
|
||||
* Allow Devise.mailer_sender to be a proc (by @grimen)
|
||||
|
||||
* bug fix
|
||||
* Fix bug with passenger, update is required to anyone deploying on passenger (by github.com/dvdpalm)
|
||||
* Fix bug with passenger, update is required to anyone deploying on passenger (by @dvdpalm)
|
||||
|
||||
== 0.8.1
|
||||
|
||||
@@ -312,11 +528,11 @@
|
||||
* enhancements
|
||||
* Warden 0.8.0 compatibility
|
||||
* Add an easy for map.connect "sign_in", :controller => "sessions", :action => "new" to work
|
||||
* Added :bcrypt encryptor (by github.com/capotej)
|
||||
* Added :bcrypt encryptor (by @capotej)
|
||||
|
||||
* bug fix
|
||||
* sign_in_count is also increased when user signs in via password change, confirmation, etc..
|
||||
* More DataMapper compatibility (by github.com/lancecarlson)
|
||||
* More DataMapper compatibility (by @lancecarlson)
|
||||
|
||||
* deprecation
|
||||
* Removed DeviseMailer.sender
|
||||
@@ -356,7 +572,7 @@
|
||||
== 0.7.1
|
||||
|
||||
* enhancements
|
||||
* Small enhancements for other plugins compatibility (by github.com/grimen)
|
||||
* Small enhancements for other plugins compatibility (by @grimen)
|
||||
|
||||
== 0.7.0
|
||||
|
||||
@@ -450,9 +666,9 @@
|
||||
* Fixed a bug where remember me module was not working properly
|
||||
|
||||
* enhancements
|
||||
* Moved encryption strategy into the Encryptors module to allow several algorithms (by github.com/mhfs)
|
||||
* Implemented encryptors for Clearance, Authlogic and Restful-Authentication (by github.com/mhfs)
|
||||
* Added support for MongoMapper (by github.com/shingara)
|
||||
* Moved encryption strategy into the Encryptors module to allow several algorithms (by @mhfs)
|
||||
* Implemented encryptors for Clearance, Authlogic and Restful-Authentication (by @mhfs)
|
||||
* Added support for MongoMapper (by @shingara)
|
||||
|
||||
== 0.4.3
|
||||
|
||||
|
||||
28
Gemfile
28
Gemfile
@@ -2,28 +2,34 @@ source "http://rubygems.org"
|
||||
|
||||
gemspec
|
||||
|
||||
gem "rails", "~> 3.0.4"
|
||||
gem "oa-oauth", '~> 0.2.0', :require => "omniauth/oauth"
|
||||
gem "oa-openid", '~> 0.2.0', :require => "omniauth/openid"
|
||||
gem "rails", "~> 3.2.0"
|
||||
gem "omniauth", "~> 1.0.0"
|
||||
gem "omniauth-oauth2", "~> 1.0.0"
|
||||
gem "rdoc"
|
||||
|
||||
group :test do
|
||||
gem "omniauth-facebook"
|
||||
gem "omniauth-openid", "~> 1.0.1"
|
||||
gem "webrat", "0.7.2", :require => false
|
||||
gem "mocha", :require => false
|
||||
|
||||
platforms :mri_18 do
|
||||
gem "ruby-debug", ">= 0.10.3"
|
||||
end
|
||||
end
|
||||
|
||||
platforms :jruby do
|
||||
gem 'activerecord-jdbcsqlite3-adapter'
|
||||
gem "activerecord-jdbc-adapter"
|
||||
gem "activerecord-jdbcsqlite3-adapter"
|
||||
gem "jruby-openssl"
|
||||
end
|
||||
|
||||
platforms :ruby do
|
||||
group :test do
|
||||
gem "sqlite3-ruby"
|
||||
gem "ruby-debug", ">= 0.10.3" if RUBY_VERSION < '1.9'
|
||||
end
|
||||
gem "sqlite3-ruby"
|
||||
|
||||
group :mongoid do
|
||||
gem "mongo", "1.1.2"
|
||||
gem "mongoid", "2.0.0.beta.20"
|
||||
gem "bson_ext", "1.2.1"
|
||||
gem "mongo", "~> 1.3.0"
|
||||
gem "mongoid", "~> 2.0"
|
||||
gem "bson_ext", "~> 1.3.0"
|
||||
end
|
||||
end
|
||||
|
||||
239
Gemfile.lock
239
Gemfile.lock
@@ -1,158 +1,167 @@
|
||||
PATH
|
||||
remote: .
|
||||
specs:
|
||||
devise (1.2.rc2)
|
||||
bcrypt-ruby (~> 2.1.2)
|
||||
devise (2.0.0)
|
||||
bcrypt-ruby (~> 3.0)
|
||||
orm_adapter (~> 0.0.3)
|
||||
warden (~> 1.0.3)
|
||||
railties (~> 3.1)
|
||||
warden (~> 1.1)
|
||||
|
||||
GEM
|
||||
remote: http://rubygems.org/
|
||||
specs:
|
||||
abstract (1.0.0)
|
||||
actionmailer (3.0.4)
|
||||
actionpack (= 3.0.4)
|
||||
mail (~> 2.2.15)
|
||||
actionpack (3.0.4)
|
||||
activemodel (= 3.0.4)
|
||||
activesupport (= 3.0.4)
|
||||
builder (~> 2.1.2)
|
||||
erubis (~> 2.6.6)
|
||||
i18n (~> 0.4)
|
||||
rack (~> 1.2.1)
|
||||
rack-mount (~> 0.6.13)
|
||||
rack-test (~> 0.5.7)
|
||||
tzinfo (~> 0.3.23)
|
||||
activemodel (3.0.4)
|
||||
activesupport (= 3.0.4)
|
||||
builder (~> 2.1.2)
|
||||
i18n (~> 0.4)
|
||||
activerecord (3.0.4)
|
||||
activemodel (= 3.0.4)
|
||||
activesupport (= 3.0.4)
|
||||
arel (~> 2.0.2)
|
||||
tzinfo (~> 0.3.23)
|
||||
activerecord-jdbc-adapter (1.1.1)
|
||||
activerecord-jdbcsqlite3-adapter (1.1.1)
|
||||
activerecord-jdbc-adapter (= 1.1.1)
|
||||
jdbc-sqlite3 (~> 3.6.0)
|
||||
activeresource (3.0.4)
|
||||
activemodel (= 3.0.4)
|
||||
activesupport (= 3.0.4)
|
||||
activesupport (3.0.4)
|
||||
addressable (2.2.4)
|
||||
arel (2.0.8)
|
||||
bcrypt-ruby (2.1.4)
|
||||
bson (1.2.1)
|
||||
bson_ext (1.2.1)
|
||||
builder (2.1.2)
|
||||
columnize (0.3.2)
|
||||
erubis (2.6.6)
|
||||
abstract (>= 1.0.0)
|
||||
faraday (0.5.7)
|
||||
addressable (~> 2.2.4)
|
||||
multipart-post (~> 1.1.0)
|
||||
actionmailer (3.2.0)
|
||||
actionpack (= 3.2.0)
|
||||
mail (~> 2.4.0)
|
||||
actionpack (3.2.0)
|
||||
activemodel (= 3.2.0)
|
||||
activesupport (= 3.2.0)
|
||||
builder (~> 3.0.0)
|
||||
erubis (~> 2.7.0)
|
||||
journey (~> 1.0.0)
|
||||
rack (~> 1.4.0)
|
||||
rack-cache (~> 1.1)
|
||||
rack-test (~> 0.6.1)
|
||||
sprockets (~> 2.1.2)
|
||||
activemodel (3.2.0)
|
||||
activesupport (= 3.2.0)
|
||||
builder (~> 3.0.0)
|
||||
activerecord (3.2.0)
|
||||
activemodel (= 3.2.0)
|
||||
activesupport (= 3.2.0)
|
||||
arel (~> 3.0.0)
|
||||
tzinfo (~> 0.3.29)
|
||||
activeresource (3.2.0)
|
||||
activemodel (= 3.2.0)
|
||||
activesupport (= 3.2.0)
|
||||
activesupport (3.2.0)
|
||||
i18n (~> 0.6)
|
||||
multi_json (~> 1.0)
|
||||
addressable (2.2.6)
|
||||
arel (3.0.0)
|
||||
bcrypt-ruby (3.0.1)
|
||||
bson (1.5.1)
|
||||
bson_ext (1.3.1)
|
||||
builder (3.0.0)
|
||||
columnize (0.3.5)
|
||||
erubis (2.7.0)
|
||||
faraday (0.7.5)
|
||||
addressable (~> 2.2.6)
|
||||
multipart-post (~> 1.1.3)
|
||||
rack (>= 1.1.0, < 2)
|
||||
i18n (0.5.0)
|
||||
jdbc-sqlite3 (3.6.14.2.056-java)
|
||||
linecache (0.43)
|
||||
mail (2.2.15)
|
||||
activesupport (>= 2.3.6)
|
||||
hashie (1.2.0)
|
||||
hike (1.2.1)
|
||||
i18n (0.6.0)
|
||||
journey (1.0.0)
|
||||
json (1.6.5)
|
||||
linecache (0.46)
|
||||
rbx-require-relative (> 0.0.4)
|
||||
mail (2.4.1)
|
||||
i18n (>= 0.4.0)
|
||||
mime-types (~> 1.16)
|
||||
treetop (~> 1.4.8)
|
||||
mime-types (1.16)
|
||||
mocha (0.9.12)
|
||||
mongo (1.1.2)
|
||||
bson (>= 1.1.1)
|
||||
mongoid (2.0.0.beta.20)
|
||||
activemodel (~> 3.0)
|
||||
mongo (~> 1.1)
|
||||
metaclass (0.0.1)
|
||||
mime-types (1.17.2)
|
||||
mocha (0.10.0)
|
||||
metaclass (~> 0.0.1)
|
||||
mongo (1.3.1)
|
||||
bson (>= 1.3.1)
|
||||
mongoid (2.3.4)
|
||||
activemodel (~> 3.1)
|
||||
mongo (~> 1.3)
|
||||
tzinfo (~> 0.3.22)
|
||||
will_paginate (~> 3.0.pre)
|
||||
multi_json (0.0.5)
|
||||
multipart-post (1.1.0)
|
||||
nokogiri (1.4.4)
|
||||
nokogiri (1.4.4-java)
|
||||
weakling (>= 0.0.3)
|
||||
oa-core (0.2.0)
|
||||
rack (~> 1.1)
|
||||
oa-oauth (0.2.0)
|
||||
multi_json (~> 0.0.2)
|
||||
nokogiri (~> 1.4.2)
|
||||
oa-core (= 0.2.0)
|
||||
oauth (~> 0.4.0)
|
||||
oauth2 (~> 0.1.1)
|
||||
oa-openid (0.2.0)
|
||||
oa-core (= 0.2.0)
|
||||
rack-openid (~> 1.2.0)
|
||||
ruby-openid-apps-discovery
|
||||
oauth (0.4.4)
|
||||
oauth2 (0.1.1)
|
||||
faraday (~> 0.5.0)
|
||||
multi_json (~> 0.0.4)
|
||||
orm_adapter (0.0.4)
|
||||
polyglot (0.3.1)
|
||||
rack (1.2.1)
|
||||
rack-mount (0.6.13)
|
||||
rack (>= 1.0.0)
|
||||
rack-openid (1.2.0)
|
||||
multi_json (1.0.4)
|
||||
multipart-post (1.1.4)
|
||||
nokogiri (1.5.0)
|
||||
oauth2 (0.5.1)
|
||||
faraday (~> 0.7.4)
|
||||
multi_json (~> 1.0.3)
|
||||
omniauth (1.0.1)
|
||||
hashie (~> 1.2)
|
||||
rack
|
||||
omniauth-facebook (1.0.0)
|
||||
omniauth-oauth2 (~> 1.0.0)
|
||||
omniauth-oauth2 (1.0.0)
|
||||
oauth2 (~> 0.5.0)
|
||||
omniauth (~> 1.0)
|
||||
omniauth-openid (1.0.1)
|
||||
omniauth (~> 1.0)
|
||||
rack-openid (~> 1.3.1)
|
||||
orm_adapter (0.0.6)
|
||||
polyglot (0.3.3)
|
||||
rack (1.4.1)
|
||||
rack-cache (1.1)
|
||||
rack (>= 0.4)
|
||||
rack-openid (1.3.1)
|
||||
rack (>= 1.1.0)
|
||||
ruby-openid (>= 2.1.8)
|
||||
rack-test (0.5.7)
|
||||
rack-ssl (1.3.2)
|
||||
rack
|
||||
rack-test (0.6.1)
|
||||
rack (>= 1.0)
|
||||
rails (3.0.4)
|
||||
actionmailer (= 3.0.4)
|
||||
actionpack (= 3.0.4)
|
||||
activerecord (= 3.0.4)
|
||||
activeresource (= 3.0.4)
|
||||
activesupport (= 3.0.4)
|
||||
rails (3.2.0)
|
||||
actionmailer (= 3.2.0)
|
||||
actionpack (= 3.2.0)
|
||||
activerecord (= 3.2.0)
|
||||
activeresource (= 3.2.0)
|
||||
activesupport (= 3.2.0)
|
||||
bundler (~> 1.0)
|
||||
railties (= 3.0.4)
|
||||
railties (3.0.4)
|
||||
actionpack (= 3.0.4)
|
||||
activesupport (= 3.0.4)
|
||||
railties (= 3.2.0)
|
||||
railties (3.2.0)
|
||||
actionpack (= 3.2.0)
|
||||
activesupport (= 3.2.0)
|
||||
rack-ssl (~> 1.3.2)
|
||||
rake (>= 0.8.7)
|
||||
thor (~> 0.14.4)
|
||||
rake (0.8.7)
|
||||
rdoc (~> 3.4)
|
||||
thor (~> 0.14.6)
|
||||
rake (0.9.2.2)
|
||||
rbx-require-relative (0.0.5)
|
||||
rdoc (3.12)
|
||||
json (~> 1.4)
|
||||
ruby-debug (0.10.4)
|
||||
columnize (>= 0.1)
|
||||
ruby-debug-base (~> 0.10.4.0)
|
||||
ruby-debug-base (0.10.4)
|
||||
linecache (>= 0.3)
|
||||
ruby-openid (2.1.8)
|
||||
ruby-openid-apps-discovery (1.2.0)
|
||||
ruby-openid (>= 2.1.7)
|
||||
sqlite3 (1.3.3)
|
||||
sprockets (2.1.2)
|
||||
hike (~> 1.2)
|
||||
rack (~> 1.0)
|
||||
tilt (~> 1.1, != 1.3.0)
|
||||
sqlite3 (1.3.5)
|
||||
sqlite3-ruby (1.3.3)
|
||||
sqlite3 (>= 1.3.3)
|
||||
thor (0.14.6)
|
||||
treetop (1.4.9)
|
||||
tilt (1.3.3)
|
||||
treetop (1.4.10)
|
||||
polyglot
|
||||
polyglot (>= 0.3.1)
|
||||
tzinfo (0.3.24)
|
||||
warden (1.0.3)
|
||||
rack (>= 1.0.0)
|
||||
weakling (0.0.4-java)
|
||||
tzinfo (0.3.31)
|
||||
warden (1.1.0)
|
||||
rack (>= 1.0)
|
||||
webrat (0.7.2)
|
||||
nokogiri (>= 1.2.0)
|
||||
rack (>= 1.0)
|
||||
rack-test (>= 0.5.3)
|
||||
will_paginate (3.0.pre2)
|
||||
|
||||
PLATFORMS
|
||||
java
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
activerecord-jdbc-adapter
|
||||
activerecord-jdbcsqlite3-adapter
|
||||
bson_ext (= 1.2.1)
|
||||
bson_ext (~> 1.3.0)
|
||||
devise!
|
||||
jruby-openssl
|
||||
mocha
|
||||
mongo (= 1.1.2)
|
||||
mongoid (= 2.0.0.beta.20)
|
||||
oa-oauth (~> 0.2.0)
|
||||
oa-openid (~> 0.2.0)
|
||||
rails (~> 3.0.4)
|
||||
mongo (~> 1.3.0)
|
||||
mongoid (~> 2.0)
|
||||
omniauth (~> 1.0.0)
|
||||
omniauth-facebook
|
||||
omniauth-oauth2 (~> 1.0.0)
|
||||
omniauth-openid (~> 1.0.1)
|
||||
rails (~> 3.2.0)
|
||||
rdoc
|
||||
ruby-debug (>= 0.10.3)
|
||||
sqlite3-ruby
|
||||
webrat (= 0.7.2)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Copyright 2009-2011 Plataforma Tecnologia. http://blog.plataformatec.com.br
|
||||
Copyright 2009-2012 Plataforma Tecnologia. http://blog.plataformatec.com.br
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
== Devise
|
||||
*IMPORTANT:* Devise 2.0.0 is out. If you are upgrading, please read: https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0
|
||||
|
||||
## Devise
|
||||
|
||||
INFO: This README is [also available in a friendly navigable format](http://devise.plataformatec.com.br/).
|
||||
|
||||
[](http://travis-ci.org/plataformatec/devise)
|
||||
|
||||
Devise is a flexible authentication solution for Rails based on Warden. It:
|
||||
|
||||
@@ -7,7 +13,7 @@ Devise is a flexible authentication solution for Rails based on Warden. It:
|
||||
* Allows you to have multiple roles (or models/scopes) signed in at the same time;
|
||||
* Is based on a modularity concept: use just what you really need.
|
||||
|
||||
It's composed of 12 modules:
|
||||
It's comprised of 12 modules:
|
||||
|
||||
* Database Authenticatable: encrypts and stores a password in the database to validate the authenticity of a user while signing in. The authentication can be done both through POST requests or HTTP Basic Authentication.
|
||||
* Token Authenticatable: signs in a user based on an authentication token (also known as "single access token"). The token can be given both through query string or HTTP Basic Authentication.
|
||||
@@ -22,333 +28,361 @@ It's composed of 12 modules:
|
||||
* Lockable: locks an account after a specified number of failed sign-in attempts. Can unlock via email or after a specified time period.
|
||||
* Encryptable: adds support of other authentication mechanisms besides the built-in Bcrypt (the default).
|
||||
|
||||
== Information
|
||||
## Information
|
||||
|
||||
=== The Devise wiki
|
||||
### The Devise wiki
|
||||
|
||||
The Devise Wiki has lots of additional information about Devise including many "how-to" articles and answers to the most frequently asked questions. Please browse the Wiki after finishing this README:
|
||||
|
||||
http://wiki.github.com/plataformatec/devise
|
||||
https://wiki.github.com/plataformatec/devise
|
||||
|
||||
=== Bug reports
|
||||
### Bug reports
|
||||
|
||||
If you discover a problem with Devise, we would like to know about it. However, we ask that you please review these guidelines before submitting a bug report:
|
||||
|
||||
http://github.com/plataformatec/devise/wiki/Bug-reports
|
||||
https://github.com/plataformatec/devise/wiki/Bug-reports
|
||||
|
||||
If you found a security bug, do *NOT* use the GitHub issue tracker. Send email or a private GitHub message to the maintainers listed at the bottom of the README.
|
||||
|
||||
=== Mailing list
|
||||
### Mailing list
|
||||
|
||||
If you have any questions, comments, or concerns, please use the Google Group instead of the GitHub issue tracker:
|
||||
|
||||
http://groups.google.com/group/plataformatec-devise
|
||||
https://groups.google.com/group/plataformatec-devise
|
||||
|
||||
=== RDocs
|
||||
### RDocs
|
||||
|
||||
You can view the Devise documentation in RDoc format here:
|
||||
|
||||
http://rubydoc.info/github/plataformatec/devise/master/frames
|
||||
|
||||
If you need to use Devise with Rails 2.3, you can always run `gem server` from the command line after you install the gem to access the old documentation.
|
||||
If you need to use Devise with Rails 2.3, you can always run "gem server" from the command line after you install the gem to access the old documentation.
|
||||
|
||||
=== Example applications
|
||||
### Example applications
|
||||
|
||||
There are a few example applications available on GitHub that demonstrate various features of Devise with different versions of Rails. You can view them here:
|
||||
|
||||
http://github.com/plataformatec/devise/wiki/Example-Applications
|
||||
https://github.com/plataformatec/devise/wiki/Example-Applications
|
||||
|
||||
=== Extensions
|
||||
### Extensions
|
||||
|
||||
Our community has created a number of extensions that add functionality above and beyond what is included with Devise. You can view a list of available extensions and add your own here:
|
||||
|
||||
http://github.com/plataformatec/devise/wiki/Extensions
|
||||
https://github.com/plataformatec/devise/wiki/Extensions
|
||||
|
||||
=== Contributing
|
||||
### Contributing
|
||||
|
||||
We hope that you will consider contributing to Devise. Please read this short overview for some information about how to get started:
|
||||
|
||||
http://github.com/plataformatec/devise/wiki/Contributing
|
||||
https://github.com/plataformatec/devise/wiki/Contributing
|
||||
|
||||
You will usually want to write tests for your changes. To run the test suite, `cd` into Devise's top-level directory and run `bundle install` and `rake`. For the tests to pass, you will need to have a MongoDB server (version 1.6 or newer) running on your system.
|
||||
You will usually want to write tests for your changes. To run the test suite, go into Devise's top-level directory and run "bundle install" and "rake". For the tests to pass, you will need to have a MongoDB server (version 2.0 or newer) running on your system.
|
||||
|
||||
== Installation
|
||||
|
||||
You can use the latest Rails 3 gem with the latest Devise gem:
|
||||
|
||||
gem install devise
|
||||
|
||||
After you install Devise and add it to your Gemfile, you need to run the generator:
|
||||
|
||||
rails generate devise:install
|
||||
|
||||
The generator will install an initializer which describes ALL Devise's configuration options and you MUST take a look at it. When you are done, you are ready to add Devise to any of your models using the generator:
|
||||
|
||||
rails generate devise MODEL
|
||||
|
||||
Replace MODEL by the class name you want to add devise, like User, Admin, etc. This will create a model (if one does not exist) and configure it with default Devise modules. The generator will also create a migration file (if your ORM support them) and configure your routes. Continue reading this file to understand exactly what the generator produces and how to use it.
|
||||
|
||||
Support for Rails 2.3.x can be found by installing Devise 1.0.x from the v1.0 branch.
|
||||
|
||||
== Starting with Rails?
|
||||
## Starting with Rails?
|
||||
|
||||
If you are building your first Rails application, we recommend you to *not* use Devise. Devise requires a good understanding of the Rails Framework. In such cases, we advise you to start a simple authentication system from scratch, today we have two resources:
|
||||
|
||||
* Michael Hartl's online book: http://railstutorial.org/chapters/modeling-and-viewing-users-two#top
|
||||
* Ryan Bates' Railscast: http://railscasts.com/episodes/250-authentication-from-scratch
|
||||
|
||||
Once you have solidified you understanding of Rails and authentication mechanisms, we assure you Devise will be very pleasant to work with. :)
|
||||
Once you have solidified your understanding of Rails and authentication mechanisms, we assure you Devise will be very pleasant to work with. :)
|
||||
|
||||
== Getting started
|
||||
## Getting started
|
||||
|
||||
This is a walkthrough with all steps you need to setup a devise resource, including model, migration, route files, and optional configuration.
|
||||
Devise 2.0 works with Rails 3.1 onwards. You can install it with:
|
||||
|
||||
Devise must be set up within the model (or models) you want to use. Devise routes must be created inside your config/routes.rb file.
|
||||
```console
|
||||
gem install devise
|
||||
```
|
||||
|
||||
We're assuming here you want a User model with some Devise modules, as outlined below:
|
||||
After you install Devise and add it to your Gemfile, you need to run the generator:
|
||||
|
||||
class User < ActiveRecord::Base
|
||||
devise :database_authenticatable, :confirmable, :recoverable, :rememberable, :trackable, :validatable
|
||||
end
|
||||
```console
|
||||
rails generate devise:install
|
||||
```
|
||||
|
||||
After you choose which modules to use, you need to set up your migrations. Luckily, Devise has some helpers to save you from this boring work:
|
||||
The generator will install an initializer which describes ALL Devise's configuration options and you MUST take a look at it. When you are done, you are ready to add Devise to any of your models using the generator:
|
||||
|
||||
create_table :users do |t|
|
||||
t.database_authenticatable
|
||||
t.confirmable
|
||||
t.recoverable
|
||||
t.rememberable
|
||||
t.trackable
|
||||
t.timestamps
|
||||
end
|
||||
```console
|
||||
rails generate devise MODEL
|
||||
```
|
||||
|
||||
Devise doesn't use _attr_accessible_ or _attr_protected_ inside its modules, so be sure to define attributes as accessible or protected in your model.
|
||||
Replace MODEL by the class name used for the applications users, it's frequently 'User' but could also be 'Admin'. This will create a model (if one does not exist) and configure it with default Devise modules. Next, you'll usually run "rake db:migrate" as the generator will have created a migration file (if your ORM supports them). This generator also configures your config/routes.rb file to point to Devise controller.
|
||||
|
||||
Configure your routes after setting up your model. Open your config/routes.rb file and add:
|
||||
|
||||
devise_for :users
|
||||
|
||||
This will use your User model to create a set of needed routes (you can see them by running `rake routes`). If you invoked the devise generator, you noticed that this is exactly what the generator produces for us: model, routes and migrations.
|
||||
|
||||
Don't forget to run rake db:migrate and you are ready to go! But don't stop reading here, we still have a lot to tell you.
|
||||
|
||||
=== Controller filters and helpers
|
||||
### Controller filters and helpers
|
||||
|
||||
Devise will create some helpers to use inside your controllers and views. To set up a controller with user authentication, just add this before_filter:
|
||||
|
||||
before_filter :authenticate_user!
|
||||
```ruby
|
||||
before_filter :authenticate_user!
|
||||
```
|
||||
|
||||
To verify if a user is signed in, use the following helper:
|
||||
|
||||
user_signed_in?
|
||||
```ruby
|
||||
user_signed_in?
|
||||
```
|
||||
|
||||
For the current signed-in user, this helper is available:
|
||||
|
||||
current_user
|
||||
```ruby
|
||||
current_user
|
||||
```
|
||||
|
||||
You can access the session for this scope:
|
||||
|
||||
user_session
|
||||
```ruby
|
||||
user_session
|
||||
```
|
||||
|
||||
After signing in a user, confirming the account or updating the password, Devise will look for a scoped root path to redirect. Example: For a :user resource, it will use user_root_path if it exists, otherwise default root_path will be used. This means that you need to set the root inside your routes:
|
||||
After signing in a user, confirming the account or updating the password, Devise will look for a scoped root path to redirect. Example: For a :user resource, it will use +user_root_path+ if it exists, otherwise default +root_path+ will be used. This means that you need to set the root inside your routes:
|
||||
|
||||
root :to => "home"
|
||||
```ruby
|
||||
root :to => "home#index"
|
||||
```
|
||||
|
||||
You can also overwrite after_sign_in_path_for and after_sign_out_path_for to customize your redirect hooks.
|
||||
You can also overwrite +after_sign_in_path_for+ and +after_sign_out_path_for+ to customize your redirect hooks.
|
||||
|
||||
Finally, you need to set up default url options for the mailer in each environment. Here is the configuration for config/environments/development.rb:
|
||||
Finally, you need to set up default url options for the mailer in each environment. Here is the configuration for "config/environments/development.rb":
|
||||
|
||||
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
|
||||
```ruby
|
||||
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
|
||||
```
|
||||
|
||||
Notice that if your devise model is not called "user" but "member", then the helpers you should use are:
|
||||
|
||||
before_filter :authenticate_member!
|
||||
```ruby
|
||||
before_filter :authenticate_member!
|
||||
|
||||
member_signed_in?
|
||||
member_signed_in?
|
||||
|
||||
current_member
|
||||
current_member
|
||||
|
||||
member_session
|
||||
member_session
|
||||
```
|
||||
|
||||
=== Configuring Models
|
||||
### Configuring Models
|
||||
|
||||
The devise method in your models also accepts some options to configure its modules. For example, you can choose which encryptor to use in database_authenticatable:
|
||||
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:
|
||||
|
||||
devise :database_authenticatable, :confirmable, :recoverable, :stretches => 20
|
||||
```ruby
|
||||
devise :database_authenticatable, :registerable, :confirmable, :recoverable, :stretches => 20
|
||||
```
|
||||
|
||||
Besides :stretches, you can define :pepper, :encryptor, :confirm_within, :remember_for, :timeout_in, :unlock_in and other values. For details, see the initializer file that was created when you invoked the "devise:install" generator described above.
|
||||
|
||||
=== Configuring multiple models
|
||||
### Configuring multiple models
|
||||
|
||||
Devise allows you to set up as many roles as you want. For example, you may have a User model and also want an Admin model with just authentication, trackable, lockable and timeoutable features and no confirmation or password-recovery features. Just follow these steps:
|
||||
Devise allows you to set up as many roles as you want. For example, you may have a User model and also want an Admin model with just authentication and timeoutable features. If so, just follow these steps:
|
||||
|
||||
# Create a migration with the required fields
|
||||
create_table :admins do |t|
|
||||
t.database_authenticatable
|
||||
t.lockable
|
||||
t.trackable
|
||||
t.timestamps
|
||||
end
|
||||
```ruby
|
||||
# Create a migration with the required fields
|
||||
create_table :admins do |t|
|
||||
t.string :email
|
||||
t.string :encrypted_password
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
# Inside your Admin model
|
||||
devise :database_authenticatable, :trackable, :timeoutable, :lockable
|
||||
# Inside your Admin model
|
||||
devise :database_authenticatable, :timeoutable
|
||||
|
||||
# Inside your routes
|
||||
devise_for :admins
|
||||
# Inside your routes
|
||||
devise_for :admins
|
||||
|
||||
# Inside your protected controller
|
||||
before_filter :authenticate_admin!
|
||||
# Inside your protected controller
|
||||
before_filter :authenticate_admin!
|
||||
|
||||
# Inside your controllers and views
|
||||
admin_signed_in?
|
||||
current_admin
|
||||
admin_session
|
||||
# Inside your controllers and views
|
||||
admin_signed_in?
|
||||
current_admin
|
||||
admin_session
|
||||
```
|
||||
|
||||
=== Configuring views
|
||||
On the other hand, you can simply run the generator!
|
||||
|
||||
### Configuring views
|
||||
|
||||
We built Devise to help you quickly develop an application that uses authentication. However, we don't want to be in your way when you need to customize it.
|
||||
|
||||
Since Devise is an engine, all its views are packaged inside the gem. These views will help you get started, but after sometime 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:
|
||||
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:
|
||||
|
||||
rails generate devise:views
|
||||
```console
|
||||
rails generate devise:views
|
||||
```
|
||||
|
||||
If you have more than one role in your application (such as "User" and "Admin"), you will notice that Devise uses the same views for all roles. Fortunately, Devise offers an easy way to customize views. All you need to do is set "config.scoped_views = true" inside "config/initializers/devise.rb".
|
||||
|
||||
After doing so, you will be able to have views based on the role like "users/sessions/new" and "admins/sessions/new". If no view is found within the scope, Devise will use the default view at "devise/sessions/new". You can also use the generator to generate scoped views:
|
||||
|
||||
rails generate devise:views users
|
||||
```console
|
||||
rails generate devise:views users
|
||||
```
|
||||
|
||||
=== Configuring controllers
|
||||
### Configuring controllers
|
||||
|
||||
If the customization at the views level is not enough, you can customize each controller by following these steps:
|
||||
|
||||
1) Create your custom controller, for example a Admins::SessionsController:
|
||||
|
||||
class Admins::SessionsController < Devise::SessionsController
|
||||
end
|
||||
```ruby
|
||||
class Admins::SessionsController < Devise::SessionsController
|
||||
end
|
||||
```
|
||||
|
||||
2) Tell the router to use this controller:
|
||||
|
||||
devise_for :admins, :controllers => { :sessions => "admins/sessions" }
|
||||
```ruby
|
||||
devise_for :admins, :controllers => { :sessions => "admins/sessions" }
|
||||
```
|
||||
|
||||
3) And since we changed the controller, it won't use the "devise/sessions" views, so remember to copy "devise/sessions" to "admin/sessions".
|
||||
|
||||
Remember that Devise uses flash messages to let users know if sign in was successful or failed. Devise expects your application to call "flash[:notice]" and "flash[:alert]" as appropriate.
|
||||
|
||||
=== Configuring routes
|
||||
### Configuring routes
|
||||
|
||||
Devise also ships with default routes. If you need to customize them, you should probably be able to do it through the devise_for method. It accepts several options like :class_name, :path_prefix and so on, including the possibility to change path names for I18n:
|
||||
|
||||
devise_for :users, :path => "usuarios", :path_names => { :sign_in => 'login', :sign_out => 'logout', :password => 'secret', :confirmation => 'verification', :unlock => 'unblock', :registration => 'register', :sign_up => 'cmon_let_me_in' }
|
||||
```ruby
|
||||
devise_for :users, :path => "usuarios", :path_names => { :sign_in => 'login', :sign_out => 'logout', :password => 'secret', :confirmation => 'verification', :unlock => 'unblock', :registration => 'register', :sign_up => 'cmon_let_me_in' }
|
||||
```
|
||||
|
||||
Be sure to check devise_for documentation for details.
|
||||
Be sure to check +devise_for+ documentation 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:
|
||||
|
||||
devise_scope :user do
|
||||
get "sign_in", :to => "devise/sessions#new"
|
||||
end
|
||||
```ruby
|
||||
devise_scope :user do
|
||||
get "sign_in", :to => "devise/sessions#new"
|
||||
end
|
||||
```
|
||||
|
||||
This way you tell devise to use the scope :user when "/sign_in" is accessed. Notice +devise_scope+ is also aliased as +as+ and you can also give a block to +devise_for+, resulting in the same behavior:
|
||||
|
||||
devise_for :users do
|
||||
get "sign_in", :to => "devise/sessions#new"
|
||||
end
|
||||
```ruby
|
||||
devise_for :users do
|
||||
get "sign_in", :to => "devise/sessions#new"
|
||||
end
|
||||
```
|
||||
|
||||
Feel free to choose the one you prefer!
|
||||
|
||||
=== I18n
|
||||
### I18n
|
||||
|
||||
Devise uses flash messages with I18n with the flash keys :success and :failure. To customize your app, you can set up your locale file:
|
||||
Devise uses flash messages with I18n with the flash keys :notice and :alert. To customize your app, you can set up your locale file:
|
||||
|
||||
en:
|
||||
devise:
|
||||
sessions:
|
||||
signed_in: 'Signed in successfully.'
|
||||
```yaml
|
||||
en:
|
||||
devise:
|
||||
sessions:
|
||||
signed_in: 'Signed in successfully.'
|
||||
```
|
||||
|
||||
You can also create distinct messages based on the resource you've configured using the singular name given in routes:
|
||||
|
||||
en:
|
||||
devise:
|
||||
sessions:
|
||||
user:
|
||||
signed_in: 'Welcome user, you are signed in.'
|
||||
admin:
|
||||
signed_in: 'Hello admin!'
|
||||
```yaml
|
||||
en:
|
||||
devise:
|
||||
sessions:
|
||||
user:
|
||||
signed_in: 'Welcome user, you are signed in.'
|
||||
admin:
|
||||
signed_in: 'Hello admin!'
|
||||
```
|
||||
|
||||
The Devise mailer uses a similar pattern to create subject messages:
|
||||
|
||||
en:
|
||||
devise:
|
||||
mailer:
|
||||
confirmation_instructions:
|
||||
subject: 'Hello everybody!'
|
||||
user_subject: 'Hello User! Please confirm your email'
|
||||
reset_password_instructions:
|
||||
subject: 'Reset instructions'
|
||||
```yaml
|
||||
en:
|
||||
devise:
|
||||
mailer:
|
||||
confirmation_instructions:
|
||||
subject: 'Hello everybody!'
|
||||
user_subject: 'Hello User! Please confirm your email'
|
||||
reset_password_instructions:
|
||||
subject: 'Reset instructions'
|
||||
```
|
||||
|
||||
Take a look at our locale file to check all available messages. You may also be interested in one of the many translations that are available on our wiki:
|
||||
|
||||
http://github.com/plataformatec/devise/wiki/I18n
|
||||
https://github.com/plataformatec/devise/wiki/I18n
|
||||
|
||||
=== Test helpers
|
||||
### Test helpers
|
||||
|
||||
Devise includes some tests helpers for functional specs. To use them, you just need to include Devise::TestHelpers in your test class and use the sign_in and sign_out method. Such methods have the same signature as in controllers:
|
||||
|
||||
sign_in :user, @user # sign_in(scope, resource)
|
||||
sign_in @user # sign_in(resource)
|
||||
```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_out :user # sign_out(scope)
|
||||
sign_out @user # sign_out(resource)
|
||||
```
|
||||
|
||||
You can include the Devise Test Helpers in all of your tests by adding the following to the bottom of your test/test_helper.rb file:
|
||||
|
||||
class ActionController::TestCase
|
||||
include Devise::TestHelpers
|
||||
end
|
||||
```ruby
|
||||
class ActionController::TestCase
|
||||
include Devise::TestHelpers
|
||||
end
|
||||
```
|
||||
|
||||
If you're using RSpec and want the helpers automatically included within all +describe+ blocks, add a file called spec/support/devise.rb with the following contents:
|
||||
|
||||
RSpec.configure do |config|
|
||||
config.include Devise::TestHelpers, :type => :controller
|
||||
end
|
||||
```ruby
|
||||
RSpec.configure do |config|
|
||||
config.include Devise::TestHelpers, :type => :controller
|
||||
end
|
||||
```
|
||||
|
||||
Do not use such helpers for integration tests such as Cucumber or Webrat. Instead, fill in the form or explicitly set the user in session. For more tips, check the wiki (http://wiki.github.com/plataformatec/devise).
|
||||
Do not use such helpers for integration tests such as Cucumber or Webrat. Instead, fill in the form or explicitly set the user in session. For more tips, check the wiki (https://wiki.github.com/plataformatec/devise).
|
||||
|
||||
=== OAuth2
|
||||
### Omniauth
|
||||
|
||||
Devise comes with OAuth support out of the box if you're using Devise from the git repository (for now). You can read more about OAuth2 support in the wiki:
|
||||
Devise comes with Omniauth support out of the box to authenticate from other providers. You can read more about Omniauth support in the wiki:
|
||||
|
||||
* http://github.com/plataformatec/devise/wiki/OAuth2:-Overview
|
||||
* http://github.com/plataformatec/devise/wiki/OAuth2:-Testing
|
||||
* https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview
|
||||
|
||||
=== Other ORMs
|
||||
### Other ORMs
|
||||
|
||||
Devise supports ActiveRecord (default) and Mongoid. To choose other ORM, you just need to require it in the initializer file.
|
||||
|
||||
=== Migrating from other solutions
|
||||
### Migrating from other solutions
|
||||
|
||||
Devise implements encryption strategies for Clearance, Authlogic and Restful-Authentication. To make use of these strategies, you need set the desired encryptor in the encryptor initializer config option and add :encryptable to your model. You might also need to rename your encrypted password and salt columns to match Devise's fields (encrypted_password and password_salt).
|
||||
|
||||
== Additional information
|
||||
## Troubleshooting
|
||||
|
||||
=== Warden
|
||||
### Heroku
|
||||
|
||||
Using devise on Heroku with Ruby on Rails 3.1 requires setting:
|
||||
|
||||
```ruby
|
||||
config.assets.initialize_on_precompile = false
|
||||
```
|
||||
|
||||
Read more about the potential issues at http://guides.rubyonrails.org/asset_pipeline.html
|
||||
|
||||
## Additional information
|
||||
|
||||
### Warden
|
||||
|
||||
Devise is based on Warden, which is a general Rack authentication framework created by Daniel Neighman. We encourage you to read more about Warden here:
|
||||
|
||||
http://github.com/hassox/warden
|
||||
https://github.com/hassox/warden
|
||||
|
||||
=== Contributors
|
||||
### Contributors
|
||||
|
||||
We have a long list of valued contributors. Check them all at:
|
||||
|
||||
http://github.com/plataformatec/devise/contributors
|
||||
https://github.com/plataformatec/devise/contributors
|
||||
|
||||
=== Maintainers
|
||||
### Maintainers
|
||||
|
||||
* José Valim (http://github.com/josevalim)
|
||||
* Carlos Antônio da Silva (http://github.com/carlosantoniodasilva)
|
||||
* José Valim (https://github.com/josevalim)
|
||||
* Carlos Antônio da Silva (https://github.com/carlosantoniodasilva)
|
||||
* Rodrigo Flores (https://github.com/rodrigoflores)
|
||||
|
||||
== License
|
||||
## License
|
||||
|
||||
MIT License. Copyright 2010 Plataforma Tecnologia. http://blog.plataformatec.com.br
|
||||
MIT License. Copyright 2012 Plataforma Tecnologia. http://blog.plataformatec.com.br
|
||||
4
Rakefile
4
Rakefile
@@ -1,10 +1,10 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
require 'rake/testtask'
|
||||
require 'rake/rdoctask'
|
||||
require 'rdoc/task'
|
||||
|
||||
desc 'Default: run tests for all ORMs.'
|
||||
task :default => :pre_commit
|
||||
task :default => :test
|
||||
|
||||
desc 'Run Devise tests for all ORMs.'
|
||||
task :pre_commit do
|
||||
|
||||
@@ -1,21 +1,17 @@
|
||||
class Devise::ConfirmationsController < ApplicationController
|
||||
include Devise::Controllers::InternalHelpers
|
||||
|
||||
class Devise::ConfirmationsController < DeviseController
|
||||
# GET /resource/confirmation/new
|
||||
def new
|
||||
build_resource({})
|
||||
render_with_scope :new
|
||||
end
|
||||
|
||||
# POST /resource/confirmation
|
||||
def create
|
||||
self.resource = resource_class.send_confirmation_instructions(params[resource_name])
|
||||
|
||||
if resource.errors.empty?
|
||||
set_flash_message :notice, :send_instructions
|
||||
redirect_to new_session_path(resource_name)
|
||||
if successfully_sent?(resource)
|
||||
respond_with({}, :location => after_resending_confirmation_instructions_path_for(resource_name))
|
||||
else
|
||||
render_with_scope :new
|
||||
respond_with(resource)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -24,10 +20,24 @@ class Devise::ConfirmationsController < ApplicationController
|
||||
self.resource = resource_class.confirm_by_token(params[:confirmation_token])
|
||||
|
||||
if resource.errors.empty?
|
||||
set_flash_message :notice, :confirmed
|
||||
sign_in_and_redirect(resource_name, resource)
|
||||
set_flash_message(:notice, :confirmed) if is_navigational_format?
|
||||
sign_in(resource_name, resource)
|
||||
respond_with_navigational(resource){ redirect_to after_confirmation_path_for(resource_name, resource) }
|
||||
else
|
||||
render_with_scope :new
|
||||
respond_with_navigational(resource.errors, :status => :unprocessable_entity){ render :new }
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
# The path used after resending confirmation instructions.
|
||||
def after_resending_confirmation_instructions_path_for(resource_name)
|
||||
new_session_path(resource_name)
|
||||
end
|
||||
|
||||
# The path used after confirmation.
|
||||
def after_confirmation_path_for(resource_name, resource)
|
||||
after_sign_in_path_for(resource)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
class Devise::OmniauthCallbacksController < ApplicationController
|
||||
include Devise::Controllers::InternalHelpers
|
||||
|
||||
class Devise::OmniauthCallbacksController < DeviseController
|
||||
def failure
|
||||
set_flash_message :alert, :failure, :kind => failed_strategy.name.to_s.humanize, :reason => failure_message
|
||||
redirect_to after_omniauth_failure_path_for(resource_name)
|
||||
|
||||
@@ -1,22 +1,19 @@
|
||||
class Devise::PasswordsController < ApplicationController
|
||||
class Devise::PasswordsController < DeviseController
|
||||
prepend_before_filter :require_no_authentication
|
||||
include Devise::Controllers::InternalHelpers
|
||||
|
||||
# GET /resource/password/new
|
||||
def new
|
||||
build_resource({})
|
||||
render_with_scope :new
|
||||
end
|
||||
|
||||
# POST /resource/password
|
||||
def create
|
||||
self.resource = resource_class.send_reset_password_instructions(params[resource_name])
|
||||
|
||||
if resource.errors.empty?
|
||||
set_flash_message :notice, :send_instructions
|
||||
redirect_to new_session_path(resource_name)
|
||||
if successfully_sent?(resource)
|
||||
respond_with({}, :location => after_sending_reset_password_instructions_path_for(resource_name))
|
||||
else
|
||||
render_with_scope :new
|
||||
respond_with(resource)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -24,7 +21,6 @@ class Devise::PasswordsController < ApplicationController
|
||||
def edit
|
||||
self.resource = resource_class.new
|
||||
resource.reset_password_token = params[:reset_password_token]
|
||||
render_with_scope :edit
|
||||
end
|
||||
|
||||
# PUT /resource/password
|
||||
@@ -32,10 +28,20 @@ class Devise::PasswordsController < ApplicationController
|
||||
self.resource = resource_class.reset_password_by_token(params[resource_name])
|
||||
|
||||
if resource.errors.empty?
|
||||
set_flash_message :notice, :updated
|
||||
sign_in_and_redirect(resource_name, resource)
|
||||
flash_message = resource.active_for_authentication? ? :updated : :updated_not_active
|
||||
set_flash_message(:notice, flash_message) if is_navigational_format?
|
||||
sign_in(resource_name, resource)
|
||||
respond_with resource, :location => after_sign_in_path_for(resource)
|
||||
else
|
||||
render_with_scope :edit
|
||||
respond_with resource
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
# The path used after sending reset password instructions
|
||||
def after_sending_reset_password_instructions_path_for(resource_name)
|
||||
new_session_path(resource_name)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
class Devise::RegistrationsController < ApplicationController
|
||||
class Devise::RegistrationsController < DeviseController
|
||||
prepend_before_filter :require_no_authentication, :only => [ :new, :create, :cancel ]
|
||||
prepend_before_filter :authenticate_scope!, :only => [:edit, :update, :destroy]
|
||||
include Devise::Controllers::InternalHelpers
|
||||
|
||||
# GET /resource/sign_up
|
||||
def new
|
||||
build_resource({})
|
||||
render_with_scope :new
|
||||
resource = build_resource({})
|
||||
respond_with resource
|
||||
end
|
||||
|
||||
# POST /resource
|
||||
@@ -15,41 +14,52 @@ class Devise::RegistrationsController < ApplicationController
|
||||
|
||||
if resource.save
|
||||
if resource.active_for_authentication?
|
||||
set_flash_message :notice, :signed_up
|
||||
sign_in_and_redirect(resource_name, resource)
|
||||
set_flash_message :notice, :signed_up if is_navigational_format?
|
||||
sign_in(resource_name, resource)
|
||||
respond_with resource, :location => after_sign_up_path_for(resource)
|
||||
else
|
||||
set_flash_message :notice, :inactive_signed_up, :reason => resource.inactive_message.to_s
|
||||
set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format?
|
||||
expire_session_data_after_sign_in!
|
||||
redirect_to after_inactive_sign_up_path_for(resource)
|
||||
respond_with resource, :location => after_inactive_sign_up_path_for(resource)
|
||||
end
|
||||
else
|
||||
clean_up_passwords(resource)
|
||||
render_with_scope :new
|
||||
clean_up_passwords resource
|
||||
respond_with resource
|
||||
end
|
||||
end
|
||||
|
||||
# GET /resource/edit
|
||||
def edit
|
||||
render_with_scope :edit
|
||||
render :edit
|
||||
end
|
||||
|
||||
# PUT /resource
|
||||
# We need to use a copy of the resource because we don't want to change
|
||||
# the current user in place.
|
||||
def update
|
||||
self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key)
|
||||
|
||||
if resource.update_with_password(params[resource_name])
|
||||
set_flash_message :notice, :updated
|
||||
if is_navigational_format?
|
||||
if resource.respond_to?(:pending_reconfirmation?) && resource.pending_reconfirmation?
|
||||
flash_key = :update_needs_confirmation
|
||||
end
|
||||
set_flash_message :notice, flash_key || :updated
|
||||
end
|
||||
sign_in resource_name, resource, :bypass => true
|
||||
redirect_to after_update_path_for(resource)
|
||||
respond_with resource, :location => after_update_path_for(resource)
|
||||
else
|
||||
clean_up_passwords(resource)
|
||||
render_with_scope :edit
|
||||
clean_up_passwords resource
|
||||
respond_with resource
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /resource
|
||||
def destroy
|
||||
resource.destroy
|
||||
sign_out_and_redirect(self.resource)
|
||||
set_flash_message :notice, :destroyed
|
||||
Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)
|
||||
set_flash_message :notice, :destroyed if is_navigational_format?
|
||||
respond_with_navigational(resource){ redirect_to after_sign_out_path_for(resource_name) }
|
||||
end
|
||||
|
||||
# GET /resource/cancel
|
||||
@@ -64,47 +74,34 @@ class Devise::RegistrationsController < ApplicationController
|
||||
|
||||
protected
|
||||
|
||||
# Build a devise resource passing in the session. Useful to move
|
||||
# temporary session data to the newly created user.
|
||||
def build_resource(hash=nil)
|
||||
hash ||= params[resource_name] || {}
|
||||
self.resource = resource_class.new_with_session(hash, session)
|
||||
end
|
||||
# Build a devise resource passing in the session. Useful to move
|
||||
# temporary session data to the newly created user.
|
||||
def build_resource(hash=nil)
|
||||
hash ||= params[resource_name] || {}
|
||||
self.resource = resource_class.new_with_session(hash, session)
|
||||
end
|
||||
|
||||
# The path used after sign up. You need to overwrite this method
|
||||
# in your own RegistrationsController.
|
||||
def after_sign_up_path_for(resource)
|
||||
after_sign_in_path_for(resource)
|
||||
end
|
||||
# The path used after sign up. You need to overwrite this method
|
||||
# in your own RegistrationsController.
|
||||
def after_sign_up_path_for(resource)
|
||||
after_sign_in_path_for(resource)
|
||||
end
|
||||
|
||||
# Overwrite redirect_for_sign_in so it takes uses after_sign_up_path_for.
|
||||
def redirect_location(scope, resource) #:nodoc:
|
||||
stored_location_for(scope) || after_sign_up_path_for(resource)
|
||||
end
|
||||
# The path used after sign up for inactive accounts. You need to overwrite
|
||||
# this method in your own RegistrationsController.
|
||||
def after_inactive_sign_up_path_for(resource)
|
||||
respond_to?(:root_path) ? root_path : "/"
|
||||
end
|
||||
|
||||
# The path used after sign up for inactive accounts. You need to overwrite
|
||||
# this method in your own RegistrationsController.
|
||||
def after_inactive_sign_up_path_for(resource)
|
||||
root_path
|
||||
end
|
||||
# The default url to be used after updating a resource. You need to overwrite
|
||||
# this method in your own RegistrationsController.
|
||||
def after_update_path_for(resource)
|
||||
signed_in_root_path(resource)
|
||||
end
|
||||
|
||||
# The default url to be used after updating a resource. You need to overwrite
|
||||
# this method in your own RegistrationsController.
|
||||
def after_update_path_for(resource)
|
||||
if defined?(super)
|
||||
ActiveSupport::Deprecation.warn "Defining after_update_path_for in ApplicationController " <<
|
||||
"is deprecated. Please add a RegistrationsController to your application and define it there."
|
||||
super
|
||||
else
|
||||
after_sign_in_path_for(resource)
|
||||
end
|
||||
end
|
||||
|
||||
# Authenticates the current scope and gets a copy of the current resource.
|
||||
# We need to use a copy because we don't want actions like update changing
|
||||
# the current user in place.
|
||||
def authenticate_scope!
|
||||
send(:"authenticate_#{resource_name}!", true)
|
||||
self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key)
|
||||
end
|
||||
# Authenticates the current scope and gets the current resource from the session.
|
||||
def authenticate_scope!
|
||||
send(:"authenticate_#{resource_name}!", :force => true)
|
||||
self.resource = send(:"current_#{resource_name}")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,25 +1,52 @@
|
||||
class Devise::SessionsController < ApplicationController
|
||||
class Devise::SessionsController < DeviseController
|
||||
prepend_before_filter :require_no_authentication, :only => [ :new, :create ]
|
||||
include Devise::Controllers::InternalHelpers
|
||||
prepend_before_filter :allow_params_authentication!, :only => :create
|
||||
|
||||
# GET /resource/sign_in
|
||||
def new
|
||||
clean_up_passwords(build_resource)
|
||||
render_with_scope :new
|
||||
resource = build_resource
|
||||
clean_up_passwords(resource)
|
||||
respond_with(resource, serialize_options(resource))
|
||||
end
|
||||
|
||||
# POST /resource/sign_in
|
||||
def create
|
||||
resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#new")
|
||||
resource = warden.authenticate!(auth_options)
|
||||
set_flash_message(:notice, :signed_in) if is_navigational_format?
|
||||
sign_in(resource_name, resource)
|
||||
respond_with resource, :location => redirect_location(resource_name, resource)
|
||||
respond_with resource, :location => after_sign_in_path_for(resource)
|
||||
end
|
||||
|
||||
# GET /resource/sign_out
|
||||
# DELETE /resource/sign_out
|
||||
def destroy
|
||||
signed_in = signed_in?(resource_name)
|
||||
sign_out_and_redirect(resource_name)
|
||||
redirect_path = after_sign_out_path_for(resource_name)
|
||||
Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)
|
||||
set_flash_message :notice, :signed_out if signed_in
|
||||
|
||||
# We actually need to hardcode this as Rails default responder doesn't
|
||||
# support returning empty response on GET request
|
||||
respond_to do |format|
|
||||
format.any(*navigational_formats) { redirect_to redirect_path }
|
||||
format.all do
|
||||
method = "to_#{request_format}"
|
||||
text = {}.respond_to?(method) ? {}.send(method) : ""
|
||||
render :text => text, :status => :ok
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def serialize_options(resource)
|
||||
methods = resource_class.authentication_keys.dup
|
||||
methods = methods.keys if methods.is_a?(Hash)
|
||||
methods << :password if resource.respond_to?(:password)
|
||||
{ :methods => methods, :only => [:password] }
|
||||
end
|
||||
|
||||
def auth_options
|
||||
{ :scope => resource_name, :recall => "#{controller_path}#new" }
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,22 +1,19 @@
|
||||
class Devise::UnlocksController < ApplicationController
|
||||
class Devise::UnlocksController < DeviseController
|
||||
prepend_before_filter :require_no_authentication
|
||||
include Devise::Controllers::InternalHelpers
|
||||
|
||||
# GET /resource/unlock/new
|
||||
def new
|
||||
build_resource({})
|
||||
render_with_scope :new
|
||||
end
|
||||
|
||||
# POST /resource/unlock
|
||||
def create
|
||||
self.resource = resource_class.send_unlock_instructions(params[resource_name])
|
||||
|
||||
if resource.errors.empty?
|
||||
set_flash_message :notice, :send_instructions
|
||||
redirect_to new_session_path(resource_name)
|
||||
if successfully_sent?(resource)
|
||||
respond_with({}, :location => new_session_path(resource_name))
|
||||
else
|
||||
render_with_scope :new
|
||||
respond_with(resource)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -25,10 +22,10 @@ class Devise::UnlocksController < ApplicationController
|
||||
self.resource = resource_class.unlock_access_by_token(params[:unlock_token])
|
||||
|
||||
if resource.errors.empty?
|
||||
set_flash_message :notice, :unlocked
|
||||
sign_in_and_redirect(resource_name, resource)
|
||||
set_flash_message :notice, :unlocked if is_navigational_format?
|
||||
respond_with_navigational(resource){ redirect_to new_session_path(resource) }
|
||||
else
|
||||
render_with_scope :new
|
||||
respond_with_navigational(resource.errors, :status => :unprocessable_entity){ render :new }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
169
app/controllers/devise_controller.rb
Normal file
169
app/controllers/devise_controller.rb
Normal file
@@ -0,0 +1,169 @@
|
||||
# All Devise controllers are inherited from here.
|
||||
class DeviseController < Devise.parent_controller.constantize
|
||||
include Devise::Controllers::ScopedViews
|
||||
|
||||
helper DeviseHelper
|
||||
|
||||
helpers = %w(resource scope_name resource_name signed_in_resource
|
||||
resource_class devise_mapping devise_controller?)
|
||||
hide_action *helpers
|
||||
helper_method *helpers
|
||||
|
||||
prepend_before_filter :assert_is_devise_resource!
|
||||
respond_to *Mime::SET.map(&:to_sym) if mimes_for_respond_to.empty?
|
||||
|
||||
# Gets the actual resource stored in the instance variable
|
||||
def resource
|
||||
instance_variable_get(:"@#{resource_name}")
|
||||
end
|
||||
|
||||
# Proxy to devise map name
|
||||
def resource_name
|
||||
devise_mapping.name
|
||||
end
|
||||
alias :scope_name :resource_name
|
||||
|
||||
# Proxy to devise map class
|
||||
def resource_class
|
||||
devise_mapping.to
|
||||
end
|
||||
|
||||
# Returns a signed in resource from session (if one exists)
|
||||
def signed_in_resource
|
||||
warden.authenticate(:scope => resource_name)
|
||||
end
|
||||
|
||||
# Attempt to find the mapped route for devise based on request path
|
||||
def devise_mapping
|
||||
@devise_mapping ||= request.env["devise.mapping"]
|
||||
end
|
||||
|
||||
# Overwrites devise_controller? to return true
|
||||
def devise_controller?
|
||||
true
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
# Checks whether it's a devise mapped resource or not.
|
||||
def assert_is_devise_resource! #:nodoc:
|
||||
unknown_action! <<-MESSAGE unless devise_mapping
|
||||
Could not find devise mapping for path #{request.fullpath.inspect}.
|
||||
Maybe you forgot to wrap your route inside the scope block? For example:
|
||||
|
||||
devise_scope :user do
|
||||
match "/some/route" => "some_devise_controller"
|
||||
end
|
||||
MESSAGE
|
||||
end
|
||||
|
||||
# Returns real navigational formats which are supported by Rails
|
||||
def navigational_formats
|
||||
@navigational_formats ||= Devise.navigational_formats.select { |format| Mime::EXTENSION_LOOKUP[format.to_s] }
|
||||
end
|
||||
|
||||
def unknown_action!(msg)
|
||||
logger.debug "[Devise] #{msg}" if logger
|
||||
raise AbstractController::ActionNotFound, msg
|
||||
end
|
||||
|
||||
# Sets the resource creating an instance variable
|
||||
def resource=(new_resource)
|
||||
instance_variable_set(:"@#{resource_name}", new_resource)
|
||||
end
|
||||
|
||||
# Build a devise resource.
|
||||
def build_resource(hash=nil)
|
||||
hash ||= params[resource_name] || {}
|
||||
self.resource = resource_class.new(hash)
|
||||
end
|
||||
|
||||
# Helper for use in before_filters where no authentication is required.
|
||||
#
|
||||
# Example:
|
||||
# before_filter :require_no_authentication, :only => :new
|
||||
def require_no_authentication
|
||||
assert_is_devise_resource!
|
||||
return unless is_navigational_format?
|
||||
no_input = devise_mapping.no_input_strategies
|
||||
|
||||
authenticated = if no_input.present?
|
||||
args = no_input.dup.push :scope => resource_name
|
||||
warden.authenticate?(*args)
|
||||
else
|
||||
warden.authenticated?(resource_name)
|
||||
end
|
||||
|
||||
if authenticated
|
||||
resource = warden.user(resource_name)
|
||||
flash[:alert] = I18n.t("devise.failure.already_authenticated")
|
||||
redirect_to after_sign_in_path_for(resource)
|
||||
end
|
||||
end
|
||||
|
||||
# Helper for use after calling send_*_instructions methods on a resource.
|
||||
# If we are in paranoid mode, we always act as if the resource was valid
|
||||
# and instructions were sent.
|
||||
def successfully_sent?(resource)
|
||||
notice = if Devise.paranoid
|
||||
resource.errors.clear
|
||||
:send_paranoid_instructions
|
||||
elsif resource.errors.empty?
|
||||
:send_instructions
|
||||
end
|
||||
|
||||
if notice
|
||||
set_flash_message :notice, notice if is_navigational_format?
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
# Sets the flash message with :key, using I18n. By default you are able
|
||||
# to setup your messages using specific resource scope, and if no one is
|
||||
# found we look to default scope.
|
||||
# Example (i18n locale file):
|
||||
#
|
||||
# en:
|
||||
# devise:
|
||||
# passwords:
|
||||
# #default_scope_messages - only if resource_scope is not found
|
||||
# user:
|
||||
# #resource_scope_messages
|
||||
#
|
||||
# Please refer to README or en.yml locale file to check what messages are
|
||||
# available.
|
||||
def set_flash_message(key, kind, options={})
|
||||
options[:scope] = "devise.#{controller_name}"
|
||||
options[:default] = Array(options[:default]).unshift(kind.to_sym)
|
||||
options[:resource_name] = resource_name
|
||||
message = I18n.t("#{resource_name}.#{kind}", options)
|
||||
flash[key] = message if message.present?
|
||||
end
|
||||
|
||||
def clean_up_passwords(object)
|
||||
object.clean_up_passwords if object.respond_to?(:clean_up_passwords)
|
||||
end
|
||||
|
||||
def respond_with_navigational(*args, &block)
|
||||
respond_with(*args) do |format|
|
||||
format.any(*navigational_formats, &block)
|
||||
end
|
||||
end
|
||||
|
||||
def request_format
|
||||
@request_format ||= request.format.try(:ref)
|
||||
end
|
||||
|
||||
def is_navigational_format?
|
||||
Devise.navigational_formats.include?(request.format.try(:ref))
|
||||
end
|
||||
|
||||
# Override prefixes to consider the scoped view.
|
||||
def _prefixes #:nodoc:
|
||||
@_prefixes ||= if self.class.scoped_views?
|
||||
super.unshift("#{devise_mapping.scoped_path}/#{controller_name}")
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -11,7 +11,7 @@ module DeviseHelper
|
||||
messages = resource.errors.full_messages.map { |msg| content_tag(:li, msg) }.join
|
||||
sentence = I18n.t("errors.messages.not_saved",
|
||||
:count => resource.errors.count,
|
||||
:resource => resource_name)
|
||||
:resource => resource.class.model_name.human.downcase)
|
||||
|
||||
html = <<-HTML
|
||||
<div id="error_explanation">
|
||||
|
||||
@@ -1,88 +1,15 @@
|
||||
class Devise::Mailer < ::ActionMailer::Base
|
||||
include Devise::Controllers::ScopedViews
|
||||
attr_reader :scope_name, :resource
|
||||
include Devise::Mailers::Helpers
|
||||
|
||||
def confirmation_instructions(record)
|
||||
setup_mail(record, :confirmation_instructions)
|
||||
devise_mail(record, :confirmation_instructions)
|
||||
end
|
||||
|
||||
def reset_password_instructions(record)
|
||||
setup_mail(record, :reset_password_instructions)
|
||||
devise_mail(record, :reset_password_instructions)
|
||||
end
|
||||
|
||||
def unlock_instructions(record)
|
||||
setup_mail(record, :unlock_instructions)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Configure default email options
|
||||
def setup_mail(record, action)
|
||||
initialize_from_record(record)
|
||||
mail headers_for(action)
|
||||
end
|
||||
|
||||
def initialize_from_record(record)
|
||||
@scope_name = Devise::Mapping.find_scope!(record)
|
||||
@resource = instance_variable_set("@#{devise_mapping.name}", record)
|
||||
end
|
||||
|
||||
def devise_mapping
|
||||
@devise_mapping ||= Devise.mappings[scope_name]
|
||||
end
|
||||
|
||||
def headers_for(action)
|
||||
headers = {
|
||||
:subject => translate(devise_mapping, action),
|
||||
:from => mailer_sender(devise_mapping),
|
||||
:to => resource.email,
|
||||
:template_path => template_paths
|
||||
}
|
||||
|
||||
if resource.respond_to?(:headers_for)
|
||||
headers.merge!(resource.headers_for(action))
|
||||
end
|
||||
|
||||
unless headers.key?(:reply_to)
|
||||
headers[:reply_to] = headers[:from]
|
||||
end
|
||||
|
||||
headers
|
||||
end
|
||||
|
||||
def mailer_sender(mapping)
|
||||
if Devise.mailer_sender.is_a?(Proc)
|
||||
Devise.mailer_sender.call(mapping.name)
|
||||
else
|
||||
Devise.mailer_sender
|
||||
end
|
||||
end
|
||||
|
||||
def template_paths
|
||||
template_path = [self.class.mailer_name]
|
||||
template_path.unshift "#{@devise_mapping.scoped_path}/mailer" if self.class.scoped_views?
|
||||
template_path
|
||||
end
|
||||
|
||||
# Setup a subject doing an I18n lookup. At first, it attemps to set a subject
|
||||
# based on the current mapping:
|
||||
#
|
||||
# en:
|
||||
# devise:
|
||||
# mailer:
|
||||
# confirmation_instructions:
|
||||
# user_subject: '...'
|
||||
#
|
||||
# If one does not exist, it fallbacks to ActionMailer default:
|
||||
#
|
||||
# en:
|
||||
# devise:
|
||||
# mailer:
|
||||
# confirmation_instructions:
|
||||
# subject: '...'
|
||||
#
|
||||
def translate(mapping, key)
|
||||
I18n.t(:"#{mapping.name}_subject", :scope => [:devise, :mailer, key],
|
||||
:default => [:subject, key.to_s.humanize])
|
||||
devise_mail(record, :unlock_instructions)
|
||||
end
|
||||
end
|
||||
|
||||
25
app/views/devise/_links.erb
Normal file
25
app/views/devise/_links.erb
Normal file
@@ -0,0 +1,25 @@
|
||||
<%- if controller_name != 'sessions' %>
|
||||
<%= link_to "Sign in", new_session_path(resource_name) %><br />
|
||||
<% end -%>
|
||||
|
||||
<%- if devise_mapping.registerable? && controller_name != 'registrations' %>
|
||||
<%= link_to "Sign up", new_registration_path(resource_name) %><br />
|
||||
<% end -%>
|
||||
|
||||
<%- if devise_mapping.recoverable? && controller_name != 'passwords' %>
|
||||
<%= link_to "Forgot your password?", new_password_path(resource_name) %><br />
|
||||
<% end -%>
|
||||
|
||||
<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
|
||||
<%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %><br />
|
||||
<% end -%>
|
||||
|
||||
<%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %>
|
||||
<%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %><br />
|
||||
<% end -%>
|
||||
|
||||
<%- 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 />
|
||||
<% end -%>
|
||||
<% end -%>
|
||||
@@ -3,10 +3,10 @@
|
||||
<%= form_for(resource, :as => resource_name, :url => confirmation_path(resource_name), :html => { :method => :post }) do |f| %>
|
||||
<%= devise_error_messages! %>
|
||||
|
||||
<p><%= f.label :email %><br />
|
||||
<%= f.email_field :email %></p>
|
||||
<div><%= f.label :email %><br />
|
||||
<%= f.email_field :email %></div>
|
||||
|
||||
<p><%= f.submit "Resend confirmation instructions" %></p>
|
||||
<div><%= f.submit "Resend confirmation instructions" %></div>
|
||||
<% end %>
|
||||
|
||||
<%= render :partial => "devise/shared/links" %>
|
||||
<%= render "links" %>
|
||||
@@ -1,5 +1,5 @@
|
||||
<p>Welcome <%= @resource.email %>!</p>
|
||||
|
||||
<p>You can confirm your account through the link below:</p>
|
||||
<p>You can confirm your account email through the link below:</p>
|
||||
|
||||
<p><%= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) %></p>
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
<%= devise_error_messages! %>
|
||||
<%= f.hidden_field :reset_password_token %>
|
||||
|
||||
<p><%= f.label :password, "New password" %><br />
|
||||
<%= f.password_field :password %></p>
|
||||
<div><%= f.label :password, "New password" %><br />
|
||||
<%= f.password_field :password %></div>
|
||||
|
||||
<p><%= f.label :password_confirmation, "Confirm new password" %><br />
|
||||
<%= f.password_field :password_confirmation %></p>
|
||||
<div><%= f.label :password_confirmation, "Confirm new password" %><br />
|
||||
<%= f.password_field :password_confirmation %></div>
|
||||
|
||||
<p><%= f.submit "Change my password" %></p>
|
||||
<div><%= f.submit "Change my password" %></div>
|
||||
<% end %>
|
||||
|
||||
<%= render :partial => "devise/shared/links" %>
|
||||
<%= render "links" %>
|
||||
@@ -3,10 +3,10 @@
|
||||
<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :post }) do |f| %>
|
||||
<%= devise_error_messages! %>
|
||||
|
||||
<p><%= f.label :email %><br />
|
||||
<%= f.email_field :email %></p>
|
||||
<div><%= f.label :email %><br />
|
||||
<%= f.email_field :email %></div>
|
||||
|
||||
<p><%= f.submit "Send me reset password instructions" %></p>
|
||||
<div><%= f.submit "Send me reset password instructions" %></div>
|
||||
<% end %>
|
||||
|
||||
<%= render :partial => "devise/shared/links" %>
|
||||
<%= render "links" %>
|
||||
@@ -3,19 +3,19 @@
|
||||
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %>
|
||||
<%= devise_error_messages! %>
|
||||
|
||||
<p><%= f.label :email %><br />
|
||||
<%= f.email_field :email %></p>
|
||||
<div><%= f.label :email %><br />
|
||||
<%= f.email_field :email %></div>
|
||||
|
||||
<p><%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
|
||||
<%= f.password_field :password %></p>
|
||||
<div><%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
|
||||
<%= f.password_field :password %></div>
|
||||
|
||||
<p><%= f.label :password_confirmation %><br />
|
||||
<%= f.password_field :password_confirmation %></p>
|
||||
<div><%= f.label :password_confirmation %><br />
|
||||
<%= f.password_field :password_confirmation %></div>
|
||||
|
||||
<p><%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
|
||||
<%= f.password_field :current_password %></p>
|
||||
<div><%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
|
||||
<%= f.password_field :current_password %></div>
|
||||
|
||||
<p><%= f.submit "Update" %></p>
|
||||
<div><%= f.submit "Update" %></div>
|
||||
<% end %>
|
||||
|
||||
<h3>Cancel my account</h3>
|
||||
|
||||
@@ -3,16 +3,16 @@
|
||||
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
|
||||
<%= devise_error_messages! %>
|
||||
|
||||
<p><%= f.label :email %><br />
|
||||
<%= f.email_field :email %></p>
|
||||
<div><%= f.label :email %><br />
|
||||
<%= f.email_field :email %></div>
|
||||
|
||||
<p><%= f.label :password %><br />
|
||||
<%= f.password_field :password %></p>
|
||||
<div><%= f.label :password %><br />
|
||||
<%= f.password_field :password %></div>
|
||||
|
||||
<p><%= f.label :password_confirmation %><br />
|
||||
<%= f.password_field :password_confirmation %></p>
|
||||
<div><%= f.label :password_confirmation %><br />
|
||||
<%= f.password_field :password_confirmation %></div>
|
||||
|
||||
<p><%= f.submit "Sign up" %></p>
|
||||
<div><%= f.submit "Sign up" %></div>
|
||||
<% end %>
|
||||
|
||||
<%= render :partial => "devise/shared/links" %>
|
||||
<%= render "links" %>
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
<h2>Sign in</h2>
|
||||
|
||||
<%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
|
||||
<p><%= f.label :email %><br />
|
||||
<%= f.email_field :email %></p>
|
||||
<div><%= f.label :email %><br />
|
||||
<%= f.email_field :email %></div>
|
||||
|
||||
<p><%= f.label :password %><br />
|
||||
<%= f.password_field :password %></p>
|
||||
<div><%= f.label :password %><br />
|
||||
<%= f.password_field :password %></div>
|
||||
|
||||
<% if devise_mapping.rememberable? -%>
|
||||
<p><%= f.check_box :remember_me %> <%= f.label :remember_me %></p>
|
||||
<div><%= f.check_box :remember_me %> <%= f.label :remember_me %></div>
|
||||
<% end -%>
|
||||
|
||||
<p><%= f.submit "Sign in" %></p>
|
||||
<div><%= f.submit "Sign in" %></div>
|
||||
<% end %>
|
||||
|
||||
<%= render :partial => "devise/shared/links" %>
|
||||
<%= render "links" %>
|
||||
@@ -1,25 +1,3 @@
|
||||
<%- if controller_name != 'sessions' %>
|
||||
<%= link_to "Sign in", new_session_path(resource_name) %><br />
|
||||
<% end -%>
|
||||
|
||||
<%- if devise_mapping.registerable? && controller_name != 'registrations' %>
|
||||
<%= link_to "Sign up", new_registration_path(resource_name) %><br />
|
||||
<% end -%>
|
||||
|
||||
<%- if devise_mapping.recoverable? && controller_name != 'passwords' %>
|
||||
<%= link_to "Forgot your password?", new_password_path(resource_name) %><br />
|
||||
<% end -%>
|
||||
|
||||
<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
|
||||
<%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %><br />
|
||||
<% end -%>
|
||||
|
||||
<%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %>
|
||||
<%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %><br />
|
||||
<% end -%>
|
||||
|
||||
<%- 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 />
|
||||
<% end -%>
|
||||
<% end -%>
|
||||
<% ActiveSupport::Deprecation.warn "Rendering partials devise/shared/_links.erb is deprecated" \
|
||||
"please use devise/_links.erb instead." %>
|
||||
<%= render "links" %>
|
||||
@@ -3,10 +3,10 @@
|
||||
<%= form_for(resource, :as => resource_name, :url => unlock_path(resource_name), :html => { :method => :post }) do |f| %>
|
||||
<%= devise_error_messages! %>
|
||||
|
||||
<p><%= f.label :email %><br />
|
||||
<%= f.email_field :email %></p>
|
||||
<div><%= f.label :email %><br />
|
||||
<%= f.email_field :email %></div>
|
||||
|
||||
<p><%= f.submit "Resend unlock instructions" %></p>
|
||||
<div><%= f.submit "Resend unlock instructions" %></div>
|
||||
<% end %>
|
||||
|
||||
<%= render :partial => "devise/shared/links" %>
|
||||
<%= render "links" %>
|
||||
@@ -1,8 +1,9 @@
|
||||
# Additional translations at http://github.com/plataformatec/devise/wiki/I18n
|
||||
# Additional translations at https://github.com/plataformatec/devise/wiki/I18n
|
||||
|
||||
en:
|
||||
errors:
|
||||
messages:
|
||||
expired: "has expired, please request a new one"
|
||||
not_found: "not found"
|
||||
already_confirmed: "was already confirmed, please try signing in"
|
||||
not_locked: "was not locked"
|
||||
@@ -12,6 +13,7 @@ en:
|
||||
|
||||
devise:
|
||||
failure:
|
||||
already_authenticated: 'You are already signed in.'
|
||||
unauthenticated: 'You need to sign in or sign up before continuing.'
|
||||
unconfirmed: 'You have to confirm your account before continuing.'
|
||||
locked: 'Your account is locked.'
|
||||
@@ -25,17 +27,24 @@ en:
|
||||
passwords:
|
||||
send_instructions: 'You will receive an email with instructions about how to reset your password in a few minutes.'
|
||||
updated: 'Your password was changed successfully. You are now signed in.'
|
||||
updated_not_active: 'Your password was changed successfully.'
|
||||
send_paranoid_instructions: "If your e-mail exists on our database, you will receive a password recovery link on your e-mail"
|
||||
confirmations:
|
||||
send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.'
|
||||
send_paranoid_instructions: 'If your e-mail exists on our database, you will receive an email with instructions about how to confirm your account in a few minutes.'
|
||||
confirmed: 'Your account was successfully confirmed. You are now signed in.'
|
||||
registrations:
|
||||
signed_up: 'Welcome! You have signed up successfully.'
|
||||
inactive_signed_up: 'You have signed up successfully. However, we could not sign you in because your account is %{reason}.'
|
||||
signed_up_but_unconfirmed: 'A message with a confirmation link has been sent to your email address. Please open the link to activate your account.'
|
||||
signed_up_but_inactive: 'You have signed up successfully. However, we could not sign you in because your account is not yet activated.'
|
||||
signed_up_but_locked: 'You have signed up successfully. However, we could not sign you in because your account is locked.'
|
||||
updated: 'You updated your account successfully.'
|
||||
update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and click on the confirm link to finalize confirming your new email address."
|
||||
destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.'
|
||||
unlocks:
|
||||
send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.'
|
||||
unlocked: 'Your account was successfully unlocked. You are now signed in.'
|
||||
unlocked: 'Your account has been unlocked successfully. Please sign in to continue.'
|
||||
send_paranoid_instructions: 'If your account exists, you will receive an email with instructions about how to unlock it in a few minutes.'
|
||||
omniauth_callbacks:
|
||||
success: 'Successfully authorized from %{kind} account.'
|
||||
failure: 'Could not authorize you from %{kind} because "%{reason}".'
|
||||
|
||||
@@ -5,7 +5,7 @@ require "devise/version"
|
||||
Gem::Specification.new do |s|
|
||||
s.name = "devise"
|
||||
s.version = Devise::VERSION.dup
|
||||
s.platform = Gem::Platform::RUBY
|
||||
s.platform = Gem::Platform::RUBY
|
||||
s.summary = "Flexible authentication solution for Rails with Warden"
|
||||
s.email = "contact@plataformatec.com.br"
|
||||
s.homepage = "http://github.com/plataformatec/devise"
|
||||
@@ -15,11 +15,11 @@ Gem::Specification.new do |s|
|
||||
s.rubyforge_project = "devise"
|
||||
|
||||
s.files = `git ls-files`.split("\n")
|
||||
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
||||
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
||||
s.test_files = `git ls-files -- test/*`.split("\n")
|
||||
s.require_paths = ["lib"]
|
||||
|
||||
s.add_dependency("warden", "~> 1.0.3")
|
||||
s.add_dependency("warden", "~> 1.1")
|
||||
s.add_dependency("orm_adapter", "~> 0.0.3")
|
||||
s.add_dependency("bcrypt-ruby", "~> 2.1.2")
|
||||
end
|
||||
s.add_dependency("bcrypt-ruby", "~> 3.0")
|
||||
s.add_dependency("railties", "~> 3.1")
|
||||
end
|
||||
|
||||
35
gemfiles/Gemfile.rails-3.1.x
Normal file
35
gemfiles/Gemfile.rails-3.1.x
Normal file
@@ -0,0 +1,35 @@
|
||||
source "http://rubygems.org"
|
||||
|
||||
gem "devise", :path => ".."
|
||||
|
||||
gem "rails", "~> 3.1.0"
|
||||
gem "omniauth", "~> 1.0.0"
|
||||
gem "omniauth-oauth2", "~> 1.0.0"
|
||||
gem "rdoc"
|
||||
|
||||
group :test do
|
||||
gem "omniauth-facebook"
|
||||
gem "omniauth-openid", "~> 1.0.1"
|
||||
gem "webrat", "0.7.2", :require => false
|
||||
gem "mocha", :require => false
|
||||
|
||||
platforms :mri_18 do
|
||||
gem "ruby-debug", ">= 0.10.3"
|
||||
end
|
||||
end
|
||||
|
||||
platforms :jruby do
|
||||
gem "activerecord-jdbc-adapter"
|
||||
gem "activerecord-jdbcsqlite3-adapter"
|
||||
gem "jruby-openssl"
|
||||
end
|
||||
|
||||
platforms :ruby do
|
||||
gem "sqlite3-ruby"
|
||||
|
||||
group :mongoid do
|
||||
gem "mongo", "~> 1.3.0"
|
||||
gem "mongoid", "~> 2.0"
|
||||
gem "bson_ext", "~> 1.3.0"
|
||||
end
|
||||
end
|
||||
166
lib/devise.rb
166
lib/devise.rb
@@ -3,17 +3,19 @@ require 'active_support/core_ext/numeric/time'
|
||||
require 'active_support/dependencies'
|
||||
require 'orm_adapter'
|
||||
require 'set'
|
||||
require 'securerandom'
|
||||
|
||||
module Devise
|
||||
autoload :FailureApp, 'devise/failure_app'
|
||||
autoload :OmniAuth, 'devise/omniauth'
|
||||
autoload :Delegator, 'devise/delegator'
|
||||
autoload :FailureApp, 'devise/failure_app'
|
||||
autoload :OmniAuth, 'devise/omniauth'
|
||||
autoload :ParamFilter, 'devise/param_filter'
|
||||
autoload :PathChecker, 'devise/path_checker'
|
||||
autoload :Schema, 'devise/schema'
|
||||
autoload :Schema, 'devise/schema'
|
||||
autoload :TestHelpers, 'devise/test_helpers'
|
||||
|
||||
module Controllers
|
||||
autoload :Helpers, 'devise/controllers/helpers'
|
||||
autoload :InternalHelpers, 'devise/controllers/internal_helpers'
|
||||
autoload :Rememberable, 'devise/controllers/rememberable'
|
||||
autoload :ScopedViews, 'devise/controllers/scoped_views'
|
||||
autoload :UrlHelpers, 'devise/controllers/url_helpers'
|
||||
@@ -28,6 +30,10 @@ module Devise
|
||||
autoload :Sha1, 'devise/encryptors/sha1'
|
||||
end
|
||||
|
||||
module Mailers
|
||||
autoload :Helpers, 'devise/mailers/helpers'
|
||||
end
|
||||
|
||||
module Strategies
|
||||
autoload :Base, 'devise/strategies/base'
|
||||
autoload :Authenticatable, 'devise/strategies/authenticatable'
|
||||
@@ -41,6 +47,9 @@ module Devise
|
||||
STRATEGIES = ActiveSupport::OrderedHash.new
|
||||
URL_HELPERS = ActiveSupport::OrderedHash.new
|
||||
|
||||
# Strategies that do not require user input.
|
||||
NO_INPUT = []
|
||||
|
||||
# True values used to check params
|
||||
TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE']
|
||||
|
||||
@@ -74,6 +83,11 @@ module Devise
|
||||
mattr_accessor :case_insensitive_keys
|
||||
@@case_insensitive_keys = false
|
||||
|
||||
# Keys that should have whitespace stripped.
|
||||
# False by default for backwards compatibility.
|
||||
mattr_accessor :strip_whitespace_keys
|
||||
@@strip_whitespace_keys = false
|
||||
|
||||
# If http authentication is enabled by default.
|
||||
mattr_accessor :http_authenticatable
|
||||
@@http_authenticatable = false
|
||||
@@ -90,39 +104,37 @@ module Devise
|
||||
mattr_accessor :http_authentication_realm
|
||||
@@http_authentication_realm = "Application"
|
||||
|
||||
# Email regex used to validate email formats. Adapted from authlogic.
|
||||
# Email regex used to validate email formats. It simply asserts that
|
||||
# an one (and only one) @ exists in the given string. This is mainly
|
||||
# to give user feedback and not to assert the e-mail validity.
|
||||
mattr_accessor :email_regexp
|
||||
@@email_regexp = /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i
|
||||
@@email_regexp = /\A[^@]+@([^@\.]+\.)+[^@\.]+\z/
|
||||
|
||||
# Range validation for password length
|
||||
mattr_accessor :password_length
|
||||
@@password_length = 6..20
|
||||
@@password_length = 6..128
|
||||
|
||||
# The time the user will be remembered without asking for credentials again.
|
||||
mattr_accessor :remember_for
|
||||
@@remember_for = 2.weeks
|
||||
|
||||
# If true, a valid remember token can be re-used between multiple browsers.
|
||||
mattr_accessor :remember_across_browsers
|
||||
@@remember_across_browsers = true
|
||||
|
||||
# If true, extends the user's remember period when remembered via cookie.
|
||||
mattr_accessor :extend_remember_period
|
||||
@@extend_remember_period = false
|
||||
|
||||
# If true, uses salt as remember token and does not create it in the database.
|
||||
# By default is false for backwards compatibility.
|
||||
mattr_accessor :use_salt_as_remember_token
|
||||
@@use_salt_as_remember_token = false
|
||||
|
||||
# Time interval you can access your account before confirming your account.
|
||||
mattr_accessor :confirm_within
|
||||
@@confirm_within = 0.days
|
||||
mattr_accessor :allow_unconfirmed_access_for
|
||||
@@allow_unconfirmed_access_for = 0.days
|
||||
|
||||
# Defines which key will be used when confirming an account
|
||||
# Defines which key will be used when confirming an account.
|
||||
mattr_accessor :confirmation_keys
|
||||
@@confirmation_keys = [ :email ]
|
||||
|
||||
# Defines if email should be reconfirmable.
|
||||
# False by default for backwards compatibility.
|
||||
mattr_accessor :reconfirmable
|
||||
@@reconfirmable = false
|
||||
|
||||
# Time interval to timeout the user session without activity.
|
||||
mattr_accessor :timeout_in
|
||||
@@timeout_in = 30.minutes
|
||||
@@ -135,11 +147,6 @@ module Devise
|
||||
mattr_accessor :encryptor
|
||||
@@encryptor = nil
|
||||
|
||||
# Tells if devise should apply the schema in ORMs where devise declaration
|
||||
# and schema belongs to the same class (as Datamapper and Mongoid).
|
||||
mattr_accessor :apply_schema
|
||||
@@apply_schema = true
|
||||
|
||||
# Scoped views. Since it relies on fallbacks to render default views, it's
|
||||
# turned off by default.
|
||||
mattr_accessor :scoped_views
|
||||
@@ -171,6 +178,11 @@ module Devise
|
||||
mattr_accessor :reset_password_keys
|
||||
@@reset_password_keys = [ :email ]
|
||||
|
||||
# Time interval you can reset your password with a reset password key
|
||||
# Nil by default for backwards compatibility.
|
||||
mattr_accessor :reset_password_within
|
||||
@@reset_password_within = nil
|
||||
|
||||
# The default scope which is used by warden.
|
||||
mattr_accessor :default_scope
|
||||
@@default_scope = nil
|
||||
@@ -183,14 +195,13 @@ module Devise
|
||||
mattr_accessor :token_authentication_key
|
||||
@@token_authentication_key = :auth_token
|
||||
|
||||
# If true, authentication through token does not store user in session
|
||||
mattr_accessor :stateless_token
|
||||
@@stateless_token = false
|
||||
# Skip session storage for the following strategies
|
||||
mattr_accessor :skip_session_storage
|
||||
@@skip_session_storage = []
|
||||
|
||||
# Which formats should be treated as navigational.
|
||||
# We need both :"*/*" and "*/*" to work on different Rails versions.
|
||||
mattr_accessor :navigational_formats
|
||||
@@navigational_formats = [:"*/*", "*/*", :html]
|
||||
@@navigational_formats = ["*/*", :html]
|
||||
|
||||
# When set to true, signing out a user signs out all other scopes.
|
||||
mattr_accessor :sign_out_all_scopes
|
||||
@@ -200,6 +211,45 @@ module Devise
|
||||
mattr_accessor :sign_out_via
|
||||
@@sign_out_via = :get
|
||||
|
||||
# The parent controller all Devise controllers inherits from.
|
||||
# Defaults to ApplicationController. This should be set early
|
||||
# in the initialization process and should be set to a string.
|
||||
mattr_accessor :parent_controller
|
||||
@@parent_controller = "ApplicationController"
|
||||
|
||||
# The router Devise should use to generate routes. Defaults
|
||||
# to :main_app. Should be overriden by engines in order
|
||||
# to provide custom routes.
|
||||
mattr_accessor :router_name
|
||||
@@router_name = nil
|
||||
|
||||
# DEPRECATED CONFIG
|
||||
|
||||
# If true, uses salt as remember token and does not create it in the database.
|
||||
# By default is false for backwards compatibility.
|
||||
mattr_accessor :use_salt_as_remember_token
|
||||
@@use_salt_as_remember_token = false
|
||||
|
||||
# Tells if devise should apply the schema in ORMs where devise declaration
|
||||
# and schema belongs to the same class (as Datamapper and Mongoid).
|
||||
mattr_accessor :apply_schema
|
||||
@@apply_schema = true
|
||||
|
||||
def self.remember_across_browsers=(value)
|
||||
warn "\n[DEVISE] Devise.remember_across_browsers is deprecated and has no effect. Please remove it.\n"
|
||||
end
|
||||
|
||||
def self.confirm_within=(value)
|
||||
warn "\n[DEVISE] Devise.confirm_within= is deprecated. Please set Devise.allow_unconfirmed_access_for= instead.\n"
|
||||
Devise.allow_unconfirmed_access_for = value
|
||||
end
|
||||
|
||||
def self.stateless_token=(value)
|
||||
warn "\n[DEVISE] Devise.stateless_token= is deprecated. Please append :token_auth to Devise.skip_session_storage " \
|
||||
"instead, for example: Devise.skip_session_storage << :token_auth\n"
|
||||
Devise.skip_session_storage << :token_auth
|
||||
end
|
||||
|
||||
# PRIVATE CONFIGURATION
|
||||
|
||||
# Store scopes mappings.
|
||||
@@ -220,15 +270,30 @@ module Devise
|
||||
@@warden_config = nil
|
||||
@@warden_config_block = nil
|
||||
|
||||
# When true, enter in paranoid mode to avoid user enumeration.
|
||||
mattr_accessor :paranoid
|
||||
@@paranoid = false
|
||||
|
||||
# Default way to setup Devise. Run rails generate devise_install to create
|
||||
# a fresh initializer with all configuration values.
|
||||
def self.setup
|
||||
yield self
|
||||
end
|
||||
|
||||
class Getter
|
||||
def initialize name
|
||||
@name = name
|
||||
end
|
||||
|
||||
def get
|
||||
ActiveSupport::Dependencies.constantize(@name)
|
||||
end
|
||||
end
|
||||
|
||||
def self.ref(arg)
|
||||
if defined?(ActiveSupport::Dependencies::ClassCache)
|
||||
ActiveSupport::Dependencies::Reference.store(arg)
|
||||
ActiveSupport::Dependencies::reference(arg)
|
||||
Getter.new(arg)
|
||||
else
|
||||
ActiveSupport::Dependencies.ref(arg)
|
||||
end
|
||||
@@ -238,19 +303,9 @@ module Devise
|
||||
omniauth_configs.keys
|
||||
end
|
||||
|
||||
def self.cookie_domain=(value)
|
||||
ActiveSupport::Deprecation.warn "Devise.cookie_domain=(value) is deprecated. "
|
||||
"Please use Devise.cookie_options = { :domain => value } instead."
|
||||
self.cookie_options[:domain] = value
|
||||
end
|
||||
|
||||
# Get the mailer class from the mailer reference object.
|
||||
def self.mailer
|
||||
if defined?(ActiveSupport::Dependencies::ClassCache)
|
||||
@@mailer_ref.get "Devise::Mailer"
|
||||
else
|
||||
@@mailer_ref.get
|
||||
end
|
||||
@@mailer_ref.get
|
||||
end
|
||||
|
||||
# Set the mailer reference object to access the mailer.
|
||||
@@ -288,16 +343,20 @@ module Devise
|
||||
#
|
||||
def self.add_module(module_name, options = {})
|
||||
ALL << module_name
|
||||
options.assert_valid_keys(:strategy, :model, :controller, :route)
|
||||
options.assert_valid_keys(:strategy, :model, :controller, :route, :no_input)
|
||||
|
||||
if strategy = options[:strategy]
|
||||
STRATEGIES[module_name] = (strategy == true ? module_name : strategy)
|
||||
strategy = (strategy == true ? module_name : strategy)
|
||||
STRATEGIES[module_name] = strategy
|
||||
end
|
||||
|
||||
if controller = options[:controller]
|
||||
CONTROLLERS[module_name] = (controller == true ? module_name : controller)
|
||||
controller = (controller == true ? module_name : controller)
|
||||
CONTROLLERS[module_name] = controller
|
||||
end
|
||||
|
||||
NO_INPUT << strategy if options[:no_input]
|
||||
|
||||
if route = options[:route]
|
||||
case route
|
||||
when TrueClass
|
||||
@@ -319,7 +378,8 @@ module Devise
|
||||
|
||||
if options[:model]
|
||||
path = (options[:model] == true ? "devise/models/#{module_name}" : options[:model])
|
||||
Devise::Models.send(:autoload, module_name.to_s.camelize.to_sym, path)
|
||||
camelized = ActiveSupport::Inflector.camelize(module_name.to_s)
|
||||
Devise::Models.send(:autoload, camelized.to_sym, path)
|
||||
end
|
||||
|
||||
Devise::Mapping.add_module module_name
|
||||
@@ -329,7 +389,7 @@ module Devise
|
||||
# initialization.
|
||||
#
|
||||
# Devise.initialize do |config|
|
||||
# config.confirm_within = 2.days
|
||||
# config.allow_unconfirmed_access_for = 2.days
|
||||
#
|
||||
# config.warden do |manager|
|
||||
# # Configure warden to use other strategies, like oauth.
|
||||
@@ -346,7 +406,8 @@ module Devise
|
||||
#
|
||||
def self.omniauth(provider, *args)
|
||||
@@helpers << Devise::OmniAuth::UrlHelpers
|
||||
@@omniauth_configs[provider] = Devise::OmniAuth::Config.new(provider, args)
|
||||
config = Devise::OmniAuth::Config.new(provider, args)
|
||||
@@omniauth_configs[config.strategy_name.to_sym] = config
|
||||
end
|
||||
|
||||
# Include helpers in the given scope to AC and AV.
|
||||
@@ -361,16 +422,17 @@ module Devise
|
||||
end
|
||||
end
|
||||
|
||||
# Returns true if Rails version is bigger than 3.0.x
|
||||
def self.rack_session?
|
||||
Rails::VERSION::STRING[0,3] != "3.0"
|
||||
# Regenerates url helpers considering Devise.mapping
|
||||
def self.regenerate_helpers!
|
||||
Devise::Controllers::UrlHelpers.remove_helpers!
|
||||
Devise::Controllers::UrlHelpers.generate_helpers!
|
||||
end
|
||||
|
||||
# A method used internally to setup warden manager from the Rails initialize
|
||||
# block.
|
||||
def self.configure_warden! #:nodoc:
|
||||
@@warden_configured ||= begin
|
||||
warden_config.failure_app = Devise::FailureApp
|
||||
warden_config.failure_app = Devise::Delegator.new
|
||||
warden_config.default_scope = Devise.default_scope
|
||||
warden_config.intercept_401 = false
|
||||
|
||||
@@ -385,7 +447,7 @@ module Devise
|
||||
|
||||
# Generate a friendly string randomically to be used as token.
|
||||
def self.friendly_token
|
||||
ActiveSupport::SecureRandom.base64(15).tr('+/=', 'xyz')
|
||||
SecureRandom.base64(15).tr('+/=lIO0', 'pqrsxyz')
|
||||
end
|
||||
|
||||
# constant-time comparison algorithm to prevent timing attacks
|
||||
|
||||
@@ -5,7 +5,14 @@ module Devise
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
helper_method :warden, :signed_in?, :devise_controller?, :anybody_signed_in?
|
||||
helper_method :warden, :signed_in?, :devise_controller?
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
def log_process_action(payload)
|
||||
payload[:status] ||= 401 unless payload[:exception]
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
# Define authentication filters and accessor helpers based on mappings.
|
||||
@@ -36,8 +43,9 @@ module Devise
|
||||
mapping = mapping.name
|
||||
|
||||
class_eval <<-METHODS, __FILE__, __LINE__ + 1
|
||||
def authenticate_#{mapping}!(force = false)
|
||||
warden.authenticate!(:scope => :#{mapping}) if !devise_controller? || force
|
||||
def authenticate_#{mapping}!(opts={})
|
||||
opts[:scope] = :#{mapping}
|
||||
warden.authenticate!(opts) if !devise_controller? || opts.delete(:force)
|
||||
end
|
||||
|
||||
def #{mapping}_signed_in?
|
||||
@@ -72,20 +80,19 @@ module Devise
|
||||
false
|
||||
end
|
||||
|
||||
# Tell warden that params authentication is allowed for that specific page.
|
||||
def allow_params_authentication!
|
||||
request.env["devise.allow_params_authentication"] = true
|
||||
end
|
||||
|
||||
# Return true if the given scope is signed in session. If no scope given, return
|
||||
# true if any scope is signed in. Does not run authentication hooks.
|
||||
def signed_in?(scope=nil)
|
||||
[ scope || Devise.mappings.keys ].flatten.any? do |scope|
|
||||
[ scope || Devise.mappings.keys ].flatten.any? do |scope|
|
||||
warden.authenticate?(:scope => scope)
|
||||
end
|
||||
end
|
||||
|
||||
def anybody_signed_in?
|
||||
ActiveSupport::Deprecation.warn "Devise#anybody_signed_in? is deprecated. "
|
||||
"Please use Devise#signed_in?(nil) instead."
|
||||
signed_in?
|
||||
end
|
||||
|
||||
# Sign in a user that already was authenticated. This helper is useful for logging
|
||||
# users in after sign up.
|
||||
#
|
||||
@@ -100,7 +107,7 @@ module Devise
|
||||
# sign_in @user # sign_in(resource)
|
||||
# sign_in @user, :event => :authentication # sign_in(resource, options)
|
||||
# sign_in @user, :bypass => true # sign_in(resource, options)
|
||||
#
|
||||
#
|
||||
def sign_in(resource_or_scope, *args)
|
||||
options = args.extract_options!
|
||||
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
||||
@@ -112,6 +119,7 @@ module Devise
|
||||
warden.session_serializer.store(resource, scope)
|
||||
elsif warden.user(scope) == resource && !options.delete(:force)
|
||||
# Do nothing. User already signed in and we are not forcing it.
|
||||
true
|
||||
else
|
||||
warden.set_user(resource, options.merge!(:scope => scope))
|
||||
end
|
||||
@@ -131,6 +139,7 @@ module Devise
|
||||
warden.user(scope) # Without loading user here, before_logout hook is not called
|
||||
warden.raw_session.inspect # Without this inspect here. The session does not clear.
|
||||
warden.logout(scope)
|
||||
instance_variable_set(:"@current_#{scope}", nil)
|
||||
end
|
||||
|
||||
# Sign out all active users or scopes. This helper is useful for signing out all roles
|
||||
@@ -139,6 +148,7 @@ module Devise
|
||||
Devise.mappings.keys.each { |s| warden.user(s) }
|
||||
warden.raw_session.inspect
|
||||
warden.logout
|
||||
expire_devise_cached_variables!
|
||||
end
|
||||
|
||||
# Returns and delete the url stored in the session for the given scope. Useful
|
||||
@@ -153,12 +163,27 @@ module Devise
|
||||
session.delete("#{scope}_return_to")
|
||||
end
|
||||
|
||||
# The scope root url to be used when he's signed in. By default, it first
|
||||
# tries to find a resource_root_path, otherwise it uses the root_path.
|
||||
def signed_in_root_path(resource_or_scope)
|
||||
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
||||
home_path = "#{scope}_root_path"
|
||||
if respond_to?(home_path, true)
|
||||
send(home_path)
|
||||
elsif respond_to?(:root_path)
|
||||
root_path
|
||||
else
|
||||
"/"
|
||||
end
|
||||
end
|
||||
|
||||
# The default url to be used after signing in. This is used by all Devise
|
||||
# controllers and you can overwrite it in your ApplicationController to
|
||||
# provide a custom hook for a custom resource.
|
||||
#
|
||||
# By default, it first tries to find a resource_root_path, otherwise it
|
||||
# uses the root path. For a user scope, you can define the default url in
|
||||
# By default, it first tries to find a valid resource_return_to key in the
|
||||
# session, then it fallbacks to resource_root_path, otherwise it uses the
|
||||
# root path. For a user scope, you can define the default url in
|
||||
# the following way:
|
||||
#
|
||||
# map.user_root '/users', :controller => 'users' # creates user_root_path
|
||||
@@ -167,22 +192,20 @@ module Devise
|
||||
# user.root :controller => 'users' # creates user_root_path
|
||||
# end
|
||||
#
|
||||
#
|
||||
# If the resource root path is not defined, root_path is used. However,
|
||||
# if this default is not enough, you can customize it, for example:
|
||||
#
|
||||
# def after_sign_in_path_for(resource)
|
||||
# if resource.is_a?(User) && resource.can_publish?
|
||||
# publisher_url
|
||||
# else
|
||||
# super
|
||||
# end
|
||||
# stored_location_for(resource) ||
|
||||
# if resource.is_a?(User) && resource.can_publish?
|
||||
# publisher_url
|
||||
# else
|
||||
# signed_in_root_path(resource)
|
||||
# end
|
||||
# end
|
||||
#
|
||||
def after_sign_in_path_for(resource_or_scope)
|
||||
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
||||
home_path = "#{scope}_root_path"
|
||||
respond_to?(home_path, true) ? send(home_path) : root_path
|
||||
stored_location_for(resource_or_scope) || signed_in_root_path(resource_or_scope)
|
||||
end
|
||||
|
||||
# Method used by sessions controller to sign out a user. You can overwrite
|
||||
@@ -190,9 +213,9 @@ module Devise
|
||||
# scope. Notice that differently from +after_sign_in_path_for+ this method
|
||||
# receives a symbol with the scope, and not the resource.
|
||||
#
|
||||
# By default is the root_path.
|
||||
# By default it is the root_path.
|
||||
def after_sign_out_path_for(resource_or_scope)
|
||||
root_path
|
||||
respond_to?(:root_path) ? root_path : "/"
|
||||
end
|
||||
|
||||
# Sign in a user and tries to redirect first to the stored location and
|
||||
@@ -203,32 +226,41 @@ module Devise
|
||||
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
||||
resource = args.last || resource_or_scope
|
||||
sign_in(scope, resource, options)
|
||||
redirect_to redirect_location(scope, resource)
|
||||
redirect_to after_sign_in_path_for(resource)
|
||||
end
|
||||
|
||||
def redirect_location(scope, resource) #:nodoc:
|
||||
stored_location_for(scope) || after_sign_in_path_for(resource)
|
||||
ActiveSupport::Deprecation.warn "redirect_location in Devise is deprecated. Please use after_sign_in_path_for instead.", caller
|
||||
after_sign_in_path_for(resource)
|
||||
end
|
||||
|
||||
def expire_session_data_after_sign_in!
|
||||
session.keys.grep(/^devise\./).each { |k| session.delete(k) }
|
||||
end
|
||||
|
||||
# Sign out a user and tries to redirect to the url specified by
|
||||
# after_sign_out_path_for.
|
||||
def sign_out_and_redirect(resource_or_scope)
|
||||
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
||||
redirect_path = after_sign_out_path_for(scope)
|
||||
Devise.sign_out_all_scopes ? sign_out : sign_out(scope)
|
||||
redirect_to after_sign_out_path_for(scope)
|
||||
redirect_to redirect_path
|
||||
end
|
||||
|
||||
# A hook called to expire session data after sign up/in. All keys
|
||||
# stored under "devise." namespace are removed after sign in.
|
||||
def expire_session_data_after_sign_in!
|
||||
session.keys.grep(/^devise\./).each { |k| session.delete(k) }
|
||||
end
|
||||
|
||||
# Overwrite Rails' handle unverified request to sign out all scopes.
|
||||
# Overwrite Rails' handle unverified request to sign out all scopes,
|
||||
# clear run strategies and remove cached variables.
|
||||
def handle_unverified_request
|
||||
sign_out_all_scopes
|
||||
warden.clear_strategies_cache!
|
||||
expire_devise_cached_variables!
|
||||
super # call the default behaviour which resets the session
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def expire_devise_cached_variables!
|
||||
Devise.mappings.each { |_,m| instance_variable_set("@current_#{m.name}", nil) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,119 +0,0 @@
|
||||
module Devise
|
||||
module Controllers
|
||||
# Those helpers are used only inside Devise controllers and should not be
|
||||
# included in ApplicationController since they all depend on the url being
|
||||
# accessed.
|
||||
module InternalHelpers #:nodoc:
|
||||
extend ActiveSupport::Concern
|
||||
include Devise::Controllers::ScopedViews
|
||||
|
||||
included do
|
||||
helper DeviseHelper
|
||||
|
||||
helpers = %w(resource scope_name resource_name signed_in_resource
|
||||
resource_class devise_mapping devise_controller?)
|
||||
hide_action *helpers
|
||||
helper_method *helpers
|
||||
|
||||
prepend_before_filter :is_devise_resource?
|
||||
respond_to *Mime::SET.map(&:to_sym) if mimes_for_respond_to.empty?
|
||||
end
|
||||
|
||||
# Gets the actual resource stored in the instance variable
|
||||
def resource
|
||||
instance_variable_get(:"@#{resource_name}")
|
||||
end
|
||||
|
||||
# Proxy to devise map name
|
||||
def resource_name
|
||||
devise_mapping.name
|
||||
end
|
||||
alias :scope_name :resource_name
|
||||
|
||||
# Proxy to devise map class
|
||||
def resource_class
|
||||
devise_mapping.to
|
||||
end
|
||||
|
||||
# Returns a signed in resource from session (if one exists)
|
||||
def signed_in_resource
|
||||
warden.authenticate(:scope => resource_name)
|
||||
end
|
||||
|
||||
# Attempt to find the mapped route for devise based on request path
|
||||
def devise_mapping
|
||||
@devise_mapping ||= request.env["devise.mapping"]
|
||||
end
|
||||
|
||||
# Overwrites devise_controller? to return true
|
||||
def devise_controller?
|
||||
true
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
# Checks whether it's a devise mapped resource or not.
|
||||
def is_devise_resource? #:nodoc:
|
||||
unknown_action!("Could not find devise mapping for path #{request.fullpath.inspect}") unless devise_mapping
|
||||
end
|
||||
|
||||
# Check whether it's navigational format, such as :html or :iphone, or not.
|
||||
def is_navigational_format?
|
||||
Devise.navigational_formats.include?(request.format.to_sym)
|
||||
end
|
||||
|
||||
def unknown_action!(msg)
|
||||
logger.debug "[Devise] #{msg}" if logger
|
||||
raise ActionController::UnknownAction, msg
|
||||
end
|
||||
|
||||
# Sets the resource creating an instance variable
|
||||
def resource=(new_resource)
|
||||
instance_variable_set(:"@#{resource_name}", new_resource)
|
||||
end
|
||||
|
||||
# Build a devise resource.
|
||||
def build_resource(hash=nil)
|
||||
hash ||= params[resource_name] || {}
|
||||
self.resource = resource_class.new(hash)
|
||||
end
|
||||
|
||||
# Helper for use in before_filters where no authentication is required.
|
||||
#
|
||||
# Example:
|
||||
# before_filter :require_no_authentication, :only => :new
|
||||
def require_no_authentication
|
||||
if warden.authenticated?(resource_name)
|
||||
resource = warden.user(resource_name)
|
||||
redirect_to after_sign_in_path_for(resource)
|
||||
end
|
||||
end
|
||||
|
||||
# Sets the flash message with :key, using I18n. By default you are able
|
||||
# to setup your messages using specific resource scope, and if no one is
|
||||
# found we look to default scope.
|
||||
# Example (i18n locale file):
|
||||
#
|
||||
# en:
|
||||
# devise:
|
||||
# passwords:
|
||||
# #default_scope_messages - only if resource_scope is not found
|
||||
# user:
|
||||
# #resource_scope_messages
|
||||
#
|
||||
# Please refer to README or en.yml locale file to check what messages are
|
||||
# available.
|
||||
def set_flash_message(key, kind, options={}) #:nodoc:
|
||||
options[:scope] = "devise.#{controller_name}"
|
||||
options[:default] = Array(options[:default]).unshift(kind.to_sym)
|
||||
options[:resource_name] = resource_name
|
||||
message = I18n.t("#{resource_name}.#{kind}", options)
|
||||
flash[key] = message if message.present?
|
||||
end
|
||||
|
||||
def clean_up_passwords(object) #:nodoc:
|
||||
object.clean_up_passwords if object.respond_to?(:clean_up_passwords)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -29,7 +29,7 @@ module Devise
|
||||
# Forgets the given resource by deleting a cookie
|
||||
def forget_me(resource)
|
||||
scope = Devise::Mapping.find_scope!(resource)
|
||||
resource.forget_me! unless resource.frozen?
|
||||
resource.forget_me!
|
||||
cookies.delete("remember_#{scope}_token", forget_cookie_values(resource))
|
||||
end
|
||||
|
||||
|
||||
@@ -12,22 +12,6 @@ module Devise
|
||||
@scoped_views = value
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
# Render a view for the specified scope. Turned off by default.
|
||||
# Accepts just :controller as option.
|
||||
def render_with_scope(action, path=self.controller_path)
|
||||
if self.class.scoped_views?
|
||||
begin
|
||||
render :template => "#{devise_mapping.scoped_path}/#{path.split("/").last}/#{action}"
|
||||
rescue ActionView::MissingTemplate
|
||||
render :template => "#{path}/#{action}"
|
||||
end
|
||||
else
|
||||
render :template => "#{path}/#{action}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -16,24 +16,52 @@ module Devise
|
||||
# new_confirmation_path(:user) => new_user_confirmation_path
|
||||
# confirmation_path(:user) => user_confirmation_path
|
||||
#
|
||||
# Those helpers are added to your ApplicationController.
|
||||
# Those helpers are included by default to ActionController::Base.
|
||||
#
|
||||
# In case you want to add such helpers to another class, you can do
|
||||
# that as long as this new class includes both url_helpers and
|
||||
# mounted_helpers. Example:
|
||||
#
|
||||
# include Rails.application.routes.url_helpers
|
||||
# include Rails.application.routes.mounted_helpers
|
||||
#
|
||||
module UrlHelpers
|
||||
def self.remove_helpers!
|
||||
self.instance_methods.map(&:to_s).grep(/_(url|path)$/).each do |method|
|
||||
remove_method method
|
||||
end
|
||||
end
|
||||
|
||||
Devise::URL_HELPERS.each do |module_name, actions|
|
||||
[:path, :url].each do |path_or_url|
|
||||
actions.each do |action|
|
||||
action = action ? "#{action}_" : ""
|
||||
def self.generate_helpers!(routes=nil)
|
||||
routes ||= begin
|
||||
mappings = Devise.mappings.values.map(&:used_helpers).flatten.uniq
|
||||
Devise::URL_HELPERS.slice(*mappings)
|
||||
end
|
||||
|
||||
class_eval <<-URL_HELPERS, __FILE__, __LINE__ + 1
|
||||
def #{action}#{module_name}_#{path_or_url}(resource_or_scope, *args)
|
||||
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
||||
send("#{action}\#{scope}_#{module_name}_#{path_or_url}", *args)
|
||||
end
|
||||
URL_HELPERS
|
||||
routes.each do |module_name, actions|
|
||||
[:path, :url].each do |path_or_url|
|
||||
actions.each do |action|
|
||||
action = action ? "#{action}_" : ""
|
||||
method = "#{action}#{module_name}_#{path_or_url}"
|
||||
|
||||
class_eval <<-URL_HELPERS, __FILE__, __LINE__ + 1
|
||||
def #{method}(resource_or_scope, *args)
|
||||
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
||||
_devise_route_context.send("#{action}\#{scope}_#{module_name}_#{path_or_url}", *args)
|
||||
end
|
||||
URL_HELPERS
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
generate_helpers!(Devise::URL_HELPERS)
|
||||
|
||||
private
|
||||
|
||||
def _devise_route_context
|
||||
@_devise_route_context ||= send(Devise.router_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
16
lib/devise/delegator.rb
Normal file
16
lib/devise/delegator.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
module Devise
|
||||
# Checks the scope in the given environment and returns the associated failure app.
|
||||
class Delegator
|
||||
def call(env)
|
||||
failure_app(env).call(env)
|
||||
end
|
||||
|
||||
def failure_app(env)
|
||||
app = env["warden.options"] &&
|
||||
(scope = env["warden.options"][:scope]) &&
|
||||
Devise.mappings[scope.to_sym].failure_app
|
||||
|
||||
app || Devise::FailureApp
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -7,7 +7,7 @@ module Devise
|
||||
# Warning: it uses Devise's stretches configuration to port Authlogic's one. Should be set to 20 in the initializer to simulate
|
||||
# the default behavior.
|
||||
class AuthlogicSha512 < Base
|
||||
# Gererates a default password digest based on salt, pepper and the
|
||||
# Generates a default password digest based on salt, pepper and the
|
||||
# incoming password.
|
||||
def self.digest(password, stretches, salt, pepper)
|
||||
digest = [password, salt].flatten.join('')
|
||||
|
||||
@@ -7,7 +7,7 @@ module Devise
|
||||
# Warning: it uses Devise's pepper to port the concept of REST_AUTH_SITE_KEY
|
||||
# Warning: it uses Devise's stretches configuration to port the concept of REST_AUTH_DIGEST_STRETCHES
|
||||
class ClearanceSha1 < Base
|
||||
# Gererates a default password digest based on salt, pepper and the
|
||||
# Generates a default password digest based on salt, pepper and the
|
||||
# incoming password.
|
||||
def self.digest(password, stretches, salt, pepper)
|
||||
Digest::SHA1.hexdigest("--#{salt}--#{password}--")
|
||||
|
||||
@@ -9,7 +9,7 @@ module Devise
|
||||
# the initializer to simulate the default behavior.
|
||||
class RestfulAuthenticationSha1 < Base
|
||||
|
||||
# Gererates a default password digest based on salt, pepper and the
|
||||
# Generates a default password digest based on salt, pepper and the
|
||||
# incoming password.
|
||||
def self.digest(password, stretches, salt, pepper)
|
||||
digest = pepper
|
||||
|
||||
@@ -5,7 +5,7 @@ module Devise
|
||||
# = Sha1
|
||||
# Uses the Sha1 hash algorithm to encrypt passwords.
|
||||
class Sha1 < Base
|
||||
# Gererates a default password digest based on stretches, salt, pepper and the
|
||||
# Generates a default password digest based on stretches, salt, pepper and the
|
||||
# incoming password.
|
||||
def self.digest(password, stretches, salt, pepper)
|
||||
digest = pepper
|
||||
|
||||
@@ -5,7 +5,7 @@ module Devise
|
||||
# = Sha512
|
||||
# Uses the Sha512 hash algorithm to encrypt passwords.
|
||||
class Sha512 < Base
|
||||
# Gererates a default password digest based on salt, pepper and the
|
||||
# Generates a default password digest based on salt, pepper and the
|
||||
# incoming password.
|
||||
def self.digest(password, stretches, salt, pepper)
|
||||
digest = pepper
|
||||
|
||||
@@ -9,16 +9,23 @@ module Devise
|
||||
include ActionController::RackDelegation
|
||||
include ActionController::UrlFor
|
||||
include ActionController::Redirecting
|
||||
|
||||
include Rails.application.routes.url_helpers
|
||||
include Rails.application.routes.mounted_helpers
|
||||
|
||||
delegate :flash, :to => :request
|
||||
|
||||
def self.call(env)
|
||||
action(:respond).call(env)
|
||||
@respond ||= action(:respond)
|
||||
@respond.call(env)
|
||||
end
|
||||
|
||||
def self.default_url_options(*args)
|
||||
ApplicationController.default_url_options(*args)
|
||||
if defined?(ApplicationController)
|
||||
ApplicationController.default_url_options(*args)
|
||||
else
|
||||
{}
|
||||
end
|
||||
end
|
||||
|
||||
def respond
|
||||
@@ -46,31 +53,57 @@ module Devise
|
||||
|
||||
def redirect
|
||||
store_location!
|
||||
flash[:alert] = i18n_message
|
||||
if flash[:timedout] && flash[:alert]
|
||||
flash.keep(:timedout)
|
||||
flash.keep(:alert)
|
||||
else
|
||||
flash[:alert] = i18n_message
|
||||
end
|
||||
redirect_to redirect_url
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def i18n_message(default = nil)
|
||||
message = warden.message || warden_options[:message] || default || :unauthenticated
|
||||
message = warden_message || default || :unauthenticated
|
||||
|
||||
if message.is_a?(Symbol)
|
||||
I18n.t(:"#{scope}.#{message}", :resource_name => scope,
|
||||
:scope => "devise.failure", :default => [message, message.to_s])
|
||||
:scope => "devise.failure", :default => [message])
|
||||
else
|
||||
message.to_s
|
||||
end
|
||||
end
|
||||
|
||||
def redirect_url
|
||||
if request_format == :html
|
||||
send(:"new_#{scope}_session_path")
|
||||
if warden_message == :timeout
|
||||
flash[:timedout] = true
|
||||
attempted_path || scope_path
|
||||
else
|
||||
send(:"new_#{scope}_session_path", :format => request_format)
|
||||
scope_path
|
||||
end
|
||||
end
|
||||
|
||||
def scope_path
|
||||
opts = {}
|
||||
route = :"new_#{scope}_session_path"
|
||||
opts[:format] = request_format unless skip_format?
|
||||
|
||||
context = send(Devise.router_name)
|
||||
|
||||
if context.respond_to?(route)
|
||||
context.send(route, opts)
|
||||
elsif respond_to?(:root_path)
|
||||
root_path(opts)
|
||||
else
|
||||
"/"
|
||||
end
|
||||
end
|
||||
|
||||
def skip_format?
|
||||
%w(html */*).include? request_format.to_s
|
||||
end
|
||||
|
||||
# Choose whether we should respond in a http authentication fashion,
|
||||
# including 401 and optional headers.
|
||||
#
|
||||
@@ -83,7 +116,7 @@ module Devise
|
||||
if request.xhr?
|
||||
Devise.http_authenticatable_on_xhr
|
||||
else
|
||||
!(request_format && Devise.navigational_formats.include?(request_format))
|
||||
!(request_format && is_navigational_format?)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -96,12 +129,20 @@ module Devise
|
||||
def http_auth_body
|
||||
return i18n_message unless request_format
|
||||
method = "to_#{request_format}"
|
||||
{}.respond_to?(method) ? { :error => i18n_message }.send(method) : i18n_message
|
||||
if method == "to_xml"
|
||||
{ :error => i18n_message }.to_xml(:root => "errors")
|
||||
elsif {}.respond_to?(method)
|
||||
{ :error => i18n_message }.send(method)
|
||||
else
|
||||
i18n_message
|
||||
end
|
||||
end
|
||||
|
||||
def recall_app(app)
|
||||
controller, action = app.split("#")
|
||||
"#{controller.camelize}Controller".constantize.action(action)
|
||||
controller_name = ActiveSupport::Inflector.camelize(controller)
|
||||
controller_klass = ActiveSupport::Inflector.constantize("#{controller_name}Controller")
|
||||
controller_klass.action(action)
|
||||
end
|
||||
|
||||
def warden
|
||||
@@ -112,6 +153,10 @@ module Devise
|
||||
env['warden.options']
|
||||
end
|
||||
|
||||
def warden_message
|
||||
@message ||= warden.message || warden_options[:message]
|
||||
end
|
||||
|
||||
def scope
|
||||
@scope ||= warden_options[:scope] || Devise.default_scope
|
||||
end
|
||||
@@ -128,16 +173,12 @@ module Devise
|
||||
session["#{scope}_return_to"] = attempted_path if request.get? && !http_auth?
|
||||
end
|
||||
|
||||
MIME_REFERENCES = Mime::HTML.respond_to?(:ref)
|
||||
def is_navigational_format?
|
||||
Devise.navigational_formats.include?(request_format)
|
||||
end
|
||||
|
||||
def request_format
|
||||
@request_format ||= if request.format.respond_to?(:ref)
|
||||
request.format.ref
|
||||
elsif MIME_REFERENCES
|
||||
request.format
|
||||
else # Rails < 3.0.4
|
||||
request.format.to_sym
|
||||
end
|
||||
@request_format ||= request.format.try(:ref)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Before logout hook to forget the user in the given scope, if it responds
|
||||
# to forget_me! Also clear remember token to ensure the user won't be
|
||||
# remembered again. Notice that we forget the user unless the record is frozen.
|
||||
# remembered again. Notice that we forget the user unless the record is not persisted.
|
||||
# This avoids forgetting deleted users.
|
||||
Warden::Manager.before_logout do |record, warden, options|
|
||||
if record.respond_to?(:forget_me!)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Each time a record is set we check whether its session has already timed out
|
||||
# or not, based on last request time. If so, the record is logged out and
|
||||
# redirected to the sign in page. Also, each time the request comes and the
|
||||
# record is set, we set the last request time inside it's scoped session to
|
||||
# record is set, we set the last request time inside its scoped session to
|
||||
# verify timeout in the following request.
|
||||
Warden::Manager.after_set_user do |record, warden, options|
|
||||
scope = options[:scope]
|
||||
@@ -17,6 +17,8 @@ Warden::Manager.after_set_user do |record, warden, options|
|
||||
end
|
||||
end
|
||||
|
||||
warden.session(scope)['last_request_at'] = Time.now.utc
|
||||
unless warden.request.env['devise.skip_trackable']
|
||||
warden.session(scope)['last_request_at'] = Time.now.utc
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
# and on authentication. Retrieving the user from session (:fetch) does
|
||||
# not trigger it.
|
||||
Warden::Manager.after_set_user :except => :fetch do |record, warden, options|
|
||||
if record.respond_to?(:update_tracked_fields!) && warden.authenticated?(options[:scope])
|
||||
if record.respond_to?(:update_tracked_fields!) && warden.authenticated?(options[:scope]) && !warden.request.env['devise.skip_trackable']
|
||||
record.update_tracked_fields!(warden.request)
|
||||
end
|
||||
end
|
||||
|
||||
86
lib/devise/mailers/helpers.rb
Normal file
86
lib/devise/mailers/helpers.rb
Normal file
@@ -0,0 +1,86 @@
|
||||
module Devise
|
||||
module Mailers
|
||||
module Helpers
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
include Devise::Controllers::ScopedViews
|
||||
attr_reader :scope_name, :resource
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
# Configure default email options
|
||||
def devise_mail(record, action)
|
||||
initialize_from_record(record)
|
||||
mail headers_for(action)
|
||||
end
|
||||
|
||||
def initialize_from_record(record)
|
||||
@scope_name = Devise::Mapping.find_scope!(record)
|
||||
@resource = instance_variable_set("@#{devise_mapping.name}", record)
|
||||
end
|
||||
|
||||
def devise_mapping
|
||||
@devise_mapping ||= Devise.mappings[scope_name]
|
||||
end
|
||||
|
||||
def headers_for(action)
|
||||
headers = {
|
||||
:subject => translate(devise_mapping, action),
|
||||
:from => mailer_sender(devise_mapping),
|
||||
:to => resource.email,
|
||||
:template_path => template_paths
|
||||
}
|
||||
|
||||
if resource.respond_to?(:headers_for)
|
||||
headers.merge!(resource.headers_for(action))
|
||||
end
|
||||
|
||||
unless headers.key?(:reply_to)
|
||||
headers[:reply_to] = headers[:from]
|
||||
end
|
||||
|
||||
headers
|
||||
end
|
||||
|
||||
def mailer_sender(mapping)
|
||||
if default_params[:from].present?
|
||||
default_params[:from]
|
||||
elsif Devise.mailer_sender.is_a?(Proc)
|
||||
Devise.mailer_sender.call(mapping.name)
|
||||
else
|
||||
Devise.mailer_sender
|
||||
end
|
||||
end
|
||||
|
||||
def template_paths
|
||||
template_path = [self.class.mailer_name]
|
||||
template_path.unshift "#{@devise_mapping.scoped_path}/mailer" if self.class.scoped_views?
|
||||
template_path
|
||||
end
|
||||
|
||||
# Setup a subject doing an I18n lookup. At first, it attemps to set a subject
|
||||
# based on the current mapping:
|
||||
#
|
||||
# en:
|
||||
# devise:
|
||||
# mailer:
|
||||
# confirmation_instructions:
|
||||
# user_subject: '...'
|
||||
#
|
||||
# If one does not exist, it fallbacks to ActionMailer default:
|
||||
#
|
||||
# en:
|
||||
# devise:
|
||||
# mailer:
|
||||
# confirmation_instructions:
|
||||
# subject: '...'
|
||||
#
|
||||
def translate(mapping, key)
|
||||
I18n.t(:"#{mapping.name}_subject", :scope => [:devise, :mailer, key],
|
||||
:default => [:subject, key.to_s.humanize])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -22,7 +22,9 @@ module Devise
|
||||
# # is the modules included in the class
|
||||
#
|
||||
class Mapping #:nodoc:
|
||||
attr_reader :singular, :scoped_path, :path, :controllers, :path_names, :class_name, :sign_out_via
|
||||
attr_reader :singular, :scoped_path, :path, :controllers, :path_names,
|
||||
:class_name, :sign_out_via, :format, :used_routes, :used_helpers, :failure_app
|
||||
|
||||
alias :name :singular
|
||||
|
||||
# Receives an object and find a scope for it. If a scope cannot be found,
|
||||
@@ -50,20 +52,19 @@ module Devise
|
||||
@singular = (options[:singular] || @scoped_path.tr('/', '_').singularize).to_sym
|
||||
|
||||
@class_name = (options[:class_name] || name.to_s.classify).to_s
|
||||
@ref = Devise.ref(@class_name)
|
||||
@klass = Devise.ref(@class_name)
|
||||
|
||||
@path = (options[:path] || name).to_s
|
||||
@path_prefix = options[:path_prefix]
|
||||
|
||||
mod = options[:module] || "devise"
|
||||
@controllers = Hash.new { |h,k| h[k] = "#{mod}/#{k}" }
|
||||
@controllers.merge!(options[:controllers] || {})
|
||||
|
||||
@path_names = Hash.new { |h,k| h[k] = k.to_s }
|
||||
@path_names.merge!(:registration => "")
|
||||
@path_names.merge!(options[:path_names] || {})
|
||||
|
||||
@sign_out_via = options[:sign_out_via] || Devise.sign_out_via
|
||||
@format = options[:format]
|
||||
|
||||
default_failure_app(options)
|
||||
default_controllers(options)
|
||||
default_path_names(options)
|
||||
default_used_route(options)
|
||||
default_used_helpers(options)
|
||||
end
|
||||
|
||||
# Return modules for the mapping.
|
||||
@@ -73,17 +74,17 @@ module Devise
|
||||
|
||||
# Gives the class the mapping points to.
|
||||
def to
|
||||
if defined?(ActiveSupport::Dependencies::ClassCache)
|
||||
@ref.get @class_name
|
||||
else
|
||||
@ref.get
|
||||
end
|
||||
@klass.get
|
||||
end
|
||||
|
||||
def strategies
|
||||
@strategies ||= STRATEGIES.values_at(*self.modules).compact.uniq.reverse
|
||||
end
|
||||
|
||||
def no_input_strategies
|
||||
self.strategies & Devise::NO_INPUT
|
||||
end
|
||||
|
||||
def routes
|
||||
@routes ||= ROUTES.values_at(*self.modules).compact.uniq
|
||||
end
|
||||
@@ -110,5 +111,62 @@ module Devise
|
||||
end
|
||||
METHOD
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def default_failure_app(options)
|
||||
@failure_app = options[:failure_app] || Devise::FailureApp
|
||||
if @failure_app.is_a?(String)
|
||||
ref = Devise.ref(@failure_app)
|
||||
@failure_app = lambda { |env| ref.get.call(env) }
|
||||
end
|
||||
end
|
||||
|
||||
def default_controllers(options)
|
||||
mod = options[:module] || "devise"
|
||||
@controllers = Hash.new { |h,k| h[k] = "#{mod}/#{k}" }
|
||||
@controllers.merge!(options[:controllers]) if options[:controllers]
|
||||
@controllers.each { |k,v| @controllers[k] = v.to_s }
|
||||
end
|
||||
|
||||
def default_path_names(options)
|
||||
@path_names = Hash.new { |h,k| h[k] = k.to_s }
|
||||
@path_names[:registration] = ""
|
||||
@path_names.merge!(options[:path_names]) if options[:path_names]
|
||||
end
|
||||
|
||||
def default_constraints(options)
|
||||
@constraints = Hash.new
|
||||
@constraints.merge!(options[:constraints]) if options[:constraints]
|
||||
end
|
||||
|
||||
def default_defaults(options)
|
||||
@defaults = Hash.new
|
||||
@defaults.merge!(options[:defaults]) if options[:defaults]
|
||||
end
|
||||
|
||||
def default_used_route(options)
|
||||
singularizer = lambda { |s| s.to_s.singularize.to_sym }
|
||||
|
||||
if options.has_key?(:only)
|
||||
@used_routes = self.routes & Array(options[:only]).map(&singularizer)
|
||||
elsif options[:skip] == :all
|
||||
@used_routes = []
|
||||
else
|
||||
@used_routes = self.routes - Array(options[:skip]).map(&singularizer)
|
||||
end
|
||||
end
|
||||
|
||||
def default_used_helpers(options)
|
||||
singularizer = lambda { |s| s.to_s.singularize.to_sym }
|
||||
|
||||
if options[:skip_helpers] == true
|
||||
@used_helpers = @used_routes
|
||||
elsif skip = options[:skip_helpers]
|
||||
@used_helpers = self.routes - Array(skip).map(&singularizer)
|
||||
else
|
||||
@used_helpers = self.routes
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -17,6 +17,9 @@ module Devise
|
||||
# inside the given class.
|
||||
#
|
||||
def self.config(mod, *accessors) #:nodoc:
|
||||
(class << mod; self; end).send :attr_accessor, :available_configs
|
||||
mod.available_configs = accessors
|
||||
|
||||
accessors.each do |accessor|
|
||||
mod.class_eval <<-METHOD, __FILE__, __LINE__ + 1
|
||||
def #{accessor}
|
||||
@@ -45,14 +48,34 @@ module Devise
|
||||
# for a complete description on those values.
|
||||
#
|
||||
def devise(*modules)
|
||||
include Devise::Models::Authenticatable
|
||||
options = modules.extract_options!
|
||||
self.devise_modules += modules.map(&:to_sym).uniq.sort_by { |s|
|
||||
options = modules.extract_options!.dup
|
||||
|
||||
selected_modules = modules.map(&:to_sym).uniq.sort_by do |s|
|
||||
Devise::ALL.index(s) || -1 # follow Devise::ALL order
|
||||
}
|
||||
end
|
||||
|
||||
devise_modules_hook! do
|
||||
devise_modules.each { |m| include Devise::Models.const_get(m.to_s.classify) }
|
||||
include Devise::Models::Authenticatable
|
||||
selected_modules.each do |m|
|
||||
mod = Devise::Models.const_get(m.to_s.classify)
|
||||
|
||||
if mod.const_defined?("ClassMethods")
|
||||
class_mod = mod.const_get("ClassMethods")
|
||||
extend class_mod
|
||||
|
||||
if class_mod.respond_to?(:available_configs)
|
||||
available_configs = class_mod.available_configs
|
||||
available_configs.each do |config|
|
||||
next unless options.key?(config)
|
||||
send(:"#{config}=", options.delete(config))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
include mod
|
||||
end
|
||||
|
||||
self.devise_modules |= selected_modules
|
||||
options.each { |key, value| send(:"#{key}=", value) }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
require 'devise/hooks/activatable'
|
||||
require 'devise/models/serializable'
|
||||
|
||||
module Devise
|
||||
module Models
|
||||
@@ -24,9 +25,14 @@ module Devise
|
||||
# * +params_authenticatable+: if this model allows authentication through request params. By default true.
|
||||
# It also accepts an array specifying the strategies that should allow params authentication.
|
||||
#
|
||||
# * +skip_session_storage+: By default Devise will store the user in session.
|
||||
# You can skip storage for http and token auth by appending values to array:
|
||||
# :skip_session_storage => [:token_auth] or :skip_session_storage => [:http_auth, :token_auth],
|
||||
# by default is set to :skip_session_storage => [:http_auth].
|
||||
#
|
||||
# == active_for_authentication?
|
||||
#
|
||||
# Before authenticating a user and in each request, Devise checks if your model is active by
|
||||
# After authenticating a user and in each request, Devise checks if your model is active by
|
||||
# calling model.active_for_authentication?. This method is overwriten by other devise modules. For instance,
|
||||
# :confirmable overwrites .active_for_authentication? to only return true if your model was confirmed.
|
||||
#
|
||||
@@ -46,9 +52,14 @@ module Devise
|
||||
module Authenticatable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
include Devise::Models::Serializable
|
||||
|
||||
included do
|
||||
class_attribute :devise_modules, :instance_writer => false
|
||||
self.devise_modules ||= []
|
||||
|
||||
before_validation :downcase_keys
|
||||
before_validation :strip_whitespace
|
||||
end
|
||||
|
||||
# Check if the current object is valid for authentication. This method and
|
||||
@@ -58,27 +69,11 @@ module Devise
|
||||
# However, you should not overwrite this method, you should overwrite active_for_authentication?
|
||||
# and inactive_message instead.
|
||||
def valid_for_authentication?
|
||||
if active_for_authentication?
|
||||
block_given? ? yield : true
|
||||
else
|
||||
inactive_message
|
||||
end
|
||||
end
|
||||
|
||||
def active?
|
||||
ActiveSupport::Deprecation.warn "[DEVISE] active? is deprecated, please use active_for_authentication? instead.", caller
|
||||
active_for_authentication?
|
||||
block_given? ? yield : true
|
||||
end
|
||||
|
||||
def active_for_authentication?
|
||||
my_methods = self.class.instance_methods(false)
|
||||
if my_methods.include?("active?") || my_methods.include?(:active?)
|
||||
ActiveSupport::Deprecation.warn "[DEVISE] Overriding active? is deprecated to avoid conflicts. " \
|
||||
"Please use active_for_authentication? instead.", caller
|
||||
active?
|
||||
else
|
||||
true
|
||||
end
|
||||
true
|
||||
end
|
||||
|
||||
def inactive_message
|
||||
@@ -88,8 +83,34 @@ module Devise
|
||||
def authenticatable_salt
|
||||
end
|
||||
|
||||
def devise_mailer
|
||||
Devise.mailer
|
||||
end
|
||||
|
||||
def headers_for(name)
|
||||
{}
|
||||
end
|
||||
|
||||
def downcase_keys
|
||||
(self.class.case_insensitive_keys || []).each { |k| self[k].try(:downcase!) }
|
||||
end
|
||||
|
||||
def strip_whitespace
|
||||
(self.class.strip_whitespace_keys || []).each { |k| self[k].try(:strip!) }
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
Devise::Models.config(self, :authentication_keys, :request_keys, :case_insensitive_keys, :http_authenticatable, :params_authenticatable)
|
||||
Devise::Models.config(self, :authentication_keys, :request_keys, :strip_whitespace_keys,
|
||||
:case_insensitive_keys, :http_authenticatable, :params_authenticatable, :skip_session_storage)
|
||||
|
||||
def serialize_into_session(record)
|
||||
[record.to_key, record.authenticatable_salt]
|
||||
end
|
||||
|
||||
def serialize_from_session(key, salt)
|
||||
record = to_adapter.get(key)
|
||||
record if record && record.authenticatable_salt == salt
|
||||
end
|
||||
|
||||
def params_authenticatable?(strategy)
|
||||
params_authenticatable.is_a?(Array) ?
|
||||
@@ -112,9 +133,11 @@ module Devise
|
||||
# end
|
||||
#
|
||||
def find_for_authentication(conditions)
|
||||
filter_auth_params(conditions)
|
||||
(case_insensitive_keys || []).each { |k| conditions[k].try(:downcase!) }
|
||||
to_adapter.find_first(conditions)
|
||||
find_first_by_auth_conditions(conditions)
|
||||
end
|
||||
|
||||
def find_first_by_auth_conditions(conditions)
|
||||
to_adapter.find_first devise_param_filter.filter(conditions)
|
||||
end
|
||||
|
||||
# Find an initialize a record setting an error if it can't be found.
|
||||
@@ -124,15 +147,13 @@ module Devise
|
||||
|
||||
# Find an initialize a group of attributes based on a list of required attributes.
|
||||
def find_or_initialize_with_errors(required_attributes, attributes, error=:invalid) #:nodoc:
|
||||
(case_insensitive_keys || []).each { |k| attributes[k].try(:downcase!) }
|
||||
|
||||
attributes = attributes.slice(*required_attributes)
|
||||
attributes.delete_if { |key, value| value.blank? }
|
||||
|
||||
if attributes.size == required_attributes.size
|
||||
record = to_adapter.find_first(filter_auth_params(attributes))
|
||||
record = find_first_by_auth_conditions(attributes)
|
||||
end
|
||||
|
||||
|
||||
unless record
|
||||
record = new
|
||||
|
||||
@@ -148,11 +169,8 @@ module Devise
|
||||
|
||||
protected
|
||||
|
||||
# Force keys to be string to avoid injection on mongoid related database.
|
||||
def filter_auth_params(conditions)
|
||||
conditions.each do |k, v|
|
||||
conditions[k] = v.to_s
|
||||
end if conditions.is_a?(Hash)
|
||||
def devise_param_filter
|
||||
@devise_param_filter ||= Devise::ParamFilter.new(case_insensitive_keys, strip_whitespace_keys)
|
||||
end
|
||||
|
||||
# Generate a token by looping and ensuring does not already exist.
|
||||
|
||||
@@ -9,11 +9,16 @@ module Devise
|
||||
#
|
||||
# Confirmable adds the following options to devise_for:
|
||||
#
|
||||
# * +confirm_within+: the time you want to allow the user to access his account
|
||||
# * +allow_unconfirmed_access_for+: the time you want to allow the user to access his account
|
||||
# before confirming it. After this period, the user access is denied. You can
|
||||
# use this to let your user access some features of your application without
|
||||
# confirming the account, but blocking it after a certain period (ie 7 days).
|
||||
# By default confirm_within is zero, it means users always have to confirm to sign in.
|
||||
# By default allow_unconfirmed_access_for is zero, it means users always have to confirm to sign in.
|
||||
# * +reconfirmable+: requires any email changes to be confirmed (exactly the same way as
|
||||
# initial account confirmation) to be applied. Requires additional unconfirmed_email
|
||||
# db field to be setup (t.reconfirmable in migrations). Until confirmed new email is
|
||||
# stored in unconfirmed email column, and copied to email column on successful
|
||||
# confirmation.
|
||||
#
|
||||
# == Examples
|
||||
#
|
||||
@@ -26,16 +31,29 @@ module Devise
|
||||
|
||||
included do
|
||||
before_create :generate_confirmation_token, :if => :confirmation_required?
|
||||
after_create :send_confirmation_instructions, :if => :confirmation_required?
|
||||
after_create :send_on_create_confirmation_instructions, :if => :confirmation_required?
|
||||
before_update :postpone_email_change_until_confirmation, :if => :postpone_email_change?
|
||||
after_update :send_confirmation_instructions, :if => :reconfirmation_required?
|
||||
end
|
||||
|
||||
# Confirm a user by setting it's confirmed_at to actual time. If the user
|
||||
# is already confirmed, add en error to email field
|
||||
# is already confirmed, add an error to email field. If the user is invalid
|
||||
# add errors
|
||||
def confirm!
|
||||
unless_confirmed do
|
||||
pending_any_confirmation do
|
||||
self.confirmation_token = nil
|
||||
self.confirmed_at = Time.now
|
||||
save(:validate => false)
|
||||
self.confirmed_at = Time.now.utc
|
||||
|
||||
if self.class.reconfirmable && unconfirmed_email.present?
|
||||
@bypass_postpone = true
|
||||
self.email = unconfirmed_email
|
||||
self.unconfirmed_email = nil
|
||||
|
||||
# We need to validate in such cases to enforce e-mail uniqueness
|
||||
save(:validate => true)
|
||||
else
|
||||
save(:validate => false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -44,15 +62,22 @@ module Devise
|
||||
!!confirmed_at
|
||||
end
|
||||
|
||||
def pending_reconfirmation?
|
||||
self.class.reconfirmable && unconfirmed_email.present?
|
||||
end
|
||||
|
||||
# Send confirmation instructions by email
|
||||
def send_confirmation_instructions
|
||||
generate_confirmation_token! if self.confirmation_token.nil?
|
||||
::Devise.mailer.confirmation_instructions(self).deliver
|
||||
self.confirmation_token = nil if reconfirmation_required?
|
||||
@reconfirmation_required = false
|
||||
|
||||
generate_confirmation_token! if self.confirmation_token.blank?
|
||||
self.devise_mailer.confirmation_instructions(self).deliver
|
||||
end
|
||||
|
||||
# Resend confirmation token. This method does not need to generate a new token.
|
||||
def resend_confirmation_token
|
||||
unless_confirmed { send_confirmation_instructions }
|
||||
pending_any_confirmation { send_confirmation_instructions }
|
||||
end
|
||||
|
||||
# Overwrites active_for_authentication? for confirmation
|
||||
@@ -71,11 +96,26 @@ module Devise
|
||||
# If you don't want confirmation to be sent on create, neither a code
|
||||
# to be generated, call skip_confirmation!
|
||||
def skip_confirmation!
|
||||
self.confirmed_at = Time.now
|
||||
self.confirmed_at = Time.now.utc
|
||||
end
|
||||
|
||||
def headers_for(action)
|
||||
headers = super
|
||||
if action == :confirmation_instructions && pending_reconfirmation?
|
||||
headers[:to] = unconfirmed_email
|
||||
end
|
||||
headers
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
# A callback method used to deliver confirmation
|
||||
# instructions on creation. This can be overriden
|
||||
# in models to map to a nice sign up e-mail.
|
||||
def send_on_create_confirmation_instructions
|
||||
self.devise_mailer.confirmation_instructions(self).deliver
|
||||
end
|
||||
|
||||
# Callback to overwrite if confirmation is required or not.
|
||||
def confirmation_required?
|
||||
!confirmed?
|
||||
@@ -84,30 +124,29 @@ module Devise
|
||||
# Checks if the confirmation for the user is within the limit time.
|
||||
# We do this by calculating if the difference between today and the
|
||||
# confirmation sent date does not exceed the confirm in time configured.
|
||||
# Confirm_in is a model configuration, must always be an integer value.
|
||||
# Confirm_within is a model configuration, must always be an integer value.
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# # confirm_within = 1.day and confirmation_sent_at = today
|
||||
# # allow_unconfirmed_access_for = 1.day and confirmation_sent_at = today
|
||||
# confirmation_period_valid? # returns true
|
||||
#
|
||||
# # confirm_within = 5.days and confirmation_sent_at = 4.days.ago
|
||||
# # allow_unconfirmed_access_for = 5.days and confirmation_sent_at = 4.days.ago
|
||||
# confirmation_period_valid? # returns true
|
||||
#
|
||||
# # confirm_within = 5.days and confirmation_sent_at = 5.days.ago
|
||||
# # allow_unconfirmed_access_for = 5.days and confirmation_sent_at = 5.days.ago
|
||||
# confirmation_period_valid? # returns false
|
||||
#
|
||||
# # confirm_within = 0.days
|
||||
# # allow_unconfirmed_access_for = 0.days
|
||||
# confirmation_period_valid? # will always return false
|
||||
#
|
||||
def confirmation_period_valid?
|
||||
confirmation_sent_at && confirmation_sent_at.utc >= self.class.confirm_within.ago
|
||||
confirmation_sent_at && confirmation_sent_at.utc >= self.class.allow_unconfirmed_access_for.ago
|
||||
end
|
||||
|
||||
# Checks whether the record is confirmed or not, yielding to the block
|
||||
# if it's already confirmed, otherwise adds an error to email.
|
||||
def unless_confirmed
|
||||
unless confirmed?
|
||||
# Checks whether the record requires any confirmation.
|
||||
def pending_any_confirmation
|
||||
if !confirmed? || pending_reconfirmation?
|
||||
yield
|
||||
else
|
||||
self.errors.add(:email, :already_confirmed)
|
||||
@@ -118,7 +157,6 @@ module Devise
|
||||
# Generates a new random token for confirmation, and stores the time
|
||||
# this token is being generated
|
||||
def generate_confirmation_token
|
||||
self.confirmed_at = nil
|
||||
self.confirmation_token = self.class.confirmation_token
|
||||
self.confirmation_sent_at = Time.now.utc
|
||||
end
|
||||
@@ -127,18 +165,42 @@ module Devise
|
||||
generate_confirmation_token && save(:validate => false)
|
||||
end
|
||||
|
||||
def after_password_reset
|
||||
super
|
||||
confirm! unless confirmed?
|
||||
end
|
||||
|
||||
def postpone_email_change_until_confirmation
|
||||
@reconfirmation_required = true
|
||||
self.unconfirmed_email = self.email
|
||||
self.email = self.email_was
|
||||
end
|
||||
|
||||
def postpone_email_change?
|
||||
postpone = self.class.reconfirmable && email_changed? && !@bypass_postpone
|
||||
@bypass_postpone = nil
|
||||
postpone
|
||||
end
|
||||
|
||||
def reconfirmation_required?
|
||||
self.class.reconfirmable && @reconfirmation_required
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
# Attempt to find a user by it's email. If a record is found, send new
|
||||
# confirmation instructions to it. If not user is found, returns a new user
|
||||
# with an email not found error.
|
||||
# Attempt to find a user by its email. If a record is found, send new
|
||||
# confirmation instructions to it. If not, try searching for a user by unconfirmed_email
|
||||
# field. If no user is found, returns a new user with an email not found error.
|
||||
# Options must contain the user email
|
||||
def send_confirmation_instructions(attributes={})
|
||||
confirmable = find_or_initialize_with_errors(confirmation_keys, attributes, :not_found)
|
||||
confirmable = find_by_unconfirmed_email_with_errors(attributes) if reconfirmable
|
||||
unless confirmable.try(:persisted?)
|
||||
confirmable = find_or_initialize_with_errors(confirmation_keys, attributes, :not_found)
|
||||
end
|
||||
confirmable.resend_confirmation_token if confirmable.persisted?
|
||||
confirmable
|
||||
end
|
||||
|
||||
# Find a user by it's confirmation token and try to confirm it.
|
||||
# Find a user by its confirmation token and try to confirm it.
|
||||
# If no user is found, returns a new user with an error.
|
||||
# If the user is already confirmed, create an error for the user
|
||||
# Options must have the confirmation_token
|
||||
@@ -153,7 +215,15 @@ module Devise
|
||||
generate_token(:confirmation_token)
|
||||
end
|
||||
|
||||
Devise::Models.config(self, :confirm_within, :confirmation_keys)
|
||||
# Find a record for confirmation by unconfirmed email field
|
||||
def find_by_unconfirmed_email_with_errors(attributes = {})
|
||||
unconfirmed_required_attributes = confirmation_keys.map { |k| k == :email ? :unconfirmed_email : k }
|
||||
unconfirmed_attributes = attributes.symbolize_keys
|
||||
unconfirmed_attributes[:unconfirmed_email] = unconfirmed_attributes.delete(:email)
|
||||
find_or_initialize_with_errors(unconfirmed_required_attributes, unconfirmed_attributes, :not_found)
|
||||
end
|
||||
|
||||
Devise::Models.config(self, :allow_unconfirmed_access_for, :confirmation_keys, :reconfirmable)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -10,6 +10,9 @@ module Devise
|
||||
#
|
||||
# DatabaseAuthenticable adds the following options to devise_for:
|
||||
#
|
||||
# * +pepper+: a random string used to provide a more secure hash. Use
|
||||
# `rake secret` to generate new keys.
|
||||
#
|
||||
# * +stretches+: the cost given to bcrypt.
|
||||
#
|
||||
# == Examples
|
||||
@@ -22,7 +25,6 @@ module Devise
|
||||
included do
|
||||
attr_reader :password, :current_password
|
||||
attr_accessor :password_confirmation
|
||||
before_save :downcase_keys
|
||||
end
|
||||
|
||||
# Generates password encryption based on the given value.
|
||||
@@ -33,6 +35,7 @@ module Devise
|
||||
|
||||
# Verifies whether an password (ie from sign in) is the user password.
|
||||
def valid_password?(password)
|
||||
return false if encrypted_password.blank?
|
||||
bcrypt = ::BCrypt::Password.new(self.encrypted_password)
|
||||
password = ::BCrypt::Engine.hash_secret("#{password}#{self.class.pepper}", bcrypt.salt)
|
||||
Devise.secure_compare(password, self.encrypted_password)
|
||||
@@ -46,7 +49,7 @@ module Devise
|
||||
# Update record attributes when :current_password matches, otherwise returns
|
||||
# error on :current_password. It also automatically rejects :password and
|
||||
# :password_confirmation if they are blank.
|
||||
def update_with_password(params={})
|
||||
def update_with_password(params, *options)
|
||||
current_password = params.delete(:current_password)
|
||||
|
||||
if params[:password].blank?
|
||||
@@ -55,10 +58,11 @@ module Devise
|
||||
end
|
||||
|
||||
result = if valid_password?(current_password)
|
||||
update_attributes(params)
|
||||
update_attributes(params, *options)
|
||||
else
|
||||
self.errors.add(:current_password, current_password.blank? ? :blank : :invalid)
|
||||
self.attributes = params
|
||||
self.valid?
|
||||
self.errors.add(:current_password, current_password.blank? ? :blank : :invalid)
|
||||
false
|
||||
end
|
||||
|
||||
@@ -66,6 +70,27 @@ module Devise
|
||||
result
|
||||
end
|
||||
|
||||
# Updates record attributes without asking for the current password.
|
||||
# Never allows to change the current password. If you are using this
|
||||
# method, you should probably override this method to protect other
|
||||
# attributes you would not like to be updated without a password.
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# def update_without_password(params={})
|
||||
# params.delete(:email)
|
||||
# super(params)
|
||||
# end
|
||||
#
|
||||
def update_without_password(params, *options)
|
||||
params.delete(:password)
|
||||
params.delete(:password_confirmation)
|
||||
|
||||
result = update_attributes(params, *options)
|
||||
clean_up_passwords
|
||||
result
|
||||
end
|
||||
|
||||
def after_database_authentication
|
||||
end
|
||||
|
||||
@@ -76,11 +101,6 @@ module Devise
|
||||
|
||||
protected
|
||||
|
||||
# Downcase case-insensitive keys
|
||||
def downcase_keys
|
||||
(self.class.case_insensitive_keys || []).each { |k| self[k].try(:downcase!) }
|
||||
end
|
||||
|
||||
# Digests the password using bcrypt.
|
||||
def password_digest(password)
|
||||
::BCrypt::Password.create("#{password}#{self.class.pepper}", :cost => self.class.stretches).to_s
|
||||
|
||||
@@ -3,13 +3,13 @@ module Devise
|
||||
# Handles blocking a user access after a certain number of attempts.
|
||||
# Lockable accepts two different strategies to unlock a user after it's
|
||||
# blocked: email and time. The former will send an email to the user when
|
||||
# the lock happens, containing a link to unlock it's account. The second
|
||||
# the lock happens, containing a link to unlock its account. The second
|
||||
# will unlock the user automatically after some configured time (ie 2.hours).
|
||||
# It's also possible to setup lockable to use both email and time strategies.
|
||||
#
|
||||
# == Options
|
||||
#
|
||||
# Lockable adds the following options to devise_for:
|
||||
# Lockable adds the following options to +devise+:
|
||||
#
|
||||
# * +maximum_attempts+: how many attempts should be accepted before blocking the user.
|
||||
# * +lock_strategy+: lock the user account by :failed_attempts or :none.
|
||||
@@ -22,9 +22,9 @@ module Devise
|
||||
|
||||
delegate :lock_strategy_enabled?, :unlock_strategy_enabled?, :to => "self.class"
|
||||
|
||||
# Lock a user setting it's locked_at to actual time.
|
||||
# Lock a user setting its locked_at to actual time.
|
||||
def lock_access!
|
||||
self.locked_at = Time.now
|
||||
self.locked_at = Time.now.utc
|
||||
|
||||
if unlock_strategy_enabled?(:email)
|
||||
generate_unlock_token
|
||||
@@ -49,7 +49,7 @@ module Devise
|
||||
|
||||
# Send unlock instructions by email
|
||||
def send_unlock_instructions
|
||||
::Devise.mailer.unlock_instructions(self).deliver
|
||||
self.devise_mailer.unlock_instructions(self).deliver
|
||||
end
|
||||
|
||||
# Resend the unlock instructions if the user is locked.
|
||||
@@ -79,25 +79,21 @@ module Devise
|
||||
# if the user can login or not (wrong password, etc)
|
||||
unlock_access! if lock_expired?
|
||||
|
||||
case (result = super)
|
||||
when Symbol
|
||||
return result
|
||||
when TrueClass
|
||||
if super && !access_locked?
|
||||
self.failed_attempts = 0
|
||||
save(:validate => false)
|
||||
when FalseClass
|
||||
# PostgreSQL uses nil as the default value for integer columns set to 0
|
||||
true
|
||||
else
|
||||
self.failed_attempts ||= 0
|
||||
self.failed_attempts += 1
|
||||
if attempts_exceeded?
|
||||
lock_access!
|
||||
lock_access! unless access_locked?
|
||||
return :locked
|
||||
else
|
||||
save(:validate => false)
|
||||
end
|
||||
false
|
||||
end
|
||||
|
||||
result
|
||||
end
|
||||
|
||||
protected
|
||||
@@ -132,7 +128,7 @@ module Devise
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
# Attempt to find a user by it's email. If a record is found, send new
|
||||
# Attempt to find a user by its email. If a record is found, send new
|
||||
# unlock instructions to it. If not user is found, returns a new user
|
||||
# with an email not found error.
|
||||
# Options must contain the user email
|
||||
@@ -142,7 +138,7 @@ module Devise
|
||||
lockable
|
||||
end
|
||||
|
||||
# Find a user by it's unlock token and try to unlock it.
|
||||
# Find a user by its unlock token and try to unlock it.
|
||||
# If no user is found, returns a new user with an error.
|
||||
# If the user is not locked, creates an error for the user
|
||||
# Options must have the unlock_token
|
||||
|
||||
@@ -29,21 +29,56 @@ module Devise
|
||||
def reset_password!(new_password, new_password_confirmation)
|
||||
self.password = new_password
|
||||
self.password_confirmation = new_password_confirmation
|
||||
clear_reset_password_token if valid?
|
||||
|
||||
if valid?
|
||||
clear_reset_password_token
|
||||
after_password_reset
|
||||
end
|
||||
|
||||
save
|
||||
end
|
||||
|
||||
# Resets reset password token and send reset password instructions by email
|
||||
def send_reset_password_instructions
|
||||
generate_reset_password_token!
|
||||
::Devise.mailer.reset_password_instructions(self).deliver
|
||||
generate_reset_password_token! if should_generate_reset_token?
|
||||
self.devise_mailer.reset_password_instructions(self).deliver
|
||||
end
|
||||
|
||||
# Checks if the reset password token sent is within the limit time.
|
||||
# We do this by calculating if the difference between today and the
|
||||
# sending date does not exceed the confirm in time configured.
|
||||
# Returns true if the resource is not responding to reset_password_sent_at at all.
|
||||
# reset_password_within is a model configuration, must always be an integer value.
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# # reset_password_within = 1.day and reset_password_sent_at = today
|
||||
# reset_password_period_valid? # returns true
|
||||
#
|
||||
# # reset_password_within = 5.days and reset_password_sent_at = 4.days.ago
|
||||
# reset_password_period_valid? # returns true
|
||||
#
|
||||
# # reset_password_within = 5.days and reset_password_sent_at = 5.days.ago
|
||||
# reset_password_period_valid? # returns false
|
||||
#
|
||||
# # reset_password_within = 0.days
|
||||
# reset_password_period_valid? # will always return false
|
||||
#
|
||||
def reset_password_period_valid?
|
||||
reset_password_sent_at && reset_password_sent_at.utc >= self.class.reset_password_within.ago
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def should_generate_reset_token?
|
||||
reset_password_token.nil? || !reset_password_period_valid?
|
||||
end
|
||||
|
||||
# Generates a new random token for reset password
|
||||
def generate_reset_password_token
|
||||
self.reset_password_token = self.class.reset_password_token
|
||||
self.reset_password_sent_at = Time.now.utc
|
||||
self.reset_password_token
|
||||
end
|
||||
|
||||
# Resets the reset password token with and save the record without
|
||||
@@ -55,10 +90,14 @@ module Devise
|
||||
# Removes reset_password token
|
||||
def clear_reset_password_token
|
||||
self.reset_password_token = nil
|
||||
self.reset_password_sent_at = nil
|
||||
end
|
||||
|
||||
def after_password_reset
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
# Attempt to find a user by it's email. If a record is found, send new
|
||||
# Attempt to find a user by its email. If a record is found, send new
|
||||
# password instructions to it. If not user is found, returns a new user
|
||||
# with an email not found error.
|
||||
# Attributes must contain the user email
|
||||
@@ -73,18 +112,24 @@ module Devise
|
||||
generate_token(:reset_password_token)
|
||||
end
|
||||
|
||||
# Attempt to find a user by it's reset_password_token to reset it's
|
||||
# password. If a user is found, reset it's password and automatically
|
||||
# Attempt to find a user by its reset_password_token to reset its
|
||||
# password. If a user is found and token is still valid, reset its password and automatically
|
||||
# try saving the record. If not user is found, returns a new user
|
||||
# containing an error in reset_password_token attribute.
|
||||
# Attributes must contain reset_password_token, password and confirmation
|
||||
def reset_password_by_token(attributes={})
|
||||
recoverable = find_or_initialize_with_error_by(:reset_password_token, attributes[:reset_password_token])
|
||||
recoverable.reset_password!(attributes[:password], attributes[:password_confirmation]) if recoverable.persisted?
|
||||
if recoverable.persisted?
|
||||
if recoverable.reset_password_period_valid?
|
||||
recoverable.reset_password!(attributes[:password], attributes[:password_confirmation])
|
||||
else
|
||||
recoverable.errors.add(:reset_password_token, :expired)
|
||||
end
|
||||
end
|
||||
recoverable
|
||||
end
|
||||
|
||||
Devise::Models.config(self, :reset_password_keys)
|
||||
Devise::Models.config(self, :reset_password_keys, :reset_password_within)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -21,11 +21,6 @@ module Devise
|
||||
# used to calculate the expires time for the cookie created to remember
|
||||
# the user. By default remember_for is 2.weeks.
|
||||
#
|
||||
# * +remember_across_browsers+: if a valid remember token can be re-used
|
||||
# between multiple browsers. By default remember_across_browsers is true
|
||||
# and cannot be turned off if you are using password salt instead of remember
|
||||
# token.
|
||||
#
|
||||
# * +extend_remember_period+: if true, extends the user's remember period
|
||||
# when remembered via cookie. False by default.
|
||||
#
|
||||
@@ -49,17 +44,18 @@ module Devise
|
||||
# Generate a new remember token and save the record without validations
|
||||
# unless remember_across_browsers is true and the user already has a valid token.
|
||||
def remember_me!(extend_period=false)
|
||||
self.remember_token = self.class.remember_token if respond_to?(:remember_token) && generate_remember_token?
|
||||
self.remember_created_at = Time.now.utc if generate_remember_timestamp?(extend_period)
|
||||
save(:validate => false)
|
||||
end
|
||||
|
||||
# Removes the remember token only if it exists, and save the record
|
||||
# without validations.
|
||||
# If the record is persisted, remove the remember token (but only if
|
||||
# it exists), and save the record without validations.
|
||||
def forget_me!
|
||||
self.remember_token = nil if respond_to?(:remember_token=)
|
||||
self.remember_created_at = nil
|
||||
save(:validate => false)
|
||||
if persisted?
|
||||
self.remember_token = nil if respond_to?(:remember_token=)
|
||||
self.remember_created_at = nil
|
||||
save(:validate => false)
|
||||
end
|
||||
end
|
||||
|
||||
# Remember token should be expired if expiration time not overpass now.
|
||||
@@ -73,14 +69,12 @@ module Devise
|
||||
end
|
||||
|
||||
def rememberable_value
|
||||
if respond_to?(:remember_token)
|
||||
remember_token
|
||||
elsif respond_to?(:authenticatable_salt) && (salt = authenticatable_salt)
|
||||
if salt = authenticatable_salt
|
||||
salt
|
||||
else
|
||||
raise "The #{self.class.name} class does not respond to remember_token and " <<
|
||||
"authenticatable_salt returns nil. In order to use rememberable, you must " <<
|
||||
"add a remember_token field to your model or ensure a password is always set."
|
||||
raise "authenticable_salt returned nil for the #{self.class.name} model. " \
|
||||
"In order to use rememberable, you must ensure a password is always set " \
|
||||
"or implement rememberable_value in your model with your own logic."
|
||||
end
|
||||
end
|
||||
|
||||
@@ -90,12 +84,6 @@ module Devise
|
||||
|
||||
protected
|
||||
|
||||
# Generate a token unless remember_across_browsers is true and there is
|
||||
# an existing remember_token or the existing remember_token has expried.
|
||||
def generate_remember_token? #:nodoc:
|
||||
!(self.class.remember_across_browsers && remember_token) || remember_expired?
|
||||
end
|
||||
|
||||
# Generate a timestamp if extend_remember_period is true, if no remember_token
|
||||
# exists, or if an existing remember token has expired.
|
||||
def generate_remember_timestamp?(extend_period) #:nodoc:
|
||||
@@ -119,8 +107,7 @@ module Devise
|
||||
generate_token(:remember_token)
|
||||
end
|
||||
|
||||
Devise::Models.config(self, :remember_for, :remember_across_browsers,
|
||||
:extend_remember_period, :cookie_options)
|
||||
Devise::Models.config(self, :remember_for, :extend_remember_period, :cookie_options)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
46
lib/devise/models/serializable.rb
Normal file
46
lib/devise/models/serializable.rb
Normal file
@@ -0,0 +1,46 @@
|
||||
module Devise
|
||||
module Models
|
||||
# This module redefine to_xml and serializable_hash in models for more
|
||||
# secure defaults. By default, it removes from the serializable model
|
||||
# all attributes that are *not* accessible. You can remove this default
|
||||
# by using :force_except and passing a new list of attributes you want
|
||||
# to exempt. All attributes given to :except will simply add names to
|
||||
# exempt to Devise internal list.
|
||||
module Serializable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
array = %w(serializable_hash)
|
||||
# to_xml does not call serializable_hash on 3.1
|
||||
array << "to_xml" if Rails::VERSION::STRING[0,3] == "3.1"
|
||||
|
||||
array.each do |method|
|
||||
class_eval <<-RUBY, __FILE__, __LINE__
|
||||
def #{method}(options=nil)
|
||||
options ||= {}
|
||||
if options.key?(:force_except)
|
||||
options[:except] = options.delete(:force_except)
|
||||
super(options)
|
||||
elsif self.class.blacklist_keys?
|
||||
except = Array(options[:except])
|
||||
super(options.merge(:except => except + self.class.blacklist_keys))
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
# Return true if we can retrieve blacklist keys from the record.
|
||||
def blacklist_keys?
|
||||
@has_except_keys ||= respond_to?(:accessible_attributes) && !accessible_attributes.to_a.empty?
|
||||
end
|
||||
|
||||
# Returns keys that should be removed when serializing the record.
|
||||
def blacklist_keys
|
||||
@blacklist_keys ||= to_adapter.column_names.map(&:to_s) - accessible_attributes.to_a.map(&:to_s)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -23,18 +23,20 @@ module Devise
|
||||
# Checks whether the user session has expired based on configured time.
|
||||
def timedout?(last_access)
|
||||
return false if remember_exists_and_not_expired?
|
||||
|
||||
last_access && last_access <= self.class.timeout_in.ago
|
||||
!timeout_in.nil? && last_access && last_access <= timeout_in.ago
|
||||
end
|
||||
|
||||
|
||||
def timeout_in
|
||||
self.class.timeout_in
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
|
||||
def remember_exists_and_not_expired?
|
||||
return false unless respond_to?(:remember_expired?)
|
||||
|
||||
return false unless respond_to?(:remember_created_at)
|
||||
remember_created_at && !remember_expired?
|
||||
end
|
||||
|
||||
|
||||
module ClassMethods
|
||||
Devise::Models.config(self, :timeout_in)
|
||||
end
|
||||
|
||||
@@ -24,9 +24,6 @@ module Devise
|
||||
#
|
||||
# * +token_authentication_key+: Defines name of the authentication token params key. E.g. /users/sign_in?some_key=...
|
||||
#
|
||||
# * +stateless_token+: By default, when you sign up with a token, Devise will store the user in session
|
||||
# as any other authentication strategy. You can set stateless_token to true to avoid this.
|
||||
#
|
||||
module TokenAuthenticatable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
@@ -65,7 +62,7 @@ module Devise
|
||||
generate_token(:authentication_token)
|
||||
end
|
||||
|
||||
::Devise::Models.config(self, :token_authentication_key, :stateless_token)
|
||||
::Devise::Models.config(self, :token_authentication_key)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,18 +5,18 @@ module Devise
|
||||
# Track information about your user sign in. It tracks the following columns:
|
||||
#
|
||||
# * sign_in_count - Increased every time a sign in is made (by form, openid, oauth)
|
||||
# * current_sign_in_at - A tiemstamp updated when the user signs in
|
||||
# * current_sign_in_at - A timestamp updated when the user signs in
|
||||
# * last_sign_in_at - Holds the timestamp of the previous sign in
|
||||
# * current_sign_in_ip - The remote ip updated when the user sign in
|
||||
# * last_sign_in_at - Holds the remote ip of the previous sign in
|
||||
# * last_sign_in_ip - Holds the remote ip of the previous sign in
|
||||
#
|
||||
module Trackable
|
||||
def update_tracked_fields!(request)
|
||||
old_current, new_current = self.current_sign_in_at, Time.now
|
||||
old_current, new_current = self.current_sign_in_at, Time.now.utc
|
||||
self.last_sign_in_at = old_current || new_current
|
||||
self.current_sign_in_at = new_current
|
||||
|
||||
old_current, new_current = self.current_sign_in_ip, request.remote_ip
|
||||
old_current, new_current = self.current_sign_in_ip, request.ip
|
||||
self.last_sign_in_ip = old_current || new_current
|
||||
self.current_sign_in_ip = new_current
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ module Devise
|
||||
module Models
|
||||
# Validatable creates all needed validations for a user email and password.
|
||||
# It's optional, given you may want to create the validations by yourself.
|
||||
# Automatically validate if the email is present, unique and it's format is
|
||||
# Automatically validate if the email is present, unique and its format is
|
||||
# valid. Also tests presence of password, confirmation and length.
|
||||
#
|
||||
# == Options
|
||||
@@ -10,7 +10,7 @@ module Devise
|
||||
# Validatable adds the following options to devise_for:
|
||||
#
|
||||
# * +email_regexp+: the regular expression used to validate e-mails;
|
||||
# * +password_length+: a range expressing password length. Defaults to 6..20.
|
||||
# * +password_length+: a range expressing password length. Defaults to 6..128.
|
||||
#
|
||||
module Validatable
|
||||
# All validations used by this module.
|
||||
@@ -23,15 +23,12 @@ module Devise
|
||||
|
||||
base.class_eval do
|
||||
validates_presence_of :email, :if => :email_required?
|
||||
validates_uniqueness_of :email, :scope => authentication_keys[1..-1],
|
||||
:case_sensitive => (case_insensitive_keys != false), :allow_blank => true
|
||||
validates_format_of :email, :with => email_regexp, :allow_blank => true
|
||||
validates_uniqueness_of :email, :allow_blank => true, :if => :email_changed?
|
||||
validates_format_of :email, :with => email_regexp, :allow_blank => true, :if => :email_changed?
|
||||
|
||||
with_options :if => :password_required? do |v|
|
||||
v.validates_presence_of :password
|
||||
v.validates_confirmation_of :password
|
||||
v.validates_length_of :password, :within => password_length, :allow_blank => true
|
||||
end
|
||||
validates_presence_of :password, :if => :password_required?
|
||||
validates_confirmation_of :password, :if => :password_required?
|
||||
validates_length_of :password, :within => password_length, :allow_blank => true
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@ Devise.with_options :model => true do |d|
|
||||
d.with_options :strategy => true do |s|
|
||||
routes = [nil, :new, :destroy]
|
||||
s.add_module :database_authenticatable, :controller => :sessions, :route => { :session => routes }
|
||||
s.add_module :token_authenticatable, :controller => :sessions, :route => { :session => routes }
|
||||
s.add_module :rememberable
|
||||
s.add_module :token_authenticatable, :controller => :sessions, :route => { :session => routes }, :no_input => true
|
||||
s.add_module :rememberable, :no_input => true
|
||||
end
|
||||
|
||||
# Other authentications
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
begin
|
||||
require "omniauth/core"
|
||||
require "omniauth"
|
||||
require "omniauth/version"
|
||||
rescue LoadError => e
|
||||
warn "Could not load 'omniauth/core'. Please ensure you have the oa-core gem installed and listed in your Gemfile."
|
||||
warn "Could not load 'omniauth'. Please ensure you have the omniauth gem >= 1.0.0 installed and listed in your Gemfile."
|
||||
raise
|
||||
end
|
||||
|
||||
unless OmniAuth.config.respond_to? :test_mode
|
||||
raise "You are using an old OmniAuth version, please ensure you have 0.2.0.beta version or later installed."
|
||||
unless OmniAuth::VERSION =~ /^1\./
|
||||
raise "You are using an old OmniAuth version, please ensure you have 1.0.0.pr2 version or later installed."
|
||||
end
|
||||
|
||||
# Clean up the default path_prefix. It will be automatically set by Devise.
|
||||
@@ -14,19 +15,14 @@ OmniAuth.config.path_prefix = nil
|
||||
|
||||
OmniAuth.config.on_failure = Proc.new do |env|
|
||||
env['devise.mapping'] = Devise::Mapping.find_by_path!(env['PATH_INFO'], :path)
|
||||
controller_klass = "#{env['devise.mapping'].controllers[:omniauth_callbacks].camelize}Controller"
|
||||
controller_klass.constantize.action(:failure).call(env)
|
||||
controller_name = ActiveSupport::Inflector.camelize(env['devise.mapping'].controllers[:omniauth_callbacks])
|
||||
controller_klass = ActiveSupport::Inflector.constantize("#{controller_name}Controller")
|
||||
controller_klass.action(:failure).call(env)
|
||||
end
|
||||
|
||||
module Devise
|
||||
module OmniAuth
|
||||
autoload :Config, "devise/omniauth/config"
|
||||
autoload :UrlHelpers, "devise/omniauth/url_helpers"
|
||||
autoload :TestHelpers, "devise/omniauth/test_helpers"
|
||||
|
||||
class << self
|
||||
delegate :short_circuit_authorizers!, :unshort_circuit_authorizers!,
|
||||
:test_mode!, :stub!, :reset_stubs!, :to => "Devise::OmniAuth::TestHelpers"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,18 +1,45 @@
|
||||
module Devise
|
||||
module OmniAuth
|
||||
class StrategyNotFound < NameError
|
||||
def initialize(strategy)
|
||||
@strategy = strategy
|
||||
super("Could not find a strategy with name `#{strategy}'. " \
|
||||
"Please ensure it is required or explicitly set it using the :strategy_class option.")
|
||||
end
|
||||
end
|
||||
|
||||
class Config
|
||||
attr_accessor :strategy
|
||||
attr_reader :args
|
||||
attr_reader :args, :options, :provider, :strategy_name
|
||||
|
||||
def initialize(provider, args)
|
||||
@provider = provider
|
||||
@args = args
|
||||
@strategy = nil
|
||||
@provider = provider
|
||||
@args = args
|
||||
@options = @args.last.is_a?(Hash) ? @args.last : {}
|
||||
@strategy = nil
|
||||
@strategy_name = options[:name] || @provider
|
||||
@strategy_class = options.delete(:strategy_class)
|
||||
end
|
||||
|
||||
def strategy_class
|
||||
::OmniAuth::Strategies.const_get("#{::OmniAuth::Utils.camelize(@provider.to_s)}")
|
||||
@strategy_class ||= find_strategy || autoload_strategy
|
||||
end
|
||||
|
||||
def find_strategy
|
||||
::OmniAuth.strategies.find do |strategy_class|
|
||||
strategy_class.to_s =~ /#{::OmniAuth::Utils.camelize(strategy_name)}$/ ||
|
||||
strategy_class.default_options[:name] == strategy_name
|
||||
end
|
||||
end
|
||||
|
||||
def autoload_strategy
|
||||
name = ::OmniAuth::Utils.camelize(provider.to_s)
|
||||
if ::OmniAuth::Strategies.const_defined?(name)
|
||||
::OmniAuth::Strategies.const_get(name)
|
||||
else
|
||||
raise StrategyNotFound, name
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -26,6 +26,12 @@ module Devise
|
||||
|
||||
# Tell how to apply schema methods.
|
||||
def apply_devise_schema(name, type, options={})
|
||||
@__devise_warning_raised ||= begin
|
||||
$stderr.puts "\n[DEVISE] You are using t.database_authenticatable and others in your migration " \
|
||||
"and this feature is deprecated. Please simply use Rails helpers instead as mentioned here:\n" \
|
||||
"https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0-migration-schema-style\n\n"
|
||||
true
|
||||
end
|
||||
column name, type.to_s.downcase.to_sym, options
|
||||
end
|
||||
end
|
||||
|
||||
41
lib/devise/param_filter.rb
Normal file
41
lib/devise/param_filter.rb
Normal file
@@ -0,0 +1,41 @@
|
||||
module Devise
|
||||
class ParamFilter
|
||||
def initialize(case_insensitive_keys, strip_whitespace_keys)
|
||||
@case_insensitive_keys = case_insensitive_keys || []
|
||||
@strip_whitespace_keys = strip_whitespace_keys || []
|
||||
end
|
||||
|
||||
def filter(conditions)
|
||||
conditions = stringify_params(conditions.dup)
|
||||
|
||||
@case_insensitive_keys.each do |k|
|
||||
value = conditions[k]
|
||||
next unless value.respond_to?(:downcase)
|
||||
conditions[k] = value.downcase
|
||||
end
|
||||
|
||||
@strip_whitespace_keys.each do |k|
|
||||
value = conditions[k]
|
||||
next unless value.respond_to?(:strip)
|
||||
conditions[k] = value.strip
|
||||
end
|
||||
|
||||
conditions
|
||||
end
|
||||
|
||||
# Force keys to be string to avoid injection on mongoid related database.
|
||||
def stringify_params(conditions)
|
||||
return conditions unless conditions.is_a?(Hash)
|
||||
conditions.each do |k, v|
|
||||
conditions[k] = v.to_s if param_requires_string_conversion?(v)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Determine which values should be transformed to string or passed as-is to the query builder underneath
|
||||
def param_requires_string_conversion?(value)
|
||||
[Fixnum, TrueClass, FalseClass, Regexp].none? {|clz| value.is_a? clz }
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -3,7 +3,11 @@ module Devise
|
||||
include Rails.application.routes.url_helpers
|
||||
|
||||
def self.default_url_options(*args)
|
||||
ApplicationController.default_url_options(*args)
|
||||
if defined?(ApplicationController)
|
||||
ApplicationController.default_url_options(*args)
|
||||
else
|
||||
{}
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(env, scope)
|
||||
@@ -12,7 +16,8 @@ module Devise
|
||||
end
|
||||
|
||||
def signing_out?
|
||||
@current_path == send("destroy_#{@scope}_session_path")
|
||||
route = "destroy_#{@scope}_session_path"
|
||||
respond_to?(route) && @current_path == send(route)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -17,14 +17,6 @@ module Devise
|
||||
Devise.include_helpers(Devise::Controllers)
|
||||
end
|
||||
|
||||
initializer "devise.navigationals" do
|
||||
formats = Devise.navigational_formats
|
||||
if formats.include?(:"*/*") && formats.exclude?("*/*")
|
||||
puts "[DEVISE] We see the symbol :\"*/*\" in the navigational formats in your initializer " \
|
||||
"but not the string \"*/*\". Due to changes in latest Rails, please include the latter."
|
||||
end
|
||||
end
|
||||
|
||||
initializer "devise.omniauth" do |app|
|
||||
Devise.omniauth_configs.each do |provider, config|
|
||||
app.middleware.use config.strategy_class, *config.args do |strategy|
|
||||
@@ -37,21 +29,82 @@ module Devise
|
||||
end
|
||||
end
|
||||
|
||||
initializer "devise.encryptor_check" do
|
||||
case Devise.encryptor
|
||||
when :bcrypt
|
||||
puts "[DEVISE] From version 1.2, there is no need to set your encryptor to bcrypt " \
|
||||
"since encryptors are only enabled if you include :encryptable in your models. " \
|
||||
"With this change, we can integrate better with bcrypt and get rid of the " \
|
||||
"password_salt column (since bcrypt stores the salt with password). " \
|
||||
"Please comment config.encryptor in your initializer to get rid of this warning."
|
||||
when nil
|
||||
# Nothing to say
|
||||
else
|
||||
puts "[DEVISE] You are using #{Devise.encryptor} as encryptor. From version 1.2, " \
|
||||
"you need to explicitly add `devise :encryptable, :encryptor => :#{Devise.encryptor}` " \
|
||||
"to your models and comment the current value in the config/initializers/devise.rb. " \
|
||||
"You must also add t.encryptable to your existing migrations."
|
||||
initializer "devise.mongoid_version_warning" do
|
||||
if defined?(Mongoid)
|
||||
require 'mongoid/version'
|
||||
if Mongoid::VERSION.to_f < 2.1
|
||||
puts "\n[DEVISE] Please note that Mongoid versions prior to 2.1 handle dirty model " \
|
||||
"object attributes in such a way that the Devise `validatable` module will not apply " \
|
||||
"its usual uniqueness and format validations for the email field. It is recommended " \
|
||||
"that you upgrade to Mongoid 2.1+ for this and other fixes, but if for some reason you " \
|
||||
"are unable to do so, you should add these validations manually.\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
initializer "devise.fix_routes_proxy_missing_respond_to_bug" do
|
||||
# We can get rid of this once we support Rails > 3.2
|
||||
ActionDispatch::Routing::RoutesProxy.class_eval do
|
||||
def respond_to?(method, include_private = false)
|
||||
super || routes.url_helpers.respond_to?(method)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
initializer "devise.deprecations" do
|
||||
unless defined?(Rails::Generators)
|
||||
if Devise.case_insensitive_keys == false
|
||||
warn "\n[DEVISE] Devise.case_insensitive_keys is false which is no longer " \
|
||||
"supported. Recent Devise versions automatically downcase the e-mail before " \
|
||||
"saving it to the database but your app isn't using this feature. You can solve " \
|
||||
"this issue by either:\n\n" \
|
||||
"1) Setting config.case_insensitive_keys = [:email] in your Devise initializer and " \
|
||||
"running a migration that will downcase all emails already in the database;\n\n" \
|
||||
"2) Setting config.case_insensitive_keys = [] (so nothing will be downcased) and " \
|
||||
"making sure you are not using Devise :validatable (since validatable assumes case" \
|
||||
"insensitivity)\n"
|
||||
end
|
||||
|
||||
if Devise.apply_schema && defined?(Mongoid)
|
||||
warn "\n[DEVISE] Devise.apply_schema is true. This means Devise was " \
|
||||
"automatically configuring your DB. This no longer happens. You should " \
|
||||
"set Devise.apply_schema to false and manually set the fields used by Devise as shown here: " \
|
||||
"https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0-migration-schema-style\n"
|
||||
end
|
||||
|
||||
# TODO: Deprecate the true value of this option as well
|
||||
if Devise.use_salt_as_remember_token == false
|
||||
warn "\n[DEVISE] Devise.use_salt_as_remember_token is false which is no longer " \
|
||||
"supported. Devise now only uses the salt as remember token and the remember_token " \
|
||||
"column can be removed from your models.\n"
|
||||
end
|
||||
|
||||
if Devise.reset_password_within.nil?
|
||||
warn "\n[DEVISE] Devise.reset_password_within is nil. Please set this value to " \
|
||||
"an interval (for example, 6.hours) and add a reset_password_sent_at field to " \
|
||||
"your Devise models (if they don't have one already).\n"
|
||||
end
|
||||
end
|
||||
|
||||
config.after_initialize do
|
||||
example = <<-YAML
|
||||
en:
|
||||
devise:
|
||||
registrations:
|
||||
signed_up_but_unconfirmed: 'A message with a confirmation link has been sent to your email address. Please open the link to activate your account.'
|
||||
signed_up_but_inactive: 'You have signed up successfully. However, we could not sign you in because your account is not yet activated.'
|
||||
signed_up_but_locked: 'You have signed up successfully. However, we could not sign you in because your account is locked.'
|
||||
YAML
|
||||
|
||||
if I18n.t(:"devise.registrations.reasons", :default => {}).present?
|
||||
warn "\n[DEVISE] devise.registrations.reasons in yml files is deprecated, " \
|
||||
"please use devise.registrations.signed_up_but_REASON instead. The default values are:\n\n#{example}\n"
|
||||
end
|
||||
|
||||
if I18n.t(:"devise.registrations.inactive_signed_up", :default => "").present?
|
||||
warn "\n[DEVISE] devise.registrations.inactive_signed_up in yml files is deprecated, " \
|
||||
"please use devise.registrations.signed_up_but_REASON instead. The default values are:\n\n#{example}\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,10 +1,25 @@
|
||||
require "active_support/core_ext/object/try"
|
||||
|
||||
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!
|
||||
finalize_without_devise!
|
||||
Devise.configure_warden!
|
||||
|
||||
@devise_finalized ||= begin
|
||||
if Devise.router_name.nil? && self != Rails.application.try(:routes)
|
||||
warn "[Devise] We have detected that you are using devise_for inside engine routes. " \
|
||||
"In this case, you probably want to set Devise.router_name = MOUNT_POINT, where " \
|
||||
"MOUNT_POINT is a symbol representing where this engine will be mounted at. For " \
|
||||
"now, Devise will default the mount point to :main_app."
|
||||
end
|
||||
|
||||
Devise.router_name ||= :main_app
|
||||
Devise.configure_warden!
|
||||
Devise.regenerate_helpers!
|
||||
true
|
||||
end
|
||||
end
|
||||
alias_method_chain :finalize!, :devise
|
||||
end
|
||||
@@ -44,23 +59,23 @@ module ActionDispatch::Routing
|
||||
#
|
||||
# You can configure your routes with some options:
|
||||
#
|
||||
# * :class_name => setup a different class to be looked up by devise,
|
||||
# if it cannot be correctly find by the route name.
|
||||
# * :class_name => setup a different class to be looked up by devise, if it cannot be
|
||||
# properly found by the route name.
|
||||
#
|
||||
# devise_for :users, :class_name => 'Account'
|
||||
#
|
||||
# * :path => allows you to setup path name that will be used, as rails routes does.
|
||||
# The following route configuration would setup your route as /accounts instead of /users:
|
||||
# The following route configuration would setup your route as /accounts instead of /users:
|
||||
#
|
||||
# devise_for :users, :path => 'accounts'
|
||||
#
|
||||
# * :singular => setup the singular name for the given resource. This is used as the instance variable name in
|
||||
# controller, as the name in routes and the scope given to warden.
|
||||
# * :singular => setup the singular name for the given resource. This is used as the instance variable
|
||||
# name in controller, as the name in routes and the scope given to warden.
|
||||
#
|
||||
# devise_for :users, :singular => :user
|
||||
#
|
||||
# * :path_names => configure different path names to overwrite defaults :sign_in, :sign_out, :sign_up,
|
||||
# :password, :confirmation, :unlock.
|
||||
# :password, :confirmation, :unlock.
|
||||
#
|
||||
# devise_for :users, :path_names => { :sign_in => 'login', :sign_out => 'logout', :password => 'secret', :confirmation => 'verification' }
|
||||
#
|
||||
@@ -69,6 +84,9 @@ module ActionDispatch::Routing
|
||||
#
|
||||
# devise_for :users, :controllers => { :sessions => "users/sessions" }
|
||||
#
|
||||
# * :failure_app => a rack app which is invoked whenever there is a failure. Strings representing a given
|
||||
# are also allowed as parameter.
|
||||
#
|
||||
# * :sign_out_via => the HTTP method(s) accepted for the :sign_out action (default: :get),
|
||||
# if you wish to restrict this to accept only :post or :delete requests you should do:
|
||||
#
|
||||
@@ -76,15 +94,16 @@ module ActionDispatch::Routing
|
||||
#
|
||||
# You need to make sure that your sign_out controls trigger a request with a matching HTTP method.
|
||||
#
|
||||
# * :module => the namespace to find controlers. By default, devise will access devise/sessions,
|
||||
# devise/registrations and so on. If you want to namespace all at once, use module:
|
||||
# * :module => the namespace to find controllers (default: "devise", thus
|
||||
# accessing devise/sessions, devise/registrations, and so on). If you want
|
||||
# to namespace all at once, use module:
|
||||
#
|
||||
# devise_for :users, :module => "users"
|
||||
#
|
||||
# Notice that whenever you use namespace in the router DSL, it automatically sets the module.
|
||||
# So the following setup:
|
||||
#
|
||||
# namespace :publisher
|
||||
# namespace :publisher do
|
||||
# devise_for :account
|
||||
# end
|
||||
#
|
||||
@@ -93,12 +112,32 @@ module ActionDispatch::Routing
|
||||
#
|
||||
# Also pay attention that when you use a namespace it will affect all the helpers and methods for controllers
|
||||
# and views. For example, using the above setup you'll end with following methods:
|
||||
# current_publisher_account, authenticate_publisher_account!, pusblisher_account_signed_in, etc.
|
||||
# current_publisher_account, authenticate_publisher_account!, publisher_account_signed_in, etc.
|
||||
#
|
||||
# * :skip => tell which controller you want to skip routes from being created:
|
||||
#
|
||||
# devise_for :users, :skip => :sessions
|
||||
#
|
||||
# * :only => the opposite of :skip, tell which controllers only to generate routes to:
|
||||
#
|
||||
# devise_for :users, :only => :sessions
|
||||
#
|
||||
# * :skip_helpers => skip generating Devise url helpers like new_session_path(@user).
|
||||
# This is useful to avoid conflicts with previous routes and is false by default.
|
||||
# It accepts true as option, meaning it will skip all the helpers for the controllers
|
||||
# given in :skip but it also accepts specific helpers to be skipped:
|
||||
#
|
||||
# devise_for :users, :skip => [:registrations, :confirmations], :skip_helpers => true
|
||||
# devise_for :users, :skip_helpers => [:registrations, :confirmations]
|
||||
#
|
||||
# * :format => include "(.:format)" in the generated routes? true by default, set to false to disable:
|
||||
#
|
||||
# devise_for :users, :format => false
|
||||
#
|
||||
# * :constraints => works the same as Rails' contraints
|
||||
#
|
||||
# * :defaults => works the same as Rails' defaults
|
||||
#
|
||||
# ==== Scoping
|
||||
#
|
||||
# Following Rails 3 routes DSL, you can nest devise_for calls inside a scope:
|
||||
@@ -107,15 +146,15 @@ module ActionDispatch::Routing
|
||||
# devise_for :users
|
||||
# end
|
||||
#
|
||||
# However, since Devise uses the request path to retrieve the current user, it has one caveats.
|
||||
# If you are using a dynamic segment, as below:
|
||||
# However, since Devise uses the request path to retrieve the current user,
|
||||
# this has one caveat: If you are using a dynamic segment, like so ...
|
||||
#
|
||||
# scope ":locale" do
|
||||
# devise_for :users
|
||||
# end
|
||||
#
|
||||
# You are required to configure default_url_options in your ApplicationController class level, so
|
||||
# Devise can pick it:
|
||||
# you are required to configure default_url_options in your
|
||||
# ApplicationController class, so Devise can pick it:
|
||||
#
|
||||
# class ApplicationController < ActionController::Base
|
||||
# def self.default_url_options
|
||||
@@ -124,9 +163,9 @@ module ActionDispatch::Routing
|
||||
# end
|
||||
#
|
||||
# ==== Adding custom actions to override controllers
|
||||
#
|
||||
# You can pass a block to devise_for that will add any routes defined in the block to Devise's
|
||||
# list of known actions. This is important if you add a custom action to a controller that
|
||||
#
|
||||
# You can pass a block to devise_for that will add any routes defined in the block to Devise's
|
||||
# list of known actions. This is important if you add a custom action to a controller that
|
||||
# overrides an out of the box Devise controller.
|
||||
# For example:
|
||||
#
|
||||
@@ -148,12 +187,16 @@ module ActionDispatch::Routing
|
||||
# end
|
||||
#
|
||||
def devise_for(*resources)
|
||||
@devise_finalized = false
|
||||
options = resources.extract_options!
|
||||
|
||||
options[:as] ||= @scope[:as] if @scope[:as].present?
|
||||
options[:module] ||= @scope[:module] if @scope[:module].present?
|
||||
options[:path_prefix] ||= @scope[:path] if @scope[:path].present?
|
||||
options[:path_names] = (@scope[:path_names] || {}).merge(options[:path_names] || {})
|
||||
options[:constraints] = (@scope[:constraints] || {}).merge(options[:constraints] || {})
|
||||
options[:defaults] = (@scope[:defaults] || {}).merge(options[:defaults] || {})
|
||||
options[:options] = (@scope[:options] || {}).merge({:format => false}) if options[:format] == false
|
||||
|
||||
resources.map!(&:to_sym)
|
||||
|
||||
@@ -172,12 +215,18 @@ module ActionDispatch::Routing
|
||||
raise_no_devise_method_error!(mapping.class_name)
|
||||
end
|
||||
|
||||
routes = mapping.routes
|
||||
routes -= Array(options.delete(:skip)).map { |s| s.to_s.singularize.to_sym }
|
||||
routes = mapping.used_routes
|
||||
|
||||
devise_scope mapping.name do
|
||||
yield if block_given?
|
||||
with_devise_exclusive_scope mapping.fullpath, mapping.name do
|
||||
if block_given?
|
||||
ActiveSupport::Deprecation.warn "Passing a block to devise_for is deprecated. " \
|
||||
"Please remove the block from devise_for (only the block, the call to " \
|
||||
"devise_for must still exist) and call devise_scope :#{mapping.name} do ... end " \
|
||||
"with the block instead", caller
|
||||
yield
|
||||
end
|
||||
|
||||
with_devise_exclusive_scope mapping.fullpath, mapping.name, options do
|
||||
routes.each { |mod| send("devise_#{mod}", mapping, mapping.controllers) }
|
||||
end
|
||||
end
|
||||
@@ -186,11 +235,15 @@ module ActionDispatch::Routing
|
||||
|
||||
# Allow you to add authentication request from the router:
|
||||
#
|
||||
# authenticate(:user) do
|
||||
# authenticate do
|
||||
# resources :post
|
||||
# end
|
||||
#
|
||||
def authenticate(scope)
|
||||
# authenticate(:admin) do
|
||||
# resources :users
|
||||
# end
|
||||
#
|
||||
def authenticate(scope=nil)
|
||||
constraint = lambda do |request|
|
||||
request.env["warden"].authenticate!(:scope => scope)
|
||||
end
|
||||
@@ -200,6 +253,50 @@ module ActionDispatch::Routing
|
||||
end
|
||||
end
|
||||
|
||||
# Allow you to route based on whether a scope is authenticated. You
|
||||
# can optionally specify which scope.
|
||||
#
|
||||
# authenticated :admin do
|
||||
# root :to => 'admin/dashboard#show'
|
||||
# end
|
||||
#
|
||||
# authenticated do
|
||||
# root :to => 'dashboard#show'
|
||||
# end
|
||||
#
|
||||
# root :to => 'landing#show'
|
||||
#
|
||||
def authenticated(scope=nil)
|
||||
constraint = lambda do |request|
|
||||
request.env["warden"].authenticate? :scope => scope
|
||||
end
|
||||
|
||||
constraints(constraint) do
|
||||
yield
|
||||
end
|
||||
end
|
||||
|
||||
# Allow you to route based on whether a scope is *not* authenticated.
|
||||
# You can optionally specify which scope.
|
||||
#
|
||||
# unauthenticated do
|
||||
# as :user do
|
||||
# root :to => 'devise/registrations#new'
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# root :to => 'dashboard#show'
|
||||
#
|
||||
def unauthenticated(scope=nil)
|
||||
constraint = lambda do |request|
|
||||
not request.env["warden"].authenticate? :scope => scope
|
||||
end
|
||||
|
||||
constraints(constraint) do
|
||||
yield
|
||||
end
|
||||
end
|
||||
|
||||
# Sets the devise scope to be used in the controller. If you have custom routes,
|
||||
# you are required to call this method (also aliased as :as) in order to specify
|
||||
# to which controller it is targetted.
|
||||
@@ -211,6 +308,17 @@ module ActionDispatch::Routing
|
||||
# Notice you cannot have two scopes mapping to the same URL. And remember, if
|
||||
# you try to access a devise controller without specifying a scope, it will
|
||||
# raise ActionNotFound error.
|
||||
#
|
||||
# Also be aware of that 'devise_scope' and 'as' use the singular form of the
|
||||
# noun where other devise route commands expect the plural form. This would be a
|
||||
# good and working example.
|
||||
#
|
||||
# devise_scope :user do
|
||||
# match "/some/route" => "some_devise_controller"
|
||||
# end
|
||||
# devise_for :users
|
||||
#
|
||||
# Notice and be aware of the differences above between :user and :users
|
||||
def devise_scope(scope)
|
||||
constraint = lambda do |request|
|
||||
request.env["devise.mapping"] = Devise.mappings[scope]
|
||||
@@ -256,7 +364,7 @@ module ActionDispatch::Routing
|
||||
:cancel => mapping.path_names[:cancel]
|
||||
}
|
||||
|
||||
resource :registration, :except => :show, :path => mapping.path_names[:registration],
|
||||
resource :registration, :only => [:new, :create, :edit, :update, :destroy], :path => mapping.path_names[:registration],
|
||||
:path_names => path_names, :controller => controllers[:registrations] do
|
||||
get :cancel
|
||||
end
|
||||
@@ -267,28 +375,34 @@ module ActionDispatch::Routing
|
||||
path_prefix = "/#{mapping.path}/auth".squeeze("/")
|
||||
|
||||
if ::OmniAuth.config.path_prefix && ::OmniAuth.config.path_prefix != path_prefix
|
||||
warn "[DEVISE] You can only add :omniauthable behavior to one model."
|
||||
raise "Wrong OmniAuth configuration. If you are getting this exception, it means that either:\n\n" \
|
||||
"1) You are manually setting OmniAuth.config.path_prefix and it doesn't match the Devise one\n" \
|
||||
"2) You are setting :omniauthable in more than one model\n" \
|
||||
"3) You changed your Devise routes/OmniAuth setting and haven't restarted your server"
|
||||
else
|
||||
::OmniAuth.config.path_prefix = path_prefix
|
||||
end
|
||||
|
||||
match "#{path_prefix}/:action/callback", :action => Regexp.union(mapping.to.omniauth_providers.map(&:to_s)),
|
||||
match "#{path_prefix}/:action/callback", :constraints => { :action => Regexp.union(mapping.to.omniauth_providers.map(&:to_s)) },
|
||||
:to => controllers[:omniauth_callbacks], :as => :omniauth_callback
|
||||
ensure
|
||||
@scope[:path] = path
|
||||
end
|
||||
|
||||
def with_devise_exclusive_scope(new_path, new_as) #:nodoc:
|
||||
old_as, old_path, old_module = @scope[:as], @scope[:path], @scope[:module]
|
||||
@scope[:as], @scope[:path], @scope[:module] = new_as, new_path, nil
|
||||
def with_devise_exclusive_scope(new_path, new_as, options) #:nodoc:
|
||||
old_as, old_path, old_module, old_constraints, old_defaults, old_options =
|
||||
*@scope.values_at(:as, :path, :module, :constraints, :defaults, :options)
|
||||
@scope[:as], @scope[:path], @scope[:module], @scope[:constraints], @scope[:defaults], @scope[:options] =
|
||||
new_as, new_path, nil, *options.values_at(:constraints, :defaults, :options)
|
||||
yield
|
||||
ensure
|
||||
@scope[:as], @scope[:path], @scope[:module] = old_as, old_path, old_module
|
||||
@scope[:as], @scope[:path], @scope[:module], @scope[:constraints], @scope[:defaults], @scope[:options] =
|
||||
old_as, old_path, old_module, old_constraints, old_defaults, old_options
|
||||
end
|
||||
|
||||
def raise_no_devise_method_error!(klass) #:nodoc:
|
||||
raise "#{klass} does not respond to 'devise' method. This usually means you haven't " <<
|
||||
"loaded your ORM file or it's being loaded too late. To fix it, be sure to require 'devise/orm/YOUR_ORM' " <<
|
||||
raise "#{klass} does not respond to 'devise' method. This usually means you haven't " \
|
||||
"loaded your ORM file or it's being loaded too late. To fix it, be sure to require 'devise/orm/YOUR_ORM' " \
|
||||
"inside 'config/initializers/devise.rb' or before your application definition in 'config/application.rb'"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -15,21 +15,16 @@ end
|
||||
|
||||
class Warden::SessionSerializer
|
||||
def serialize(record)
|
||||
[record.class.name, record.to_key, record.authenticatable_salt]
|
||||
klass = record.class
|
||||
array = klass.serialize_into_session(record)
|
||||
array.unshift(klass.name)
|
||||
end
|
||||
|
||||
def deserialize(keys)
|
||||
if keys.size == 2
|
||||
raise "Devise changed how it stores objects in session. If you are seeing this message, " <<
|
||||
"you can fix it by changing one character in your cookie secret or cleaning up your " <<
|
||||
"database sessions if you are using a db store."
|
||||
end
|
||||
|
||||
klass, id, salt = keys
|
||||
klass, *args = keys
|
||||
|
||||
begin
|
||||
record = klass.constantize.to_adapter.get(id)
|
||||
record if record && record.authenticatable_salt == salt
|
||||
ActiveSupport::Inflector.constantize(klass).serialize_from_session(*args)
|
||||
rescue NameError => e
|
||||
if e.message =~ /uninitialized constant/
|
||||
Rails.logger.debug "[Devise] Trying to deserialize invalid class #{klass}"
|
||||
@@ -39,87 +34,4 @@ class Warden::SessionSerializer
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
unless Devise.rack_session?
|
||||
# We cannot use Rails Indifferent Hash because it messes up the flash object.
|
||||
class Devise::IndifferentHash < Hash
|
||||
alias_method :regular_writer, :[]= unless method_defined?(:regular_writer)
|
||||
alias_method :regular_update, :update unless method_defined?(:regular_update)
|
||||
|
||||
def [](key)
|
||||
super(convert_key(key))
|
||||
end
|
||||
|
||||
def []=(key, value)
|
||||
regular_writer(convert_key(key), value)
|
||||
end
|
||||
|
||||
alias_method :store, :[]=
|
||||
|
||||
def update(other_hash)
|
||||
other_hash.each_pair { |key, value| regular_writer(convert_key(key), value) }
|
||||
self
|
||||
end
|
||||
|
||||
alias_method :merge!, :update
|
||||
|
||||
def key?(key)
|
||||
super(convert_key(key))
|
||||
end
|
||||
|
||||
alias_method :include?, :key?
|
||||
alias_method :has_key?, :key?
|
||||
alias_method :member?, :key?
|
||||
|
||||
def fetch(key, *extras)
|
||||
super(convert_key(key), *extras)
|
||||
end
|
||||
|
||||
def values_at(*indices)
|
||||
indices.collect {|key| self[convert_key(key)]}
|
||||
end
|
||||
|
||||
def merge(hash)
|
||||
self.dup.update(hash)
|
||||
end
|
||||
|
||||
def delete(key)
|
||||
super(convert_key(key))
|
||||
end
|
||||
|
||||
def stringify_keys!; self end
|
||||
def stringify_keys; dup end
|
||||
|
||||
undef :symbolize_keys!
|
||||
def symbolize_keys; to_hash.symbolize_keys end
|
||||
|
||||
def to_options!; self end
|
||||
def to_hash; Hash.new.update(self) end
|
||||
|
||||
protected
|
||||
|
||||
def convert_key(key)
|
||||
key.kind_of?(Symbol) ? key.to_s : key
|
||||
end
|
||||
end
|
||||
|
||||
class ActionDispatch::Request
|
||||
def reset_session
|
||||
session.destroy if session && session.respond_to?(:destroy)
|
||||
self.session = {}
|
||||
@env['action_dispatch.request.flash_hash'] = nil
|
||||
end
|
||||
end
|
||||
|
||||
Warden::Manager.after_set_user :event => [:set_user, :authentication] do |record, warden, options|
|
||||
if options[:scope] && warden.authenticated?(options[:scope])
|
||||
request, flash = warden.request, warden.env['action_dispatch.request.flash_hash']
|
||||
backup = request.session.to_hash
|
||||
backup.delete("session_id")
|
||||
request.reset_session
|
||||
warden.env['action_dispatch.request.flash_hash'] = flash
|
||||
request.session = Devise::IndifferentHash.new.update(backup)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -3,11 +3,12 @@ module Devise
|
||||
# and overwrite the apply_schema method.
|
||||
module Schema
|
||||
|
||||
# Creates email when enabled (on by default), encrypted_password and password_salt.
|
||||
# Creates encrypted_password, and email when it is used as an authentication
|
||||
# key (default).
|
||||
#
|
||||
# == Options
|
||||
# * :null - When true, allow columns to be null.
|
||||
# * :default - Should be set to "" when :null is false.
|
||||
# * :default - Set to "" when :null is false, unless overridden.
|
||||
#
|
||||
# == Notes
|
||||
# For Datamapper compatibility, we explicitly hardcode the limit for the
|
||||
@@ -15,13 +16,14 @@ module Devise
|
||||
def database_authenticatable(options={})
|
||||
null = options[:null] || false
|
||||
default = options.key?(:default) ? options[:default] : ("" if null == false)
|
||||
include_email = !self.respond_to?(:authentication_keys) || self.authentication_keys.include?(:email)
|
||||
include_email = !respond_to?(:authentication_keys) || self.authentication_keys.include?(:email)
|
||||
|
||||
apply_devise_schema :email, String, :null => null, :default => default if include_email
|
||||
apply_devise_schema :encrypted_password, String, :null => null, :default => default, :limit => 128
|
||||
end
|
||||
|
||||
# Creates password salt for encryption support.
|
||||
# Creates password salt for encryption support when using encryptors other
|
||||
# than the database_authenticable default of bcrypt.
|
||||
def encryptable
|
||||
apply_devise_schema :password_salt, String
|
||||
end
|
||||
@@ -38,9 +40,19 @@ module Devise
|
||||
apply_devise_schema :confirmation_sent_at, DateTime
|
||||
end
|
||||
|
||||
# Creates reset_password_token.
|
||||
def recoverable
|
||||
# Creates unconfirmed_email
|
||||
def reconfirmable
|
||||
apply_devise_schema :unconfirmed_email, String
|
||||
end
|
||||
|
||||
# Creates reset_password_token and reset_password_sent_at.
|
||||
#
|
||||
# == Options
|
||||
# * :reset_within - When true, adds a column that reset passwords within some date
|
||||
def recoverable(options={})
|
||||
use_within = options.fetch(:reset_within, Devise.reset_password_within.present?)
|
||||
apply_devise_schema :reset_password_token, String
|
||||
apply_devise_schema :reset_password_sent_at, DateTime if use_within
|
||||
end
|
||||
|
||||
# Creates remember_token and remember_created_at.
|
||||
|
||||
@@ -6,7 +6,11 @@ module Devise
|
||||
# parameters both from params or from http authorization headers. See database_authenticatable
|
||||
# for an example.
|
||||
class Authenticatable < Base
|
||||
attr_accessor :authentication_hash, :password
|
||||
attr_accessor :authentication_hash, :authentication_type, :password
|
||||
|
||||
def store?
|
||||
!mapping.to.skip_session_storage.include?(authentication_type)
|
||||
end
|
||||
|
||||
def valid?
|
||||
valid_for_params_auth? || valid_for_http_auth?
|
||||
@@ -47,7 +51,7 @@ module Devise
|
||||
# * If all authentication keys are present;
|
||||
#
|
||||
def valid_for_http_auth?
|
||||
http_authenticatable? && request.authorization && with_authentication_hash(http_auth_hash)
|
||||
http_authenticatable? && request.authorization && with_authentication_hash(:http_auth, http_auth_hash)
|
||||
end
|
||||
|
||||
# Check if this is strategy is valid for params authentication by:
|
||||
@@ -58,8 +62,8 @@ module Devise
|
||||
# * If all authentication keys are present;
|
||||
#
|
||||
def valid_for_params_auth?
|
||||
params_authenticatable? && valid_request? &&
|
||||
valid_params? && with_authentication_hash(params_auth_hash)
|
||||
params_authenticatable? && valid_params_request? &&
|
||||
valid_params? && with_authentication_hash(:params_auth, params_auth_hash)
|
||||
end
|
||||
|
||||
# Check if the model accepts this strategy as http authenticatable.
|
||||
@@ -83,19 +87,9 @@ module Devise
|
||||
Hash[*keys.zip(decode_credentials).flatten]
|
||||
end
|
||||
|
||||
# By default, a request is valid if the controller is allowed and the VERB is POST.
|
||||
def valid_request?
|
||||
valid_controller? && valid_verb?
|
||||
end
|
||||
|
||||
# Check if the controller is the one registered for authentication.
|
||||
def valid_controller?
|
||||
mapping.controllers[:sessions] == params[:controller]
|
||||
end
|
||||
|
||||
# Check if it was a POST request.
|
||||
def valid_verb?
|
||||
request.post?
|
||||
# By default, a request is valid if the controller set the proper env variable.
|
||||
def valid_params_request?
|
||||
!!env["devise.allow_params_authentication"]
|
||||
end
|
||||
|
||||
# If the request is valid, finally check if params_auth_hash returns a hash.
|
||||
@@ -111,12 +105,12 @@ module Devise
|
||||
# Helper to decode credentials from HTTP.
|
||||
def decode_credentials
|
||||
return [] unless request.authorization && request.authorization =~ /^Basic (.*)/m
|
||||
ActiveSupport::Base64.decode64($1).split(/:/, 2)
|
||||
Base64.decode64($1).split(/:/, 2)
|
||||
end
|
||||
|
||||
# Sets the authentication hash and the password from params_auth_hash or http_auth_hash.
|
||||
def with_authentication_hash(auth_values)
|
||||
self.authentication_hash = {}
|
||||
def with_authentication_hash(auth_type, auth_values)
|
||||
self.authentication_hash, self.authentication_type = {}, auth_type
|
||||
self.password = auth_values[:password]
|
||||
|
||||
parse_authentication_key_values(auth_values, authentication_keys) &&
|
||||
@@ -157,8 +151,9 @@ module Devise
|
||||
# becomes simply :database.
|
||||
def authenticatable_name
|
||||
@authenticatable_name ||=
|
||||
self.class.name.split("::").last.underscore.sub("_authenticatable", "").to_sym
|
||||
ActiveSupport::Inflector.underscore(self.class.name.split("::").last).
|
||||
sub("_authenticatable", "").to_sym
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -9,6 +9,7 @@ module Devise
|
||||
class Rememberable < Authenticatable
|
||||
# A valid strategy for rememberable needs a remember token in the cookies.
|
||||
def valid?
|
||||
@remember_cookie = nil
|
||||
remember_cookie.present?
|
||||
end
|
||||
|
||||
@@ -41,10 +42,10 @@ module Devise
|
||||
"remember_#{scope}_token"
|
||||
end
|
||||
|
||||
# Accessor for remember cookie
|
||||
def remember_cookie
|
||||
@remember_cookie ||= cookies.signed[remember_key]
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -11,7 +11,7 @@ module Devise
|
||||
# a password, you can pass "X" as password and it will simply be ignored.
|
||||
class TokenAuthenticatable < Authenticatable
|
||||
def store?
|
||||
!mapping.to.stateless_token
|
||||
super && !mapping.to.skip_session_storage.include?(:token_auth)
|
||||
end
|
||||
|
||||
def authenticate!
|
||||
@@ -27,8 +27,8 @@ module Devise
|
||||
|
||||
private
|
||||
|
||||
# TokenAuthenticatable request is valid for any controller and any verb.
|
||||
def valid_request?
|
||||
# Token Authenticatable can be authenticated with params in any controller and any verb.
|
||||
def valid_params_request?
|
||||
true
|
||||
end
|
||||
|
||||
@@ -39,7 +39,11 @@ module Devise
|
||||
|
||||
# Try both scoped and non scoped keys.
|
||||
def params_auth_hash
|
||||
params[scope] || params
|
||||
if params[scope].kind_of?(Hash) && params[scope].has_key?(authentication_keys.first)
|
||||
params[scope]
|
||||
else
|
||||
params
|
||||
end
|
||||
end
|
||||
|
||||
# Overwrite authentication keys to use token_authentication_key.
|
||||
|
||||
@@ -13,48 +13,11 @@ module Devise
|
||||
end
|
||||
end
|
||||
|
||||
# This is a Warden::Proxy customized for functional tests. It's meant to
|
||||
# some of Warden::Manager responsibilities, as retrieving configuration
|
||||
# options and calling the FailureApp.
|
||||
class TestWarden < Warden::Proxy #:nodoc:
|
||||
attr_reader :controller
|
||||
|
||||
def initialize(controller)
|
||||
@controller = controller
|
||||
manager = Warden::Manager.new(nil) do |config|
|
||||
config.merge! Devise.warden_config
|
||||
end
|
||||
super(controller.request.env, manager)
|
||||
end
|
||||
|
||||
def authenticate!(*args)
|
||||
catch_with_redirect { super }
|
||||
end
|
||||
|
||||
def user(*args)
|
||||
catch_with_redirect { super }
|
||||
end
|
||||
|
||||
def catch_with_redirect(&block)
|
||||
result = catch(:warden, &block)
|
||||
|
||||
if result.is_a?(Hash) && !custom_failure? && !@controller.send(:performed?)
|
||||
result[:action] ||= :unauthenticated
|
||||
|
||||
env = @controller.request.env
|
||||
env["PATH_INFO"] = "/#{result[:action]}"
|
||||
env["warden.options"] = result
|
||||
Warden::Manager._run_callbacks(:before_failure, env, result)
|
||||
|
||||
status, headers, body = Devise.warden_config[:failure_app].call(env).to_a
|
||||
@controller.send :render, :status => status, :text => body,
|
||||
:content_type => headers["Content-Type"], :location => headers["Location"]
|
||||
|
||||
nil
|
||||
else
|
||||
result
|
||||
end
|
||||
end
|
||||
# Override process to consider warden.
|
||||
def process(*)
|
||||
result = nil
|
||||
_catch_warden { result = super }
|
||||
result
|
||||
end
|
||||
|
||||
# We need to setup the environment variables and the response in the controller.
|
||||
@@ -64,7 +27,12 @@ module Devise
|
||||
|
||||
# Quick access to Warden::Proxy.
|
||||
def warden #:nodoc:
|
||||
@warden ||= (@request.env['warden'] = TestWarden.new(@controller))
|
||||
@warden ||= begin
|
||||
manager = Warden::Manager.new(nil) do |config|
|
||||
config.merge! Devise.warden_config
|
||||
end
|
||||
@request.env['warden'] = Warden::Proxy.new(@request.env, manager)
|
||||
end
|
||||
end
|
||||
|
||||
# sign_in a given resource by storing its keys in the session.
|
||||
@@ -96,5 +64,27 @@ module Devise
|
||||
warden.session_serializer.delete(scope, user)
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def _catch_warden(&block)
|
||||
result = catch(:warden, &block)
|
||||
|
||||
if result.is_a?(Hash) && !warden.custom_failure? && !@controller.send(:performed?)
|
||||
result[:action] ||= :unauthenticated
|
||||
|
||||
env = @controller.request.env
|
||||
env["PATH_INFO"] = "/#{result[:action]}"
|
||||
env["warden.options"] = result
|
||||
Warden::Manager._run_callbacks(:before_failure, env, result)
|
||||
|
||||
status, headers, body = Devise.warden_config[:failure_app].call(env).to_a
|
||||
@controller.send :render, :status => status, :text => body,
|
||||
:content_type => headers["Content-Type"], :location => headers["Location"]
|
||||
|
||||
nil
|
||||
else
|
||||
result
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
module Devise
|
||||
VERSION = "1.2.0".freeze
|
||||
VERSION = "2.0.1".freeze
|
||||
end
|
||||
|
||||
@@ -9,12 +9,16 @@ module ActiveRecord
|
||||
include Devise::Generators::OrmHelpers
|
||||
source_root File.expand_path("../templates", __FILE__)
|
||||
|
||||
def generate_model
|
||||
invoke "active_record:model", [name], :migration => false unless model_exists? && behavior == :invoke
|
||||
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}"
|
||||
else
|
||||
migration_template "migration.rb", "db/migrate/devise_create_#{table_name}"
|
||||
end
|
||||
end
|
||||
|
||||
def copy_devise_migration
|
||||
migration_template "migration.rb", "db/migrate/devise_create_#{table_name}"
|
||||
def generate_model
|
||||
invoke "active_record:model", [name], :migration => false unless model_exists? && behavior == :invoke
|
||||
end
|
||||
|
||||
def inject_devise_content
|
||||
@@ -23,6 +27,45 @@ module ActiveRecord
|
||||
attr_accessible :email, :password, :password_confirmation, :remember_me
|
||||
CONTENT
|
||||
end
|
||||
|
||||
def migration_data
|
||||
<<RUBY
|
||||
## Database authenticatable
|
||||
t.string :email, :null => false, :default => ""
|
||||
t.string :encrypted_password, :null => false, :default => ""
|
||||
|
||||
## Recoverable
|
||||
t.string :reset_password_token
|
||||
t.datetime :reset_password_sent_at
|
||||
|
||||
## Rememberable
|
||||
t.datetime :remember_created_at
|
||||
|
||||
## Trackable
|
||||
t.integer :sign_in_count, :default => 0
|
||||
t.datetime :current_sign_in_at
|
||||
t.datetime :last_sign_in_at
|
||||
t.string :current_sign_in_ip
|
||||
t.string :last_sign_in_ip
|
||||
|
||||
## Encryptable
|
||||
# t.string :password_salt
|
||||
|
||||
## Confirmable
|
||||
# t.string :confirmation_token
|
||||
# t.datetime :confirmed_at
|
||||
# t.datetime :confirmation_sent_at
|
||||
# t.string :unconfirmed_email # Only if using reconfirmable
|
||||
|
||||
## Lockable
|
||||
# t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts
|
||||
# t.string :unlock_token # Only if unlock strategy is :email or :both
|
||||
# t.datetime :locked_at
|
||||
|
||||
## Token authenticatable
|
||||
# t.string :authentication_token
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,17 +1,9 @@
|
||||
class DeviseCreate<%= table_name.camelize %> < ActiveRecord::Migration
|
||||
def self.up
|
||||
def change
|
||||
create_table(:<%= table_name %>) do |t|
|
||||
t.database_authenticatable :null => false
|
||||
t.recoverable
|
||||
t.rememberable
|
||||
t.trackable
|
||||
<%= migration_data -%>
|
||||
|
||||
# t.encryptable
|
||||
# t.confirmable
|
||||
# t.lockable :lock_strategy => :<%= Devise.lock_strategy %>, :unlock_strategy => :<%= Devise.unlock_strategy %>
|
||||
# t.token_authenticatable
|
||||
|
||||
<% for attribute in attributes -%>
|
||||
<% attributes.each do |attribute| -%>
|
||||
t.<%= attribute.type %> :<%= attribute.name %>
|
||||
<% end -%>
|
||||
|
||||
@@ -24,8 +16,4 @@ class DeviseCreate<%= table_name.camelize %> < ActiveRecord::Migration
|
||||
# add_index :<%= table_name %>, :unlock_token, :unique => true
|
||||
# add_index :<%= table_name %>, :authentication_token, :unique => true
|
||||
end
|
||||
|
||||
def self.down
|
||||
drop_table :<%= table_name %>
|
||||
end
|
||||
end
|
||||
|
||||
26
lib/generators/active_record/templates/migration_existing.rb
Normal file
26
lib/generators/active_record/templates/migration_existing.rb
Normal file
@@ -0,0 +1,26 @@
|
||||
class AddDeviseTo<%= table_name.camelize %> < ActiveRecord::Migration
|
||||
def self.up
|
||||
change_table(:<%= table_name %>) do |t|
|
||||
<%= migration_data -%>
|
||||
|
||||
<% attributes.each do |attribute| -%>
|
||||
t.<%= attribute.type %> :<%= attribute.name %>
|
||||
<% end -%>
|
||||
|
||||
# Uncomment below if timestamps were not included in your original model.
|
||||
# t.timestamps
|
||||
end
|
||||
|
||||
add_index :<%= table_name %>, :email, :unique => true
|
||||
add_index :<%= table_name %>, :reset_password_token, :unique => true
|
||||
# add_index :<%= table_name %>, :confirmation_token, :unique => true
|
||||
# add_index :<%= table_name %>, :unlock_token, :unique => true
|
||||
# add_index :<%= table_name %>, :authentication_token, :unique => true
|
||||
end
|
||||
|
||||
def self.down
|
||||
# By default, we don't want to make any assumption about how to roll back a migration when your
|
||||
# model already existed. Please edit below which fields you would like to remove in this migration.
|
||||
raise ActiveRecord::IrreversibleMigration
|
||||
end
|
||||
end
|
||||
@@ -9,9 +9,12 @@ module Devise
|
||||
|
||||
hook_for :orm
|
||||
|
||||
class_option :routes, :desc => "Generate routes", :type => :boolean, :default => true
|
||||
|
||||
def add_devise_routes
|
||||
devise_route = "devise_for :#{plural_name}"
|
||||
devise_route += %Q(, :class_name => "#{class_name}") if class_name.include?("::")
|
||||
devise_route << %Q(, :class_name => "#{class_name}") if class_name.include?("::")
|
||||
devise_route << %Q(, :skip => :all) unless options.routes?
|
||||
route devise_route
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
require 'active_support/secure_random'
|
||||
require 'securerandom'
|
||||
|
||||
module Devise
|
||||
module Generators
|
||||
@@ -21,4 +21,4 @@ module Devise
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -14,6 +14,14 @@ CONTENT
|
||||
def model_exists?
|
||||
File.exists?(File.join(destination_root, model_path))
|
||||
end
|
||||
|
||||
def migration_exists?(table_name)
|
||||
Dir.glob("#{File.join(destination_root, migration_path)}/[0-9]*_*.rb").grep(/\d+_add_devise_to_#{table_name}.rb$/).first
|
||||
end
|
||||
|
||||
def migration_path
|
||||
@migration_path ||= File.join("db", "migrate")
|
||||
end
|
||||
|
||||
def model_path
|
||||
@model_path ||= File.join("app", "models", "#{file_path}.rb")
|
||||
|
||||
@@ -1,26 +1,101 @@
|
||||
require 'tmpdir'
|
||||
|
||||
module Devise
|
||||
module Generators
|
||||
class ViewsGenerator < Rails::Generators::Base
|
||||
source_root File.expand_path("../../../../app/views", __FILE__)
|
||||
desc "Copies all Devise views to your application."
|
||||
# Include this module in your generator to generate Devise views.
|
||||
# `copy_views` is the main method and by default copies all views
|
||||
# with forms.
|
||||
module ViewPathTemplates #:nodoc:
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
argument :scope, :required => false, :default => nil,
|
||||
:desc => "The scope to copy views to"
|
||||
included do
|
||||
argument :scope, :required => false, :default => nil,
|
||||
:desc => "The scope to copy views to"
|
||||
|
||||
class_option :template_engine, :type => :string, :aliases => "-t",
|
||||
:desc => "Template engine for the views. Available options are 'erb', 'haml' and 'slim'."
|
||||
public_task :copy_views
|
||||
end
|
||||
|
||||
def copy_views
|
||||
template = options[:template_engine].to_s
|
||||
case template
|
||||
when "haml", "slim"
|
||||
warn "#{template} templates have been removed from Devise gem"
|
||||
else
|
||||
directory "devise", "app/views/#{scope || :devise}"
|
||||
# TODO: Add this to Rails itslef
|
||||
module ClassMethods
|
||||
def hide!
|
||||
Rails::Generators.hide_namespace self.namespace
|
||||
end
|
||||
end
|
||||
|
||||
def copy_views
|
||||
view_directory :confirmations
|
||||
view_directory :passwords
|
||||
view_directory :registrations
|
||||
view_directory :sessions
|
||||
view_directory :unlocks
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def view_directory(name, _target_path = nil)
|
||||
directory name.to_s, _target_path || "#{target_path}/#{name}"
|
||||
end
|
||||
|
||||
def target_path
|
||||
@target_path ||= "app/views/#{scope || :devise}"
|
||||
end
|
||||
end
|
||||
|
||||
class FormForGenerator < Rails::Generators::Base #:nodoc:
|
||||
include ViewPathTemplates
|
||||
source_root File.expand_path("../../../../app/views/devise", __FILE__)
|
||||
desc "Copies default Devise views to your application."
|
||||
hide!
|
||||
end
|
||||
|
||||
class SimpleFormForGenerator < Rails::Generators::Base #:nodoc:
|
||||
include ViewPathTemplates
|
||||
source_root File.expand_path("../../templates/simple_form_for", __FILE__)
|
||||
desc "Copies simple form enabled views to your application."
|
||||
hide!
|
||||
end
|
||||
|
||||
class ErbGenerator < Rails::Generators::Base #:nodoc:
|
||||
include ViewPathTemplates
|
||||
source_root File.expand_path("../../../../app/views/devise", __FILE__)
|
||||
desc "Copies Devise mail erb views to your application."
|
||||
hide!
|
||||
|
||||
def copy_views
|
||||
view_directory :mailer
|
||||
end
|
||||
end
|
||||
|
||||
class MarkerbGenerator < Rails::Generators::Base #:nodoc:
|
||||
include ViewPathTemplates
|
||||
source_root File.expand_path("../../templates", __FILE__)
|
||||
desc "Copies Devise mail markerb views to your application."
|
||||
hide!
|
||||
|
||||
def copy_views
|
||||
view_directory :markerb, target_path
|
||||
end
|
||||
|
||||
def target_path
|
||||
"app/views/#{scope || :devise}/mailer"
|
||||
end
|
||||
end
|
||||
|
||||
class ViewsGenerator < Rails::Generators::Base
|
||||
include ViewPathTemplates
|
||||
|
||||
source_root File.expand_path("../../../../app/views/devise", __FILE__)
|
||||
desc "Copies Devise views to your application."
|
||||
|
||||
def copy_views
|
||||
copy_file "_links.erb", "#{target_path}/_links.erb"
|
||||
end
|
||||
|
||||
hook_for :form_builder, :aliases => "-b",
|
||||
:desc => "Form builder to be used",
|
||||
:default => defined?(SimpleForm) ? "simple_form_for" : "form_for"
|
||||
|
||||
hook_for :markerb, :desc => "Generate markerb instead of erb mail views",
|
||||
:default => defined?(Markerb) ? :markerb : :erb,
|
||||
:type => :boolean
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -9,9 +9,52 @@ module Mongoid
|
||||
invoke "mongoid:model", [name] unless model_exists? && behavior == :invoke
|
||||
end
|
||||
|
||||
def inject_field_types
|
||||
inject_into_file model_path, migration_data, :after => "include Mongoid::Document\n" if model_exists?
|
||||
end
|
||||
|
||||
def inject_devise_content
|
||||
inject_into_file model_path, model_contents, :after => "include Mongoid::Document\n" if model_exists?
|
||||
end
|
||||
|
||||
def migration_data
|
||||
<<RUBY
|
||||
## Database authenticatable
|
||||
field :email, :type => String, :null => false, :default => ""
|
||||
field :encrypted_password, :type => String, :null => false, :default => ""
|
||||
|
||||
## Recoverable
|
||||
field :reset_password_token, :type => String
|
||||
field :reset_password_sent_at, :type => Time
|
||||
|
||||
## Rememberable
|
||||
field :remember_created_at, :type => Time
|
||||
|
||||
## Trackable
|
||||
field :sign_in_count, :type => Integer, :default => 0
|
||||
field :current_sign_in_at, :type => Time
|
||||
field :last_sign_in_at, :type => Time
|
||||
field :current_sign_in_ip, :type => String
|
||||
field :last_sign_in_ip, :type => String
|
||||
|
||||
## Encryptable
|
||||
# field :password_salt, :type => String
|
||||
|
||||
## Confirmable
|
||||
# field :confirmation_token, :type => String
|
||||
# field :confirmed_at, :type => Time
|
||||
# field :confirmation_sent_at, :type => Time
|
||||
# field :unconfirmed_email, :type => String # Only if using reconfirmable
|
||||
|
||||
## Lockable
|
||||
# field :failed_attempts, :type => Integer, :default => 0 # Only if lock strategy is :failed_attempts
|
||||
# field :unlock_token, :type => String # Only if unlock strategy is :email or :both
|
||||
# field :locked_at, :type => Time
|
||||
|
||||
## Token authenticatable
|
||||
# field :authentication_token, :type => String
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -22,4 +22,11 @@ Some setup you must do manually if you haven't yet:
|
||||
<p class="notice"><%= notice %></p>
|
||||
<p class="alert"><%= alert %></p>
|
||||
|
||||
4. If you are deploying Rails 3.1 on Heroku, you may want to set:
|
||||
|
||||
config.assets.initialize_on_precompile = false
|
||||
|
||||
On config/application.rb forcing your application to not access the DB
|
||||
or load models when precompiling your assets.
|
||||
|
||||
===============================================================================
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
# Use this hook to configure devise mailer, warden hooks and so forth. The first
|
||||
# four configuration values can also be set straight in your models.
|
||||
# Use this hook to configure devise mailer, warden hooks and so forth.
|
||||
# Many of these configuration options can be set straight in your model.
|
||||
Devise.setup do |config|
|
||||
# ==> Mailer Configuration
|
||||
# Configure the e-mail address which will be shown in DeviseMailer.
|
||||
config.mailer_sender = "please-change-me@config-initializers-devise.com"
|
||||
# Configure the e-mail address which will be shown in Devise::Mailer,
|
||||
# note that it will be overwritten if you use your own mailer class with default "from" parameter.
|
||||
config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com"
|
||||
|
||||
# Configure the class responsible to send e-mails.
|
||||
# config.mailer = "Devise::Mailer"
|
||||
|
||||
# Automatically apply schema changes in tableless databases
|
||||
config.apply_schema = false
|
||||
|
||||
# ==> ORM configuration
|
||||
# Load and configure the ORM. Supports :active_record (default) and
|
||||
# :mongoid (bson_ext recommended) by default. Other ORMs may be
|
||||
@@ -36,10 +40,21 @@ Devise.setup do |config|
|
||||
# to authenticate or find a user. Default is :email.
|
||||
config.case_insensitive_keys = [ :email ]
|
||||
|
||||
# Configure which authentication keys should have whitespace stripped.
|
||||
# These keys will have whitespace before and after removed upon creating or
|
||||
# modifying a user and when used to authenticate or find a user. Default is :email.
|
||||
config.strip_whitespace_keys = [ :email ]
|
||||
|
||||
# Tell if authentication through request.params is enabled. True by default.
|
||||
# It can be set to an array that will enable params authentication only for the
|
||||
# given strategies, for example, `config.params_authenticatable = [:database]` will
|
||||
# enable it only for database (email + password) authentication.
|
||||
# config.params_authenticatable = true
|
||||
|
||||
# Tell if authentication through HTTP Basic Auth is enabled. False by default.
|
||||
# It can be set to an array that will enable http authentication only for the
|
||||
# given strategies, for example, `config.http_authenticatable = [:token]` will
|
||||
# enable it only for token authentication.
|
||||
# config.http_authenticatable = false
|
||||
|
||||
# If http headers should be returned for AJAX requests. True by default.
|
||||
@@ -48,22 +63,43 @@ Devise.setup do |config|
|
||||
# The realm used in Http Basic Authentication. "Application" by default.
|
||||
# config.http_authentication_realm = "Application"
|
||||
|
||||
# It will change confirmation, password recovery and other workflows
|
||||
# to behave the same regardless if the e-mail provided was right or wrong.
|
||||
# Does not affect registerable.
|
||||
# config.paranoid = true
|
||||
|
||||
# By default Devise will store the user in session. You can skip storage for
|
||||
# :http_auth and :token_auth by adding those symbols to the array below.
|
||||
# Notice that if you are skipping storage for all authentication paths, you
|
||||
# may want to disable generating routes to Devise's sessions controller by
|
||||
# passing :skip => :sessions to `devise_for` in your config/routes.rb
|
||||
config.skip_session_storage = [:http_auth]
|
||||
|
||||
# ==> Configuration for :database_authenticatable
|
||||
# For bcrypt, this is the cost for hashing the password and defaults to 10. If
|
||||
# using other encryptors, it sets how many times you want the password re-encrypted.
|
||||
config.stretches = 10
|
||||
#
|
||||
# Limiting the stretches to just one in testing will increase the performance of
|
||||
# your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
|
||||
# a value less than 10 in other environments.
|
||||
config.stretches = Rails.env.test? ? 1 : 10
|
||||
|
||||
# Setup a pepper to generate the encrypted password.
|
||||
# config.pepper = <%= ActiveSupport::SecureRandom.hex(64).inspect %>
|
||||
# config.pepper = <%= SecureRandom.hex(64).inspect %>
|
||||
|
||||
# ==> Configuration for :confirmable
|
||||
# The time you want to give your user to confirm his account. During this time
|
||||
# he will be able to access your application without confirming. Default is 0.days
|
||||
# When confirm_within is zero, the user won't be able to sign in without confirming.
|
||||
# You can use this to let your user access some features of your application
|
||||
# without confirming the account, but blocking it after a certain period
|
||||
# (ie 2 days).
|
||||
# config.confirm_within = 2.days
|
||||
# A period that the user is allowed to access the website even without
|
||||
# confirming his account. For instance, if set to 2.days, the user will be
|
||||
# able to access the website for two days without confirming his account,
|
||||
# access will be blocked just in the third day. Default is 0.days, meaning
|
||||
# the user cannot access the website without confirming his account.
|
||||
# config.allow_unconfirmed_access_for = 2.days
|
||||
|
||||
# If true, requires any email changes to be confirmed (exctly the same way as
|
||||
# initial account confirmation) to be applied. Requires additional unconfirmed_email
|
||||
# db field (see migrations). Until confirmed new email is stored in
|
||||
# unconfirmed email column, and copied to email column on successful confirmation.
|
||||
config.reconfirmable = true
|
||||
|
||||
# Defines which key will be used when confirming an account
|
||||
# config.confirmation_keys = [ :email ]
|
||||
@@ -72,9 +108,6 @@ Devise.setup do |config|
|
||||
# The time the user will be remembered without asking for credentials again.
|
||||
# config.remember_for = 2.weeks
|
||||
|
||||
# If true, a valid remember token can be re-used between multiple browsers.
|
||||
# config.remember_across_browsers = true
|
||||
|
||||
# If true, extends the user's remember period when remembered via cookie.
|
||||
# config.extend_remember_period = false
|
||||
|
||||
@@ -82,12 +115,18 @@ Devise.setup do |config|
|
||||
# to false if you are not using database authenticatable.
|
||||
config.use_salt_as_remember_token = true
|
||||
|
||||
# ==> Configuration for :validatable
|
||||
# Range for password length. Default is 6..20.
|
||||
# config.password_length = 6..20
|
||||
# Options to be passed to the created cookie. For instance, you can set
|
||||
# :secure => true in order to force SSL only cookies.
|
||||
# config.cookie_options = {}
|
||||
|
||||
# Regex to use to validate the email address
|
||||
# config.email_regexp = /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i
|
||||
# ==> Configuration for :validatable
|
||||
# Range for password length. Default is 6..128.
|
||||
# config.password_length = 6..128
|
||||
|
||||
# Email regex used to validate email formats. It simply asserts that
|
||||
# an one (and only one) @ exists in the given string. This is mainly
|
||||
# to give user feedback and not to assert the e-mail validity.
|
||||
# config.email_regexp = /\A[^@]+@[^@]+\z/
|
||||
|
||||
# ==> Configuration for :timeoutable
|
||||
# The time you want to timeout the user session without activity. After this
|
||||
@@ -122,6 +161,11 @@ Devise.setup do |config|
|
||||
# Defines which key will be used when recovering the password for an account
|
||||
# config.reset_password_keys = [ :email ]
|
||||
|
||||
# Time interval you can reset your password with a reset password key.
|
||||
# Don't put a too small interval or your users won't have the time to
|
||||
# change their passwords.
|
||||
config.reset_password_within = 6.hours
|
||||
|
||||
# ==> Configuration for :encryptable
|
||||
# Allow you to use another encryption algorithm besides bcrypt (default). You can use
|
||||
# :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1,
|
||||
@@ -134,10 +178,6 @@ Devise.setup do |config|
|
||||
# Defines name of the authentication token params key
|
||||
# config.token_authentication_key = :auth_token
|
||||
|
||||
# If true, authentication through token does not store user in session and needs
|
||||
# to be supplied on each request. Useful if you are using the token as API token.
|
||||
# config.stateless_token = false
|
||||
|
||||
# ==> Scopes configuration
|
||||
# Turn scoped views on. Before rendering "sessions/new", it will first check for
|
||||
# "users/sessions/new". It's turned off by default because it's slower if you
|
||||
@@ -161,12 +201,11 @@ Devise.setup do |config|
|
||||
# If you have any extra navigational formats, like :iphone or :mobile, you
|
||||
# should add them to the navigational formats lists.
|
||||
#
|
||||
# The :"*/*" and "*/*" formats below is required to match Internet
|
||||
# Explorer requests.
|
||||
# config.navigational_formats = [:"*/*", "*/*", :html]
|
||||
# The "*/*" below is required to match Internet Explorer requests.
|
||||
# config.navigational_formats = ["*/*", :html]
|
||||
|
||||
# The default HTTP method used to sign out a resource. Default is :get.
|
||||
# config.sign_out_via = :get
|
||||
# The default HTTP method used to sign out a resource. Default is :delete.
|
||||
config.sign_out_via = :delete
|
||||
|
||||
# ==> OmniAuth
|
||||
# Add a new OmniAuth provider. Check the wiki for more information on setting
|
||||
@@ -178,7 +217,6 @@ Devise.setup do |config|
|
||||
# change the failure app, you can configure them inside the config.warden block.
|
||||
#
|
||||
# config.warden do |manager|
|
||||
# manager.failure_app = AnotherApp
|
||||
# manager.intercept_401 = false
|
||||
# manager.default_strategies(:scope => :user).unshift :some_external_strategy
|
||||
# end
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
Welcome <%= @resource.email %>!
|
||||
|
||||
You can confirm your account through the link below:
|
||||
|
||||
<%= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) %>
|
||||
@@ -0,0 +1,8 @@
|
||||
Hello <%= @resource.email %>!
|
||||
|
||||
Someone has requested a link to change your password, and you can do this through the link below.
|
||||
|
||||
<%= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @resource.reset_password_token) %>
|
||||
|
||||
If you didn't request this, please ignore this email.
|
||||
Your password won't change until you access the link above and create a new one.
|
||||
@@ -0,0 +1,7 @@
|
||||
Hello <%= @resource.email %>!
|
||||
|
||||
Your account has been locked due to an excessive amount of unsuccessful sign in attempts.
|
||||
|
||||
Click the link below to unlock your account:
|
||||
|
||||
<%= link_to 'Unlock my account', unlock_url(@resource, :unlock_token => @resource.unlock_token) %>
|
||||
@@ -0,0 +1,15 @@
|
||||
<h2>Resend confirmation instructions</h2>
|
||||
|
||||
<%= simple_form_for(resource, :as => resource_name, :url => confirmation_path(resource_name), :html => { :method => :post }) do |f| %>
|
||||
<%= f.error_notification %>
|
||||
|
||||
<div class="inputs">
|
||||
<%= f.input :email, :required => true %>
|
||||
</div>
|
||||
|
||||
<div class="actions">
|
||||
<%= f.button :submit, "Resend confirmation instructions" %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= render "links" %>
|
||||
@@ -0,0 +1,19 @@
|
||||
<h2>Change your password</h2>
|
||||
|
||||
<%= simple_form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :put }) do |f| %>
|
||||
<%= f.error_notification %>
|
||||
|
||||
<%= f.input :reset_password_token, :as => :hidden %>
|
||||
<%= f.full_error :reset_password_token %>
|
||||
|
||||
<div class="inputs">
|
||||
<%= f.input :password, :label => "New password", :required => true %>
|
||||
<%= f.input :password_confirmation, :label => "Confirm your new password", :required => true %>
|
||||
</div>
|
||||
|
||||
<div class="actions">
|
||||
<%= f.button :submit, "Change my password" %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= render "links" %>
|
||||
@@ -0,0 +1,15 @@
|
||||
<h2>Forgot your password?</h2>
|
||||
|
||||
<%= simple_form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :post }) do |f| %>
|
||||
<%= f.error_notification %>
|
||||
|
||||
<div class="inputs">
|
||||
<%= f.input :email, :required => true %>
|
||||
</div>
|
||||
|
||||
<div class="actions">
|
||||
<%= f.button :submit, "Send me reset password instructions" %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= render "links" %>
|
||||
@@ -0,0 +1,22 @@
|
||||
<h2>Edit <%= resource_name.to_s.humanize %></h2>
|
||||
|
||||
<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %>
|
||||
<%= f.error_notification %>
|
||||
|
||||
<div class="inputs">
|
||||
<%= f.input :email, :required => true, :autofocus => true %>
|
||||
<%= f.input :password, :hint => "leave it blank if you don't want to change it", :required => false %>
|
||||
<%= f.input :password_confirmation, :required => false %>
|
||||
<%= f.input :current_password, :hint => "we need your current password to confirm your changes", :required => true %>
|
||||
</div>
|
||||
|
||||
<div class="actions">
|
||||
<%= f.button :submit, "Update" %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<h3>Cancel my account</h3>
|
||||
|
||||
<p>Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), :confirm => "Are you sure?", :method => :delete %>.</p>
|
||||
|
||||
<%= link_to "Back", :back %>
|
||||
@@ -0,0 +1,17 @@
|
||||
<h2>Sign up</h2>
|
||||
|
||||
<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
|
||||
<%= f.error_notification %>
|
||||
|
||||
<div class="inputs">
|
||||
<%= f.input :email, :required => true, :autofocus => true %>
|
||||
<%= f.input :password, :required => true %>
|
||||
<%= f.input :password_confirmation, :required => true %>
|
||||
</div>
|
||||
|
||||
<div class="actions">
|
||||
<%= f.button :submit, "Sign up" %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= render "links" %>
|
||||
@@ -0,0 +1,15 @@
|
||||
<h2>Sign in</h2>
|
||||
|
||||
<%= simple_form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
|
||||
<div class="inputs">
|
||||
<%= f.input :email, :required => false, :autofocus => true %>
|
||||
<%= f.input :password, :required => false %>
|
||||
<%= f.input :remember_me, :as => :boolean if devise_mapping.rememberable? %>
|
||||
</div>
|
||||
|
||||
<div class="actions">
|
||||
<%= f.button :submit, "Sign in" %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= render "links" %>
|
||||
@@ -0,0 +1,15 @@
|
||||
<h2>Resend unlock instructions</h2>
|
||||
|
||||
<%= simple_form_for(resource, :as => resource_name, :url => unlock_path(resource_name), :html => { :method => :post }) do |f| %>
|
||||
<%= f.error_notification %>
|
||||
|
||||
<div class="inputs">
|
||||
<%= f.input :email, :required => true %>
|
||||
</div>
|
||||
|
||||
<div class="actions">
|
||||
<%= f.button :submit, "Resend unlock instructions" %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= render "links" %>
|
||||
@@ -45,6 +45,11 @@ class ControllerAuthenticatableTest < ActionController::TestCase
|
||||
@controller.authenticate_user!
|
||||
end
|
||||
|
||||
test 'proxy authenticate_user! options to authenticate with user scope' do
|
||||
@mock_warden.expects(:authenticate!).with(:scope => :user, :recall => "foo")
|
||||
@controller.authenticate_user!(:recall => "foo")
|
||||
end
|
||||
|
||||
test 'proxy authenticate_admin! to authenticate with admin scope' do
|
||||
@mock_warden.expects(:authenticate!).with(:scope => :admin)
|
||||
@controller.authenticate_admin!
|
||||
@@ -106,7 +111,7 @@ class ControllerAuthenticatableTest < ActionController::TestCase
|
||||
user = User.new
|
||||
@mock_warden.expects(:user).returns(user)
|
||||
@mock_warden.expects(:set_user).never
|
||||
@controller.sign_in(user)
|
||||
assert @controller.sign_in(user)
|
||||
end
|
||||
|
||||
test 'sign in again when the user is already in only if force is given' do
|
||||
@@ -123,6 +128,26 @@ class ControllerAuthenticatableTest < ActionController::TestCase
|
||||
@controller.sign_in(user, :bypass => true)
|
||||
end
|
||||
|
||||
test 'sign out clears up any signed in user from all scopes' do
|
||||
user = User.new
|
||||
@mock_warden.expects(:user).times(Devise.mappings.size)
|
||||
@mock_warden.expects(:logout).with().returns(true)
|
||||
@controller.instance_variable_set(:@current_user, user)
|
||||
@controller.instance_variable_set(:@current_admin, user)
|
||||
@controller.sign_out
|
||||
assert_equal nil, @controller.instance_variable_get(:@current_user)
|
||||
assert_equal nil, @controller.instance_variable_get(:@current_admin)
|
||||
end
|
||||
|
||||
test 'sign out clears up any signed in user by scope' do
|
||||
user = User.new
|
||||
@mock_warden.expects(:user).with(:user).returns(user)
|
||||
@mock_warden.expects(:logout).with(:user).returns(true)
|
||||
@controller.instance_variable_set(:@current_user, user)
|
||||
@controller.sign_out(:user)
|
||||
assert_equal nil, @controller.instance_variable_get(:@current_user)
|
||||
end
|
||||
|
||||
test 'sign out proxy to logout on warden' do
|
||||
@mock_warden.expects(:user).with(:user).returns(true)
|
||||
@mock_warden.expects(:logout).with(:user).returns(true)
|
||||
@@ -203,17 +228,6 @@ class ControllerAuthenticatableTest < ActionController::TestCase
|
||||
@controller.sign_in_and_redirect(admin)
|
||||
end
|
||||
|
||||
test 'redirect_location returns the stored location if set' do
|
||||
user = User.new
|
||||
@controller.session[:"user_return_to"] = "/foo.bar"
|
||||
assert_equal '/foo.bar', @controller.redirect_location('user', user)
|
||||
end
|
||||
|
||||
test 'redirect_location returns the after sign in path by default' do
|
||||
user = User.new
|
||||
assert_equal @controller.after_sign_in_path_for(:user), @controller.redirect_location('user', user)
|
||||
end
|
||||
|
||||
test 'sign out and redirect uses the configured after sign out path when signing out only the current scope' do
|
||||
swap Devise, :sign_out_all_scopes => false do
|
||||
@mock_warden.expects(:user).with(:admin).returns(true)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
require 'test_helper'
|
||||
|
||||
class MyController < ApplicationController
|
||||
include Devise::Controllers::InternalHelpers
|
||||
class MyController < DeviseController
|
||||
end
|
||||
|
||||
class HelpersTest < ActionController::TestCase
|
||||
@@ -39,12 +38,29 @@ class HelpersTest < ActionController::TestCase
|
||||
end
|
||||
|
||||
test 'require no authentication tests current mapping' do
|
||||
@mock_warden.expects(:authenticated?).with(:user).returns(true)
|
||||
@mock_warden.expects(:authenticate?).with(:rememberable, :token_authenticatable, :scope => :user).returns(true)
|
||||
@mock_warden.expects(:user).with(:user).returns(User.new)
|
||||
@controller.expects(:redirect_to).with(root_path)
|
||||
@controller.send :require_no_authentication
|
||||
end
|
||||
|
||||
test 'require no authentication only checks if already authenticated if no inputs strategies are available' do
|
||||
Devise.mappings[:user].expects(:no_input_strategies).returns([])
|
||||
@mock_warden.expects(:authenticate?).never
|
||||
@mock_warden.expects(:authenticated?).with(:user).once.returns(true)
|
||||
@mock_warden.expects(:user).with(:user).returns(User.new)
|
||||
@controller.expects(:redirect_to).with(root_path)
|
||||
@controller.send :require_no_authentication
|
||||
end
|
||||
|
||||
test 'require no authentication sets a flash message' do
|
||||
@mock_warden.expects(:authenticate?).with(:rememberable, :token_authenticatable, :scope => :user).returns(true)
|
||||
@mock_warden.expects(:user).with(:user).returns(User.new)
|
||||
@controller.expects(:redirect_to).with(root_path)
|
||||
@controller.send :require_no_authentication
|
||||
assert flash[:alert] == I18n.t("devise.failure.already_authenticated")
|
||||
end
|
||||
|
||||
test 'signed in resource returns signed in resource for current scope' do
|
||||
@mock_warden.expects(:authenticate).with(:scope => :user).returns(User.new)
|
||||
assert_kind_of User, @controller.signed_in_resource
|
||||
@@ -69,4 +85,11 @@ class HelpersTest < ActionController::TestCase
|
||||
assert flash[:notice] == 'non-blank'
|
||||
MyController.send(:protected, :set_flash_message)
|
||||
end
|
||||
|
||||
test 'navigational_formats not returning a wild card' do
|
||||
MyController.send(:public, :navigational_formats)
|
||||
Devise.navigational_formats = [:"*/*", :html]
|
||||
assert_not @controller.navigational_formats.include?(:"*/*")
|
||||
MyController.send(:protected, :navigational_formats)
|
||||
end
|
||||
end
|
||||
|
||||
16
test/controllers/sessions_controller_test.rb
Normal file
16
test/controllers/sessions_controller_test.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
require 'test_helper'
|
||||
|
||||
class SessionsControllerTest < ActionController::TestCase
|
||||
tests Devise::SessionsController
|
||||
include Devise::TestHelpers
|
||||
|
||||
test "#create doesn't raise exception after Warden authentication fails when TestHelpers included" do
|
||||
request.env["devise.mapping"] = Devise.mappings[:user]
|
||||
post :create, :user => {
|
||||
:email => "nosuchuser@example.com",
|
||||
:password => "wevdude"
|
||||
}
|
||||
assert_equal 200, @response.status
|
||||
assert_template "devise/sessions/new"
|
||||
end
|
||||
end
|
||||
19
test/delegator_test.rb
Normal file
19
test/delegator_test.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
require 'test_helper'
|
||||
|
||||
class DelegatorTest < ActiveSupport::TestCase
|
||||
def delegator
|
||||
Devise::Delegator.new
|
||||
end
|
||||
|
||||
test 'failure_app returns default failure app if no warden options in env' do
|
||||
assert_equal Devise::FailureApp, delegator.failure_app({})
|
||||
end
|
||||
|
||||
test 'failure_app returns default failure app if no scope in warden options' do
|
||||
assert_equal Devise::FailureApp, delegator.failure_app({"warden.options" => {}})
|
||||
end
|
||||
|
||||
test 'failure_app returns associated failure app by scope in the given environment' do
|
||||
assert_kind_of Proc, delegator.failure_app({"warden.options" => {:scope => "manager"}})
|
||||
end
|
||||
end
|
||||
@@ -12,8 +12,8 @@ end
|
||||
|
||||
class DeviseTest < ActiveSupport::TestCase
|
||||
test 'model options can be configured through Devise' do
|
||||
swap Devise, :confirm_within => 113, :pepper => "foo" do
|
||||
assert_equal 113, Devise.confirm_within
|
||||
swap Devise, :allow_unconfirmed_access_for => 113, :pepper => "foo" do
|
||||
assert_equal 113, Devise.allow_unconfirmed_access_for
|
||||
assert_equal "foo", Devise.pepper
|
||||
end
|
||||
end
|
||||
@@ -25,7 +25,7 @@ class DeviseTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
test 'stores warden configuration' do
|
||||
assert_equal Devise::FailureApp, Devise.warden_config.failure_app
|
||||
assert_kind_of Devise::Delegator, Devise.warden_config.failure_app
|
||||
assert_equal :user, Devise.warden_config.default_scope
|
||||
end
|
||||
|
||||
@@ -58,9 +58,6 @@ class DeviseTest < ActiveSupport::TestCase
|
||||
assert_equal :fruits, Devise::CONTROLLERS[:kivi]
|
||||
Devise::ALL.delete(:kivi)
|
||||
Devise::CONTROLLERS.delete(:kivi)
|
||||
|
||||
assert_nothing_raised(Exception) { Devise.add_module(:authenticatable_again, :model => 'devise/model/authenticatable') }
|
||||
assert defined?(Devise::Models::AuthenticatableAgain)
|
||||
end
|
||||
|
||||
test 'should complain when comparing empty or different sized passes' do
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user