loyal_devise 2.1.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 +10 -0
  2. data/.travis.yml +15 -0
  3. data/CHANGELOG.rdoc +881 -0
  4. data/CONTRIBUTING.md +12 -0
  5. data/Gemfile +31 -0
  6. data/Gemfile.lock +154 -0
  7. data/MIT-LICENSE +20 -0
  8. data/README.md +388 -0
  9. data/Rakefile +34 -0
  10. data/app/controllers/devise/confirmations_controller.rb +44 -0
  11. data/app/controllers/devise/omniauth_callbacks_controller.rb +31 -0
  12. data/app/controllers/devise/passwords_controller.rb +57 -0
  13. data/app/controllers/devise/registrations_controller.rb +120 -0
  14. data/app/controllers/devise/sessions_controller.rb +51 -0
  15. data/app/controllers/devise/unlocks_controller.rb +45 -0
  16. data/app/controllers/devise_controller.rb +193 -0
  17. data/app/helpers/devise_helper.rb +26 -0
  18. data/app/mailers/devise/mailer.rb +16 -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 +26 -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/controllers/helpers.rb +273 -0
  36. data/lib/devise/controllers/rememberable.rb +53 -0
  37. data/lib/devise/controllers/scoped_views.rb +18 -0
  38. data/lib/devise/controllers/url_helpers.rb +68 -0
  39. data/lib/devise/delegator.rb +17 -0
  40. data/lib/devise/failure_app.rb +188 -0
  41. data/lib/devise/hooks/activatable.rb +12 -0
  42. data/lib/devise/hooks/forgetable.rb +10 -0
  43. data/lib/devise/hooks/lockable.rb +8 -0
  44. data/lib/devise/hooks/rememberable.rb +7 -0
  45. data/lib/devise/hooks/timeoutable.rb +26 -0
  46. data/lib/devise/hooks/trackable.rb +10 -0
  47. data/lib/devise/mailers/helpers.rb +92 -0
  48. data/lib/devise/mapping.rb +173 -0
  49. data/lib/devise/models/authenticatable.rb +269 -0
  50. data/lib/devise/models/confirmable.rb +271 -0
  51. data/lib/devise/models/database_authenticatable.rb +127 -0
  52. data/lib/devise/models/lockable.rb +194 -0
  53. data/lib/devise/models/omniauthable.rb +28 -0
  54. data/lib/devise/models/recoverable.rb +141 -0
  55. data/lib/devise/models/registerable.rb +26 -0
  56. data/lib/devise/models/rememberable.rb +126 -0
  57. data/lib/devise/models/timeoutable.rb +50 -0
  58. data/lib/devise/models/token_authenticatable.rb +90 -0
  59. data/lib/devise/models/trackable.rb +36 -0
  60. data/lib/devise/models/validatable.rb +67 -0
  61. data/lib/devise/models.rb +129 -0
  62. data/lib/devise/modules.rb +30 -0
  63. data/lib/devise/omniauth/config.rb +46 -0
  64. data/lib/devise/omniauth/url_helpers.rb +19 -0
  65. data/lib/devise/omniauth.rb +29 -0
  66. data/lib/devise/orm/active_record.rb +4 -0
  67. data/lib/devise/orm/mongoid.rb +4 -0
  68. data/lib/devise/param_filter.rb +42 -0
  69. data/lib/devise/rails/routes.rb +447 -0
  70. data/lib/devise/rails/warden_compat.rb +44 -0
  71. data/lib/devise/rails.rb +55 -0
  72. data/lib/devise/strategies/authenticatable.rb +177 -0
  73. data/lib/devise/strategies/base.rb +21 -0
  74. data/lib/devise/strategies/database_authenticatable.rb +21 -0
  75. data/lib/devise/strategies/rememberable.rb +56 -0
  76. data/lib/devise/strategies/token_authenticatable.rb +57 -0
  77. data/lib/devise/test_helpers.rb +132 -0
  78. data/lib/devise/time_inflector.rb +15 -0
  79. data/lib/devise/version.rb +4 -0
  80. data/lib/devise.rb +445 -0
  81. data/lib/generators/active_record/devise_generator.rb +80 -0
  82. data/lib/generators/active_record/templates/migration.rb +20 -0
  83. data/lib/generators/active_record/templates/migration_existing.rb +27 -0
  84. data/lib/generators/devise/devise_generator.rb +25 -0
  85. data/lib/generators/devise/install_generator.rb +25 -0
  86. data/lib/generators/devise/orm_helpers.rb +33 -0
  87. data/lib/generators/devise/views_generator.rb +117 -0
  88. data/lib/generators/mongoid/devise_generator.rb +58 -0
  89. data/lib/generators/templates/README +35 -0
  90. data/lib/generators/templates/devise.rb +241 -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 +63 -0
  102. data/test/controllers/helpers_test.rb +254 -0
  103. data/test/controllers/internal_helpers_test.rb +111 -0
  104. data/test/controllers/sessions_controller_test.rb +58 -0
  105. data/test/controllers/url_helpers_test.rb +60 -0
  106. data/test/delegator_test.rb +20 -0
  107. data/test/devise_test.rb +73 -0
  108. data/test/failure_app_test.rb +222 -0
  109. data/test/generators/active_record_generator_test.rb +76 -0
  110. data/test/generators/devise_generator_test.rb +40 -0
  111. data/test/generators/install_generator_test.rb +14 -0
  112. data/test/generators/mongoid_generator_test.rb +24 -0
  113. data/test/generators/views_generator_test.rb +53 -0
  114. data/test/helpers/devise_helper_test.rb +52 -0
  115. data/test/indifferent_hash.rb +34 -0
  116. data/test/integration/authenticatable_test.rb +634 -0
  117. data/test/integration/confirmable_test.rb +299 -0
  118. data/test/integration/database_authenticatable_test.rb +83 -0
  119. data/test/integration/http_authenticatable_test.rb +98 -0
  120. data/test/integration/lockable_test.rb +243 -0
  121. data/test/integration/omniauthable_test.rb +134 -0
  122. data/test/integration/recoverable_test.rb +307 -0
  123. data/test/integration/registerable_test.rb +346 -0
  124. data/test/integration/rememberable_test.rb +159 -0
  125. data/test/integration/timeoutable_test.rb +141 -0
  126. data/test/integration/token_authenticatable_test.rb +162 -0
  127. data/test/integration/trackable_test.rb +93 -0
  128. data/test/mailers/confirmation_instructions_test.rb +103 -0
  129. data/test/mailers/reset_password_instructions_test.rb +84 -0
  130. data/test/mailers/unlock_instructions_test.rb +78 -0
  131. data/test/mapping_test.rb +128 -0
  132. data/test/models/authenticatable_test.rb +8 -0
  133. data/test/models/confirmable_test.rb +392 -0
  134. data/test/models/database_authenticatable_test.rb +190 -0
  135. data/test/models/lockable_test.rb +274 -0
  136. data/test/models/omniauthable_test.rb +8 -0
  137. data/test/models/recoverable_test.rb +206 -0
  138. data/test/models/registerable_test.rb +8 -0
  139. data/test/models/rememberable_test.rb +175 -0
  140. data/test/models/serializable_test.rb +49 -0
  141. data/test/models/timeoutable_test.rb +47 -0
  142. data/test/models/token_authenticatable_test.rb +56 -0
  143. data/test/models/trackable_test.rb +14 -0
  144. data/test/models/validatable_test.rb +117 -0
  145. data/test/models_test.rb +180 -0
  146. data/test/omniauth/config_test.rb +58 -0
  147. data/test/omniauth/url_helpers_test.rb +52 -0
  148. data/test/orm/active_record.rb +10 -0
  149. data/test/orm/mongoid.rb +15 -0
  150. data/test/rails_app/Rakefile +10 -0
  151. data/test/rails_app/app/active_record/admin.rb +7 -0
  152. data/test/rails_app/app/active_record/shim.rb +3 -0
  153. data/test/rails_app/app/active_record/user.rb +7 -0
  154. data/test/rails_app/app/controllers/admins/sessions_controller.rb +7 -0
  155. data/test/rails_app/app/controllers/admins_controller.rb +12 -0
  156. data/test/rails_app/app/controllers/application_controller.rb +9 -0
  157. data/test/rails_app/app/controllers/home_controller.rb +26 -0
  158. data/test/rails_app/app/controllers/publisher/registrations_controller.rb +3 -0
  159. data/test/rails_app/app/controllers/publisher/sessions_controller.rb +3 -0
  160. data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +15 -0
  161. data/test/rails_app/app/controllers/users_controller.rb +24 -0
  162. data/test/rails_app/app/helpers/application_helper.rb +4 -0
  163. data/test/rails_app/app/mailers/users/mailer.rb +9 -0
  164. data/test/rails_app/app/mongoid/admin.rb +28 -0
  165. data/test/rails_app/app/mongoid/shim.rb +25 -0
  166. data/test/rails_app/app/mongoid/user.rb +43 -0
  167. data/test/rails_app/app/views/admins/index.html.erb +1 -0
  168. data/test/rails_app/app/views/admins/sessions/new.html.erb +2 -0
  169. data/test/rails_app/app/views/home/admin_dashboard.html.erb +1 -0
  170. data/test/rails_app/app/views/home/index.html.erb +1 -0
  171. data/test/rails_app/app/views/home/join.html.erb +1 -0
  172. data/test/rails_app/app/views/home/private.html.erb +1 -0
  173. data/test/rails_app/app/views/home/user_dashboard.html.erb +1 -0
  174. data/test/rails_app/app/views/layouts/application.html.erb +24 -0
  175. data/test/rails_app/app/views/users/index.html.erb +1 -0
  176. data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +1 -0
  177. data/test/rails_app/app/views/users/sessions/new.html.erb +1 -0
  178. data/test/rails_app/config/application.rb +42 -0
  179. data/test/rails_app/config/boot.rb +9 -0
  180. data/test/rails_app/config/database.yml +18 -0
  181. data/test/rails_app/config/environment.rb +6 -0
  182. data/test/rails_app/config/environments/development.rb +19 -0
  183. data/test/rails_app/config/environments/production.rb +34 -0
  184. data/test/rails_app/config/environments/test.rb +34 -0
  185. data/test/rails_app/config/initializers/backtrace_silencers.rb +8 -0
  186. data/test/rails_app/config/initializers/devise.rb +179 -0
  187. data/test/rails_app/config/initializers/inflections.rb +3 -0
  188. data/test/rails_app/config/initializers/secret_token.rb +3 -0
  189. data/test/rails_app/config/routes.rb +101 -0
  190. data/test/rails_app/config.ru +4 -0
  191. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +75 -0
  192. data/test/rails_app/db/schema.rb +53 -0
  193. data/test/rails_app/lib/shared_admin.rb +15 -0
  194. data/test/rails_app/lib/shared_user.rb +27 -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 +249 -0
  201. data/test/support/assertions.rb +41 -0
  202. data/test/support/helpers.rb +92 -0
  203. data/test/support/integration.rb +93 -0
  204. data/test/support/locale/en.yml +4 -0
  205. data/test/support/webrat/integrations/rails.rb +25 -0
  206. data/test/test_helper.rb +28 -0
  207. data/test/test_helpers_test.rb +152 -0
  208. metadata +407 -0
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,12 @@
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. In case it was not, create your report including Rails, Devise and Warden versions. If you are getting exceptions, please include the full backtrace.
8
+
9
+ That's it! The more information you give, the more easy it becomes for us to track it down and fix it.
10
+ Ideally, you should provide an application that reproduces the error or a test case to Devise's suite.
11
+
12
+ Thanks!
data/Gemfile ADDED
@@ -0,0 +1,31 @@
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", :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 "mongo", "~> 1.3.0"
28
+ gem "mongoid", "~> 2.0"
29
+ gem "bson_ext", "~> 1.3.0"
30
+ end
31
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,154 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ loyal_devise (2.1.2)
5
+ bcrypt-ruby (~> 3.0)
6
+ loyal_warden (~> 2.0.0)
7
+ orm_adapter (~> 0.1)
8
+
9
+ GEM
10
+ remote: http://rubygems.org/
11
+ specs:
12
+ actionmailer (3.2.6)
13
+ actionpack (= 3.2.6)
14
+ mail (~> 2.4.4)
15
+ actionpack (3.2.6)
16
+ activemodel (= 3.2.6)
17
+ activesupport (= 3.2.6)
18
+ builder (~> 3.0.0)
19
+ erubis (~> 2.7.0)
20
+ journey (~> 1.0.1)
21
+ rack (~> 1.4.0)
22
+ rack-cache (~> 1.2)
23
+ rack-test (~> 0.6.1)
24
+ sprockets (~> 2.1.3)
25
+ activemodel (3.2.6)
26
+ activesupport (= 3.2.6)
27
+ builder (~> 3.0.0)
28
+ activerecord (3.2.6)
29
+ activemodel (= 3.2.6)
30
+ activesupport (= 3.2.6)
31
+ arel (~> 3.0.2)
32
+ tzinfo (~> 0.3.29)
33
+ activeresource (3.2.6)
34
+ activemodel (= 3.2.6)
35
+ activesupport (= 3.2.6)
36
+ activesupport (3.2.6)
37
+ i18n (~> 0.6)
38
+ multi_json (~> 1.0)
39
+ addressable (2.2.6)
40
+ arel (3.0.2)
41
+ bcrypt-ruby (3.0.1)
42
+ bson (1.5.1)
43
+ bson_ext (1.3.1)
44
+ builder (3.0.0)
45
+ erubis (2.7.0)
46
+ faraday (0.7.5)
47
+ addressable (~> 2.2.6)
48
+ multipart-post (~> 1.1.3)
49
+ rack (>= 1.1.0, < 2)
50
+ hashie (1.2.0)
51
+ hike (1.2.1)
52
+ i18n (0.6.0)
53
+ journey (1.0.4)
54
+ json (1.7.3)
55
+ loyal_warden (2.0.0)
56
+ rack (>= 1.0)
57
+ mail (2.4.4)
58
+ i18n (>= 0.4.0)
59
+ mime-types (~> 1.16)
60
+ treetop (~> 1.4.8)
61
+ metaclass (0.0.1)
62
+ mime-types (1.18)
63
+ mocha (0.10.0)
64
+ metaclass (~> 0.0.1)
65
+ mongo (1.3.1)
66
+ bson (>= 1.3.1)
67
+ mongoid (2.3.4)
68
+ activemodel (~> 3.1)
69
+ mongo (~> 1.3)
70
+ tzinfo (~> 0.3.22)
71
+ multi_json (1.0.4)
72
+ multipart-post (1.1.4)
73
+ nokogiri (1.5.0)
74
+ oauth2 (0.5.1)
75
+ faraday (~> 0.7.4)
76
+ multi_json (~> 1.0.3)
77
+ omniauth (1.0.1)
78
+ hashie (~> 1.2)
79
+ rack
80
+ omniauth-facebook (1.0.0)
81
+ omniauth-oauth2 (~> 1.0.0)
82
+ omniauth-oauth2 (1.0.0)
83
+ oauth2 (~> 0.5.0)
84
+ omniauth (~> 1.0)
85
+ omniauth-openid (1.0.1)
86
+ omniauth (~> 1.0)
87
+ rack-openid (~> 1.3.1)
88
+ orm_adapter (0.4.0)
89
+ polyglot (0.3.3)
90
+ rack (1.4.1)
91
+ rack-cache (1.2)
92
+ rack (>= 0.4)
93
+ rack-openid (1.3.1)
94
+ rack (>= 1.1.0)
95
+ ruby-openid (>= 2.1.8)
96
+ rack-ssl (1.3.2)
97
+ rack
98
+ rack-test (0.6.1)
99
+ rack (>= 1.0)
100
+ rails (3.2.6)
101
+ actionmailer (= 3.2.6)
102
+ actionpack (= 3.2.6)
103
+ activerecord (= 3.2.6)
104
+ activeresource (= 3.2.6)
105
+ activesupport (= 3.2.6)
106
+ bundler (~> 1.0)
107
+ railties (= 3.2.6)
108
+ railties (3.2.6)
109
+ actionpack (= 3.2.6)
110
+ activesupport (= 3.2.6)
111
+ rack-ssl (~> 1.3.2)
112
+ rake (>= 0.8.7)
113
+ rdoc (~> 3.4)
114
+ thor (>= 0.14.6, < 2.0)
115
+ rake (0.9.2.2)
116
+ rdoc (3.12)
117
+ json (~> 1.4)
118
+ ruby-openid (2.1.8)
119
+ sprockets (2.1.3)
120
+ hike (~> 1.2)
121
+ rack (~> 1.0)
122
+ tilt (~> 1.1, != 1.3.0)
123
+ sqlite3 (1.3.5)
124
+ thor (0.15.2)
125
+ tilt (1.3.3)
126
+ treetop (1.4.10)
127
+ polyglot
128
+ polyglot (>= 0.3.1)
129
+ tzinfo (0.3.33)
130
+ webrat (0.7.2)
131
+ nokogiri (>= 1.2.0)
132
+ rack (>= 1.0)
133
+ rack-test (>= 0.5.3)
134
+
135
+ PLATFORMS
136
+ ruby
137
+
138
+ DEPENDENCIES
139
+ activerecord-jdbc-adapter
140
+ activerecord-jdbcsqlite3-adapter
141
+ bson_ext (~> 1.3.0)
142
+ jruby-openssl
143
+ loyal_devise!
144
+ mocha
145
+ mongo (~> 1.3.0)
146
+ mongoid (~> 2.0)
147
+ omniauth (~> 1.0.0)
148
+ omniauth-facebook
149
+ omniauth-oauth2 (~> 1.0.0)
150
+ omniauth-openid (~> 1.0.1)
151
+ rails (~> 3.2.6)
152
+ rdoc
153
+ sqlite3
154
+ webrat (= 0.7.2)
data/MIT-LICENSE ADDED
@@ -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.
data/README.md ADDED
@@ -0,0 +1,388 @@
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 from other providers. You can read more about Omniauth support in the wiki:
343
+
344
+ * https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview
345
+
346
+ ### Other ORMs
347
+
348
+ Devise supports ActiveRecord (default) and Mongoid. To choose other ORM, you just need to require it in the initializer file.
349
+
350
+ ### Migrating from other solutions
351
+
352
+ 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).
353
+
354
+ ## Troubleshooting
355
+
356
+ ### Heroku
357
+
358
+ Using devise on Heroku with Ruby on Rails 3.1 requires setting:
359
+
360
+ ```ruby
361
+ config.assets.initialize_on_precompile = false
362
+ ```
363
+
364
+ Read more about the potential issues at http://guides.rubyonrails.org/asset_pipeline.html
365
+
366
+ ## Additional information
367
+
368
+ ### Warden
369
+
370
+ 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:
371
+
372
+ https://github.com/hassox/warden
373
+
374
+ ### Contributors
375
+
376
+ We have a long list of valued contributors. Check them all at:
377
+
378
+ https://github.com/plataformatec/devise/contributors
379
+
380
+ ### Maintainers
381
+
382
+ * José Valim (https://github.com/josevalim)
383
+ * Carlos Antônio da Silva (https://github.com/carlosantoniodasilva)
384
+ * Rodrigo Flores (https://github.com/rodrigoflores)
385
+
386
+ ## License
387
+
388
+ MIT License. Copyright 2012 Plataformatec. http://plataformatec.com.br
data/Rakefile ADDED
@@ -0,0 +1,34 @@
1
+ # encoding: UTF-8
2
+ require "bundler/gem_tasks"
3
+ require 'rake/testtask'
4
+ require 'rdoc/task'
5
+
6
+ desc 'Default: run tests for all ORMs.'
7
+ task :default => :test
8
+
9
+ desc 'Run Devise tests for all ORMs.'
10
+ task :pre_commit do
11
+ Dir[File.join(File.dirname(__FILE__), 'test', 'orm', '*.rb')].each do |file|
12
+ orm = File.basename(file).split(".").first
13
+ # "Some day, my son, rake's inner wisdom will reveal itself. Until then,
14
+ # take this `system` -- may its brute force protect you well."
15
+ exit 1 unless system "rake test DEVISE_ORM=#{orm}"
16
+ end
17
+ end
18
+
19
+ desc 'Run Devise unit tests.'
20
+ Rake::TestTask.new(:test) do |t|
21
+ t.libs << 'lib'
22
+ t.libs << 'test'
23
+ t.pattern = 'test/**/*_test.rb'
24
+ t.verbose = true
25
+ end
26
+
27
+ desc 'Generate documentation for Devise.'
28
+ Rake::RDocTask.new(:rdoc) do |rdoc|
29
+ rdoc.rdoc_dir = 'rdoc'
30
+ rdoc.title = 'Devise'
31
+ rdoc.options << '--line-numbers' << '--inline-source'
32
+ rdoc.rdoc_files.include('README.md')
33
+ rdoc.rdoc_files.include('lib/**/*.rb')
34
+ end
@@ -0,0 +1,44 @@
1
+ # -*- encoding : utf-8 -*-
2
+ class Devise::ConfirmationsController < DeviseController
3
+ # GET /resource/confirmation/new
4
+ def new
5
+ build_resource({})
6
+ end
7
+
8
+ # POST /resource/confirmation
9
+ def create
10
+ self.resource = resource_class.send_confirmation_instructions(resource_params)
11
+
12
+ if successfully_sent?(resource)
13
+ respond_with({}, :location => after_resending_confirmation_instructions_path_for(resource_name))
14
+ else
15
+ respond_with(resource)
16
+ end
17
+ end
18
+
19
+ # GET /resource/confirmation?confirmation_token=abcdef
20
+ def show
21
+ self.resource = resource_class.confirm_by_token(params[:confirmation_token])
22
+
23
+ if resource.errors.empty?
24
+ set_flash_message(:notice, :confirmed) if is_navigational_format?
25
+ sign_in(resource_name, resource)
26
+ respond_with_navigational(resource){ redirect_to after_confirmation_path_for(resource_name, resource) }
27
+ else
28
+ respond_with_navigational(resource.errors, :status => :unprocessable_entity){ render :new }
29
+ end
30
+ end
31
+
32
+ protected
33
+
34
+ # The path used after resending confirmation instructions.
35
+ def after_resending_confirmation_instructions_path_for(resource_name)
36
+ new_session_path(resource_name)
37
+ end
38
+
39
+ # The path used after confirmation.
40
+ def after_confirmation_path_for(resource_name, resource)
41
+ after_sign_in_path_for(resource)
42
+ end
43
+
44
+ end