af-devise 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (207) hide show
  1. data/.gitignore +10 -0
  2. data/.travis.yml +15 -0
  3. data/CHANGELOG.rdoc +885 -0
  4. data/CONTRIBUTING.md +14 -0
  5. data/Gemfile +29 -0
  6. data/Gemfile.lock +155 -0
  7. data/MIT-LICENSE +20 -0
  8. data/README.md +394 -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 +50 -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 +25 -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 +25 -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 +444 -0
  36. data/lib/devise/controllers/helpers.rb +285 -0
  37. data/lib/devise/controllers/rememberable.rb +52 -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 +91 -0
  49. data/lib/devise/mapping.rb +172 -0
  50. data/lib/devise/models.rb +128 -0
  51. data/lib/devise/models/authenticatable.rb +268 -0
  52. data/lib/devise/models/confirmable.rb +270 -0
  53. data/lib/devise/models/database_authenticatable.rb +127 -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 +41 -0
  70. data/lib/devise/rails.rb +54 -0
  71. data/lib/devise/rails/routes.rb +446 -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 +116 -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 +15 -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 +22 -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 +15 -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 +72 -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 +52 -0
  114. data/test/helpers/devise_helper_test.rb +51 -0
  115. data/test/integration/authenticatable_test.rb +633 -0
  116. data/test/integration/confirmable_test.rb +298 -0
  117. data/test/integration/database_authenticatable_test.rb +82 -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 +345 -0
  123. data/test/integration/rememberable_test.rb +158 -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 +102 -0
  128. data/test/mailers/reset_password_instructions_test.rb +83 -0
  129. data/test/mailers/unlock_instructions_test.rb +77 -0
  130. data/test/mapping_test.rb +127 -0
  131. data/test/models/authenticatable_test.rb +7 -0
  132. data/test/models/confirmable_test.rb +391 -0
  133. data/test/models/database_authenticatable_test.rb +196 -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 +179 -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 +8 -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. metadata +421 -0
@@ -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,29 @@
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
+
26
+ group :mongoid do
27
+ gem "mongoid", "~> 3.0"
28
+ end
29
+ end
@@ -0,0 +1,155 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ devise (2.1.2)
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.8)
14
+ actionpack (= 3.2.8)
15
+ mail (~> 2.4.4)
16
+ actionpack (3.2.8)
17
+ activemodel (= 3.2.8)
18
+ activesupport (= 3.2.8)
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.1.3)
26
+ activemodel (3.2.8)
27
+ activesupport (= 3.2.8)
28
+ builder (~> 3.0.0)
29
+ activerecord (3.2.8)
30
+ activemodel (= 3.2.8)
31
+ activesupport (= 3.2.8)
32
+ arel (~> 3.0.2)
33
+ tzinfo (~> 0.3.29)
34
+ activeresource (3.2.8)
35
+ activemodel (= 3.2.8)
36
+ activesupport (= 3.2.8)
37
+ activesupport (3.2.8)
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.5)
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.11)
63
+ activemodel (~> 3.1)
64
+ moped (~> 1.1)
65
+ origin (~> 1.0)
66
+ tzinfo (~> 0.3.22)
67
+ moped (1.2.8)
68
+ multi_json (1.3.7)
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.10)
89
+ orm_adapter (0.4.0)
90
+ polyglot (0.3.3)
91
+ rack (1.4.1)
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.8)
102
+ actionmailer (= 3.2.8)
103
+ actionpack (= 3.2.8)
104
+ activerecord (= 3.2.8)
105
+ activeresource (= 3.2.8)
106
+ activesupport (= 3.2.8)
107
+ bundler (~> 1.0)
108
+ railties (= 3.2.8)
109
+ railties (3.2.8)
110
+ actionpack (= 3.2.8)
111
+ activesupport (= 3.2.8)
112
+ rack-ssl (~> 1.3.2)
113
+ rake (>= 0.8.7)
114
+ rdoc (~> 3.4)
115
+ thor (>= 0.14.6, < 2.0)
116
+ rake (0.9.2.2)
117
+ rdoc (3.12)
118
+ json (~> 1.4)
119
+ ruby-openid (2.2.2)
120
+ sprockets (2.1.3)
121
+ hike (~> 1.2)
122
+ rack (~> 1.0)
123
+ tilt (~> 1.1, != 1.3.0)
124
+ sqlite3 (1.3.6)
125
+ thor (0.16.0)
126
+ tilt (1.3.3)
127
+ treetop (1.4.12)
128
+ polyglot
129
+ polyglot (>= 0.3.1)
130
+ tzinfo (0.3.35)
131
+ warden (1.2.1)
132
+ rack (>= 1.0)
133
+ webrat (0.7.2)
134
+ nokogiri (>= 1.2.0)
135
+ rack (>= 1.0)
136
+ rack-test (>= 0.5.3)
137
+
138
+ PLATFORMS
139
+ ruby
140
+
141
+ DEPENDENCIES
142
+ activerecord-jdbc-adapter
143
+ activerecord-jdbcsqlite3-adapter
144
+ devise!
145
+ jruby-openssl
146
+ mocha (= 0.10.0)
147
+ mongoid (~> 3.0)
148
+ omniauth (~> 1.0.0)
149
+ omniauth-facebook
150
+ omniauth-oauth2 (~> 1.0.0)
151
+ omniauth-openid (~> 1.0.1)
152
+ rails (~> 3.2.6)
153
+ rdoc
154
+ sqlite3
155
+ webrat (= 0.7.2)
@@ -0,0 +1,20 @@
1
+ Copyright 2009-2012 Plataformatec. http://plataformatec.com.br
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,394 @@
1
+ ## Devise
2
+
3
+ [![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)
4
+
5
+ This README is [also available in a friendly navigable format](http://devise.plataformatec.com.br/).
6
+
7
+ Devise is a flexible authentication solution for Rails based on Warden. It:
8
+
9
+ * Is Rack based;
10
+ * Is a complete MVC solution based on Rails engines;
11
+ * Allows you to have multiple roles (or models/scopes) signed in at the same time;
12
+ * Is based on a modularity concept: use just what you really need.
13
+
14
+ It's composed of 12 modules:
15
+
16
+ * [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.
17
+ * [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.
18
+ * [Omniauthable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Omniauthable): adds Omniauth (https://github.com/intridea/omniauth) support;
19
+ * [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.
20
+ * [Recoverable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Recoverable): resets the user password and sends reset instructions.
21
+ * [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.
22
+ * [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.
23
+ * [Trackable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Trackable): tracks sign in count, timestamps and IP address.
24
+ * [Timeoutable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Timeoutable): expires sessions that have no activity in a specified period of time.
25
+ * [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.
26
+ * [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.
27
+
28
+ ## Information
29
+
30
+ ### The Devise wiki
31
+
32
+ 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:
33
+
34
+ https://wiki.github.com/plataformatec/devise
35
+
36
+ ### Bug reports
37
+
38
+ 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:
39
+
40
+ https://github.com/plataformatec/devise/wiki/Bug-reports
41
+
42
+ 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.
43
+
44
+ ### Mailing list
45
+
46
+ If you have any questions, comments, or concerns, please use the Google Group instead of the GitHub issue tracker:
47
+
48
+ https://groups.google.com/group/plataformatec-devise
49
+
50
+ ### RDocs
51
+
52
+ You can view the Devise documentation in RDoc format here:
53
+
54
+ http://rubydoc.info/github/plataformatec/devise/master/frames
55
+
56
+ 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.
57
+
58
+ ### Example applications
59
+
60
+ 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:
61
+
62
+ https://github.com/plataformatec/devise/wiki/Example-Applications
63
+
64
+ ### Extensions
65
+
66
+ 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:
67
+
68
+ https://github.com/plataformatec/devise/wiki/Extensions
69
+
70
+ ### Contributing
71
+
72
+ We hope that you will consider contributing to Devise. Please read this short overview for some information about how to get started:
73
+
74
+ https://github.com/plataformatec/devise/wiki/Contributing
75
+
76
+ 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.
77
+
78
+ ## Starting with Rails?
79
+
80
+ 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:
81
+
82
+ * Michael Hartl's online book: http://railstutorial.org/chapters/modeling-and-viewing-users-two#top
83
+ * Ryan Bates' Railscast: http://railscasts.com/episodes/250-authentication-from-scratch
84
+
85
+ Once you have solidified your understanding of Rails and authentication mechanisms, we assure you Devise will be very pleasant to work with. :)
86
+
87
+ ## Getting started
88
+
89
+ Devise 2.0 works with Rails 3.1 onwards. You can add it to your Gemfile with:
90
+
91
+ ```ruby
92
+ gem 'devise'
93
+ ```
94
+
95
+ Run the bundle command to install it.
96
+
97
+ After you install Devise and add it to your Gemfile, you need to run the generator:
98
+
99
+ ```console
100
+ rails generate devise:install
101
+ ```
102
+
103
+ 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:
104
+
105
+ ```console
106
+ rails generate devise MODEL
107
+ ```
108
+
109
+ 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.
110
+
111
+ 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.
112
+
113
+ ### Controller filters and helpers
114
+
115
+ 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:
116
+
117
+ ```ruby
118
+ before_filter :authenticate_user!
119
+ ```
120
+
121
+ To verify if a user is signed in, use the following helper:
122
+
123
+ ```ruby
124
+ user_signed_in?
125
+ ```
126
+
127
+ For the current signed-in user, this helper is available:
128
+
129
+ ```ruby
130
+ current_user
131
+ ```
132
+
133
+ You can access the session for this scope:
134
+
135
+ ```ruby
136
+ user_session
137
+ ```
138
+
139
+ 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:
140
+
141
+ ```ruby
142
+ root :to => "home#index"
143
+ ```
144
+
145
+ You can also overwrite `after_sign_in_path_for` and `after_sign_out_path_for` to customize your redirect hooks.
146
+
147
+ Finally, you need to set up default url options for the mailer in each environment. Here is the configuration for "config/environments/development.rb":
148
+
149
+ ```ruby
150
+ config.action_mailer.default_url_options = { :host => 'localhost:3000' }
151
+ ```
152
+
153
+ Notice that if your devise model is not called "user" but "member", then the helpers you should use are:
154
+
155
+ ```ruby
156
+ before_filter :authenticate_member!
157
+
158
+ member_signed_in?
159
+
160
+ current_member
161
+
162
+ member_session
163
+ ```
164
+
165
+ ### Configuring Models
166
+
167
+ 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:
168
+
169
+ ```ruby
170
+ devise :database_authenticatable, :registerable, :confirmable, :recoverable, :stretches => 20
171
+ ```
172
+
173
+ 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.
174
+
175
+ ### Configuring multiple models
176
+
177
+ 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:
178
+
179
+ ```ruby
180
+ # Create a migration with the required fields
181
+ create_table :admins do |t|
182
+ t.string :email
183
+ t.string :encrypted_password
184
+ t.timestamps
185
+ end
186
+
187
+ # Inside your Admin model
188
+ devise :database_authenticatable, :timeoutable
189
+
190
+ # Inside your routes
191
+ devise_for :admins
192
+
193
+ # Inside your protected controller
194
+ before_filter :authenticate_admin!
195
+
196
+ # Inside your controllers and views
197
+ admin_signed_in?
198
+ current_admin
199
+ admin_session
200
+ ```
201
+
202
+ On the other hand, you can simply run the generator!
203
+
204
+ ### Configuring views
205
+
206
+ 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.
207
+
208
+ 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:
209
+
210
+ ```console
211
+ rails generate devise:views
212
+ ```
213
+
214
+ 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".
215
+
216
+ 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:
217
+
218
+ ```console
219
+ rails generate devise:views users
220
+ ```
221
+
222
+ ### Configuring controllers
223
+
224
+ If the customization at the views level is not enough, you can customize each controller by following these steps:
225
+
226
+ 1) Create your custom controller, for example a Admins::SessionsController:
227
+
228
+ ```ruby
229
+ class Admins::SessionsController < Devise::SessionsController
230
+ end
231
+ ```
232
+
233
+ 2) Tell the router to use this controller:
234
+
235
+ ```ruby
236
+ devise_for :admins, :controllers => { :sessions => "admins/sessions" }
237
+ ```
238
+
239
+ 3) And since we changed the controller, it won't use the "devise/sessions" views, so remember to copy "devise/sessions" to "admin/sessions".
240
+
241
+ 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.
242
+
243
+ ### Configuring routes
244
+
245
+ 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:
246
+
247
+ ```ruby
248
+ 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' }
249
+ ```
250
+
251
+ Be sure to check `devise_for` documentation for details.
252
+
253
+ 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:
254
+
255
+ ```ruby
256
+ devise_scope :user do
257
+ get "sign_in", :to => "devise/sessions#new"
258
+ end
259
+ ```
260
+
261
+ 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.
262
+
263
+ ### I18n
264
+
265
+ Devise uses flash messages with I18n with the flash keys :notice and :alert. To customize your app, you can set up your locale file:
266
+
267
+ ```yaml
268
+ en:
269
+ devise:
270
+ sessions:
271
+ signed_in: 'Signed in successfully.'
272
+ ```
273
+
274
+ You can also create distinct messages based on the resource you've configured using the singular name given in routes:
275
+
276
+ ```yaml
277
+ en:
278
+ devise:
279
+ sessions:
280
+ user:
281
+ signed_in: 'Welcome user, you are signed in.'
282
+ admin:
283
+ signed_in: 'Hello admin!'
284
+ ```
285
+
286
+ The Devise mailer uses a similar pattern to create subject messages:
287
+
288
+ ```yaml
289
+ en:
290
+ devise:
291
+ mailer:
292
+ confirmation_instructions:
293
+ subject: 'Hello everybody!'
294
+ user_subject: 'Hello User! Please confirm your email'
295
+ reset_password_instructions:
296
+ subject: 'Reset instructions'
297
+ ```
298
+
299
+ 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:
300
+
301
+ https://github.com/plataformatec/devise/wiki/I18n
302
+
303
+ ### Test helpers
304
+
305
+ 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:
306
+
307
+ ```ruby
308
+ class ActionController::TestCase
309
+ include Devise::TestHelpers
310
+ end
311
+ ```
312
+
313
+ If you're using RSpec, you can put the following inside a file named `spec/support/devise.rb`:
314
+
315
+ ```ruby
316
+ RSpec.configure do |config|
317
+ config.include Devise::TestHelpers, :type => :controller
318
+ end
319
+ ```
320
+
321
+ Now you are ready to use the `sign_in` and `sign_out` methods. Such methods have the same signature as in controllers:
322
+
323
+ ```ruby
324
+ sign_in :user, @user # sign_in(scope, resource)
325
+ sign_in @user # sign_in(resource)
326
+
327
+ sign_out :user # sign_out(scope)
328
+ sign_out @user # sign_out(resource)
329
+ ```
330
+
331
+ There are two things that is important to keep in mind:
332
+
333
+ 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;
334
+
335
+ 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:
336
+
337
+ @request.env["devise.mapping"] = Devise.mappings[:user]
338
+ get :new
339
+
340
+ ### Omniauth
341
+
342
+ 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`:
343
+
344
+ ```ruby
345
+ config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo'
346
+ ```
347
+
348
+ You can read more about Omniauth support in the wiki:
349
+
350
+ * https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview
351
+
352
+ ### Other ORMs
353
+
354
+ Devise supports ActiveRecord (default) and Mongoid. To choose other ORM, you just need to require it in the initializer file.
355
+
356
+ ### Migrating from other solutions
357
+
358
+ 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).
359
+
360
+ ## Troubleshooting
361
+
362
+ ### Heroku
363
+
364
+ Using devise on Heroku with Ruby on Rails 3.1 requires setting:
365
+
366
+ ```ruby
367
+ config.assets.initialize_on_precompile = false
368
+ ```
369
+
370
+ Read more about the potential issues at http://guides.rubyonrails.org/asset_pipeline.html
371
+
372
+ ## Additional information
373
+
374
+ ### Warden
375
+
376
+ 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
+
378
+ https://github.com/hassox/warden
379
+
380
+ ### Contributors
381
+
382
+ We have a long list of valued contributors. Check them all at:
383
+
384
+ https://github.com/plataformatec/devise/contributors
385
+
386
+ ### Maintainers
387
+
388
+ * José Valim (https://github.com/josevalim)
389
+ * Carlos Antônio da Silva (https://github.com/carlosantoniodasilva)
390
+ * Rodrigo Flores (https://github.com/rodrigoflores)
391
+
392
+ ## License
393
+
394
+ MIT License. Copyright 2012 Plataformatec. http://plataformatec.com.br