devise 2.1.2 → 3.5.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (242) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +39 -10
  3. data/.yardopts +9 -0
  4. data/{CHANGELOG.rdoc → CHANGELOG.md} +445 -112
  5. data/CODE_OF_CONDUCT.md +22 -0
  6. data/CONTRIBUTING.md +16 -0
  7. data/Gemfile +10 -15
  8. data/Gemfile.lock +151 -129
  9. data/MIT-LICENSE +1 -1
  10. data/README.md +256 -96
  11. data/Rakefile +4 -2
  12. data/app/controllers/devise/confirmations_controller.rb +15 -7
  13. data/app/controllers/devise/omniauth_callbacks_controller.rb +6 -2
  14. data/app/controllers/devise/passwords_controller.rb +33 -9
  15. data/app/controllers/devise/registrations_controller.rb +66 -26
  16. data/app/controllers/devise/sessions_controller.rb +52 -21
  17. data/app/controllers/devise/unlocks_controller.rb +11 -6
  18. data/app/controllers/devise_controller.rb +65 -58
  19. data/app/helpers/devise_helper.rb +2 -2
  20. data/app/mailers/devise/mailer.rb +19 -10
  21. data/app/views/devise/confirmations/new.html.erb +8 -4
  22. data/app/views/devise/mailer/confirmation_instructions.html.erb +2 -2
  23. data/app/views/devise/mailer/password_change.html.erb +3 -0
  24. data/app/views/devise/mailer/reset_password_instructions.html.erb +2 -2
  25. data/app/views/devise/mailer/unlock_instructions.html.erb +2 -2
  26. data/app/views/devise/passwords/edit.html.erb +15 -6
  27. data/app/views/devise/passwords/new.html.erb +8 -4
  28. data/app/views/devise/registrations/edit.html.erb +29 -15
  29. data/app/views/devise/registrations/new.html.erb +19 -8
  30. data/app/views/devise/sessions/new.html.erb +17 -8
  31. data/app/views/devise/shared/{_links.erb → _links.html.erb} +4 -4
  32. data/app/views/devise/unlocks/new.html.erb +8 -4
  33. data/config/locales/en.yml +51 -47
  34. data/devise.gemspec +8 -6
  35. data/devise.png +0 -0
  36. data/gemfiles/Gemfile.rails-3.2-stable +29 -0
  37. data/gemfiles/Gemfile.rails-3.2-stable.lock +172 -0
  38. data/gemfiles/Gemfile.rails-4.0-stable +30 -0
  39. data/gemfiles/Gemfile.rails-4.0-stable.lock +166 -0
  40. data/gemfiles/Gemfile.rails-4.1-stable +30 -0
  41. data/gemfiles/Gemfile.rails-4.1-stable.lock +171 -0
  42. data/gemfiles/Gemfile.rails-4.2-stable +30 -0
  43. data/gemfiles/Gemfile.rails-4.2-stable.lock +193 -0
  44. data/lib/devise/controllers/helpers.rb +126 -108
  45. data/lib/devise/controllers/rememberable.rb +19 -17
  46. data/lib/devise/controllers/scoped_views.rb +1 -1
  47. data/lib/devise/controllers/sign_in_out.rb +96 -0
  48. data/lib/devise/controllers/store_location.rb +58 -0
  49. data/lib/devise/controllers/url_helpers.rb +7 -7
  50. data/lib/devise/encryptor.rb +22 -0
  51. data/lib/devise/failure_app.rb +85 -25
  52. data/lib/devise/hooks/activatable.rb +5 -6
  53. data/lib/devise/hooks/csrf_cleaner.rb +7 -0
  54. data/lib/devise/hooks/forgetable.rb +1 -1
  55. data/lib/devise/hooks/lockable.rb +2 -2
  56. data/lib/devise/hooks/proxy.rb +21 -0
  57. data/lib/devise/hooks/rememberable.rb +5 -4
  58. data/lib/devise/hooks/timeoutable.rb +16 -8
  59. data/lib/devise/hooks/trackable.rb +1 -1
  60. data/lib/devise/mailers/helpers.rb +27 -23
  61. data/lib/devise/mapping.rb +11 -7
  62. data/lib/devise/models/authenticatable.rb +82 -66
  63. data/lib/devise/models/confirmable.rb +142 -55
  64. data/lib/devise/models/database_authenticatable.rb +59 -15
  65. data/lib/devise/models/lockable.rb +41 -30
  66. data/lib/devise/models/omniauthable.rb +3 -3
  67. data/lib/devise/models/recoverable.rb +56 -41
  68. data/lib/devise/models/rememberable.rb +65 -27
  69. data/lib/devise/models/timeoutable.rb +2 -8
  70. data/lib/devise/models/trackable.rb +6 -4
  71. data/lib/devise/models/validatable.rb +9 -9
  72. data/lib/devise/models.rb +4 -13
  73. data/lib/devise/modules.rb +10 -11
  74. data/lib/devise/omniauth/url_helpers.rb +2 -2
  75. data/lib/devise/orm/active_record.rb +1 -1
  76. data/lib/devise/orm/mongoid.rb +1 -1
  77. data/lib/devise/{param_filter.rb → parameter_filter.rb} +10 -11
  78. data/lib/devise/parameter_sanitizer.rb +99 -0
  79. data/lib/devise/rails/routes.rb +173 -115
  80. data/lib/devise/rails/warden_compat.rb +10 -31
  81. data/lib/devise/rails.rb +14 -12
  82. data/lib/devise/strategies/authenticatable.rb +26 -26
  83. data/lib/devise/strategies/base.rb +1 -1
  84. data/lib/devise/strategies/database_authenticatable.rb +8 -4
  85. data/lib/devise/strategies/rememberable.rb +15 -5
  86. data/lib/devise/test_helpers.rb +7 -5
  87. data/lib/devise/time_inflector.rb +14 -0
  88. data/lib/devise/token_generator.rb +70 -0
  89. data/lib/devise/version.rb +1 -1
  90. data/lib/devise.rb +110 -52
  91. data/lib/generators/active_record/devise_generator.rb +34 -18
  92. data/lib/generators/active_record/templates/migration.rb +5 -6
  93. data/lib/generators/active_record/templates/migration_existing.rb +5 -6
  94. data/lib/generators/devise/controllers_generator.rb +44 -0
  95. data/lib/generators/devise/devise_generator.rb +5 -3
  96. data/lib/generators/devise/install_generator.rb +5 -0
  97. data/lib/generators/devise/orm_helpers.rb +25 -6
  98. data/lib/generators/devise/views_generator.rb +52 -22
  99. data/lib/generators/mongoid/devise_generator.rb +21 -26
  100. data/lib/generators/templates/README +9 -5
  101. data/lib/generators/templates/controllers/README +14 -0
  102. data/lib/generators/templates/controllers/confirmations_controller.rb +28 -0
  103. data/lib/generators/templates/controllers/omniauth_callbacks_controller.rb +28 -0
  104. data/lib/generators/templates/controllers/passwords_controller.rb +32 -0
  105. data/lib/generators/templates/controllers/registrations_controller.rb +60 -0
  106. data/lib/generators/templates/controllers/sessions_controller.rb +25 -0
  107. data/lib/generators/templates/controllers/unlocks_controller.rb +28 -0
  108. data/lib/generators/templates/devise.rb +80 -43
  109. data/lib/generators/templates/markerb/confirmation_instructions.markerb +2 -2
  110. data/lib/generators/templates/markerb/password_change.markerb +3 -0
  111. data/lib/generators/templates/markerb/reset_password_instructions.markerb +1 -1
  112. data/lib/generators/templates/markerb/unlock_instructions.markerb +2 -2
  113. data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +3 -2
  114. data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +4 -4
  115. data/lib/generators/templates/simple_form_for/passwords/new.html.erb +2 -2
  116. data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +11 -6
  117. data/lib/generators/templates/simple_form_for/registrations/new.html.erb +4 -4
  118. data/lib/generators/templates/simple_form_for/sessions/new.html.erb +6 -6
  119. data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +3 -2
  120. data/script/cached-bundle +49 -0
  121. data/script/s3-put +71 -0
  122. data/test/controllers/custom_registrations_controller_test.rb +40 -0
  123. data/test/controllers/helper_methods_test.rb +21 -0
  124. data/test/controllers/helpers_test.rb +95 -32
  125. data/test/controllers/inherited_controller_i18n_messages_test.rb +51 -0
  126. data/test/controllers/internal_helpers_test.rb +39 -14
  127. data/test/controllers/load_hooks_controller_test.rb +19 -0
  128. data/test/controllers/passwords_controller_test.rb +31 -0
  129. data/test/controllers/sessions_controller_test.rb +66 -6
  130. data/test/controllers/url_helpers_test.rb +10 -4
  131. data/test/delegator_test.rb +1 -1
  132. data/test/devise_test.rb +45 -10
  133. data/test/failure_app_test.rb +121 -27
  134. data/test/generators/active_record_generator_test.rb +48 -8
  135. data/test/generators/controllers_generator_test.rb +48 -0
  136. data/test/generators/devise_generator_test.rb +2 -2
  137. data/test/generators/mongoid_generator_test.rb +3 -3
  138. data/test/generators/views_generator_test.rb +54 -3
  139. data/test/helpers/devise_helper_test.rb +18 -20
  140. data/test/integration/authenticatable_test.rb +161 -65
  141. data/test/integration/confirmable_test.rb +146 -77
  142. data/test/integration/database_authenticatable_test.rb +43 -30
  143. data/test/integration/http_authenticatable_test.rb +30 -22
  144. data/test/integration/lockable_test.rb +64 -49
  145. data/test/integration/omniauthable_test.rb +17 -15
  146. data/test/integration/recoverable_test.rb +111 -70
  147. data/test/integration/registerable_test.rb +114 -79
  148. data/test/integration/rememberable_test.rb +87 -31
  149. data/test/integration/timeoutable_test.rb +77 -33
  150. data/test/integration/trackable_test.rb +5 -5
  151. data/test/mailers/confirmation_instructions_test.rb +28 -8
  152. data/test/mailers/reset_password_instructions_test.rb +21 -8
  153. data/test/mailers/unlock_instructions_test.rb +20 -6
  154. data/test/mapping_test.rb +12 -5
  155. data/test/models/authenticatable_test.rb +17 -1
  156. data/test/models/confirmable_test.rb +216 -62
  157. data/test/models/database_authenticatable_test.rb +129 -49
  158. data/test/models/lockable_test.rb +132 -45
  159. data/test/models/recoverable_test.rb +100 -54
  160. data/test/models/rememberable_test.rb +89 -94
  161. data/test/models/serializable_test.rb +12 -11
  162. data/test/models/timeoutable_test.rb +6 -1
  163. data/test/models/trackable_test.rb +28 -0
  164. data/test/models/validatable_test.rb +31 -21
  165. data/test/models_test.rb +22 -48
  166. data/test/omniauth/config_test.rb +4 -4
  167. data/test/omniauth/url_helpers_test.rb +7 -4
  168. data/test/orm/active_record.rb +1 -0
  169. data/test/orm/mongoid.rb +2 -3
  170. data/test/parameter_sanitizer_test.rb +81 -0
  171. data/test/rails_app/Rakefile +0 -4
  172. data/test/rails_app/app/active_record/shim.rb +1 -1
  173. data/test/rails_app/app/active_record/user_on_engine.rb +7 -0
  174. data/test/rails_app/app/active_record/user_on_main_app.rb +7 -0
  175. data/test/rails_app/app/active_record/user_without_email.rb +8 -0
  176. data/test/rails_app/app/controllers/admins/sessions_controller.rb +1 -1
  177. data/test/rails_app/app/controllers/admins_controller.rb +0 -5
  178. data/test/rails_app/app/controllers/application_controller.rb +6 -2
  179. data/test/rails_app/app/controllers/application_with_fake_engine.rb +30 -0
  180. data/test/rails_app/app/controllers/custom/registrations_controller.rb +31 -0
  181. data/test/rails_app/app/controllers/home_controller.rb +1 -1
  182. data/test/rails_app/app/controllers/publisher/registrations_controller.rb +1 -1
  183. data/test/rails_app/app/controllers/publisher/sessions_controller.rb +1 -1
  184. data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +4 -4
  185. data/test/rails_app/app/controllers/users_controller.rb +12 -4
  186. data/test/rails_app/app/mailers/users/from_proc_mailer.rb +3 -0
  187. data/test/rails_app/app/mailers/users/mailer.rb +1 -1
  188. data/test/rails_app/app/mailers/users/reply_to_mailer.rb +4 -0
  189. data/test/rails_app/app/mongoid/admin.rb +12 -10
  190. data/test/rails_app/app/mongoid/shim.rb +4 -5
  191. data/test/rails_app/app/mongoid/user.rb +19 -22
  192. data/test/rails_app/app/mongoid/user_on_engine.rb +39 -0
  193. data/test/rails_app/app/mongoid/user_on_main_app.rb +39 -0
  194. data/test/rails_app/app/mongoid/user_without_email.rb +33 -0
  195. data/test/rails_app/app/views/admins/sessions/new.html.erb +1 -1
  196. data/test/rails_app/app/views/home/admin_dashboard.html.erb +1 -1
  197. data/test/rails_app/app/views/home/index.html.erb +1 -1
  198. data/test/rails_app/app/views/home/join.html.erb +1 -1
  199. data/test/rails_app/app/views/home/user_dashboard.html.erb +1 -1
  200. data/test/rails_app/app/views/layouts/application.html.erb +1 -1
  201. data/test/rails_app/app/views/users/edit_form.html.erb +1 -0
  202. data/test/rails_app/bin/bundle +3 -0
  203. data/test/rails_app/bin/rails +4 -0
  204. data/test/rails_app/bin/rake +4 -0
  205. data/test/rails_app/config/application.rb +4 -5
  206. data/test/rails_app/config/boot.rb +9 -3
  207. data/test/rails_app/config/environment.rb +2 -2
  208. data/test/rails_app/config/environments/development.rb +19 -7
  209. data/test/rails_app/config/environments/production.rb +68 -17
  210. data/test/rails_app/config/environments/test.rb +24 -16
  211. data/test/rails_app/config/initializers/devise.rb +22 -20
  212. data/test/rails_app/config/initializers/secret_token.rb +8 -2
  213. data/test/rails_app/config/initializers/session_store.rb +1 -0
  214. data/test/rails_app/config/routes.rb +71 -46
  215. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +9 -12
  216. data/test/rails_app/db/schema.rb +21 -18
  217. data/test/rails_app/lib/shared_admin.rb +7 -4
  218. data/test/rails_app/lib/shared_user.rb +6 -3
  219. data/test/rails_app/lib/shared_user_without_email.rb +26 -0
  220. data/test/rails_app/lib/shared_user_without_omniauth.rb +13 -0
  221. data/test/rails_test.rb +9 -0
  222. data/test/routes_test.rb +94 -78
  223. data/test/support/action_controller/record_identifier.rb +10 -0
  224. data/test/support/assertions.rb +2 -3
  225. data/test/support/helpers.rb +18 -32
  226. data/test/support/integration.rb +17 -16
  227. data/test/support/locale/en.yml +4 -0
  228. data/test/support/mongoid.yml +6 -0
  229. data/test/test_helper.rb +8 -1
  230. data/test/test_helpers_test.rb +64 -20
  231. data/test/test_models.rb +33 -0
  232. data/test/time_helpers.rb +137 -0
  233. metadata +172 -51
  234. data/app/views/devise/_links.erb +0 -3
  235. data/gemfiles/Gemfile.rails-3.1.x +0 -35
  236. data/gemfiles/Gemfile.rails-3.1.x.lock +0 -167
  237. data/lib/devise/models/token_authenticatable.rb +0 -77
  238. data/lib/devise/strategies/token_authenticatable.rb +0 -56
  239. data/test/indifferent_hash.rb +0 -33
  240. data/test/integration/token_authenticatable_test.rb +0 -161
  241. data/test/models/token_authenticatable_test.rb +0 -55
  242. data/test/rails_app/script/rails +0 -10
@@ -0,0 +1,22 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality.
6
+
7
+ Examples of unacceptable behavior by participants include:
8
+
9
+ * The use of sexualized language or imagery
10
+ * Personal attacks
11
+ * Trolling or insulting/derogatory comments
12
+ * Public or private harassment
13
+ * Publishing other's private information, such as physical or electronic addresses, without explicit permission
14
+ * Other unethical or unprofessional conduct.
15
+
16
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team.
17
+
18
+ This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community.
19
+
20
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by sending an email to [conduct@plataformatec.com.br](conduct@plataformatec.com.br) or contacting one or more of the project maintainers.
21
+
22
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.2.0, available at [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/)
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,16 @@
1
+ ### Please read before contributing
2
+
3
+ 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).
4
+
5
+ 2) If you find a security bug, **DO NOT** submit an issue here. Please send an e-mail to [opensource@plataformatec.com.br](mailto:opensource@plataformatec.com.br) instead.
6
+
7
+ 3) Do a small search on the issues tracker before submitting your issue to see if it was already reported / fixed.
8
+
9
+ 4) When reporting an issue, include Rails, Devise and Warden versions. If you are getting exceptions, please include the full backtrace.
10
+
11
+ 5) Notice that all of your interactions in the project are expected to follow our [Code of Conduct](CODE_OF_CONDUCT.md)
12
+
13
+ That's it! The more information you give, the easier it becomes for us to track it down and fix it.
14
+ Ideally, you should provide an application that reproduces the error or a test case to Devise's suite.
15
+
16
+ Thanks!
data/Gemfile CHANGED
@@ -1,21 +1,18 @@
1
- source "http://rubygems.org"
1
+ source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
- gem "rails", "~> 3.2.6"
6
- gem "omniauth", "~> 1.0.0"
7
- gem "omniauth-oauth2", "~> 1.0.0"
5
+ gem "rails", "4.2.2"
6
+ gem "omniauth", "~> 1.2.0"
7
+ gem "omniauth-oauth2", "~> 1.1.0"
8
8
  gem "rdoc"
9
+ gem "mime-types", "~> 2.99"
9
10
 
10
11
  group :test do
11
12
  gem "omniauth-facebook"
12
13
  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
14
+ gem "webrat", "0.7.3", require: false
15
+ gem "mocha", "~> 1.1", require: false
19
16
  end
20
17
 
21
18
  platforms :jruby do
@@ -26,10 +23,8 @@ end
26
23
 
27
24
  platforms :ruby do
28
25
  gem "sqlite3"
26
+ end
29
27
 
30
- group :mongoid do
31
- gem "mongo", "~> 1.3.0"
32
- gem "mongoid", "~> 2.0"
33
- gem "bson_ext", "~> 1.3.0"
34
- end
28
+ group :mongoid do
29
+ gem "mongoid", "~> 4.0"
35
30
  end
data/Gemfile.lock CHANGED
@@ -1,143 +1,164 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- devise (2.1.2)
5
- bcrypt-ruby (~> 3.0)
4
+ devise (3.5.10)
5
+ bcrypt (~> 3.0)
6
6
  orm_adapter (~> 0.1)
7
- railties (~> 3.1)
8
- warden (~> 1.2.1)
7
+ railties (>= 3.2.6, < 5)
8
+ responders
9
+ thread_safe (~> 0.1)
10
+ warden (~> 1.2.3)
9
11
 
10
12
  GEM
11
- remote: http://rubygems.org/
13
+ remote: https://rubygems.org/
12
14
  specs:
13
- actionmailer (3.2.6)
14
- actionpack (= 3.2.6)
15
- mail (~> 2.4.4)
16
- actionpack (3.2.6)
17
- activemodel (= 3.2.6)
18
- activesupport (= 3.2.6)
19
- builder (~> 3.0.0)
15
+ actionmailer (4.2.2)
16
+ actionpack (= 4.2.2)
17
+ actionview (= 4.2.2)
18
+ activejob (= 4.2.2)
19
+ mail (~> 2.5, >= 2.5.4)
20
+ rails-dom-testing (~> 1.0, >= 1.0.5)
21
+ actionpack (4.2.2)
22
+ actionview (= 4.2.2)
23
+ activesupport (= 4.2.2)
24
+ rack (~> 1.6)
25
+ rack-test (~> 0.6.2)
26
+ rails-dom-testing (~> 1.0, >= 1.0.5)
27
+ rails-html-sanitizer (~> 1.0, >= 1.0.1)
28
+ actionview (4.2.2)
29
+ activesupport (= 4.2.2)
30
+ builder (~> 3.1)
20
31
  erubis (~> 2.7.0)
21
- journey (~> 1.0.1)
22
- rack (~> 1.4.0)
23
- rack-cache (~> 1.2)
24
- rack-test (~> 0.6.1)
25
- sprockets (~> 2.1.3)
26
- activemodel (3.2.6)
27
- activesupport (= 3.2.6)
28
- builder (~> 3.0.0)
29
- activerecord (3.2.6)
30
- activemodel (= 3.2.6)
31
- activesupport (= 3.2.6)
32
- arel (~> 3.0.2)
33
- tzinfo (~> 0.3.29)
34
- activeresource (3.2.6)
35
- activemodel (= 3.2.6)
36
- activesupport (= 3.2.6)
37
- activesupport (3.2.6)
38
- i18n (~> 0.6)
39
- multi_json (~> 1.0)
40
- addressable (2.2.6)
41
- arel (3.0.2)
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)
32
+ rails-dom-testing (~> 1.0, >= 1.0.5)
33
+ rails-html-sanitizer (~> 1.0, >= 1.0.1)
34
+ activejob (4.2.2)
35
+ activesupport (= 4.2.2)
36
+ globalid (>= 0.3.0)
37
+ activemodel (4.2.2)
38
+ activesupport (= 4.2.2)
39
+ builder (~> 3.1)
40
+ activerecord (4.2.2)
41
+ activemodel (= 4.2.2)
42
+ activesupport (= 4.2.2)
43
+ arel (~> 6.0)
44
+ activesupport (4.2.2)
45
+ i18n (~> 0.7)
46
+ json (~> 1.7, >= 1.7.7)
47
+ minitest (~> 5.1)
48
+ thread_safe (~> 0.3, >= 0.3.4)
49
+ tzinfo (~> 1.1)
50
+ arel (6.0.3)
51
+ bcrypt (3.1.11)
52
+ bson (3.2.6)
53
+ builder (3.2.2)
54
+ concurrent-ruby (1.0.1)
55
+ connection_pool (2.2.0)
47
56
  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.4)
56
- json (1.7.3)
57
- linecache (0.46)
58
- rbx-require-relative (> 0.0.4)
59
- mail (2.4.4)
60
- i18n (>= 0.4.0)
61
- mime-types (~> 1.16)
62
- treetop (~> 1.4.8)
63
- metaclass (0.0.1)
64
- mime-types (1.18)
65
- mocha (0.10.0)
57
+ faraday (0.9.2)
58
+ multipart-post (>= 1.2, < 3)
59
+ globalid (0.3.6)
60
+ activesupport (>= 4.1.0)
61
+ hashie (3.4.3)
62
+ i18n (0.7.0)
63
+ json (1.8.3)
64
+ jwt (1.5.4)
65
+ loofah (2.0.3)
66
+ nokogiri (>= 1.5.9)
67
+ mail (2.6.4)
68
+ mime-types (>= 1.16, < 4)
69
+ metaclass (0.0.4)
70
+ mime-types (2.99.1)
71
+ mini_portile2 (2.0.0)
72
+ minitest (5.8.4)
73
+ mocha (1.1.0)
66
74
  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)
75
+ mongoid (4.0.2)
76
+ activemodel (~> 4.0)
77
+ moped (~> 2.0.0)
78
+ origin (~> 2.1)
79
+ tzinfo (>= 0.3.37)
80
+ moped (2.0.7)
81
+ bson (~> 3.0)
82
+ connection_pool (~> 2.0)
83
+ optionable (~> 0.2.0)
84
+ multi_json (1.11.3)
85
+ multi_xml (0.5.5)
86
+ multipart-post (2.0.0)
87
+ nokogiri (1.6.7.2)
88
+ mini_portile2 (~> 2.0.0.rc2)
89
+ oauth2 (0.9.4)
90
+ faraday (>= 0.8, < 0.10)
91
+ jwt (~> 1.0)
92
+ multi_json (~> 1.3)
93
+ multi_xml (~> 0.5)
94
+ rack (~> 1.2)
95
+ omniauth (1.2.2)
96
+ hashie (>= 1.2, < 4)
97
+ rack (~> 1.0)
98
+ omniauth-facebook (1.6.0)
99
+ omniauth-oauth2 (~> 1.1)
100
+ omniauth-oauth2 (1.1.2)
101
+ faraday (>= 0.8, < 0.10)
102
+ multi_json (~> 1.3)
103
+ oauth2 (~> 0.9.3)
104
+ omniauth (~> 1.2)
87
105
  omniauth-openid (1.0.1)
88
106
  omniauth (~> 1.0)
89
107
  rack-openid (~> 1.3.1)
90
- orm_adapter (0.1.0)
91
- polyglot (0.3.3)
92
- rack (1.4.1)
93
- rack-cache (1.2)
94
- rack (>= 0.4)
108
+ optionable (0.2.0)
109
+ origin (2.2.0)
110
+ orm_adapter (0.5.0)
111
+ rack (1.6.4)
95
112
  rack-openid (1.3.1)
96
113
  rack (>= 1.1.0)
97
114
  ruby-openid (>= 2.1.8)
98
- rack-ssl (1.3.2)
99
- rack
100
- rack-test (0.6.1)
115
+ rack-test (0.6.3)
101
116
  rack (>= 1.0)
102
- rails (3.2.6)
103
- actionmailer (= 3.2.6)
104
- actionpack (= 3.2.6)
105
- activerecord (= 3.2.6)
106
- activeresource (= 3.2.6)
107
- activesupport (= 3.2.6)
108
- bundler (~> 1.0)
109
- railties (= 3.2.6)
110
- railties (3.2.6)
111
- actionpack (= 3.2.6)
112
- activesupport (= 3.2.6)
113
- rack-ssl (~> 1.3.2)
117
+ rails (4.2.2)
118
+ actionmailer (= 4.2.2)
119
+ actionpack (= 4.2.2)
120
+ actionview (= 4.2.2)
121
+ activejob (= 4.2.2)
122
+ activemodel (= 4.2.2)
123
+ activerecord (= 4.2.2)
124
+ activesupport (= 4.2.2)
125
+ bundler (>= 1.3.0, < 2.0)
126
+ railties (= 4.2.2)
127
+ sprockets-rails
128
+ rails-deprecated_sanitizer (1.0.3)
129
+ activesupport (>= 4.2.0.alpha)
130
+ rails-dom-testing (1.0.7)
131
+ activesupport (>= 4.2.0.beta, < 5.0)
132
+ nokogiri (~> 1.6.0)
133
+ rails-deprecated_sanitizer (>= 1.0.1)
134
+ rails-html-sanitizer (1.0.3)
135
+ loofah (~> 2.0)
136
+ railties (4.2.2)
137
+ actionpack (= 4.2.2)
138
+ activesupport (= 4.2.2)
114
139
  rake (>= 0.8.7)
115
- rdoc (~> 3.4)
116
- thor (>= 0.14.6, < 2.0)
117
- rake (0.9.2.2)
118
- rbx-require-relative (0.0.5)
119
- rdoc (3.12)
140
+ thor (>= 0.18.1, < 2.0)
141
+ rake (11.1.2)
142
+ rdoc (4.2.2)
120
143
  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.3)
128
- hike (~> 1.2)
129
- rack (~> 1.0)
130
- tilt (~> 1.1, != 1.3.0)
131
- sqlite3 (1.3.5)
132
- thor (0.15.2)
133
- tilt (1.3.3)
134
- treetop (1.4.10)
135
- polyglot
136
- polyglot (>= 0.3.1)
137
- tzinfo (0.3.33)
138
- warden (1.2.1)
144
+ responders (2.2.0)
145
+ railties (>= 4.2.0, < 5.1)
146
+ ruby-openid (2.7.0)
147
+ sprockets (3.6.0)
148
+ concurrent-ruby (~> 1.0)
149
+ rack (> 1, < 3)
150
+ sprockets-rails (3.0.4)
151
+ actionpack (>= 4.0)
152
+ activesupport (>= 4.0)
153
+ sprockets (>= 3.0.0)
154
+ sqlite3 (1.3.11)
155
+ thor (0.19.1)
156
+ thread_safe (0.3.5)
157
+ tzinfo (1.2.2)
158
+ thread_safe (~> 0.1)
159
+ warden (1.2.6)
139
160
  rack (>= 1.0)
140
- webrat (0.7.2)
161
+ webrat (0.7.3)
141
162
  nokogiri (>= 1.2.0)
142
163
  rack (>= 1.0)
143
164
  rack-test (>= 0.5.3)
@@ -148,18 +169,19 @@ PLATFORMS
148
169
  DEPENDENCIES
149
170
  activerecord-jdbc-adapter
150
171
  activerecord-jdbcsqlite3-adapter
151
- bson_ext (~> 1.3.0)
152
172
  devise!
153
173
  jruby-openssl
154
- mocha
155
- mongo (~> 1.3.0)
156
- mongoid (~> 2.0)
157
- omniauth (~> 1.0.0)
174
+ mime-types (~> 2.99)
175
+ mocha (~> 1.1)
176
+ mongoid (~> 4.0)
177
+ omniauth (~> 1.2.0)
158
178
  omniauth-facebook
159
- omniauth-oauth2 (~> 1.0.0)
179
+ omniauth-oauth2 (~> 1.1.0)
160
180
  omniauth-openid (~> 1.0.1)
161
- rails (~> 3.2.6)
181
+ rails (= 4.2.2)
162
182
  rdoc
163
- ruby-debug (>= 0.10.3)
164
183
  sqlite3
165
- webrat (= 0.7.2)
184
+ webrat (= 0.7.3)
185
+
186
+ BUNDLED WITH
187
+ 1.12.3
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2009-2012 Plataformatec. http://plataformatec.com.br
1
+ Copyright 2009-2015 Plataformatec. http://plataformatec.com.br
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,39 +1,42 @@
1
- *IMPORTANT:* Devise 2.1 is out. If you are upgrading, please read: https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.1
1
+ ![Devise Logo](https://raw.github.com/plataformatec/devise/master/devise.png)
2
2
 
3
- ## Devise
3
+ By [Plataformatec](http://plataformatec.com.br/).
4
4
 
5
- INFO: This README is [also available in a friendly navigable format](http://devise.plataformatec.com.br/).
5
+ [![Build Status](https://api.travis-ci.org/plataformatec/devise.svg?branch=master)](http://travis-ci.org/plataformatec/devise)
6
+ [![Code Climate](https://codeclimate.com/github/plataformatec/devise.svg)](https://codeclimate.com/github/plataformatec/devise)
7
+ [![Security](https://hakiri.io/github/plataformatec/devise/master.svg)](https://hakiri.io/github/plataformatec/devise/master)
6
8
 
7
- [![Build Status](https://secure.travis-ci.org/plataformatec/devise.png)](http://travis-ci.org/plataformatec/devise) [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/plataformatec/devise)
9
+ This README is [also available in a friendly navigable format](http://devise.plataformatec.com.br/).
8
10
 
9
11
  Devise is a flexible authentication solution for Rails based on Warden. It:
10
12
 
11
13
  * Is Rack based;
12
14
  * 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
+ * Allows you to have multiple models signed in at the same time;
16
+ * Is based on a modularity concept: use only what you really need.
15
17
 
16
- It's composed of 12 modules:
18
+ It's composed of 10 modules:
17
19
 
18
20
  * [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.
19
- * [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.
20
- * [Omniauthable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Omniauthable): adds Omniauth (https://github.com/intridea/omniauth) support;
21
+ * [Omniauthable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Omniauthable): adds OmniAuth (https://github.com/intridea/omniauth) support.
21
22
  * [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.
22
23
  * [Recoverable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Recoverable): resets the user password and sends reset instructions.
23
24
  * [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.
24
25
  * [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.
25
26
  * [Trackable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Trackable): tracks sign in count, timestamps and IP address.
26
- * [Timeoutable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Timeoutable): expires sessions that have no activity in a specified period of time.
27
+ * [Timeoutable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Timeoutable): expires sessions that have not been active in a specified period of time.
27
28
  * [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.
28
29
  * [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.
29
30
 
31
+ Devise is guaranteed to be thread-safe on YARV. Thread-safety support on JRuby is in progress.
32
+
30
33
  ## Information
31
34
 
32
35
  ### The Devise wiki
33
36
 
34
37
  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:
35
38
 
36
- https://wiki.github.com/plataformatec/devise
39
+ https://github.com/plataformatec/devise/wiki
37
40
 
38
41
  ### Bug reports
39
42
 
@@ -41,7 +44,7 @@ If you discover a problem with Devise, we would like to know about it. However,
41
44
 
42
45
  https://github.com/plataformatec/devise/wiki/Bug-reports
43
46
 
44
- 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.
47
+ If you have discovered a security related bug, please do *NOT* use the GitHub issue tracker. Send an email to opensource@plataformatec.com.br.
45
48
 
46
49
  ### Mailing list
47
50
 
@@ -55,7 +58,7 @@ You can view the Devise documentation in RDoc format here:
55
58
 
56
59
  http://rubydoc.info/github/plataformatec/devise/master/frames
57
60
 
58
- 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.
61
+ If you need to use Devise with previous versions of Rails, you can always run "gem server" from the command line after you install the gem to access the old documentation.
59
62
 
60
63
  ### Example applications
61
64
 
@@ -79,16 +82,17 @@ You will usually want to write tests for your changes. To run the test suite, g
79
82
 
80
83
  ## Starting with Rails?
81
84
 
82
- 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:
85
+ If you are building your first Rails application, we recommend you *do not* use Devise. Devise requires a good understanding of the Rails Framework. In such cases, we advise you to start a simple authentication system from scratch. Today, we have three resources that should help you get started:
83
86
 
84
- * Michael Hartl's online book: http://railstutorial.org/chapters/modeling-and-viewing-users-two#top
87
+ * Michael Hartl's online book: https://www.railstutorial.org/book/modeling_users
85
88
  * Ryan Bates' Railscast: http://railscasts.com/episodes/250-authentication-from-scratch
89
+ * Codecademy's Ruby on Rails: Authentication and Authorization: http://www.codecademy.com/en/learn/rails-auth
86
90
 
87
- Once you have solidified your understanding of Rails and authentication mechanisms, we assure you Devise will be very pleasant to work with. :)
91
+ Once you have solidified your understanding of Rails and authentication mechanisms, we assure you Devise will be very pleasant to work with. :smiley:
88
92
 
89
93
  ## Getting started
90
94
 
91
- Devise 2.0 works with Rails 3.1 onwards. You can add it to your Gemfile with:
95
+ Devise 3.0 works with Rails 3.2 onwards. You can add it to your Gemfile with:
92
96
 
93
97
  ```ruby
94
98
  gem 'devise'
@@ -102,24 +106,34 @@ After you install Devise and add it to your Gemfile, you need to run the generat
102
106
  rails generate devise:install
103
107
  ```
104
108
 
105
- 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:
109
+ The generator will install an initializer which describes ALL of Devise's configuration options. It is *imperative* that you take a look at it. When you are done, you are ready to add Devise to any of your models using the generator:
106
110
 
107
111
  ```console
108
112
  rails generate devise MODEL
109
113
  ```
110
114
 
111
- 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.
115
+ Replace MODEL with the class name used for the application’s users (its frequently `User` but could also be `Admin`). This will create a model (if one does not exist) and configure it with default Devise modules. The generator also configures your `config/routes.rb` file to point to the Devise controller.
116
+
117
+ Next, check the MODEL for any additional configuration options you might want to add, such as confirmable or lockable. If you add an option, be sure to inspect the migration file (created by the generator if your ORM supports them) and uncomment the appropriate section. For example, if you add the confirmable option in the model, you'll need to uncomment the Confirmable section in the migration. Then run `rake db:migrate`
118
+
119
+ Next, you need to set up the default URL options for the Devise mailer in each environment. Here is a possible configuration for `config/environments/development.rb`:
120
+
121
+ ```ruby
122
+ config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
123
+ ```
112
124
 
113
- 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.
125
+ You should restart your application after changing Devise's configuration options. Otherwise, you will run into strange errors, for example, users being unable to login and route helpers being undefined.
114
126
 
115
127
  ### Controller filters and helpers
116
128
 
117
- 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:
129
+ Devise will create some helpers to use inside your controllers and views. To set up a controller with user authentication, just add this before_action (assuming your devise model is 'User'):
118
130
 
119
131
  ```ruby
120
- before_filter :authenticate_user!
132
+ before_action :authenticate_user!
121
133
  ```
122
134
 
135
+ If your devise model is something other than User, replace "_user" with "_yourmodel". The same logic applies to the instructions below.
136
+
123
137
  To verify if a user is signed in, use the following helper:
124
138
 
125
139
  ```ruby
@@ -138,24 +152,18 @@ You can access the session for this scope:
138
152
  user_session
139
153
  ```
140
154
 
141
- 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:
155
+ After signing in a user, confirming the account or updating the password, Devise will look for a scoped root path to redirect to. For instance, when using a `:user` resource, the `user_root_path` will be used if it exists; otherwise, the default `root_path` will be used. This means that you need to set the root inside your routes:
142
156
 
143
157
  ```ruby
144
- root :to => "home#index"
158
+ root to: "home#index"
145
159
  ```
146
160
 
147
- You can also overwrite `after_sign_in_path_for` and `after_sign_out_path_for` to customize your redirect hooks.
148
-
149
- Finally, you need to set up default url options for the mailer in each environment. Here is the configuration for "config/environments/development.rb":
161
+ You can also override `after_sign_in_path_for` and `after_sign_out_path_for` to customize your redirect hooks.
150
162
 
151
- ```ruby
152
- config.action_mailer.default_url_options = { :host => 'localhost:3000' }
153
- ```
154
-
155
- Notice that if your devise model is not called "user" but "member", then the helpers you should use are:
163
+ Notice that if your Devise model is called `Member` instead of `User`, for example, then the helpers available are:
156
164
 
157
165
  ```ruby
158
- before_filter :authenticate_member!
166
+ before_action :authenticate_member!
159
167
 
160
168
  member_signed_in?
161
169
 
@@ -166,42 +174,86 @@ member_session
166
174
 
167
175
  ### Configuring Models
168
176
 
169
- 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:
177
+ 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:
170
178
 
171
179
  ```ruby
172
- devise :database_authenticatable, :registerable, :confirmable, :recoverable, :stretches => 20
180
+ devise :database_authenticatable, :registerable, :confirmable, :recoverable, stretches: 20
173
181
  ```
174
182
 
175
- 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.
183
+ Besides `:stretches`, you can define `:pepper`, `:encryptor`, `:confirm_within`, `:remember_for`, `:timeout_in`, `:unlock_in` among other options. For more details, see the initializer file that was created when you invoked the "devise:install" generator described above. This file is usually located at `/config/initializers/devise.rb`.
176
184
 
177
- ### Configuring multiple models
185
+ ### Strong Parameters
178
186
 
179
- 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:
187
+ When you customize your own views, you may end up adding new attributes to forms. Rails 4 moved the parameter sanitization from the model to the controller, causing Devise to handle this concern at the controller as well.
188
+
189
+ There are just three actions in Devise that allow any set of parameters to be passed down to the model, therefore requiring sanitization. Their names and the permitted parameters by default are:
190
+
191
+ * `sign_in` (`Devise::SessionsController#create`) - Permits only the authentication keys (like `email`)
192
+ * `sign_up` (`Devise::RegistrationsController#create`) - Permits authentication keys plus `password` and `password_confirmation`
193
+ * `account_update` (`Devise::RegistrationsController#update`) - Permits authentication keys plus `password`, `password_confirmation` and `current_password`
194
+
195
+ In case you want to permit additional parameters (the lazy way™), you can do so using a simple before filter in your `ApplicationController`:
180
196
 
181
197
  ```ruby
182
- # Create a migration with the required fields
183
- create_table :admins do |t|
184
- t.string :email
185
- t.string :encrypted_password
186
- t.timestamps
198
+ class ApplicationController < ActionController::Base
199
+ before_action :configure_permitted_parameters, if: :devise_controller?
200
+
201
+ protected
202
+
203
+ def configure_permitted_parameters
204
+ devise_parameter_sanitizer.for(:sign_up) << :username
205
+ end
187
206
  end
207
+ ```
188
208
 
189
- # Inside your Admin model
190
- devise :database_authenticatable, :timeoutable
209
+ The above works for any additional fields where the parameters are simple scalar types. If you have nested attributes (say you're using `accepts_nested_attributes_for`), then you will need to tell devise about those nestings and types. Devise allows you to completely change Devise defaults or invoke custom behaviour by passing a block:
191
210
 
192
- # Inside your routes
193
- devise_for :admins
211
+ To permit simple scalar values for username and email, use this
194
212
 
195
- # Inside your protected controller
196
- before_filter :authenticate_admin!
213
+ ```ruby
214
+ def configure_permitted_parameters
215
+ devise_parameter_sanitizer.for(:sign_in) { |u| u.permit(:username, :email) }
216
+ end
217
+ ```
197
218
 
198
- # Inside your controllers and views
199
- admin_signed_in?
200
- current_admin
201
- admin_session
219
+ If you have some checkboxes that express the roles a user may take on registration, the browser will send those selected checkboxes as an array. An array is not one of Strong Parameters' permitted scalars, so we need to configure Devise in the following way:
220
+
221
+ ```ruby
222
+ def configure_permitted_parameters
223
+ devise_parameter_sanitizer.for(:sign_up) { |u| u.permit({ roles: [] }, :email, :password, :password_confirmation) }
224
+ end
225
+ ```
226
+ For the list of permitted scalars, and how to declare permitted keys in nested hashes and arrays, see
227
+
228
+ https://github.com/rails/strong_parameters#nested-parameters
229
+
230
+ If you have multiple Devise models, you may want to set up a different parameter sanitizer per model. In this case, we recommend inheriting from `Devise::ParameterSanitizer` and adding your own logic:
231
+
232
+ ```ruby
233
+ class User::ParameterSanitizer < Devise::ParameterSanitizer
234
+ def sign_in
235
+ default_params.permit(:username, :email)
236
+ end
237
+ end
238
+ ```
239
+
240
+ And then configure your controllers to use it:
241
+
242
+ ```ruby
243
+ class ApplicationController < ActionController::Base
244
+ protected
245
+
246
+ def devise_parameter_sanitizer
247
+ if resource_class == User
248
+ User::ParameterSanitizer.new(User, :user, params)
249
+ else
250
+ super # Use the default one
251
+ end
252
+ end
253
+ end
202
254
  ```
203
255
 
204
- On the other hand, you can simply run the generator!
256
+ The example above overrides the permitted parameters for the user to be both `:username` and `:email`. The non-lazy way to configure parameters would be by defining the before filter above in a custom controller. We detail how to configure and customize controllers in some sections below.
205
257
 
206
258
  ### Configuring views
207
259
 
@@ -213,58 +265,103 @@ Since Devise is an engine, all its views are packaged inside the gem. These view
213
265
  rails generate devise:views
214
266
  ```
215
267
 
216
- 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".
268
+ If you have more than one Devise model in your application (such as `User` and `Admin`), you will notice that Devise uses the same views for all models. Fortunately, Devise offers an easy way to customize views. All you need to do is set `config.scoped_views = true` inside the `config/initializers/devise.rb` file.
217
269
 
218
- 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:
270
+ 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:
219
271
 
220
272
  ```console
221
273
  rails generate devise:views users
222
274
  ```
223
275
 
276
+ If you would like to generate only a few sets of views, like the ones for the `registerable` and `confirmable` module,
277
+ you can pass a list of modules to the generator with the `-v` flag.
278
+
279
+ ```console
280
+ rails generate devise:views -v registrations confirmations
281
+ ```
282
+
224
283
  ### Configuring controllers
225
284
 
226
285
  If the customization at the views level is not enough, you can customize each controller by following these steps:
227
286
 
228
- 1) Create your custom controller, for example a Admins::SessionsController:
287
+ 1. Create your custom controllers using the generator which requires a scope:
229
288
 
230
- ```ruby
231
- class Admins::SessionsController < Devise::SessionsController
232
- end
233
- ```
289
+ ```console
290
+ rails generate devise:controllers [scope]
291
+ ```
234
292
 
235
- 2) Tell the router to use this controller:
293
+ If you specify `users` as the scope, controllers will be created in `app/controllers/users/`.
294
+ And the sessions controller will look like this:
236
295
 
237
- ```ruby
238
- devise_for :admins, :controllers => { :sessions => "admins/sessions" }
239
- ```
296
+ ```ruby
297
+ class Users::SessionsController < Devise::SessionsController
298
+ # GET /resource/sign_in
299
+ # def new
300
+ # super
301
+ # end
302
+ ...
303
+ end
304
+ ```
305
+
306
+ 2. Tell the router to use this controller:
307
+
308
+ ```ruby
309
+ devise_for :users, controllers: { sessions: "users/sessions" }
310
+ ```
311
+
312
+ 3. Copy the views from `devise/sessions` to `users/sessions`. Since the controller was changed, it won't use the default views located in `devise/sessions`.
240
313
 
241
- 3) And since we changed the controller, it won't use the "devise/sessions" views, so remember to copy "devise/sessions" to "admin/sessions".
314
+ 4. Finally, change or extend the desired controller actions.
242
315
 
243
- 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.
316
+ You can completely override a controller action:
317
+
318
+ ```ruby
319
+ class Users::SessionsController < Devise::SessionsController
320
+ def create
321
+ # custom sign-in code
322
+ end
323
+ end
324
+ ```
325
+
326
+ Or you can simply add new behaviour to it:
327
+
328
+ ```ruby
329
+ class Users::SessionsController < Devise::SessionsController
330
+ def create
331
+ super do |resource|
332
+ BackgroundWorker.trigger(resource)
333
+ end
334
+ end
335
+ end
336
+ ```
337
+
338
+ This is useful for triggering background jobs or logging events during certain actions.
339
+
340
+ Remember that Devise uses flash messages to let users know if sign in was successful or unsuccessful. Devise expects your application to call `flash[:notice]` and `flash[:alert]` as appropriate. Do not print the entire flash hash, print only specific keys. In some circumstances, Devise adds a `:timedout` key to the flash hash, which is not meant for display. Remove this key from the hash if you intend to print the entire hash.
244
341
 
245
342
  ### Configuring routes
246
343
 
247
344
  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:
248
345
 
249
346
  ```ruby
250
- 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' }
347
+ 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' }
251
348
  ```
252
349
 
253
350
  Be sure to check `devise_for` documentation for details.
254
351
 
255
- 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:
352
+ If you have the need for more deep customization, for instance to also allow "/sign_in" besides "/users/sign_in", all you need to do is create your routes normally and wrap them in a `devise_scope` block in the router:
256
353
 
257
354
  ```ruby
258
355
  devise_scope :user do
259
- get "sign_in", :to => "devise/sessions#new"
356
+ get "sign_in", to: "devise/sessions#new"
260
357
  end
261
358
  ```
262
359
 
263
- 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.
360
+ 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.
264
361
 
265
362
  ### I18n
266
363
 
267
- Devise uses flash messages with I18n with the flash keys :notice and :alert. To customize your app, you can set up your locale file:
364
+ Devise uses flash messages with I18n, in conjunction with the flash keys :notice and :alert. To customize your app, you can set up your locale file:
268
365
 
269
366
  ```yaml
270
367
  en:
@@ -302,9 +399,11 @@ Take a look at our locale file to check all available messages. You may also be
302
399
 
303
400
  https://github.com/plataformatec/devise/wiki/I18n
304
401
 
402
+ Caution: Devise Controllers inherit from ApplicationController. If your app uses multiple locales, you should be sure to set I18n.locale in ApplicationController.
403
+
305
404
  ### Test helpers
306
405
 
307
- Devise includes some tests helpers for functional specs. In other 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:
406
+ Devise includes some test helpers for functional specs. In order to use them, you need to include Devise in your functional tests by adding the following to the bottom of your `test/test_helper.rb` file:
308
407
 
309
408
  ```ruby
310
409
  class ActionController::TestCase
@@ -312,14 +411,16 @@ class ActionController::TestCase
312
411
  end
313
412
  ```
314
413
 
315
- If you're using RSpec, you can put the following inside a file named `spec/support/devise.rb`:
414
+ If you're using RSpec, you can put the following inside a file named `spec/support/devise.rb` or in your `spec/spec_helper.rb` (or `spec/rails_helper.rb` if you are using rspec-rails):
316
415
 
317
416
  ```ruby
318
417
  RSpec.configure do |config|
319
- config.include Devise::TestHelpers, :type => :controller
418
+ config.include Devise::TestHelpers, type: :controller
320
419
  end
321
420
  ```
322
421
 
422
+ Just be sure that this inclusion is made *after* the `require 'rspec/rails'` directive.
423
+
323
424
  Now you are ready to use the `sign_in` and `sign_out` methods. Such methods have the same signature as in controllers:
324
425
 
325
426
  ```ruby
@@ -330,34 +431,99 @@ sign_out :user # sign_out(scope)
330
431
  sign_out @user # sign_out(resource)
331
432
  ```
332
433
 
333
- There are two things that is important to keep in mind:
434
+ There are two things that are important to keep in mind:
334
435
 
335
- 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;
436
+ 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;
336
437
 
337
- 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:
438
+ 2. If you are testing Devise internal controllers or a controller that inherits from Devise's, you need to tell Devise which mapping should be used before a request. This is necessary because Devise gets this information from the router, but since functional tests do not pass through the router, it needs to be stated explicitly. For example, if you are testing the user scope, simply use:
338
439
 
440
+ ```ruby
339
441
  @request.env["devise.mapping"] = Devise.mappings[:user]
340
442
  get :new
443
+ ```
444
+
445
+ You can read more about testing your Rails 3 - Rails 4 controllers with RSpec in the wiki:
341
446
 
342
- ### Omniauth
447
+ * https://github.com/plataformatec/devise/wiki/How-To:-Test-controllers-with-Rails-3-and-4-%28and-RSpec%29
343
448
 
344
- Devise comes with Omniauth support out of the box to authenticate from other providers. You can read more about Omniauth support in the wiki:
449
+ ### OmniAuth
450
+
451
+ Devise comes with OmniAuth support out of the box to authenticate with other providers. To use it, simply specify your OmniAuth configuration in `config/initializers/devise.rb`:
452
+
453
+ ```ruby
454
+ config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo'
455
+ ```
456
+
457
+ You can read more about OmniAuth support in the wiki:
345
458
 
346
459
  * https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview
347
460
 
348
- ### Other ORMs
461
+ ### Configuring multiple models
462
+
463
+ Devise allows you to set up as many Devise models as you want. If you want to have an Admin model with just authentication and timeout features, in addition to the User model above, just run:
464
+
465
+ ```ruby
466
+ # Create a migration with the required fields
467
+ create_table :admins do |t|
468
+ t.string :email
469
+ t.string :encrypted_password
470
+ t.timestamps null: false
471
+ end
472
+
473
+ # Inside your Admin model
474
+ devise :database_authenticatable, :timeoutable
475
+
476
+ # Inside your routes
477
+ devise_for :admins
478
+
479
+ # Inside your protected controller
480
+ before_filter :authenticate_admin!
481
+
482
+ # Inside your controllers and views
483
+ admin_signed_in?
484
+ current_admin
485
+ admin_session
486
+ ```
487
+
488
+ Alternatively, you can simply run the Devise generator.
489
+
490
+ Keep in mind that those models will have completely different routes. They **do not** and **cannot** share the same controller for sign in, sign out and so on. In case you want to have different roles sharing the same actions, we recommend that you use a role-based approach, by either providing a role column or using a dedicated gem for authorization.
491
+
492
+ ### ActiveJob Integration
493
+
494
+ If you are using Rails 4.2 and ActiveJob to deliver ActionMailer messages in the
495
+ background through a queuing back-end, you can send Devise emails through your
496
+ existing queue by overriding the `send_devise_notification` method in your model.
497
+
498
+ ```ruby
499
+ def send_devise_notification(notification, *args)
500
+ devise_mailer.send(notification, self, *args).deliver_later
501
+ end
502
+ ```
503
+
504
+ ### Password reset tokens and Rails logs
505
+
506
+ If you enable the [Recoverable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Recoverable) module, note that a stolen password reset token could give an attacker access to your application. Devise takes effort to generate random, secure tokens, and stores only token digests in the database, never plaintext. However the default logging behavior in Rails can cause plaintext tokens to leak into log files:
507
+
508
+ 1. Action Mailer logs the entire contents of all outgoing emails to the DEBUG level. Password reset tokens delivered to users in email will be leaked.
509
+ 2. Active Job logs all arguments to every enqueued job at the INFO level. If you configure Devise to use `deliver_later` to send password reset emails, password reset tokens will be leaked.
349
510
 
350
- Devise supports ActiveRecord (default) and Mongoid. To choose other ORM, you just need to require it in the initializer file.
511
+ Rails sets the production logger level to DEBUG by default. Consider changing your production logger level to WARN if you wish to prevent tokens from being leaked into your logs. In `config/environments/production.rb`:
351
512
 
352
- ### Migrating from other solutions
513
+ ```ruby
514
+ config.log_level = :warn
515
+ ```
353
516
 
354
- 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).
355
517
 
356
- ## Troubleshooting
518
+ ### Other ORMs
519
+
520
+ Devise supports ActiveRecord (default) and Mongoid. To select another ORM, simply require it in the initializer file.
521
+
522
+ ## Additional information
357
523
 
358
524
  ### Heroku
359
525
 
360
- Using devise on Heroku with Ruby on Rails 3.1 requires setting:
526
+ Using Devise on Heroku with Ruby on Rails 3.2 requires setting:
361
527
 
362
528
  ```ruby
363
529
  config.assets.initialize_on_precompile = false
@@ -365,8 +531,6 @@ config.assets.initialize_on_precompile = false
365
531
 
366
532
  Read more about the potential issues at http://guides.rubyonrails.org/asset_pipeline.html
367
533
 
368
- ## Additional information
369
-
370
534
  ### Warden
371
535
 
372
536
  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:
@@ -377,14 +541,10 @@ https://github.com/hassox/warden
377
541
 
378
542
  We have a long list of valued contributors. Check them all at:
379
543
 
380
- https://github.com/plataformatec/devise/contributors
381
-
382
- ### Maintainers
383
-
384
- * José Valim (https://github.com/josevalim)
385
- * Carlos Antônio da Silva (https://github.com/carlosantoniodasilva)
386
- * Rodrigo Flores (https://github.com/rodrigoflores)
544
+ https://github.com/plataformatec/devise/graphs/contributors
387
545
 
388
546
  ## License
389
547
 
390
- MIT License. Copyright 2012 Plataformatec. http://plataformatec.com.br
548
+ MIT License. Copyright 2009-2015 Plataformatec. http://plataformatec.com.br
549
+
550
+ You are not granted rights or licenses to the trademarks of Plataformatec, including without limitation the Devise name or logo.