mirror of
https://github.com/heartcombo/devise.git
synced 2026-01-09 23:58:06 -05:00
Compare commits
1605 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d099d8f0ac | ||
|
|
5190f52857 | ||
|
|
5790107f49 | ||
|
|
6fd21ae37e | ||
|
|
b95c321660 | ||
|
|
0061f113db | ||
|
|
1fb3fbbd88 | ||
|
|
d3f8bd6cae | ||
|
|
0642e2fc9b | ||
|
|
cc017b1f0d | ||
|
|
6c2f51e35e | ||
|
|
47db984f52 | ||
|
|
0c4615e337 | ||
|
|
85e46f0163 | ||
|
|
9913fde749 | ||
|
|
1f940f61c6 | ||
|
|
70e38fe66d | ||
|
|
872ef2b97f | ||
|
|
33fb89340a | ||
|
|
bd9bf326c0 | ||
|
|
d48414b0a5 | ||
|
|
b6a7d11e5a | ||
|
|
75ce916be9 | ||
|
|
c768366240 | ||
|
|
ca7d479e90 | ||
|
|
5bfbc264b7 | ||
|
|
9f8d3db2b4 | ||
|
|
4b0d161f95 | ||
|
|
b2b8b5bf9a | ||
|
|
beda0fe9bd | ||
|
|
8fa3951bea | ||
|
|
9724e386c3 | ||
|
|
f2de7bf84c | ||
|
|
84b8188db9 | ||
|
|
19b5bcbe0f | ||
|
|
7c8f636b98 | ||
|
|
5745d97232 | ||
|
|
86f0bff332 | ||
|
|
30ab6f923d | ||
|
|
839e8fc8ac | ||
|
|
4c83743263 | ||
|
|
e1fde192f2 | ||
|
|
73389ea491 | ||
|
|
eeb6a30752 | ||
|
|
01669c7374 | ||
|
|
ac3a25bf2e | ||
|
|
0652117c79 | ||
|
|
2261005ed5 | ||
|
|
e80e0c9a89 | ||
|
|
79e9d6e564 | ||
|
|
0c6f2adf14 | ||
|
|
77ec1b08cd | ||
|
|
2be9fb292e | ||
|
|
88dba417ef | ||
|
|
b98f021d0f | ||
|
|
c026b5a3f6 | ||
|
|
3696cbf33e | ||
|
|
cbfdcbeaed | ||
|
|
130d684198 | ||
|
|
f0f3e15c08 | ||
|
|
19a1ea5211 | ||
|
|
6c2c808478 | ||
|
|
adc9a45f05 | ||
|
|
50186474d4 | ||
|
|
ffab77c35e | ||
|
|
cde2229e59 | ||
|
|
397fce1f9d | ||
|
|
f044916f94 | ||
|
|
0415564a7d | ||
|
|
ed6f2abc23 | ||
|
|
96a0477555 | ||
|
|
da5464acf6 | ||
|
|
1c8fc18fad | ||
|
|
fbf667e009 | ||
|
|
071ba358a9 | ||
|
|
ef4db2e93d | ||
|
|
6a2ef52aa0 | ||
|
|
d821275588 | ||
|
|
59966e817c | ||
|
|
b1df686a2e | ||
|
|
ae426dcc1c | ||
|
|
1646684af9 | ||
|
|
ac58c28617 | ||
|
|
7d72121bd7 | ||
|
|
10235f9d72 | ||
|
|
5d311e7557 | ||
|
|
5d86327e4d | ||
|
|
61903b534a | ||
|
|
ee61d86546 | ||
|
|
06a2cff140 | ||
|
|
2f36d0dd32 | ||
|
|
d5a2a9b2da | ||
|
|
8ee1591868 | ||
|
|
18c377e0d7 | ||
|
|
00a01c2bc4 | ||
|
|
00e8841e93 | ||
|
|
f79bb31ee6 | ||
|
|
d6449d014e | ||
|
|
b853871667 | ||
|
|
f796439cf2 | ||
|
|
692175b897 | ||
|
|
68dc20cba2 | ||
|
|
90dbae4c7a | ||
|
|
564e588f5e | ||
|
|
8f4b06542e | ||
|
|
7513512000 | ||
|
|
7b04ecdddb | ||
|
|
50338b34f9 | ||
|
|
75268bed5c | ||
|
|
e873e2aeed | ||
|
|
b27491061e | ||
|
|
9e096a4113 | ||
|
|
8c7bf7dd15 | ||
|
|
f7dd59839c | ||
|
|
84c4759f58 | ||
|
|
e345d3940c | ||
|
|
d59301ed2a | ||
|
|
48751783a7 | ||
|
|
691172d01f | ||
|
|
eb51d0365f | ||
|
|
422bf89182 | ||
|
|
4962fbcb51 | ||
|
|
be2b481385 | ||
|
|
d169ef3641 | ||
|
|
2a64972321 | ||
|
|
33fac7f765 | ||
|
|
5c2e3e1a12 | ||
|
|
4a24667e80 | ||
|
|
c3d9dc3007 | ||
|
|
df0a9401b1 | ||
|
|
f7f086faae | ||
|
|
6ae64b1723 | ||
|
|
7d41072c0e | ||
|
|
2f75b12add | ||
|
|
352dd1f2fc | ||
|
|
bdf0bc7b1e | ||
|
|
b1f490a2f8 | ||
|
|
73f617db7b | ||
|
|
1da8490dbc | ||
|
|
6e79c5c242 | ||
|
|
f4db03d31c | ||
|
|
8bc1096099 | ||
|
|
a23247d431 | ||
|
|
6a37945025 | ||
|
|
dcada8fe75 | ||
|
|
f80cecc864 | ||
|
|
1d6ee13aae | ||
|
|
01d3ed7172 | ||
|
|
a1411c885f | ||
|
|
6e48fcee76 | ||
|
|
42a0c30139 | ||
|
|
87f2fa9767 | ||
|
|
8463c6dce4 | ||
|
|
9b77ac0cab | ||
|
|
0afae74386 | ||
|
|
56c1ab0824 | ||
|
|
1ec23994f2 | ||
|
|
2950434ed3 | ||
|
|
1aca139c65 | ||
|
|
fa451306fc | ||
|
|
c179cef365 | ||
|
|
1579ec9a87 | ||
|
|
cbc6926e3d | ||
|
|
9678b422ff | ||
|
|
d1bf31729d | ||
|
|
a89a2052b8 | ||
|
|
6c80839e7b | ||
|
|
972ac3b5f0 | ||
|
|
caa8961938 | ||
|
|
619826fbc8 | ||
|
|
fe62d1bf6a | ||
|
|
95f20587ef | ||
|
|
8171ad39e0 | ||
|
|
0c9b79947d | ||
|
|
4c9680787d | ||
|
|
6eeb9e4b7d | ||
|
|
80b2240ef0 | ||
|
|
2f142724c5 | ||
|
|
174c2903d7 | ||
|
|
1f4c8e39f8 | ||
|
|
3caab6d2ea | ||
|
|
4e5a9bd600 | ||
|
|
fef34d360b | ||
|
|
05ddd9c204 | ||
|
|
ba2e44c6a4 | ||
|
|
4f07ed42e3 | ||
|
|
66716023e4 | ||
|
|
4bc2ff997a | ||
|
|
b1633f2454 | ||
|
|
41a91188f5 | ||
|
|
4def600076 | ||
|
|
18a18e4c72 | ||
|
|
85c90671bc | ||
|
|
16b688eced | ||
|
|
37c55eb192 | ||
|
|
2d7dc3e82d | ||
|
|
e7a8a7247c | ||
|
|
c4818a9fb2 | ||
|
|
8c2a7146df | ||
|
|
311e3206c9 | ||
|
|
6ad6b3d2a6 | ||
|
|
471a05fd59 | ||
|
|
7a12655111 | ||
|
|
1b26869b74 | ||
|
|
13f35d80a9 | ||
|
|
1c4faa7d8a | ||
|
|
c26ed53927 | ||
|
|
fe0f6e96b3 | ||
|
|
6dd7ccee68 | ||
|
|
9327cf8af5 | ||
|
|
512b52e23a | ||
|
|
5df7105301 | ||
|
|
a84fdb771f | ||
|
|
ff75341c75 | ||
|
|
f0d48a96ca | ||
|
|
215fdf119e | ||
|
|
985b646ee1 | ||
|
|
622e480c4b | ||
|
|
2e78a46c52 | ||
|
|
b1b6e53d6f | ||
|
|
65325f7f81 | ||
|
|
9bd82e5a24 | ||
|
|
0689b4558e | ||
|
|
dbea934701 | ||
|
|
8e4d5fb38f | ||
|
|
e324ee9823 | ||
|
|
54e9cabf5d | ||
|
|
7a3f6fb53d | ||
|
|
59a9576498 | ||
|
|
57eb3886ba | ||
|
|
fe9e6db0e2 | ||
|
|
db8eeb6c6e | ||
|
|
2b7328535d | ||
|
|
d4e5424360 | ||
|
|
d67d992749 | ||
|
|
b6c7aafe55 | ||
|
|
9829384829 | ||
|
|
1d79c1982a | ||
|
|
f6259531c3 | ||
|
|
ed03039d19 | ||
|
|
b6abc4623b | ||
|
|
d1949b7b42 | ||
|
|
b6e30427a3 | ||
|
|
96e0dcf5d5 | ||
|
|
ab48435211 | ||
|
|
8bcb05d6c0 | ||
|
|
6b363d6af9 | ||
|
|
2fd2a8662d | ||
|
|
f1db0809b1 | ||
|
|
30ca072f50 | ||
|
|
85ea53198a | ||
|
|
7ec4c1424d | ||
|
|
f95513e86b | ||
|
|
8baacecdcf | ||
|
|
ff6e30cec4 | ||
|
|
308275c8a8 | ||
|
|
5ed6534aa3 | ||
|
|
120ca0e3a5 | ||
|
|
d193802613 | ||
|
|
50b4d2eb6b | ||
|
|
36db032ca0 | ||
|
|
afbcc31c6a | ||
|
|
52c35b18da | ||
|
|
454a5ad1ec | ||
|
|
1698f0f57c | ||
|
|
bb6d7334d0 | ||
|
|
659ec4d6ea | ||
|
|
2e50204700 | ||
|
|
39dc9a7ba6 | ||
|
|
65ef2592f6 | ||
|
|
ad0aed3ba5 | ||
|
|
0d868b9ec1 | ||
|
|
5f440dfe13 | ||
|
|
768f8832b9 | ||
|
|
32f20dddd6 | ||
|
|
7aa93a3ecb | ||
|
|
b07dd76453 | ||
|
|
4600b4ab22 | ||
|
|
a8d2dce563 | ||
|
|
5e845ee265 | ||
|
|
a9b7a4a1de | ||
|
|
32d2f78239 | ||
|
|
2a3a8b8008 | ||
|
|
90a63d4d89 | ||
|
|
66f74ed579 | ||
|
|
d376d11d42 | ||
|
|
6664acd27f | ||
|
|
525bcd4e2d | ||
|
|
34a64070ca | ||
|
|
67f2074c81 | ||
|
|
e6717e3d68 | ||
|
|
271eac7381 | ||
|
|
4bf4036bf7 | ||
|
|
22c210c8b9 | ||
|
|
afc3888391 | ||
|
|
411b565cca | ||
|
|
f6c06ac786 | ||
|
|
852a6ff175 | ||
|
|
d6f4d936ee | ||
|
|
cba1820168 | ||
|
|
0cfc88d2ee | ||
|
|
ec3eed5d2a | ||
|
|
49873f4fea | ||
|
|
ee29bf8d42 | ||
|
|
0e0bfe6686 | ||
|
|
fafea15fa8 | ||
|
|
3752981cfa | ||
|
|
9ec1003f1e | ||
|
|
64c99bcfd4 | ||
|
|
d4351183d9 | ||
|
|
cef5c93bca | ||
|
|
eb4e23274d | ||
|
|
dacdc72581 | ||
|
|
6846014def | ||
|
|
07ef99a8f0 | ||
|
|
857af600f7 | ||
|
|
3cbced4e4e | ||
|
|
85e4a0e6ec | ||
|
|
45aca40f6c | ||
|
|
7ecbba089f | ||
|
|
205ddfb7c9 | ||
|
|
8a50b207eb | ||
|
|
9f99ccdca3 | ||
|
|
f49b605514 | ||
|
|
52b4bab461 | ||
|
|
f1ccaf86a4 | ||
|
|
b59ce51760 | ||
|
|
60d2c6fddb | ||
|
|
25a563119b | ||
|
|
a4c9d5826d | ||
|
|
1d3b89458e | ||
|
|
f94b71038e | ||
|
|
076f4b4db1 | ||
|
|
18829a56e4 | ||
|
|
ac7b1b3c1f | ||
|
|
b74f71fbed | ||
|
|
c3c0f4bd89 | ||
|
|
e860ade718 | ||
|
|
e9a8c6cb62 | ||
|
|
473a68dbf9 | ||
|
|
885d8836d1 | ||
|
|
e92ae37dc3 | ||
|
|
e6af9763fd | ||
|
|
ca73dae1f0 | ||
|
|
3623215b8c | ||
|
|
a1376ac8ea | ||
|
|
9d724cb72a | ||
|
|
91ba14e77e | ||
|
|
2cab75d72b | ||
|
|
b37a74533d | ||
|
|
939d0f25c5 | ||
|
|
61929d2e2f | ||
|
|
a7658f9d75 | ||
|
|
033e91b7b9 | ||
|
|
68de34c03e | ||
|
|
94c05e346d | ||
|
|
45298c0a37 | ||
|
|
c12fc1afea | ||
|
|
136b5b0be9 | ||
|
|
9203651110 | ||
|
|
a394ceaef1 | ||
|
|
0ab28ef8ee | ||
|
|
b928b8b3a2 | ||
|
|
075fc96f10 | ||
|
|
15f6255c7c | ||
|
|
2b79519ad1 | ||
|
|
617a8876a6 | ||
|
|
7b7af57813 | ||
|
|
a12f6ec70c | ||
|
|
fffc3b1e0e | ||
|
|
af12ec2b01 | ||
|
|
ecfc7d752a | ||
|
|
bc096994b0 | ||
|
|
ba80074b7b | ||
|
|
f04d883ac1 | ||
|
|
9bf718dd82 | ||
|
|
643d5600b2 | ||
|
|
1edae9c6c1 | ||
|
|
b41e5f5bf6 | ||
|
|
2f6ecc1328 | ||
|
|
b93288875f | ||
|
|
bb4f699d03 | ||
|
|
f1d991fa8b | ||
|
|
4ce7854f44 | ||
|
|
5ef35ee1bd | ||
|
|
6d5bccc050 | ||
|
|
3ac2c1dd18 | ||
|
|
07a41ecf6f | ||
|
|
61e85a578e | ||
|
|
88d68587e1 | ||
|
|
23ae04e6cb | ||
|
|
64c05f2ce9 | ||
|
|
c5cb60a752 | ||
|
|
803e4f5524 | ||
|
|
a909bfaf85 | ||
|
|
bc11e9f300 | ||
|
|
e3412d4207 | ||
|
|
faf8b01ecc | ||
|
|
d7337c5b26 | ||
|
|
2ab1086b80 | ||
|
|
85f2f88c59 | ||
|
|
ce3422e75a | ||
|
|
bee87843b4 | ||
|
|
18aef6ac33 | ||
|
|
890f6031c3 | ||
|
|
f3bace570d | ||
|
|
533511f8c3 | ||
|
|
6489354b0e | ||
|
|
1bbae013cc | ||
|
|
8ac8129fe7 | ||
|
|
9667a38bc9 | ||
|
|
e3df7f033e | ||
|
|
989fd92b84 | ||
|
|
de24170a79 | ||
|
|
5a0548621f | ||
|
|
0f8e472dab | ||
|
|
b190fa38c7 | ||
|
|
b0b01dae81 | ||
|
|
f2b4ba6110 | ||
|
|
d15d0ba6a5 | ||
|
|
fc3af50b55 | ||
|
|
a0a141b457 | ||
|
|
0315ca2701 | ||
|
|
9f4f973277 | ||
|
|
b825e16e36 | ||
|
|
24b4db4352 | ||
|
|
06941ac7a2 | ||
|
|
91d0360a11 | ||
|
|
17bae5bba2 | ||
|
|
1a41fff009 | ||
|
|
7739c495e7 | ||
|
|
5607f7a2c8 | ||
|
|
2a74416d68 | ||
|
|
65f08ea175 | ||
|
|
70b9bdcc9a | ||
|
|
584d5d1a81 | ||
|
|
9e7ab38bce | ||
|
|
71f5a01b83 | ||
|
|
df8ac1cfe6 | ||
|
|
72b6a0a0c9 | ||
|
|
93cf836564 | ||
|
|
d2223ee5e3 | ||
|
|
b6ab8d6776 | ||
|
|
456989ca8d | ||
|
|
2e27d1f763 | ||
|
|
27a83f3dd3 | ||
|
|
79aadb4bc9 | ||
|
|
43d0715238 | ||
|
|
fb8e093389 | ||
|
|
4b47c3ab73 | ||
|
|
a0eff85d73 | ||
|
|
aa36719bd9 | ||
|
|
33aa71c38f | ||
|
|
1f20d7da25 | ||
|
|
dfcf825721 | ||
|
|
eaae041b4c | ||
|
|
dbd79746b1 | ||
|
|
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 | ||
|
|
da510508bb | ||
|
|
02ae0c22ef | ||
|
|
edee511cd1 | ||
|
|
fbd35ec332 | ||
|
|
30b35e3727 | ||
|
|
330cafd3d2 | ||
|
|
fe9024218c | ||
|
|
0c9bd3259e | ||
|
|
b23e2e807a | ||
|
|
7876acf960 | ||
|
|
74166e224b | ||
|
|
cb778d033f | ||
|
|
1bf7da148a | ||
|
|
d58a72ee32 | ||
|
|
15d195d2f0 | ||
|
|
4f093574da | ||
|
|
64457e2c1f | ||
|
|
3f4fb1a769 | ||
|
|
1982ad9f57 | ||
|
|
569d205ca7 | ||
|
|
63b72cd512 | ||
|
|
bb89ca4865 | ||
|
|
307fe6cb60 | ||
|
|
fe2d7b5ffe | ||
|
|
d445db9e5e | ||
|
|
e4cae200f4 | ||
|
|
a535b047ff | ||
|
|
aa81df261c | ||
|
|
0cc900e7cf | ||
|
|
9bff1cf658 | ||
|
|
305059f573 | ||
|
|
392e664036 | ||
|
|
43a3431c3e | ||
|
|
930d5874ca | ||
|
|
3375985ab8 | ||
|
|
2e43944567 | ||
|
|
352edc024b | ||
|
|
b5e289c9a8 | ||
|
|
42d002702c | ||
|
|
6bd65209d5 | ||
|
|
970457f2c2 | ||
|
|
bbaaefa995 | ||
|
|
fdf6a48a7e | ||
|
|
7113beac81 | ||
|
|
0c5acc6f38 | ||
|
|
dd721f1857 | ||
|
|
ae75186c52 | ||
|
|
ca293d17ba | ||
|
|
add8f8a203 | ||
|
|
6a6ed6702e | ||
|
|
2d0f887ba7 | ||
|
|
3109b0924b | ||
|
|
bbafb70655 | ||
|
|
aac9c40cba | ||
|
|
f964ea526b | ||
|
|
bca43a7576 | ||
|
|
8440ed0101 | ||
|
|
cb5e0c4a7b | ||
|
|
0287d8cc80 | ||
|
|
a48c815dc8 | ||
|
|
f332d7e932 | ||
|
|
a14b833581 | ||
|
|
c9fe8885f9 | ||
|
|
e1c3b915e7 | ||
|
|
f06bed279a | ||
|
|
3fd206c591 | ||
|
|
7a1852e9f5 | ||
|
|
76a4800446 | ||
|
|
5f93d8355c | ||
|
|
1f8909458f | ||
|
|
68f699bfd4 | ||
|
|
0615c0a0a4 | ||
|
|
c78bb68c66 | ||
|
|
d018970c4b | ||
|
|
971f68f97d | ||
|
|
4207c2321f | ||
|
|
54dc82ad25 | ||
|
|
fa239b984a | ||
|
|
692f7b27ff | ||
|
|
258eb1c7e6 | ||
|
|
aa61034d40 | ||
|
|
42f2196d01 | ||
|
|
d87521723d | ||
|
|
6e91edd5e3 | ||
|
|
fb4ec6e9da | ||
|
|
7ff0231ab7 | ||
|
|
3f086656aa | ||
|
|
55cb7195b8 | ||
|
|
555435e6fe | ||
|
|
88d4aca2c4 | ||
|
|
038eb321d4 | ||
|
|
c8c84c77c6 | ||
|
|
8f20b13f84 | ||
|
|
af1295284c | ||
|
|
1b43cb5203 | ||
|
|
b34f456096 | ||
|
|
e95eb93eb7 | ||
|
|
1a2590dc08 | ||
|
|
1cdb02bd54 | ||
|
|
7759c8b3f3 | ||
|
|
b32883a7c5 | ||
|
|
27051cb2fe | ||
|
|
e8e3df3891 | ||
|
|
2561cd4eac | ||
|
|
146090f86e | ||
|
|
4519364eaf | ||
|
|
f56c588a6a | ||
|
|
379d8c69a5 | ||
|
|
13e8bc22e3 | ||
|
|
c27bc21af9 | ||
|
|
a156576ce9 | ||
|
|
b942520dc4 | ||
|
|
a2e92a2ef2 | ||
|
|
60be68436b | ||
|
|
fe4eaf2d12 | ||
|
|
845c186f48 | ||
|
|
9f832d2cb2 | ||
|
|
a23a52b2f7 | ||
|
|
7ed1fb116f | ||
|
|
b50fd1a72e | ||
|
|
2305e8f8cf | ||
|
|
f2f9232b89 | ||
|
|
cb62597afa | ||
|
|
089c316f37 | ||
|
|
ec5bfe9119 | ||
|
|
912969b5a0 | ||
|
|
fe5ef25614 | ||
|
|
1d6944d201 | ||
|
|
268eae1013 | ||
|
|
eb7760b4b2 | ||
|
|
112f499937 | ||
|
|
a582d4dca1 | ||
|
|
4977bd1222 | ||
|
|
ed30114bd8 | ||
|
|
71450998c5 | ||
|
|
6f205fe4c4 | ||
|
|
4a8f9a9ba8 | ||
|
|
d8016ea3fd | ||
|
|
6bfcbeffdd | ||
|
|
094790295c | ||
|
|
8d1e23c67d | ||
|
|
e911abf13b | ||
|
|
26b1bc4107 | ||
|
|
0c0444c078 | ||
|
|
94c666e439 | ||
|
|
67645c68f7 | ||
|
|
13968f49af | ||
|
|
1b05d8c3bd | ||
|
|
020f919dcd | ||
|
|
b70b72b6b0 | ||
|
|
19219cbe0f | ||
|
|
32c6f7b00b | ||
|
|
67a49f3b75 | ||
|
|
14d772972d | ||
|
|
b2496d1bc1 | ||
|
|
2d2c4c63be | ||
|
|
c7efb68a77 | ||
|
|
2366530d55 | ||
|
|
505bd39700 | ||
|
|
07fedb4383 | ||
|
|
931b902583 | ||
|
|
835d1044ae | ||
|
|
f49efdff13 | ||
|
|
1f44c61d08 | ||
|
|
ad8d2d7d99 | ||
|
|
74edcb8bec | ||
|
|
e8dd48c824 | ||
|
|
0948334393 | ||
|
|
3b1f1ea719 | ||
|
|
9b468816dd | ||
|
|
4210499f7f | ||
|
|
2aeaf4b109 | ||
|
|
ab033ea986 | ||
|
|
09a46695f2 | ||
|
|
bf19b15914 | ||
|
|
94622054de | ||
|
|
c429fe8d1c | ||
|
|
d8f33b8925 | ||
|
|
e30c0f3319 | ||
|
|
976d77defe | ||
|
|
4b776c4910 | ||
|
|
f53f02f385 | ||
|
|
b3d3deb12f | ||
|
|
6b04312be5 | ||
|
|
31edd76369 | ||
|
|
3d1152fb8f | ||
|
|
ca038677f2 | ||
|
|
3e38043085 | ||
|
|
611261c64e | ||
|
|
2f360bf201 | ||
|
|
5d4e4fbb88 | ||
|
|
21d5e50054 | ||
|
|
bca72ddf59 | ||
|
|
0aa21dca4c | ||
|
|
31170b9100 | ||
|
|
cdbd03c45a | ||
|
|
fb81453274 | ||
|
|
8539f5f915 | ||
|
|
8a8ba6c70c | ||
|
|
b409184a98 | ||
|
|
e4c5158851 | ||
|
|
7bc37e5237 | ||
|
|
9f032350e3 | ||
|
|
b4a99f6698 | ||
|
|
94ccfc5322 | ||
|
|
721843c841 | ||
|
|
a1c80b6211 | ||
|
|
69ecbd1fa3 | ||
|
|
ec5f8ae831 | ||
|
|
db1ce8eeb2 | ||
|
|
e01dccaefb | ||
|
|
16c39a9f17 | ||
|
|
fbb77a6edd | ||
|
|
ab690bf36f | ||
|
|
c8cb7d270d | ||
|
|
3e9b2092f8 | ||
|
|
ef3480004c | ||
|
|
ffaba3f1d3 | ||
|
|
f60123ce01 | ||
|
|
a7cc3388b4 | ||
|
|
98e69cfd71 | ||
|
|
6a09daf570 | ||
|
|
fbac68d51a | ||
|
|
2169e5de97 | ||
|
|
4d8d1f5222 | ||
|
|
0bc80cec35 | ||
|
|
38f3f6318a | ||
|
|
1dfcbe3bd4 | ||
|
|
531f221be7 | ||
|
|
617e142e34 | ||
|
|
6613653df0 | ||
|
|
09088706bb | ||
|
|
31d821c2e0 | ||
|
|
1ed674afa8 | ||
|
|
2aa1d2f3b7 | ||
|
|
c12d75eecf | ||
|
|
b6089145c1 | ||
|
|
d02ea3153b | ||
|
|
dd11f43014 | ||
|
|
f96061b350 | ||
|
|
aaeb053c1d | ||
|
|
ec0e105c52 | ||
|
|
f3e348f6f4 | ||
|
|
589de27bcd | ||
|
|
fdb4cd5b38 | ||
|
|
d6084ab1f7 | ||
|
|
c121d8026e | ||
|
|
5429f940e7 | ||
|
|
850afec96e | ||
|
|
fb86f772e7 | ||
|
|
b2066cc229 | ||
|
|
fc37436a24 | ||
|
|
7c630fdb5e | ||
|
|
57ab87a1b6 | ||
|
|
ff0b4deb1a | ||
|
|
29e9be92b0 | ||
|
|
0388380614 | ||
|
|
a9f7b3258a | ||
|
|
7b069e641b | ||
|
|
2fdb71716f | ||
|
|
5c928df66b | ||
|
|
0f0eb4e8ce | ||
|
|
006f48232f | ||
|
|
6e71eca2dd | ||
|
|
31d7020637 | ||
|
|
c8bd965462 | ||
|
|
e582112369 | ||
|
|
736654e1bc | ||
|
|
5fb5efbd42 | ||
|
|
bf122d8fea | ||
|
|
daf4b35f85 | ||
|
|
ee49077072 | ||
|
|
c6002bb9bd | ||
|
|
5701542adc | ||
|
|
c96e17dd8d | ||
|
|
1e17b6a5ec | ||
|
|
219c05ce49 | ||
|
|
08da923276 | ||
|
|
a9aab6bd27 | ||
|
|
e1006bd6c6 | ||
|
|
b8ab9a835b | ||
|
|
617b95fdcd | ||
|
|
ab7f3bc175 | ||
|
|
3d3bb352fb | ||
|
|
731650a0f1 | ||
|
|
6754ae761c | ||
|
|
81c49c69df | ||
|
|
f3385e96ab | ||
|
|
f04e633542 | ||
|
|
701bbf2d3c | ||
|
|
01c272c692 | ||
|
|
c0c7aefce4 | ||
|
|
c31b1f2146 | ||
|
|
a707423d23 | ||
|
|
afaf42df5a | ||
|
|
fcef459db3 | ||
|
|
cd985667db | ||
|
|
83dc11df14 | ||
|
|
e6218b3ac2 | ||
|
|
d6c6e7cfe1 | ||
|
|
9d5a5beb59 | ||
|
|
0a3099663e | ||
|
|
fd35b36c4a | ||
|
|
2d67432c23 | ||
|
|
2308361fe0 | ||
|
|
817a7802e1 | ||
|
|
33ce94363e | ||
|
|
fefbf51c79 | ||
|
|
a36cb6e758 | ||
|
|
3beb6ef1a6 | ||
|
|
ac69078534 | ||
|
|
4ac6b6e407 | ||
|
|
9222601c5b | ||
|
|
4bfa98eb7c | ||
|
|
00c6f583e2 | ||
|
|
adba4e2262 | ||
|
|
ac8221aca7 | ||
|
|
d0d88cf259 | ||
|
|
bd8d11e291 | ||
|
|
0d6f303735 | ||
|
|
ef841ca17d | ||
|
|
eb3118e89a | ||
|
|
5d6900dcdb | ||
|
|
bd1006d321 | ||
|
|
17ec0c08ed | ||
|
|
b31d60ce7c | ||
|
|
b87dc84079 | ||
|
|
0aa41d6388 | ||
|
|
8bf6a66e05 | ||
|
|
3ba424774e | ||
|
|
1a9db03b22 | ||
|
|
faf771c798 | ||
|
|
bd8294aecf | ||
|
|
6c5be8dfd5 | ||
|
|
9ab64c53f4 | ||
|
|
c5999c8f61 | ||
|
|
680f2612f4 | ||
|
|
81620fecab | ||
|
|
2939a61a49 | ||
|
|
058d433f28 | ||
|
|
5aeb8cf1cf | ||
|
|
abfd7e5a4b | ||
|
|
869c658e3b | ||
|
|
5e64699a5f | ||
|
|
aecc014d33 | ||
|
|
55fd7e3b0a | ||
|
|
b4794e041b | ||
|
|
4f6113ab68 | ||
|
|
05d23f1a00 | ||
|
|
e567c00dd8 | ||
|
|
ebe3e791d6 | ||
|
|
2602ef41cf | ||
|
|
a87bc4a861 | ||
|
|
eca511a8f2 | ||
|
|
9c5ff02ff1 | ||
|
|
9f29ca480b | ||
|
|
b9df42c350 | ||
|
|
bd0e2a3180 | ||
|
|
750560ae87 | ||
|
|
e2a4ebce4a | ||
|
|
77b7692b57 | ||
|
|
ae6322efb5 | ||
|
|
238226e33a | ||
|
|
96a9c88420 | ||
|
|
dd612753f9 | ||
|
|
35923c9c69 | ||
|
|
f54013a181 | ||
|
|
1cf77028c1 | ||
|
|
7774accb6c | ||
|
|
6c49b428b3 | ||
|
|
7113dfe93a | ||
|
|
4083d679d4 | ||
|
|
7a1adbb61e | ||
|
|
18cccae82f | ||
|
|
e9fbb3d7ef | ||
|
|
04c25539c2 | ||
|
|
55bc0ace5a | ||
|
|
421256d294 | ||
|
|
8e3ef2a620 | ||
|
|
aefcd53765 | ||
|
|
0eb9208503 | ||
|
|
8824b767f3 | ||
|
|
2103a673f0 | ||
|
|
78e7642bd2 | ||
|
|
8526056bde | ||
|
|
4b272767d6 | ||
|
|
84c34ff0c4 | ||
|
|
4db3ac820b | ||
|
|
503d27f2e1 | ||
|
|
2475faf9c7 | ||
|
|
819db39263 | ||
|
|
f864259f1e | ||
|
|
12ae21117c | ||
|
|
1a224c7486 | ||
|
|
f10b747f7f | ||
|
|
8370006591 | ||
|
|
1924a915a8 | ||
|
|
7a45043bc8 | ||
|
|
ad63e25c89 | ||
|
|
895a7a4951 | ||
|
|
b8c2bbe73c | ||
|
|
b76bf10203 | ||
|
|
748eced9e8 | ||
|
|
a39312e26b | ||
|
|
b2c2cb272f | ||
|
|
fccde42f20 | ||
|
|
e90732c8c3 | ||
|
|
21874d8559 | ||
|
|
cfadaf80a2 | ||
|
|
df444663ac | ||
|
|
5b63605c94 | ||
|
|
3660cbac30 | ||
|
|
92cf50454b | ||
|
|
29ba790e07 | ||
|
|
4e2cd157c1 | ||
|
|
194959f312 | ||
|
|
e3b815de49 | ||
|
|
ac0105d15f | ||
|
|
7dbd2eac2a | ||
|
|
025c3875b6 | ||
|
|
f1a990c2ae | ||
|
|
1f4a31f1cf | ||
|
|
31910b85a2 | ||
|
|
5e1ef9319e | ||
|
|
70a429d9ff | ||
|
|
f16d01869a | ||
|
|
290cfd1f72 | ||
|
|
ed22295963 | ||
|
|
a2f84852af | ||
|
|
c4a4032b6b | ||
|
|
80895c3b9a | ||
|
|
84686d285c | ||
|
|
6c18c92598 | ||
|
|
0333caeb92 | ||
|
|
bece09c653 | ||
|
|
cd78a26f88 | ||
|
|
5c9fe5e769 | ||
|
|
fb0aec09f1 | ||
|
|
5f2a19d784 | ||
|
|
cc608f82dd | ||
|
|
7e784b258c | ||
|
|
870912d458 | ||
|
|
f0c0f5f11b | ||
|
|
7dc1842cc4 | ||
|
|
28b10e397f | ||
|
|
6ff77c9fdf | ||
|
|
d98882d745 | ||
|
|
80977c6dee | ||
|
|
7c82d3ee67 | ||
|
|
0150fddb4c | ||
|
|
c8ec42a41c | ||
|
|
bff64a6291 | ||
|
|
a65fd873dd | ||
|
|
592fa59e88 | ||
|
|
02c2df65cd | ||
|
|
59bee679ca | ||
|
|
21129ae38c | ||
|
|
f1bbce58f3 | ||
|
|
8e173f486c | ||
|
|
e905762611 | ||
|
|
d38421dde8 | ||
|
|
6162e1f5ff | ||
|
|
08c5179869 | ||
|
|
bb39243da2 | ||
|
|
9bdc711324 | ||
|
|
a4351b0b77 | ||
|
|
416bff3daa | ||
|
|
07204c500d | ||
|
|
f5bc66521f | ||
|
|
fb0f8fcd0d | ||
|
|
61fbec858e | ||
|
|
25302de1f8 | ||
|
|
b86c1c241b | ||
|
|
2bf9e462fa | ||
|
|
57712737b2 | ||
|
|
c582e9cb0f | ||
|
|
d750b48879 | ||
|
|
708fe78d86 | ||
|
|
41311eb38d | ||
|
|
da971e4249 | ||
|
|
eb23ca0ca7 | ||
|
|
c9fe7900c3 | ||
|
|
9d6a78f7f4 | ||
|
|
4da63c5395 | ||
|
|
b5f892bcdb | ||
|
|
3135487931 | ||
|
|
9291ab55b8 | ||
|
|
1db86a0810 | ||
|
|
fb832e6ffe | ||
|
|
ca6248cfd3 | ||
|
|
b9c0676a01 | ||
|
|
731f156f50 | ||
|
|
b2a50db1df | ||
|
|
6bd0c7fc2b | ||
|
|
4e674ab9a0 | ||
|
|
cbfeb59fb3 | ||
|
|
8db559148c | ||
|
|
7403c9f80e | ||
|
|
f3d654a733 | ||
|
|
bafc859f75 | ||
|
|
bf63824aae | ||
|
|
32d37cebed | ||
|
|
d2ebaa43ec | ||
|
|
045af3a614 | ||
|
|
a96fdcf0bd | ||
|
|
fd934f1434 | ||
|
|
b2fe7e49fd | ||
|
|
22392f23f2 | ||
|
|
3ce98d4163 | ||
|
|
c07b5ae858 | ||
|
|
dbe116c255 | ||
|
|
9d1a52978c | ||
|
|
0d3c6b9d99 | ||
|
|
71f74a10f7 | ||
|
|
0bd75469ba | ||
|
|
1591294b7a | ||
|
|
f9cbd3c457 | ||
|
|
66ca9f5ce0 | ||
|
|
d3c31ef16d | ||
|
|
b974b7bc78 | ||
|
|
23e608e27b | ||
|
|
0f7b311171 | ||
|
|
27c4280eca | ||
|
|
1ba525a0e9 | ||
|
|
d8b6ba9022 | ||
|
|
f5d01c217d | ||
|
|
2b5a068246 | ||
|
|
13b8ddf54c | ||
|
|
16666b7587 | ||
|
|
dac7887d7c | ||
|
|
42d06a241b | ||
|
|
3d1a04fd83 | ||
|
|
1d65a76cf3 | ||
|
|
015c74e734 | ||
|
|
6cc32db2dd | ||
|
|
597a930c74 | ||
|
|
d7f614b726 | ||
|
|
e04c5ba977 | ||
|
|
4fc41dd68a | ||
|
|
22e1fa0cb9 | ||
|
|
a6a018253e | ||
|
|
81926c2cd2 | ||
|
|
7d14f0bbb9 | ||
|
|
e038d82410 | ||
|
|
65b8908960 | ||
|
|
1c5d4771ff | ||
|
|
604b7ef61c | ||
|
|
0d704c02ca | ||
|
|
1c39590e20 | ||
|
|
6d31e368bf | ||
|
|
63deb0e80a | ||
|
|
2a082f3e4c | ||
|
|
97b7ba8659 | ||
|
|
bc00a13a3a | ||
|
|
033db1ca7c | ||
|
|
066c6e8771 | ||
|
|
96c8238b02 | ||
|
|
4b7a9204b8 | ||
|
|
ea71be8d2a | ||
|
|
6bcf18b04f | ||
|
|
bb504e08aa | ||
|
|
afe6a8c8c8 | ||
|
|
a53cc74fd9 | ||
|
|
fd035b841b | ||
|
|
e127463ac8 | ||
|
|
bd4b29c0fd | ||
|
|
6f41284714 | ||
|
|
a5ba2ac1a8 | ||
|
|
386e7be823 | ||
|
|
ca4e09390e | ||
|
|
5c19605d6f | ||
|
|
e136573905 | ||
|
|
ae729aedc3 | ||
|
|
12b64c691f | ||
|
|
4d3a3ceb43 | ||
|
|
c76df8239f | ||
|
|
28a6be456a | ||
|
|
76e45ecb12 | ||
|
|
8fbbe34bdd | ||
|
|
3a84fd4f3f | ||
|
|
37bb6948a2 | ||
|
|
f129b9ffd7 | ||
|
|
6ce33b7b57 | ||
|
|
185541b9e4 | ||
|
|
e81d428d53 | ||
|
|
de92be39f2 | ||
|
|
3f85fa88c3 | ||
|
|
2ebbc30540 | ||
|
|
b8091928a0 | ||
|
|
cbd35a846a | ||
|
|
90e8253205 | ||
|
|
3f0bae1968 | ||
|
|
59b26d8427 | ||
|
|
cbc3747039 | ||
|
|
ed3a460bad | ||
|
|
ac742e3271 | ||
|
|
cd17099401 | ||
|
|
829c85631b | ||
|
|
1a740774e3 | ||
|
|
bb9f594cc8 | ||
|
|
d64e146ec9 | ||
|
|
0a0d7ba577 | ||
|
|
288b92d2be | ||
|
|
1d4f4c19c9 | ||
|
|
901c6ae4df | ||
|
|
0e64bc74b7 | ||
|
|
038627574c | ||
|
|
af39afcdf8 | ||
|
|
1660831002 | ||
|
|
03e11e4a18 | ||
|
|
20ca0dc981 | ||
|
|
5c59f4cd1b | ||
|
|
5bc741cdab | ||
|
|
cfb3305ae5 | ||
|
|
8525b56318 | ||
|
|
bcb46bbccb | ||
|
|
484361e815 |
6
.gitignore
vendored
6
.gitignore
vendored
@@ -1,8 +1,10 @@
|
||||
**/*/log/*
|
||||
**/*/tmp/*
|
||||
test/rails_app/log/*
|
||||
test/rails_app/tmp/*
|
||||
*~
|
||||
coverage/*
|
||||
*.sqlite3
|
||||
.bundle
|
||||
rdoc/*
|
||||
pkg
|
||||
log
|
||||
test/tmp/*
|
||||
|
||||
42
.travis.yml
Normal file
42
.travis.yml
Normal file
@@ -0,0 +1,42 @@
|
||||
language: ruby
|
||||
script: "bundle exec rake test"
|
||||
rvm:
|
||||
- 1.8.7
|
||||
- 1.9.2
|
||||
- 1.9.3
|
||||
- ree
|
||||
env:
|
||||
- DEVISE_ORM=mongoid
|
||||
- DEVISE_ORM=active_record
|
||||
matrix:
|
||||
exclude:
|
||||
- rvm: ree
|
||||
env: DEVISE_ORM=mongoid
|
||||
gemfile: Gemfile
|
||||
- rvm: ree
|
||||
env: DEVISE_ORM=mongoid
|
||||
gemfile: gemfiles/Gemfile.rails-3.1.x
|
||||
- rvm: 1.8.7
|
||||
env: DEVISE_ORM=mongoid
|
||||
gemfile: Gemfile
|
||||
- rvm: 1.8.7
|
||||
env: DEVISE_ORM=mongoid
|
||||
gemfile: gemfiles/Gemfile.rails-3.1.x
|
||||
- rvm: 1.9.2
|
||||
env: DEVISE_ORM=mongoid
|
||||
gemfile: Gemfile
|
||||
- rvm: 1.9.2
|
||||
env: DEVISE_ORM=mongoid
|
||||
gemfile: gemfiles/Gemfile.rails-3.1.x
|
||||
gemfile:
|
||||
- gemfiles/Gemfile.rails-3.1.x
|
||||
- Gemfile
|
||||
services:
|
||||
- mongodb
|
||||
notifications:
|
||||
email: false
|
||||
campfire:
|
||||
on_success: change
|
||||
on_failure: always
|
||||
rooms:
|
||||
- secure: "TRiqvuM4i/QmRDWjUSNitE5/P91BOzDkNl53+bZjjtxcISCswZtmECWBR7n9\n3xwqCOU1o2lfohxZ32OHOj/Nj7o+90zWJfWxcv+if0hIXRiil62M5pg0lZUd\nyJ4M5VQ0lSWo5he1OUrXhSabPJeaK3B8yT/tdh+qO5yzR+vb/jc="
|
||||
600
CHANGELOG.rdoc
600
CHANGELOG.rdoc
@@ -1,19 +1,567 @@
|
||||
== 1.1.pre
|
||||
== 2.2.3
|
||||
|
||||
* bug fix
|
||||
* Require string conversion for all values
|
||||
|
||||
== 2.2.2
|
||||
|
||||
* bug fix
|
||||
* Fix bug when checking for reconfirmable in templates
|
||||
|
||||
== 2.2.1
|
||||
|
||||
* bug fix
|
||||
* Fix regression with case_insensitive_keys
|
||||
* Fix regression when password is blank when it is invalid
|
||||
|
||||
== 2.2.0
|
||||
|
||||
* backwards incompatible changes
|
||||
* `headers_for` is deprecated, customize the mailer directly instead
|
||||
* All mailer methods now expect a second argument with delivery options
|
||||
* Default minimum password length is now 8 (by @carlosgaldino)
|
||||
* Support alternate sign in error message when email record does not exist (this adds a new I18n key to the locale file) (by @gabetax)
|
||||
* DeviseController responds only to HTML requests by default (call `DeviseController.respond_to` or `ApplicationController.respond_to` to add new formats)
|
||||
* Support Mongoid 3 onwards (by @durran)
|
||||
|
||||
* enhancements
|
||||
* Rails 3 compatibility.
|
||||
* All controllers and views are namespaced, for example: Devise::SessionsController and "devise/sessions".
|
||||
* You can specify the controller in routes and have specific controllers for each role.
|
||||
* Devise.orm is deprecated. This reduces the required API to hook your ORM with devise.
|
||||
* Use metal for failure app.
|
||||
* HTML e-mails now have proper formatting.
|
||||
* Do not remove options from Datamapper and MongoMapper in find
|
||||
* Fix unlockable which could leak account existence on paranoid mode (by @latortuga)
|
||||
* Confirmable now has a confirm_within option to set a period while the confirmation token is still valid (by @promisedlandt)
|
||||
* Flash messages in controller now respects `resource_name` (by @latortuga)
|
||||
* Separate `sign_in` and `sign_up` on RegistrationsController (by @rubynortheast)
|
||||
* Add autofocus to default views (by @Radagaisus)
|
||||
* Unlock user on password reset (by @marcinb)
|
||||
* Allow validation callbacks to apply to virtual attributes (by @latortuga)
|
||||
|
||||
* bug fix
|
||||
* unconfirmed_email now uses the proper e-mail on salutation
|
||||
* Fix default email_regexp config to not allow spaces (by @kukula)
|
||||
* Fix a regression introduced on warden 1.2.1 (by @ejfinneran)
|
||||
* Properly camelize omniauth strategies (by @saizai)
|
||||
* Do not set flash messages for non navigational requests on session sign out (by @mathieul)
|
||||
* Set the proper fields as required on the lockable module (by @nickhoffman)
|
||||
* Respects Devise mailer default's reply_to (by @mrchrisadams)
|
||||
* Properly assign resource on `sign_in` related action (by @adammcnamara)
|
||||
* `update_with_password` doesn't change encrypted password when it is invalid (by @nashby)
|
||||
* Properly handle namespaced models on Active Record generator (by @nashby)
|
||||
|
||||
== 2.1.2
|
||||
|
||||
* enhancements
|
||||
* Handle backwards incompatibility between Rails 3.2.6 and Thor 0.15.x
|
||||
|
||||
* bug fix
|
||||
* Fix regression on strategy validation on previous release
|
||||
|
||||
== 2.1.1 (yanked)
|
||||
|
||||
* enhancements
|
||||
* `sign_out_all_scopes` now locks warden and does not allow new logins in the same action
|
||||
* `Devise.omniauth_path_prefix` is available to configure omniauth path prefix
|
||||
* Redirect to sign in page when trying to access password#edit without a token (by @gbataille)
|
||||
* Allow a lambda in authenticate(d) routes helpers to further select the scope
|
||||
* Removed warnings on Rails 3.2.6 (by @nashby)
|
||||
|
||||
* bug fix
|
||||
* `update_with_password` now relies on assign_attributes and forwards the :as option (by @wtn)
|
||||
* Do not trigger timeout on sign in related actions
|
||||
* Timeout does not explode when reset_authentication_token! is accidentally defined by Active Model (by @remomueller)
|
||||
|
||||
* deprecations
|
||||
* Rails 3 compatible only.
|
||||
* Scoped views are no longer "sessions/users/new". Now use "users/sessions/new".
|
||||
* Devise.orm is deprecated, just require "devise/orm/YOUR_ORM" instead.
|
||||
* Devise.default_url_options is deprecated, just modify ApplicationController.default_url_options.
|
||||
* Strategy#validate() no longer validates nil resources
|
||||
|
||||
== 2.1.0
|
||||
|
||||
* enhancements
|
||||
* Add `check_fields!(model_class)` method on Devise::Models to check if the model includes the fields that Devise uses
|
||||
* Add `skip_reconfirmation!` to skip reconfirmation
|
||||
* Devise model generator now works with engines
|
||||
* Devise encryptable was moved to its new gem (http://github.com/plataformatec/devise-encryptable)
|
||||
|
||||
* deprecations
|
||||
* Deprecations warnings added on Devise 2.0 are now removed with their features
|
||||
* All devise modules should now have a `required_fields(klass)` module method to help gathering missing attributes
|
||||
* `use_salt_as_remember_token` and `apply_schema` does not have any effect since 2.0 and are now deprecated
|
||||
* `valid_for_authentication?` must now return a boolean
|
||||
|
||||
* bug fix
|
||||
* Ensure after sign in hook is not called without a resource
|
||||
* Fix a term: now on Omniauth related flash messages, we say that we're authenticating from an omniauth provider instead of authorizing
|
||||
* Fixed redirect when authenticated mounted apps (by @hakanensari)
|
||||
* Ensure the failure app still respects config.relative_url_root
|
||||
* `/users/sign_in` doesn't choke on protected attributes used to select sign in scope (by @Paymium)
|
||||
* `failed_attempts` is set to zero after any sign in (including via reset password) (by @rodrigoflores)
|
||||
* Added token expiration on timeout (by @antiarchitect)
|
||||
* Do not accidentally mark `_prefixes` as private
|
||||
* Better support for custom strategies on test helpers (by @mattconnolly)
|
||||
* Return `head :no_content` in SessionsController now that most JS libraries handle it (by @julianvargasalvarez)
|
||||
|
||||
== 2.0.4
|
||||
|
||||
Notes: https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0
|
||||
|
||||
* bug fix
|
||||
* Fix when :host is used with devise_for (by @mreinsch)
|
||||
* Fix a regression that caused Warden to be initialized too late
|
||||
|
||||
== 2.0.3 (yanked)
|
||||
|
||||
* bug fix
|
||||
* Ensure warning is not shown by mistake on apps with mounted engines
|
||||
* Fixes related to remember_token and rememberable_options
|
||||
* Ensure serializable_hash does not depend on accessible attributes
|
||||
* Ensure that timeout callback does not run on sign out action
|
||||
|
||||
== 2.0.2
|
||||
|
||||
* enhancements
|
||||
* Add devise_i18n_options to customize I18n message
|
||||
|
||||
* bug fix
|
||||
* Ensure Devise.available_router_name defaults to :main_app
|
||||
* Set autocomplete to off for password on edit forms
|
||||
* Better error messages in case a trackable model can't be saved
|
||||
* Show a warning in case someone gives a pluralized name to devise generator
|
||||
* Fix test behavior for rspec subject requests (by @sj26)
|
||||
|
||||
== 2.0.1
|
||||
|
||||
* 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_*
|
||||
* Protected method render_with_scope was removed.
|
||||
|
||||
== 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 (yanked)
|
||||
|
||||
* 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
|
||||
* Properly ignore path prefix on omniauthable
|
||||
* Faster uniqueness queries
|
||||
* Rename active? to active_for_authentication? to avoid conflicts
|
||||
|
||||
== 1.2.rc2
|
||||
|
||||
* enhancements
|
||||
* Make friendly_token 20 chars long
|
||||
* Use secure_compare
|
||||
|
||||
* bug fix
|
||||
* Fix an issue causing infinite redirects in production
|
||||
* 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 @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 @jaghion)
|
||||
* Do not depend on ActiveModel::Dirty
|
||||
* Manual sign_in now triggers remember token
|
||||
* Be sure to halt strategies on failures
|
||||
* Consider SCRIPT_NAME on Omniauth paths
|
||||
* Reset failed attempts when lock is expired
|
||||
* Ensure there is no Mongoid injection
|
||||
|
||||
* deprecations
|
||||
* 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
|
||||
|
||||
== 1.2.rc
|
||||
|
||||
* deprecations
|
||||
* cookie_domain is deprecated in favor of cookie_options
|
||||
* after_update_path_for can no longer be defined in ApplicationController
|
||||
|
||||
* 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 @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 @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
|
||||
* Allow :stateless_token to be set to true avoiding users to be stored in session through token authentication
|
||||
* cookie_options uses session_options values by default
|
||||
* 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 @adahl)
|
||||
|
||||
* default behavior changes
|
||||
* sign_out_all_scopes defaults to true as security measure
|
||||
* http authenticatable is disabled by default
|
||||
* Devise does not intercept 401 returned from applications
|
||||
|
||||
* bugfix
|
||||
* after_sign_in_path_for always receives a resource
|
||||
* 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 @sxross)
|
||||
|
||||
== 1.1.6
|
||||
|
||||
* Use a more secure e-mail regexp
|
||||
* Implement Rails 3.0.4 handle unverified request
|
||||
* Use secure_compare to compare passwords
|
||||
|
||||
== 1.1.5
|
||||
|
||||
* bugfix
|
||||
* Ensure to convert keys on indifferent hash
|
||||
|
||||
* defaults
|
||||
* Set config.http_authenticatable to false to avoid confusion
|
||||
|
||||
== 1.1.4
|
||||
|
||||
* bugfix
|
||||
* Avoid session fixation attacks
|
||||
|
||||
== 1.1.3
|
||||
|
||||
* bugfix
|
||||
* Add reply-to to e-mail headers by default
|
||||
* 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 @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
|
||||
|
||||
* bugfix
|
||||
* Compatibility with latest Rails routes schema
|
||||
|
||||
== 1.1.1
|
||||
|
||||
* bugfix
|
||||
* Fix a small bug where generated locale file was empty on devise:install
|
||||
|
||||
== 1.1.0
|
||||
|
||||
* enhancements
|
||||
* 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 @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 @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
|
||||
|
||||
* deprecations
|
||||
* use_default_scope is deprecated and has no effect. Use :as or :devise_scope in the router instead
|
||||
|
||||
== 1.1.rc2
|
||||
|
||||
* enhancements
|
||||
* 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 @wildchild)
|
||||
* Added after_update_path_for to registrations controller (by @thedelchop)
|
||||
* Allow the mailer object to be replaced through config.mailer = "MyOwnMailer"
|
||||
|
||||
* bug fix
|
||||
* Fix a bug where session was timing out on sign out
|
||||
|
||||
* deprecations
|
||||
* bcrypt is now the default encryptor
|
||||
* devise.mailer.confirmations_instructions now should be devise.mailer.confirmations_instructions.subject
|
||||
* devise.mailer.user.confirmations_instructions now should be devise.mailer.confirmations_instructions.user_subject
|
||||
* Generators now use Rails 3 syntax (devise:install) instead of devise_install
|
||||
|
||||
== 1.1.rc1
|
||||
|
||||
* enhancements
|
||||
* Rails 3 compatibility
|
||||
* All controllers and views are namespaced, for example: Devise::SessionsController and "devise/sessions"
|
||||
* Devise.orm is deprecated. This reduces the required API to hook your ORM with devise
|
||||
* Use metal for failure app
|
||||
* HTML e-mails now have proper formatting
|
||||
* Allow to give :skip and :controllers in routes
|
||||
* Move trackable logic to the model
|
||||
* E-mails now use any template available in the filesystem. Easy to create multipart e-mails
|
||||
* E-mails asks headers_for in the model to set the proper headers
|
||||
* Allow to specify haml in devise_views
|
||||
* Compatibility with Mongoid
|
||||
* Make config.devise available on config/application.rb
|
||||
* TokenAuthenticatable now works with HTTP Basic Auth
|
||||
* Allow :unlock_strategy to be :none and add :lock_strategy which can be :failed_attempts or none. Setting those values to :none means that you want to handle lock and unlocking by yourself
|
||||
* No need to append ?unauthenticated=true in URLs anymore since Flash was moved to a middleware in Rails 3
|
||||
* :activatable is included by default in your models
|
||||
|
||||
* bug fix
|
||||
* Fix a bug with STI
|
||||
|
||||
* deprecations
|
||||
* Rails 3 compatible only
|
||||
* Removed support for MongoMapper
|
||||
* Scoped views are no longer "sessions/users/new". Now use "users/sessions/new"
|
||||
* Devise.orm is deprecated, just require "devise/orm/YOUR_ORM" instead
|
||||
* Devise.default_url_options is deprecated, just modify ApplicationController.default_url_options
|
||||
* All messages under devise.sessions, except :signed_in and :signed_out, should be moved to devise.failure
|
||||
* :as and :scope in routes is deprecated. Use :path and :singular instead
|
||||
|
||||
== 1.0.8
|
||||
|
||||
* enhancements
|
||||
* Support for latest MongoMapper
|
||||
* Added anybody_signed_in? helper (by @SSDany)
|
||||
|
||||
* bug fix
|
||||
* confirmation_required? is properly honored on active? calls. (by @paulrosania)
|
||||
|
||||
== 1.0.7
|
||||
|
||||
* bug fix
|
||||
* Ensure password confirmation is always required
|
||||
|
||||
* deprecations
|
||||
* authenticatable was deprecated and renamed to database_authenticatable
|
||||
* confirmable is not included by default on generation
|
||||
|
||||
== 1.0.6
|
||||
|
||||
* bug fix
|
||||
* Do not allow unlockable strategies based on time to access a controller.
|
||||
* Do not send unlockable email several times.
|
||||
* Allow controller to upstram custom! failures to Warden.
|
||||
|
||||
== 1.0.5
|
||||
|
||||
* bug fix
|
||||
* Use prepend_before_filter in require_no_authentication.
|
||||
* require_no_authentication on unlockable.
|
||||
* Fix a bug when giving an association proxy to devise.
|
||||
* Do not use lock! on lockable since it's part of ActiveRecord API.
|
||||
|
||||
== 1.0.4
|
||||
|
||||
* bug fix
|
||||
* Fixed a bug when deleting an account with rememberable
|
||||
* Fixed a bug with custom controllers
|
||||
|
||||
== 1.0.3
|
||||
|
||||
@@ -24,7 +572,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
|
||||
@@ -57,12 +605,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
|
||||
@@ -72,11 +620,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
|
||||
@@ -85,10 +633,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
|
||||
|
||||
@@ -105,11 +653,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
|
||||
@@ -149,7 +697,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
|
||||
|
||||
@@ -243,9 +791,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
|
||||
|
||||
|
||||
14
CONTRIBUTING.md
Normal file
14
CONTRIBUTING.md
Normal file
@@ -0,0 +1,14 @@
|
||||
### Please read before contributing
|
||||
|
||||
1) Do not post questions in the issues tracker. If you have any questions about Devise, search the [Wiki](https://github.com/plataformatec/devise/wiki) or use the [Mailing List](https://groups.google.com/group/plataformatec-devise) or [Stack Overflow](http://stackoverflow.com/questions/tagged/devise).
|
||||
|
||||
2) If you find a security bug, **DO NOT** submit an issue here. Please send an e-mail to [developers@plataformatec.com.br](mailto:developers@plataformatec.com.br) instead.
|
||||
|
||||
3) Do a small search on the issues tracker before submitting your issue to see if it was already reported / fixed.
|
||||
|
||||
4) When reporting an issue, include Rails, Devise and Warden versions. If you are getting exceptions, please include the full backtrace.
|
||||
|
||||
That's it! The more information you give, the easier it becomes for us to track it down and fix it.
|
||||
Ideally, you should provide an application that reproduces the error or a test case to Devise's suite.
|
||||
|
||||
Thanks!
|
||||
40
Gemfile
40
Gemfile
@@ -1,18 +1,32 @@
|
||||
source "http://gemcutter.org"
|
||||
source "http://rubygems.org"
|
||||
|
||||
gem "rails", "3.0.0.beta"
|
||||
gem "warden", "0.9.4"
|
||||
gem "sqlite3-ruby", :require => "sqlite3"
|
||||
gem "webrat", "0.7"
|
||||
gem "mocha", :require => false
|
||||
gem "bcrypt-ruby", :require => "bcrypt"
|
||||
gemspec
|
||||
|
||||
if RUBY_VERSION < '1.9'
|
||||
gem "ruby-debug", ">= 0.10.3"
|
||||
gem "rails", "~> 3.2.6"
|
||||
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", "0.10.0", :require => false
|
||||
end
|
||||
|
||||
group :mongo_mapper do
|
||||
gem "mongo", "0.18.3"
|
||||
gem "mongo_ext", "0.18.3", :require => false
|
||||
gem "mongo_mapper", :git => "git://github.com/merbjedi/mongomapper.git", :branch => "rails3"
|
||||
platforms :jruby do
|
||||
gem "activerecord-jdbc-adapter"
|
||||
gem "activerecord-jdbcsqlite3-adapter"
|
||||
gem "jruby-openssl"
|
||||
end
|
||||
|
||||
platforms :ruby do
|
||||
gem "sqlite3"
|
||||
end
|
||||
|
||||
|
||||
platforms :mri_19 do
|
||||
group :mongoid do
|
||||
gem "mongoid", "~> 3.0"
|
||||
end
|
||||
end
|
||||
156
Gemfile.lock
Normal file
156
Gemfile.lock
Normal file
@@ -0,0 +1,156 @@
|
||||
PATH
|
||||
remote: .
|
||||
specs:
|
||||
devise (2.2.2)
|
||||
bcrypt-ruby (~> 3.0)
|
||||
orm_adapter (~> 0.1)
|
||||
railties (~> 3.1)
|
||||
warden (~> 1.2.1)
|
||||
|
||||
GEM
|
||||
remote: http://rubygems.org/
|
||||
specs:
|
||||
actionmailer (3.2.11)
|
||||
actionpack (= 3.2.11)
|
||||
mail (~> 2.4.4)
|
||||
actionpack (3.2.11)
|
||||
activemodel (= 3.2.11)
|
||||
activesupport (= 3.2.11)
|
||||
builder (~> 3.0.0)
|
||||
erubis (~> 2.7.0)
|
||||
journey (~> 1.0.4)
|
||||
rack (~> 1.4.0)
|
||||
rack-cache (~> 1.2)
|
||||
rack-test (~> 0.6.1)
|
||||
sprockets (~> 2.2.1)
|
||||
activemodel (3.2.11)
|
||||
activesupport (= 3.2.11)
|
||||
builder (~> 3.0.0)
|
||||
activerecord (3.2.11)
|
||||
activemodel (= 3.2.11)
|
||||
activesupport (= 3.2.11)
|
||||
arel (~> 3.0.2)
|
||||
tzinfo (~> 0.3.29)
|
||||
activeresource (3.2.11)
|
||||
activemodel (= 3.2.11)
|
||||
activesupport (= 3.2.11)
|
||||
activesupport (3.2.11)
|
||||
i18n (~> 0.6)
|
||||
multi_json (~> 1.0)
|
||||
arel (3.0.2)
|
||||
bcrypt-ruby (3.0.1)
|
||||
builder (3.0.4)
|
||||
erubis (2.7.0)
|
||||
faraday (0.8.4)
|
||||
multipart-post (~> 1.1)
|
||||
hashie (1.2.0)
|
||||
hike (1.2.1)
|
||||
httpauth (0.2.0)
|
||||
i18n (0.6.1)
|
||||
journey (1.0.4)
|
||||
json (1.7.6)
|
||||
jwt (0.1.5)
|
||||
multi_json (>= 1.0)
|
||||
mail (2.4.4)
|
||||
i18n (>= 0.4.0)
|
||||
mime-types (~> 1.16)
|
||||
treetop (~> 1.4.8)
|
||||
metaclass (0.0.1)
|
||||
mime-types (1.19)
|
||||
mocha (0.10.0)
|
||||
metaclass (~> 0.0.1)
|
||||
mongoid (3.0.16)
|
||||
activemodel (~> 3.1)
|
||||
moped (~> 1.1)
|
||||
origin (~> 1.0)
|
||||
tzinfo (~> 0.3.22)
|
||||
moped (1.3.2)
|
||||
multi_json (1.5.0)
|
||||
multipart-post (1.1.5)
|
||||
nokogiri (1.5.5)
|
||||
oauth2 (0.8.0)
|
||||
faraday (~> 0.8)
|
||||
httpauth (~> 0.1)
|
||||
jwt (~> 0.1.4)
|
||||
multi_json (~> 1.0)
|
||||
rack (~> 1.2)
|
||||
omniauth (1.0.3)
|
||||
hashie (~> 1.2)
|
||||
rack
|
||||
omniauth-facebook (1.4.0)
|
||||
omniauth-oauth2 (~> 1.0.2)
|
||||
omniauth-oauth2 (1.0.3)
|
||||
oauth2 (~> 0.8.0)
|
||||
omniauth (~> 1.0)
|
||||
omniauth-openid (1.0.1)
|
||||
omniauth (~> 1.0)
|
||||
rack-openid (~> 1.3.1)
|
||||
origin (1.0.11)
|
||||
orm_adapter (0.4.0)
|
||||
polyglot (0.3.3)
|
||||
rack (1.4.3)
|
||||
rack-cache (1.2)
|
||||
rack (>= 0.4)
|
||||
rack-openid (1.3.1)
|
||||
rack (>= 1.1.0)
|
||||
ruby-openid (>= 2.1.8)
|
||||
rack-ssl (1.3.2)
|
||||
rack
|
||||
rack-test (0.6.2)
|
||||
rack (>= 1.0)
|
||||
rails (3.2.11)
|
||||
actionmailer (= 3.2.11)
|
||||
actionpack (= 3.2.11)
|
||||
activerecord (= 3.2.11)
|
||||
activeresource (= 3.2.11)
|
||||
activesupport (= 3.2.11)
|
||||
bundler (~> 1.0)
|
||||
railties (= 3.2.11)
|
||||
railties (3.2.11)
|
||||
actionpack (= 3.2.11)
|
||||
activesupport (= 3.2.11)
|
||||
rack-ssl (~> 1.3.2)
|
||||
rake (>= 0.8.7)
|
||||
rdoc (~> 3.4)
|
||||
thor (>= 0.14.6, < 2.0)
|
||||
rake (10.0.3)
|
||||
rdoc (3.12)
|
||||
json (~> 1.4)
|
||||
ruby-openid (2.2.2)
|
||||
sprockets (2.2.2)
|
||||
hike (~> 1.2)
|
||||
multi_json (~> 1.0)
|
||||
rack (~> 1.0)
|
||||
tilt (~> 1.1, != 1.3.0)
|
||||
sqlite3 (1.3.6)
|
||||
thor (0.16.0)
|
||||
tilt (1.3.3)
|
||||
treetop (1.4.12)
|
||||
polyglot
|
||||
polyglot (>= 0.3.1)
|
||||
tzinfo (0.3.35)
|
||||
warden (1.2.1)
|
||||
rack (>= 1.0)
|
||||
webrat (0.7.2)
|
||||
nokogiri (>= 1.2.0)
|
||||
rack (>= 1.0)
|
||||
rack-test (>= 0.5.3)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
activerecord-jdbc-adapter
|
||||
activerecord-jdbcsqlite3-adapter
|
||||
devise!
|
||||
jruby-openssl
|
||||
mocha (= 0.10.0)
|
||||
mongoid (~> 3.0)
|
||||
omniauth (~> 1.0.0)
|
||||
omniauth-facebook
|
||||
omniauth-oauth2 (~> 1.0.0)
|
||||
omniauth-openid (~> 1.0.1)
|
||||
rails (~> 3.2.6)
|
||||
rdoc
|
||||
sqlite3
|
||||
webrat (= 0.7.2)
|
||||
@@ -1,4 +1,4 @@
|
||||
Copyright 2009 Plataforma Tecnologia. http://blog.plataformatec.com.br
|
||||
Copyright 2009-2013 Plataformatec. http://plataformatec.com.br
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
|
||||
396
README.md
Normal file
396
README.md
Normal file
@@ -0,0 +1,396 @@
|
||||
## Devise
|
||||
|
||||
[](http://travis-ci.org/plataformatec/devise)
|
||||
[](https://codeclimate.com/github/plataformatec/devise)
|
||||
[](http://badge.fury.io/rb/devise)
|
||||
|
||||
This README is [also available in a friendly navigable format](http://devise.plataformatec.com.br/).
|
||||
|
||||
Devise is a flexible authentication solution for Rails based on Warden. It:
|
||||
|
||||
* Is Rack based;
|
||||
* Is a complete MVC solution based on Rails engines;
|
||||
* 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:
|
||||
|
||||
* [Database Authenticatable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/DatabaseAuthenticatable): encrypts and stores a password in the database to validate the authenticity of a user while signing in. The authentication can be done both through POST requests or HTTP Basic Authentication.
|
||||
* [Token Authenticatable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/TokenAuthenticatable): signs in a user based on an authentication token (also known as "single access token"). The token can be given both through query string or HTTP Basic Authentication.
|
||||
* [Omniauthable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Omniauthable): adds Omniauth (https://github.com/intridea/omniauth) support;
|
||||
* [Confirmable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Confirmable): sends emails with confirmation instructions and verifies whether an account is already confirmed during sign in.
|
||||
* [Recoverable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Recoverable): resets the user password and sends reset instructions.
|
||||
* [Registerable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Registerable): handles signing up users through a registration process, also allowing them to edit and destroy their account.
|
||||
* [Rememberable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Rememberable): manages generating and clearing a token for remembering the user from a saved cookie.
|
||||
* [Trackable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Trackable): tracks sign in count, timestamps and IP address.
|
||||
* [Timeoutable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Timeoutable): expires sessions that have no activity in a specified period of time.
|
||||
* [Validatable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Validatable): provides validations of email and password. It's optional and can be customized, so you're able to define your own validations.
|
||||
* [Lockable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Lockable): locks an account after a specified number of failed sign-in attempts. Can unlock via email or after a specified time period.
|
||||
|
||||
## Information
|
||||
|
||||
### 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:
|
||||
|
||||
https://wiki.github.com/plataformatec/devise
|
||||
|
||||
### Bug reports
|
||||
|
||||
If you discover a problem with Devise, we would like to know about it. However, we ask that you please review these guidelines before submitting a bug report:
|
||||
|
||||
https://github.com/plataformatec/devise/wiki/Bug-reports
|
||||
|
||||
If you found a security bug, do *NOT* use the GitHub issue tracker. Send an email to the maintainers listed at the bottom of the README.
|
||||
|
||||
### Mailing list
|
||||
|
||||
If you have any questions, comments, or concerns, please use the Google Group instead of the GitHub issue tracker:
|
||||
|
||||
https://groups.google.com/group/plataformatec-devise
|
||||
|
||||
### 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.
|
||||
|
||||
### 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:
|
||||
|
||||
https://github.com/plataformatec/devise/wiki/Example-Applications
|
||||
|
||||
### Extensions
|
||||
|
||||
Our community has created a number of extensions that add functionality above and beyond what is included with Devise. You can view a list of available extensions and add your own here:
|
||||
|
||||
https://github.com/plataformatec/devise/wiki/Extensions
|
||||
|
||||
### Contributing
|
||||
|
||||
We hope that you will consider contributing to Devise. Please read this short overview for some information about how to get started:
|
||||
|
||||
https://github.com/plataformatec/devise/wiki/Contributing
|
||||
|
||||
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.
|
||||
|
||||
## 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 your understanding of Rails and authentication mechanisms, we assure you Devise will be very pleasant to work with. :)
|
||||
|
||||
## Getting started
|
||||
|
||||
Devise 2.0 works with Rails 3.1 onwards. You can add it to your Gemfile with:
|
||||
|
||||
```ruby
|
||||
gem 'devise'
|
||||
```
|
||||
|
||||
Run the bundle command to install it.
|
||||
|
||||
After you install Devise and add it to your Gemfile, you need to run the generator:
|
||||
|
||||
```console
|
||||
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:
|
||||
|
||||
```console
|
||||
rails generate devise MODEL
|
||||
```
|
||||
|
||||
Replace MODEL by the class name used for the applications users, it's frequently 'User' but could also be 'Admin'. This will create a model (if one does not exist) and configure it with default Devise modules. Next, you'll usually run "rake db:migrate" as the generator will have created a migration file (if your ORM supports them). This generator also configures your config/routes.rb file to point to the Devise controller.
|
||||
|
||||
Note that you should re-start your app here if you've already started it. Otherwise you'll run into strange errors like users being unable to login and the route helpers being undefined.
|
||||
|
||||
### 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:
|
||||
|
||||
```ruby
|
||||
before_filter :authenticate_user!
|
||||
```
|
||||
|
||||
To verify if a user is signed in, use the following helper:
|
||||
|
||||
```ruby
|
||||
user_signed_in?
|
||||
```
|
||||
|
||||
For the current signed-in user, this helper is available:
|
||||
|
||||
```ruby
|
||||
current_user
|
||||
```
|
||||
|
||||
You can access the session for this scope:
|
||||
|
||||
```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:
|
||||
|
||||
```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.
|
||||
|
||||
Finally, you need to set up default url options for the mailer in each environment. Here is the configuration for "config/environments/development.rb":
|
||||
|
||||
```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:
|
||||
|
||||
```ruby
|
||||
before_filter :authenticate_member!
|
||||
|
||||
member_signed_in?
|
||||
|
||||
current_member
|
||||
|
||||
member_session
|
||||
```
|
||||
|
||||
### Configuring Models
|
||||
|
||||
The devise method in your models also accepts some options to configure its modules. For example, you can choose the cost of the encryption algorithm with:
|
||||
|
||||
```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
|
||||
|
||||
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:
|
||||
|
||||
```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, :timeoutable
|
||||
|
||||
# Inside your routes
|
||||
devise_for :admins
|
||||
|
||||
# Inside your protected controller
|
||||
before_filter :authenticate_admin!
|
||||
|
||||
# Inside your controllers and views
|
||||
admin_signed_in?
|
||||
current_admin
|
||||
admin_session
|
||||
```
|
||||
|
||||
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 some time you may want to change them. If this is the case, you just need to invoke the following generator, and it will copy all views to your application:
|
||||
|
||||
```console
|
||||
rails generate devise:views
|
||||
```
|
||||
|
||||
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:
|
||||
|
||||
```console
|
||||
rails generate devise:views users
|
||||
```
|
||||
|
||||
### 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:
|
||||
|
||||
```ruby
|
||||
class Admins::SessionsController < Devise::SessionsController
|
||||
end
|
||||
```
|
||||
|
||||
2) Tell the router to use this controller:
|
||||
|
||||
```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. Do not print the entire flash hash, print specific keys or at least remove the `:timedout` key from the hash as Devise adds this key in some circumstances, this key is not meant for display.
|
||||
|
||||
### Configuring routes
|
||||
|
||||
Devise also ships with default routes. If you need to customize them, you should probably be able to do it through the devise_for method. It accepts several options like :class_name, :path_prefix and so on, including the possibility to change path names for I18n:
|
||||
|
||||
```ruby
|
||||
devise_for :users, :path => "auth", :path_names => { :sign_in => 'login', :sign_out => 'logout', :password => 'secret', :confirmation => 'verification', :unlock => 'unblock', :registration => 'register', :sign_up => 'cmon_let_me_in' }
|
||||
```
|
||||
|
||||
Be sure to check `devise_for` documentation for details.
|
||||
|
||||
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:
|
||||
|
||||
```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` in your router.
|
||||
|
||||
### I18n
|
||||
|
||||
Devise uses flash messages with I18n with the flash keys :notice and :alert. To customize your app, you can set up your locale file:
|
||||
|
||||
```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:
|
||||
|
||||
```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:
|
||||
|
||||
```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:
|
||||
|
||||
https://github.com/plataformatec/devise/wiki/I18n
|
||||
|
||||
### Test helpers
|
||||
|
||||
Devise includes some tests helpers for functional specs. In order to use them, you need to include Devise in your functional tests by adding the following to the bottom of your `test/test_helper.rb` file:
|
||||
|
||||
```ruby
|
||||
class ActionController::TestCase
|
||||
include Devise::TestHelpers
|
||||
end
|
||||
```
|
||||
|
||||
If you're using RSpec, you can put the following inside a file named `spec/support/devise.rb`:
|
||||
|
||||
```ruby
|
||||
RSpec.configure do |config|
|
||||
config.include Devise::TestHelpers, :type => :controller
|
||||
end
|
||||
```
|
||||
|
||||
Now you are ready to use the `sign_in` and `sign_out` methods. Such methods have the same signature as in controllers:
|
||||
|
||||
```ruby
|
||||
sign_in :user, @user # sign_in(scope, resource)
|
||||
sign_in @user # sign_in(resource)
|
||||
|
||||
sign_out :user # sign_out(scope)
|
||||
sign_out @user # sign_out(resource)
|
||||
```
|
||||
|
||||
There are two things that is important to keep in mind:
|
||||
|
||||
1) These helpers are not going to work for integration tests driven by Capybara or Webrat. They are meant to be used with functional tests only. Instead, fill in the form or explicitly set the user in session;
|
||||
|
||||
2) If you are testing Devise internal controllers or a controller that inherits from Devise's, you need to tell Devise which mapping should be used before a request. This is necessary because Devise gets this information from router, but since functional tests do not pass through the router, it needs to be told explicitly. For example, if you are testing the user scope, simply do:
|
||||
|
||||
@request.env["devise.mapping"] = Devise.mappings[:user]
|
||||
get :new
|
||||
|
||||
### Omniauth
|
||||
|
||||
Devise comes with Omniauth support out of the box to authenticate with other providers. To use it, just specify your omniauth configuration in `config/initializers/devise.rb`:
|
||||
|
||||
```ruby
|
||||
config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo'
|
||||
```
|
||||
|
||||
You can read more about Omniauth support in the wiki:
|
||||
|
||||
* https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview
|
||||
|
||||
### 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
|
||||
|
||||
Devise implements encryption strategies for Clearance, Authlogic and Restful-Authentication. To make use of these strategies, you need set the desired encryptor in the encryptor initializer config option and add :encryptable to your model. You might also need to rename your encrypted password and salt columns to match Devise's fields (encrypted_password and password_salt).
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Heroku
|
||||
|
||||
Using devise on Heroku with Ruby on Rails 3.1 requires setting:
|
||||
|
||||
```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:
|
||||
|
||||
https://github.com/hassox/warden
|
||||
|
||||
### Contributors
|
||||
|
||||
We have a long list of valued contributors. Check them all at:
|
||||
|
||||
https://github.com/plataformatec/devise/contributors
|
||||
|
||||
### Maintainers
|
||||
|
||||
* José Valim (https://github.com/josevalim)
|
||||
* Carlos Antônio da Silva (https://github.com/carlosantoniodasilva)
|
||||
* Rodrigo Flores (https://github.com/rodrigoflores)
|
||||
|
||||
## License
|
||||
|
||||
MIT License. Copyright 2009-2013 Plataformatec. http://plataformatec.com.br
|
||||
278
README.rdoc
278
README.rdoc
@@ -1,278 +0,0 @@
|
||||
== Devise
|
||||
|
||||
Devise is a flexible authentication solution for Rails based on Warden. It:
|
||||
|
||||
* Is Rack based;
|
||||
* Is a complete MVC solution based on Rails engines;
|
||||
* 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.
|
||||
|
||||
Right now it's composed of 12 modules:
|
||||
|
||||
* Authenticatable: responsible for encrypting password and validating authenticity of a user while signing in.
|
||||
* Token Authenticatable: validates authenticity of a user while signing in using an authentication token (also known as "single access token").
|
||||
* HttpAuthenticatable: sign in users using basic HTTP authentication.
|
||||
* Confirmable: responsible for verifying whether an account is already confirmed to sign in, and to send emails with confirmation instructions.
|
||||
* Recoverable: takes care of reseting the user password and send reset instructions.
|
||||
* Registerable: handles signing up users through a registration process.
|
||||
* Rememberable: manages generating and clearing token for remember the user from a saved cookie.
|
||||
* Trackable: tracks sign in count, timestamps and ip.
|
||||
* Timeoutable: expires sessions without activity in a certain period of time.
|
||||
* Validatable: creates all needed validations for email and password. It's totally optional, so you're able to to customize validations by yourself.
|
||||
* Lockable: takes care of locking an account based on the number of failed sign in attempts. Handles unlock via expire and email.
|
||||
* Activatable: if you need to activate accounts by other means, which are not through confirmation, use this module.
|
||||
|
||||
There's an example application using Devise at http://github.com/plataformatec/devise_example .
|
||||
|
||||
== Dependencies
|
||||
|
||||
Devise is based on Warden (http://github.com/hassox/warden), a Rack Authentication Framework so you need to install it as a gem. Please ensure you have it installed in order to use devise (see installation below).
|
||||
|
||||
== Installation
|
||||
|
||||
Devise master branch now supports Rails 3 and is NOT backward compatible. You can install it as:
|
||||
|
||||
sudo gem install devise --version=1.1.pre
|
||||
|
||||
After installing them, you need configure warden and devise gems inside your gemfile:
|
||||
|
||||
gem 'warden'
|
||||
gem 'devise'
|
||||
|
||||
And run the generator:
|
||||
|
||||
rails generate devise_install
|
||||
|
||||
And you're ready to go. The generator will install an initializer which describes ALL Devise's configuration options, so be sure to take a look at it and at the documentation as well:
|
||||
|
||||
http://rdoc.info/projects/plataformatec/devise
|
||||
|
||||
== Rails 2.3
|
||||
|
||||
If you want to use the Rails 2.3.x version, you should do:
|
||||
|
||||
sudo gem install devise --version=1.0.1
|
||||
|
||||
Or checkout from the v1.0 branch:
|
||||
|
||||
http://github.com/plataformatec/devise/tree/v1.0
|
||||
|
||||
== Basic Usage
|
||||
|
||||
This is a walkthrough with all steps you need to setup a devise resource, including model, migration, route files, and optional configuration. You MUST also check out the *Generators* section below to help you start.
|
||||
|
||||
Devise must be set up within the model (or models) you want to use, and devise routes must be created inside your config/routes.rb file.
|
||||
|
||||
We're assuming here you want a User model with some modules, as outlined below:
|
||||
|
||||
class User < ActiveRecord::Base
|
||||
devise :authenticatable, :confirmable, :recoverable, :rememberable, :trackable, :validatable
|
||||
end
|
||||
|
||||
After you choose which modules to use, you need to setup your migrations. Luckily, devise has some helpers to save you from this boring work:
|
||||
|
||||
create_table :users do |t|
|
||||
t.authenticatable
|
||||
t.confirmable
|
||||
t.recoverable
|
||||
t.rememberable
|
||||
t.trackable
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
Remember that Devise don't rely on _attr_accessible_ or _attr_protected_ inside its modules, so be sure to setup what attributes are accessible or protected in your model.
|
||||
|
||||
The next setup after setting up your model is to configure your routes. You do this by opening up your config/routes.rb and adding:
|
||||
|
||||
devise_for :users
|
||||
|
||||
This is going to look inside you User model and create a set of needed routes (you can see them by running `rake routes`).
|
||||
|
||||
There are also some options available for configuring your routes, as :class_name (to set the class for that route), :path_prefix, :as and :path_names, where the last two have the same meaning as in common routes. The available :path_names are:
|
||||
|
||||
devise_for :users, :as => "usuarios", :path_names => { :sign_in => 'login', :sign_out => 'logout', :password => 'secret', :confirmation => 'verification', :unlock => 'unblock' }
|
||||
|
||||
Be sure to check devise_for documentation for detailed description.
|
||||
|
||||
After this steps, run your migrations, and you are ready to go! But don't finish reading, we still have a lot to tell you:
|
||||
|
||||
== Controller filters and helpers
|
||||
|
||||
Devise is gonna create some helpers to use inside your controllers and views. To setup a controller that needs user authentication, just add this before_filter:
|
||||
|
||||
before_filter :authenticate_user!
|
||||
|
||||
To verify if a user is signed in, you have the following helper:
|
||||
|
||||
user_signed_in?
|
||||
|
||||
And to get the current signed in user this helper is available:
|
||||
|
||||
current_user
|
||||
|
||||
You have also access to the session for this scope:
|
||||
|
||||
user_session
|
||||
|
||||
After signing in a user, confirming it's account or updating it's 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"
|
||||
|
||||
You can also overwrite after_sign_in_path_for and after_sign_out_path_for to customize better your redirect hooks.
|
||||
|
||||
Finally, you also need to setup default url options for the mailer in each environment. Here's is the configuration for config/environments/development.rb:
|
||||
|
||||
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
|
||||
|
||||
== Tidying up
|
||||
|
||||
Devise let's you setup as many roles as you want, so let's say you already have this User model and also want an Admin model with just authentication, trackable, lockable and timeoutable stuff and none of confirmation or password recovery. Just follow the same steps:
|
||||
|
||||
# Create a migration with the required fields
|
||||
create_table :admins do |t|
|
||||
t.authenticatable
|
||||
t.lockable
|
||||
t.trackable
|
||||
end
|
||||
|
||||
# Inside your Admin model
|
||||
devise :authenticatable, :trackable, :timeoutable, :lockable
|
||||
|
||||
# Inside your routes
|
||||
devise_for :admin
|
||||
|
||||
# Inside your protected controller
|
||||
before_filter :authenticate_admin!
|
||||
|
||||
# Inside your controllers and views
|
||||
admin_signed_in?
|
||||
current_admin
|
||||
admin_session
|
||||
|
||||
== Generators
|
||||
|
||||
Devise comes with some generators to help you start:
|
||||
|
||||
rails generate devise_install
|
||||
|
||||
This will generate an initializer, with a description of all configuration values. You can also generate models through:
|
||||
|
||||
rails generate devise Model
|
||||
|
||||
A model configured with all devise modules and attr_accessible for default fields will be created. The generator will also create the migration and configure your routes for devise.
|
||||
|
||||
== Model configuration
|
||||
|
||||
The devise method in your models also accept some options to configure its modules. For example, you can chose which encryptor to use in authenticatable simply doing:
|
||||
|
||||
devise :authenticatable, :confirmable, :recoverable, :encryptor => :bcrypt
|
||||
|
||||
Besides :encryptor, you can provide :pepper, :stretches, :confirm_within, :remember_for, :timeout_in, :unlock_in and others. All those are described in the initializer created when you invoke the devise_install generator describer above.
|
||||
|
||||
== Configuring controllers and views
|
||||
|
||||
One of Devise goals is to help you bootstrap your application with authentication really fast. Another goal is to not be in your way when you need to customize it.
|
||||
|
||||
Since devise is an engine, it has all default views inside the gem. They are good to get you started, but you will want to customize them at some point. And Devise has a generator to copy them all to your application:
|
||||
|
||||
rails generate devise_views
|
||||
|
||||
If you have more than one role in your application, you will notice that Devise uses the same views for all roles you have. But what if you need so different views to each of them? Devise also has an easy way to accomplish it: just setup config.scoped_views to true inside "config/initializers/devise.rb".
|
||||
|
||||
After doing so you will be able to have views based on the scope like "users/sessions/new" and "admins/sessions/new". If no view is found within the scope, Devise will fallback to the default view at "devise/sessions/new".
|
||||
|
||||
Finally, 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
|
||||
|
||||
2) Tell the router to use this controller:
|
||||
|
||||
devise_for :admins, :controllers => { :sessions = "admin/sessions" }
|
||||
|
||||
3) And finally, since we changed the controller, it won't use "devise/sessions" as views anymore, so remember to make a copy of "devise/sessions" to "admin/sessions".
|
||||
|
||||
Remember that Devise uses flash messages to let users know if sign in wass successful or not. Devise expects your application to call "flash[:notice]" and "flash[:alert]" as appropriate.
|
||||
|
||||
== I18n
|
||||
|
||||
Devise uses flash messages with I18n with the flash keys :success and :failure. To customize your app, you can setup your locale file this way:
|
||||
|
||||
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!'
|
||||
|
||||
Devise mailer uses the same pattern to create subject messages:
|
||||
|
||||
en:
|
||||
devise:
|
||||
mailer:
|
||||
confirmation_instructions: 'Hello everybody!'
|
||||
user:
|
||||
confirmation_instructions: 'Hello User! Please confirm your email'
|
||||
reset_password_instructions: 'Reset instructions'
|
||||
|
||||
Take a look at our locale file to check all available messages.
|
||||
|
||||
== 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)
|
||||
|
||||
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 or spec/spec_helper.rb file:
|
||||
|
||||
class ActionController::TestCase
|
||||
include Devise::TestHelpers
|
||||
end
|
||||
|
||||
Do not use such helpers for integration tests like Cucumber, Webrat... Just fill in the form or explicitly set the user in session. For more tips, check the wiki (http://wiki.github.com/plataformatec/devise).
|
||||
|
||||
== Migrating from other solutions
|
||||
|
||||
Devise implements encryption strategies for Clearance, Authlogic and Restful-Authentication. To make use of it set the desired encryptor in the encryptor initializer config option. You might also need to rename your encrypted password and salt columns to match Devises's one (encrypted_password and password_salt).
|
||||
|
||||
== Other ORMs
|
||||
|
||||
Devise supports both ActiveRecord (default) and MongoMapper, and has experimental Datamapper supports (in a sense that Devise test suite does not run completely with Datamapper). To choose other ORM, you just need to configure it in the initializer file.
|
||||
|
||||
== TODO
|
||||
|
||||
Please refer to TODO file.
|
||||
|
||||
== Maintainers
|
||||
|
||||
* José Valim (http://github.com/josevalim)
|
||||
* Carlos Antônio da Silva (http://github.com/carlosantoniodasilva)
|
||||
|
||||
== Contributors
|
||||
|
||||
We have a long running list of contributors. Check them in the CHANGELOG or do `git shortlog -s -n` in the cloned repository.
|
||||
|
||||
== Bugs and Feedback
|
||||
|
||||
If you discover any bugs or want to drop a line, feel free to create an issue on
|
||||
GitHub or send an e-mail to the mailing list.
|
||||
|
||||
http://github.com/plataformatec/devise/issues |
|
||||
http://groups.google.com/group/plataformatec-devise |
|
||||
http://wiki.github.com/plataformatec/devise/
|
||||
|
||||
MIT License. Copyright 2009 Plataforma Tecnologia. http://blog.plataformatec.com.br
|
||||
34
Rakefile
34
Rakefile
@@ -1,18 +1,18 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
require 'rake'
|
||||
require "bundler/gem_tasks"
|
||||
require 'rake/testtask'
|
||||
require 'rake/rdoctask'
|
||||
require File.join(File.dirname(__FILE__), 'lib', 'devise', 'version')
|
||||
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
|
||||
Dir[File.join(File.dirname(__FILE__), 'test', 'orm', '*.rb')].each do |file|
|
||||
orm = File.basename(file).split(".").first
|
||||
system "rake test DEVISE_ORM=#{orm}"
|
||||
# "Some day, my son, rake's inner wisdom will reveal itself. Until then,
|
||||
# take this `system` -- may its brute force protect you well."
|
||||
exit 1 unless system "rake test DEVISE_ORM=#{orm}"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -29,26 +29,6 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
|
||||
rdoc.rdoc_dir = 'rdoc'
|
||||
rdoc.title = 'Devise'
|
||||
rdoc.options << '--line-numbers' << '--inline-source'
|
||||
rdoc.rdoc_files.include('README.rdoc')
|
||||
rdoc.rdoc_files.include('README.md')
|
||||
rdoc.rdoc_files.include('lib/**/*.rb')
|
||||
end
|
||||
|
||||
begin
|
||||
require 'jeweler'
|
||||
Jeweler::Tasks.new do |s|
|
||||
s.name = "devise"
|
||||
s.version = Devise::VERSION
|
||||
s.summary = "Flexible authentication solution for Rails with Warden"
|
||||
s.email = "contact@plataformatec.com.br"
|
||||
s.homepage = "http://github.com/plataformatec/devise"
|
||||
s.description = "Flexible authentication solution for Rails with Warden"
|
||||
s.authors = ['José Valim', 'Carlos Antônio']
|
||||
s.files = FileList["[A-Z]*", "{app,config,lib}/**/*"]
|
||||
s.extra_rdoc_files = FileList["[A-Z]*"] - %w(Gemfile Rakefile)
|
||||
s.add_dependency("warden", "~> 0.9.4")
|
||||
end
|
||||
|
||||
Jeweler::GemcutterTasks.new
|
||||
rescue LoadError
|
||||
puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
||||
end
|
||||
|
||||
2
TODO
2
TODO
@@ -1,2 +0,0 @@
|
||||
* Make test run with DataMapper
|
||||
* Extract Activatable tests from Confirmable
|
||||
@@ -1,33 +1,43 @@
|
||||
class Devise::ConfirmationsController < ApplicationController
|
||||
include Devise::Controllers::InternalHelpers
|
||||
|
||||
class Devise::ConfirmationsController < DeviseController
|
||||
# GET /resource/confirmation/new
|
||||
def new
|
||||
build_resource
|
||||
render_with_scope :new
|
||||
build_resource({})
|
||||
end
|
||||
|
||||
# POST /resource/confirmation
|
||||
def create
|
||||
self.resource = resource_class.send_confirmation_instructions(params[resource_name])
|
||||
self.resource = resource_class.send_confirmation_instructions(resource_params)
|
||||
|
||||
if 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
|
||||
|
||||
# GET /resource/confirmation?confirmation_token=abcdef
|
||||
def show
|
||||
self.resource = resource_class.confirm!(:confirmation_token => params[:confirmation_token])
|
||||
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
|
||||
|
||||
30
app/controllers/devise/omniauth_callbacks_controller.rb
Normal file
30
app/controllers/devise/omniauth_callbacks_controller.rb
Normal file
@@ -0,0 +1,30 @@
|
||||
class Devise::OmniauthCallbacksController < DeviseController
|
||||
prepend_before_filter { request.env["devise.skip_timeout"] = true }
|
||||
|
||||
def passthru
|
||||
render :status => 404, :text => "Not found. Authentication passthru."
|
||||
end
|
||||
|
||||
def failure
|
||||
set_flash_message :alert, :failure, :kind => OmniAuth::Utils.camelize(failed_strategy.name), :reason => failure_message
|
||||
redirect_to after_omniauth_failure_path_for(resource_name)
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def failed_strategy
|
||||
env["omniauth.error.strategy"]
|
||||
end
|
||||
|
||||
def failure_message
|
||||
exception = env["omniauth.error"]
|
||||
error = exception.error_reason if exception.respond_to?(:error_reason)
|
||||
error ||= exception.error if exception.respond_to?(:error)
|
||||
error ||= env["omniauth.error.type"].to_s
|
||||
error.to_s.humanize if error
|
||||
end
|
||||
|
||||
def after_omniauth_failure_path_for(scope)
|
||||
new_session_path(scope)
|
||||
end
|
||||
end
|
||||
@@ -1,23 +1,21 @@
|
||||
class Devise::PasswordsController < ApplicationController
|
||||
include Devise::Controllers::InternalHelpers
|
||||
|
||||
before_filter :require_no_authentication
|
||||
class Devise::PasswordsController < DeviseController
|
||||
prepend_before_filter :require_no_authentication
|
||||
# Render the #edit only if coming from a reset password email link
|
||||
append_before_filter :assert_reset_token_passed, :only => :edit
|
||||
|
||||
# GET /resource/password/new
|
||||
def new
|
||||
build_resource
|
||||
render_with_scope :new
|
||||
build_resource({})
|
||||
end
|
||||
|
||||
# POST /resource/password
|
||||
def create
|
||||
self.resource = resource_class.send_reset_password_instructions(params[resource_name])
|
||||
self.resource = resource_class.send_reset_password_instructions(resource_params)
|
||||
|
||||
if 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
|
||||
|
||||
@@ -25,18 +23,43 @@ 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
|
||||
def update
|
||||
self.resource = resource_class.reset_password!(params[resource_name])
|
||||
self.resource = resource_class.reset_password_by_token(resource_params)
|
||||
|
||||
if resource.errors.empty?
|
||||
set_flash_message :notice, :updated
|
||||
sign_in_and_redirect(resource_name, resource)
|
||||
resource.unlock_access! if unlockable?(resource)
|
||||
flash_message = resource.active_for_authentication? ? :updated : :updated_not_active
|
||||
set_flash_message(:notice, flash_message) if is_navigational_format?
|
||||
sign_in(resource_name, resource)
|
||||
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
|
||||
|
||||
# Check if a reset_password_token is provided in the request
|
||||
def assert_reset_token_passed
|
||||
if params[:reset_password_token].blank?
|
||||
set_flash_message(:error, :no_token)
|
||||
redirect_to new_session_path(resource_name)
|
||||
end
|
||||
end
|
||||
|
||||
# Check if proper Lockable module methods are present & unlock strategy
|
||||
# allows to unlock resource on password reset
|
||||
def unlockable?(resource)
|
||||
resource.respond_to?(:unlock_access!) &&
|
||||
resource.respond_to?(:unlock_strategy_enabled?) &&
|
||||
resource.unlock_strategy_enabled?(:email)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,57 +1,119 @@
|
||||
class Devise::RegistrationsController < ApplicationController
|
||||
include Devise::Controllers::InternalHelpers
|
||||
|
||||
before_filter :require_no_authentication, :only => [ :new, :create ]
|
||||
before_filter :authenticate_scope!, :only => [:edit, :update, :destroy]
|
||||
class Devise::RegistrationsController < DeviseController
|
||||
prepend_before_filter :require_no_authentication, :only => [ :new, :create, :cancel ]
|
||||
prepend_before_filter :authenticate_scope!, :only => [:edit, :update, :destroy]
|
||||
|
||||
# GET /resource/sign_up
|
||||
def new
|
||||
build_resource
|
||||
render_with_scope :new
|
||||
resource = build_resource({})
|
||||
respond_with resource
|
||||
end
|
||||
|
||||
# POST /resource/sign_up
|
||||
# POST /resource
|
||||
def create
|
||||
build_resource
|
||||
|
||||
if resource.save
|
||||
flash[:"#{resource_name}_signed_up"] = true
|
||||
set_flash_message :notice, :signed_up
|
||||
sign_in_and_redirect(resource_name, resource)
|
||||
if resource.active_for_authentication?
|
||||
set_flash_message :notice, :signed_up if is_navigational_format?
|
||||
sign_up(resource_name, resource)
|
||||
respond_with resource, :location => after_sign_up_path_for(resource)
|
||||
else
|
||||
set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format?
|
||||
expire_session_data_after_sign_in!
|
||||
respond_with resource, :location => after_inactive_sign_up_path_for(resource)
|
||||
end
|
||||
else
|
||||
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
|
||||
if self.resource.update_with_password(params[resource_name])
|
||||
set_flash_message :notice, :updated
|
||||
redirect_to after_sign_in_path_for(self.resource)
|
||||
self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key)
|
||||
prev_unconfirmed_email = resource.unconfirmed_email if resource.respond_to?(:unconfirmed_email)
|
||||
|
||||
if resource.update_with_password(resource_params)
|
||||
if is_navigational_format?
|
||||
flash_key = update_needs_confirmation?(resource, prev_unconfirmed_email) ?
|
||||
:update_needs_confirmation : :updated
|
||||
set_flash_message :notice, flash_key
|
||||
end
|
||||
sign_in resource_name, resource, :bypass => true
|
||||
respond_with resource, :location => after_update_path_for(resource)
|
||||
else
|
||||
build_resource
|
||||
send(:"current_#{resource_name}").reload
|
||||
render_with_scope :edit
|
||||
clean_up_passwords resource
|
||||
respond_with resource
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /resource
|
||||
def destroy
|
||||
self.resource.destroy
|
||||
set_flash_message :notice, :destroyed
|
||||
sign_out_and_redirect(self.resource)
|
||||
resource.destroy
|
||||
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
|
||||
# Forces the session data which is usually expired after sign
|
||||
# in to be expired now. This is useful if the user wants to
|
||||
# cancel oauth signing in/up in the middle of the process,
|
||||
# removing all OAuth session data.
|
||||
def cancel
|
||||
expire_session_data_after_sign_in!
|
||||
redirect_to new_registration_path(resource_name)
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
# Authenticates the current scope and dup the resource
|
||||
def authenticate_scope!
|
||||
send(:"authenticate_#{resource_name}!")
|
||||
self.resource = send(:"current_#{resource_name}")
|
||||
end
|
||||
def update_needs_confirmation?(resource, previous)
|
||||
resource.respond_to?(:pending_reconfirmation?) &&
|
||||
resource.pending_reconfirmation? &&
|
||||
previous != resource.unconfirmed_email
|
||||
end
|
||||
|
||||
# Build a devise resource passing in the session. Useful to move
|
||||
# temporary session data to the newly created user.
|
||||
def build_resource(hash=nil)
|
||||
hash ||= resource_params || {}
|
||||
self.resource = resource_class.new_with_session(hash, session)
|
||||
end
|
||||
|
||||
# Signs in a user on sign up. You can overwrite this method in your own
|
||||
# RegistrationsController.
|
||||
def sign_up(resource_name, resource)
|
||||
sign_in(resource_name, resource)
|
||||
end
|
||||
|
||||
# The path used after sign up. You need to overwrite this method
|
||||
# in your own RegistrationsController.
|
||||
def after_sign_up_path_for(resource)
|
||||
after_sign_in_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 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
|
||||
|
||||
# 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,45 +1,48 @@
|
||||
class Devise::SessionsController < ApplicationController
|
||||
include Devise::Controllers::InternalHelpers
|
||||
|
||||
before_filter :require_no_authentication, :only => [ :new, :create ]
|
||||
class Devise::SessionsController < DeviseController
|
||||
prepend_before_filter :require_no_authentication, :only => [ :new, :create ]
|
||||
prepend_before_filter :allow_params_authentication!, :only => :create
|
||||
prepend_before_filter { request.env["devise.skip_timeout"] = true }
|
||||
|
||||
# GET /resource/sign_in
|
||||
def new
|
||||
unless resource_just_signed_up?
|
||||
Devise::FLASH_MESSAGES.each do |message|
|
||||
set_now_flash_message :alert, message if params.try(:[], message) == "true"
|
||||
end
|
||||
end
|
||||
|
||||
build_resource
|
||||
render_with_scope :new
|
||||
self.resource = build_resource(nil, :unsafe => true)
|
||||
clean_up_passwords(resource)
|
||||
respond_with(resource, serialize_options(resource))
|
||||
end
|
||||
|
||||
# POST /resource/sign_in
|
||||
def create
|
||||
if resource = authenticate(resource_name)
|
||||
set_flash_message :notice, :signed_in
|
||||
sign_in_and_redirect(resource_name, resource, true)
|
||||
else
|
||||
set_now_flash_message :alert, (warden.message || :invalid)
|
||||
clean_up_passwords(build_resource)
|
||||
render_with_scope :new
|
||||
end
|
||||
self.resource = warden.authenticate!(auth_options)
|
||||
set_flash_message(:notice, :signed_in) if is_navigational_format?
|
||||
sign_in(resource_name, resource)
|
||||
respond_with resource, :location => after_sign_in_path_for(resource)
|
||||
end
|
||||
|
||||
# GET /resource/sign_out
|
||||
# DELETE /resource/sign_out
|
||||
def destroy
|
||||
set_flash_message :notice, :signed_out if signed_in?(resource_name)
|
||||
sign_out_and_redirect(resource_name)
|
||||
redirect_path = after_sign_out_path_for(resource_name)
|
||||
signed_out = (Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name))
|
||||
set_flash_message :notice, :signed_out if signed_out && is_navigational_format?
|
||||
|
||||
# We actually need to hardcode this as Rails default responder doesn't
|
||||
# support returning empty response on GET request
|
||||
respond_to do |format|
|
||||
format.all { head :no_content }
|
||||
format.any(*navigational_formats) { redirect_to redirect_path }
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def resource_just_signed_up?
|
||||
flash[:"#{resource_name}_signed_up"]
|
||||
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 clean_up_passwords(object)
|
||||
object.clean_up_passwords if object.respond_to?(:clean_up_passwords)
|
||||
def auth_options
|
||||
{ :scope => resource_name, :recall => "#{controller_path}#new" }
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,33 +1,44 @@
|
||||
class Devise::UnlocksController < ApplicationController
|
||||
include Devise::Controllers::InternalHelpers
|
||||
class Devise::UnlocksController < DeviseController
|
||||
prepend_before_filter :require_no_authentication
|
||||
|
||||
# GET /resource/unlock/new
|
||||
def new
|
||||
build_resource
|
||||
render_with_scope :new
|
||||
build_resource({})
|
||||
end
|
||||
|
||||
# POST /resource/unlock
|
||||
def create
|
||||
self.resource = resource_class.send_unlock_instructions(params[resource_name])
|
||||
self.resource = resource_class.send_unlock_instructions(resource_params)
|
||||
|
||||
if 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_unlock_instructions_path_for(resource))
|
||||
else
|
||||
render_with_scope :new
|
||||
respond_with(resource)
|
||||
end
|
||||
end
|
||||
|
||||
# GET /resource/unlock?unlock_token=abcdef
|
||||
def show
|
||||
self.resource = resource_class.unlock!(:unlock_token => params[:unlock_token])
|
||||
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 after_unlock_path_for(resource) }
|
||||
else
|
||||
render_with_scope :new
|
||||
respond_with_navigational(resource.errors, :status => :unprocessable_entity){ render :new }
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
# The path used after sending unlock password instructions
|
||||
def after_sending_unlock_instructions_path_for(resource)
|
||||
new_session_path(resource)
|
||||
end
|
||||
|
||||
# The path used after unlocking the resource
|
||||
def after_unlock_path_for(resource)
|
||||
new_session_path(resource)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
184
app/controllers/devise_controller.rb
Normal file
184
app/controllers/devise_controller.rb
Normal file
@@ -0,0 +1,184 @@
|
||||
# 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 resource_params devise_mapping)
|
||||
hide_action *helpers
|
||||
helper_method *helpers
|
||||
|
||||
prepend_before_filter :assert_is_devise_resource!
|
||||
respond_to :html 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
|
||||
|
||||
def resource_params
|
||||
params[resource_name]
|
||||
end
|
||||
|
||||
# Returns a signed in resource from session (if one exists)
|
||||
def signed_in_resource
|
||||
warden.authenticate(:scope => resource_name)
|
||||
end
|
||||
|
||||
# Attempt to find the mapped route for devise based on request path
|
||||
def devise_mapping
|
||||
@devise_mapping ||= request.env["devise.mapping"]
|
||||
end
|
||||
|
||||
# Override prefixes to consider the scoped view.
|
||||
# Notice we need to check for the request due to a bug in
|
||||
# Action Controller tests that forces _prefixes to be
|
||||
# loaded before even having a request object.
|
||||
def _prefixes #:nodoc:
|
||||
@_prefixes ||= if self.class.scoped_views? && request && devise_mapping
|
||||
super.unshift("#{devise_mapping.scoped_path}/#{controller_name}")
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
hide_action :_prefixes
|
||||
|
||||
protected
|
||||
|
||||
# Checks whether it's a devise mapped resource or not.
|
||||
def assert_is_devise_resource! #:nodoc:
|
||||
unknown_action! <<-MESSAGE unless devise_mapping
|
||||
Could not find devise mapping for path #{request.fullpath.inspect}.
|
||||
This may happen for two reasons:
|
||||
|
||||
1) You forgot to wrap your route inside the scope block. For example:
|
||||
|
||||
devise_scope :user do
|
||||
match "/some/route" => "some_devise_controller"
|
||||
end
|
||||
|
||||
2) You are testing a Devise controller bypassing the router.
|
||||
If so, you can explicitly tell Devise which mapping to use:
|
||||
|
||||
@request.env["devise.mapping"] = Devise.mappings[:user]
|
||||
|
||||
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.
|
||||
# Assignment bypasses attribute protection when :unsafe option is passed
|
||||
def build_resource(hash = nil, options = {})
|
||||
hash ||= resource_params || {}
|
||||
|
||||
if options[:unsafe]
|
||||
self.resource = resource_class.new.tap do |resource|
|
||||
hash.each do |key, value|
|
||||
setter = :"#{key}="
|
||||
resource.send(setter, value) if resource.respond_to?(setter)
|
||||
end
|
||||
end
|
||||
else
|
||||
self.resource = resource_class.new(hash)
|
||||
end
|
||||
end
|
||||
|
||||
# Helper for use in before_filters where no authentication is required.
|
||||
#
|
||||
# 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
|
||||
options = devise_i18n_options(options) if respond_to?(:devise_i18n_options, true)
|
||||
message = I18n.t("#{options[: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
|
||||
end
|
||||
25
app/helpers/devise_helper.rb
Normal file
25
app/helpers/devise_helper.rb
Normal file
@@ -0,0 +1,25 @@
|
||||
module DeviseHelper
|
||||
# A simple way to show error messages for the current devise resource. If you need
|
||||
# to customize this method, you can either overwrite it in your application helpers or
|
||||
# copy the views to your application.
|
||||
#
|
||||
# This method is intended to stay simple and it is unlikely that we are going to change
|
||||
# it to add more behavior or options.
|
||||
def devise_error_messages!
|
||||
return "" if resource.errors.empty?
|
||||
|
||||
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.class.model_name.human.downcase)
|
||||
|
||||
html = <<-HTML
|
||||
<div id="error_explanation">
|
||||
<h2>#{sentence}</h2>
|
||||
<ul>#{messages}</ul>
|
||||
</div>
|
||||
HTML
|
||||
|
||||
html.html_safe
|
||||
end
|
||||
end
|
||||
15
app/mailers/devise/mailer.rb
Normal file
15
app/mailers/devise/mailer.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
class Devise::Mailer < Devise.parent_mailer.constantize
|
||||
include Devise::Mailers::Helpers
|
||||
|
||||
def confirmation_instructions(record, opts={})
|
||||
devise_mail(record, :confirmation_instructions, opts)
|
||||
end
|
||||
|
||||
def reset_password_instructions(record, opts={})
|
||||
devise_mail(record, :reset_password_instructions, opts)
|
||||
end
|
||||
|
||||
def unlock_instructions(record, opts={})
|
||||
devise_mail(record, :unlock_instructions, opts)
|
||||
end
|
||||
end
|
||||
@@ -1,55 +0,0 @@
|
||||
class Devise::Mailer < ::ActionMailer::Base
|
||||
include Devise::Controllers::ScopedViews
|
||||
|
||||
attr_reader :devise_mapping, :resource
|
||||
|
||||
def confirmation_instructions(record)
|
||||
setup_mail(record, :confirmation_instructions)
|
||||
end
|
||||
|
||||
def reset_password_instructions(record)
|
||||
setup_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)
|
||||
@devise_mapping = Devise::Mapping.find_by_class(record.class)
|
||||
|
||||
raise "Invalid devise resource #{record}" unless @devise_mapping
|
||||
@resource = instance_variable_set("@#{@devise_mapping.name}", record)
|
||||
|
||||
mail(:subject => translate(@devise_mapping, action),
|
||||
:from => mailer_sender(@devise_mapping), :to => record.email) do |format|
|
||||
format.html { render_with_scope(action, :controller => "mailer") }
|
||||
end
|
||||
end
|
||||
|
||||
def mailer_sender(mapping)
|
||||
if Devise.mailer_sender.is_a?(Proc)
|
||||
block_args = mapping.name if Devise.mailer_sender.arity > 0
|
||||
Devise.mailer_sender.call(block_args)
|
||||
else
|
||||
Devise.mailer_sender
|
||||
end
|
||||
end
|
||||
|
||||
# Setup subject namespaced by model. It means you're able to setup your
|
||||
# messages using specific resource scope, or provide a default one.
|
||||
# Example (i18n locale file):
|
||||
#
|
||||
# en:
|
||||
# devise:
|
||||
# mailer:
|
||||
# confirmation_instructions: '...'
|
||||
# user:
|
||||
# confirmation_instructions: '...'
|
||||
def translate(mapping, key)
|
||||
I18n.t(:"#{mapping.name}.#{key}", :scope => [:devise, :mailer], :default => key)
|
||||
end
|
||||
end
|
||||
3
app/views/devise/_links.erb
Normal file
3
app/views/devise/_links.erb
Normal file
@@ -0,0 +1,3 @@
|
||||
<% ActiveSupport::Deprecation.warn "Rendering partials devise/_links.erb is deprecated" \
|
||||
"please use devise/shared/_links.erb instead."%>
|
||||
<%= render "shared/links" %>
|
||||
@@ -1,12 +1,12 @@
|
||||
<h2>Resend confirmation instructions</h2>
|
||||
|
||||
<% form_for resource_name, resource, :url => confirmation_path(resource_name) do |f| %>
|
||||
<%= f.error_messages %>
|
||||
<%= form_for(resource, :as => resource_name, :url => confirmation_path(resource_name), :html => { :method => :post }) do |f| %>
|
||||
<%= devise_error_messages! %>
|
||||
|
||||
<p><%= f.label :email %></p>
|
||||
<p><%= f.text_field :email %></p>
|
||||
<div><%= f.label :email %><br />
|
||||
<%= f.email_field :email, :autofocus => true %></div>
|
||||
|
||||
<p><%= f.submit "Resend confirmation instructions" %></p>
|
||||
<div><%= f.submit "Resend confirmation instructions" %></div>
|
||||
<% end %>
|
||||
|
||||
<%= render :partial => "devise/shared/links" %>
|
||||
<%= render "devise/shared/links" %>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<p>Welcome <%= @resource.email %>!</p>
|
||||
<p>Welcome <%= @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>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<p>Hello <%= @resource.email %>!</p>
|
||||
|
||||
<p>Someone has requested a link to change your password, and you can do this through the link below.</p>
|
||||
<p>Someone has requested a link to change your password. You can do this through the link below.</p>
|
||||
|
||||
<p><%= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @resource.reset_password_token) %></p>
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<p>Hello <%= @resource.email %>!</p>
|
||||
|
||||
<p>Your account has been locked due to an excessive amount of unsuccessful sign in attempts.</p>
|
||||
<p>Your account has been locked due to an excessive number of unsuccessful sign in attempts.</p>
|
||||
|
||||
<p>Click the link below to unlock your account:</p>
|
||||
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
<h2>Change your password</h2>
|
||||
|
||||
<% form_for resource_name, resource, :url => password_path(resource_name), :html => { :method => :put } do |f| %>
|
||||
<%= f.error_messages %>
|
||||
<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :put }) do |f| %>
|
||||
<%= devise_error_messages! %>
|
||||
<%= f.hidden_field :reset_password_token %>
|
||||
|
||||
<p><%= f.label :password %></p>
|
||||
<p><%= f.password_field :password %></p>
|
||||
<div><%= f.label :password, "New password" %><br />
|
||||
<%= f.password_field :password, :autofocus => true %></div>
|
||||
|
||||
<p><%= f.label :password_confirmation %></p>
|
||||
<p><%= 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 "devise/shared/links" %>
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
<h2>Forgot your password?</h2>
|
||||
|
||||
<% form_for resource_name, resource, :url => password_path(resource_name) do |f| %>
|
||||
<%= f.error_messages %>
|
||||
<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :post }) do |f| %>
|
||||
<%= devise_error_messages! %>
|
||||
|
||||
<p><%= f.label :email %></p>
|
||||
<p><%= f.text_field :email %></p>
|
||||
<div><%= f.label :email %><br />
|
||||
<%= f.email_field :email, :autofocus => true %></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 "devise/shared/links" %>
|
||||
|
||||
@@ -1,25 +1,29 @@
|
||||
<h2>Edit <%= resource_name.to_s.humanize %></h2>
|
||||
|
||||
<% form_for resource_name, resource, :url => registration_path(resource_name), :html => { :method => :put } do |f| -%>
|
||||
<%= f.error_messages %>
|
||||
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %>
|
||||
<%= devise_error_messages! %>
|
||||
|
||||
<p><%= f.label :email %></p>
|
||||
<p><%= f.text_field :email %></p>
|
||||
<div><%= f.label :email %><br />
|
||||
<%= f.email_field :email, :autofocus => true %></div>
|
||||
|
||||
<p><%= f.label :password %> <i>(leave blank if you don't want to change it)</i></p>
|
||||
<p><%= f.password_field :password %></p>
|
||||
<% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
|
||||
<div>Currently waiting confirmation for: <%= resource.unconfirmed_email %></div>
|
||||
<% end %>
|
||||
|
||||
<p><%= f.label :password_confirmation %></p>
|
||||
<p><%= f.password_field :password_confirmation %></p>
|
||||
<div><%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
|
||||
<%= f.password_field :password, :autocomplete => "off" %></div>
|
||||
|
||||
<p><%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i></p>
|
||||
<p><%= f.password_field :current_password %></p>
|
||||
<div><%= f.label :password_confirmation %><br />
|
||||
<%= f.password_field :password_confirmation %></div>
|
||||
|
||||
<p><%= f.submit "Update" %></p>
|
||||
<% end -%>
|
||||
<div><%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
|
||||
<%= f.password_field :current_password %></div>
|
||||
|
||||
<div><%= f.submit "Update" %></div>
|
||||
<% end %>
|
||||
|
||||
<h3>Cancel my account</h3>
|
||||
|
||||
<p>Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), :confirm => "Are you sure?", :method => :delete %>.</p>
|
||||
<p>Unhappy? <%= button_to "Cancel my account", registration_path(resource_name), :data => { :confirm => "Are you sure?" }, :method => :delete %>.</p>
|
||||
|
||||
<%= link_to "Back", :back %>
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
<h2>Sign up</h2>
|
||||
|
||||
<% form_for resource_name, resource, :url => registration_path(resource_name) do |f| -%>
|
||||
<%= f.error_messages %>
|
||||
<p><%= f.label :email %></p>
|
||||
<p><%= f.text_field :email %></p>
|
||||
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
|
||||
<%= devise_error_messages! %>
|
||||
|
||||
<p><%= f.label :password %></p>
|
||||
<p><%= f.password_field :password %></p>
|
||||
<div><%= f.label :email %><br />
|
||||
<%= f.email_field :email, :autofocus => true %></div>
|
||||
|
||||
<p><%= f.label :password_confirmation %></p>
|
||||
<p><%= f.password_field :password_confirmation %></p>
|
||||
<div><%= f.label :password %><br />
|
||||
<%= f.password_field :password %></div>
|
||||
|
||||
<p><%= f.submit "Sign up" %></p>
|
||||
<% end -%>
|
||||
<div><%= f.label :password_confirmation %><br />
|
||||
<%= f.password_field :password_confirmation %></div>
|
||||
|
||||
<%= render :partial => "devise/shared/links" %>
|
||||
<div><%= f.submit "Sign up" %></div>
|
||||
<% end %>
|
||||
|
||||
<%= render "devise/shared/links" %>
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
<h2>Sign in</h2>
|
||||
|
||||
<% form_for resource_name, resource, :url => session_path(resource_name) do |f| -%>
|
||||
<p><%= f.label :email %></p>
|
||||
<p><%= f.text_field :email %></p>
|
||||
<%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
|
||||
<div><%= f.label :email %><br />
|
||||
<%= f.email_field :email, :autofocus => true %></div>
|
||||
|
||||
<p><%= f.label :password %></p>
|
||||
<p><%= 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>
|
||||
<% end -%>
|
||||
<div><%= f.submit "Sign in" %></div>
|
||||
<% end %>
|
||||
|
||||
<%= render :partial => "devise/shared/links" %>
|
||||
<%= render "devise/shared/links" %>
|
||||
|
||||
@@ -1,19 +1,25 @@
|
||||
<%- if controller_name != 'sessions' %>
|
||||
<%= link_to t('devise.sessions.link'), new_session_path(resource_name) %><br />
|
||||
<%= link_to "Sign in", new_session_path(resource_name) %><br />
|
||||
<% end -%>
|
||||
|
||||
<%- if devise_mapping.registerable? && controller_name != 'registrations' %>
|
||||
<%= link_to t('devise.registrations.link'), new_registration_path(resource_name) %><br />
|
||||
<%= link_to "Sign up", new_registration_path(resource_name) %><br />
|
||||
<% end -%>
|
||||
|
||||
<%- if devise_mapping.recoverable? && controller_name != 'passwords' %>
|
||||
<%= link_to t('devise.passwords.link'), new_password_path(resource_name) %><br />
|
||||
<%= link_to "Forgot your password?", new_password_path(resource_name) %><br />
|
||||
<% end -%>
|
||||
|
||||
<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
|
||||
<%= link_to t('devise.confirmations.link'), new_confirmation_path(resource_name) %><br />
|
||||
<%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %><br />
|
||||
<% end -%>
|
||||
|
||||
<%- if devise_mapping.lockable? && controller_name != 'unlocks' %>
|
||||
<%= link_to t('devise.unlocks.link'), new_unlock_path(resource_name) %><br />
|
||||
<%- 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 -%>
|
||||
@@ -1,12 +1,12 @@
|
||||
<h2>Resend unlock instructions</h2>
|
||||
|
||||
<% form_for resource_name, resource, :url => unlock_path(resource_name) do |f| %>
|
||||
<%= f.error_messages %>
|
||||
<%= form_for(resource, :as => resource_name, :url => unlock_path(resource_name), :html => { :method => :post }) do |f| %>
|
||||
<%= devise_error_messages! %>
|
||||
|
||||
<p><%= f.label :email %></p>
|
||||
<p><%= f.text_field :email %></p>
|
||||
<div><%= f.label :email %><br />
|
||||
<%= f.email_field :email, :autofocus => true %></div>
|
||||
|
||||
<p><%= f.submit "Resend unlock instructions" %></p>
|
||||
<div><%= f.submit "Resend unlock instructions" %></div>
|
||||
<% end %>
|
||||
|
||||
<%= render :partial => "devise/shared/links" %>
|
||||
<%= render "devise/shared/links" %>
|
||||
|
||||
@@ -1,41 +1,59 @@
|
||||
# Additional translations at https://github.com/plataformatec/devise/wiki/I18n
|
||||
|
||||
en:
|
||||
devise:
|
||||
confirmations:
|
||||
confirmed: "Your account was successfully confirmed. You are now signed in."
|
||||
send_instructions: "You will receive an email with instructions about how to confirm your account in a few minutes."
|
||||
send_paranoid_instructions: "If your email address exists in our database, you will receive an email with instructions about how to confirm your account in a few minutes."
|
||||
failure:
|
||||
already_authenticated: "You are already signed in."
|
||||
inactive: "Your account was not activated yet."
|
||||
invalid: "Invalid email or password."
|
||||
invalid_token: "Invalid authentication token."
|
||||
locked: "Your account is locked."
|
||||
not_found_in_database: "Invalid email or password."
|
||||
timeout: "Your session expired, please sign in again to continue."
|
||||
unauthenticated: "You need to sign in or sign up before continuing."
|
||||
unconfirmed: "You have to confirm your account before continuing."
|
||||
mailer:
|
||||
confirmation_instructions:
|
||||
subject: "Confirmation instructions"
|
||||
reset_password_instructions:
|
||||
subject: "Reset password instructions"
|
||||
unlock_instructions:
|
||||
subject: "Unlock Instructions"
|
||||
omniauth_callbacks:
|
||||
failure: "Could not authenticate you from %{kind} because \"%{reason}\"."
|
||||
success: "Successfully authenticated from %{kind} account."
|
||||
passwords:
|
||||
no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided."
|
||||
send_instructions: "You will receive an email with instructions about how to reset your password in a few minutes."
|
||||
send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes."
|
||||
updated: "Your password was changed successfully. You are now signed in."
|
||||
updated_not_active: "Your password was changed successfully."
|
||||
registrations:
|
||||
destroyed: "Bye! Your account was successfully cancelled. We hope to see you again soon."
|
||||
signed_up: "Welcome! You have signed up successfully."
|
||||
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."
|
||||
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."
|
||||
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."
|
||||
updated: "You updated your account successfully."
|
||||
sessions:
|
||||
signed_in: "Signed in successfully."
|
||||
signed_out: "Signed out successfully."
|
||||
unlocks:
|
||||
send_instructions: "You will receive an email with instructions about how to unlock your account in a few minutes."
|
||||
send_paranoid_instructions: "If your account exists, you will receive an email with instructions about how to unlock it in a few minutes."
|
||||
unlocked: "Your account has been unlocked successfully. Please sign in to continue."
|
||||
errors:
|
||||
messages:
|
||||
already_confirmed: "was already confirmed, please try signing in"
|
||||
confirmation_period_expired: "needs to be confirmed within %{period}, please request a new one"
|
||||
expired: "has expired, please request a new one"
|
||||
not_found: "not found"
|
||||
already_confirmed: "was already confirmed"
|
||||
not_locked: "was not locked"
|
||||
|
||||
devise:
|
||||
sessions:
|
||||
link: 'Sign in'
|
||||
signed_in: 'Signed in successfully.'
|
||||
signed_out: 'Signed out successfully.'
|
||||
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.'
|
||||
invalid: 'Invalid email or password.'
|
||||
invalid_token: 'Invalid authentication token.'
|
||||
timeout: 'Your session expired, please sign in again to continue.'
|
||||
inactive: 'Your account was not activated yet.'
|
||||
passwords:
|
||||
link: 'Forgot password?'
|
||||
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.'
|
||||
confirmations:
|
||||
link: "Didn't receive confirmation instructions?"
|
||||
send_instructions: '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:
|
||||
link: 'Sign up'
|
||||
signed_up: 'You have signed up successfully.'
|
||||
updated: 'You updated your account successfully.'
|
||||
destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.'
|
||||
unlocks:
|
||||
link: "Didn't receive unlock instructions?"
|
||||
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.'
|
||||
mailer:
|
||||
confirmation_instructions: 'Confirmation instructions'
|
||||
reset_password_instructions: 'Reset password instructions'
|
||||
unlock_instructions: 'Unlock Instructions'
|
||||
|
||||
not_saved:
|
||||
one: "1 error prohibited this %{resource} from being saved:"
|
||||
other: "%{count} errors prohibited this %{resource} from being saved:"
|
||||
|
||||
193
devise.gemspec
193
devise.gemspec
@@ -1,182 +1,25 @@
|
||||
# Generated by jeweler
|
||||
# DO NOT EDIT THIS FILE DIRECTLY
|
||||
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
||||
# -*- encoding: utf-8 -*-
|
||||
$:.push File.expand_path("../lib", __FILE__)
|
||||
require "devise/version"
|
||||
|
||||
Gem::Specification.new do |s|
|
||||
s.name = %q{devise}
|
||||
s.version = "1.1.pre3"
|
||||
s.name = "devise"
|
||||
s.version = Devise::VERSION.dup
|
||||
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"
|
||||
s.description = "Flexible authentication solution for Rails with Warden"
|
||||
s.authors = ['José Valim', 'Carlos Antônio']
|
||||
|
||||
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
||||
s.authors = ["Jos\303\251 Valim", "Carlos Ant\303\264nio"]
|
||||
s.date = %q{2010-02-24}
|
||||
s.description = %q{Flexible authentication solution for Rails with Warden}
|
||||
s.email = %q{contact@plataformatec.com.br}
|
||||
s.extra_rdoc_files = [
|
||||
"CHANGELOG.rdoc",
|
||||
"MIT-LICENSE",
|
||||
"README.rdoc",
|
||||
"TODO"
|
||||
]
|
||||
s.files = [
|
||||
"CHANGELOG.rdoc",
|
||||
"Gemfile",
|
||||
"MIT-LICENSE",
|
||||
"README.rdoc",
|
||||
"Rakefile",
|
||||
"TODO",
|
||||
"app/controllers/devise/confirmations_controller.rb",
|
||||
"app/controllers/devise/passwords_controller.rb",
|
||||
"app/controllers/devise/registrations_controller.rb",
|
||||
"app/controllers/devise/sessions_controller.rb",
|
||||
"app/controllers/devise/unlocks_controller.rb",
|
||||
"app/models/devise/mailer.rb",
|
||||
"app/views/devise/confirmations/new.html.erb",
|
||||
"app/views/devise/mailer/confirmation_instructions.html.erb",
|
||||
"app/views/devise/mailer/reset_password_instructions.html.erb",
|
||||
"app/views/devise/mailer/unlock_instructions.html.erb",
|
||||
"app/views/devise/passwords/edit.html.erb",
|
||||
"app/views/devise/passwords/new.html.erb",
|
||||
"app/views/devise/registrations/edit.html.erb",
|
||||
"app/views/devise/registrations/new.html.erb",
|
||||
"app/views/devise/sessions/new.html.erb",
|
||||
"app/views/devise/shared/_links.erb",
|
||||
"app/views/devise/unlocks/new.html.erb",
|
||||
"config/locales/en.yml",
|
||||
"lib/devise.rb",
|
||||
"lib/devise/controllers/helpers.rb",
|
||||
"lib/devise/controllers/internal_helpers.rb",
|
||||
"lib/devise/controllers/scoped_views.rb",
|
||||
"lib/devise/controllers/url_helpers.rb",
|
||||
"lib/devise/encryptors/authlogic_sha512.rb",
|
||||
"lib/devise/encryptors/base.rb",
|
||||
"lib/devise/encryptors/bcrypt.rb",
|
||||
"lib/devise/encryptors/clearance_sha1.rb",
|
||||
"lib/devise/encryptors/restful_authentication_sha1.rb",
|
||||
"lib/devise/encryptors/sha1.rb",
|
||||
"lib/devise/encryptors/sha512.rb",
|
||||
"lib/devise/failure_app.rb",
|
||||
"lib/devise/hooks/activatable.rb",
|
||||
"lib/devise/hooks/rememberable.rb",
|
||||
"lib/devise/hooks/timeoutable.rb",
|
||||
"lib/devise/hooks/trackable.rb",
|
||||
"lib/devise/mapping.rb",
|
||||
"lib/devise/models.rb",
|
||||
"lib/devise/models/activatable.rb",
|
||||
"lib/devise/models/authenticatable.rb",
|
||||
"lib/devise/models/confirmable.rb",
|
||||
"lib/devise/models/http_authenticatable.rb",
|
||||
"lib/devise/models/lockable.rb",
|
||||
"lib/devise/models/recoverable.rb",
|
||||
"lib/devise/models/registerable.rb",
|
||||
"lib/devise/models/rememberable.rb",
|
||||
"lib/devise/models/timeoutable.rb",
|
||||
"lib/devise/models/token_authenticatable.rb",
|
||||
"lib/devise/models/trackable.rb",
|
||||
"lib/devise/models/validatable.rb",
|
||||
"lib/devise/orm/active_record.rb",
|
||||
"lib/devise/orm/data_mapper.rb",
|
||||
"lib/devise/orm/mongo_mapper.rb",
|
||||
"lib/devise/rails.rb",
|
||||
"lib/devise/rails/routes.rb",
|
||||
"lib/devise/rails/warden_compat.rb",
|
||||
"lib/devise/schema.rb",
|
||||
"lib/devise/strategies/authenticatable.rb",
|
||||
"lib/devise/strategies/base.rb",
|
||||
"lib/devise/strategies/http_authenticatable.rb",
|
||||
"lib/devise/strategies/rememberable.rb",
|
||||
"lib/devise/strategies/token_authenticatable.rb",
|
||||
"lib/devise/test_helpers.rb",
|
||||
"lib/devise/version.rb",
|
||||
"lib/generators/devise/devise_generator.rb",
|
||||
"lib/generators/devise/templates/migration.rb",
|
||||
"lib/generators/devise_install/devise_install_generator.rb",
|
||||
"lib/generators/devise_install/templates/README",
|
||||
"lib/generators/devise_install/templates/devise.rb",
|
||||
"lib/generators/devise_views/devise_views_generator.rb"
|
||||
]
|
||||
s.homepage = %q{http://github.com/plataformatec/devise}
|
||||
s.rdoc_options = ["--charset=UTF-8"]
|
||||
s.rubyforge_project = "devise"
|
||||
|
||||
s.files = `git ls-files`.split("\n")
|
||||
s.test_files = `git ls-files -- test/*`.split("\n")
|
||||
s.require_paths = ["lib"]
|
||||
s.rubygems_version = %q{1.3.5}
|
||||
s.summary = %q{Flexible authentication solution for Rails with Warden}
|
||||
s.test_files = [
|
||||
"test/controllers/helpers_test.rb",
|
||||
"test/controllers/internal_helpers_test.rb",
|
||||
"test/controllers/url_helpers_test.rb",
|
||||
"test/devise_test.rb",
|
||||
"test/encryptors_test.rb",
|
||||
"test/failure_app_test.rb",
|
||||
"test/integration/authenticatable_test.rb",
|
||||
"test/integration/confirmable_test.rb",
|
||||
"test/integration/http_authenticatable_test.rb",
|
||||
"test/integration/lockable_test.rb",
|
||||
"test/integration/recoverable_test.rb",
|
||||
"test/integration/registerable_test.rb",
|
||||
"test/integration/rememberable_test.rb",
|
||||
"test/integration/timeoutable_test.rb",
|
||||
"test/integration/token_authenticatable_test.rb",
|
||||
"test/integration/trackable_test.rb",
|
||||
"test/mailers/confirmation_instructions_test.rb",
|
||||
"test/mailers/reset_password_instructions_test.rb",
|
||||
"test/mailers/unlock_instructions_test.rb",
|
||||
"test/mapping_test.rb",
|
||||
"test/models/authenticatable_test.rb",
|
||||
"test/models/confirmable_test.rb",
|
||||
"test/models/http_authenticatable_test.rb",
|
||||
"test/models/lockable_test.rb",
|
||||
"test/models/recoverable_test.rb",
|
||||
"test/models/rememberable_test.rb",
|
||||
"test/models/timeoutable_test.rb",
|
||||
"test/models/token_authenticatable_test.rb",
|
||||
"test/models/trackable_test.rb",
|
||||
"test/models/validatable_test.rb",
|
||||
"test/models_test.rb",
|
||||
"test/orm/active_record.rb",
|
||||
"test/orm/mongo_mapper.rb",
|
||||
"test/rails_app/app/active_record/admin.rb",
|
||||
"test/rails_app/app/active_record/user.rb",
|
||||
"test/rails_app/app/controllers/admins_controller.rb",
|
||||
"test/rails_app/app/controllers/application_controller.rb",
|
||||
"test/rails_app/app/controllers/home_controller.rb",
|
||||
"test/rails_app/app/controllers/sessions_controller.rb",
|
||||
"test/rails_app/app/controllers/users_controller.rb",
|
||||
"test/rails_app/app/helpers/application_helper.rb",
|
||||
"test/rails_app/app/mongo_mapper/admin.rb",
|
||||
"test/rails_app/app/mongo_mapper/user.rb",
|
||||
"test/rails_app/config/application.rb",
|
||||
"test/rails_app/config/boot.rb",
|
||||
"test/rails_app/config/environment.rb",
|
||||
"test/rails_app/config/environments/development.rb",
|
||||
"test/rails_app/config/environments/production.rb",
|
||||
"test/rails_app/config/environments/test.rb",
|
||||
"test/rails_app/config/initializers/backtrace_silencers.rb",
|
||||
"test/rails_app/config/initializers/cookie_verification_secret.rb",
|
||||
"test/rails_app/config/initializers/devise.rb",
|
||||
"test/rails_app/config/initializers/inflections.rb",
|
||||
"test/rails_app/config/initializers/session_store.rb",
|
||||
"test/rails_app/config/routes.rb",
|
||||
"test/routes_test.rb",
|
||||
"test/support/assertions.rb",
|
||||
"test/support/helpers.rb",
|
||||
"test/support/integration.rb",
|
||||
"test/support/test_silencer.rb",
|
||||
"test/support/webrat/integrations/rails.rb",
|
||||
"test/test_helper.rb",
|
||||
"test/test_helpers_test.rb"
|
||||
]
|
||||
|
||||
if s.respond_to? :specification_version then
|
||||
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
||||
s.specification_version = 3
|
||||
|
||||
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
||||
s.add_runtime_dependency(%q<warden>, ["~> 0.9.4"])
|
||||
else
|
||||
s.add_dependency(%q<warden>, ["~> 0.9.4"])
|
||||
end
|
||||
else
|
||||
s.add_dependency(%q<warden>, ["~> 0.9.4"])
|
||||
end
|
||||
s.add_dependency("warden", "~> 1.2.1")
|
||||
s.add_dependency("orm_adapter", "~> 0.1")
|
||||
s.add_dependency("bcrypt-ruby", "~> 3.0")
|
||||
s.add_dependency("railties", "~> 3.1")
|
||||
end
|
||||
|
||||
|
||||
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", "0.10.0", :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"
|
||||
end
|
||||
|
||||
platforms :mri_19 do
|
||||
group :mongoid do
|
||||
gem "mongoid", "~> 3.0"
|
||||
end
|
||||
end
|
||||
167
gemfiles/Gemfile.rails-3.1.x.lock
Normal file
167
gemfiles/Gemfile.rails-3.1.x.lock
Normal file
@@ -0,0 +1,167 @@
|
||||
PATH
|
||||
remote: ..
|
||||
specs:
|
||||
devise (2.2.0)
|
||||
bcrypt-ruby (~> 3.0)
|
||||
orm_adapter (~> 0.1)
|
||||
railties (~> 3.1)
|
||||
warden (~> 1.2.1)
|
||||
|
||||
GEM
|
||||
remote: http://rubygems.org/
|
||||
specs:
|
||||
actionmailer (3.1.10)
|
||||
actionpack (= 3.1.10)
|
||||
mail (~> 2.3.3)
|
||||
actionpack (3.1.10)
|
||||
activemodel (= 3.1.10)
|
||||
activesupport (= 3.1.10)
|
||||
builder (~> 3.0.0)
|
||||
erubis (~> 2.7.0)
|
||||
i18n (~> 0.6)
|
||||
rack (~> 1.3.6)
|
||||
rack-cache (~> 1.2)
|
||||
rack-mount (~> 0.8.2)
|
||||
rack-test (~> 0.6.1)
|
||||
sprockets (~> 2.0.4)
|
||||
activemodel (3.1.10)
|
||||
activesupport (= 3.1.10)
|
||||
builder (~> 3.0.0)
|
||||
i18n (~> 0.6)
|
||||
activerecord (3.1.10)
|
||||
activemodel (= 3.1.10)
|
||||
activesupport (= 3.1.10)
|
||||
arel (~> 2.2.3)
|
||||
tzinfo (~> 0.3.29)
|
||||
activeresource (3.1.10)
|
||||
activemodel (= 3.1.10)
|
||||
activesupport (= 3.1.10)
|
||||
activesupport (3.1.10)
|
||||
multi_json (>= 1.0, < 1.3)
|
||||
arel (2.2.3)
|
||||
bcrypt-ruby (3.0.1)
|
||||
builder (3.0.4)
|
||||
columnize (0.3.6)
|
||||
erubis (2.7.0)
|
||||
faraday (0.8.4)
|
||||
multipart-post (~> 1.1)
|
||||
hashie (1.2.0)
|
||||
hike (1.2.1)
|
||||
httpauth (0.2.0)
|
||||
i18n (0.6.1)
|
||||
json (1.7.6)
|
||||
jwt (0.1.5)
|
||||
multi_json (>= 1.0)
|
||||
linecache (0.46)
|
||||
rbx-require-relative (> 0.0.4)
|
||||
mail (2.3.3)
|
||||
i18n (>= 0.4.0)
|
||||
mime-types (~> 1.16)
|
||||
treetop (~> 1.4.8)
|
||||
metaclass (0.0.1)
|
||||
mime-types (1.19)
|
||||
mocha (0.10.0)
|
||||
metaclass (~> 0.0.1)
|
||||
mongoid (3.0.16)
|
||||
activemodel (~> 3.1)
|
||||
moped (~> 1.1)
|
||||
origin (~> 1.0)
|
||||
tzinfo (~> 0.3.22)
|
||||
moped (1.3.2)
|
||||
multi_json (1.2.0)
|
||||
multipart-post (1.1.5)
|
||||
nokogiri (1.5.6)
|
||||
oauth2 (0.8.0)
|
||||
faraday (~> 0.8)
|
||||
httpauth (~> 0.1)
|
||||
jwt (~> 0.1.4)
|
||||
multi_json (~> 1.0)
|
||||
rack (~> 1.2)
|
||||
omniauth (1.0.3)
|
||||
hashie (~> 1.2)
|
||||
rack
|
||||
omniauth-facebook (1.4.0)
|
||||
omniauth-oauth2 (~> 1.0.2)
|
||||
omniauth-oauth2 (1.0.3)
|
||||
oauth2 (~> 0.8.0)
|
||||
omniauth (~> 1.0)
|
||||
omniauth-openid (1.0.1)
|
||||
omniauth (~> 1.0)
|
||||
rack-openid (~> 1.3.1)
|
||||
origin (1.0.11)
|
||||
orm_adapter (0.4.0)
|
||||
polyglot (0.3.3)
|
||||
rack (1.3.8)
|
||||
rack-cache (1.2)
|
||||
rack (>= 0.4)
|
||||
rack-mount (0.8.3)
|
||||
rack (>= 1.0.0)
|
||||
rack-openid (1.3.1)
|
||||
rack (>= 1.1.0)
|
||||
ruby-openid (>= 2.1.8)
|
||||
rack-ssl (1.3.2)
|
||||
rack
|
||||
rack-test (0.6.2)
|
||||
rack (>= 1.0)
|
||||
rails (3.1.10)
|
||||
actionmailer (= 3.1.10)
|
||||
actionpack (= 3.1.10)
|
||||
activerecord (= 3.1.10)
|
||||
activeresource (= 3.1.10)
|
||||
activesupport (= 3.1.10)
|
||||
bundler (~> 1.0)
|
||||
railties (= 3.1.10)
|
||||
railties (3.1.10)
|
||||
actionpack (= 3.1.10)
|
||||
activesupport (= 3.1.10)
|
||||
rack-ssl (~> 1.3.2)
|
||||
rake (>= 0.8.7)
|
||||
rdoc (~> 3.4)
|
||||
thor (~> 0.14.6)
|
||||
rake (10.0.3)
|
||||
rbx-require-relative (0.0.9)
|
||||
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.2.2)
|
||||
sprockets (2.0.4)
|
||||
hike (~> 1.2)
|
||||
rack (~> 1.0)
|
||||
tilt (~> 1.1, != 1.3.0)
|
||||
sqlite3 (1.3.6)
|
||||
thor (0.14.6)
|
||||
tilt (1.3.3)
|
||||
treetop (1.4.12)
|
||||
polyglot
|
||||
polyglot (>= 0.3.1)
|
||||
tzinfo (0.3.35)
|
||||
warden (1.2.1)
|
||||
rack (>= 1.0)
|
||||
webrat (0.7.2)
|
||||
nokogiri (>= 1.2.0)
|
||||
rack (>= 1.0)
|
||||
rack-test (>= 0.5.3)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
activerecord-jdbc-adapter
|
||||
activerecord-jdbcsqlite3-adapter
|
||||
devise!
|
||||
jruby-openssl
|
||||
mocha (= 0.10.0)
|
||||
mongoid (~> 3.0)
|
||||
omniauth (~> 1.0.0)
|
||||
omniauth-facebook
|
||||
omniauth-oauth2 (~> 1.0.0)
|
||||
omniauth-openid (~> 1.0.1)
|
||||
rails (~> 3.1.0)
|
||||
rdoc
|
||||
ruby-debug (>= 0.10.3)
|
||||
sqlite3
|
||||
webrat (= 0.7.2)
|
||||
530
lib/devise.rb
530
lib/devise.rb
@@ -1,130 +1,169 @@
|
||||
require 'rails'
|
||||
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 :Models, 'devise/models'
|
||||
autoload :Schema, 'devise/schema'
|
||||
autoload :TestHelpers, 'devise/test_helpers'
|
||||
autoload :Delegator, 'devise/delegator'
|
||||
autoload :FailureApp, 'devise/failure_app'
|
||||
autoload :OmniAuth, 'devise/omniauth'
|
||||
autoload :ParamFilter, 'devise/param_filter'
|
||||
autoload :TestHelpers, 'devise/test_helpers'
|
||||
autoload :TimeInflector, 'devise/time_inflector'
|
||||
|
||||
module Controllers
|
||||
autoload :Helpers, 'devise/controllers/helpers'
|
||||
autoload :InternalHelpers, 'devise/controllers/internal_helpers'
|
||||
autoload :Rememberable, 'devise/controllers/rememberable'
|
||||
autoload :ScopedViews, 'devise/controllers/scoped_views'
|
||||
autoload :UrlHelpers, 'devise/controllers/url_helpers'
|
||||
end
|
||||
|
||||
module Encryptors
|
||||
autoload :Base, 'devise/encryptors/base'
|
||||
autoload :Bcrypt, 'devise/encryptors/bcrypt'
|
||||
autoload :AuthlogicSha512, 'devise/encryptors/authlogic_sha512'
|
||||
autoload :ClearanceSha1, 'devise/encryptors/clearance_sha1'
|
||||
autoload :RestfulAuthenticationSha1, 'devise/encryptors/restful_authentication_sha1'
|
||||
autoload :Sha512, 'devise/encryptors/sha512'
|
||||
autoload :Sha1, 'devise/encryptors/sha1'
|
||||
module Mailers
|
||||
autoload :Helpers, 'devise/mailers/helpers'
|
||||
end
|
||||
|
||||
ALL = []
|
||||
module Strategies
|
||||
autoload :Base, 'devise/strategies/base'
|
||||
autoload :Authenticatable, 'devise/strategies/authenticatable'
|
||||
end
|
||||
|
||||
# Authentication ones first
|
||||
ALL.push :authenticatable, :http_authenticatable, :token_authenticatable, :rememberable
|
||||
# Constants which holds devise configuration for extensions. Those should
|
||||
# not be modified by the "end user" (this is why they are constants).
|
||||
ALL = []
|
||||
CONTROLLERS = ActiveSupport::OrderedHash.new
|
||||
ROUTES = ActiveSupport::OrderedHash.new
|
||||
STRATEGIES = ActiveSupport::OrderedHash.new
|
||||
URL_HELPERS = ActiveSupport::OrderedHash.new
|
||||
|
||||
# Misc after
|
||||
ALL.push :recoverable, :registerable, :validatable
|
||||
|
||||
# The ones which can sign out after
|
||||
ALL.push :activatable, :confirmable, :lockable, :timeoutable
|
||||
|
||||
# Stats for last, so we make sure the user is really signed in
|
||||
ALL.push :trackable
|
||||
|
||||
# Maps controller names to devise modules.
|
||||
CONTROLLERS = {
|
||||
:sessions => [:authenticatable, :token_authenticatable],
|
||||
:passwords => [:recoverable],
|
||||
:confirmations => [:confirmable],
|
||||
:registrations => [:registerable],
|
||||
:unlocks => [:lockable]
|
||||
}
|
||||
|
||||
# Routes for generating url helpers.
|
||||
ROUTES = [:session, :password, :confirmation, :registration, :unlock]
|
||||
|
||||
STRATEGIES = [:rememberable, :http_authenticatable, :token_authenticatable, :authenticatable]
|
||||
# Strategies that do not require user input.
|
||||
NO_INPUT = []
|
||||
|
||||
# True values used to check params
|
||||
TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE']
|
||||
|
||||
# Maps the messages types that are used in flash message.
|
||||
FLASH_MESSAGES = [:unauthenticated, :unconfirmed, :invalid, :invalid_token, :timeout, :inactive, :locked]
|
||||
|
||||
# Declare encryptors length which are used in migrations.
|
||||
ENCRYPTORS_LENGTH = {
|
||||
:sha1 => 40,
|
||||
:sha512 => 128,
|
||||
:clearance_sha1 => 40,
|
||||
:restful_authentication_sha1 => 40,
|
||||
:authlogic_sha512 => 128,
|
||||
:bcrypt => 60
|
||||
}
|
||||
|
||||
# Email regex used to validate email formats. Adapted from authlogic.
|
||||
EMAIL_REGEX = /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i
|
||||
|
||||
# Used to encrypt password. Please generate one with rake secret.
|
||||
mattr_accessor :pepper
|
||||
@@pepper = nil
|
||||
# Custom domain or key for cookies. Not set by default
|
||||
mattr_accessor :rememberable_options
|
||||
@@rememberable_options = {}
|
||||
|
||||
# The number of times to encrypt password.
|
||||
mattr_accessor :stretches
|
||||
@@stretches = 10
|
||||
|
||||
# Keys used when authenticating an user.
|
||||
# Keys used when authenticating a user.
|
||||
mattr_accessor :authentication_keys
|
||||
@@authentication_keys = [ :email ]
|
||||
|
||||
# Time interval where the remember me token is valid.
|
||||
# Request keys used when authenticating a user.
|
||||
mattr_accessor :request_keys
|
||||
@@request_keys = []
|
||||
|
||||
# Keys that should be case-insensitive.
|
||||
mattr_accessor :case_insensitive_keys
|
||||
@@case_insensitive_keys = [ :email ]
|
||||
|
||||
# Keys that should have whitespace stripped.
|
||||
mattr_accessor :strip_whitespace_keys
|
||||
@@strip_whitespace_keys = []
|
||||
|
||||
# If http authentication is enabled by default.
|
||||
mattr_accessor :http_authenticatable
|
||||
@@http_authenticatable = false
|
||||
|
||||
# If http headers should be returned for ajax requests. True by default.
|
||||
mattr_accessor :http_authenticatable_on_xhr
|
||||
@@http_authenticatable_on_xhr = true
|
||||
|
||||
# If params authenticatable is enabled by default.
|
||||
mattr_accessor :params_authenticatable
|
||||
@@params_authenticatable = true
|
||||
|
||||
# The realm used in Http Basic Authentication.
|
||||
mattr_accessor :http_authentication_realm
|
||||
@@http_authentication_realm = "Application"
|
||||
|
||||
# Email regex used to validate email formats. It simply asserts that
|
||||
# an one (and only one) @ exists in the given string. This is mainly
|
||||
# to give user feedback and not to assert the e-mail validity.
|
||||
mattr_accessor :email_regexp
|
||||
@@email_regexp = /\A[^@\s]+@([^@\s]+\.)+[^@\s]+\z/
|
||||
|
||||
# Range validation for password length
|
||||
mattr_accessor :password_length
|
||||
@@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, extends the user's remember period when remembered via cookie.
|
||||
mattr_accessor :extend_remember_period
|
||||
@@extend_remember_period = false
|
||||
|
||||
# Time interval you can access your account before confirming your account.
|
||||
mattr_accessor :allow_unconfirmed_access_for
|
||||
@@allow_unconfirmed_access_for = 0.days
|
||||
|
||||
# Time interval the confirmation token is valid. nil = unlimited
|
||||
mattr_accessor :confirm_within
|
||||
@@confirm_within = 0.days
|
||||
@@confirm_within = nil
|
||||
|
||||
# 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
|
||||
|
||||
# Used to define the password encryption algorithm.
|
||||
mattr_accessor :encryptor
|
||||
@@encryptor = :sha1
|
||||
# Authentication token expiration on timeout
|
||||
mattr_accessor :expire_auth_token_on_timeout
|
||||
@@expire_auth_token_on_timeout = false
|
||||
|
||||
# Store scopes mappings.
|
||||
mattr_accessor :mappings
|
||||
@@mappings = ActiveSupport::OrderedHash.new
|
||||
|
||||
# Tells if devise should apply the schema in ORMs where devise declaration
|
||||
# and schema belongs to the same class (as Datamapper and MongoMapper).
|
||||
mattr_accessor :apply_schema
|
||||
@@apply_schema = true
|
||||
# Used to encrypt password. Please generate one with rake secret.
|
||||
mattr_accessor :pepper
|
||||
@@pepper = nil
|
||||
|
||||
# Scoped views. Since it relies on fallbacks to render default views, it's
|
||||
# turned off by default.
|
||||
mattr_accessor :scoped_views
|
||||
@@scoped_views = false
|
||||
|
||||
# Number of authentication tries before locking an account
|
||||
mattr_accessor :maximum_attempts
|
||||
@@maximum_attempts = 20
|
||||
# Defines which strategy can be used to lock an account.
|
||||
# Values: :failed_attempts, :none
|
||||
mattr_accessor :lock_strategy
|
||||
@@lock_strategy = :failed_attempts
|
||||
|
||||
# Defines which key will be used when locking and unlocking an account
|
||||
mattr_accessor :unlock_keys
|
||||
@@unlock_keys = [ :email ]
|
||||
|
||||
# Defines which strategy can be used to unlock an account.
|
||||
# Values: :email, :time, :both
|
||||
mattr_accessor :unlock_strategy
|
||||
@@unlock_strategy = :both
|
||||
|
||||
# Number of authentication tries before locking an account
|
||||
mattr_accessor :maximum_attempts
|
||||
@@maximum_attempts = 20
|
||||
|
||||
# Time interval to unlock the account if :time is defined as unlock_strategy.
|
||||
mattr_accessor :unlock_in
|
||||
@@unlock_in = 1.hour
|
||||
|
||||
# Tell when to use the default scope, if one cannot be found from routes.
|
||||
mattr_accessor :use_default_scope
|
||||
@@use_default_scope = false
|
||||
# Defines which key will be used when recovering the password for an account
|
||||
mattr_accessor :reset_password_keys
|
||||
@@reset_password_keys = [ :email ]
|
||||
|
||||
# Time interval you can reset your password with a reset password key
|
||||
mattr_accessor :reset_password_within
|
||||
@@reset_password_within = 6.hours
|
||||
|
||||
# The default scope which is used by warden.
|
||||
mattr_accessor :default_scope
|
||||
@@ -138,105 +177,274 @@ module Devise
|
||||
mattr_accessor :token_authentication_key
|
||||
@@token_authentication_key = :auth_token
|
||||
|
||||
# The realm used in Http Basic Authentication
|
||||
mattr_accessor :http_authentication_realm
|
||||
@@http_authentication_realm = "Application"
|
||||
# Skip session storage for the following strategies
|
||||
mattr_accessor :skip_session_storage
|
||||
@@skip_session_storage = []
|
||||
|
||||
class << self
|
||||
# Default way to setup Devise. Run script/generate devise_install to create
|
||||
# a fresh initializer with all configuration values.
|
||||
def setup
|
||||
yield self
|
||||
# Which formats should be treated as navigational.
|
||||
mattr_accessor :navigational_formats
|
||||
@@navigational_formats = ["*/*", :html]
|
||||
|
||||
# When set to true, signing out a user signs out all other scopes.
|
||||
mattr_accessor :sign_out_all_scopes
|
||||
@@sign_out_all_scopes = true
|
||||
|
||||
# The default method used while signing out
|
||||
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 parent mailer all Devise mailers inherit from.
|
||||
# Defaults to ActionMailer::Base. This should be set early
|
||||
# in the initialization process and should be set to a string.
|
||||
mattr_accessor :parent_mailer
|
||||
@@parent_mailer = "ActionMailer::Base"
|
||||
|
||||
# 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
|
||||
|
||||
# Set the omniauth path prefix so it can be overriden when
|
||||
# Devise is used in a mountable engine
|
||||
mattr_accessor :omniauth_path_prefix
|
||||
@@omniauth_path_prefix = nil
|
||||
|
||||
def self.encryptor=(value)
|
||||
warn "\n[DEVISE] To select a encryption which isn't bcrypt, you should use devise-encryptable gem.\n"
|
||||
end
|
||||
|
||||
def self.use_salt_as_remember_token=(value)
|
||||
warn "\n[DEVISE] Devise.use_salt_as_remember_token is deprecated and has no effect. Please remove it.\n"
|
||||
end
|
||||
|
||||
def self.apply_schema=(value)
|
||||
warn "\n[DEVISE] Devise.apply_schema is deprecated and has no effect. Please remove it.\n"
|
||||
end
|
||||
|
||||
# PRIVATE CONFIGURATION
|
||||
|
||||
# Store scopes mappings.
|
||||
mattr_reader :mappings
|
||||
@@mappings = ActiveSupport::OrderedHash.new
|
||||
|
||||
# Omniauth configurations.
|
||||
mattr_reader :omniauth_configs
|
||||
@@omniauth_configs = ActiveSupport::OrderedHash.new
|
||||
|
||||
# Define a set of modules that are called when a mapping is added.
|
||||
mattr_reader :helpers
|
||||
@@helpers = Set.new
|
||||
@@helpers << Devise::Controllers::Helpers
|
||||
|
||||
# Private methods to interface with Warden.
|
||||
mattr_accessor :warden_config
|
||||
@@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
|
||||
|
||||
# TODO Remove me on 1.1.0 final
|
||||
def orm=(value)
|
||||
ActiveSupport::Deprecation.warn "Devise.orm= and config.orm= are deprecated. " <<
|
||||
"Just load \"devise/orm/\#{ORM_NAME}\" if Devise supports your ORM"
|
||||
def get
|
||||
ActiveSupport::Dependencies.constantize(@name)
|
||||
end
|
||||
end
|
||||
|
||||
def self.ref(arg)
|
||||
if defined?(ActiveSupport::Dependencies::ClassCache)
|
||||
ActiveSupport::Dependencies::reference(arg)
|
||||
Getter.new(arg)
|
||||
else
|
||||
ActiveSupport::Dependencies.ref(arg)
|
||||
end
|
||||
end
|
||||
|
||||
def self.available_router_name
|
||||
router_name || :main_app
|
||||
end
|
||||
|
||||
def self.omniauth_providers
|
||||
omniauth_configs.keys
|
||||
end
|
||||
|
||||
# Get the mailer class from the mailer reference object.
|
||||
def self.mailer
|
||||
@@mailer_ref.get
|
||||
end
|
||||
|
||||
# Set the mailer reference object to access the mailer.
|
||||
def self.mailer=(class_name)
|
||||
@@mailer_ref = ref(class_name)
|
||||
end
|
||||
self.mailer = "Devise::Mailer"
|
||||
|
||||
# Small method that adds a mapping to Devise.
|
||||
def self.add_mapping(resource, options)
|
||||
mapping = Devise::Mapping.new(resource, options)
|
||||
@@mappings[mapping.name] = mapping
|
||||
@@default_scope ||= mapping.name
|
||||
@@helpers.each { |h| h.define_helpers(mapping) }
|
||||
mapping
|
||||
end
|
||||
|
||||
# Make Devise aware of an 3rd party Devise-module (like invitable). For convenience.
|
||||
#
|
||||
# == Options:
|
||||
#
|
||||
# +model+ - String representing the load path to a custom *model* for this module (to autoload.)
|
||||
# +controller+ - Symbol representing the name of an exisiting or custom *controller* for this module.
|
||||
# +route+ - Symbol representing the named *route* helper for this module.
|
||||
# +strategy+ - Symbol representing if this module got a custom *strategy*.
|
||||
#
|
||||
# All values, except :model, accept also a boolean and will have the same name as the given module
|
||||
# name.
|
||||
#
|
||||
# == Examples:
|
||||
#
|
||||
# Devise.add_module(:party_module)
|
||||
# Devise.add_module(:party_module, :strategy => true, :controller => :sessions)
|
||||
# Devise.add_module(:party_module, :model => 'party_module/model')
|
||||
#
|
||||
def self.add_module(module_name, options = {})
|
||||
ALL << module_name
|
||||
options.assert_valid_keys(:strategy, :model, :controller, :route, :no_input)
|
||||
|
||||
if strategy = options[:strategy]
|
||||
strategy = (strategy == true ? module_name : strategy)
|
||||
STRATEGIES[module_name] = strategy
|
||||
end
|
||||
|
||||
# TODO Remove me on 1.1.0 final
|
||||
def default_url_options
|
||||
ActiveSupport::Deprecation.warn "Devise.default_url_options and config.default_url_options are deprecated. " <<
|
||||
"Just modify ApplicationController.default_url_options and Devise will automatically pick it up"
|
||||
if controller = options[:controller]
|
||||
controller = (controller == true ? module_name : controller)
|
||||
CONTROLLERS[module_name] = controller
|
||||
end
|
||||
|
||||
# Sets warden configuration using a block that will be invoked on warden
|
||||
# initialization.
|
||||
#
|
||||
# Devise.initialize do |config|
|
||||
# config.confirm_within = 2.days
|
||||
#
|
||||
# config.warden do |manager|
|
||||
# # Configure warden to use other strategies, like oauth.
|
||||
# manager.oauth(:twitter)
|
||||
# end
|
||||
# end
|
||||
def warden(&block)
|
||||
@warden_config = block
|
||||
end
|
||||
NO_INPUT << strategy if options[:no_input]
|
||||
|
||||
# A method used internally to setup warden manager from the Rails initialize
|
||||
# block.
|
||||
def configure_warden(config) #:nodoc:
|
||||
config.default_strategies *Devise::STRATEGIES
|
||||
config.failure_app = Devise::FailureApp
|
||||
config.silence_missing_strategies!
|
||||
config.default_scope = Devise.default_scope
|
||||
|
||||
# If the user provided a warden hook, call it now.
|
||||
@warden_config.try :call, config
|
||||
end
|
||||
|
||||
# Generate a friendly string randomically to be used as token.
|
||||
def friendly_token
|
||||
ActiveSupport::SecureRandom.base64(15).tr('+/=', '-_ ').strip.delete("\n")
|
||||
end
|
||||
|
||||
# Make Devise aware of an 3rd party Devise-module. For convenience.
|
||||
#
|
||||
# == Options:
|
||||
#
|
||||
# +strategy+ - Boolean value representing if this module got a custom *strategy*.
|
||||
# Default is +false+. Note: Devise will auto-detect this in such case if this is true.
|
||||
# +model+ - String representing a load path to a custom *model* for this module (to autoload).
|
||||
# Default is +nil+ (i.e. +false+).
|
||||
# +controller+ - Symbol representing a name of an exisiting or custom *controller* for this module.
|
||||
# Default is +nil+ (i.e. +false+).
|
||||
#
|
||||
# == Examples:
|
||||
#
|
||||
# Devise.add_module(:party_module)
|
||||
# Devise.add_module(:party_module, :strategy => true, :controller => :sessions)
|
||||
# Devise.add_module(:party_module, :model => 'party_module/model')
|
||||
#
|
||||
def add_module(module_name, options = {})
|
||||
Devise::ALL.unshift module_name unless Devise::ALL.include?(module_name)
|
||||
Devise::STRATEGIES.unshift module_name if options[:strategy] && !Devise::STRATEGIES.include?(module_name)
|
||||
|
||||
if options[:controller]
|
||||
controller = options[:controller].to_sym
|
||||
Devise::CONTROLLERS[controller] ||= []
|
||||
Devise::CONTROLLERS[controller].unshift module_name unless Devise::CONTROLLERS[controller].include?(module_name)
|
||||
if route = options[:route]
|
||||
case route
|
||||
when TrueClass
|
||||
key, value = module_name, []
|
||||
when Symbol
|
||||
key, value = route, []
|
||||
when Hash
|
||||
key, value = route.keys.first, route.values.flatten
|
||||
else
|
||||
raise ArgumentError, ":route should be true, a Symbol or a Hash"
|
||||
end
|
||||
|
||||
if options[:model]
|
||||
Devise::Models.module_eval do
|
||||
autoload :"#{module_name.to_s.classify}", options[:model]
|
||||
end
|
||||
URL_HELPERS[key] ||= []
|
||||
URL_HELPERS[key].concat(value)
|
||||
URL_HELPERS[key].uniq!
|
||||
|
||||
ROUTES[module_name] = key
|
||||
end
|
||||
|
||||
if options[:model]
|
||||
path = (options[:model] == true ? "devise/models/#{module_name}" : options[:model])
|
||||
camelized = ActiveSupport::Inflector.camelize(module_name.to_s)
|
||||
Devise::Models.send(:autoload, camelized.to_sym, path)
|
||||
end
|
||||
|
||||
Devise::Mapping.add_module module_name
|
||||
end
|
||||
|
||||
# Sets warden configuration using a block that will be invoked on warden
|
||||
# initialization.
|
||||
#
|
||||
# Devise.initialize do |config|
|
||||
# config.allow_unconfirmed_access_for = 2.days
|
||||
#
|
||||
# config.warden do |manager|
|
||||
# # Configure warden to use other strategies, like oauth.
|
||||
# manager.oauth(:twitter)
|
||||
# end
|
||||
# end
|
||||
def self.warden(&block)
|
||||
@@warden_config_block = block
|
||||
end
|
||||
|
||||
# Specify an omniauth provider.
|
||||
#
|
||||
# config.omniauth :github, APP_ID, APP_SECRET
|
||||
#
|
||||
def self.omniauth(provider, *args)
|
||||
@@helpers << Devise::OmniAuth::UrlHelpers
|
||||
config = Devise::OmniAuth::Config.new(provider, args)
|
||||
@@omniauth_configs[config.strategy_name.to_sym] = config
|
||||
end
|
||||
|
||||
# Include helpers in the given scope to AC and AV.
|
||||
def self.include_helpers(scope)
|
||||
ActiveSupport.on_load(:action_controller) do
|
||||
include scope::Helpers if defined?(scope::Helpers)
|
||||
include scope::UrlHelpers
|
||||
end
|
||||
|
||||
ActiveSupport.on_load(:action_view) do
|
||||
include scope::UrlHelpers
|
||||
end
|
||||
end
|
||||
|
||||
# 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::Delegator.new
|
||||
warden_config.default_scope = Devise.default_scope
|
||||
warden_config.intercept_401 = false
|
||||
|
||||
Devise.mappings.each_value do |mapping|
|
||||
warden_config.scope_defaults mapping.name, :strategies => mapping.strategies
|
||||
end
|
||||
|
||||
Devise::Mapping.register module_name
|
||||
@@warden_config_block.try :call, Devise.warden_config
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
# Generate a friendly string randomically to be used as token.
|
||||
def self.friendly_token
|
||||
SecureRandom.base64(15).tr('+/=lIO0', 'pqrsxyz')
|
||||
end
|
||||
|
||||
# constant-time comparison algorithm to prevent timing attacks
|
||||
def self.secure_compare(a, b)
|
||||
return false if a.blank? || b.blank? || a.bytesize != b.bytesize
|
||||
l = a.unpack "C#{a.bytesize}"
|
||||
|
||||
res = 0
|
||||
b.each_byte { |byte| res |= byte ^ l.shift }
|
||||
res == 0
|
||||
end
|
||||
end
|
||||
|
||||
begin
|
||||
require 'warden'
|
||||
rescue
|
||||
gem 'warden'
|
||||
require 'warden'
|
||||
end
|
||||
|
||||
require 'warden'
|
||||
require 'devise/mapping'
|
||||
require 'devise/models'
|
||||
require 'devise/modules'
|
||||
require 'devise/rails'
|
||||
|
||||
@@ -5,143 +5,14 @@ module Devise
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
helper_method :warden, :signed_in?, :devise_controller?,
|
||||
*Devise.mappings.keys.map { |m| [:"current_#{m}", :"#{m}_signed_in?"] }.flatten
|
||||
helper_method :warden, :signed_in?, :devise_controller?
|
||||
end
|
||||
|
||||
# The main accessor for the warden proxy instance
|
||||
def warden
|
||||
request.env['warden']
|
||||
end
|
||||
|
||||
# Return true if it's a devise_controller. false to all controllers unless
|
||||
# the controllers defined inside devise. Useful if you want to apply a before
|
||||
# filter to all controller, except the ones in devise:
|
||||
#
|
||||
# before_filter :my_filter, :unless => { |c| c.devise_controller? }
|
||||
def devise_controller?
|
||||
false
|
||||
end
|
||||
|
||||
# Attempts to authenticate the given scope by running authentication hooks,
|
||||
# but does not redirect in case of failures.
|
||||
def authenticate(scope)
|
||||
warden.authenticate(:scope => scope)
|
||||
end
|
||||
|
||||
# Attempts to authenticate the given scope by running authentication hooks,
|
||||
# redirecting in case of failures.
|
||||
def authenticate!(scope)
|
||||
warden.authenticate!(:scope => scope)
|
||||
end
|
||||
|
||||
# Check if the given scope is signed in session, without running
|
||||
# authentication hooks.
|
||||
def signed_in?(scope)
|
||||
warden.authenticate?(:scope => scope)
|
||||
end
|
||||
|
||||
# Sign in an user that already was authenticated. This helper is useful for logging
|
||||
# users in after sign up.
|
||||
#
|
||||
# Examples:
|
||||
#
|
||||
# sign_in :user, @user # sign_in(scope, resource)
|
||||
# sign_in @user # sign_in(resource)
|
||||
#
|
||||
def sign_in(resource_or_scope, resource=nil)
|
||||
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
||||
resource ||= resource_or_scope
|
||||
warden.set_user(resource, :scope => scope)
|
||||
end
|
||||
|
||||
# Sign out a given user or scope. This helper is useful for signing out an user
|
||||
# after deleting accounts.
|
||||
#
|
||||
# Examples:
|
||||
#
|
||||
# sign_out :user # sign_out(scope)
|
||||
# sign_out @user # sign_out(resource)
|
||||
#
|
||||
def sign_out(resource_or_scope)
|
||||
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
||||
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)
|
||||
end
|
||||
|
||||
# Returns and delete the url stored in the session for the given scope. Useful
|
||||
# for giving redirect backs after sign up:
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# redirect_to stored_location_for(:user) || root_path
|
||||
#
|
||||
def stored_location_for(resource_or_scope)
|
||||
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
||||
session.delete(:"#{scope}.return_to")
|
||||
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
|
||||
# the following way:
|
||||
#
|
||||
# map.user_root '/users', :controller => 'users' # creates user_root_path
|
||||
#
|
||||
# map.resources :users do |users|
|
||||
# users.root # creates user_root_path
|
||||
# end
|
||||
#
|
||||
#
|
||||
# If none of these are 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
|
||||
# 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
|
||||
end
|
||||
|
||||
# Method used by sessions controller to sign out an user. You can overwrite
|
||||
# it in your ApplicationController to provide a custom hook for a custom
|
||||
# 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.
|
||||
def after_sign_out_path_for(resource_or_scope)
|
||||
root_path
|
||||
end
|
||||
|
||||
# Sign in an user and tries to redirect first to the stored location and
|
||||
# then to the url specified by after_sign_in_path_for.
|
||||
#
|
||||
# If just a symbol is given, consider that the user was already signed in
|
||||
# through other means and just perform the redirection.
|
||||
def sign_in_and_redirect(resource_or_scope, resource=nil, skip=false)
|
||||
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
||||
resource ||= resource_or_scope
|
||||
sign_in(scope, resource) unless skip
|
||||
redirect_to stored_location_for(scope) || after_sign_in_path_for(resource)
|
||||
end
|
||||
|
||||
# Sign out an 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)
|
||||
sign_out(scope)
|
||||
redirect_to after_sign_out_path_for(scope)
|
||||
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.
|
||||
@@ -150,17 +21,17 @@ module Devise
|
||||
# access that specific controller/action.
|
||||
# Example:
|
||||
#
|
||||
# Maps:
|
||||
# User => :authenticatable
|
||||
# Admin => :authenticatable
|
||||
# Roles:
|
||||
# User
|
||||
# Admin
|
||||
#
|
||||
# Generated methods:
|
||||
# authenticate_user! # Signs user in or redirect
|
||||
# authenticate_admin! # Signs admin in or redirect
|
||||
# user_signed_in? # Checks whether there is an user signed in or not
|
||||
# user_signed_in? # Checks whether there is a user signed in or not
|
||||
# admin_signed_in? # Checks whether there is an admin signed in or not
|
||||
# current_user # Current signed in user
|
||||
# current_admin # Currend signed in admin
|
||||
# current_admin # Current signed in admin
|
||||
# user_session # Session data available only to the user scope
|
||||
# admin_session # Session data available only to the admin scope
|
||||
#
|
||||
@@ -168,14 +39,17 @@ module Devise
|
||||
# before_filter :authenticate_user! # Tell devise to use :user map
|
||||
# before_filter :authenticate_admin! # Tell devise to use :admin map
|
||||
#
|
||||
Devise.mappings.each_key do |mapping|
|
||||
def self.define_helpers(mapping) #:nodoc:
|
||||
mapping = mapping.name
|
||||
|
||||
class_eval <<-METHODS, __FILE__, __LINE__ + 1
|
||||
def authenticate_#{mapping}!
|
||||
warden.authenticate!(:scope => :#{mapping})
|
||||
def authenticate_#{mapping}!(opts={})
|
||||
opts[:scope] = :#{mapping}
|
||||
warden.authenticate!(opts) if !devise_controller? || opts.delete(:force)
|
||||
end
|
||||
|
||||
def #{mapping}_signed_in?
|
||||
warden.authenticate?(:scope => :#{mapping})
|
||||
!!current_#{mapping}
|
||||
end
|
||||
|
||||
def current_#{mapping}
|
||||
@@ -186,8 +60,226 @@ module Devise
|
||||
current_#{mapping} && warden.session(:#{mapping})
|
||||
end
|
||||
METHODS
|
||||
|
||||
ActiveSupport.on_load(:action_controller) do
|
||||
helper_method "current_#{mapping}", "#{mapping}_signed_in?", "#{mapping}_session"
|
||||
end
|
||||
end
|
||||
|
||||
# The main accessor for the warden proxy instance
|
||||
def warden
|
||||
request.env['warden']
|
||||
end
|
||||
|
||||
# Return true if it's a devise_controller. false to all controllers unless
|
||||
# the controllers defined inside devise. Useful if you want to apply a before
|
||||
# filter to all controllers, except the ones in devise:
|
||||
#
|
||||
# before_filter :my_filter, :unless => :devise_controller?
|
||||
def devise_controller?
|
||||
is_a?(DeviseController)
|
||||
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|
|
||||
warden.authenticate?(:scope => _scope)
|
||||
end
|
||||
end
|
||||
|
||||
# Sign in a user that already was authenticated. This helper is useful for logging
|
||||
# users in after sign up.
|
||||
#
|
||||
# All options given to sign_in is passed forward to the set_user method in warden.
|
||||
# The only exception is the :bypass option, which bypass warden callbacks and stores
|
||||
# the user straight in session. This option is useful in cases the user is already
|
||||
# signed in, but we want to refresh the credentials in session.
|
||||
#
|
||||
# Examples:
|
||||
#
|
||||
# sign_in :user, @user # sign_in(scope, resource)
|
||||
# sign_in @user # sign_in(resource)
|
||||
# sign_in @user, :event => :authentication # sign_in(resource, options)
|
||||
# sign_in @user, :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)
|
||||
resource = args.last || resource_or_scope
|
||||
|
||||
expire_session_data_after_sign_in!
|
||||
|
||||
if options[:bypass]
|
||||
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
|
||||
end
|
||||
|
||||
# Sign out a given user or scope. This helper is useful for signing out a user
|
||||
# after deleting accounts. Returns true if there was a logout and false if there
|
||||
# is no user logged in on the referred scope
|
||||
#
|
||||
# Examples:
|
||||
#
|
||||
# sign_out :user # sign_out(scope)
|
||||
# sign_out @user # sign_out(resource)
|
||||
#
|
||||
def sign_out(resource_or_scope=nil)
|
||||
return sign_out_all_scopes unless resource_or_scope
|
||||
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
||||
user = warden.user(:scope => scope, :run_callbacks => false) # If there is no user
|
||||
|
||||
warden.raw_session.inspect # Without this inspect here. The session does not clear.
|
||||
warden.logout(scope)
|
||||
warden.clear_strategies_cache!(:scope => scope)
|
||||
instance_variable_set(:"@current_#{scope}", nil)
|
||||
|
||||
!!user
|
||||
end
|
||||
|
||||
# Sign out all active users or scopes. This helper is useful for signing out all roles
|
||||
# in one click. This signs out ALL scopes in warden. Returns true if there was at least one logout
|
||||
# and false if there was no user logged in on all scopes.
|
||||
def sign_out_all_scopes(lock=true)
|
||||
users = Devise.mappings.keys.map { |s| warden.user(:scope => s, :run_callbacks => false) }
|
||||
|
||||
warden.raw_session.inspect
|
||||
warden.logout
|
||||
expire_devise_cached_variables!
|
||||
warden.clear_strategies_cache!
|
||||
warden.lock! if lock
|
||||
|
||||
users.any?
|
||||
end
|
||||
|
||||
# Returns and delete (if it's navigational format) the url stored in the session for
|
||||
# the given scope. Useful for giving redirect backs after sign up:
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# redirect_to stored_location_for(:user) || root_path
|
||||
#
|
||||
def stored_location_for(resource_or_scope)
|
||||
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
||||
|
||||
if is_navigational_format?
|
||||
session.delete("#{scope}_return_to")
|
||||
else
|
||||
session["#{scope}_return_to"]
|
||||
end
|
||||
end
|
||||
|
||||
# The scope root url to be used when he's signed in. By default, it first
|
||||
# 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 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
|
||||
#
|
||||
# map.namespace :user do |user|
|
||||
# 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)
|
||||
# stored_location_for(resource) ||
|
||||
# if resource.is_a?(User) && resource.can_publish?
|
||||
# publisher_url
|
||||
# else
|
||||
# super
|
||||
# end
|
||||
# end
|
||||
#
|
||||
def after_sign_in_path_for(resource_or_scope)
|
||||
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
|
||||
# it in your ApplicationController to provide a custom hook for a custom
|
||||
# scope. Notice that differently from +after_sign_in_path_for+ this method
|
||||
# receives a symbol with the scope, and not the resource.
|
||||
#
|
||||
# By default it is the root_path.
|
||||
def after_sign_out_path_for(resource_or_scope)
|
||||
respond_to?(:root_path) ? root_path : "/"
|
||||
end
|
||||
|
||||
# Sign in a user and tries to redirect first to the stored location and
|
||||
# then to the url specified by after_sign_in_path_for. It accepts the same
|
||||
# parameters as the sign_in method.
|
||||
def sign_in_and_redirect(resource_or_scope, *args)
|
||||
options = args.extract_options!
|
||||
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
||||
resource = args.last || resource_or_scope
|
||||
sign_in(scope, resource, options)
|
||||
redirect_to 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 redirect_path
|
||||
end
|
||||
|
||||
# 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(false)
|
||||
request.env["devise.skip_storage"] = true
|
||||
expire_devise_cached_variables!
|
||||
super # call the default behaviour which resets the session
|
||||
end
|
||||
|
||||
def request_format
|
||||
@request_format ||= request.format.try(:ref)
|
||||
end
|
||||
|
||||
def is_navigational_format?
|
||||
Devise.navigational_formats.include?(request_format)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def expire_devise_cached_variables!
|
||||
Devise.mappings.each { |_,m| instance_variable_set("@current_#{m.name}", nil) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,103 +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
|
||||
helpers = [:resource, :scope_name, :resource_name,
|
||||
:resource_class, :devise_mapping, :devise_controller?]
|
||||
|
||||
hide_action *helpers
|
||||
helper_method *helpers
|
||||
|
||||
before_filter :is_devise_resource?
|
||||
skip_before_filter *Devise.mappings.keys.map { |m| :"authenticate_#{m}!" }
|
||||
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
|
||||
|
||||
# Attempt to find the mapped route for devise based on request path
|
||||
def devise_mapping
|
||||
@devise_mapping ||= begin
|
||||
mapping = Devise::Mapping.find_by_path(request.path)
|
||||
mapping ||= Devise.mappings[Devise.default_scope] if Devise.use_default_scope
|
||||
mapping
|
||||
end
|
||||
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:
|
||||
raise ActionController::UnknownAction unless devise_mapping && devise_mapping.allows?(controller_name)
|
||||
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
|
||||
self.resource = resource_class.new(params[resource_name] || {})
|
||||
end
|
||||
|
||||
# Helper for use in before_filters where no authentication is required.
|
||||
#
|
||||
# Example:
|
||||
# before_filter :require_no_authentication, :only => :new
|
||||
def require_no_authentication
|
||||
redirect_to after_sign_in_path_for(resource_name) if warden.authenticated?(resource_name)
|
||||
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, now=false)
|
||||
flash_hash = now ? flash.now : flash
|
||||
flash_hash[key] = I18n.t(:"#{resource_name}.#{kind}",
|
||||
:scope => [:devise, controller_name.to_sym], :default => kind)
|
||||
end
|
||||
|
||||
# Shortcut to set flash.now message. Same rules applied from set_flash_message
|
||||
def set_now_flash_message(key, kind)
|
||||
set_flash_message(key, kind, true)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
56
lib/devise/controllers/rememberable.rb
Normal file
56
lib/devise/controllers/rememberable.rb
Normal file
@@ -0,0 +1,56 @@
|
||||
module Devise
|
||||
module Controllers
|
||||
# A module that may be optionally included in a controller in order
|
||||
# to provide remember me behavior.
|
||||
module Rememberable
|
||||
# Return default cookie values retrieved from session options.
|
||||
def self.cookie_values
|
||||
Rails.configuration.session_options.slice(:path, :domain, :secure)
|
||||
end
|
||||
|
||||
# A small warden proxy so we can remember and forget uses from hooks.
|
||||
class Proxy #:nodoc:
|
||||
include Devise::Controllers::Rememberable
|
||||
|
||||
delegate :cookies, :env, :to => :@warden
|
||||
|
||||
def initialize(warden)
|
||||
@warden = warden
|
||||
end
|
||||
end
|
||||
|
||||
# Remembers the given resource by setting up a cookie
|
||||
def remember_me(resource)
|
||||
scope = Devise::Mapping.find_scope!(resource)
|
||||
resource.remember_me!(resource.extend_remember_period)
|
||||
cookies.signed[remember_key(resource, scope)] = remember_cookie_values(resource)
|
||||
end
|
||||
|
||||
# Forgets the given resource by deleting a cookie
|
||||
def forget_me(resource)
|
||||
scope = Devise::Mapping.find_scope!(resource)
|
||||
resource.forget_me!
|
||||
cookies.delete(remember_key(resource, scope), forget_cookie_values(resource))
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def forget_cookie_values(resource)
|
||||
Devise::Controllers::Rememberable.cookie_values.merge!(resource.rememberable_options)
|
||||
end
|
||||
|
||||
def remember_cookie_values(resource)
|
||||
options = { :httponly => true }
|
||||
options.merge!(forget_cookie_values(resource))
|
||||
options.merge!(
|
||||
:value => resource.class.serialize_into_cookie(resource),
|
||||
:expires => resource.remember_expires_at
|
||||
)
|
||||
end
|
||||
|
||||
def remember_key(resource, scope)
|
||||
resource.rememberable_options.fetch(:key, "remember_#{scope}_token")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -4,7 +4,7 @@ module Devise
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
module ClassMethods
|
||||
def scoped_views
|
||||
def scoped_views?
|
||||
defined?(@scoped_views) ? @scoped_views : Devise.scoped_views
|
||||
end
|
||||
|
||||
@@ -12,24 +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, options={})
|
||||
controller_name = options.delete(:controller) || self.controller_name
|
||||
|
||||
if self.class.scoped_views
|
||||
begin
|
||||
render :template => "#{devise_mapping.as}/#{controller_name}/#{action}"
|
||||
rescue ActionView::MissingTemplate
|
||||
render :template => "#{controller_path}/#{action}"
|
||||
end
|
||||
else
|
||||
render :template => "#{controller_path}/#{action}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -16,26 +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::ROUTES.each do |module_name|
|
||||
[:path, :url].each do |path_or_url|
|
||||
actions = [ nil, :new_ ]
|
||||
actions << :edit_ if [:password, :registration].include?(module_name)
|
||||
actions << :destroy_ if [:session].include?(module_name)
|
||||
def self.generate_helpers!(routes=nil)
|
||||
routes ||= begin
|
||||
mappings = Devise.mappings.values.map(&:used_helpers).flatten.uniq
|
||||
Devise::URL_HELPERS.slice(*mappings)
|
||||
end
|
||||
|
||||
actions.each do |action|
|
||||
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.available_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
|
||||
@@ -1,21 +0,0 @@
|
||||
require "digest/sha2"
|
||||
|
||||
module Devise
|
||||
module Encryptors
|
||||
# = AuthlogicSha512
|
||||
# Simulates Authlogic's default encryption mechanism.
|
||||
# Warning: it uses Devise's stretches configuration to port Authlogic's one. Should be set to 20 in the initializer to silumate
|
||||
# the default behavior.
|
||||
class AuthlogicSha512 < Base
|
||||
|
||||
# Gererates a default password digest based on salt, pepper and the
|
||||
# incoming password.
|
||||
def self.digest(password, stretches, salt, pepper)
|
||||
digest = [password, salt].flatten.join('')
|
||||
stretches.times { digest = Digest::SHA512.hexdigest(digest) }
|
||||
digest
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,20 +0,0 @@
|
||||
module Devise
|
||||
# Implements a way of adding different encryptions.
|
||||
# The class should implement a self.digest method that taks the following params:
|
||||
# - password
|
||||
# - stretches: the number of times the encryption will be applied
|
||||
# - salt: the password salt as defined by devise
|
||||
# - pepper: Devise config option
|
||||
#
|
||||
module Encryptors
|
||||
class Base
|
||||
def self.digest
|
||||
raise NotImplemented
|
||||
end
|
||||
|
||||
def self.salt
|
||||
Devise.friendly_token
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,21 +0,0 @@
|
||||
require "bcrypt"
|
||||
|
||||
module Devise
|
||||
module Encryptors
|
||||
# = BCrypt
|
||||
# Uses the BCrypt hash algorithm to encrypt passwords.
|
||||
class Bcrypt < Base
|
||||
|
||||
# Gererates a default password digest based on stretches, salt, pepper and the
|
||||
# incoming password. We don't strech it ourselves since BCrypt does so internally.
|
||||
def self.digest(password, stretches, salt, pepper)
|
||||
::BCrypt::Engine.hash_secret([password, pepper].join, salt, stretches)
|
||||
end
|
||||
|
||||
def self.salt
|
||||
::BCrypt::Engine.generate_salt
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,19 +0,0 @@
|
||||
require "digest/sha1"
|
||||
|
||||
module Devise
|
||||
module Encryptors
|
||||
# = ClearanceSha1
|
||||
# Simulates Clearance's default encryption mechanism.
|
||||
# Warning: it uses Devise's pepper to port the concept of REST_AUTH_SITE_KEY
|
||||
# Warning: it uses Devise's stretches configuration to port the concept of REST_AUTH_DIGEST_STRETCHES
|
||||
class ClearanceSha1 < Base
|
||||
|
||||
# Gererates a default password digest based on salt, pepper and the
|
||||
# incoming password.
|
||||
def self.digest(password, stretches, salt, pepper)
|
||||
Digest::SHA1.hexdigest("--#{salt}--#{password}--")
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,22 +0,0 @@
|
||||
require "digest/sha1"
|
||||
|
||||
module Devise
|
||||
module Encryptors
|
||||
# = RestfulAuthenticationSha1
|
||||
# Simulates Restful Authentication's default encryption mechanism.
|
||||
# Warning: it uses Devise's pepper to port the concept of REST_AUTH_SITE_KEY
|
||||
# Warning: it uses Devise's stretches configuration to port the concept of REST_AUTH_DIGEST_STRETCHES. Should be set to 10 in
|
||||
# the initializer to silumate the default behavior.
|
||||
class RestfulAuthenticationSha1 < Base
|
||||
|
||||
# Gererates a default password digest based on salt, pepper and the
|
||||
# incoming password.
|
||||
def self.digest(password, stretches, salt, pepper)
|
||||
digest = pepper
|
||||
stretches.times { digest = Digest::SHA1.hexdigest([digest, salt, password, pepper].flatten.join('--')) }
|
||||
digest
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,27 +0,0 @@
|
||||
require "digest/sha1"
|
||||
|
||||
module Devise
|
||||
module Encryptors
|
||||
# = Sha1
|
||||
# Uses the Sha1 hash algorithm to encrypt passwords.
|
||||
class Sha1 < Base
|
||||
|
||||
# Gererates a default password digest based on stretches, salt, pepper and the
|
||||
# incoming password.
|
||||
def self.digest(password, stretches, salt, pepper)
|
||||
digest = pepper
|
||||
stretches.times { digest = self.secure_digest(salt, digest, password, pepper) }
|
||||
digest
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Generate a SHA1 digest joining args. Generated token is something like
|
||||
# --arg1--arg2--arg3--argN--
|
||||
def self.secure_digest(*tokens)
|
||||
::Digest::SHA1.hexdigest('--' << tokens.flatten.join('--') << '--')
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,27 +0,0 @@
|
||||
require "digest/sha2"
|
||||
|
||||
module Devise
|
||||
module Encryptors
|
||||
# = Sha512
|
||||
# Uses the Sha512 hash algorithm to encrypt passwords.
|
||||
class Sha512 < Base
|
||||
|
||||
# Gererates a default password digest based on salt, pepper and the
|
||||
# incoming password.
|
||||
def self.digest(password, stretches, salt, pepper)
|
||||
digest = pepper
|
||||
stretches.times { digest = self.secure_digest(salt, digest, password, pepper) }
|
||||
digest
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Generate a Sha512 digest joining args. Generated token is something like
|
||||
# --arg1--arg2--arg3--argN--
|
||||
def self.secure_digest(*tokens)
|
||||
::Digest::SHA512.hexdigest('--' << tokens.flatten.join('--') << '--')
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -10,39 +10,144 @@ module Devise
|
||||
include ActionController::UrlFor
|
||||
include ActionController::Redirecting
|
||||
|
||||
mattr_accessor :default_message
|
||||
self.default_message = :unauthenticated
|
||||
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
|
||||
scope = warden_options[:scope]
|
||||
store_location!(scope)
|
||||
redirect_to send(:"new_#{scope}_session_path", query_string_params)
|
||||
if http_auth?
|
||||
http_auth
|
||||
elsif warden_options[:recall]
|
||||
recall
|
||||
else
|
||||
redirect
|
||||
end
|
||||
end
|
||||
|
||||
def http_auth
|
||||
self.status = 401
|
||||
self.headers["WWW-Authenticate"] = %(Basic realm=#{Devise.http_authentication_realm.inspect}) if http_auth_header?
|
||||
self.content_type = request.format.to_s
|
||||
self.response_body = http_auth_body
|
||||
end
|
||||
|
||||
def recall
|
||||
env["PATH_INFO"] = attempted_path
|
||||
flash.now[:alert] = i18n_message(:invalid)
|
||||
self.response = recall_app(warden_options[:recall]).call(env)
|
||||
end
|
||||
|
||||
def redirect
|
||||
store_location!
|
||||
if flash[:timedout] && flash[:alert]
|
||||
flash.keep(:timedout)
|
||||
flash.keep(:alert)
|
||||
else
|
||||
flash[:alert] = i18n_message
|
||||
end
|
||||
redirect_to redirect_url
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
# Build the proper query string based on the given message.
|
||||
def query_string_params
|
||||
message = warden.try(:message) || warden_options[:message] || self.class.default_message
|
||||
def i18n_message(default = nil)
|
||||
message = warden_message || default || :unauthenticated
|
||||
|
||||
case message
|
||||
when Symbol
|
||||
{ message => true }
|
||||
when String
|
||||
{ :message => message }
|
||||
if message.is_a?(Symbol)
|
||||
I18n.t(:"#{scope}.#{message}", :resource_name => scope,
|
||||
:scope => "devise.failure", :default => [message])
|
||||
else
|
||||
{}
|
||||
message.to_s
|
||||
end
|
||||
end
|
||||
|
||||
def redirect_url
|
||||
if warden_message == :timeout
|
||||
flash[:timedout] = true
|
||||
attempted_path || scope_path
|
||||
else
|
||||
scope_path
|
||||
end
|
||||
end
|
||||
|
||||
def scope_path
|
||||
opts = {}
|
||||
route = :"new_#{scope}_session_path"
|
||||
opts[:format] = request_format unless skip_format?
|
||||
|
||||
config = Rails.application.config
|
||||
opts[:script_name] = (config.relative_url_root if config.respond_to?(:relative_url_root))
|
||||
|
||||
context = send(Devise.available_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.
|
||||
#
|
||||
# This method allows the user to explicitly disable http authentication
|
||||
# on ajax requests in case they want to redirect on failures instead of
|
||||
# handling the errors on their own. This is useful in case your ajax API
|
||||
# is the same as your public API and uses a format like JSON (so you
|
||||
# cannot mark JSON as a navigational format).
|
||||
def http_auth?
|
||||
if request.xhr?
|
||||
Devise.http_authenticatable_on_xhr
|
||||
else
|
||||
!(request_format && is_navigational_format?)
|
||||
end
|
||||
end
|
||||
|
||||
# It does not make sense to send authenticate headers in ajax requests
|
||||
# or if the user disabled them.
|
||||
def http_auth_header?
|
||||
Devise.mappings[scope].to.http_authenticatable && !request.xhr?
|
||||
end
|
||||
|
||||
def http_auth_body
|
||||
return i18n_message unless request_format
|
||||
method = "to_#{request_format}"
|
||||
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_name = ActiveSupport::Inflector.camelize(controller)
|
||||
controller_klass = ActiveSupport::Inflector.constantize("#{controller_name}Controller")
|
||||
controller_klass.action(action)
|
||||
end
|
||||
|
||||
def warden
|
||||
env['warden']
|
||||
end
|
||||
@@ -51,12 +156,32 @@ 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
|
||||
|
||||
def attempted_path
|
||||
warden_options[:attempted_path]
|
||||
end
|
||||
|
||||
# Stores requested uri to redirect the user after signing in. We cannot use
|
||||
# scoped session provided by warden here, since the user is not authenticated
|
||||
# yet, but we still need to store the uri based on scope, so different scopes
|
||||
# would never use the same uri to redirect.
|
||||
def store_location!(scope)
|
||||
session[:"#{scope}.return_to"] = request.request_uri if request && request.get?
|
||||
def store_location!
|
||||
session["#{scope}_return_to"] = attempted_path if request.get? && !http_auth?
|
||||
end
|
||||
|
||||
def is_navigational_format?
|
||||
Devise.navigational_formats.include?(request_format)
|
||||
end
|
||||
|
||||
def request_format
|
||||
@request_format ||= request.format.try(:ref)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
# Deny user access whenever his account is not active yet.
|
||||
# Deny user access whenever his account is not active yet. All strategies that inherits from
|
||||
# Devise::Strategies::Authenticatable and uses the validate already check if the user is active_for_authentication?
|
||||
# before actively signing him in. However, we need this as hook to validate the user activity
|
||||
# in each request and in case the user is using other strategies beside Devise ones.
|
||||
Warden::Manager.after_set_user do |record, warden, options|
|
||||
if record && record.respond_to?(:active?) && !record.active?
|
||||
if record && record.respond_to?(:active_for_authentication?) && !record.active_for_authentication?
|
||||
scope = options[:scope]
|
||||
warden.logout(scope)
|
||||
|
||||
# If winning strategy was set, this is being called after authenticate and
|
||||
# there is no need to force a redirect.
|
||||
if warden.winning_strategy
|
||||
warden.winning_strategy.fail!(record.inactive_message)
|
||||
else
|
||||
throw :warden, :scope => scope, :message => record.inactive_message
|
||||
end
|
||||
throw :warden, :scope => scope, :message => record.inactive_message
|
||||
end
|
||||
end
|
||||
end
|
||||
9
lib/devise/hooks/forgetable.rb
Normal file
9
lib/devise/hooks/forgetable.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
# 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 not persisted.
|
||||
# This avoids forgetting deleted users.
|
||||
Warden::Manager.before_logout do |record, warden, options|
|
||||
if record.respond_to?(:forget_me!)
|
||||
Devise::Controllers::Rememberable::Proxy.new(warden).forget_me(record)
|
||||
end
|
||||
end
|
||||
7
lib/devise/hooks/lockable.rb
Normal file
7
lib/devise/hooks/lockable.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
# After each sign in, if resource responds to failed_attempts, sets it to 0
|
||||
# This is only triggered when the user is explicitly set (with set_user)
|
||||
Warden::Manager.after_set_user :except => :fetch do |record, warden, options|
|
||||
if record.respond_to?(:failed_attempts) && warden.authenticated?(options[:scope])
|
||||
record.update_attribute(:failed_attempts, 0)
|
||||
end
|
||||
end
|
||||
@@ -1,30 +1,6 @@
|
||||
# After authenticate hook to verify if the user in the given scope asked to be
|
||||
# remembered while he does not sign out. Generates a new remember token for
|
||||
# that specific user and adds a cookie with this user info to sign in this user
|
||||
# automatically without asking for credentials. Refer to rememberable strategy
|
||||
# for more info.
|
||||
Warden::Manager.prepend_after_authentication do |record, warden, options|
|
||||
Warden::Manager.after_set_user :except => :fetch do |record, warden, options|
|
||||
scope = options[:scope]
|
||||
remember_me = warden.params[scope].try(:fetch, :remember_me, nil)
|
||||
|
||||
if Devise::TRUE_VALUES.include?(remember_me) &&
|
||||
warden.authenticated?(scope) && record.respond_to?(:remember_me!)
|
||||
record.remember_me!
|
||||
|
||||
warden.response.set_cookie "remember_#{scope}_token", {
|
||||
:value => record.class.serialize_into_cookie(record),
|
||||
:expires => record.remember_expires_at,
|
||||
:path => "/"
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
# Before logout hook to forget the user in the given scope, only if rememberable
|
||||
# is activated for this scope. Also clear remember token to ensure the user
|
||||
# won't be remembered again.
|
||||
Warden::Manager.before_logout do |record, warden, scope|
|
||||
if record.respond_to?(:forget_me!)
|
||||
record.forget_me!
|
||||
warden.response.delete_cookie "remember_#{scope}_token"
|
||||
if record.respond_to?(:remember_me) && record.remember_me && warden.authenticated?(scope)
|
||||
Devise::Controllers::Rememberable::Proxy.new(warden).remember_me(record)
|
||||
end
|
||||
end
|
||||
@@ -1,18 +1,25 @@
|
||||
# Each time a record is set we check whether it's session has already timed out
|
||||
# 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]
|
||||
if record && record.respond_to?(:timedout?) && warden.authenticated?(scope)
|
||||
env = warden.request.env
|
||||
|
||||
if record && record.respond_to?(:timedout?) && warden.authenticated?(scope) && options[:store] != false
|
||||
last_request_at = warden.session(scope)['last_request_at']
|
||||
|
||||
if record.timedout?(last_request_at)
|
||||
if record.timedout?(last_request_at) && !env['devise.skip_timeout']
|
||||
warden.logout(scope)
|
||||
if record.respond_to?(:expire_auth_token_on_timeout) && record.expire_auth_token_on_timeout
|
||||
record.reset_authentication_token!
|
||||
end
|
||||
throw :warden, :scope => scope, :message => :timeout
|
||||
end
|
||||
|
||||
warden.session(scope)['last_request_at'] = Time.now.utc
|
||||
unless env['devise.skip_trackable']
|
||||
warden.session(scope)['last_request_at'] = Time.now.utc
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,18 +1,9 @@
|
||||
# After each sign in, update sign in time, sign in count and sign in IP.
|
||||
# This is only triggered when the user is explicitly set (with set_user)
|
||||
# and on authentication. Retrieving the user from session (:fetch) does
|
||||
# not trigger it.
|
||||
Warden::Manager.after_set_user :except => :fetch do |record, warden, options|
|
||||
scope = options[:scope]
|
||||
if Devise.mappings[scope].try(:trackable?) && warden.authenticated?(scope)
|
||||
old_current, new_current = record.current_sign_in_at, Time.now
|
||||
record.last_sign_in_at = old_current || new_current
|
||||
record.current_sign_in_at = new_current
|
||||
|
||||
old_current, new_current = record.current_sign_in_ip, warden.request.remote_ip
|
||||
record.last_sign_in_ip = old_current || new_current
|
||||
record.current_sign_in_ip = new_current
|
||||
|
||||
record.sign_in_count ||= 0
|
||||
record.sign_in_count += 1
|
||||
|
||||
record.save(:validate => false)
|
||||
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
|
||||
|
||||
95
lib/devise/mailers/helpers.rb
Normal file
95
lib/devise/mailers/helpers.rb
Normal file
@@ -0,0 +1,95 @@
|
||||
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, opts={})
|
||||
initialize_from_record(record)
|
||||
mail headers_for(action, opts)
|
||||
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, opts)
|
||||
headers = {
|
||||
:subject => subject_for(action),
|
||||
:to => resource.email,
|
||||
:from => mailer_sender(devise_mapping),
|
||||
:reply_to => mailer_reply_to(devise_mapping),
|
||||
:template_path => template_paths,
|
||||
:template_name => action
|
||||
}.merge(opts)
|
||||
|
||||
if resource.respond_to?(:headers_for)
|
||||
ActiveSupport::Deprecation.warn "Calling headers_for in the model is no longer supported. " <<
|
||||
"Please customize your mailer instead."
|
||||
headers.merge!(resource.headers_for(action))
|
||||
end
|
||||
|
||||
@email = headers[:to]
|
||||
headers
|
||||
end
|
||||
|
||||
def mailer_reply_to(mapping)
|
||||
mailer_sender(mapping, :reply_to)
|
||||
end
|
||||
|
||||
def mailer_from(mapping)
|
||||
mailer_sender(mapping, :from)
|
||||
end
|
||||
|
||||
def mailer_sender(mapping, sender = :from)
|
||||
if default_params[sender].present?
|
||||
default_params[sender]
|
||||
elsif Devise.mailer_sender.is_a?(Proc)
|
||||
Devise.mailer_sender.call(mapping.name)
|
||||
else
|
||||
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 subject_for(key)
|
||||
I18n.t(:"#{devise_mapping.name}_subject", :scope => [:devise, :mailer, key],
|
||||
:default => [:subject, key.to_s.humanize])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -18,98 +18,155 @@ module Devise
|
||||
# mapping.to #=> User
|
||||
# # is the class to be loaded from routes, given in the route as :class_name.
|
||||
#
|
||||
# mapping.for #=> [:authenticatable]
|
||||
# mapping.modules #=> [:authenticatable]
|
||||
# # is the modules included in the class
|
||||
#
|
||||
class Mapping #:nodoc:
|
||||
attr_reader :name, :as, :path_names, :path_prefix
|
||||
attr_reader :singular, :scoped_path, :path, :controllers, :path_names,
|
||||
:class_name, :sign_out_via, :format, :used_routes, :used_helpers, :failure_app
|
||||
|
||||
# Loop through all mappings looking for a map that matches with the requested
|
||||
# path (ie /users/sign_in). If a path prefix is given, it's taken into account.
|
||||
def self.find_by_path(path)
|
||||
Devise.mappings.each_value do |mapping|
|
||||
route = path.split("/")[mapping.as_position]
|
||||
return mapping if route && mapping.as == route.to_sym
|
||||
end
|
||||
nil
|
||||
end
|
||||
|
||||
# Find a mapping by a given class. It takes into account single table inheritance as well.
|
||||
def self.find_by_class(klass)
|
||||
Devise.mappings.each_value do |mapping|
|
||||
return mapping if klass <= mapping.to
|
||||
end
|
||||
nil
|
||||
end
|
||||
alias :name :singular
|
||||
|
||||
# Receives an object and find a scope for it. If a scope cannot be found,
|
||||
# raises an error. If a symbol is given, it's considered to be the scope.
|
||||
def self.find_scope!(duck)
|
||||
case duck
|
||||
when String, Symbol
|
||||
duck
|
||||
return duck
|
||||
when Class
|
||||
Devise.mappings.each_value { |m| return m.name if duck <= m.to }
|
||||
else
|
||||
klass = duck.is_a?(Class) ? duck : duck.class
|
||||
mapping = Devise::Mapping.find_by_class(klass)
|
||||
raise "Could not find a valid mapping for #{duck}" unless mapping
|
||||
mapping.name
|
||||
Devise.mappings.each_value { |m| return m.name if duck.is_a?(m.to) }
|
||||
end
|
||||
|
||||
raise "Could not find a valid mapping for #{duck.inspect}"
|
||||
end
|
||||
|
||||
def self.find_by_path!(path, path_type=:fullpath)
|
||||
Devise.mappings.each_value { |m| return m if path.include?(m.send(path_type)) }
|
||||
raise "Could not find a valid mapping for path #{path.inspect}"
|
||||
end
|
||||
|
||||
def initialize(name, options) #:nodoc:
|
||||
@as = (options.delete(:as) || name).to_sym
|
||||
@klass = (options.delete(:class_name) || name.to_s.classify).to_s
|
||||
@name = (options.delete(:scope) || name.to_s.singularize).to_sym
|
||||
@scoped_path = options[:as] ? "#{options[:as]}/#{name}" : name.to_s
|
||||
@singular = (options[:singular] || @scoped_path.tr('/', '_').singularize).to_sym
|
||||
|
||||
@path_prefix = "/#{options.delete(:path_prefix)}/".squeeze("/")
|
||||
@path_names = Hash.new { |h,k| h[k] = k.to_s }
|
||||
@path_names.merge!(options.delete(:path_names) || {})
|
||||
@class_name = (options[:class_name] || name.to_s.classify).to_s
|
||||
@klass = Devise.ref(@class_name)
|
||||
|
||||
@path = (options[:path] || name).to_s
|
||||
@path_prefix = options[:path_prefix]
|
||||
|
||||
@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.
|
||||
def for
|
||||
@for ||= to.devise_modules
|
||||
def modules
|
||||
@modules ||= to.respond_to?(:devise_modules) ? to.devise_modules : []
|
||||
end
|
||||
|
||||
# Reload mapped class each time when cache_classes is false.
|
||||
# Gives the class the mapping points to.
|
||||
def to
|
||||
return @to if @to
|
||||
klass = @klass.constantize
|
||||
@to = klass if Rails.configuration.cache_classes
|
||||
klass
|
||||
@klass.get
|
||||
end
|
||||
|
||||
# Check if the respective controller has a module in the mapping class.
|
||||
def allows?(controller)
|
||||
(self.for & CONTROLLERS[controller.to_sym]).present?
|
||||
def strategies
|
||||
@strategies ||= STRATEGIES.values_at(*self.modules).compact.uniq.reverse
|
||||
end
|
||||
|
||||
# Return in which position in the path prefix devise should find the as mapping.
|
||||
def as_position
|
||||
self.path_prefix.count("/")
|
||||
def no_input_strategies
|
||||
self.strategies & Devise::NO_INPUT
|
||||
end
|
||||
|
||||
# Returns the raw path using path_prefix and as.
|
||||
def path
|
||||
path_prefix + as.to_s
|
||||
def routes
|
||||
@routes ||= ROUTES.values_at(*self.modules).compact.uniq
|
||||
end
|
||||
|
||||
def authenticatable?
|
||||
@authenticatable ||= self.modules.any? { |m| m.to_s =~ /authenticatable/ }
|
||||
end
|
||||
|
||||
def fullpath
|
||||
"/#{@path_prefix}/#{@path}".squeeze("/")
|
||||
end
|
||||
|
||||
# Create magic predicates for verifying what module is activated by this map.
|
||||
# Example:
|
||||
#
|
||||
# def confirmable?
|
||||
# self.for.include?(:confirmable)
|
||||
# self.modules.include?(:confirmable)
|
||||
# end
|
||||
#
|
||||
def self.register(*modules)
|
||||
modules.each do |m|
|
||||
class_eval <<-METHOD, __FILE__, __LINE__ + 1
|
||||
def #{m}?
|
||||
self.for.include?(:#{m})
|
||||
end
|
||||
METHOD
|
||||
def self.add_module(m)
|
||||
class_eval <<-METHOD, __FILE__, __LINE__ + 1
|
||||
def #{m}?
|
||||
self.modules.include?(:#{m})
|
||||
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
|
||||
Devise::Mapping.register *ALL
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
module Devise
|
||||
module Models
|
||||
autoload :Activatable, 'devise/models/activatable'
|
||||
autoload :Authenticatable, 'devise/models/authenticatable'
|
||||
autoload :Confirmable, 'devise/models/confirmable'
|
||||
autoload :Lockable, 'devise/models/lockable'
|
||||
autoload :Recoverable, 'devise/models/recoverable'
|
||||
autoload :Rememberable, 'devise/models/rememberable'
|
||||
autoload :Registerable, 'devise/models/registerable'
|
||||
autoload :Timeoutable, 'devise/models/timeoutable'
|
||||
autoload :Trackable, 'devise/models/trackable'
|
||||
autoload :Validatable, 'devise/models/validatable'
|
||||
class MissingAttribute < StandardError
|
||||
def initialize(attributes)
|
||||
@attributes = attributes
|
||||
end
|
||||
|
||||
def message
|
||||
"The following attribute(s) is (are) missing on your model: #{@attributes.join(", ")}"
|
||||
end
|
||||
end
|
||||
|
||||
# Creates configuration values for Devise and for the given module.
|
||||
#
|
||||
# Devise::Models.config(Devise::Authenticable, :stretches, 10)
|
||||
# Devise::Models.config(Devise::Authenticatable, :stretches, 10)
|
||||
#
|
||||
# The line above creates:
|
||||
#
|
||||
@@ -28,6 +27,9 @@ module Devise
|
||||
# inside the given class.
|
||||
#
|
||||
def self.config(mod, *accessors) #:nodoc:
|
||||
class << mod; attr_accessor :available_configs; end
|
||||
mod.available_configs = accessors
|
||||
|
||||
accessors.each do |accessor|
|
||||
mod.class_eval <<-METHOD, __FILE__, __LINE__ + 1
|
||||
def #{accessor}
|
||||
@@ -47,58 +49,80 @@ module Devise
|
||||
end
|
||||
end
|
||||
|
||||
def self.check_fields!(klass)
|
||||
failed_attributes = []
|
||||
instance = klass.new
|
||||
|
||||
klass.devise_modules.each do |mod|
|
||||
constant = const_get(mod.to_s.classify)
|
||||
|
||||
if constant.respond_to?(:required_fields)
|
||||
constant.required_fields(klass).each do |field|
|
||||
failed_attributes << field unless instance.respond_to?(field)
|
||||
end
|
||||
else
|
||||
ActiveSupport::Deprecation.warn "The module #{mod} doesn't implement self.required_fields(klass). " \
|
||||
"Devise uses required_fields to warn developers of any missing fields in their models. " \
|
||||
"Please implement #{mod}.required_fields(klass) that returns an array of symbols with the required fields."
|
||||
end
|
||||
end
|
||||
|
||||
if failed_attributes.any?
|
||||
fail Devise::Models::MissingAttribute.new(failed_attributes)
|
||||
end
|
||||
end
|
||||
|
||||
# Include the chosen devise modules in your model:
|
||||
#
|
||||
# devise :authenticatable, :confirmable, :recoverable
|
||||
# devise :database_authenticatable, :confirmable, :recoverable
|
||||
#
|
||||
# You can also give any of the devise configuration values in form of a hash,
|
||||
# with specific values for this model. Please check your Devise initializer
|
||||
# for a complete description on those values.
|
||||
#
|
||||
def devise(*modules)
|
||||
raise "You need to give at least one Devise module" if modules.empty?
|
||||
options = modules.extract_options!.dup
|
||||
|
||||
options = modules.extract_options!
|
||||
@devise_modules = Devise::ALL & modules.map(&:to_sym).uniq
|
||||
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|
|
||||
if m == :encryptable && !(defined?(Devise::Models::Encryptable))
|
||||
warn "[DEVISE] You're trying to include :encryptable in your model but it is not bundled with the Devise gem anymore. Please add `devise-encryptable` to your Gemfile to proceed.\n"
|
||||
end
|
||||
|
||||
mod = Devise::Models.const_get(m.to_s.classify)
|
||||
|
||||
if mod.const_defined?("ClassMethods")
|
||||
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
|
||||
|
||||
# Stores all modules included inside the model, so we are able to verify
|
||||
# which routes are needed.
|
||||
def devise_modules
|
||||
@devise_modules ||= []
|
||||
end
|
||||
|
||||
# The hook which is called inside devise. So your ORM can include devise
|
||||
# compatibility stuff.
|
||||
# The hook which is called inside devise.
|
||||
# So your ORM can include devise compatibility stuff.
|
||||
def devise_modules_hook!
|
||||
yield
|
||||
end
|
||||
|
||||
# Find an initialize a record setting an error if it can't be found.
|
||||
def find_or_initialize_with_error_by(attribute, value, error=:invalid)
|
||||
if value.present?
|
||||
conditions = { attribute => value }
|
||||
record = find(:first, :conditions => conditions)
|
||||
end
|
||||
|
||||
unless record
|
||||
record = new
|
||||
|
||||
if value.present?
|
||||
record.send(:"#{attribute}=", value)
|
||||
else
|
||||
error = :blank
|
||||
end
|
||||
|
||||
record.errors.add(attribute, error)
|
||||
end
|
||||
|
||||
record
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
require 'devise/models/authenticatable'
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
require 'devise/hooks/activatable'
|
||||
|
||||
module Devise
|
||||
module Models
|
||||
# This module implements the default API required in activatable hook.
|
||||
module Activatable
|
||||
def active?
|
||||
true
|
||||
end
|
||||
|
||||
def inactive_message
|
||||
:inactive
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,130 +1,274 @@
|
||||
require 'devise/strategies/authenticatable'
|
||||
require 'devise/hooks/activatable'
|
||||
|
||||
module Devise
|
||||
module Models
|
||||
# Authenticable Module, responsible for encrypting password and validating
|
||||
# authenticity of a user while signing in.
|
||||
# Authenticatable module. Holds common settings for authentication.
|
||||
#
|
||||
# Configuration:
|
||||
# == Options
|
||||
#
|
||||
# You can overwrite configuration values by setting in globally in Devise,
|
||||
# using devise method or overwriting the respective instance method.
|
||||
# Authenticatable adds the following options to devise_for:
|
||||
#
|
||||
# pepper: encryption key used for creating encrypted password. Each time
|
||||
# password changes, it's gonna be encrypted again, and this key
|
||||
# is added to the password and salt to create a secure hash.
|
||||
# Always use `rake secret' to generate a new key.
|
||||
# * +authentication_keys+: parameters used for authentication. By default [:email].
|
||||
#
|
||||
# stretches: defines how many times the password will be encrypted.
|
||||
# * +request_keys+: parameters from the request object used for authentication.
|
||||
# By specifying a symbol (which should be a request method), it will automatically be
|
||||
# passed to find_for_authentication method and considered in your model lookup.
|
||||
#
|
||||
# encryptor: the encryptor going to be used. By default :sha1.
|
||||
# For instance, if you set :request_keys to [:subdomain], :subdomain will be considered
|
||||
# as key on authentication. This can also be a hash where the value is a boolean expliciting
|
||||
# if the value is required or not.
|
||||
#
|
||||
# authentication_keys: parameters used for authentication. By default [:email]
|
||||
# * +http_authenticatable+: if this model allows http authentication. By default true.
|
||||
# It also accepts an array specifying the strategies that should allow http.
|
||||
#
|
||||
# Examples:
|
||||
# * +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.
|
||||
#
|
||||
# User.authenticate('email@test.com', 'password123') # returns authenticated user or nil
|
||||
# User.find(1).valid_password?('password123') # returns true/false
|
||||
# * +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?
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# You overwrite this method yourself, but if you do, don't forget to call super:
|
||||
#
|
||||
# def active_for_authentication?
|
||||
# super && special_condition_is_valid?
|
||||
# end
|
||||
#
|
||||
# Whenever active_for_authentication? returns false, Devise asks the reason why your model is inactive using
|
||||
# the inactive_message method. You can overwrite it as well:
|
||||
#
|
||||
# def inactive_message
|
||||
# special_condition_is_valid? ? super : :special_condition_is_not_valid
|
||||
# end
|
||||
#
|
||||
module Authenticatable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
BLACKLIST_FOR_SERIALIZATION = [:encrypted_password, :reset_password_token, :reset_password_sent_at,
|
||||
:remember_created_at, :sign_in_count, :current_sign_in_at, :last_sign_in_at, :current_sign_in_ip,
|
||||
:last_sign_in_ip, :password_salt, :confirmation_token, :confirmed_at, :confirmation_sent_at,
|
||||
:remember_token, :unconfirmed_email, :failed_attempts, :unlock_token, :locked_at, :authentication_token]
|
||||
|
||||
included do
|
||||
attr_reader :password, :current_password
|
||||
attr_accessor :password_confirmation
|
||||
class_attribute :devise_modules, :instance_writer => false
|
||||
self.devise_modules ||= []
|
||||
|
||||
before_validation :downcase_keys
|
||||
before_validation :strip_whitespace
|
||||
end
|
||||
|
||||
# Regenerates password salt and encrypted password each time password is set,
|
||||
# and then trigger any "after_changed_password"-callbacks.
|
||||
def password=(new_password)
|
||||
@password = new_password
|
||||
|
||||
if @password.present?
|
||||
self.password_salt = self.class.encryptor_class.salt
|
||||
self.encrypted_password = password_digest(@password)
|
||||
end
|
||||
def self.required_fields(klass)
|
||||
[]
|
||||
end
|
||||
|
||||
# Verifies whether an incoming_password (ie from sign in) is the user password.
|
||||
def valid_password?(incoming_password)
|
||||
password_digest(incoming_password) == self.encrypted_password
|
||||
# Check if the current object is valid for authentication. This method and
|
||||
# find_for_authentication are the methods used in a Warden::Strategy to check
|
||||
# if a model should be signed in or not.
|
||||
#
|
||||
# However, you should not overwrite this method, you should overwrite active_for_authentication?
|
||||
# and inactive_message instead.
|
||||
def valid_for_authentication?
|
||||
block_given? ? yield : true
|
||||
end
|
||||
|
||||
# Verifies whether an +incoming_authentication_token+ (i.e. from single access URL)
|
||||
# is the user authentication token.
|
||||
def valid_authentication_token?(incoming_auth_token)
|
||||
incoming_auth_token == self.authentication_token
|
||||
def unauthenticated_message
|
||||
:invalid
|
||||
end
|
||||
|
||||
# Checks if a resource is valid upon authentication.
|
||||
def valid_for_authentication?(attributes)
|
||||
valid_password?(attributes[:password])
|
||||
def active_for_authentication?
|
||||
true
|
||||
end
|
||||
|
||||
# Set password and password confirmation to nil
|
||||
def clean_up_passwords
|
||||
self.password = self.password_confirmation = nil
|
||||
def inactive_message
|
||||
:inactive
|
||||
end
|
||||
|
||||
# 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={})
|
||||
current_password = params.delete(:current_password)
|
||||
def authenticatable_salt
|
||||
end
|
||||
|
||||
params.delete(:password) if params[:password].blank?
|
||||
params.delete(:password_confirmation) if params[:password_confirmation].blank?
|
||||
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"
|
||||
|
||||
result = if valid_password?(current_password)
|
||||
update_attributes(params)
|
||||
else
|
||||
self.errors.add(:current_password, current_password.blank? ? :blank : :invalid)
|
||||
self.attributes = params
|
||||
false
|
||||
end
|
||||
array.each do |method|
|
||||
class_eval <<-RUBY, __FILE__, __LINE__
|
||||
# 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.
|
||||
def #{method}(options=nil)
|
||||
options ||= {}
|
||||
options[:except] = Array(options[:except])
|
||||
|
||||
clean_up_passwords unless result
|
||||
result
|
||||
if options[:force_except]
|
||||
options[:except].concat Array(options[:force_except])
|
||||
else
|
||||
options[:except].concat BLACKLIST_FOR_SERIALIZATION
|
||||
end
|
||||
super(options)
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
# Digests the password using the configured encryptor.
|
||||
def password_digest(password)
|
||||
self.class.encryptor_class.digest(password, self.class.stretches, self.password_salt, self.class.pepper)
|
||||
def devise_mailer
|
||||
Devise.mailer
|
||||
end
|
||||
|
||||
# This is an internal method called every time Devise needs
|
||||
# to send a notification/mail. This can be overriden if you
|
||||
# need to customize the e-mail delivery logic. For instance,
|
||||
# if you are using a queue to deliver e-mails (delayed job,
|
||||
# sidekiq, resque, etc), you must add the delivery to the queue
|
||||
# just after the transaction was committed. To achieve this,
|
||||
# you can override send_devise_notification to store the
|
||||
# deliveries until the after_commit callback is triggered:
|
||||
#
|
||||
# class User
|
||||
# devise :database_authenticatable, :confirmable
|
||||
#
|
||||
# after_commit :send_pending_notifications
|
||||
#
|
||||
# protected
|
||||
#
|
||||
# def send_devise_notification(notification)
|
||||
# pending_notifications << notification
|
||||
# end
|
||||
#
|
||||
# def send_pending_notifications
|
||||
# pending_notifications.each do |n|
|
||||
# devise_mailer.send(n, self).deliver
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# def pending_notifications
|
||||
# @pending_notifications ||= []
|
||||
# end
|
||||
# end
|
||||
#
|
||||
def send_devise_notification(notification, opts={})
|
||||
devise_mailer.send(notification, self, opts).deliver
|
||||
end
|
||||
|
||||
def downcase_keys
|
||||
self.class.case_insensitive_keys.each { |k| apply_to_attribute_or_variable(k, :downcase!) }
|
||||
end
|
||||
|
||||
def strip_whitespace
|
||||
self.class.strip_whitespace_keys.each { |k| apply_to_attribute_or_variable(k, :strip!) }
|
||||
end
|
||||
|
||||
def apply_to_attribute_or_variable(attr, method)
|
||||
if self[attr]
|
||||
self[attr].try(method)
|
||||
|
||||
# Use respond_to? here to avoid a regression where globally
|
||||
# configured strip_whitespace_keys or case_insensitive_keys were
|
||||
# attempting to strip! or downcase! when a model didn't have the
|
||||
# globally configured key.
|
||||
elsif respond_to?(attr)
|
||||
send(attr).try(method)
|
||||
end
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
Devise::Models.config(self, :pepper, :stretches, :encryptor, :authentication_keys)
|
||||
Devise::Models.config(self, :authentication_keys, :request_keys, :strip_whitespace_keys,
|
||||
:case_insensitive_keys, :http_authenticatable, :params_authenticatable, :skip_session_storage)
|
||||
|
||||
# Authenticate a user based on configured attribute keys. Returns the
|
||||
# authenticated user if it's valid or nil.
|
||||
def authenticate(attributes={})
|
||||
return unless authentication_keys.all? { |k| attributes[k].present? }
|
||||
conditions = attributes.slice(*authentication_keys)
|
||||
resource = find_for_authentication(conditions)
|
||||
resource if resource.try(:valid_for_authentication?, attributes)
|
||||
def serialize_into_session(record)
|
||||
[record.to_key, record.authenticatable_salt]
|
||||
end
|
||||
|
||||
# Returns the class for the configured encryptor.
|
||||
def encryptor_class
|
||||
@encryptor_class ||= ::Devise::Encryptors.const_get(encryptor.to_s.classify)
|
||||
def serialize_from_session(key, salt)
|
||||
record = to_adapter.get(key)
|
||||
record if record && record.authenticatable_salt == salt
|
||||
end
|
||||
|
||||
protected
|
||||
def params_authenticatable?(strategy)
|
||||
params_authenticatable.is_a?(Array) ?
|
||||
params_authenticatable.include?(strategy) : params_authenticatable
|
||||
end
|
||||
|
||||
def http_authenticatable?(strategy)
|
||||
http_authenticatable.is_a?(Array) ?
|
||||
http_authenticatable.include?(strategy) : http_authenticatable
|
||||
end
|
||||
|
||||
# Find first record based on conditions given (ie by the sign in form).
|
||||
# This method is always called during an authentication process but
|
||||
# it may be wrapped as well. For instance, database authenticatable
|
||||
# provides a `find_for_database_authentication` that wraps a call to
|
||||
# this method. This allows you to customize both database authenticatable
|
||||
# or the whole authenticate stack by customize `find_for_authentication.`
|
||||
#
|
||||
# Overwrite to add customized conditions, create a join, or maybe use a
|
||||
# namedscope to filter records while authenticating.
|
||||
# Example:
|
||||
#
|
||||
# def self.find_for_authentication(conditions={})
|
||||
# conditions[:active] = true
|
||||
# find(:first, :conditions => conditions)
|
||||
# def self.find_for_authentication(tainted_conditions)
|
||||
# find_first_by_auth_conditions(tainted_conditions, active: true)
|
||||
# end
|
||||
#
|
||||
def find_for_authentication(conditions)
|
||||
find(:first, :conditions => conditions)
|
||||
# Finally, notice that Devise also queries for users in other scenarios
|
||||
# besides authentication, for example when retrieving an user to send
|
||||
# an e-mail for password reset. In such cases, find_for_authentication
|
||||
# is not called.
|
||||
def find_for_authentication(tainted_conditions)
|
||||
find_first_by_auth_conditions(tainted_conditions)
|
||||
end
|
||||
|
||||
def find_first_by_auth_conditions(tainted_conditions, opts={})
|
||||
to_adapter.find_first(devise_param_filter.filter(tainted_conditions).merge(opts))
|
||||
end
|
||||
|
||||
# Find an initialize a record setting an error if it can't be found.
|
||||
def find_or_initialize_with_error_by(attribute, value, error=:invalid) #:nodoc:
|
||||
find_or_initialize_with_errors([attribute], { attribute => value }, error)
|
||||
end
|
||||
|
||||
# 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:
|
||||
attributes = attributes.slice(*required_attributes)
|
||||
attributes.delete_if { |key, value| value.blank? }
|
||||
|
||||
if attributes.size == required_attributes.size
|
||||
record = find_first_by_auth_conditions(attributes)
|
||||
end
|
||||
|
||||
unless record
|
||||
record = new
|
||||
|
||||
required_attributes.each do |key|
|
||||
value = attributes[key]
|
||||
record.send("#{key}=", value)
|
||||
record.errors.add(key, value.present? ? error : :blank)
|
||||
end
|
||||
end
|
||||
|
||||
record
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
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.
|
||||
def generate_token(column)
|
||||
loop do
|
||||
token = Devise.friendly_token
|
||||
break token unless to_adapter.find_first({ column => token })
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,131 +1,186 @@
|
||||
require 'devise/models/activatable'
|
||||
|
||||
module Devise
|
||||
module Models
|
||||
|
||||
# Confirmable is responsible to verify if an account is already confirmed to
|
||||
# sign in, and to send emails with confirmation instructions.
|
||||
# Confirmation instructions are sent to the user email after creating a
|
||||
# record, after updating it's email and also when manually requested by
|
||||
# a new confirmation instruction request.
|
||||
# Whenever the user update it's email, his account is automatically unconfirmed,
|
||||
# it means it won't be able to sign in again without confirming the account
|
||||
# again through the email that was sent.
|
||||
# record and when manually requested by a new confirmation instruction request.
|
||||
#
|
||||
# Configuration:
|
||||
# == Options
|
||||
#
|
||||
# confirm_within: the time you want the user will have to confirm it's account
|
||||
# without blocking his access. 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 7 days). By default confirm_within is
|
||||
# zero, it means users always have to confirm to sign in.
|
||||
# Confirmable adds the following options to devise_for:
|
||||
#
|
||||
# Examples:
|
||||
# * +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 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.
|
||||
# * +confirm_within+: the time before a sent confirmation token becomes invalid.
|
||||
# You can use this to force the user to confirm within a set period of time.
|
||||
#
|
||||
# == Examples
|
||||
#
|
||||
# User.find(1).confirm! # returns true unless it's already confirmed
|
||||
# User.find(1).confirmed? # true/false
|
||||
# User.find(1).send_confirmation_instructions # manually send instructions
|
||||
# User.find(1).resend_confirmation! # generates a new token and resent it
|
||||
#
|
||||
module Confirmable
|
||||
extend ActiveSupport::Concern
|
||||
include Devise::Models::Activatable
|
||||
include ActionView::Helpers::DateHelper
|
||||
|
||||
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
|
||||
|
||||
def self.required_fields(klass)
|
||||
required_methods = [:confirmation_token, :confirmed_at, :confirmation_sent_at]
|
||||
required_methods << :unconfirmed_email if klass.reconfirmable
|
||||
required_methods
|
||||
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
|
||||
if confirmation_period_expired?
|
||||
self.errors.add(:email, :confirmation_period_expired,
|
||||
:period => Devise::TimeInflector.time_ago_in_words(self.class.confirm_within.ago))
|
||||
return false
|
||||
end
|
||||
|
||||
self.confirmation_token = nil
|
||||
self.confirmed_at = Time.now
|
||||
save(:validate => false)
|
||||
self.confirmed_at = Time.now.utc
|
||||
|
||||
if self.class.reconfirmable && unconfirmed_email.present?
|
||||
skip_reconfirmation!
|
||||
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
|
||||
|
||||
# Verifies whether a user is confirmed or not
|
||||
def confirmed?
|
||||
!new_record? && !confirmed_at.nil?
|
||||
!!confirmed_at
|
||||
end
|
||||
|
||||
def pending_reconfirmation?
|
||||
self.class.reconfirmable && unconfirmed_email.present?
|
||||
end
|
||||
|
||||
# Send confirmation instructions by email
|
||||
def send_confirmation_instructions
|
||||
::Devise::Mailer.confirmation_instructions(self).deliver
|
||||
self.confirmation_token = nil if reconfirmation_required?
|
||||
@reconfirmation_required = false
|
||||
|
||||
generate_confirmation_token! if self.confirmation_token.blank?
|
||||
|
||||
opts = pending_reconfirmation? ? { :to => unconfirmed_email } : { }
|
||||
send_devise_notification(:confirmation_instructions, opts)
|
||||
end
|
||||
|
||||
# Remove confirmation date and send confirmation instructions, to ensure
|
||||
# after sending these instructions the user won't be able to sign in without
|
||||
# confirming it's account
|
||||
def resend_confirmation!
|
||||
unless_confirmed do
|
||||
generate_confirmation_token
|
||||
save(:validate => false)
|
||||
# Resend confirmation token. This method does not need to generate a new token.
|
||||
def resend_confirmation_token
|
||||
pending_any_confirmation do
|
||||
self.confirmation_token = nil if confirmation_period_expired?
|
||||
send_confirmation_instructions
|
||||
end
|
||||
end
|
||||
|
||||
# Overwrites active? from Devise::Models::Activatable for confirmation
|
||||
# by verifying whether an user is active to sign in or not. If the user
|
||||
# Overwrites active_for_authentication? for confirmation
|
||||
# by verifying whether a user is active to sign in or not. If the user
|
||||
# is already confirmed, it should never be blocked. Otherwise we need to
|
||||
# calculate if the confirm time has not expired for this user.
|
||||
def active?
|
||||
super && (confirmed? || confirmation_period_valid?)
|
||||
def active_for_authentication?
|
||||
super && (!confirmation_required? || confirmed? || confirmation_period_valid?)
|
||||
end
|
||||
|
||||
# The message to be shown if the account is inactive.
|
||||
def inactive_message
|
||||
if !confirmed?
|
||||
:unconfirmed
|
||||
else
|
||||
super
|
||||
end
|
||||
!confirmed? ? :unconfirmed : super
|
||||
end
|
||||
|
||||
# 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
|
||||
@skip_confirmation = true
|
||||
self.confirmed_at = Time.now.utc
|
||||
end
|
||||
|
||||
# If you don't want reconfirmation to be sent, neither a code
|
||||
# to be generated, call skip_reconfirmation!
|
||||
def skip_reconfirmation!
|
||||
@bypass_postpone = true
|
||||
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
|
||||
send_devise_notification(:confirmation_instructions)
|
||||
end
|
||||
|
||||
# Callback to overwrite if confirmation is required or not.
|
||||
def confirmation_required?
|
||||
!@skip_confirmation
|
||||
!confirmed?
|
||||
end
|
||||
|
||||
# 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 if the user confirmation happens before the token becomes invalid
|
||||
# Examples:
|
||||
#
|
||||
# # confirm_within = 3.days and confirmation_sent_at = 2.days.ago
|
||||
# confirmation_period_expired? # returns false
|
||||
#
|
||||
# # confirm_within = 3.days and confirmation_sent_at = 4.days.ago
|
||||
# confirmation_period_expired? # returns true
|
||||
#
|
||||
# # confirm_within = nil
|
||||
# confirmation_period_expired? # will always return false
|
||||
#
|
||||
def confirmation_period_expired?
|
||||
self.class.confirm_within && (Time.now > self.confirmation_sent_at + self.class.confirm_within )
|
||||
end
|
||||
|
||||
# Checks whether the record requires any confirmation.
|
||||
def pending_any_confirmation
|
||||
if (!confirmed? || pending_reconfirmation?)
|
||||
yield
|
||||
else
|
||||
self.errors.add(:email, :already_confirmed)
|
||||
@@ -136,33 +191,73 @@ 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 = Devise.friendly_token
|
||||
self.confirmation_token = self.class.confirmation_token
|
||||
self.confirmation_sent_at = Time.now.utc
|
||||
end
|
||||
|
||||
def generate_confirmation_token!
|
||||
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_error_by(:email, attributes[:email], :not_found)
|
||||
confirmable.resend_confirmation! unless confirmable.new_record?
|
||||
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
|
||||
def confirm!(attributes={})
|
||||
confirmable = find_or_initialize_with_error_by(:confirmation_token, attributes[:confirmation_token])
|
||||
confirmable.confirm! unless confirmable.new_record?
|
||||
def confirm_by_token(confirmation_token)
|
||||
confirmable = find_or_initialize_with_error_by(:confirmation_token, confirmation_token)
|
||||
confirmable.confirm! if confirmable.persisted?
|
||||
confirmable
|
||||
end
|
||||
|
||||
Devise::Models.config(self, :confirm_within)
|
||||
# Generate a token checking if one does not already exist in the database.
|
||||
def confirmation_token
|
||||
generate_token(:confirmation_token)
|
||||
end
|
||||
|
||||
# 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, :confirm_within)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
126
lib/devise/models/database_authenticatable.rb
Normal file
126
lib/devise/models/database_authenticatable.rb
Normal file
@@ -0,0 +1,126 @@
|
||||
require 'devise/strategies/database_authenticatable'
|
||||
require 'bcrypt'
|
||||
|
||||
module Devise
|
||||
module Models
|
||||
# Authenticatable Module, responsible for encrypting password and validating
|
||||
# authenticity of a user while signing in.
|
||||
#
|
||||
# == Options
|
||||
#
|
||||
# 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
|
||||
#
|
||||
# User.find(1).valid_password?('password123') # returns true/false
|
||||
#
|
||||
module DatabaseAuthenticatable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
attr_reader :password, :current_password
|
||||
attr_accessor :password_confirmation
|
||||
end
|
||||
|
||||
def self.required_fields(klass)
|
||||
[:encrypted_password] + klass.authentication_keys
|
||||
end
|
||||
|
||||
# Generates password encryption based on the given value.
|
||||
def password=(new_password)
|
||||
@password = new_password
|
||||
self.encrypted_password = password_digest(@password) if @password.present?
|
||||
end
|
||||
|
||||
# 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(encrypted_password)
|
||||
password = ::BCrypt::Engine.hash_secret("#{password}#{self.class.pepper}", bcrypt.salt)
|
||||
Devise.secure_compare(password, encrypted_password)
|
||||
end
|
||||
|
||||
# Set password and password confirmation to nil
|
||||
def clean_up_passwords
|
||||
self.password = self.password_confirmation = nil
|
||||
end
|
||||
|
||||
# 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, *options)
|
||||
current_password = params.delete(:current_password)
|
||||
|
||||
if params[:password].blank?
|
||||
params.delete(:password)
|
||||
params.delete(:password_confirmation) if params[:password_confirmation].blank?
|
||||
end
|
||||
|
||||
result = if valid_password?(current_password)
|
||||
update_attributes(params, *options)
|
||||
else
|
||||
self.assign_attributes(params, *options)
|
||||
self.valid?
|
||||
self.errors.add(:current_password, current_password.blank? ? :blank : :invalid)
|
||||
false
|
||||
end
|
||||
|
||||
clean_up_passwords
|
||||
result
|
||||
end
|
||||
|
||||
# Updates record attributes without asking for the current password.
|
||||
# Never allows a change to the current password. If you are using this
|
||||
# method, you should probably override this method to protect other
|
||||
# attributes you would not like to be updated without a password.
|
||||
#
|
||||
# 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
|
||||
|
||||
# A reliable way to expose the salt regardless of the implementation.
|
||||
def authenticatable_salt
|
||||
encrypted_password[0,29] if encrypted_password
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
# Digests the password using bcrypt.
|
||||
def password_digest(password)
|
||||
::BCrypt::Password.create("#{password}#{self.class.pepper}", :cost => self.class.stretches).to_s
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
Devise::Models.config(self, :pepper, :stretches)
|
||||
|
||||
# We assume this method already gets the sanitized values from the
|
||||
# DatabaseAuthenticatable strategy. If you are using this method on
|
||||
# your own, be sure to sanitize the conditions hash to only include
|
||||
# the proper fields.
|
||||
def find_for_database_authentication(conditions)
|
||||
find_for_authentication(conditions)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,19 +0,0 @@
|
||||
require 'devise/strategies/http_authenticatable'
|
||||
|
||||
module Devise
|
||||
module Models
|
||||
# Adds HttpAuthenticatable behavior to your model. It expects that your
|
||||
# model class responds to authenticate and authentication_keys methods
|
||||
# (which for example are defined in authenticatable).
|
||||
module HttpAuthenticatable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
module ClassMethods
|
||||
# Authenticate an user using http.
|
||||
def authenticate_with_http(username, password)
|
||||
authenticate(authentication_keys.first => username, :password => password)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,105 +1,134 @@
|
||||
require 'devise/models/activatable'
|
||||
require "devise/hooks/lockable"
|
||||
|
||||
module Devise
|
||||
module Models
|
||||
|
||||
# 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.
|
||||
#
|
||||
# Configuration:
|
||||
# == Options
|
||||
#
|
||||
# maximum_attempts: how many attempts should be accepted before blocking the user.
|
||||
# unlock_strategy: unlock the user account by :time, :email or :both.
|
||||
# unlock_in: the time you want to lock the user after to lock happens. Only
|
||||
# available when unlock_strategy is :time or :both.
|
||||
# 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.
|
||||
# * +unlock_strategy+: unlock the user account by :time, :email, :both or :none.
|
||||
# * +unlock_in+: the time you want to lock the user after to lock happens. Only available when unlock_strategy is :time or :both.
|
||||
# * +unlock_keys+: the keys you want to use when locking and unlocking an account
|
||||
#
|
||||
module Lockable
|
||||
extend ActiveSupport::Concern
|
||||
include Devise::Models::Activatable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
delegate :lock_strategy_enabled?, :unlock_strategy_enabled?, :to => "self.class"
|
||||
|
||||
def self.required_fields(klass)
|
||||
attributes = []
|
||||
attributes << :failed_attempts if klass.lock_strategy_enabled?(:failed_attempts)
|
||||
attributes << :locked_at if klass.unlock_strategy_enabled?(:time)
|
||||
attributes << :unlock_token if klass.unlock_strategy_enabled?(:email)
|
||||
|
||||
attributes
|
||||
end
|
||||
|
||||
# Lock a user setting its locked_at to actual time.
|
||||
def lock_access!
|
||||
self.locked_at = Time.now.utc
|
||||
|
||||
# Lock an user setting it's locked_at to actual time.
|
||||
def lock
|
||||
self.locked_at = Time.now
|
||||
if unlock_strategy_enabled?(:email)
|
||||
generate_unlock_token
|
||||
generate_unlock_token!
|
||||
send_unlock_instructions
|
||||
end
|
||||
end
|
||||
|
||||
# Lock an user also saving the record.
|
||||
def lock!
|
||||
lock
|
||||
save(:validate => false)
|
||||
end
|
||||
|
||||
# Unlock an user by cleaning locket_at and failed_attempts.
|
||||
def unlock!
|
||||
if_locked do
|
||||
self.locked_at = nil
|
||||
self.failed_attempts = 0
|
||||
self.unlock_token = nil
|
||||
else
|
||||
save(:validate => false)
|
||||
end
|
||||
end
|
||||
|
||||
# Unlock a user by cleaning locked_at and failed_attempts.
|
||||
def unlock_access!
|
||||
self.locked_at = nil
|
||||
self.failed_attempts = 0 if respond_to?(:failed_attempts=)
|
||||
self.unlock_token = nil if respond_to?(:unlock_token=)
|
||||
save(:validate => false)
|
||||
end
|
||||
|
||||
# Verifies whether a user is locked or not.
|
||||
def locked?
|
||||
def access_locked?
|
||||
locked_at && !lock_expired?
|
||||
end
|
||||
|
||||
# Send unlock instructions by email
|
||||
def send_unlock_instructions
|
||||
::Devise::Mailer.unlock_instructions(self).deliver
|
||||
send_devise_notification(:unlock_instructions)
|
||||
end
|
||||
|
||||
# Resend the unlock instructions if the user is locked.
|
||||
def resend_unlock!
|
||||
if_locked do
|
||||
generate_unlock_token unless unlock_token.present?
|
||||
save(:validate => false)
|
||||
send_unlock_instructions
|
||||
end
|
||||
def resend_unlock_token
|
||||
if_access_locked { send_unlock_instructions }
|
||||
end
|
||||
|
||||
# Overwrites active? from Devise::Models::Activatable for locking purposes
|
||||
# by verifying whether an user is active to sign in or not based on locked?
|
||||
def active?
|
||||
super && !locked?
|
||||
# Overwrites active_for_authentication? from Devise::Models::Activatable for locking purposes
|
||||
# by verifying whether a user is active to sign in or not based on locked?
|
||||
def active_for_authentication?
|
||||
super && !access_locked?
|
||||
end
|
||||
|
||||
# Overwrites invalid_message from Devise::Models::Authenticatable to define
|
||||
# the correct reason for blocking the sign in.
|
||||
def inactive_message
|
||||
if locked?
|
||||
access_locked? ? :locked : super
|
||||
end
|
||||
|
||||
# Overwrites valid_for_authentication? from Devise::Models::Authenticatable
|
||||
# for verifying whether a user is allowed to sign in or not. If the user
|
||||
# is locked, it should never be allowed.
|
||||
def valid_for_authentication?
|
||||
return super unless persisted? && lock_strategy_enabled?(:failed_attempts)
|
||||
|
||||
# Unlock the user if the lock is expired, no matter
|
||||
# if the user can login or not (wrong password, etc)
|
||||
unlock_access! if lock_expired?
|
||||
|
||||
if super && !access_locked?
|
||||
true
|
||||
else
|
||||
self.failed_attempts ||= 0
|
||||
self.failed_attempts += 1
|
||||
if attempts_exceeded?
|
||||
lock_access! unless access_locked?
|
||||
else
|
||||
save(:validate => false)
|
||||
end
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
def unauthenticated_message
|
||||
# If set to paranoid mode, do not show the locked message because it
|
||||
# leaks the existence of an account.
|
||||
if Devise.paranoid
|
||||
super
|
||||
elsif lock_strategy_enabled?(:failed_attempts) && attempts_exceeded?
|
||||
:locked
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
# Overwrites valid_for_authentication? from Devise::Models::Authenticatable
|
||||
# for verifying whether an user is allowed to sign in or not. If the user
|
||||
# is locked, it should never be allowed.
|
||||
def valid_for_authentication?(attributes)
|
||||
if result = super
|
||||
self.failed_attempts = 0
|
||||
else
|
||||
self.failed_attempts += 1
|
||||
lock if failed_attempts > self.class.maximum_attempts
|
||||
end
|
||||
save(:validate => false) if changed?
|
||||
result
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def attempts_exceeded?
|
||||
self.failed_attempts > self.class.maximum_attempts
|
||||
end
|
||||
|
||||
# Generates unlock token
|
||||
def generate_unlock_token
|
||||
self.unlock_token = Devise.friendly_token
|
||||
self.unlock_token = self.class.unlock_token
|
||||
end
|
||||
|
||||
def generate_unlock_token!
|
||||
generate_unlock_token && save(:validate => false)
|
||||
end
|
||||
|
||||
# Tells if the lock is expired if :time unlock strategy is active
|
||||
@@ -113,8 +142,8 @@ module Devise
|
||||
|
||||
# Checks whether the record is locked or not, yielding to the block
|
||||
# if it's locked, otherwise adds an error to email.
|
||||
def if_locked
|
||||
if locked?
|
||||
def if_access_locked
|
||||
if access_locked?
|
||||
yield
|
||||
else
|
||||
self.errors.add(:email, :not_locked)
|
||||
@@ -122,33 +151,42 @@ module Devise
|
||||
end
|
||||
end
|
||||
|
||||
# Is the unlock enabled for the given unlock strategy?
|
||||
def unlock_strategy_enabled?(strategy)
|
||||
[:both, strategy].include?(self.class.unlock_strategy)
|
||||
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
|
||||
def send_unlock_instructions(attributes={})
|
||||
lockable = find_or_initialize_with_error_by(:email, attributes[:email], :not_found)
|
||||
lockable.resend_unlock! unless lockable.new_record?
|
||||
lockable
|
||||
end
|
||||
|
||||
# Find a user by it's 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
|
||||
def unlock!(attributes={})
|
||||
lockable = find_or_initialize_with_error_by(:unlock_token, attributes[:unlock_token])
|
||||
lockable.unlock! unless lockable.new_record?
|
||||
lockable = find_or_initialize_with_errors(unlock_keys, attributes, :not_found)
|
||||
lockable.resend_unlock_token if lockable.persisted?
|
||||
lockable
|
||||
end
|
||||
|
||||
Devise::Models.config(self, :maximum_attempts, :unlock_strategy, :unlock_in)
|
||||
# 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
|
||||
def unlock_access_by_token(unlock_token)
|
||||
lockable = find_or_initialize_with_error_by(:unlock_token, unlock_token)
|
||||
lockable.unlock_access! if lockable.persisted?
|
||||
lockable
|
||||
end
|
||||
|
||||
# Is the unlock enabled for the given unlock strategy?
|
||||
def unlock_strategy_enabled?(strategy)
|
||||
[:both, strategy].include?(self.unlock_strategy)
|
||||
end
|
||||
|
||||
# Is the lock enabled for the given lock strategy?
|
||||
def lock_strategy_enabled?(strategy)
|
||||
self.lock_strategy == strategy
|
||||
end
|
||||
|
||||
def unlock_token
|
||||
Devise.friendly_token
|
||||
end
|
||||
|
||||
Devise::Models.config(self, :maximum_attempts, :lock_strategy, :unlock_strategy, :unlock_in, :unlock_keys)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
27
lib/devise/models/omniauthable.rb
Normal file
27
lib/devise/models/omniauthable.rb
Normal file
@@ -0,0 +1,27 @@
|
||||
require 'devise/omniauth'
|
||||
|
||||
module Devise
|
||||
module Models
|
||||
# Adds OmniAuth support to your model.
|
||||
#
|
||||
# == Options
|
||||
#
|
||||
# Oauthable adds the following options to devise_for:
|
||||
#
|
||||
# * +omniauth_providers+: Which providers are avaialble to this model. It expects an array:
|
||||
#
|
||||
# devise_for :database_authenticatable, :omniauthable, :omniauth_providers => [:twitter]
|
||||
#
|
||||
module Omniauthable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
def self.required_fields(klass)
|
||||
[]
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
Devise::Models.config(self, :omniauth_providers)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,8 +1,15 @@
|
||||
module Devise
|
||||
module Models
|
||||
|
||||
# Recoverable takes care of reseting the user password and send reset instructions
|
||||
# Examples:
|
||||
# Recoverable takes care of reseting the user password and send reset instructions.
|
||||
#
|
||||
# ==Options
|
||||
#
|
||||
# Recoverable adds the following options to devise_for:
|
||||
#
|
||||
# * +reset_password_keys+: the keys you want to use when recovering the password for an account
|
||||
#
|
||||
# == Examples
|
||||
#
|
||||
# # resets the user password and save the record, true if valid passwords are given, otherwise false
|
||||
# User.find(1).reset_password!('password123', 'password123')
|
||||
@@ -13,29 +20,69 @@ module Devise
|
||||
#
|
||||
# # creates a new token and send it with instructions about how to reset the password
|
||||
# User.find(1).send_reset_password_instructions
|
||||
#
|
||||
module Recoverable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
def self.required_fields(klass)
|
||||
[:reset_password_sent_at, :reset_password_token]
|
||||
end
|
||||
|
||||
# Update password saving the record and clearing token. Returns true if
|
||||
# the passwords are valid and the record was saved, false otherwise.
|
||||
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?
|
||||
send_devise_notification(:reset_password_instructions)
|
||||
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 = Devise.friendly_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
|
||||
@@ -47,29 +94,46 @@ 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
|
||||
# password instructions to it. If not user is found, returns a new user
|
||||
# Attempt to find a user by its email. If a record is found, send new
|
||||
# password instructions to it. If user is not found, returns a new user
|
||||
# with an email not found error.
|
||||
# Attributes must contain the user email
|
||||
# Attributes must contain the user's email
|
||||
def send_reset_password_instructions(attributes={})
|
||||
recoverable = find_or_initialize_with_error_by(:email, attributes[:email], :not_found)
|
||||
recoverable.send_reset_password_instructions unless recoverable.new_record?
|
||||
recoverable = find_or_initialize_with_errors(reset_password_keys, attributes, :not_found)
|
||||
recoverable.send_reset_password_instructions if recoverable.persisted?
|
||||
recoverable
|
||||
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
|
||||
# Generate a token checking if one does not already exist in the database.
|
||||
def reset_password_token
|
||||
generate_token(:reset_password_token)
|
||||
end
|
||||
|
||||
# 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!(attributes={})
|
||||
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]) unless recoverable.new_record?
|
||||
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, :reset_password_within)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,6 +3,23 @@ module Devise
|
||||
# Registerable is responsible for everything related to registering a new
|
||||
# resource (ie user sign up).
|
||||
module Registerable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
def self.required_fields(klass)
|
||||
[]
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
# A convenience method that receives both parameters and session to
|
||||
# initialize a user. This can be used by OAuth, for example, to send
|
||||
# in the user token and be stored on initialization.
|
||||
#
|
||||
# By default discards all information sent by the session by calling
|
||||
# new with params.
|
||||
def new_with_session(params, session)
|
||||
new(params)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
require 'devise/strategies/rememberable'
|
||||
require 'devise/hooks/rememberable'
|
||||
require 'devise/hooks/forgetable'
|
||||
|
||||
module Devise
|
||||
module Models
|
||||
@@ -10,16 +11,22 @@ module Devise
|
||||
# You probably wouldn't use rememberable methods directly, they are used
|
||||
# mostly internally for handling the remember token.
|
||||
#
|
||||
# Configuration:
|
||||
# == Options
|
||||
#
|
||||
# remember_for: the time you want the user will be remembered without
|
||||
# asking for credentials. After this time the user will be
|
||||
# blocked and will have to enter his credentials again.
|
||||
# This configuration is also used to calculate the expires
|
||||
# time for the cookie created to remember the user.
|
||||
# By default remember_for is 2.weeks.
|
||||
# Rememberable adds the following options in devise_for:
|
||||
#
|
||||
# Examples:
|
||||
# * +remember_for+: the time you want the user will be remembered without
|
||||
# asking for credentials. After this time the user will be blocked and
|
||||
# will have to enter his credentials again. This configuration is also
|
||||
# used to calculate the expires time for the cookie created to remember
|
||||
# the user. By default remember_for is 2.weeks.
|
||||
#
|
||||
# * +extend_remember_period+: if true, extends the user's remember period
|
||||
# when remembered via cookie. False by default.
|
||||
#
|
||||
# * +rememberable_options+: configuration options passed to the created cookie.
|
||||
#
|
||||
# == Examples
|
||||
#
|
||||
# User.find(1).remember_me! # regenerating the token
|
||||
# User.find(1).forget_me! # clearing the token
|
||||
@@ -32,36 +39,32 @@ module Devise
|
||||
module Rememberable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
# Remember me option available in after_authentication hook.
|
||||
attr_accessor :remember_me
|
||||
attr_accessor :remember_me, :extend_remember_period
|
||||
|
||||
def self.required_fields(klass)
|
||||
[:remember_created_at]
|
||||
end
|
||||
|
||||
# Generate a new remember token and save the record without validations.
|
||||
def remember_me!
|
||||
self.remember_token = Devise.friendly_token
|
||||
self.remember_created_at = Time.now.utc
|
||||
# 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 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!
|
||||
if remember_token
|
||||
self.remember_token = nil
|
||||
self.remember_created_at = nil
|
||||
save(:validate => false)
|
||||
end
|
||||
end
|
||||
|
||||
# Checks whether the incoming token matches or not with the record token.
|
||||
def valid_remember_token?(token)
|
||||
remember_token && !remember_expired? && remember_token == token
|
||||
return unless persisted?
|
||||
self.remember_token = nil if respond_to?(:remember_token=)
|
||||
self.remember_created_at = nil
|
||||
save(:validate => false)
|
||||
end
|
||||
|
||||
# Remember token should be expired if expiration time not overpass now.
|
||||
def remember_expired?
|
||||
remember_expires_at <= Time.now.utc
|
||||
remember_created_at.nil? || (remember_expires_at <= Time.now.utc)
|
||||
end
|
||||
|
||||
# Remember token expires at created time + remember_for configuration
|
||||
@@ -69,20 +72,53 @@ module Devise
|
||||
remember_created_at + self.class.remember_for
|
||||
end
|
||||
|
||||
def rememberable_value
|
||||
if respond_to?(:remember_token)
|
||||
remember_token
|
||||
elsif respond_to?(:authenticatable_salt) && (salt = authenticatable_salt)
|
||||
salt
|
||||
else
|
||||
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 have a remember_token column in your model or implement your own " \
|
||||
"rememberable_value in the model with custom logic."
|
||||
end
|
||||
end
|
||||
|
||||
def rememberable_options
|
||||
self.class.rememberable_options
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def generate_remember_token? #:nodoc:
|
||||
respond_to?(: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:
|
||||
extend_period || remember_created_at.nil? || remember_expired?
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
# Create the cookie key using the record id and remember_token
|
||||
def serialize_into_cookie(record)
|
||||
"#{record.id}::#{record.remember_token}"
|
||||
[record.to_key, record.rememberable_value]
|
||||
end
|
||||
|
||||
# Recreate the user based on the stored cookie
|
||||
def serialize_from_cookie(cookie)
|
||||
record_id, record_token = cookie.split('::')
|
||||
record = find(:first, :conditions => { :id => record_id }) if record_id
|
||||
record if record.try(:valid_remember_token?, record_token)
|
||||
def serialize_from_cookie(id, remember_token)
|
||||
record = to_adapter.get(id)
|
||||
record if record && record.rememberable_value == remember_token && !record.remember_expired?
|
||||
end
|
||||
|
||||
Devise::Models.config(self, :remember_for)
|
||||
# Generate a token checking if one does not already exist in the database.
|
||||
def remember_token #:nodoc:
|
||||
generate_token(:remember_token)
|
||||
end
|
||||
|
||||
Devise::Models.config(self, :remember_for, :extend_remember_period, :rememberable_options)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,15 +7,38 @@ module Devise
|
||||
# will be asked for credentials again, it means, he/she will be redirected
|
||||
# to the sign in page.
|
||||
#
|
||||
# Configuration:
|
||||
# == Options
|
||||
#
|
||||
# Timeoutable adds the following options to devise_for:
|
||||
#
|
||||
# * +timeout_in+: the interval to timeout the user session without activity.
|
||||
#
|
||||
# == Examples
|
||||
#
|
||||
# user.timedout?(30.minutes.ago)
|
||||
#
|
||||
# timeout_in: the time you want to timeout the user session without activity.
|
||||
module Timeoutable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
def self.required_fields(klass)
|
||||
[]
|
||||
end
|
||||
|
||||
# Checks whether the user session has expired based on configured time.
|
||||
def timedout?(last_access)
|
||||
last_access && last_access <= self.class.timeout_in.ago
|
||||
return false if remember_exists_and_not_expired?
|
||||
!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_created_at)
|
||||
remember_created_at && !remember_expired?
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
|
||||
@@ -2,26 +2,45 @@ require 'devise/strategies/token_authenticatable'
|
||||
|
||||
module Devise
|
||||
module Models
|
||||
# Token Authenticatable Module, responsible for generate authentication token and validating
|
||||
# authenticity of a user while signing in using an authentication token (say follows an URL).
|
||||
# The TokenAuthenticatable module is responsible for generating an authentication token and
|
||||
# validating the authenticity of the same while signing in.
|
||||
#
|
||||
# == Configuration:
|
||||
# This module only provides a few helpers to help you manage the token, but it is up to you
|
||||
# to choose how to use it. For example, if you want to have a new token every time the user
|
||||
# saves his account, you can do the following:
|
||||
#
|
||||
# You can overwrite configuration values by setting in globally in Devise (+Devise.setup+),
|
||||
# using devise method, or overwriting the respective instance method.
|
||||
# before_save :reset_authentication_token
|
||||
#
|
||||
# +token_authentication_key+ - Defines name of the authentication token params key. E.g. /users/sign_in?some_key=...
|
||||
# On the other hand, if you want to generate token unless one exists, you should use instead:
|
||||
#
|
||||
# == Examples:
|
||||
# before_save :ensure_authentication_token
|
||||
#
|
||||
# User.authenticate_with_token(:auth_token => '123456789') # returns authenticated user or nil
|
||||
# User.find(1).valid_authentication_token?('rI1t6PKQ8yP7VetgwdybB') # returns true/false
|
||||
# If you want to delete the token after it is used, you can do so in the
|
||||
# after_token_authentication callback.
|
||||
#
|
||||
# == APIs
|
||||
#
|
||||
# If you are using token authentication with APIs and using trackable. Every
|
||||
# request will be considered as a new sign in (since there is no session in
|
||||
# APIs). You can disable this by creating a before filter as follow:
|
||||
#
|
||||
# before_filter :skip_trackable
|
||||
#
|
||||
# def skip_trackable
|
||||
# request.env['devise.skip_trackable'] = true
|
||||
# end
|
||||
#
|
||||
# == Options
|
||||
#
|
||||
# TokenAuthenticatable adds the following options to devise_for:
|
||||
#
|
||||
# * +token_authentication_key+: Defines name of the authentication token params key. E.g. /users/sign_in?some_key=...
|
||||
#
|
||||
module TokenAuthenticatable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
before_save :ensure_authentication_token
|
||||
def self.required_fields(klass)
|
||||
[:authentication_token]
|
||||
end
|
||||
|
||||
# Generate new authentication token (a.k.a. "single access token").
|
||||
@@ -32,56 +51,38 @@ module Devise
|
||||
# Generate new authentication token and save the record.
|
||||
def reset_authentication_token!
|
||||
reset_authentication_token
|
||||
self.save
|
||||
save(:validate => false)
|
||||
end
|
||||
|
||||
# Generate authentication token unless already exists.
|
||||
def ensure_authentication_token
|
||||
self.reset_authentication_token if self.authentication_token.blank?
|
||||
reset_authentication_token if authentication_token.blank?
|
||||
end
|
||||
|
||||
# Generate authentication token unless already exists and save the record.
|
||||
def ensure_authentication_token!
|
||||
self.reset_authentication_token! if self.authentication_token.blank?
|
||||
reset_authentication_token! if authentication_token.blank?
|
||||
end
|
||||
|
||||
# Verifies whether an +incoming_authentication_token+ (i.e. from single access URL)
|
||||
# is the user authentication token.
|
||||
def valid_authentication_token?(incoming_auth_token)
|
||||
incoming_auth_token.present? && incoming_auth_token == self.authentication_token
|
||||
# Hook called after token authentication.
|
||||
def after_token_authentication
|
||||
end
|
||||
|
||||
def expire_auth_token_on_timeout
|
||||
self.class.expire_auth_token_on_timeout
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
::Devise::Models.config(self, :token_authentication_key)
|
||||
|
||||
# Authenticate a user based on authentication token.
|
||||
def authenticate_with_token(attributes)
|
||||
token = attributes[self.token_authentication_key]
|
||||
resource = self.find_for_token_authentication(token)
|
||||
resource if resource.try(:valid_authentication_token?, token)
|
||||
def find_for_token_authentication(conditions)
|
||||
find_for_authentication(:authentication_token => conditions[token_authentication_key])
|
||||
end
|
||||
|
||||
# Generate a token checking if one does not already exist in the database.
|
||||
def authentication_token
|
||||
::Devise.friendly_token
|
||||
generate_token(:authentication_token)
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
# Find first record based on conditions given (ie by the sign in form).
|
||||
# Overwrite to add customized conditions, create a join, or maybe use a
|
||||
# namedscope to filter records while authenticating.
|
||||
#
|
||||
# == Example:
|
||||
#
|
||||
# def self.find_for_token_authentication(token, conditions = {})
|
||||
# conditions = {:active => true}
|
||||
# self.find_by_authentication_token(token, :conditions => conditions)
|
||||
# end
|
||||
#
|
||||
def find_for_token_authentication(token)
|
||||
self.find(:first, :conditions => { :authentication_token => token})
|
||||
end
|
||||
|
||||
Devise::Models.config(self, :token_authentication_key, :expire_auth_token_on_timeout)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,12 +5,31 @@ 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 self.required_fields(klass)
|
||||
[:current_sign_in_at, :current_sign_in_ip, :last_sign_in_at, :last_sign_in_ip, :sign_in_count]
|
||||
end
|
||||
|
||||
def update_tracked_fields!(request)
|
||||
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
|
||||
self.last_sign_in_ip = old_current || new_current
|
||||
self.current_sign_in_ip = new_current
|
||||
|
||||
self.sign_in_count ||= 0
|
||||
self.sign_in_count += 1
|
||||
|
||||
save(:validate => false) or raise "Devise trackable could not save #{inspect}." \
|
||||
"Please make sure a model using trackable can be saved at sign in."
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,28 +1,38 @@
|
||||
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
|
||||
# valid. Also tests presence of password, confirmation and length
|
||||
# Automatically validate if the email is present, unique and its format is
|
||||
# valid. Also tests presence of password, confirmation and length.
|
||||
#
|
||||
# == Options
|
||||
#
|
||||
# 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 8..128.
|
||||
#
|
||||
module Validatable
|
||||
# All validations used by this module.
|
||||
VALIDATIONS = [ :validates_presence_of, :validates_uniqueness_of, :validates_format_of,
|
||||
:validates_confirmation_of, :validates_length_of ].freeze
|
||||
|
||||
def self.required_fields(klass)
|
||||
[]
|
||||
end
|
||||
|
||||
def self.included(base)
|
||||
base.extend ClassMethods
|
||||
assert_validations_api!(base)
|
||||
|
||||
base.class_eval do
|
||||
validates_presence_of :email
|
||||
validates_uniqueness_of :email, :scope => authentication_keys[1..-1], :allow_blank => true
|
||||
validates_format_of :email, :with => EMAIL_REGEX, :allow_blank => true
|
||||
validates_presence_of :email, :if => :email_required?
|
||||
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 => 6..20, :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
|
||||
|
||||
@@ -35,14 +45,22 @@ module Devise
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
protected
|
||||
|
||||
# Checks whether a password is needed or not. For validations only.
|
||||
# Passwords are always required if it's a new record, or if the password
|
||||
# or confirmation are being set somewhere.
|
||||
def password_required?
|
||||
new_record? || !password.nil? || !password_confirmation.nil?
|
||||
end
|
||||
# Checks whether a password is needed or not. For validations only.
|
||||
# Passwords are always required if it's a new record, or if the password
|
||||
# or confirmation are being set somewhere.
|
||||
def password_required?
|
||||
!persisted? || !password.nil? || !password_confirmation.nil?
|
||||
end
|
||||
|
||||
def email_required?
|
||||
true
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
Devise::Models.config(self, :email_regexp, :password_length)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
29
lib/devise/modules.rb
Normal file
29
lib/devise/modules.rb
Normal file
@@ -0,0 +1,29 @@
|
||||
require 'active_support/core_ext/object/with_options'
|
||||
|
||||
Devise.with_options :model => true do |d|
|
||||
# Strategies first
|
||||
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 }, :no_input => true
|
||||
s.add_module :rememberable, :no_input => true
|
||||
end
|
||||
|
||||
# Other authentications
|
||||
d.add_module :omniauthable, :controller => :omniauth_callbacks, :route => :omniauth_callback
|
||||
|
||||
# Misc after
|
||||
routes = [nil, :new, :edit]
|
||||
d.add_module :recoverable, :controller => :passwords, :route => { :password => routes }
|
||||
d.add_module :registerable, :controller => :registrations, :route => { :registration => (routes << :cancel) }
|
||||
d.add_module :validatable
|
||||
|
||||
# The ones which can sign out after
|
||||
routes = [nil, :new]
|
||||
d.add_module :confirmable, :controller => :confirmations, :route => { :confirmation => routes }
|
||||
d.add_module :lockable, :controller => :unlocks, :route => { :unlock => routes }
|
||||
d.add_module :timeoutable
|
||||
|
||||
# Stats for last, so we make sure the user is really signed in
|
||||
d.add_module :trackable
|
||||
end
|
||||
28
lib/devise/omniauth.rb
Normal file
28
lib/devise/omniauth.rb
Normal file
@@ -0,0 +1,28 @@
|
||||
begin
|
||||
require "omniauth"
|
||||
require "omniauth/version"
|
||||
rescue LoadError
|
||||
warn "Could not load 'omniauth'. Please ensure you have the omniauth gem >= 1.0.0 installed and listed in your Gemfile."
|
||||
raise
|
||||
end
|
||||
|
||||
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.
|
||||
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_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"
|
||||
end
|
||||
end
|
||||
45
lib/devise/omniauth/config.rb
Normal file
45
lib/devise/omniauth/config.rb
Normal file
@@ -0,0 +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, :options, :provider, :strategy_name
|
||||
|
||||
def initialize(provider, args)
|
||||
@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
|
||||
@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
|
||||
18
lib/devise/omniauth/url_helpers.rb
Normal file
18
lib/devise/omniauth/url_helpers.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
module Devise
|
||||
module OmniAuth
|
||||
module UrlHelpers
|
||||
def self.define_helpers(mapping)
|
||||
end
|
||||
|
||||
def omniauth_authorize_path(resource_or_scope, *args)
|
||||
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
||||
send("#{scope}_omniauth_authorize_path", *args)
|
||||
end
|
||||
|
||||
def omniauth_callback_path(resource_or_scope, *args)
|
||||
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
||||
send("#{scope}_omniauth_callback_path", *args)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,38 +1,3 @@
|
||||
module Devise
|
||||
module Orm
|
||||
# This module contains some helpers and handle schema (migrations):
|
||||
#
|
||||
# create_table :accounts do |t|
|
||||
# t.authenticatable
|
||||
# t.confirmable
|
||||
# t.recoverable
|
||||
# t.rememberable
|
||||
# t.trackable
|
||||
# t.lockable
|
||||
# t.timestamps
|
||||
# end
|
||||
#
|
||||
# However this method does not add indexes. If you need them, here is the declaration:
|
||||
#
|
||||
# add_index "accounts", ["email"], :name => "email", :unique => true
|
||||
# add_index "accounts", ["confirmation_token"], :name => "confirmation_token", :unique => true
|
||||
# add_index "accounts", ["reset_password_token"], :name => "reset_password_token", :unique => true
|
||||
#
|
||||
module ActiveRecord
|
||||
module Schema
|
||||
include Devise::Schema
|
||||
require 'orm_adapter/adapters/active_record'
|
||||
|
||||
# Tell how to apply schema methods.
|
||||
def apply_schema(name, type, options={})
|
||||
column name, type.to_s.downcase.to_sym, options
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if defined?(ActiveRecord)
|
||||
ActiveRecord::Base.extend Devise::Models
|
||||
ActiveRecord::ConnectionAdapters::Table.send :include, Devise::Orm::ActiveRecord::Schema
|
||||
ActiveRecord::ConnectionAdapters::TableDefinition.send :include, Devise::Orm::ActiveRecord::Schema
|
||||
end
|
||||
ActiveRecord::Base.extend Devise::Models
|
||||
@@ -1,86 +0,0 @@
|
||||
module Devise
|
||||
module Orm
|
||||
module DataMapper
|
||||
module Hook
|
||||
def devise_modules_hook!
|
||||
extend Schema
|
||||
include Compatibility
|
||||
yield
|
||||
return unless Devise.apply_schema
|
||||
devise_modules.each { |m| send(m) if respond_to?(m, true) }
|
||||
end
|
||||
end
|
||||
|
||||
module Schema
|
||||
include Devise::Schema
|
||||
|
||||
SCHEMA_OPTIONS = {
|
||||
:null => :required,
|
||||
:limit => :length
|
||||
}
|
||||
|
||||
# Tell how to apply schema methods. This automatically maps :limit to
|
||||
# :length and :null to :required.
|
||||
def apply_schema(name, type, options={})
|
||||
SCHEMA_OPTIONS.each do |old_key, new_key|
|
||||
next unless options.key?(old_key)
|
||||
options[new_key] = !options.delete(old_key)
|
||||
end
|
||||
|
||||
property name, type, options
|
||||
end
|
||||
end
|
||||
|
||||
module Compatibility
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
module ClassMethods
|
||||
# Hooks for confirmable
|
||||
def before_create(*args)
|
||||
wrap_hook(:before, *args)
|
||||
end
|
||||
|
||||
def after_create(*args)
|
||||
wrap_hook(:after, *args)
|
||||
end
|
||||
|
||||
def wrap_hook(action, *args)
|
||||
options = args.extract_options!
|
||||
|
||||
args.each do |callback|
|
||||
send action, :create, callback
|
||||
class_eval <<-METHOD, __FILE__, __LINE__ + 1
|
||||
def #{callback}
|
||||
super if #{options[:if] || true}
|
||||
end
|
||||
METHOD
|
||||
end
|
||||
end
|
||||
|
||||
# Add ActiveRecord like finder
|
||||
def find(*args)
|
||||
case args.first
|
||||
when :first, :all
|
||||
send(args.shift, *args)
|
||||
else
|
||||
get(*args)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def save(options=nil)
|
||||
if options.is_a?(Hash) && options[:validate] == false
|
||||
save!
|
||||
else
|
||||
super()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
DataMapper::Model.class_eval do
|
||||
extend Devise::ORM::DataMapper::Hook
|
||||
include Devise::Models
|
||||
end
|
||||
@@ -1,49 +0,0 @@
|
||||
module Devise
|
||||
module Orm
|
||||
module MongoMapper
|
||||
module Hook
|
||||
def devise_modules_hook!
|
||||
extend Schema
|
||||
include Compatibility
|
||||
yield
|
||||
return unless Devise.apply_schema
|
||||
devise_modules.each { |m| send(m) if respond_to?(m, true) }
|
||||
end
|
||||
end
|
||||
|
||||
module Schema
|
||||
include Devise::Schema
|
||||
|
||||
# Tell how to apply schema methods. This automatically converts DateTime
|
||||
# to Time, since MongoMapper does not recognize the former.
|
||||
def apply_schema(name, type, options={})
|
||||
type = Time if type == DateTime
|
||||
key name, type, options
|
||||
end
|
||||
end
|
||||
|
||||
module Compatibility
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
module ClassMethods
|
||||
def find(*args)
|
||||
case args.first
|
||||
when :first, :all
|
||||
send(args.shift, *args)
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
[MongoMapper::Document, MongoMapper::EmbeddedDocument].each do |mod|
|
||||
mod::ClassMethods.class_eval do
|
||||
include Devise::Models
|
||||
include Devise::Orm::MongoMapper::Hook
|
||||
end
|
||||
end
|
||||
3
lib/devise/orm/mongoid.rb
Normal file
3
lib/devise/orm/mongoid.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
require 'orm_adapter/adapters/mongoid'
|
||||
|
||||
Mongoid::Document::ClassMethods.send :include, Devise::Models
|
||||
40
lib/devise/param_filter.rb
Normal file
40
lib/devise/param_filter.rb
Normal file
@@ -0,0 +1,40 @@
|
||||
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
|
||||
|
||||
def param_requires_string_conversion?(value)
|
||||
true
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -3,10 +3,52 @@ require 'devise/rails/warden_compat'
|
||||
|
||||
module Devise
|
||||
class Engine < ::Rails::Engine
|
||||
engine_name :devise
|
||||
config.devise = Devise
|
||||
|
||||
config.middleware.use Warden::Manager do |config|
|
||||
Devise.configure_warden(config)
|
||||
# Initialize Warden and copy its configurations.
|
||||
config.app_middleware.use Warden::Manager do |config|
|
||||
Devise.warden_config = config
|
||||
end
|
||||
|
||||
# Force routes to be loaded if we are doing any eager load.
|
||||
config.before_eager_load { |app| app.reload_routes! }
|
||||
|
||||
initializer "devise.url_helpers" do
|
||||
Devise.include_helpers(Devise::Controllers)
|
||||
end
|
||||
|
||||
initializer "devise.omniauth" do |app|
|
||||
Devise.omniauth_configs.each do |provider, config|
|
||||
app.middleware.use config.strategy_class, *config.args do |strategy|
|
||||
config.strategy = strategy
|
||||
end
|
||||
end
|
||||
|
||||
if Devise.omniauth_configs.any?
|
||||
Devise.include_helpers(Devise::OmniAuth)
|
||||
end
|
||||
end
|
||||
|
||||
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 only Rails > 3.2
|
||||
ActionDispatch::Routing::RoutesProxy.class_eval do
|
||||
def respond_to?(method, include_private = false)
|
||||
super || routes.url_helpers.respond_to?(method)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,15 +1,28 @@
|
||||
require "active_support/core_ext/object/try"
|
||||
require "active_support/core_ext/hash/slice"
|
||||
|
||||
module ActionDispatch::Routing
|
||||
class RouteSet #:nodoc:
|
||||
# Ensure Devise modules are included only after loading routes, because we
|
||||
# need devise_for mappings already declared to create filters and helpers.
|
||||
def finalize_with_devise!
|
||||
finalize_without_devise!
|
||||
return if Devise.mappings.empty?
|
||||
result = finalize_without_devise!
|
||||
|
||||
ActionController::Base.send :include, Devise::Controllers::Helpers
|
||||
ActionController::Base.send :include, Devise::Controllers::UrlHelpers
|
||||
@devise_finalized ||= begin
|
||||
if Devise.router_name.nil? && defined?(@devise_finalized) && self != Rails.application.try(:routes)
|
||||
warn "[DEVISE] We have detected that you are using devise_for inside engine routes. " \
|
||||
"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. You can explicitly set it" \
|
||||
" to :main_app as well in case you want to keep the current behavior."
|
||||
end
|
||||
|
||||
ActionView::Base.send :include, Devise::Controllers::UrlHelpers
|
||||
Devise.configure_warden!
|
||||
Devise.regenerate_helpers!
|
||||
true
|
||||
end
|
||||
|
||||
result
|
||||
end
|
||||
alias_method_chain :finalize!, :devise
|
||||
end
|
||||
@@ -18,123 +31,416 @@ module ActionDispatch::Routing
|
||||
# Includes devise_for method for routes. This method is responsible to
|
||||
# generate all needed routes for devise, based on what modules you have
|
||||
# defined in your model.
|
||||
# Examples: Let's say you have an User model configured to use
|
||||
# authenticatable, confirmable and recoverable modules. After creating this
|
||||
# inside your routes:
|
||||
#
|
||||
# ==== Examples
|
||||
#
|
||||
# Let's say you have an User model configured to use authenticatable,
|
||||
# confirmable and recoverable modules. After creating this inside your routes:
|
||||
#
|
||||
# devise_for :users
|
||||
#
|
||||
# this method is going to look inside your User model and create the
|
||||
# This method is going to look inside your User model and create the
|
||||
# needed routes:
|
||||
#
|
||||
# # Session routes for Authenticatable (default)
|
||||
# new_user_session GET /users/sign_in {:controller=>"sessions", :action=>"new"}
|
||||
# user_session POST /users/sign_in {:controller=>"sessions", :action=>"create"}
|
||||
# destroy_user_session GET /users/sign_out {:controller=>"sessions", :action=>"destroy"}
|
||||
# new_user_session GET /users/sign_in {:controller=>"devise/sessions", :action=>"new"}
|
||||
# user_session POST /users/sign_in {:controller=>"devise/sessions", :action=>"create"}
|
||||
# destroy_user_session DELETE /users/sign_out {:controller=>"devise/sessions", :action=>"destroy"}
|
||||
#
|
||||
# # Password routes for Recoverable, if User model has :recoverable configured
|
||||
# new_user_password GET /users/password/new(.:format) {:controller=>"passwords", :action=>"new"}
|
||||
# edit_user_password GET /users/password/edit(.:format) {:controller=>"passwords", :action=>"edit"}
|
||||
# user_password PUT /users/password(.:format) {:controller=>"passwords", :action=>"update"}
|
||||
# POST /users/password(.:format) {:controller=>"passwords", :action=>"create"}
|
||||
# new_user_password GET /users/password/new(.:format) {:controller=>"devise/passwords", :action=>"new"}
|
||||
# edit_user_password GET /users/password/edit(.:format) {:controller=>"devise/passwords", :action=>"edit"}
|
||||
# user_password PUT /users/password(.:format) {:controller=>"devise/passwords", :action=>"update"}
|
||||
# POST /users/password(.:format) {:controller=>"devise/passwords", :action=>"create"}
|
||||
#
|
||||
# # Confirmation routes for Confirmable, if User model has :confirmable configured
|
||||
# new_user_confirmation GET /users/confirmation/new(.:format) {:controller=>"confirmations", :action=>"new"}
|
||||
# user_confirmation GET /users/confirmation(.:format) {:controller=>"confirmations", :action=>"show"}
|
||||
# POST /users/confirmation(.:format) {:controller=>"confirmations", :action=>"create"}
|
||||
# new_user_confirmation GET /users/confirmation/new(.:format) {:controller=>"devise/confirmations", :action=>"new"}
|
||||
# user_confirmation GET /users/confirmation(.:format) {:controller=>"devise/confirmations", :action=>"show"}
|
||||
# POST /users/confirmation(.:format) {:controller=>"devise/confirmations", :action=>"create"}
|
||||
#
|
||||
# ==== Options
|
||||
#
|
||||
# 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'
|
||||
# devise_for :users, :class_name => 'Account'
|
||||
#
|
||||
# * :as => allows you to setup path name that will be used, as rails routes does.
|
||||
# The following route configuration would setup your route as /accounts instead of /users:
|
||||
# * :path => allows you to setup path name that will be used, as rails routes does.
|
||||
# The following route configuration would setup your route as /accounts instead of /users:
|
||||
#
|
||||
# devise_for :users, :as => 'accounts'
|
||||
# devise_for :users, :path => 'accounts'
|
||||
#
|
||||
# * :scope => setup the scope name. This is used as the instance variable name in controller,
|
||||
# as the name in routes and the scope given to warden. Defaults to the singular of the given name:
|
||||
# * :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, :scope => :account
|
||||
# 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' }
|
||||
#
|
||||
# * :path_prefix => the path prefix to be used in all routes.
|
||||
#
|
||||
# devise_for :users, :path_prefix => "/:locale"
|
||||
#
|
||||
# If you are using a dynamic prefix, like :locale above, you need to configure default_url_options in your ApplicationController
|
||||
# class level, so Devise can pick it:
|
||||
#
|
||||
# class ApplicationController < ActionController::Base
|
||||
# def self.default_url_options
|
||||
# { :locale => I18n.locale }
|
||||
# end
|
||||
# end
|
||||
# devise_for :users, :path_names => { :sign_in => 'login', :sign_out => 'logout', :password => 'secret', :confirmation => 'verification' }
|
||||
#
|
||||
# * :controllers => the controller which should be used. All routes by default points to Devise controllers.
|
||||
# However, if you want them to point to custom controller, you should do:
|
||||
#
|
||||
# devise_for :users, :controllers => { :sessions => "users/sessions" }
|
||||
# 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:
|
||||
#
|
||||
# devise_for :users, :sign_out_via => [ :post, :delete ]
|
||||
#
|
||||
# You need to make sure that your sign_out controls trigger a request with a matching HTTP method.
|
||||
#
|
||||
# * :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 do
|
||||
# devise_for :account
|
||||
# end
|
||||
#
|
||||
# Will use publisher/sessions controller instead of devise/sessions controller. You can revert
|
||||
# this by providing the :module option to devise_for.
|
||||
#
|
||||
# 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!, 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' constraints
|
||||
#
|
||||
# * :defaults => works the same as Rails' defaults
|
||||
#
|
||||
# ==== Scoping
|
||||
#
|
||||
# Following Rails 3 routes DSL, you can nest devise_for calls inside a scope:
|
||||
#
|
||||
# scope "/my" do
|
||||
# devise_for :users
|
||||
# end
|
||||
#
|
||||
# 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, so Devise can pick it:
|
||||
#
|
||||
# class ApplicationController < ActionController::Base
|
||||
# def self.default_url_options
|
||||
# { :locale => I18n.locale }
|
||||
# end
|
||||
# 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
|
||||
# overrides an out of the box Devise controller.
|
||||
# For example:
|
||||
#
|
||||
# class RegistrationsController < Devise::RegistrationsController
|
||||
# def update
|
||||
# # do something different here
|
||||
# end
|
||||
#
|
||||
# def deactivate
|
||||
# # not a standard action
|
||||
# # deactivate code here
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# In order to get Devise to recognize the deactivate action, your devise_scope entry should look like this:
|
||||
#
|
||||
# devise_scope :owner do
|
||||
# post "deactivate", :to => "registrations#deactivate", :as => "deactivate_registration"
|
||||
# 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] || {}
|
||||
options[:options][:format] = false if options[:format] == false
|
||||
|
||||
resources.map!(&:to_sym)
|
||||
|
||||
controllers = Hash.new { |h,k| h[k] = "devise/#{k}" }
|
||||
controllers.merge!(options.delete(:controllers) || {})
|
||||
|
||||
resources.each do |resource|
|
||||
mapping = Devise::Mapping.new(resource, options.dup)
|
||||
mapping = Devise.add_mapping(resource, options)
|
||||
|
||||
Devise.default_scope ||= mapping.name
|
||||
Devise.mappings[mapping.name] = mapping
|
||||
begin
|
||||
raise_no_devise_method_error!(mapping.class_name) unless mapping.to.respond_to?(:devise)
|
||||
rescue NameError => e
|
||||
raise unless mapping.class_name == resource.to_s.classify
|
||||
warn "[WARNING] You provided devise_for #{resource.inspect} but there is " <<
|
||||
"no model #{mapping.class_name} defined in your application"
|
||||
next
|
||||
rescue NoMethodError => e
|
||||
raise unless e.message.include?("undefined method `devise'")
|
||||
raise_no_devise_method_error!(mapping.class_name)
|
||||
end
|
||||
|
||||
mapping.for.each do |mod|
|
||||
send(mod, mapping, controllers) if self.respond_to?(mod, true)
|
||||
routes = mapping.used_routes
|
||||
|
||||
devise_scope 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
|
||||
end
|
||||
end
|
||||
|
||||
# Allow you to add authentication request from the router.
|
||||
# Takes an optional scope and block to provide constraints
|
||||
# on the model instance itself.
|
||||
#
|
||||
# authenticate do
|
||||
# resources :post
|
||||
# end
|
||||
#
|
||||
# authenticate(:admin) do
|
||||
# resources :users
|
||||
# end
|
||||
#
|
||||
# authenticate :user, lambda {|u| u.role == "admin"} do
|
||||
# root :to => "admin/dashboard#show"
|
||||
# end
|
||||
#
|
||||
def authenticate(scope=nil, block=nil)
|
||||
constraint = lambda do |request|
|
||||
request.env["warden"].authenticate!(:scope => scope) && (block.nil? || block.call(request.env["warden"].user(scope)))
|
||||
end
|
||||
|
||||
constraints(constraint) do
|
||||
yield
|
||||
end
|
||||
end
|
||||
|
||||
# Allow you to route based on whether a scope is authenticated. You
|
||||
# can optionally specify which scope and a block. The block accepts
|
||||
# a model and allows extra constraints to be done on the instance.
|
||||
#
|
||||
# authenticated :admin do
|
||||
# root :to => 'admin/dashboard#show'
|
||||
# end
|
||||
#
|
||||
# authenticated do
|
||||
# root :to => 'dashboard#show'
|
||||
# end
|
||||
#
|
||||
# authenticated :user, lambda {|u| u.role == "admin"} do
|
||||
# root :to => "admin/dashboard#show"
|
||||
# end
|
||||
#
|
||||
# root :to => 'landing#show'
|
||||
#
|
||||
def authenticated(scope=nil, block=nil)
|
||||
constraint = lambda do |request|
|
||||
request.env["warden"].authenticate?(:scope => scope) && (block.nil? || block.call(request.env["warden"].user(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.
|
||||
#
|
||||
# as :user do
|
||||
# get "sign_in", :to => "devise/sessions#new"
|
||||
# end
|
||||
#
|
||||
# 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]
|
||||
true
|
||||
end
|
||||
|
||||
constraints(constraint) do
|
||||
yield
|
||||
end
|
||||
end
|
||||
alias :as :devise_scope
|
||||
|
||||
protected
|
||||
|
||||
def authenticatable(mapping, controllers)
|
||||
scope mapping.path do
|
||||
get mapping.path_names[:sign_in], :to => "#{controllers[:sessions]}#new", :as => :"new_#{mapping.name}_session"
|
||||
post mapping.path_names[:sign_in], :to => "#{controllers[:sessions]}#create", :as => :"#{mapping.name}_session"
|
||||
get mapping.path_names[:sign_out], :to => "#{controllers[:sessions]}#destroy", :as => :"destroy_#{mapping.name}_session"
|
||||
end
|
||||
end
|
||||
|
||||
def recoverable(mapping, controllers)
|
||||
scope mapping.path, :name_prefix => mapping.name do
|
||||
resource :password, :only => [:new, :create, :edit, :update], :as => mapping.path_names[:password], :controller => controllers[:passwords]
|
||||
end
|
||||
end
|
||||
|
||||
def confirmable(mapping, controllers)
|
||||
scope mapping.path, :name_prefix => mapping.name do
|
||||
resource :confirmation, :only => [:new, :create, :show], :as => mapping.path_names[:confirmation], :controller => controllers[:confirmations]
|
||||
end
|
||||
end
|
||||
|
||||
def lockable(mapping, controllers)
|
||||
scope mapping.path, :name_prefix => mapping.name do
|
||||
resource :unlock, :only => [:new, :create, :show], :as => mapping.path_names[:unlock], :controller => controllers[:unlocks]
|
||||
def devise_session(mapping, controllers) #:nodoc:
|
||||
resource :session, :only => [], :controller => controllers[:sessions], :path => "" do
|
||||
get :new, :path => mapping.path_names[:sign_in], :as => "new"
|
||||
post :create, :path => mapping.path_names[:sign_in]
|
||||
match :destroy, :path => mapping.path_names[:sign_out], :as => "destroy", :via => mapping.sign_out_via
|
||||
end
|
||||
end
|
||||
|
||||
def registerable(mapping, controllers)
|
||||
scope :name_prefix => mapping.name do
|
||||
resource :registration, :only => [:new, :create, :edit, :update, :destroy], :as => mapping.path[1..-1],
|
||||
:path_names => { :new => mapping.path_names[:sign_up] }, :controller => controllers[:registrations]
|
||||
def devise_password(mapping, controllers) #:nodoc:
|
||||
resource :password, :only => [:new, :create, :edit, :update],
|
||||
:path => mapping.path_names[:password], :controller => controllers[:passwords]
|
||||
end
|
||||
|
||||
def devise_confirmation(mapping, controllers) #:nodoc:
|
||||
resource :confirmation, :only => [:new, :create, :show],
|
||||
:path => mapping.path_names[:confirmation], :controller => controllers[:confirmations]
|
||||
end
|
||||
|
||||
def devise_unlock(mapping, controllers) #:nodoc:
|
||||
if mapping.to.unlock_strategy_enabled?(:email)
|
||||
resource :unlock, :only => [:new, :create, :show],
|
||||
:path => mapping.path_names[:unlock], :controller => controllers[:unlocks]
|
||||
end
|
||||
end
|
||||
|
||||
def devise_registration(mapping, controllers) #:nodoc:
|
||||
path_names = {
|
||||
:new => mapping.path_names[:sign_up],
|
||||
:cancel => mapping.path_names[:cancel]
|
||||
}
|
||||
|
||||
options = {
|
||||
:only => [:new, :create, :edit, :update, :destroy],
|
||||
:path => mapping.path_names[:registration],
|
||||
:path_names => path_names,
|
||||
:controller => controllers[:registrations]
|
||||
}
|
||||
|
||||
resource :registration, options do
|
||||
get :cancel
|
||||
end
|
||||
end
|
||||
|
||||
def devise_omniauth_callback(mapping, controllers) #:nodoc:
|
||||
path, @scope[:path] = @scope[:path], nil
|
||||
path_prefix = Devise.omniauth_path_prefix || "/#{mapping.path}/auth".squeeze("/")
|
||||
set_omniauth_path_prefix!(path_prefix)
|
||||
|
||||
providers = Regexp.union(mapping.to.omniauth_providers.map(&:to_s))
|
||||
|
||||
match "#{path_prefix}/:provider",
|
||||
:constraints => { :provider => providers },
|
||||
:to => "#{controllers[:omniauth_callbacks]}#passthru",
|
||||
:as => :omniauth_authorize
|
||||
|
||||
match "#{path_prefix}/:action/callback",
|
||||
:constraints => { :action => providers },
|
||||
:to => controllers[:omniauth_callbacks],
|
||||
:as => :omniauth_callback
|
||||
ensure
|
||||
@scope[:path] = path
|
||||
end
|
||||
|
||||
DEVISE_SCOPE_KEYS = [:as, :path, :module, :constraints, :defaults, :options]
|
||||
|
||||
def with_devise_exclusive_scope(new_path, new_as, options) #:nodoc:
|
||||
old = {}
|
||||
DEVISE_SCOPE_KEYS.each { |k| old[k] = @scope[k] }
|
||||
|
||||
new = { :as => new_as, :path => new_path, :module => nil }
|
||||
new.merge!(options.slice(:constraints, :defaults, :options))
|
||||
|
||||
@scope.merge!(new)
|
||||
yield
|
||||
ensure
|
||||
@scope.merge!(old)
|
||||
end
|
||||
|
||||
def set_omniauth_path_prefix!(path_prefix) #:nodoc:
|
||||
if ::OmniAuth.config.path_prefix && ::OmniAuth.config.path_prefix != path_prefix
|
||||
raise "Wrong OmniAuth configuration. If you are getting this exception, it means that either:\n\n" \
|
||||
"1) You are manually setting OmniAuth.config.path_prefix and it doesn't match the Devise one\n" \
|
||||
"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
|
||||
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' " \
|
||||
"inside 'config/initializers/devise.rb' or before your application definition in 'config/application.rb'"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,23 +3,41 @@ module Warden::Mixins::Common
|
||||
@request ||= ActionDispatch::Request.new(env)
|
||||
end
|
||||
|
||||
# This is called internally by Warden on logout
|
||||
def reset_session!
|
||||
raw_session.inspect # why do I have to inspect it to get it to clear?
|
||||
raw_session.clear
|
||||
request.reset_session
|
||||
end
|
||||
|
||||
def response
|
||||
@response ||= env['action_controller.instance'].response
|
||||
def cookies
|
||||
request.cookie_jar
|
||||
end
|
||||
end
|
||||
|
||||
class Warden::SessionSerializer
|
||||
def serialize(record)
|
||||
[record.class, record.id]
|
||||
klass = record.class
|
||||
array = klass.serialize_into_session(record)
|
||||
array.unshift(klass.name)
|
||||
end
|
||||
|
||||
def deserialize(keys)
|
||||
klass, id = keys
|
||||
klass.find(:first, :conditions => { :id => id })
|
||||
klass_name, *args = keys
|
||||
|
||||
begin
|
||||
klass = ActiveSupport::Inflector.constantize(klass_name)
|
||||
if klass.respond_to? :serialize_from_session
|
||||
klass.serialize_from_session(*args)
|
||||
else
|
||||
Rails.logger.warn "[Devise] Stored serialized class #{klass_name} seems not to be Devise enabled anymore. Did you do that on purpose?"
|
||||
nil
|
||||
end
|
||||
rescue NameError => e
|
||||
if e.message =~ /uninitialized constant/
|
||||
Rails.logger.debug "[Devise] Trying to deserialize invalid class #{klass_name}"
|
||||
nil
|
||||
else
|
||||
raise
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
module Devise
|
||||
# Holds devise schema information. To use it, just include its methods
|
||||
# and overwrite the apply_schema method.
|
||||
module Schema
|
||||
|
||||
# Creates email, encrypted_password and password_salt.
|
||||
#
|
||||
# == Options
|
||||
# * :null - When true, allow columns to be null.
|
||||
# * :encryptor - The encryptor going to be used, necessary for setting the proper encrypter password length.
|
||||
def authenticatable(options={})
|
||||
null = options[:null] || false
|
||||
encryptor = options[:encryptor] || (respond_to?(:encryptor) ? self.encryptor : :sha1)
|
||||
|
||||
apply_schema :email, String, :null => null
|
||||
apply_schema :encrypted_password, String, :null => null, :limit => Devise::ENCRYPTORS_LENGTH[encryptor]
|
||||
apply_schema :password_salt, String, :null => null
|
||||
end
|
||||
|
||||
# Creates authentication_token.
|
||||
def token_authenticatable
|
||||
apply_schema :authentication_token, String, :limit => 20
|
||||
end
|
||||
|
||||
# Creates confirmation_token, confirmed_at and confirmation_sent_at.
|
||||
def confirmable
|
||||
apply_schema :confirmation_token, String, :limit => 20
|
||||
apply_schema :confirmed_at, DateTime
|
||||
apply_schema :confirmation_sent_at, DateTime
|
||||
end
|
||||
|
||||
# Creates reset_password_token.
|
||||
def recoverable
|
||||
apply_schema :reset_password_token, String, :limit => 20
|
||||
end
|
||||
|
||||
# Creates remember_token and remember_created_at.
|
||||
def rememberable
|
||||
apply_schema :remember_token, String, :limit => 20
|
||||
apply_schema :remember_created_at, DateTime
|
||||
end
|
||||
|
||||
# Creates sign_in_count, current_sign_in_at, last_sign_in_at,
|
||||
# current_sign_in_ip, last_sign_in_ip.
|
||||
def trackable
|
||||
apply_schema :sign_in_count, Integer
|
||||
apply_schema :current_sign_in_at, DateTime
|
||||
apply_schema :last_sign_in_at, DateTime
|
||||
apply_schema :current_sign_in_ip, String
|
||||
apply_schema :last_sign_in_ip, String
|
||||
end
|
||||
|
||||
# Creates failed_attempts, unlock_token and locked_at
|
||||
def lockable
|
||||
apply_schema :failed_attempts, Integer, :default => 0
|
||||
apply_schema :unlock_token, String, :limit => 20
|
||||
apply_schema :locked_at, DateTime
|
||||
end
|
||||
|
||||
# Overwrite with specific modification to create your own schema.
|
||||
def apply_schema(name, type, options={})
|
||||
raise NotImplementedError
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -2,35 +2,175 @@ require 'devise/strategies/base'
|
||||
|
||||
module Devise
|
||||
module Strategies
|
||||
# Default strategy for signing in a user, based on his email and password.
|
||||
# Redirects to sign_in page if it's not authenticated
|
||||
# This strategy should be used as basis for authentication strategies. It retrieves
|
||||
# parameters both from params or from http authorization headers. See database_authenticatable
|
||||
# for an example.
|
||||
class Authenticatable < Base
|
||||
attr_accessor :authentication_hash, :authentication_type, :password
|
||||
|
||||
def store?
|
||||
super && !mapping.to.skip_session_storage.include?(authentication_type)
|
||||
end
|
||||
|
||||
def valid?
|
||||
valid_controller? && valid_params? && mapping.to.respond_to?(:authenticate)
|
||||
valid_for_params_auth? || valid_for_http_auth?
|
||||
end
|
||||
|
||||
# Authenticate a user based on email and password params, returning to warden
|
||||
# success and the authenticated user if everything is okay. Otherwise redirect
|
||||
# to sign in page.
|
||||
def authenticate!
|
||||
if resource = mapping.to.authenticate(params[scope])
|
||||
success!(resource)
|
||||
private
|
||||
|
||||
# Receives a resource and check if it is valid by calling valid_for_authentication?
|
||||
# An optional block that will be triggered while validating can be optionally
|
||||
# given as parameter. Check Devise::Models::Authenticable.valid_for_authentication?
|
||||
# for more information.
|
||||
#
|
||||
# In case the resource can't be validated, it will fail with the given
|
||||
# unauthenticated_message.
|
||||
def validate(resource, &block)
|
||||
unless resource
|
||||
ActiveSupport::Deprecation.warn "an empty resource was given to #{self.class.name}#validate. " \
|
||||
"Please ensure the resource is not nil", caller
|
||||
end
|
||||
|
||||
result = resource && resource.valid_for_authentication?(&block)
|
||||
|
||||
case result
|
||||
when Symbol, String
|
||||
ActiveSupport::Deprecation.warn "valid_for_authentication? should return a boolean value"
|
||||
fail!(result)
|
||||
return false
|
||||
end
|
||||
|
||||
if result
|
||||
decorate(resource)
|
||||
true
|
||||
else
|
||||
fail!(:invalid)
|
||||
if resource
|
||||
fail!(resource.unauthenticated_message)
|
||||
end
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
# Get values from params and set in the resource.
|
||||
def decorate(resource)
|
||||
resource.remember_me = remember_me? if resource.respond_to?(:remember_me=)
|
||||
end
|
||||
|
||||
def valid_controller?
|
||||
params[:controller] =~ /sessions$/
|
||||
end
|
||||
# Should this resource be marked to be remembered?
|
||||
def remember_me?
|
||||
valid_params? && Devise::TRUE_VALUES.include?(params_auth_hash[:remember_me])
|
||||
end
|
||||
|
||||
def valid_params?
|
||||
params[scope] && params[scope][:password].present?
|
||||
# Check if this is strategy is valid for http authentication by:
|
||||
#
|
||||
# * Validating if the model allows params authentication;
|
||||
# * If any of the authorization headers were sent;
|
||||
# * If all authentication keys are present;
|
||||
#
|
||||
def valid_for_http_auth?
|
||||
http_authenticatable? && request.authorization && with_authentication_hash(:http_auth, http_auth_hash)
|
||||
end
|
||||
|
||||
# Check if this is strategy is valid for params authentication by:
|
||||
#
|
||||
# * Validating if the model allows params authentication;
|
||||
# * If the request hits the sessions controller through POST;
|
||||
# * If the params[scope] returns a hash with credentials;
|
||||
# * If all authentication keys are present;
|
||||
#
|
||||
def valid_for_params_auth?
|
||||
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.
|
||||
def http_authenticatable?
|
||||
mapping.to.http_authenticatable?(authenticatable_name)
|
||||
end
|
||||
|
||||
# Check if the model accepts this strategy as params authenticatable.
|
||||
def params_authenticatable?
|
||||
mapping.to.params_authenticatable?(authenticatable_name)
|
||||
end
|
||||
|
||||
# Extract the appropriate subhash for authentication from params.
|
||||
def params_auth_hash
|
||||
params[scope]
|
||||
end
|
||||
|
||||
# Extract a hash with attributes:values from the http params.
|
||||
def http_auth_hash
|
||||
keys = [authentication_keys.first, :password]
|
||||
Hash[*keys.zip(decode_credentials).flatten]
|
||||
end
|
||||
|
||||
# By default, a request is valid if the controller set the proper env variable.
|
||||
def valid_params_request?
|
||||
!!env["devise.allow_params_authentication"]
|
||||
end
|
||||
|
||||
# If the request is valid, finally check if params_auth_hash returns a hash.
|
||||
def valid_params?
|
||||
params_auth_hash.is_a?(Hash)
|
||||
end
|
||||
|
||||
# Check if password is present and is not equal to "X" (default value for token).
|
||||
def valid_password?
|
||||
password.present? && password != "X"
|
||||
end
|
||||
|
||||
# Helper to decode credentials from HTTP.
|
||||
def decode_credentials
|
||||
return [] unless request.authorization && request.authorization =~ /^Basic (.*)/m
|
||||
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_type, auth_values)
|
||||
self.authentication_hash, self.authentication_type = {}, auth_type
|
||||
self.password = auth_values[:password]
|
||||
|
||||
parse_authentication_key_values(auth_values, authentication_keys) &&
|
||||
parse_authentication_key_values(request_values, request_keys)
|
||||
end
|
||||
|
||||
# Holds the authentication keys.
|
||||
def authentication_keys
|
||||
@authentication_keys ||= mapping.to.authentication_keys
|
||||
end
|
||||
|
||||
# Holds request keys.
|
||||
def request_keys
|
||||
@request_keys ||= mapping.to.request_keys
|
||||
end
|
||||
|
||||
# Returns values from the request object.
|
||||
def request_values
|
||||
keys = request_keys.respond_to?(:keys) ? request_keys.keys : request_keys
|
||||
values = keys.map { |k| self.request.send(k) }
|
||||
Hash[keys.zip(values)]
|
||||
end
|
||||
|
||||
# Parse authentication keys considering if they should be enforced or not.
|
||||
def parse_authentication_key_values(hash, keys)
|
||||
keys.each do |key, enforce|
|
||||
value = hash[key].presence
|
||||
if value
|
||||
self.authentication_hash[key] = value
|
||||
else
|
||||
return false unless enforce == false
|
||||
end
|
||||
end
|
||||
true
|
||||
end
|
||||
|
||||
# Holds the authenticatable name for this class. Devise::Strategies::DatabaseAuthenticatable
|
||||
# becomes simply :database.
|
||||
def authenticatable_name
|
||||
@authenticatable_name ||=
|
||||
ActiveSupport::Inflector.underscore(self.class.name.split("::").last).
|
||||
sub("_authenticatable", "").to_sym
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Warden::Strategies.add(:authenticatable, Devise::Strategies::Authenticatable)
|
||||
|
||||
@@ -2,8 +2,12 @@ module Devise
|
||||
module Strategies
|
||||
# Base strategy for Devise. Responsible for verifying correct scope and mapping.
|
||||
class Base < ::Warden::Strategies::Base
|
||||
# Checks if a valid scope was given for devise and find mapping based on
|
||||
# this scope.
|
||||
# Whenever CSRF cannot be verified, we turn off any kind of storage
|
||||
def store?
|
||||
!env["devise.skip_storage"]
|
||||
end
|
||||
|
||||
# Checks if a valid scope was given for devise and find mapping based on this scope.
|
||||
def mapping
|
||||
@mapping ||= begin
|
||||
mapping = Devise.mappings[scope]
|
||||
@@ -13,4 +17,4 @@ module Devise
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
20
lib/devise/strategies/database_authenticatable.rb
Normal file
20
lib/devise/strategies/database_authenticatable.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
require 'devise/strategies/authenticatable'
|
||||
|
||||
module Devise
|
||||
module Strategies
|
||||
# Default strategy for signing in a user, based on his email and password in the database.
|
||||
class DatabaseAuthenticatable < Authenticatable
|
||||
def authenticate!
|
||||
resource = valid_password? && mapping.to.find_for_database_authentication(authentication_hash)
|
||||
return fail(:not_found_in_database) unless resource
|
||||
|
||||
if validate(resource){ resource.valid_password?(password) }
|
||||
resource.after_database_authentication
|
||||
success!(resource)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Warden::Strategies.add(:database_authenticatable, Devise::Strategies::DatabaseAuthenticatable)
|
||||
@@ -1,47 +0,0 @@
|
||||
require 'devise/strategies/base'
|
||||
|
||||
module Devise
|
||||
module Strategies
|
||||
# Sign in an user using HTTP authentication.
|
||||
class HttpAuthenticatable < Base
|
||||
def valid?
|
||||
request.authorization && mapping.to.respond_to?(:authenticate_with_http)
|
||||
end
|
||||
|
||||
def authenticate!
|
||||
username, password = username_and_password
|
||||
|
||||
if resource = mapping.to.authenticate_with_http(username, password)
|
||||
success!(resource)
|
||||
else
|
||||
custom!([401, custom_headers, [response_body]])
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def username_and_password
|
||||
decode_credentials(request).split(/:/, 2)
|
||||
end
|
||||
|
||||
def decode_credentials(request)
|
||||
ActiveSupport::Base64.decode64(request.authorization.split(' ', 2).last || '')
|
||||
end
|
||||
|
||||
def response_body
|
||||
body = "HTTP Basic: Access denied."
|
||||
method = :"to_#{request.format.to_sym}"
|
||||
{}.respond_to?(method) ? { :error => body }.send(method) : body
|
||||
end
|
||||
|
||||
def custom_headers
|
||||
{
|
||||
"Content-Type" => request.format.to_s,
|
||||
"WWW-Authenticate" => %(Basic realm="#{Devise.http_authentication_realm.gsub(/"/, "")}")
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Warden::Strategies.add(:http_authenticatable, Devise::Strategies::HttpAuthenticatable)
|
||||
@@ -1,37 +1,55 @@
|
||||
require 'devise/strategies/base'
|
||||
require 'devise/strategies/authenticatable'
|
||||
|
||||
module Devise
|
||||
module Strategies
|
||||
# Remember the user through the remember token. This strategy is responsible
|
||||
# to verify whether there is a cookie with the remember token, and to
|
||||
# recreate the user from this cookie if it exists. Must be called *before*
|
||||
# recreate the user from this cookie if it exists. Must be called *before*
|
||||
# authenticatable.
|
||||
class Rememberable < Devise::Strategies::Base
|
||||
|
||||
class Rememberable < Authenticatable
|
||||
# A valid strategy for rememberable needs a remember token in the cookies.
|
||||
def valid?
|
||||
remember_me_cookie.present? && mapping.to.respond_to?(:serialize_from_cookie)
|
||||
@remember_cookie = nil
|
||||
remember_cookie.present?
|
||||
end
|
||||
|
||||
# To authenticate a user we deserialize the cookie and attempt finding
|
||||
# the record in the database. If the attempt fails, we pass to another
|
||||
# strategy handle the authentication.
|
||||
def authenticate!
|
||||
if resource = mapping.to.serialize_from_cookie(remember_me_cookie)
|
||||
resource = mapping.to.serialize_from_cookie(*remember_cookie)
|
||||
|
||||
unless resource
|
||||
cookies.delete(remember_key)
|
||||
return pass
|
||||
end
|
||||
|
||||
if validate(resource)
|
||||
success!(resource)
|
||||
else
|
||||
pass
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Accessor for remember cookie
|
||||
def remember_me_cookie
|
||||
@remember_me_cookie ||= request.cookies["remember_#{mapping.name}_token"]
|
||||
def decorate(resource)
|
||||
super
|
||||
resource.extend_remember_period = mapping.to.extend_remember_period if resource.respond_to?(:extend_remember_period=)
|
||||
end
|
||||
|
||||
def remember_me?
|
||||
true
|
||||
end
|
||||
|
||||
def remember_key
|
||||
mapping.to.rememberable_options.fetch(:key, "remember_#{scope}_token")
|
||||
end
|
||||
|
||||
def remember_cookie
|
||||
@remember_cookie ||= cookies.signed[remember_key]
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Warden::Strategies.add(:rememberable, Devise::Strategies::Rememberable)
|
||||
Warden::Strategies.add(:rememberable, Devise::Strategies::Rememberable)
|
||||
|
||||
@@ -2,34 +2,53 @@ require 'devise/strategies/base'
|
||||
|
||||
module Devise
|
||||
module Strategies
|
||||
# Strategy for signing in a user, based on a authenticatable token.
|
||||
# Redirects to sign_in page if it's not authenticated.
|
||||
class TokenAuthenticatable < Base
|
||||
def valid?
|
||||
mapping.to.respond_to?(:authenticate_with_token) && authentication_token(scope).present?
|
||||
# Strategy for signing in a user, based on a authenticatable token. This works for both params
|
||||
# and http. For the former, all you need to do is to pass the params in the URL:
|
||||
#
|
||||
# http://myapp.example.com/?user_token=SECRET
|
||||
#
|
||||
# For HTTP, you can pass the token as username and blank password. Since some clients may require
|
||||
# a password, you can pass "X" as password and it will simply be ignored.
|
||||
class TokenAuthenticatable < Authenticatable
|
||||
def store?
|
||||
super && !mapping.to.skip_session_storage.include?(:token_auth)
|
||||
end
|
||||
|
||||
# Authenticate a user based on authenticatable token params, returning to warden
|
||||
# success and the authenticated user if everything is okay. Otherwise redirect
|
||||
# to sign in page.
|
||||
def authenticate!
|
||||
if resource = mapping.to.authenticate_with_token(params[scope] || params)
|
||||
resource = mapping.to.find_for_token_authentication(authentication_hash)
|
||||
return fail(:invalid_token) unless resource
|
||||
|
||||
if validate(resource)
|
||||
resource.after_token_authentication
|
||||
success!(resource)
|
||||
else
|
||||
fail!(:invalid_token)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Detect authentication token in params: scoped or not.
|
||||
def authentication_token(scope)
|
||||
if params[scope]
|
||||
params[scope][mapping.to.token_authentication_key]
|
||||
# Token Authenticatable can be authenticated with params in any controller and any verb.
|
||||
def valid_params_request?
|
||||
true
|
||||
end
|
||||
|
||||
# Do not use remember_me behavior with token.
|
||||
def remember_me?
|
||||
false
|
||||
end
|
||||
|
||||
# Try both scoped and non scoped keys.
|
||||
def params_auth_hash
|
||||
if params[scope].kind_of?(Hash) && params[scope].has_key?(authentication_keys.first)
|
||||
params[scope]
|
||||
else
|
||||
params[mapping.to.token_authentication_key]
|
||||
params
|
||||
end
|
||||
end
|
||||
|
||||
# Overwrite authentication keys to use token_authentication_key.
|
||||
def authentication_keys
|
||||
@authentication_keys ||= [mapping.to.token_authentication_key]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
module Devise
|
||||
# Devise::TestHelpers provides a facility to test controllers in isolation
|
||||
# when using ActionController::TestCase allowing you to quickly sign_in or
|
||||
# sign_out a user. Do not use Devise::TestHelpers in integration tests.
|
||||
#
|
||||
# Notice you should not test Warden specific behavior (like Warden callbacks)
|
||||
# using Devise::TestHelpers since it is a stub of the actual behavior. Such
|
||||
# callbacks should be tested in your integration suite instead.
|
||||
module TestHelpers
|
||||
def self.included(base)
|
||||
base.class_eval do
|
||||
@@ -6,41 +13,10 @@ 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|
|
||||
Devise.configure_warden(config)
|
||||
end
|
||||
super(controller.request.env, manager)
|
||||
end
|
||||
|
||||
def authenticate!(*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._before_failure.each{ |hook| hook.call(env, result) }
|
||||
|
||||
status, headers, body = Devise::FailureApp.call(env).to_a
|
||||
@controller.send :redirect_to, headers["Location"]
|
||||
else
|
||||
result
|
||||
end
|
||||
end
|
||||
# Override process to consider warden.
|
||||
def process(*)
|
||||
# Make sure we always return @response, a la ActionController::TestCase::Behaviour#process, even if warden interrupts
|
||||
_catch_warden { super } || @response
|
||||
end
|
||||
|
||||
# We need to setup the environment variables and the response in the controller.
|
||||
@@ -50,10 +26,16 @@ 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.
|
||||
# This method bypass any warden authentication callback.
|
||||
#
|
||||
# Examples:
|
||||
#
|
||||
@@ -63,10 +45,12 @@ module Devise
|
||||
def sign_in(resource_or_scope, resource=nil)
|
||||
scope ||= Devise::Mapping.find_scope!(resource_or_scope)
|
||||
resource ||= resource_or_scope
|
||||
warden.instance_variable_get(:@users).delete(scope)
|
||||
warden.session_serializer.store(resource, scope)
|
||||
end
|
||||
|
||||
# Sign out a given resource or scope by calling logout on Warden.
|
||||
# This method bypass any warden logout callback.
|
||||
#
|
||||
# Examples:
|
||||
#
|
||||
@@ -76,8 +60,72 @@ module Devise
|
||||
def sign_out(resource_or_scope)
|
||||
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
||||
@controller.instance_variable_set(:"@current_#{scope}", nil)
|
||||
warden.logout(scope)
|
||||
user = warden.instance_variable_get(:@users).delete(scope)
|
||||
warden.session_serializer.delete(scope, user)
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
# Catch warden continuations and handle like the middleware would.
|
||||
# Returns nil when interrupted, otherwise the normal result of the block.
|
||||
def _catch_warden(&block)
|
||||
result = catch(:warden, &block)
|
||||
|
||||
env = @controller.request.env
|
||||
|
||||
result ||= {}
|
||||
|
||||
# Set the response. In production, the rack result is returned
|
||||
# from Warden::Manager#call, which the following is modelled on.
|
||||
case result
|
||||
when Array
|
||||
if result.first == 401 && intercept_401?(env) # does this happen during testing?
|
||||
_process_unauthenticated(env)
|
||||
else
|
||||
result
|
||||
end
|
||||
when Hash
|
||||
_process_unauthenticated(env, result)
|
||||
else
|
||||
result
|
||||
end
|
||||
end
|
||||
|
||||
def _process_unauthenticated(env, options = {})
|
||||
options[:action] ||= :unauthenticated
|
||||
proxy = env['warden']
|
||||
result = options[:result] || proxy.result
|
||||
|
||||
ret = case result
|
||||
when :redirect
|
||||
body = proxy.message || "You are being redirected to #{proxy.headers['Location']}"
|
||||
[proxy.status, proxy.headers, [body]]
|
||||
when :custom
|
||||
proxy.custom_response
|
||||
else
|
||||
env["PATH_INFO"] = "/#{options[:action]}"
|
||||
env["warden.options"] = options
|
||||
Warden::Manager._run_callbacks(:before_failure, env, options)
|
||||
|
||||
status, headers, response = Devise.warden_config[:failure_app].call(env).to_a
|
||||
@controller.send :render, :status => status, :text => response.body,
|
||||
:content_type => headers["Content-Type"], :location => headers["Location"]
|
||||
nil # causes process return @response
|
||||
end
|
||||
|
||||
# ensure that the controller response is set up. In production, this is
|
||||
# not necessary since warden returns the results to rack. However, at
|
||||
# testing time, we want the response to be available to the testing
|
||||
# framework to verify what would be returned to rack.
|
||||
if ret.is_a?(Array)
|
||||
# ensure the controller response is set to our response.
|
||||
@controller.response ||= @response
|
||||
@response.status = ret.first
|
||||
@response.headers = ret.second
|
||||
@response.body = ret.third
|
||||
end
|
||||
|
||||
ret
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
14
lib/devise/time_inflector.rb
Normal file
14
lib/devise/time_inflector.rb
Normal file
@@ -0,0 +1,14 @@
|
||||
require "active_support/core_ext/module/delegation"
|
||||
|
||||
module Devise
|
||||
class TimeInflector
|
||||
include ActionView::Helpers::DateHelper
|
||||
|
||||
class << self
|
||||
attr_reader :instance
|
||||
delegate :time_ago_in_words, :to => :instance
|
||||
end
|
||||
|
||||
@instance = new
|
||||
end
|
||||
end
|
||||
@@ -1,3 +1,3 @@
|
||||
module Devise
|
||||
VERSION = "1.1.pre3".freeze
|
||||
VERSION = "2.2.3".freeze
|
||||
end
|
||||
|
||||
79
lib/generators/active_record/devise_generator.rb
Normal file
79
lib/generators/active_record/devise_generator.rb
Normal file
@@ -0,0 +1,79 @@
|
||||
require 'rails/generators/active_record'
|
||||
require 'generators/devise/orm_helpers'
|
||||
|
||||
module ActiveRecord
|
||||
module Generators
|
||||
class DeviseGenerator < ActiveRecord::Generators::Base
|
||||
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
||||
|
||||
include Devise::Generators::OrmHelpers
|
||||
source_root File.expand_path("../templates", __FILE__)
|
||||
|
||||
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 generate_model
|
||||
invoke "active_record:model", [name], :migration => false unless model_exists? && behavior == :invoke
|
||||
end
|
||||
|
||||
def inject_devise_content
|
||||
content = model_contents + <<CONTENT
|
||||
# Setup accessible (or protected) attributes for your model
|
||||
attr_accessible :email, :password, :password_confirmation, :remember_me
|
||||
CONTENT
|
||||
|
||||
class_path = if namespaced?
|
||||
class_name.to_s.split("::")
|
||||
else
|
||||
[class_name]
|
||||
end
|
||||
|
||||
indent_depth = class_path.size - 1
|
||||
content = content.split("\n").map { |line| " " * indent_depth + line } .join("\n") << "\n"
|
||||
|
||||
inject_into_class(model_path, class_path.last, content) if model_exists?
|
||||
end
|
||||
|
||||
def migration_data
|
||||
<<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
|
||||
|
||||
## 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,23 +1,19 @@
|
||||
class DeviseCreate<%= table_name.camelize %> < ActiveRecord::Migration
|
||||
def self.up
|
||||
def change
|
||||
create_table(:<%= table_name %>) do |t|
|
||||
t.authenticatable :encryptor => :sha1, :null => false
|
||||
t.confirmable
|
||||
t.recoverable
|
||||
t.rememberable
|
||||
t.trackable
|
||||
# t.lockable
|
||||
<%= migration_data -%>
|
||||
|
||||
<% attributes.each do |attribute| -%>
|
||||
t.<%= attribute.type %> :<%= attribute.name %>
|
||||
<% end -%>
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :<%= table_name %>, :email, :unique => true
|
||||
add_index :<%= table_name %>, :confirmation_token, :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
|
||||
end
|
||||
|
||||
def self.down
|
||||
drop_table :<%= table_name %>
|
||||
# add_index :<%= table_name %>, :authentication_token, :unique => true
|
||||
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
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user