upstream-devise 2.1.0.rc

Sign up to get free protection for your applications and to get access to all the features.
Files changed (215) hide show
  1. data/.gitignore +10 -0
  2. data/.travis.yml +15 -0
  3. data/CHANGELOG.rdoc +846 -0
  4. data/Gemfile +35 -0
  5. data/Gemfile.lock +165 -0
  6. data/MIT-LICENSE +20 -0
  7. data/README.md +384 -0
  8. data/Rakefile +34 -0
  9. data/app/controllers/devise/confirmations_controller.rb +43 -0
  10. data/app/controllers/devise/omniauth_callbacks_controller.rb +24 -0
  11. data/app/controllers/devise/passwords_controller.rb +47 -0
  12. data/app/controllers/devise/registrations_controller.rb +107 -0
  13. data/app/controllers/devise/sessions_controller.rb +49 -0
  14. data/app/controllers/devise/unlocks_controller.rb +44 -0
  15. data/app/controllers/devise_controller.rb +177 -0
  16. data/app/helpers/devise_helper.rb +25 -0
  17. data/app/mailers/devise/mailer.rb +15 -0
  18. data/app/views/devise/_links.erb +3 -0
  19. data/app/views/devise/confirmations/new.html.erb +12 -0
  20. data/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
  21. data/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
  22. data/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
  23. data/app/views/devise/passwords/edit.html.erb +16 -0
  24. data/app/views/devise/passwords/new.html.erb +12 -0
  25. data/app/views/devise/registrations/edit.html.erb +25 -0
  26. data/app/views/devise/registrations/new.html.erb +18 -0
  27. data/app/views/devise/sessions/new.html.erb +17 -0
  28. data/app/views/devise/shared/_links.erb +25 -0
  29. data/app/views/devise/unlocks/new.html.erb +12 -0
  30. data/config/locales/en.yml +57 -0
  31. data/devise.gemspec +25 -0
  32. data/gemfiles/Gemfile.rails-3.1.x +35 -0
  33. data/gemfiles/Gemfile.rails-3.1.x.lock +167 -0
  34. data/lib/devise.rb +455 -0
  35. data/lib/devise/controllers/helpers.rb +269 -0
  36. data/lib/devise/controllers/rememberable.rb +52 -0
  37. data/lib/devise/controllers/scoped_views.rb +17 -0
  38. data/lib/devise/controllers/url_helpers.rb +67 -0
  39. data/lib/devise/delegator.rb +17 -0
  40. data/lib/devise/encryptors/authlogic_sha512.rb +19 -0
  41. data/lib/devise/encryptors/base.rb +24 -0
  42. data/lib/devise/encryptors/clearance_sha1.rb +17 -0
  43. data/lib/devise/encryptors/restful_authentication_sha1.rb +22 -0
  44. data/lib/devise/encryptors/sha1.rb +25 -0
  45. data/lib/devise/encryptors/sha512.rb +25 -0
  46. data/lib/devise/failure_app.rb +185 -0
  47. data/lib/devise/hooks/activatable.rb +11 -0
  48. data/lib/devise/hooks/forgetable.rb +9 -0
  49. data/lib/devise/hooks/lockable.rb +7 -0
  50. data/lib/devise/hooks/rememberable.rb +6 -0
  51. data/lib/devise/hooks/timeoutable.rb +22 -0
  52. data/lib/devise/hooks/trackable.rb +9 -0
  53. data/lib/devise/mailers/helpers.rb +86 -0
  54. data/lib/devise/mapping.rb +172 -0
  55. data/lib/devise/models.rb +123 -0
  56. data/lib/devise/models/authenticatable.rb +231 -0
  57. data/lib/devise/models/confirmable.rb +242 -0
  58. data/lib/devise/models/database_authenticatable.rb +126 -0
  59. data/lib/devise/models/encryptable.rb +86 -0
  60. data/lib/devise/models/lockable.rb +185 -0
  61. data/lib/devise/models/omniauthable.rb +27 -0
  62. data/lib/devise/models/recoverable.rb +140 -0
  63. data/lib/devise/models/registerable.rb +25 -0
  64. data/lib/devise/models/rememberable.rb +125 -0
  65. data/lib/devise/models/timeoutable.rb +49 -0
  66. data/lib/devise/models/token_authenticatable.rb +77 -0
  67. data/lib/devise/models/trackable.rb +35 -0
  68. data/lib/devise/models/validatable.rb +66 -0
  69. data/lib/devise/modules.rb +30 -0
  70. data/lib/devise/omniauth.rb +28 -0
  71. data/lib/devise/omniauth/config.rb +45 -0
  72. data/lib/devise/omniauth/url_helpers.rb +33 -0
  73. data/lib/devise/orm/active_record.rb +3 -0
  74. data/lib/devise/orm/mongoid.rb +3 -0
  75. data/lib/devise/param_filter.rb +41 -0
  76. data/lib/devise/rails.rb +54 -0
  77. data/lib/devise/rails/routes.rb +412 -0
  78. data/lib/devise/rails/warden_compat.rb +43 -0
  79. data/lib/devise/strategies/authenticatable.rb +165 -0
  80. data/lib/devise/strategies/base.rb +15 -0
  81. data/lib/devise/strategies/database_authenticatable.rb +21 -0
  82. data/lib/devise/strategies/rememberable.rb +53 -0
  83. data/lib/devise/strategies/token_authenticatable.rb +57 -0
  84. data/lib/devise/test_helpers.rb +130 -0
  85. data/lib/devise/version.rb +3 -0
  86. data/lib/generators/active_record/devise_generator.rb +78 -0
  87. data/lib/generators/active_record/templates/migration.rb +19 -0
  88. data/lib/generators/active_record/templates/migration_existing.rb +26 -0
  89. data/lib/generators/devise/devise_generator.rb +24 -0
  90. data/lib/generators/devise/install_generator.rb +24 -0
  91. data/lib/generators/devise/orm_helpers.rb +32 -0
  92. data/lib/generators/devise/views_generator.rb +110 -0
  93. data/lib/generators/mongoid/devise_generator.rb +60 -0
  94. data/lib/generators/templates/README +31 -0
  95. data/lib/generators/templates/devise.rb +216 -0
  96. data/lib/generators/templates/markerb/confirmation_instructions.markerb +5 -0
  97. data/lib/generators/templates/markerb/reset_password_instructions.markerb +8 -0
  98. data/lib/generators/templates/markerb/unlock_instructions.markerb +7 -0
  99. data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +15 -0
  100. data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +19 -0
  101. data/lib/generators/templates/simple_form_for/passwords/new.html.erb +15 -0
  102. data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +22 -0
  103. data/lib/generators/templates/simple_form_for/registrations/new.html.erb +17 -0
  104. data/lib/generators/templates/simple_form_for/sessions/new.html.erb +15 -0
  105. data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +15 -0
  106. data/test/controllers/custom_strategy_test.rb +62 -0
  107. data/test/controllers/helpers_test.rb +254 -0
  108. data/test/controllers/internal_helpers_test.rb +97 -0
  109. data/test/controllers/sessions_controller_test.rb +36 -0
  110. data/test/controllers/url_helpers_test.rb +59 -0
  111. data/test/delegator_test.rb +19 -0
  112. data/test/devise_test.rb +72 -0
  113. data/test/encryptors_test.rb +30 -0
  114. data/test/failure_app_test.rb +211 -0
  115. data/test/generators/active_record_generator_test.rb +69 -0
  116. data/test/generators/devise_generator_test.rb +39 -0
  117. data/test/generators/install_generator_test.rb +13 -0
  118. data/test/generators/mongoid_generator_test.rb +23 -0
  119. data/test/generators/views_generator_test.rb +52 -0
  120. data/test/helpers/devise_helper_test.rb +51 -0
  121. data/test/indifferent_hash.rb +33 -0
  122. data/test/integration/authenticatable_test.rb +587 -0
  123. data/test/integration/confirmable_test.rb +255 -0
  124. data/test/integration/database_authenticatable_test.rb +82 -0
  125. data/test/integration/http_authenticatable_test.rb +97 -0
  126. data/test/integration/lockable_test.rb +224 -0
  127. data/test/integration/omniauthable_test.rb +133 -0
  128. data/test/integration/recoverable_test.rb +300 -0
  129. data/test/integration/registerable_test.rb +324 -0
  130. data/test/integration/rememberable_test.rb +158 -0
  131. data/test/integration/timeoutable_test.rb +114 -0
  132. data/test/integration/token_authenticatable_test.rb +161 -0
  133. data/test/integration/trackable_test.rb +92 -0
  134. data/test/mailers/confirmation_instructions_test.rb +95 -0
  135. data/test/mailers/reset_password_instructions_test.rb +83 -0
  136. data/test/mailers/unlock_instructions_test.rb +77 -0
  137. data/test/mapping_test.rb +127 -0
  138. data/test/models/authenticatable_test.rb +7 -0
  139. data/test/models/confirmable_test.rb +357 -0
  140. data/test/models/database_authenticatable_test.rb +189 -0
  141. data/test/models/encryptable_test.rb +73 -0
  142. data/test/models/lockable_test.rb +263 -0
  143. data/test/models/omniauthable_test.rb +7 -0
  144. data/test/models/recoverable_test.rb +205 -0
  145. data/test/models/registerable_test.rb +7 -0
  146. data/test/models/rememberable_test.rb +174 -0
  147. data/test/models/serializable_test.rb +48 -0
  148. data/test/models/timeoutable_test.rb +46 -0
  149. data/test/models/token_authenticatable_test.rb +55 -0
  150. data/test/models/trackable_test.rb +13 -0
  151. data/test/models/validatable_test.rb +117 -0
  152. data/test/models_test.rb +179 -0
  153. data/test/omniauth/config_test.rb +57 -0
  154. data/test/omniauth/url_helpers_test.rb +58 -0
  155. data/test/orm/active_record.rb +9 -0
  156. data/test/orm/mongoid.rb +14 -0
  157. data/test/rails_app/Rakefile +10 -0
  158. data/test/rails_app/app/active_record/admin.rb +6 -0
  159. data/test/rails_app/app/active_record/shim.rb +2 -0
  160. data/test/rails_app/app/active_record/user.rb +6 -0
  161. data/test/rails_app/app/controllers/admins/sessions_controller.rb +6 -0
  162. data/test/rails_app/app/controllers/admins_controller.rb +6 -0
  163. data/test/rails_app/app/controllers/application_controller.rb +8 -0
  164. data/test/rails_app/app/controllers/home_controller.rb +25 -0
  165. data/test/rails_app/app/controllers/publisher/registrations_controller.rb +2 -0
  166. data/test/rails_app/app/controllers/publisher/sessions_controller.rb +2 -0
  167. data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +14 -0
  168. data/test/rails_app/app/controllers/users_controller.rb +23 -0
  169. data/test/rails_app/app/helpers/application_helper.rb +3 -0
  170. data/test/rails_app/app/mailers/users/mailer.rb +3 -0
  171. data/test/rails_app/app/mongoid/admin.rb +30 -0
  172. data/test/rails_app/app/mongoid/shim.rb +24 -0
  173. data/test/rails_app/app/mongoid/user.rb +45 -0
  174. data/test/rails_app/app/views/admins/index.html.erb +1 -0
  175. data/test/rails_app/app/views/admins/sessions/new.html.erb +2 -0
  176. data/test/rails_app/app/views/home/admin_dashboard.html.erb +1 -0
  177. data/test/rails_app/app/views/home/index.html.erb +1 -0
  178. data/test/rails_app/app/views/home/join.html.erb +1 -0
  179. data/test/rails_app/app/views/home/private.html.erb +1 -0
  180. data/test/rails_app/app/views/home/user_dashboard.html.erb +1 -0
  181. data/test/rails_app/app/views/layouts/application.html.erb +24 -0
  182. data/test/rails_app/app/views/users/index.html.erb +1 -0
  183. data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +1 -0
  184. data/test/rails_app/app/views/users/sessions/new.html.erb +1 -0
  185. data/test/rails_app/config.ru +4 -0
  186. data/test/rails_app/config/application.rb +41 -0
  187. data/test/rails_app/config/boot.rb +8 -0
  188. data/test/rails_app/config/database.yml +18 -0
  189. data/test/rails_app/config/environment.rb +5 -0
  190. data/test/rails_app/config/environments/development.rb +18 -0
  191. data/test/rails_app/config/environments/production.rb +33 -0
  192. data/test/rails_app/config/environments/test.rb +33 -0
  193. data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
  194. data/test/rails_app/config/initializers/devise.rb +186 -0
  195. data/test/rails_app/config/initializers/inflections.rb +2 -0
  196. data/test/rails_app/config/initializers/secret_token.rb +2 -0
  197. data/test/rails_app/config/routes.rb +90 -0
  198. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +77 -0
  199. data/test/rails_app/db/schema.rb +52 -0
  200. data/test/rails_app/lib/shared_admin.rb +14 -0
  201. data/test/rails_app/lib/shared_user.rb +26 -0
  202. data/test/rails_app/public/404.html +26 -0
  203. data/test/rails_app/public/422.html +26 -0
  204. data/test/rails_app/public/500.html +26 -0
  205. data/test/rails_app/public/favicon.ico +0 -0
  206. data/test/rails_app/script/rails +10 -0
  207. data/test/routes_test.rb +248 -0
  208. data/test/support/assertions.rb +42 -0
  209. data/test/support/helpers.rb +91 -0
  210. data/test/support/integration.rb +90 -0
  211. data/test/support/locale/en.yml +4 -0
  212. data/test/support/webrat/integrations/rails.rb +24 -0
  213. data/test/test_helper.rb +27 -0
  214. data/test/test_helpers_test.rb +134 -0
  215. metadata +451 -0
data/Gemfile ADDED
@@ -0,0 +1,35 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem "rails", "~> 3.2.0"
6
+ gem "omniauth", "~> 1.0.0"
7
+ gem "omniauth-oauth2", "~> 1.0.0"
8
+ gem "rdoc"
9
+
10
+ group :test do
11
+ gem "omniauth-facebook"
12
+ gem "omniauth-openid", "~> 1.0.1"
13
+ gem "webrat", "0.7.2", :require => false
14
+ gem "mocha", :require => false
15
+
16
+ platforms :mri_18 do
17
+ gem "ruby-debug", ">= 0.10.3"
18
+ end
19
+ end
20
+
21
+ platforms :jruby do
22
+ gem "activerecord-jdbc-adapter"
23
+ gem "activerecord-jdbcsqlite3-adapter"
24
+ gem "jruby-openssl"
25
+ end
26
+
27
+ platforms :ruby do
28
+ gem "sqlite3"
29
+
30
+ group :mongoid do
31
+ gem "mongo", "~> 1.3.0"
32
+ gem "mongoid", "~> 2.0"
33
+ gem "bson_ext", "~> 1.3.0"
34
+ end
35
+ end
@@ -0,0 +1,165 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ devise (2.1.0.rc)
5
+ bcrypt-ruby (~> 3.0)
6
+ orm_adapter (~> 0.0.7)
7
+ railties (~> 3.1)
8
+ warden (~> 1.1.1)
9
+
10
+ GEM
11
+ remote: http://rubygems.org/
12
+ specs:
13
+ actionmailer (3.2.0)
14
+ actionpack (= 3.2.0)
15
+ mail (~> 2.4.0)
16
+ actionpack (3.2.0)
17
+ activemodel (= 3.2.0)
18
+ activesupport (= 3.2.0)
19
+ builder (~> 3.0.0)
20
+ erubis (~> 2.7.0)
21
+ journey (~> 1.0.0)
22
+ rack (~> 1.4.0)
23
+ rack-cache (~> 1.1)
24
+ rack-test (~> 0.6.1)
25
+ sprockets (~> 2.1.2)
26
+ activemodel (3.2.0)
27
+ activesupport (= 3.2.0)
28
+ builder (~> 3.0.0)
29
+ activerecord (3.2.0)
30
+ activemodel (= 3.2.0)
31
+ activesupport (= 3.2.0)
32
+ arel (~> 3.0.0)
33
+ tzinfo (~> 0.3.29)
34
+ activeresource (3.2.0)
35
+ activemodel (= 3.2.0)
36
+ activesupport (= 3.2.0)
37
+ activesupport (3.2.0)
38
+ i18n (~> 0.6)
39
+ multi_json (~> 1.0)
40
+ addressable (2.2.6)
41
+ arel (3.0.0)
42
+ bcrypt-ruby (3.0.1)
43
+ bson (1.5.1)
44
+ bson_ext (1.3.1)
45
+ builder (3.0.0)
46
+ columnize (0.3.5)
47
+ erubis (2.7.0)
48
+ faraday (0.7.5)
49
+ addressable (~> 2.2.6)
50
+ multipart-post (~> 1.1.3)
51
+ rack (>= 1.1.0, < 2)
52
+ hashie (1.2.0)
53
+ hike (1.2.1)
54
+ i18n (0.6.0)
55
+ journey (1.0.0)
56
+ json (1.6.5)
57
+ linecache (0.46)
58
+ rbx-require-relative (> 0.0.4)
59
+ mail (2.4.1)
60
+ i18n (>= 0.4.0)
61
+ mime-types (~> 1.16)
62
+ treetop (~> 1.4.8)
63
+ metaclass (0.0.1)
64
+ mime-types (1.17.2)
65
+ mocha (0.10.0)
66
+ metaclass (~> 0.0.1)
67
+ mongo (1.3.1)
68
+ bson (>= 1.3.1)
69
+ mongoid (2.3.4)
70
+ activemodel (~> 3.1)
71
+ mongo (~> 1.3)
72
+ tzinfo (~> 0.3.22)
73
+ multi_json (1.0.4)
74
+ multipart-post (1.1.4)
75
+ nokogiri (1.5.0)
76
+ oauth2 (0.5.1)
77
+ faraday (~> 0.7.4)
78
+ multi_json (~> 1.0.3)
79
+ omniauth (1.0.1)
80
+ hashie (~> 1.2)
81
+ rack
82
+ omniauth-facebook (1.0.0)
83
+ omniauth-oauth2 (~> 1.0.0)
84
+ omniauth-oauth2 (1.0.0)
85
+ oauth2 (~> 0.5.0)
86
+ omniauth (~> 1.0)
87
+ omniauth-openid (1.0.1)
88
+ omniauth (~> 1.0)
89
+ rack-openid (~> 1.3.1)
90
+ orm_adapter (0.0.7)
91
+ polyglot (0.3.3)
92
+ rack (1.4.1)
93
+ rack-cache (1.1)
94
+ rack (>= 0.4)
95
+ rack-openid (1.3.1)
96
+ rack (>= 1.1.0)
97
+ ruby-openid (>= 2.1.8)
98
+ rack-ssl (1.3.2)
99
+ rack
100
+ rack-test (0.6.1)
101
+ rack (>= 1.0)
102
+ rails (3.2.0)
103
+ actionmailer (= 3.2.0)
104
+ actionpack (= 3.2.0)
105
+ activerecord (= 3.2.0)
106
+ activeresource (= 3.2.0)
107
+ activesupport (= 3.2.0)
108
+ bundler (~> 1.0)
109
+ railties (= 3.2.0)
110
+ railties (3.2.0)
111
+ actionpack (= 3.2.0)
112
+ activesupport (= 3.2.0)
113
+ rack-ssl (~> 1.3.2)
114
+ rake (>= 0.8.7)
115
+ rdoc (~> 3.4)
116
+ thor (~> 0.14.6)
117
+ rake (0.9.2.2)
118
+ rbx-require-relative (0.0.5)
119
+ rdoc (3.12)
120
+ json (~> 1.4)
121
+ ruby-debug (0.10.4)
122
+ columnize (>= 0.1)
123
+ ruby-debug-base (~> 0.10.4.0)
124
+ ruby-debug-base (0.10.4)
125
+ linecache (>= 0.3)
126
+ ruby-openid (2.1.8)
127
+ sprockets (2.1.2)
128
+ hike (~> 1.2)
129
+ rack (~> 1.0)
130
+ tilt (~> 1.1, != 1.3.0)
131
+ sqlite3 (1.3.5)
132
+ thor (0.14.6)
133
+ tilt (1.3.3)
134
+ treetop (1.4.10)
135
+ polyglot
136
+ polyglot (>= 0.3.1)
137
+ tzinfo (0.3.31)
138
+ warden (1.1.1)
139
+ rack (>= 1.0)
140
+ webrat (0.7.2)
141
+ nokogiri (>= 1.2.0)
142
+ rack (>= 1.0)
143
+ rack-test (>= 0.5.3)
144
+
145
+ PLATFORMS
146
+ ruby
147
+
148
+ DEPENDENCIES
149
+ activerecord-jdbc-adapter
150
+ activerecord-jdbcsqlite3-adapter
151
+ bson_ext (~> 1.3.0)
152
+ devise!
153
+ jruby-openssl
154
+ mocha
155
+ mongo (~> 1.3.0)
156
+ mongoid (~> 2.0)
157
+ omniauth (~> 1.0.0)
158
+ omniauth-facebook
159
+ omniauth-oauth2 (~> 1.0.0)
160
+ omniauth-openid (~> 1.0.1)
161
+ rails (~> 3.2.0)
162
+ rdoc
163
+ ruby-debug (>= 0.10.3)
164
+ sqlite3
165
+ webrat (= 0.7.2)
@@ -0,0 +1,20 @@
1
+ Copyright 2009-2012 Plataformatec. http://plataformatec.com.br
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,384 @@
1
+ *IMPORTANT:* Devise 2.0 is out. If you are upgrading, please read: https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0
2
+
3
+ ## Devise
4
+
5
+ INFO: This README is [also available in a friendly navigable format](http://devise.plataformatec.com.br/).
6
+
7
+ [![Build Status](https://secure.travis-ci.org/plataformatec/devise.png)](http://travis-ci.org/plataformatec/devise)
8
+
9
+ Devise is a flexible authentication solution for Rails based on Warden. It:
10
+
11
+ * Is Rack based;
12
+ * Is a complete MVC solution based on Rails engines;
13
+ * Allows you to have multiple roles (or models/scopes) signed in at the same time;
14
+ * Is based on a modularity concept: use just what you really need.
15
+
16
+ It's comprised of 12 modules:
17
+
18
+ * Database Authenticatable: encrypts and stores a password in the database to validate the authenticity of a user while signing in. The authentication can be done both through POST requests or HTTP Basic Authentication.
19
+ * Token Authenticatable: signs in a user based on an authentication token (also known as "single access token"). The token can be given both through query string or HTTP Basic Authentication.
20
+ * Omniauthable: adds Omniauth (github.com/intridea/omniauth) support;
21
+ * Confirmable: sends emails with confirmation instructions and verifies whether an account is already confirmed during sign in.
22
+ * Recoverable: resets the user password and sends reset instructions.
23
+ * Registerable: handles signing up users through a registration process, also allowing them to edit and destroy their account.
24
+ * Rememberable: manages generating and clearing a token for remembering the user from a saved cookie.
25
+ * Trackable: tracks sign in count, timestamps and IP address.
26
+ * Timeoutable: expires sessions that have no activity in a specified period of time.
27
+ * Validatable: provides validations of email and password. It's optional and can be customized, so you're able to define your own validations.
28
+ * Lockable: locks an account after a specified number of failed sign-in attempts. Can unlock via email or after a specified time period.
29
+ * Encryptable: adds support of other authentication mechanisms besides the built-in Bcrypt (the default).
30
+
31
+ ## Information
32
+
33
+ ### The Devise wiki
34
+
35
+ 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:
36
+
37
+ https://wiki.github.com/plataformatec/devise
38
+
39
+ ### Bug reports
40
+
41
+ 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:
42
+
43
+ https://github.com/plataformatec/devise/wiki/Bug-reports
44
+
45
+ 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.
46
+
47
+ ### Mailing list
48
+
49
+ If you have any questions, comments, or concerns, please use the Google Group instead of the GitHub issue tracker:
50
+
51
+ https://groups.google.com/group/plataformatec-devise
52
+
53
+ ### RDocs
54
+
55
+ You can view the Devise documentation in RDoc format here:
56
+
57
+ http://rubydoc.info/github/plataformatec/devise/master/frames
58
+
59
+ 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.
60
+
61
+ ### Example applications
62
+
63
+ 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:
64
+
65
+ https://github.com/plataformatec/devise/wiki/Example-Applications
66
+
67
+ ### Extensions
68
+
69
+ 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:
70
+
71
+ https://github.com/plataformatec/devise/wiki/Extensions
72
+
73
+ ### Contributing
74
+
75
+ We hope that you will consider contributing to Devise. Please read this short overview for some information about how to get started:
76
+
77
+ https://github.com/plataformatec/devise/wiki/Contributing
78
+
79
+ 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.
80
+
81
+ ## Starting with Rails?
82
+
83
+ 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:
84
+
85
+ * Michael Hartl's online book: http://railstutorial.org/chapters/modeling-and-viewing-users-two#top
86
+ * Ryan Bates' Railscast: http://railscasts.com/episodes/250-authentication-from-scratch
87
+
88
+ Once you have solidified your understanding of Rails and authentication mechanisms, we assure you Devise will be very pleasant to work with. :)
89
+
90
+ ## Getting started
91
+
92
+ Devise 2.0 works with Rails 3.1 onwards. You can add it to your Gemfile with:
93
+
94
+ ```ruby
95
+ gem 'devise'
96
+ ```
97
+
98
+ Run the bundle command to install it.
99
+
100
+ After you install Devise and add it to your Gemfile, you need to run the generator:
101
+
102
+ ```console
103
+ rails generate devise:install
104
+ ```
105
+
106
+ 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:
107
+
108
+ ```console
109
+ rails generate devise MODEL
110
+ ```
111
+
112
+ Replace MODEL by the class name used for the applications users, it's frequently 'User' but could also be 'Admin'. This will create a model (if one does not exist) and configure it with default Devise modules. Next, you'll usually run "rake db:migrate" as the generator will have created a migration file (if your ORM supports them). This generator also configures your config/routes.rb file to point to Devise controller.
113
+
114
+ 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.
115
+
116
+ ### Controller filters and helpers
117
+
118
+ 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:
119
+
120
+ ```ruby
121
+ before_filter :authenticate_user!
122
+ ```
123
+
124
+ To verify if a user is signed in, use the following helper:
125
+
126
+ ```ruby
127
+ user_signed_in?
128
+ ```
129
+
130
+ For the current signed-in user, this helper is available:
131
+
132
+ ```ruby
133
+ current_user
134
+ ```
135
+
136
+ You can access the session for this scope:
137
+
138
+ ```ruby
139
+ user_session
140
+ ```
141
+
142
+ 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:
143
+
144
+ ```ruby
145
+ root :to => "home#index"
146
+ ```
147
+
148
+ You can also overwrite `after_sign_in_path_for` and `after_sign_out_path_for` to customize your redirect hooks.
149
+
150
+ Finally, you need to set up default url options for the mailer in each environment. Here is the configuration for "config/environments/development.rb":
151
+
152
+ ```ruby
153
+ config.action_mailer.default_url_options = { :host => 'localhost:3000' }
154
+ ```
155
+
156
+ Notice that if your devise model is not called "user" but "member", then the helpers you should use are:
157
+
158
+ ```ruby
159
+ before_filter :authenticate_member!
160
+
161
+ member_signed_in?
162
+
163
+ current_member
164
+
165
+ member_session
166
+ ```
167
+
168
+ ### Configuring Models
169
+
170
+ 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:
171
+
172
+ ```ruby
173
+ devise :database_authenticatable, :registerable, :confirmable, :recoverable, :stretches => 20
174
+ ```
175
+
176
+ 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.
177
+
178
+ ### Configuring multiple models
179
+
180
+ 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:
181
+
182
+ ```ruby
183
+ # Create a migration with the required fields
184
+ create_table :admins do |t|
185
+ t.string :email
186
+ t.string :encrypted_password
187
+ t.timestamps
188
+ end
189
+
190
+ # Inside your Admin model
191
+ devise :database_authenticatable, :timeoutable
192
+
193
+ # Inside your routes
194
+ devise_for :admins
195
+
196
+ # Inside your protected controller
197
+ before_filter :authenticate_admin!
198
+
199
+ # Inside your controllers and views
200
+ admin_signed_in?
201
+ current_admin
202
+ admin_session
203
+ ```
204
+
205
+ On the other hand, you can simply run the generator!
206
+
207
+ ### Configuring views
208
+
209
+ 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.
210
+
211
+ 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:
212
+
213
+ ```console
214
+ rails generate devise:views
215
+ ```
216
+
217
+ 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".
218
+
219
+ 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:
220
+
221
+ ```console
222
+ rails generate devise:views users
223
+ ```
224
+
225
+ ### Configuring controllers
226
+
227
+ If the customization at the views level is not enough, you can customize each controller by following these steps:
228
+
229
+ 1) Create your custom controller, for example a Admins::SessionsController:
230
+
231
+ ```ruby
232
+ class Admins::SessionsController < Devise::SessionsController
233
+ end
234
+ ```
235
+
236
+ 2) Tell the router to use this controller:
237
+
238
+ ```ruby
239
+ devise_for :admins, :controllers => { :sessions => "admins/sessions" }
240
+ ```
241
+
242
+ 3) And since we changed the controller, it won't use the "devise/sessions" views, so remember to copy "devise/sessions" to "admin/sessions".
243
+
244
+ 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.
245
+
246
+ ### Configuring routes
247
+
248
+ 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:
249
+
250
+ ```ruby
251
+ devise_for :users, :path => "usuarios", :path_names => { :sign_in => 'login', :sign_out => 'logout', :password => 'secret', :confirmation => 'verification', :unlock => 'unblock', :registration => 'register', :sign_up => 'cmon_let_me_in' }
252
+ ```
253
+
254
+ Be sure to check `devise_for` documentation for details.
255
+
256
+ 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:
257
+
258
+ ```ruby
259
+ devise_scope :user do
260
+ get "sign_in", :to => "devise/sessions#new"
261
+ end
262
+ ```
263
+
264
+ 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.
265
+
266
+ ### I18n
267
+
268
+ Devise uses flash messages with I18n with the flash keys :notice and :alert. To customize your app, you can set up your locale file:
269
+
270
+ ```yaml
271
+ en:
272
+ devise:
273
+ sessions:
274
+ signed_in: 'Signed in successfully.'
275
+ ```
276
+
277
+ You can also create distinct messages based on the resource you've configured using the singular name given in routes:
278
+
279
+ ```yaml
280
+ en:
281
+ devise:
282
+ sessions:
283
+ user:
284
+ signed_in: 'Welcome user, you are signed in.'
285
+ admin:
286
+ signed_in: 'Hello admin!'
287
+ ```
288
+
289
+ The Devise mailer uses a similar pattern to create subject messages:
290
+
291
+ ```yaml
292
+ en:
293
+ devise:
294
+ mailer:
295
+ confirmation_instructions:
296
+ subject: 'Hello everybody!'
297
+ user_subject: 'Hello User! Please confirm your email'
298
+ reset_password_instructions:
299
+ subject: 'Reset instructions'
300
+ ```
301
+
302
+ 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:
303
+
304
+ https://github.com/plataformatec/devise/wiki/I18n
305
+
306
+ ### Test helpers
307
+
308
+ 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:
309
+
310
+ ```ruby
311
+ sign_in :user, @user # sign_in(scope, resource)
312
+ sign_in @user # sign_in(resource)
313
+
314
+ sign_out :user # sign_out(scope)
315
+ sign_out @user # sign_out(resource)
316
+ ```
317
+
318
+ You can include the Devise Test Helpers in all of your tests by adding the following to the bottom of your test/test_helper.rb file:
319
+
320
+ ```ruby
321
+ class ActionController::TestCase
322
+ include Devise::TestHelpers
323
+ end
324
+ ```
325
+
326
+ If you're using RSpec and want the helpers automatically included within all `describe` blocks, add a file called spec/support/devise.rb with the following contents:
327
+
328
+ ```ruby
329
+ RSpec.configure do |config|
330
+ config.include Devise::TestHelpers, :type => :controller
331
+ end
332
+ ```
333
+
334
+ Do not use such helpers for integration tests such as Cucumber or Webrat. Instead, fill in the form or explicitly set the user in session. For more tips, check the wiki (https://wiki.github.com/plataformatec/devise).
335
+
336
+ ### Omniauth
337
+
338
+ Devise comes with Omniauth support out of the box to authenticate from other providers. You can read more about Omniauth support in the wiki:
339
+
340
+ * https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview
341
+
342
+ ### Other ORMs
343
+
344
+ Devise supports ActiveRecord (default) and Mongoid. To choose other ORM, you just need to require it in the initializer file.
345
+
346
+ ### Migrating from other solutions
347
+
348
+ 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).
349
+
350
+ ## Troubleshooting
351
+
352
+ ### Heroku
353
+
354
+ Using devise on Heroku with Ruby on Rails 3.1 requires setting:
355
+
356
+ ```ruby
357
+ config.assets.initialize_on_precompile = false
358
+ ```
359
+
360
+ Read more about the potential issues at http://guides.rubyonrails.org/asset_pipeline.html
361
+
362
+ ## Additional information
363
+
364
+ ### Warden
365
+
366
+ 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:
367
+
368
+ https://github.com/hassox/warden
369
+
370
+ ### Contributors
371
+
372
+ We have a long list of valued contributors. Check them all at:
373
+
374
+ https://github.com/plataformatec/devise/contributors
375
+
376
+ ### Maintainers
377
+
378
+ * José Valim (https://github.com/josevalim)
379
+ * Carlos Antônio da Silva (https://github.com/carlosantoniodasilva)
380
+ * Rodrigo Flores (https://github.com/rodrigoflores)
381
+
382
+ ## License
383
+
384
+ MIT License. Copyright 2012 Plataformatec. http://plataformatec.com.br