devise-warbler 2.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (208) hide show
  1. data/.gitignore +10 -0
  2. data/.travis.yml +35 -0
  3. data/CHANGELOG.rdoc +923 -0
  4. data/CONTRIBUTING.md +14 -0
  5. data/Gemfile +32 -0
  6. data/Gemfile.lock +156 -0
  7. data/MIT-LICENSE +20 -0
  8. data/README.md +396 -0
  9. data/Rakefile +34 -0
  10. data/app/controllers/devise/confirmations_controller.rb +43 -0
  11. data/app/controllers/devise/omniauth_callbacks_controller.rb +30 -0
  12. data/app/controllers/devise/passwords_controller.rb +65 -0
  13. data/app/controllers/devise/registrations_controller.rb +119 -0
  14. data/app/controllers/devise/sessions_controller.rb +48 -0
  15. data/app/controllers/devise/unlocks_controller.rb +44 -0
  16. data/app/controllers/devise_controller.rb +184 -0
  17. data/app/helpers/devise_helper.rb +25 -0
  18. data/app/mailers/devise/mailer.rb +15 -0
  19. data/app/views/devise/_links.erb +3 -0
  20. data/app/views/devise/confirmations/new.html.erb +12 -0
  21. data/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
  22. data/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
  23. data/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
  24. data/app/views/devise/passwords/edit.html.erb +16 -0
  25. data/app/views/devise/passwords/new.html.erb +12 -0
  26. data/app/views/devise/registrations/edit.html.erb +29 -0
  27. data/app/views/devise/registrations/new.html.erb +18 -0
  28. data/app/views/devise/sessions/new.html.erb +17 -0
  29. data/app/views/devise/shared/_links.erb +25 -0
  30. data/app/views/devise/unlocks/new.html.erb +12 -0
  31. data/config/locales/en.yml +59 -0
  32. data/devise.gemspec +24 -0
  33. data/gemfiles/Gemfile.rails-3.1.x +35 -0
  34. data/gemfiles/Gemfile.rails-3.1.x.lock +167 -0
  35. data/lib/devise.rb +451 -0
  36. data/lib/devise/controllers/helpers.rb +285 -0
  37. data/lib/devise/controllers/rememberable.rb +56 -0
  38. data/lib/devise/controllers/scoped_views.rb +17 -0
  39. data/lib/devise/controllers/url_helpers.rb +67 -0
  40. data/lib/devise/delegator.rb +16 -0
  41. data/lib/devise/failure_app.rb +187 -0
  42. data/lib/devise/hooks/activatable.rb +11 -0
  43. data/lib/devise/hooks/forgetable.rb +9 -0
  44. data/lib/devise/hooks/lockable.rb +7 -0
  45. data/lib/devise/hooks/rememberable.rb +6 -0
  46. data/lib/devise/hooks/timeoutable.rb +25 -0
  47. data/lib/devise/hooks/trackable.rb +9 -0
  48. data/lib/devise/mailers/helpers.rb +95 -0
  49. data/lib/devise/mapping.rb +172 -0
  50. data/lib/devise/models.rb +128 -0
  51. data/lib/devise/models/authenticatable.rb +276 -0
  52. data/lib/devise/models/confirmable.rb +267 -0
  53. data/lib/devise/models/database_authenticatable.rb +126 -0
  54. data/lib/devise/models/lockable.rb +193 -0
  55. data/lib/devise/models/omniauthable.rb +27 -0
  56. data/lib/devise/models/recoverable.rb +140 -0
  57. data/lib/devise/models/registerable.rb +25 -0
  58. data/lib/devise/models/rememberable.rb +125 -0
  59. data/lib/devise/models/timeoutable.rb +49 -0
  60. data/lib/devise/models/token_authenticatable.rb +89 -0
  61. data/lib/devise/models/trackable.rb +35 -0
  62. data/lib/devise/models/validatable.rb +66 -0
  63. data/lib/devise/modules.rb +29 -0
  64. data/lib/devise/omniauth.rb +28 -0
  65. data/lib/devise/omniauth/config.rb +45 -0
  66. data/lib/devise/omniauth/url_helpers.rb +18 -0
  67. data/lib/devise/orm/active_record.rb +3 -0
  68. data/lib/devise/orm/mongoid.rb +3 -0
  69. data/lib/devise/param_filter.rb +40 -0
  70. data/lib/devise/rails.rb +51 -0
  71. data/lib/devise/rails/routes.rb +448 -0
  72. data/lib/devise/rails/warden_compat.rb +43 -0
  73. data/lib/devise/strategies/authenticatable.rb +176 -0
  74. data/lib/devise/strategies/base.rb +20 -0
  75. data/lib/devise/strategies/database_authenticatable.rb +20 -0
  76. data/lib/devise/strategies/rememberable.rb +55 -0
  77. data/lib/devise/strategies/token_authenticatable.rb +56 -0
  78. data/lib/devise/test_helpers.rb +131 -0
  79. data/lib/devise/time_inflector.rb +14 -0
  80. data/lib/devise/version.rb +3 -0
  81. data/lib/generators/active_record/devise_generator.rb +79 -0
  82. data/lib/generators/active_record/templates/migration.rb +19 -0
  83. data/lib/generators/active_record/templates/migration_existing.rb +26 -0
  84. data/lib/generators/devise/devise_generator.rb +24 -0
  85. data/lib/generators/devise/install_generator.rb +24 -0
  86. data/lib/generators/devise/orm_helpers.rb +32 -0
  87. data/lib/generators/devise/views_generator.rb +122 -0
  88. data/lib/generators/mongoid/devise_generator.rb +57 -0
  89. data/lib/generators/templates/README +35 -0
  90. data/lib/generators/templates/devise.rb +240 -0
  91. data/lib/generators/templates/markerb/confirmation_instructions.markerb +5 -0
  92. data/lib/generators/templates/markerb/reset_password_instructions.markerb +8 -0
  93. data/lib/generators/templates/markerb/unlock_instructions.markerb +7 -0
  94. data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +16 -0
  95. data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +19 -0
  96. data/lib/generators/templates/simple_form_for/passwords/new.html.erb +15 -0
  97. data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +27 -0
  98. data/lib/generators/templates/simple_form_for/registrations/new.html.erb +17 -0
  99. data/lib/generators/templates/simple_form_for/sessions/new.html.erb +15 -0
  100. data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +16 -0
  101. data/test/controllers/custom_strategy_test.rb +62 -0
  102. data/test/controllers/helpers_test.rb +253 -0
  103. data/test/controllers/internal_helpers_test.rb +110 -0
  104. data/test/controllers/sessions_controller_test.rb +85 -0
  105. data/test/controllers/url_helpers_test.rb +59 -0
  106. data/test/delegator_test.rb +19 -0
  107. data/test/devise_test.rb +83 -0
  108. data/test/failure_app_test.rb +221 -0
  109. data/test/generators/active_record_generator_test.rb +75 -0
  110. data/test/generators/devise_generator_test.rb +39 -0
  111. data/test/generators/install_generator_test.rb +13 -0
  112. data/test/generators/mongoid_generator_test.rb +23 -0
  113. data/test/generators/views_generator_test.rb +67 -0
  114. data/test/helpers/devise_helper_test.rb +51 -0
  115. data/test/integration/authenticatable_test.rb +687 -0
  116. data/test/integration/confirmable_test.rb +299 -0
  117. data/test/integration/database_authenticatable_test.rb +84 -0
  118. data/test/integration/http_authenticatable_test.rb +97 -0
  119. data/test/integration/lockable_test.rb +242 -0
  120. data/test/integration/omniauthable_test.rb +133 -0
  121. data/test/integration/recoverable_test.rb +334 -0
  122. data/test/integration/registerable_test.rb +347 -0
  123. data/test/integration/rememberable_test.rb +165 -0
  124. data/test/integration/timeoutable_test.rb +140 -0
  125. data/test/integration/token_authenticatable_test.rb +161 -0
  126. data/test/integration/trackable_test.rb +92 -0
  127. data/test/mailers/confirmation_instructions_test.rb +106 -0
  128. data/test/mailers/reset_password_instructions_test.rb +87 -0
  129. data/test/mailers/unlock_instructions_test.rb +82 -0
  130. data/test/mapping_test.rb +127 -0
  131. data/test/models/authenticatable_test.rb +13 -0
  132. data/test/models/confirmable_test.rb +398 -0
  133. data/test/models/database_authenticatable_test.rb +207 -0
  134. data/test/models/lockable_test.rb +273 -0
  135. data/test/models/omniauthable_test.rb +7 -0
  136. data/test/models/recoverable_test.rb +205 -0
  137. data/test/models/registerable_test.rb +7 -0
  138. data/test/models/rememberable_test.rb +174 -0
  139. data/test/models/serializable_test.rb +49 -0
  140. data/test/models/timeoutable_test.rb +46 -0
  141. data/test/models/token_authenticatable_test.rb +55 -0
  142. data/test/models/trackable_test.rb +13 -0
  143. data/test/models/validatable_test.rb +117 -0
  144. data/test/models_test.rb +158 -0
  145. data/test/omniauth/config_test.rb +57 -0
  146. data/test/omniauth/url_helpers_test.rb +51 -0
  147. data/test/orm/active_record.rb +9 -0
  148. data/test/orm/mongoid.rb +13 -0
  149. data/test/rails_app/Rakefile +10 -0
  150. data/test/rails_app/app/active_record/admin.rb +6 -0
  151. data/test/rails_app/app/active_record/shim.rb +2 -0
  152. data/test/rails_app/app/active_record/user.rb +6 -0
  153. data/test/rails_app/app/controllers/admins/sessions_controller.rb +6 -0
  154. data/test/rails_app/app/controllers/admins_controller.rb +11 -0
  155. data/test/rails_app/app/controllers/application_controller.rb +9 -0
  156. data/test/rails_app/app/controllers/home_controller.rb +25 -0
  157. data/test/rails_app/app/controllers/publisher/registrations_controller.rb +2 -0
  158. data/test/rails_app/app/controllers/publisher/sessions_controller.rb +2 -0
  159. data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +14 -0
  160. data/test/rails_app/app/controllers/users_controller.rb +23 -0
  161. data/test/rails_app/app/helpers/application_helper.rb +3 -0
  162. data/test/rails_app/app/mailers/users/mailer.rb +8 -0
  163. data/test/rails_app/app/mongoid/admin.rb +29 -0
  164. data/test/rails_app/app/mongoid/shim.rb +24 -0
  165. data/test/rails_app/app/mongoid/user.rb +42 -0
  166. data/test/rails_app/app/views/admins/index.html.erb +1 -0
  167. data/test/rails_app/app/views/admins/sessions/new.html.erb +2 -0
  168. data/test/rails_app/app/views/home/admin_dashboard.html.erb +1 -0
  169. data/test/rails_app/app/views/home/index.html.erb +1 -0
  170. data/test/rails_app/app/views/home/join.html.erb +1 -0
  171. data/test/rails_app/app/views/home/private.html.erb +1 -0
  172. data/test/rails_app/app/views/home/user_dashboard.html.erb +1 -0
  173. data/test/rails_app/app/views/layouts/application.html.erb +24 -0
  174. data/test/rails_app/app/views/users/index.html.erb +1 -0
  175. data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +1 -0
  176. data/test/rails_app/app/views/users/sessions/new.html.erb +1 -0
  177. data/test/rails_app/config.ru +4 -0
  178. data/test/rails_app/config/application.rb +41 -0
  179. data/test/rails_app/config/boot.rb +8 -0
  180. data/test/rails_app/config/database.yml +18 -0
  181. data/test/rails_app/config/environment.rb +5 -0
  182. data/test/rails_app/config/environments/development.rb +18 -0
  183. data/test/rails_app/config/environments/production.rb +33 -0
  184. data/test/rails_app/config/environments/test.rb +33 -0
  185. data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
  186. data/test/rails_app/config/initializers/devise.rb +178 -0
  187. data/test/rails_app/config/initializers/inflections.rb +2 -0
  188. data/test/rails_app/config/initializers/secret_token.rb +2 -0
  189. data/test/rails_app/config/routes.rb +100 -0
  190. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +74 -0
  191. data/test/rails_app/db/schema.rb +52 -0
  192. data/test/rails_app/lib/shared_admin.rb +14 -0
  193. data/test/rails_app/lib/shared_user.rb +26 -0
  194. data/test/rails_app/public/404.html +26 -0
  195. data/test/rails_app/public/422.html +26 -0
  196. data/test/rails_app/public/500.html +26 -0
  197. data/test/rails_app/public/favicon.ico +0 -0
  198. data/test/rails_app/script/rails +10 -0
  199. data/test/routes_test.rb +248 -0
  200. data/test/support/assertions.rb +40 -0
  201. data/test/support/helpers.rb +91 -0
  202. data/test/support/integration.rb +92 -0
  203. data/test/support/locale/en.yml +4 -0
  204. data/test/support/webrat/integrations/rails.rb +24 -0
  205. data/test/test_helper.rb +27 -0
  206. data/test/test_helpers_test.rb +151 -0
  207. data/test/test_models.rb +27 -0
  208. metadata +423 -0
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,14 @@
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 [developers@plataformatec.com.br](mailto:developers@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
+ That's it! The more information you give, the easier it becomes for us to track it down and fix it.
12
+ Ideally, you should provide an application that reproduces the error or a test case to Devise's suite.
13
+
14
+ Thanks!
data/Gemfile ADDED
@@ -0,0 +1,32 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem "rails", "~> 3.2.6"
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", "0.10.0", :require => false
15
+ end
16
+
17
+ platforms :jruby do
18
+ gem "activerecord-jdbc-adapter"
19
+ gem "activerecord-jdbcsqlite3-adapter"
20
+ gem "jruby-openssl"
21
+ end
22
+
23
+ platforms :ruby do
24
+ gem "sqlite3"
25
+ end
26
+
27
+
28
+ platforms :mri_19 do
29
+ group :mongoid do
30
+ gem "mongoid", "~> 3.0"
31
+ end
32
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,156 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ devise (2.2.3)
5
+ bcrypt-ruby (~> 3.0)
6
+ orm_adapter (~> 0.1)
7
+ railties (~> 3.1)
8
+ warden (~> 1.2.1)
9
+
10
+ GEM
11
+ remote: http://rubygems.org/
12
+ specs:
13
+ actionmailer (3.2.11)
14
+ actionpack (= 3.2.11)
15
+ mail (~> 2.4.4)
16
+ actionpack (3.2.11)
17
+ activemodel (= 3.2.11)
18
+ activesupport (= 3.2.11)
19
+ builder (~> 3.0.0)
20
+ erubis (~> 2.7.0)
21
+ journey (~> 1.0.4)
22
+ rack (~> 1.4.0)
23
+ rack-cache (~> 1.2)
24
+ rack-test (~> 0.6.1)
25
+ sprockets (~> 2.2.1)
26
+ activemodel (3.2.11)
27
+ activesupport (= 3.2.11)
28
+ builder (~> 3.0.0)
29
+ activerecord (3.2.11)
30
+ activemodel (= 3.2.11)
31
+ activesupport (= 3.2.11)
32
+ arel (~> 3.0.2)
33
+ tzinfo (~> 0.3.29)
34
+ activeresource (3.2.11)
35
+ activemodel (= 3.2.11)
36
+ activesupport (= 3.2.11)
37
+ activesupport (3.2.11)
38
+ i18n (~> 0.6)
39
+ multi_json (~> 1.0)
40
+ arel (3.0.2)
41
+ bcrypt-ruby (3.0.1)
42
+ builder (3.0.4)
43
+ erubis (2.7.0)
44
+ faraday (0.8.4)
45
+ multipart-post (~> 1.1)
46
+ hashie (1.2.0)
47
+ hike (1.2.1)
48
+ httpauth (0.2.0)
49
+ i18n (0.6.1)
50
+ journey (1.0.4)
51
+ json (1.7.6)
52
+ jwt (0.1.5)
53
+ multi_json (>= 1.0)
54
+ mail (2.4.4)
55
+ i18n (>= 0.4.0)
56
+ mime-types (~> 1.16)
57
+ treetop (~> 1.4.8)
58
+ metaclass (0.0.1)
59
+ mime-types (1.19)
60
+ mocha (0.10.0)
61
+ metaclass (~> 0.0.1)
62
+ mongoid (3.0.16)
63
+ activemodel (~> 3.1)
64
+ moped (~> 1.1)
65
+ origin (~> 1.0)
66
+ tzinfo (~> 0.3.22)
67
+ moped (1.3.2)
68
+ multi_json (1.5.0)
69
+ multipart-post (1.1.5)
70
+ nokogiri (1.5.5)
71
+ oauth2 (0.8.0)
72
+ faraday (~> 0.8)
73
+ httpauth (~> 0.1)
74
+ jwt (~> 0.1.4)
75
+ multi_json (~> 1.0)
76
+ rack (~> 1.2)
77
+ omniauth (1.0.3)
78
+ hashie (~> 1.2)
79
+ rack
80
+ omniauth-facebook (1.4.0)
81
+ omniauth-oauth2 (~> 1.0.2)
82
+ omniauth-oauth2 (1.0.3)
83
+ oauth2 (~> 0.8.0)
84
+ omniauth (~> 1.0)
85
+ omniauth-openid (1.0.1)
86
+ omniauth (~> 1.0)
87
+ rack-openid (~> 1.3.1)
88
+ origin (1.0.11)
89
+ orm_adapter (0.4.0)
90
+ polyglot (0.3.3)
91
+ rack (1.4.3)
92
+ rack-cache (1.2)
93
+ rack (>= 0.4)
94
+ rack-openid (1.3.1)
95
+ rack (>= 1.1.0)
96
+ ruby-openid (>= 2.1.8)
97
+ rack-ssl (1.3.2)
98
+ rack
99
+ rack-test (0.6.2)
100
+ rack (>= 1.0)
101
+ rails (3.2.11)
102
+ actionmailer (= 3.2.11)
103
+ actionpack (= 3.2.11)
104
+ activerecord (= 3.2.11)
105
+ activeresource (= 3.2.11)
106
+ activesupport (= 3.2.11)
107
+ bundler (~> 1.0)
108
+ railties (= 3.2.11)
109
+ railties (3.2.11)
110
+ actionpack (= 3.2.11)
111
+ activesupport (= 3.2.11)
112
+ rack-ssl (~> 1.3.2)
113
+ rake (>= 0.8.7)
114
+ rdoc (~> 3.4)
115
+ thor (>= 0.14.6, < 2.0)
116
+ rake (10.0.3)
117
+ rdoc (3.12)
118
+ json (~> 1.4)
119
+ ruby-openid (2.2.2)
120
+ sprockets (2.2.2)
121
+ hike (~> 1.2)
122
+ multi_json (~> 1.0)
123
+ rack (~> 1.0)
124
+ tilt (~> 1.1, != 1.3.0)
125
+ sqlite3 (1.3.6)
126
+ thor (0.16.0)
127
+ tilt (1.3.3)
128
+ treetop (1.4.12)
129
+ polyglot
130
+ polyglot (>= 0.3.1)
131
+ tzinfo (0.3.35)
132
+ warden (1.2.1)
133
+ rack (>= 1.0)
134
+ webrat (0.7.2)
135
+ nokogiri (>= 1.2.0)
136
+ rack (>= 1.0)
137
+ rack-test (>= 0.5.3)
138
+
139
+ PLATFORMS
140
+ ruby
141
+
142
+ DEPENDENCIES
143
+ activerecord-jdbc-adapter
144
+ activerecord-jdbcsqlite3-adapter
145
+ devise!
146
+ jruby-openssl
147
+ mocha (= 0.10.0)
148
+ mongoid (~> 3.0)
149
+ omniauth (~> 1.0.0)
150
+ omniauth-facebook
151
+ omniauth-oauth2 (~> 1.0.0)
152
+ omniauth-openid (~> 1.0.1)
153
+ rails (~> 3.2.6)
154
+ rdoc
155
+ sqlite3
156
+ webrat (= 0.7.2)
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2009-2013 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.
data/README.md ADDED
@@ -0,0 +1,396 @@
1
+ ## Devise
2
+
3
+ [![Build Status](https://secure.travis-ci.org/plataformatec/devise.png?branch=master)](http://travis-ci.org/plataformatec/devise)
4
+ [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/plataformatec/devise)
5
+ [![Gem Version](https://fury-badge.herokuapp.com/rb/devise.png)](http://badge.fury.io/rb/devise)
6
+
7
+ This README is [also available in a friendly navigable format](http://devise.plataformatec.com.br/).
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 composed of 11 modules:
17
+
18
+ * [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
+ * [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
+ * [Recoverable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Recoverable): resets the user password and sends reset instructions.
23
+ * [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
+ * [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
+ * [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
+ * [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
+ * [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
+ ## Information
31
+
32
+ ### The Devise wiki
33
+
34
+ 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
+
36
+ https://wiki.github.com/plataformatec/devise
37
+
38
+ ### Bug reports
39
+
40
+ 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:
41
+
42
+ https://github.com/plataformatec/devise/wiki/Bug-reports
43
+
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.
45
+
46
+ ### Mailing list
47
+
48
+ If you have any questions, comments, or concerns, please use the Google Group instead of the GitHub issue tracker:
49
+
50
+ https://groups.google.com/group/plataformatec-devise
51
+
52
+ ### RDocs
53
+
54
+ You can view the Devise documentation in RDoc format here:
55
+
56
+ http://rubydoc.info/github/plataformatec/devise/master/frames
57
+
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.
59
+
60
+ ### Example applications
61
+
62
+ 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:
63
+
64
+ https://github.com/plataformatec/devise/wiki/Example-Applications
65
+
66
+ ### Extensions
67
+
68
+ 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:
69
+
70
+ https://github.com/plataformatec/devise/wiki/Extensions
71
+
72
+ ### Contributing
73
+
74
+ We hope that you will consider contributing to Devise. Please read this short overview for some information about how to get started:
75
+
76
+ https://github.com/plataformatec/devise/wiki/Contributing
77
+
78
+ 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.
79
+
80
+ ## Starting with Rails?
81
+
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:
83
+
84
+ * Michael Hartl's online book: http://railstutorial.org/chapters/modeling-and-viewing-users-two#top
85
+ * Ryan Bates' Railscast: http://railscasts.com/episodes/250-authentication-from-scratch
86
+
87
+ Once you have solidified your understanding of Rails and authentication mechanisms, we assure you Devise will be very pleasant to work with. :)
88
+
89
+ ## Getting started
90
+
91
+ Devise 2.0 works with Rails 3.1 onwards. You can add it to your Gemfile with:
92
+
93
+ ```ruby
94
+ gem 'devise'
95
+ ```
96
+
97
+ Run the bundle command to install it.
98
+
99
+ After you install Devise and add it to your Gemfile, you need to run the generator:
100
+
101
+ ```console
102
+ rails generate devise:install
103
+ ```
104
+
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:
106
+
107
+ ```console
108
+ rails generate devise MODEL
109
+ ```
110
+
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 the Devise controller.
112
+
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.
114
+
115
+ ### Controller filters and helpers
116
+
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:
118
+
119
+ ```ruby
120
+ before_filter :authenticate_user!
121
+ ```
122
+
123
+ To verify if a user is signed in, use the following helper:
124
+
125
+ ```ruby
126
+ user_signed_in?
127
+ ```
128
+
129
+ For the current signed-in user, this helper is available:
130
+
131
+ ```ruby
132
+ current_user
133
+ ```
134
+
135
+ You can access the session for this scope:
136
+
137
+ ```ruby
138
+ user_session
139
+ ```
140
+
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:
142
+
143
+ ```ruby
144
+ root :to => "home#index"
145
+ ```
146
+
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":
150
+
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:
156
+
157
+ ```ruby
158
+ before_filter :authenticate_member!
159
+
160
+ member_signed_in?
161
+
162
+ current_member
163
+
164
+ member_session
165
+ ```
166
+
167
+ ### Configuring Models
168
+
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:
170
+
171
+ ```ruby
172
+ devise :database_authenticatable, :registerable, :confirmable, :recoverable, :stretches => 20
173
+ ```
174
+
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.
176
+
177
+ ### Configuring multiple models
178
+
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:
180
+
181
+ ```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
187
+ end
188
+
189
+ # Inside your Admin model
190
+ devise :database_authenticatable, :timeoutable
191
+
192
+ # Inside your routes
193
+ devise_for :admins
194
+
195
+ # Inside your protected controller
196
+ before_filter :authenticate_admin!
197
+
198
+ # Inside your controllers and views
199
+ admin_signed_in?
200
+ current_admin
201
+ admin_session
202
+ ```
203
+
204
+ On the other hand, you can simply run the generator!
205
+
206
+ ### Configuring views
207
+
208
+ 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.
209
+
210
+ 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:
211
+
212
+ ```console
213
+ rails generate devise:views
214
+ ```
215
+
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".
217
+
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:
219
+
220
+ ```console
221
+ rails generate devise:views users
222
+ ```
223
+
224
+ ### Configuring controllers
225
+
226
+ If the customization at the views level is not enough, you can customize each controller by following these steps:
227
+
228
+ 1) Create your custom controller, for example a Admins::SessionsController:
229
+
230
+ ```ruby
231
+ class Admins::SessionsController < Devise::SessionsController
232
+ end
233
+ ```
234
+
235
+ 2) Tell the router to use this controller:
236
+
237
+ ```ruby
238
+ devise_for :admins, :controllers => { :sessions => "admins/sessions" }
239
+ ```
240
+
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".
242
+
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. Do not print the entire flash hash, print specific keys or at least remove the `:timedout` key from the hash as Devise adds this key in some circumstances, this key is not meant for display.
244
+
245
+ ### Configuring routes
246
+
247
+ 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
+
249
+ ```ruby
250
+ 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
+ ```
252
+
253
+ Be sure to check `devise_for` documentation for details.
254
+
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:
256
+
257
+ ```ruby
258
+ devise_scope :user do
259
+ get "sign_in", :to => "devise/sessions#new"
260
+ end
261
+ ```
262
+
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.
264
+
265
+ ### I18n
266
+
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:
268
+
269
+ ```yaml
270
+ en:
271
+ devise:
272
+ sessions:
273
+ signed_in: 'Signed in successfully.'
274
+ ```
275
+
276
+ You can also create distinct messages based on the resource you've configured using the singular name given in routes:
277
+
278
+ ```yaml
279
+ en:
280
+ devise:
281
+ sessions:
282
+ user:
283
+ signed_in: 'Welcome user, you are signed in.'
284
+ admin:
285
+ signed_in: 'Hello admin!'
286
+ ```
287
+
288
+ The Devise mailer uses a similar pattern to create subject messages:
289
+
290
+ ```yaml
291
+ en:
292
+ devise:
293
+ mailer:
294
+ confirmation_instructions:
295
+ subject: 'Hello everybody!'
296
+ user_subject: 'Hello User! Please confirm your email'
297
+ reset_password_instructions:
298
+ subject: 'Reset instructions'
299
+ ```
300
+
301
+ 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:
302
+
303
+ https://github.com/plataformatec/devise/wiki/I18n
304
+
305
+ ### Test helpers
306
+
307
+ Devise includes some tests helpers for functional specs. In order to use them, you need to include Devise in your functional tests by adding the following to the bottom of your `test/test_helper.rb` file:
308
+
309
+ ```ruby
310
+ class ActionController::TestCase
311
+ include Devise::TestHelpers
312
+ end
313
+ ```
314
+
315
+ If you're using RSpec, you can put the following inside a file named `spec/support/devise.rb`:
316
+
317
+ ```ruby
318
+ RSpec.configure do |config|
319
+ config.include Devise::TestHelpers, :type => :controller
320
+ end
321
+ ```
322
+
323
+ Now you are ready to use the `sign_in` and `sign_out` methods. Such methods have the same signature as in controllers:
324
+
325
+ ```ruby
326
+ sign_in :user, @user # sign_in(scope, resource)
327
+ sign_in @user # sign_in(resource)
328
+
329
+ sign_out :user # sign_out(scope)
330
+ sign_out @user # sign_out(resource)
331
+ ```
332
+
333
+ There are two things that is important to keep in mind:
334
+
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;
336
+
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:
338
+
339
+ @request.env["devise.mapping"] = Devise.mappings[:user]
340
+ get :new
341
+
342
+ ### Omniauth
343
+
344
+ Devise comes with Omniauth support out of the box to authenticate with other providers. To use it, just specify your omniauth configuration in `config/initializers/devise.rb`:
345
+
346
+ ```ruby
347
+ config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo'
348
+ ```
349
+
350
+ You can read more about Omniauth support in the wiki:
351
+
352
+ * https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview
353
+
354
+ ### Other ORMs
355
+
356
+ Devise supports ActiveRecord (default) and Mongoid. To choose other ORM, you just need to require it in the initializer file.
357
+
358
+ ### Migrating from other solutions
359
+
360
+ 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).
361
+
362
+ ## Troubleshooting
363
+
364
+ ### Heroku
365
+
366
+ Using devise on Heroku with Ruby on Rails 3.1 requires setting:
367
+
368
+ ```ruby
369
+ config.assets.initialize_on_precompile = false
370
+ ```
371
+
372
+ Read more about the potential issues at http://guides.rubyonrails.org/asset_pipeline.html
373
+
374
+ ## Additional information
375
+
376
+ ### Warden
377
+
378
+ 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:
379
+
380
+ https://github.com/hassox/warden
381
+
382
+ ### Contributors
383
+
384
+ We have a long list of valued contributors. Check them all at:
385
+
386
+ https://github.com/plataformatec/devise/contributors
387
+
388
+ ### Maintainers
389
+
390
+ * José Valim (https://github.com/josevalim)
391
+ * Carlos Antônio da Silva (https://github.com/carlosantoniodasilva)
392
+ * Rodrigo Flores (https://github.com/rodrigoflores)
393
+
394
+ ## License
395
+
396
+ MIT License. Copyright 2009-2013 Plataformatec. http://plataformatec.com.br