rmello-devise 2.1.0.2

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 +12 -0
  2. data/.travis.yml +15 -0
  3. data/CHANGELOG.rdoc +845 -0
  4. data/Gemfile +35 -0
  5. data/Gemfile.lock +165 -0
  6. data/MIT-LICENSE +20 -0
  7. data/README.md +383 -0
  8. data/Rakefile +34 -0
  9. data/app/controllers/devise/confirmations_controller.rb +43 -0
  10. data/app/controllers/devise/omniauth_callbacks_controller.rb +24 -0
  11. data/app/controllers/devise/passwords_controller.rb +47 -0
  12. data/app/controllers/devise/registrations_controller.rb +107 -0
  13. data/app/controllers/devise/sessions_controller.rb +49 -0
  14. data/app/controllers/devise/unlocks_controller.rb +44 -0
  15. data/app/controllers/devise_controller.rb +184 -0
  16. data/app/helpers/devise_helper.rb +25 -0
  17. data/app/mailers/devise/mailer.rb +15 -0
  18. data/app/views/devise/_links.erb +3 -0
  19. data/app/views/devise/confirmations/new.html.erb +12 -0
  20. data/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
  21. data/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
  22. data/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
  23. data/app/views/devise/passwords/edit.html.erb +16 -0
  24. data/app/views/devise/passwords/new.html.erb +12 -0
  25. data/app/views/devise/registrations/edit.html.erb +25 -0
  26. data/app/views/devise/registrations/new.html.erb +18 -0
  27. data/app/views/devise/sessions/new.html.erb +17 -0
  28. data/app/views/devise/shared/_links.erb +25 -0
  29. data/app/views/devise/unlocks/new.html.erb +12 -0
  30. data/config/locales/en.yml +57 -0
  31. data/devise.gemspec +25 -0
  32. data/gemfiles/Gemfile.rails-3.1.x +35 -0
  33. data/gemfiles/Gemfile.rails-3.1.x.lock +167 -0
  34. data/lib/devise.rb +440 -0
  35. data/lib/devise/controllers/helpers.rb +269 -0
  36. data/lib/devise/controllers/rememberable.rb +52 -0
  37. data/lib/devise/controllers/scoped_views.rb +17 -0
  38. data/lib/devise/controllers/url_helpers.rb +67 -0
  39. data/lib/devise/delegator.rb +16 -0
  40. data/lib/devise/failure_app.rb +187 -0
  41. data/lib/devise/hooks/activatable.rb +11 -0
  42. data/lib/devise/hooks/forgetable.rb +9 -0
  43. data/lib/devise/hooks/lockable.rb +7 -0
  44. data/lib/devise/hooks/rememberable.rb +6 -0
  45. data/lib/devise/hooks/timeoutable.rb +22 -0
  46. data/lib/devise/hooks/trackable.rb +9 -0
  47. data/lib/devise/mailers/helpers.rb +86 -0
  48. data/lib/devise/mapping.rb +172 -0
  49. data/lib/devise/models.rb +128 -0
  50. data/lib/devise/models/authenticatable.rb +231 -0
  51. data/lib/devise/models/confirmable.rb +268 -0
  52. data/lib/devise/models/database_authenticatable.rb +126 -0
  53. data/lib/devise/models/lockable.rb +185 -0
  54. data/lib/devise/models/omniauthable.rb +27 -0
  55. data/lib/devise/models/recoverable.rb +140 -0
  56. data/lib/devise/models/registerable.rb +25 -0
  57. data/lib/devise/models/rememberable.rb +125 -0
  58. data/lib/devise/models/timeoutable.rb +49 -0
  59. data/lib/devise/models/token_authenticatable.rb +77 -0
  60. data/lib/devise/models/trackable.rb +35 -0
  61. data/lib/devise/models/validatable.rb +66 -0
  62. data/lib/devise/modules.rb +29 -0
  63. data/lib/devise/omniauth.rb +28 -0
  64. data/lib/devise/omniauth/config.rb +45 -0
  65. data/lib/devise/omniauth/url_helpers.rb +33 -0
  66. data/lib/devise/orm/active_record.rb +3 -0
  67. data/lib/devise/orm/mongoid.rb +3 -0
  68. data/lib/devise/param_filter.rb +41 -0
  69. data/lib/devise/rails.rb +54 -0
  70. data/lib/devise/rails/routes.rb +426 -0
  71. data/lib/devise/rails/warden_compat.rb +43 -0
  72. data/lib/devise/strategies/authenticatable.rb +176 -0
  73. data/lib/devise/strategies/base.rb +15 -0
  74. data/lib/devise/strategies/database_authenticatable.rb +20 -0
  75. data/lib/devise/strategies/rememberable.rb +55 -0
  76. data/lib/devise/strategies/token_authenticatable.rb +56 -0
  77. data/lib/devise/test_helpers.rb +130 -0
  78. data/lib/devise/version.rb +3 -0
  79. data/lib/generators/active_record/devise_generator.rb +75 -0
  80. data/lib/generators/active_record/templates/migration.rb +19 -0
  81. data/lib/generators/active_record/templates/migration_existing.rb +26 -0
  82. data/lib/generators/devise/devise_generator.rb +24 -0
  83. data/lib/generators/devise/install_generator.rb +24 -0
  84. data/lib/generators/devise/orm_helpers.rb +32 -0
  85. data/lib/generators/devise/views_generator.rb +110 -0
  86. data/lib/generators/mongoid/devise_generator.rb +57 -0
  87. data/lib/generators/templates/README +31 -0
  88. data/lib/generators/templates/devise.rb +216 -0
  89. data/lib/generators/templates/markerb/confirmation_instructions.markerb +5 -0
  90. data/lib/generators/templates/markerb/reset_password_instructions.markerb +8 -0
  91. data/lib/generators/templates/markerb/unlock_instructions.markerb +7 -0
  92. data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +15 -0
  93. data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +19 -0
  94. data/lib/generators/templates/simple_form_for/passwords/new.html.erb +15 -0
  95. data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +22 -0
  96. data/lib/generators/templates/simple_form_for/registrations/new.html.erb +17 -0
  97. data/lib/generators/templates/simple_form_for/sessions/new.html.erb +15 -0
  98. data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +15 -0
  99. data/test/controllers/custom_strategy_test.rb +62 -0
  100. data/test/controllers/helpers_test.rb +254 -0
  101. data/test/controllers/internal_helpers_test.rb +104 -0
  102. data/test/controllers/sessions_controller_test.rb +43 -0
  103. data/test/controllers/url_helpers_test.rb +59 -0
  104. data/test/delegator_test.rb +19 -0
  105. data/test/devise_test.rb +72 -0
  106. data/test/failure_app_test.rb +221 -0
  107. data/test/generators/active_record_generator_test.rb +69 -0
  108. data/test/generators/devise_generator_test.rb +39 -0
  109. data/test/generators/install_generator_test.rb +13 -0
  110. data/test/generators/mongoid_generator_test.rb +23 -0
  111. data/test/generators/views_generator_test.rb +52 -0
  112. data/test/helpers/devise_helper_test.rb +51 -0
  113. data/test/indifferent_hash.rb +33 -0
  114. data/test/integration/authenticatable_test.rb +587 -0
  115. data/test/integration/confirmable_test.rb +255 -0
  116. data/test/integration/database_authenticatable_test.rb +82 -0
  117. data/test/integration/http_authenticatable_test.rb +97 -0
  118. data/test/integration/lockable_test.rb +224 -0
  119. data/test/integration/omniauthable_test.rb +133 -0
  120. data/test/integration/recoverable_test.rb +300 -0
  121. data/test/integration/registerable_test.rb +324 -0
  122. data/test/integration/rememberable_test.rb +158 -0
  123. data/test/integration/timeoutable_test.rb +114 -0
  124. data/test/integration/token_authenticatable_test.rb +161 -0
  125. data/test/integration/trackable_test.rb +92 -0
  126. data/test/mailers/confirmation_instructions_test.rb +95 -0
  127. data/test/mailers/reset_password_instructions_test.rb +83 -0
  128. data/test/mailers/unlock_instructions_test.rb +77 -0
  129. data/test/mapping_test.rb +127 -0
  130. data/test/models/authenticatable_test.rb +7 -0
  131. data/test/models/confirmable_test.rb +377 -0
  132. data/test/models/database_authenticatable_test.rb +189 -0
  133. data/test/models/lockable_test.rb +263 -0
  134. data/test/models/omniauthable_test.rb +7 -0
  135. data/test/models/recoverable_test.rb +205 -0
  136. data/test/models/registerable_test.rb +7 -0
  137. data/test/models/rememberable_test.rb +174 -0
  138. data/test/models/serializable_test.rb +48 -0
  139. data/test/models/timeoutable_test.rb +46 -0
  140. data/test/models/token_authenticatable_test.rb +55 -0
  141. data/test/models/trackable_test.rb +13 -0
  142. data/test/models/validatable_test.rb +117 -0
  143. data/test/models_test.rb +179 -0
  144. data/test/omniauth/config_test.rb +57 -0
  145. data/test/omniauth/url_helpers_test.rb +58 -0
  146. data/test/orm/active_record.rb +9 -0
  147. data/test/orm/mongoid.rb +14 -0
  148. data/test/rails_app/Rakefile +10 -0
  149. data/test/rails_app/app/active_record/admin.rb +6 -0
  150. data/test/rails_app/app/active_record/mobile_user.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 +6 -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 +3 -0
  163. data/test/rails_app/app/mongoid/admin.rb +27 -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 +93 -0
  190. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +88 -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_mobile_user.rb +13 -0
  194. data/test/rails_app/lib/shared_user.rb +26 -0
  195. data/test/rails_app/public/404.html +26 -0
  196. data/test/rails_app/public/422.html +26 -0
  197. data/test/rails_app/public/500.html +26 -0
  198. data/test/rails_app/public/favicon.ico +0 -0
  199. data/test/rails_app/script/rails +10 -0
  200. data/test/routes_test.rb +248 -0
  201. data/test/support/assertions.rb +40 -0
  202. data/test/support/helpers.rb +97 -0
  203. data/test/support/integration.rb +90 -0
  204. data/test/support/locale/en.yml +4 -0
  205. data/test/support/webrat/integrations/rails.rb +24 -0
  206. data/test/test_helper.rb +27 -0
  207. data/test/test_helpers_test.rb +134 -0
  208. metadata +425 -0
data/Gemfile ADDED
@@ -0,0 +1,35 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem "rails", "~> 3.2.3"
6
+ gem "omniauth", "~> 1.0.0"
7
+ gem "omniauth-oauth2", "~> 1.0.0"
8
+ gem "rdoc"
9
+
10
+ group :test do
11
+ gem "omniauth-facebook"
12
+ gem "omniauth-openid", "~> 1.0.1"
13
+ gem "webrat", "0.7.2", :require => false
14
+ gem "mocha", :require => false
15
+
16
+ platforms :mri_18 do
17
+ gem "ruby-debug", ">= 0.10.3"
18
+ end
19
+ end
20
+
21
+ platforms :jruby do
22
+ gem "activerecord-jdbc-adapter"
23
+ gem "activerecord-jdbcsqlite3-adapter"
24
+ gem "jruby-openssl"
25
+ end
26
+
27
+ platforms :ruby do
28
+ gem "sqlite3"
29
+
30
+ group :mongoid do
31
+ gem "mongo", "~> 1.3.0"
32
+ gem "mongoid", "~> 2.0"
33
+ gem "bson_ext", "~> 1.3.0"
34
+ end
35
+ end
@@ -0,0 +1,165 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rmello-devise (2.1.0.1)
5
+ bcrypt-ruby (~> 3.0)
6
+ orm_adapter (~> 0.0.7)
7
+ railties (~> 3.1)
8
+ warden (~> 1.1.1)
9
+
10
+ GEM
11
+ remote: http://rubygems.org/
12
+ specs:
13
+ actionmailer (3.2.3)
14
+ actionpack (= 3.2.3)
15
+ mail (~> 2.4.4)
16
+ actionpack (3.2.3)
17
+ activemodel (= 3.2.3)
18
+ activesupport (= 3.2.3)
19
+ builder (~> 3.0.0)
20
+ 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.2)
26
+ activemodel (3.2.3)
27
+ activesupport (= 3.2.3)
28
+ builder (~> 3.0.0)
29
+ activerecord (3.2.3)
30
+ activemodel (= 3.2.3)
31
+ activesupport (= 3.2.3)
32
+ arel (~> 3.0.2)
33
+ tzinfo (~> 0.3.29)
34
+ activeresource (3.2.3)
35
+ activemodel (= 3.2.3)
36
+ activesupport (= 3.2.3)
37
+ activesupport (3.2.3)
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)
47
+ erubis (2.7.0)
48
+ faraday (0.7.5)
49
+ addressable (~> 2.2.6)
50
+ multipart-post (~> 1.1.3)
51
+ rack (>= 1.1.0, < 2)
52
+ hashie (1.2.0)
53
+ hike (1.2.1)
54
+ i18n (0.6.0)
55
+ journey (1.0.3)
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)
66
+ metaclass (~> 0.0.1)
67
+ mongo (1.3.1)
68
+ bson (>= 1.3.1)
69
+ mongoid (2.3.4)
70
+ activemodel (~> 3.1)
71
+ mongo (~> 1.3)
72
+ tzinfo (~> 0.3.22)
73
+ multi_json (1.0.4)
74
+ multipart-post (1.1.4)
75
+ nokogiri (1.5.0)
76
+ oauth2 (0.5.1)
77
+ faraday (~> 0.7.4)
78
+ multi_json (~> 1.0.3)
79
+ omniauth (1.0.1)
80
+ hashie (~> 1.2)
81
+ rack
82
+ omniauth-facebook (1.0.0)
83
+ omniauth-oauth2 (~> 1.0.0)
84
+ omniauth-oauth2 (1.0.0)
85
+ oauth2 (~> 0.5.0)
86
+ omniauth (~> 1.0)
87
+ omniauth-openid (1.0.1)
88
+ omniauth (~> 1.0)
89
+ rack-openid (~> 1.3.1)
90
+ orm_adapter (0.0.7)
91
+ polyglot (0.3.3)
92
+ rack (1.4.1)
93
+ rack-cache (1.2)
94
+ rack (>= 0.4)
95
+ rack-openid (1.3.1)
96
+ rack (>= 1.1.0)
97
+ ruby-openid (>= 2.1.8)
98
+ rack-ssl (1.3.2)
99
+ rack
100
+ rack-test (0.6.1)
101
+ rack (>= 1.0)
102
+ rails (3.2.3)
103
+ actionmailer (= 3.2.3)
104
+ actionpack (= 3.2.3)
105
+ activerecord (= 3.2.3)
106
+ activeresource (= 3.2.3)
107
+ activesupport (= 3.2.3)
108
+ bundler (~> 1.0)
109
+ railties (= 3.2.3)
110
+ railties (3.2.3)
111
+ actionpack (= 3.2.3)
112
+ activesupport (= 3.2.3)
113
+ rack-ssl (~> 1.3.2)
114
+ rake (>= 0.8.7)
115
+ rdoc (~> 3.4)
116
+ thor (~> 0.14.6)
117
+ rake (0.9.2.2)
118
+ rbx-require-relative (0.0.5)
119
+ rdoc (3.12)
120
+ json (~> 1.4)
121
+ ruby-debug (0.10.4)
122
+ columnize (>= 0.1)
123
+ ruby-debug-base (~> 0.10.4.0)
124
+ ruby-debug-base (0.10.4)
125
+ linecache (>= 0.3)
126
+ ruby-openid (2.1.8)
127
+ sprockets (2.1.3)
128
+ hike (~> 1.2)
129
+ rack (~> 1.0)
130
+ tilt (~> 1.1, != 1.3.0)
131
+ sqlite3 (1.3.5)
132
+ thor (0.14.6)
133
+ tilt (1.3.3)
134
+ treetop (1.4.10)
135
+ polyglot
136
+ polyglot (>= 0.3.1)
137
+ tzinfo (0.3.33)
138
+ warden (1.1.1)
139
+ rack (>= 1.0)
140
+ webrat (0.7.2)
141
+ nokogiri (>= 1.2.0)
142
+ rack (>= 1.0)
143
+ rack-test (>= 0.5.3)
144
+
145
+ PLATFORMS
146
+ ruby
147
+
148
+ DEPENDENCIES
149
+ activerecord-jdbc-adapter
150
+ activerecord-jdbcsqlite3-adapter
151
+ bson_ext (~> 1.3.0)
152
+ jruby-openssl
153
+ mocha
154
+ mongo (~> 1.3.0)
155
+ mongoid (~> 2.0)
156
+ omniauth (~> 1.0.0)
157
+ omniauth-facebook
158
+ omniauth-oauth2 (~> 1.0.0)
159
+ omniauth-openid (~> 1.0.1)
160
+ rails (~> 3.2.3)
161
+ rdoc
162
+ rmello-devise!
163
+ ruby-debug (>= 0.10.3)
164
+ sqlite3
165
+ webrat (= 0.7.2)
@@ -0,0 +1,20 @@
1
+ Copyright 2009-2012 Plataformatec. http://plataformatec.com.br
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,383 @@
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
2
+
3
+ ## Devise
4
+
5
+ INFO: This README is [also available in a friendly navigable format](http://devise.plataformatec.com.br/).
6
+
7
+ [![Build Status](https://secure.travis-ci.org/plataformatec/devise.png)](http://travis-ci.org/plataformatec/devise) [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/plataformatec/devise)
8
+
9
+ Devise is a flexible authentication solution for Rails based on Warden. It:
10
+
11
+ * Is Rack based;
12
+ * Is a complete MVC solution based on Rails engines;
13
+ * Allows you to have multiple roles (or models/scopes) signed in at the same time;
14
+ * Is based on a modularity concept: use just what you really need.
15
+
16
+ It's composed of 12 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 (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 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.
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 => "usuarios", :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. To use them, you just need to include Devise::TestHelpers in your test class and use the sign_in and sign_out method. Such methods have the same signature as in controllers:
308
+
309
+ ```ruby
310
+ sign_in :user, @user # sign_in(scope, resource)
311
+ sign_in @user # sign_in(resource)
312
+
313
+ sign_out :user # sign_out(scope)
314
+ sign_out @user # sign_out(resource)
315
+ ```
316
+
317
+ You can include the Devise Test Helpers in all of your tests by adding the following to the bottom of your test/test_helper.rb file:
318
+
319
+ ```ruby
320
+ class ActionController::TestCase
321
+ include Devise::TestHelpers
322
+ end
323
+ ```
324
+
325
+ If you're using RSpec and want the helpers automatically included within all `describe` blocks, add a file called spec/support/devise.rb with the following contents:
326
+
327
+ ```ruby
328
+ RSpec.configure do |config|
329
+ config.include Devise::TestHelpers, :type => :controller
330
+ end
331
+ ```
332
+
333
+ Do not use such helpers for integration tests such as Cucumber or Webrat. Instead, fill in the form or explicitly set the user in session. For more tips, check the wiki (https://wiki.github.com/plataformatec/devise).
334
+
335
+ ### Omniauth
336
+
337
+ Devise comes with Omniauth support out of the box to authenticate from other providers. You can read more about Omniauth support in the wiki:
338
+
339
+ * https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview
340
+
341
+ ### Other ORMs
342
+
343
+ Devise supports ActiveRecord (default) and Mongoid. To choose other ORM, you just need to require it in the initializer file.
344
+
345
+ ### Migrating from other solutions
346
+
347
+ 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).
348
+
349
+ ## Troubleshooting
350
+
351
+ ### Heroku
352
+
353
+ Using devise on Heroku with Ruby on Rails 3.1 requires setting:
354
+
355
+ ```ruby
356
+ config.assets.initialize_on_precompile = false
357
+ ```
358
+
359
+ Read more about the potential issues at http://guides.rubyonrails.org/asset_pipeline.html
360
+
361
+ ## Additional information
362
+
363
+ ### Warden
364
+
365
+ 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:
366
+
367
+ https://github.com/hassox/warden
368
+
369
+ ### Contributors
370
+
371
+ We have a long list of valued contributors. Check them all at:
372
+
373
+ https://github.com/plataformatec/devise/contributors
374
+
375
+ ### Maintainers
376
+
377
+ * José Valim (https://github.com/josevalim)
378
+ * Carlos Antônio da Silva (https://github.com/carlosantoniodasilva)
379
+ * Rodrigo Flores (https://github.com/rodrigoflores)
380
+
381
+ ## License
382
+
383
+ MIT License. Copyright 2012 Plataformatec. http://plataformatec.com.br