brainsome_devise 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (234) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.travis.yml +35 -0
  4. data/.yardopts +9 -0
  5. data/CHANGELOG.md +1086 -0
  6. data/CONTRIBUTING.md +14 -0
  7. data/Gemfile +29 -0
  8. data/Gemfile.lock +166 -0
  9. data/MIT-LICENSE +20 -0
  10. data/README.md +506 -0
  11. data/Rakefile +35 -0
  12. data/app/controllers/devise/confirmations_controller.rb +47 -0
  13. data/app/controllers/devise/omniauth_callbacks_controller.rb +30 -0
  14. data/app/controllers/devise/passwords_controller.rb +70 -0
  15. data/app/controllers/devise/registrations_controller.rb +148 -0
  16. data/app/controllers/devise/sessions_controller.rb +76 -0
  17. data/app/controllers/devise/unlocks_controller.rb +46 -0
  18. data/app/controllers/devise_controller.rb +176 -0
  19. data/app/helpers/devise_helper.rb +25 -0
  20. data/app/mailers/devise/mailer.rb +20 -0
  21. data/app/views/devise/confirmations/new.html.erb +12 -0
  22. data/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
  23. data/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
  24. data/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
  25. data/app/views/devise/passwords/edit.html.erb +16 -0
  26. data/app/views/devise/passwords/new.html.erb +12 -0
  27. data/app/views/devise/registrations/edit.html.erb +29 -0
  28. data/app/views/devise/registrations/new.html.erb +18 -0
  29. data/app/views/devise/sessions/new.html.erb +17 -0
  30. data/app/views/devise/shared/_links.html.erb +25 -0
  31. data/app/views/devise/unlocks/new.html.erb +12 -0
  32. data/config/locales/en.yml +60 -0
  33. data/devise.gemspec +27 -0
  34. data/devise.png +0 -0
  35. data/gemfiles/Gemfile.rails-3.2-stable +29 -0
  36. data/gemfiles/Gemfile.rails-3.2-stable.lock +166 -0
  37. data/gemfiles/Gemfile.rails-4.0-stable +29 -0
  38. data/gemfiles/Gemfile.rails-4.0-stable.lock +162 -0
  39. data/gemfiles/Gemfile.rails-head +32 -0
  40. data/gemfiles/Gemfile.rails-head.lock +206 -0
  41. data/lib/devise.rb +495 -0
  42. data/lib/devise/controllers/helpers.rb +284 -0
  43. data/lib/devise/controllers/rememberable.rb +47 -0
  44. data/lib/devise/controllers/scoped_views.rb +17 -0
  45. data/lib/devise/controllers/sign_in_out.rb +102 -0
  46. data/lib/devise/controllers/store_location.rb +56 -0
  47. data/lib/devise/controllers/url_helpers.rb +69 -0
  48. data/lib/devise/delegator.rb +16 -0
  49. data/lib/devise/failure_app.rb +205 -0
  50. data/lib/devise/hooks/activatable.rb +10 -0
  51. data/lib/devise/hooks/csrf_cleaner.rb +7 -0
  52. data/lib/devise/hooks/forgetable.rb +9 -0
  53. data/lib/devise/hooks/lockable.rb +7 -0
  54. data/lib/devise/hooks/proxy.rb +21 -0
  55. data/lib/devise/hooks/rememberable.rb +7 -0
  56. data/lib/devise/hooks/timeoutable.rb +35 -0
  57. data/lib/devise/hooks/trackable.rb +9 -0
  58. data/lib/devise/mailers/helpers.rb +90 -0
  59. data/lib/devise/mapping.rb +175 -0
  60. data/lib/devise/models.rb +119 -0
  61. data/lib/devise/models/authenticatable.rb +284 -0
  62. data/lib/devise/models/confirmable.rb +295 -0
  63. data/lib/devise/models/database_authenticatable.rb +164 -0
  64. data/lib/devise/models/lockable.rb +196 -0
  65. data/lib/devise/models/omniauthable.rb +27 -0
  66. data/lib/devise/models/recoverable.rb +147 -0
  67. data/lib/devise/models/registerable.rb +25 -0
  68. data/lib/devise/models/rememberable.rb +129 -0
  69. data/lib/devise/models/timeoutable.rb +49 -0
  70. data/lib/devise/models/trackable.rb +38 -0
  71. data/lib/devise/models/validatable.rb +66 -0
  72. data/lib/devise/modules.rb +28 -0
  73. data/lib/devise/omniauth.rb +28 -0
  74. data/lib/devise/omniauth/config.rb +45 -0
  75. data/lib/devise/omniauth/url_helpers.rb +18 -0
  76. data/lib/devise/orm/active_record.rb +3 -0
  77. data/lib/devise/orm/mongoid.rb +3 -0
  78. data/lib/devise/parameter_filter.rb +40 -0
  79. data/lib/devise/parameter_sanitizer.rb +99 -0
  80. data/lib/devise/rails.rb +56 -0
  81. data/lib/devise/rails/routes.rb +498 -0
  82. data/lib/devise/rails/warden_compat.rb +22 -0
  83. data/lib/devise/strategies/authenticatable.rb +174 -0
  84. data/lib/devise/strategies/base.rb +20 -0
  85. data/lib/devise/strategies/database_authenticatable.rb +23 -0
  86. data/lib/devise/strategies/rememberable.rb +55 -0
  87. data/lib/devise/test_helpers.rb +132 -0
  88. data/lib/devise/time_inflector.rb +14 -0
  89. data/lib/devise/token_generator.rb +70 -0
  90. data/lib/devise/version.rb +3 -0
  91. data/lib/generators/active_record/devise_generator.rb +91 -0
  92. data/lib/generators/active_record/templates/migration.rb +18 -0
  93. data/lib/generators/active_record/templates/migration_existing.rb +25 -0
  94. data/lib/generators/devise/devise_generator.rb +26 -0
  95. data/lib/generators/devise/install_generator.rb +29 -0
  96. data/lib/generators/devise/orm_helpers.rb +51 -0
  97. data/lib/generators/devise/views_generator.rb +135 -0
  98. data/lib/generators/mongoid/devise_generator.rb +55 -0
  99. data/lib/generators/templates/README +35 -0
  100. data/lib/generators/templates/devise.rb +263 -0
  101. data/lib/generators/templates/markerb/confirmation_instructions.markerb +5 -0
  102. data/lib/generators/templates/markerb/reset_password_instructions.markerb +8 -0
  103. data/lib/generators/templates/markerb/unlock_instructions.markerb +7 -0
  104. data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +16 -0
  105. data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +19 -0
  106. data/lib/generators/templates/simple_form_for/passwords/new.html.erb +15 -0
  107. data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +27 -0
  108. data/lib/generators/templates/simple_form_for/registrations/new.html.erb +17 -0
  109. data/lib/generators/templates/simple_form_for/sessions/new.html.erb +15 -0
  110. data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +16 -0
  111. data/script/cached-bundle +49 -0
  112. data/script/s3-put +71 -0
  113. data/test/controllers/custom_registrations_controller_test.rb +35 -0
  114. data/test/controllers/custom_strategy_test.rb +62 -0
  115. data/test/controllers/helpers_test.rb +311 -0
  116. data/test/controllers/internal_helpers_test.rb +123 -0
  117. data/test/controllers/passwords_controller_test.rb +31 -0
  118. data/test/controllers/sessions_controller_test.rb +103 -0
  119. data/test/controllers/url_helpers_test.rb +59 -0
  120. data/test/delegator_test.rb +19 -0
  121. data/test/devise_test.rb +107 -0
  122. data/test/failure_app_test.rb +268 -0
  123. data/test/generators/active_record_generator_test.rb +109 -0
  124. data/test/generators/devise_generator_test.rb +39 -0
  125. data/test/generators/install_generator_test.rb +13 -0
  126. data/test/generators/mongoid_generator_test.rb +23 -0
  127. data/test/generators/views_generator_test.rb +96 -0
  128. data/test/helpers/devise_helper_test.rb +52 -0
  129. data/test/integration/authenticatable_test.rb +729 -0
  130. data/test/integration/confirmable_test.rb +324 -0
  131. data/test/integration/database_authenticatable_test.rb +84 -0
  132. data/test/integration/http_authenticatable_test.rb +105 -0
  133. data/test/integration/lockable_test.rb +239 -0
  134. data/test/integration/omniauthable_test.rb +133 -0
  135. data/test/integration/recoverable_test.rb +334 -0
  136. data/test/integration/registerable_test.rb +359 -0
  137. data/test/integration/rememberable_test.rb +167 -0
  138. data/test/integration/timeoutable_test.rb +189 -0
  139. data/test/integration/trackable_test.rb +92 -0
  140. data/test/mailers/confirmation_instructions_test.rb +115 -0
  141. data/test/mailers/reset_password_instructions_test.rb +96 -0
  142. data/test/mailers/unlock_instructions_test.rb +91 -0
  143. data/test/mapping_test.rb +127 -0
  144. data/test/models/authenticatable_test.rb +13 -0
  145. data/test/models/confirmable_test.rb +454 -0
  146. data/test/models/database_authenticatable_test.rb +249 -0
  147. data/test/models/lockable_test.rb +322 -0
  148. data/test/models/omniauthable_test.rb +7 -0
  149. data/test/models/recoverable_test.rb +196 -0
  150. data/test/models/registerable_test.rb +7 -0
  151. data/test/models/rememberable_test.rb +198 -0
  152. data/test/models/serializable_test.rb +49 -0
  153. data/test/models/timeoutable_test.rb +51 -0
  154. data/test/models/trackable_test.rb +41 -0
  155. data/test/models/validatable_test.rb +127 -0
  156. data/test/models_test.rb +144 -0
  157. data/test/omniauth/config_test.rb +57 -0
  158. data/test/omniauth/url_helpers_test.rb +54 -0
  159. data/test/orm/active_record.rb +10 -0
  160. data/test/orm/mongoid.rb +13 -0
  161. data/test/parameter_sanitizer_test.rb +81 -0
  162. data/test/rails_app/Rakefile +6 -0
  163. data/test/rails_app/app/active_record/admin.rb +6 -0
  164. data/test/rails_app/app/active_record/shim.rb +2 -0
  165. data/test/rails_app/app/active_record/user.rb +6 -0
  166. data/test/rails_app/app/active_record/user_on_engine.rb +7 -0
  167. data/test/rails_app/app/active_record/user_on_main_app.rb +7 -0
  168. data/test/rails_app/app/controllers/admins/sessions_controller.rb +6 -0
  169. data/test/rails_app/app/controllers/admins_controller.rb +11 -0
  170. data/test/rails_app/app/controllers/application_controller.rb +12 -0
  171. data/test/rails_app/app/controllers/application_with_fake_engine.rb +30 -0
  172. data/test/rails_app/app/controllers/custom/registrations_controller.rb +21 -0
  173. data/test/rails_app/app/controllers/home_controller.rb +25 -0
  174. data/test/rails_app/app/controllers/publisher/registrations_controller.rb +2 -0
  175. data/test/rails_app/app/controllers/publisher/sessions_controller.rb +2 -0
  176. data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +14 -0
  177. data/test/rails_app/app/controllers/users_controller.rb +31 -0
  178. data/test/rails_app/app/helpers/application_helper.rb +3 -0
  179. data/test/rails_app/app/mailers/users/mailer.rb +12 -0
  180. data/test/rails_app/app/mongoid/admin.rb +29 -0
  181. data/test/rails_app/app/mongoid/shim.rb +23 -0
  182. data/test/rails_app/app/mongoid/user.rb +39 -0
  183. data/test/rails_app/app/mongoid/user_on_engine.rb +39 -0
  184. data/test/rails_app/app/mongoid/user_on_main_app.rb +39 -0
  185. data/test/rails_app/app/views/admins/index.html.erb +1 -0
  186. data/test/rails_app/app/views/admins/sessions/new.html.erb +2 -0
  187. data/test/rails_app/app/views/home/admin_dashboard.html.erb +1 -0
  188. data/test/rails_app/app/views/home/index.html.erb +1 -0
  189. data/test/rails_app/app/views/home/join.html.erb +1 -0
  190. data/test/rails_app/app/views/home/private.html.erb +1 -0
  191. data/test/rails_app/app/views/home/user_dashboard.html.erb +1 -0
  192. data/test/rails_app/app/views/layouts/application.html.erb +24 -0
  193. data/test/rails_app/app/views/users/edit_form.html.erb +1 -0
  194. data/test/rails_app/app/views/users/index.html.erb +1 -0
  195. data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +1 -0
  196. data/test/rails_app/app/views/users/sessions/new.html.erb +1 -0
  197. data/test/rails_app/bin/bundle +3 -0
  198. data/test/rails_app/bin/rails +4 -0
  199. data/test/rails_app/bin/rake +4 -0
  200. data/test/rails_app/config.ru +4 -0
  201. data/test/rails_app/config/application.rb +40 -0
  202. data/test/rails_app/config/boot.rb +14 -0
  203. data/test/rails_app/config/database.yml +18 -0
  204. data/test/rails_app/config/environment.rb +5 -0
  205. data/test/rails_app/config/environments/development.rb +30 -0
  206. data/test/rails_app/config/environments/production.rb +80 -0
  207. data/test/rails_app/config/environments/test.rb +36 -0
  208. data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
  209. data/test/rails_app/config/initializers/devise.rb +183 -0
  210. data/test/rails_app/config/initializers/inflections.rb +2 -0
  211. data/test/rails_app/config/initializers/secret_token.rb +8 -0
  212. data/test/rails_app/config/initializers/session_store.rb +1 -0
  213. data/test/rails_app/config/routes.rb +122 -0
  214. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +71 -0
  215. data/test/rails_app/db/schema.rb +55 -0
  216. data/test/rails_app/lib/shared_admin.rb +17 -0
  217. data/test/rails_app/lib/shared_user.rb +29 -0
  218. data/test/rails_app/lib/shared_user_without_omniauth.rb +13 -0
  219. data/test/rails_app/public/404.html +26 -0
  220. data/test/rails_app/public/422.html +26 -0
  221. data/test/rails_app/public/500.html +26 -0
  222. data/test/rails_app/public/favicon.ico +0 -0
  223. data/test/routes_test.rb +264 -0
  224. data/test/support/action_controller/record_identifier.rb +10 -0
  225. data/test/support/assertions.rb +39 -0
  226. data/test/support/helpers.rb +70 -0
  227. data/test/support/integration.rb +92 -0
  228. data/test/support/locale/en.yml +8 -0
  229. data/test/support/mongoid.yml +6 -0
  230. data/test/support/webrat/integrations/rails.rb +24 -0
  231. data/test/test_helper.rb +29 -0
  232. data/test/test_helpers_test.rb +163 -0
  233. data/test/test_models.rb +33 -0
  234. metadata +474 -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 [opensource@plataformatec.com.br](mailto:opensource@plataformatec.com.br) instead.
6
+
7
+ 3) Do a small search on the issues tracker before submitting your issue to see if it was already reported / fixed.
8
+
9
+ 4) When reporting an issue, include Rails, Devise and Warden versions. If you are getting exceptions, please include the full backtrace.
10
+
11
+ 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 "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem "rails", "~> 4.1.0"
6
+ gem "omniauth", "~> 1.2.0"
7
+ gem "omniauth-oauth2", "~> 1.1.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.3", require: false
14
+ gem "mocha", "~> 1.1", require: false
15
+ end
16
+
17
+ platforms :jruby do
18
+ gem "activerecord-jdbc-adapter"
19
+ gem "activerecord-jdbcsqlite3-adapter"
20
+ gem "jruby-openssl"
21
+ end
22
+
23
+ platforms :ruby do
24
+ gem "sqlite3"
25
+ end
26
+
27
+ group :mongoid do
28
+ gem "mongoid", "~> 4.0.0"
29
+ end
@@ -0,0 +1,166 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ devise (3.3.0)
5
+ bcrypt (~> 3.0)
6
+ orm_adapter (~> 0.1)
7
+ railties (>= 3.2.6, < 5)
8
+ thread_safe (~> 0.1)
9
+ warden (~> 1.2.3)
10
+
11
+ GEM
12
+ remote: https://rubygems.org/
13
+ specs:
14
+ actionmailer (4.1.5)
15
+ actionpack (= 4.1.5)
16
+ actionview (= 4.1.5)
17
+ mail (~> 2.5.4)
18
+ actionpack (4.1.5)
19
+ actionview (= 4.1.5)
20
+ activesupport (= 4.1.5)
21
+ rack (~> 1.5.2)
22
+ rack-test (~> 0.6.2)
23
+ actionview (4.1.5)
24
+ activesupport (= 4.1.5)
25
+ builder (~> 3.1)
26
+ erubis (~> 2.7.0)
27
+ activemodel (4.1.5)
28
+ activesupport (= 4.1.5)
29
+ builder (~> 3.1)
30
+ activerecord (4.1.5)
31
+ activemodel (= 4.1.5)
32
+ activesupport (= 4.1.5)
33
+ arel (~> 5.0.0)
34
+ activesupport (4.1.5)
35
+ i18n (~> 0.6, >= 0.6.9)
36
+ json (~> 1.7, >= 1.7.7)
37
+ minitest (~> 5.1)
38
+ thread_safe (~> 0.1)
39
+ tzinfo (~> 1.1)
40
+ arel (5.0.1.20140414130214)
41
+ bcrypt (3.1.7)
42
+ bson (2.3.0)
43
+ builder (3.2.2)
44
+ connection_pool (2.0.0)
45
+ erubis (2.7.0)
46
+ faraday (0.9.0)
47
+ multipart-post (>= 1.2, < 3)
48
+ hashie (3.2.0)
49
+ hike (1.2.3)
50
+ i18n (0.6.11)
51
+ json (1.8.1)
52
+ jwt (1.0.0)
53
+ mail (2.5.4)
54
+ mime-types (~> 1.16)
55
+ treetop (~> 1.4.8)
56
+ metaclass (0.0.4)
57
+ mime-types (1.25.1)
58
+ mini_portile (0.6.0)
59
+ minitest (5.4.0)
60
+ mocha (1.1.0)
61
+ metaclass (~> 0.0.1)
62
+ mongoid (4.0.0)
63
+ activemodel (~> 4.0)
64
+ moped (~> 2.0.0)
65
+ origin (~> 2.1)
66
+ tzinfo (>= 0.3.37)
67
+ moped (2.0.0)
68
+ bson (~> 2.2)
69
+ connection_pool (~> 2.0)
70
+ optionable (~> 0.2.0)
71
+ multi_json (1.10.1)
72
+ multi_xml (0.5.5)
73
+ multipart-post (2.0.0)
74
+ nokogiri (1.6.3.1)
75
+ mini_portile (= 0.6.0)
76
+ oauth2 (0.9.4)
77
+ faraday (>= 0.8, < 0.10)
78
+ jwt (~> 1.0)
79
+ multi_json (~> 1.3)
80
+ multi_xml (~> 0.5)
81
+ rack (~> 1.2)
82
+ omniauth (1.2.2)
83
+ hashie (>= 1.2, < 4)
84
+ rack (~> 1.0)
85
+ omniauth-facebook (1.6.0)
86
+ omniauth-oauth2 (~> 1.1)
87
+ omniauth-oauth2 (1.1.2)
88
+ faraday (>= 0.8, < 0.10)
89
+ multi_json (~> 1.3)
90
+ oauth2 (~> 0.9.3)
91
+ omniauth (~> 1.2)
92
+ omniauth-openid (1.0.1)
93
+ omniauth (~> 1.0)
94
+ rack-openid (~> 1.3.1)
95
+ optionable (0.2.0)
96
+ origin (2.1.1)
97
+ orm_adapter (0.5.0)
98
+ polyglot (0.3.5)
99
+ rack (1.5.2)
100
+ rack-openid (1.3.1)
101
+ rack (>= 1.1.0)
102
+ ruby-openid (>= 2.1.8)
103
+ rack-test (0.6.2)
104
+ rack (>= 1.0)
105
+ rails (4.1.5)
106
+ actionmailer (= 4.1.5)
107
+ actionpack (= 4.1.5)
108
+ actionview (= 4.1.5)
109
+ activemodel (= 4.1.5)
110
+ activerecord (= 4.1.5)
111
+ activesupport (= 4.1.5)
112
+ bundler (>= 1.3.0, < 2.0)
113
+ railties (= 4.1.5)
114
+ sprockets-rails (~> 2.0)
115
+ railties (4.1.5)
116
+ actionpack (= 4.1.5)
117
+ activesupport (= 4.1.5)
118
+ rake (>= 0.8.7)
119
+ thor (>= 0.18.1, < 2.0)
120
+ rake (10.3.2)
121
+ rdoc (4.1.1)
122
+ json (~> 1.4)
123
+ ruby-openid (2.5.0)
124
+ sprockets (2.12.1)
125
+ hike (~> 1.2)
126
+ multi_json (~> 1.0)
127
+ rack (~> 1.0)
128
+ tilt (~> 1.1, != 1.3.0)
129
+ sprockets-rails (2.1.3)
130
+ actionpack (>= 3.0)
131
+ activesupport (>= 3.0)
132
+ sprockets (~> 2.8)
133
+ sqlite3 (1.3.9)
134
+ thor (0.19.1)
135
+ thread_safe (0.3.4)
136
+ tilt (1.4.1)
137
+ treetop (1.4.15)
138
+ polyglot
139
+ polyglot (>= 0.3.1)
140
+ tzinfo (1.2.2)
141
+ thread_safe (~> 0.1)
142
+ warden (1.2.3)
143
+ rack (>= 1.0)
144
+ webrat (0.7.3)
145
+ nokogiri (>= 1.2.0)
146
+ rack (>= 1.0)
147
+ rack-test (>= 0.5.3)
148
+
149
+ PLATFORMS
150
+ ruby
151
+
152
+ DEPENDENCIES
153
+ activerecord-jdbc-adapter
154
+ activerecord-jdbcsqlite3-adapter
155
+ devise!
156
+ jruby-openssl
157
+ mocha (~> 1.1)
158
+ mongoid (~> 4.0.0)
159
+ omniauth (~> 1.2.0)
160
+ omniauth-facebook
161
+ omniauth-oauth2 (~> 1.1.0)
162
+ omniauth-openid (~> 1.0.1)
163
+ rails (~> 4.1.0)
164
+ rdoc
165
+ sqlite3
166
+ webrat (= 0.7.3)
@@ -0,0 +1,20 @@
1
+ Copyright 2009-2014 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,506 @@
1
+ ![Devise Logo](https://raw.github.com/plataformatec/devise/master/devise.png)
2
+
3
+ By [Plataformatec](http://plataformatec.com.br/).
4
+
5
+ [![Build Status](https://api.travis-ci.org/plataformatec/devise.png?branch=master)](http://travis-ci.org/plataformatec/devise)
6
+ [![Code Climate](https://codeclimate.com/github/plataformatec/devise.png)](https://codeclimate.com/github/plataformatec/devise)
7
+
8
+ This README is [also available in a friendly navigable format](http://devise.plataformatec.com.br/).
9
+
10
+ Devise is a flexible authentication solution for Rails based on Warden. It:
11
+
12
+ * Is Rack based;
13
+ * Is a complete MVC solution based on Rails engines;
14
+ * Allows you to have multiple models signed in at the same time;
15
+ * Is based on a modularity concept: use just what you really need.
16
+
17
+ It's composed of 10 modules:
18
+
19
+ * [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.
20
+ * [Omniauthable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Omniauthable): adds Omniauth (https://github.com/intridea/omniauth) support.
21
+ * [Confirmable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Confirmable): sends emails with confirmation instructions and verifies whether an account is already confirmed during sign in.
22
+ * [Recoverable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Recoverable): resets the user password and sends reset instructions.
23
+ * [Registerable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Registerable): handles signing up users through a registration process, also allowing them to edit and destroy their account.
24
+ * [Rememberable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Rememberable): manages generating and clearing a token for remembering the user from a saved cookie.
25
+ * [Trackable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Trackable): tracks sign in count, timestamps and IP address.
26
+ * [Timeoutable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Timeoutable): expires sessions that have no activity in a specified period of time.
27
+ * [Validatable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Validatable): provides validations of email and password. It's optional and can be customized, so you're able to define your own validations.
28
+ * [Lockable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Lockable): locks an account after a specified number of failed sign-in attempts. Can unlock via email or after a specified time period.
29
+
30
+ Devise is guaranteed to be thread-safe on YARV. Thread-safety support on JRuby is in progress.
31
+
32
+ ## Information
33
+
34
+ ### The Devise wiki
35
+
36
+ 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:
37
+
38
+ https://github.com/plataformatec/devise/wiki
39
+
40
+ ### Bug reports
41
+
42
+ 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:
43
+
44
+ https://github.com/plataformatec/devise/wiki/Bug-reports
45
+
46
+ If you found a security bug, do *NOT* use the GitHub issue tracker. Send an email to opensource@plataformatec.com.br.
47
+
48
+ ### Mailing list
49
+
50
+ If you have any questions, comments, or concerns, please use the Google Group instead of the GitHub issue tracker:
51
+
52
+ https://groups.google.com/group/plataformatec-devise
53
+
54
+ ### RDocs
55
+
56
+ You can view the Devise documentation in RDoc format here:
57
+
58
+ http://rubydoc.info/github/plataformatec/devise/master/frames
59
+
60
+ If you need to use Devise with previous versions of Rails, you can always run "gem server" from the command line after you install the gem to access the old documentation.
61
+
62
+ ### Example applications
63
+
64
+ 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:
65
+
66
+ https://github.com/plataformatec/devise/wiki/Example-Applications
67
+
68
+ ### Extensions
69
+
70
+ 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:
71
+
72
+ https://github.com/plataformatec/devise/wiki/Extensions
73
+
74
+ ### Contributing
75
+
76
+ We hope that you will consider contributing to Devise. Please read this short overview for some information about how to get started:
77
+
78
+ https://github.com/plataformatec/devise/wiki/Contributing
79
+
80
+ 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.
81
+
82
+ ## Starting with Rails?
83
+
84
+ If you are building your first Rails application, we recommend you to *not* use Devise. Devise requires a good understanding of the Rails Framework. In such cases, we advise you to start a simple authentication system from scratch, today we have two resources:
85
+
86
+ * Michael Hartl's online book: http://www.railstutorial.org/book/demo_app#sec-modeling_demo_users
87
+ * Ryan Bates' Railscast: http://railscasts.com/episodes/250-authentication-from-scratch
88
+
89
+ Once you have solidified your understanding of Rails and authentication mechanisms, we assure you Devise will be very pleasant to work with. :)
90
+
91
+ ## Getting started
92
+
93
+ Devise 3.0 works with Rails 3.2 onwards. You can add it to your Gemfile with:
94
+
95
+ ```ruby
96
+ gem 'devise'
97
+ ```
98
+
99
+ Run the bundle command to install it.
100
+
101
+ After you install Devise and add it to your Gemfile, you need to run the generator:
102
+
103
+ ```console
104
+ rails generate devise:install
105
+ ```
106
+
107
+ 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:
108
+
109
+ ```console
110
+ rails generate devise MODEL
111
+ ```
112
+
113
+ Replace MODEL with the class name used for the application’s 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. The generator also configures your `config/routes.rb` file to point to the Devise controller.
114
+
115
+ Next, check the MODEL for any additional configuration options you might want to add, such as confirmable or lockable. If you add an option, be sure to inspect the migration file (created by the generator if your ORM supports them) and uncomment the appropriate section. For example, if you add the confirmable option in the model, you'll need to uncomment the Confirmable section in the migration. Then run `rake db:migrate`
116
+
117
+ Next, you need to set up the default URL options for the Devise mailer in each environment. Here is a possible configuration for `config/environments/development.rb`:
118
+
119
+ ```ruby
120
+ config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
121
+ ```
122
+
123
+ You should restart your application after changing Devise's configuration options. Otherwise you'll run into strange errors like users being unable to login and route helpers being undefined.
124
+
125
+ ### Controller filters and helpers
126
+
127
+ Devise will create some helpers to use inside your controllers and views. To set up a controller with user authentication, just add this before_action (assuming your devise model is 'User'):
128
+
129
+ ```ruby
130
+ before_action :authenticate_user!
131
+ ```
132
+
133
+ If your devise model is something other than User, replace "_user" with "_yourmodel". The same logic applies to the instructions below.
134
+
135
+ To verify if a user is signed in, use the following helper:
136
+
137
+ ```ruby
138
+ user_signed_in?
139
+ ```
140
+
141
+ For the current signed-in user, this helper is available:
142
+
143
+ ```ruby
144
+ current_user
145
+ ```
146
+
147
+ You can access the session for this scope:
148
+
149
+ ```ruby
150
+ user_session
151
+ ```
152
+
153
+ After signing in a user, confirming the account or updating the password, Devise will look for a scoped root path to redirect. For instance, for a `:user` resource, the `user_root_path` will be used if it exists, otherwise the default `root_path` will be used. This means that you need to set the root inside your routes:
154
+
155
+ ```ruby
156
+ root to: "home#index"
157
+ ```
158
+
159
+ You can also override `after_sign_in_path_for` and `after_sign_out_path_for` to customize your redirect hooks.
160
+
161
+ Notice that if your Devise model is called `Member` instead of `User`, for example, then the helpers available are:
162
+
163
+ ```ruby
164
+ before_action :authenticate_member!
165
+
166
+ member_signed_in?
167
+
168
+ current_member
169
+
170
+ member_session
171
+ ```
172
+
173
+ ### Configuring Models
174
+
175
+ 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:
176
+
177
+ ```ruby
178
+ devise :database_authenticatable, :registerable, :confirmable, :recoverable, stretches: 20
179
+ ```
180
+
181
+ Besides `:stretches`, you can define `:pepper`, `:encryptor`, `:confirm_within`, `:remember_for`, `:timeout_in`, `:unlock_in` among other options. For more details, see the initializer file that was created when you invoked the "devise:install" generator described above.
182
+
183
+ ### Strong Parameters
184
+
185
+ When you customize your own views, you may end up adding new attributes to forms. Rails 4 moved the parameter sanitization from the model to the controller, causing Devise to handle this concern at the controller as well.
186
+
187
+ There are just three actions in Devise that allows any set of parameters to be passed down to the model, therefore requiring sanitization. Their names and the permitted parameters by default are:
188
+
189
+ * `sign_in` (`Devise::SessionsController#new`) - Permits only the authentication keys (like `email`)
190
+ * `sign_up` (`Devise::RegistrationsController#create`) - Permits authentication keys plus `password` and `password_confirmation`
191
+ * `account_update` (`Devise::RegistrationsController#update`) - Permits authentication keys plus `password`, `password_confirmation` and `current_password`
192
+
193
+ In case you want to permit additional parameters (the lazy way™) you can do with a simple before filter in your `ApplicationController`:
194
+
195
+ ```ruby
196
+ class ApplicationController < ActionController::Base
197
+ before_action :configure_permitted_parameters, if: :devise_controller?
198
+
199
+ protected
200
+
201
+ def configure_permitted_parameters
202
+ devise_parameter_sanitizer.for(:sign_up) << :username
203
+ end
204
+ end
205
+ ```
206
+
207
+ The above works for any additional fields where the parameters are simple scalar types. If you have nested attributes (say you're using `accepts_nested_attributes_for`), then you will need to tell devise about those nestings and types. Devise allows you to completely change Devise defaults or invoke custom behaviour by passing a block:
208
+
209
+ To permit simple scalar values for username and email, use this
210
+
211
+ ```ruby
212
+ def configure_permitted_parameters
213
+ devise_parameter_sanitizer.for(:sign_in) { |u| u.permit(:username, :email) }
214
+ end
215
+ ```
216
+
217
+ If you have some checkboxes that express the roles a user may take on registration, the browser will send those selected checkboxes as an array. An array is not one of Strong Parameters permitted scalars, so we need to configure Devise thusly:
218
+
219
+ ```ruby
220
+ def configure_permitted_parameters
221
+ devise_parameter_sanitizer.for(:sign_up) { |u| u.permit({ roles: [] }, :email, :password, :password_confirmation) }
222
+ end
223
+ ```
224
+ For the list of permitted scalars, and how to declare permitted keys in nested hashes and arrays, see
225
+
226
+ https://github.com/rails/strong_parameters#nested-parameters
227
+
228
+ If you have multiple Devise models, you may want to set up different parameter sanitizer per model. In this case, we recommend inheriting from `Devise::ParameterSanitizer` and add your own logic:
229
+
230
+ ```ruby
231
+ class User::ParameterSanitizer < Devise::ParameterSanitizer
232
+ def sign_in
233
+ default_params.permit(:username, :email)
234
+ end
235
+ end
236
+ ```
237
+
238
+ And then configure your controllers to use it:
239
+
240
+ ```ruby
241
+ class ApplicationController < ActionController::Base
242
+ protected
243
+
244
+ def devise_parameter_sanitizer
245
+ if resource_class == User
246
+ User::ParameterSanitizer.new(User, :user, params)
247
+ else
248
+ super # Use the default one
249
+ end
250
+ end
251
+ end
252
+ ```
253
+
254
+ The example above overrides the permitted parameters for the user to be both `:username` and `:email`. The non-lazy way to configure parameters would be by defining the before filter above in a custom controller. We detail how to configure and customize controllers in some sections below.
255
+
256
+ ### Configuring views
257
+
258
+ 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.
259
+
260
+ 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:
261
+
262
+ ```console
263
+ rails generate devise:views
264
+ ```
265
+
266
+ If you have more than one Devise model in your application (such as `User` and `Admin`), you will notice that Devise uses the same views for all models. Fortunately, Devise offers an easy way to customize views. All you need to do is set `config.scoped_views = true` inside the `config/initializers/devise.rb` file.
267
+
268
+ 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:
269
+
270
+ ```console
271
+ rails generate devise:views users
272
+ ```
273
+
274
+ If you want to generate only a few set of views, like the ones for the `registrable` and `confirmable` module,
275
+ you can pass a list of modules to the generator with the `-v` flag.
276
+
277
+ ```console
278
+ rails generate devise:views -v registrations confirmations
279
+ ```
280
+
281
+ ### Configuring controllers
282
+
283
+ If the customization at the views level is not enough, you can customize each controller by following these steps:
284
+
285
+ 1. Create your custom controller, for example a `Admins::SessionsController`:
286
+
287
+ ```ruby
288
+ class Admins::SessionsController < Devise::SessionsController
289
+ end
290
+ ```
291
+
292
+ Note that in the above example, the controller needs to be created in the `app/controllers/admins/` directory.
293
+
294
+ 2. Tell the router to use this controller:
295
+
296
+ ```ruby
297
+ devise_for :admins, controllers: { sessions: "admins/sessions" }
298
+ ```
299
+
300
+ 3. Copy the views from `devise/sessions` to `admins/sessions`. Since the controller was changed, it won't use the default views located in `devise/sessions`.
301
+
302
+ 4. Finally, change or extend the desired controller actions.
303
+
304
+ You can completely override a controller action:
305
+
306
+ ```ruby
307
+ class Admins::SessionsController < Devise::SessionsController
308
+ def create
309
+ # custom sign-in code
310
+ end
311
+ end
312
+ ```
313
+
314
+ Or you can simply add new behaviour to it:
315
+
316
+ ```ruby
317
+ class Admins::SessionsController < Devise::SessionsController
318
+ def create
319
+ super do |resource|
320
+ BackgroundWorker.trigger(resource)
321
+ end
322
+ end
323
+ end
324
+ ```
325
+
326
+ This is useful for triggering background jobs or logging events during certain actions.
327
+
328
+ 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 only specific keys. In some circumstances, Devise adds a `:timedout` key to the flash hash, which is not meant for display. Remove this key from the hash if you intend to print the entire hash.
329
+
330
+ ### Configuring routes
331
+
332
+ 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:
333
+
334
+ ```ruby
335
+ devise_for :users, path: "auth", path_names: { sign_in: 'login', sign_out: 'logout', password: 'secret', confirmation: 'verification', unlock: 'unblock', registration: 'register', sign_up: 'cmon_let_me_in' }
336
+ ```
337
+
338
+ Be sure to check `devise_for` documentation for details.
339
+
340
+ 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:
341
+
342
+ ```ruby
343
+ devise_scope :user do
344
+ get "sign_in", to: "devise/sessions#new"
345
+ end
346
+ ```
347
+
348
+ 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.
349
+
350
+ ### I18n
351
+
352
+ Devise uses flash messages with I18n with the flash keys :notice and :alert. To customize your app, you can set up your locale file:
353
+
354
+ ```yaml
355
+ en:
356
+ devise:
357
+ sessions:
358
+ signed_in: 'Signed in successfully.'
359
+ ```
360
+
361
+ You can also create distinct messages based on the resource you've configured using the singular name given in routes:
362
+
363
+ ```yaml
364
+ en:
365
+ devise:
366
+ sessions:
367
+ user:
368
+ signed_in: 'Welcome user, you are signed in.'
369
+ admin:
370
+ signed_in: 'Hello admin!'
371
+ ```
372
+
373
+ The Devise mailer uses a similar pattern to create subject messages:
374
+
375
+ ```yaml
376
+ en:
377
+ devise:
378
+ mailer:
379
+ confirmation_instructions:
380
+ subject: 'Hello everybody!'
381
+ user_subject: 'Hello User! Please confirm your email'
382
+ reset_password_instructions:
383
+ subject: 'Reset instructions'
384
+ ```
385
+
386
+ 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:
387
+
388
+ https://github.com/plataformatec/devise/wiki/I18n
389
+
390
+ Caution: Devise Controllers inherit from ApplicationController. If your app uses multiple locales, you should be sure to set I18n.locale in ApplicationController
391
+
392
+ ### Test helpers
393
+
394
+ Devise includes some test helpers for functional specs. In order to use them, you need to include Devise in your functional tests by adding the following to the bottom of your `test/test_helper.rb` file:
395
+
396
+ ```ruby
397
+ class ActionController::TestCase
398
+ include Devise::TestHelpers
399
+ end
400
+ ```
401
+
402
+ If you're using RSpec, you can put the following inside a file named `spec/support/devise.rb` or in your `spec/spec_helper.rb`:
403
+
404
+ ```ruby
405
+ RSpec.configure do |config|
406
+ config.include Devise::TestHelpers, type: :controller
407
+ end
408
+ ```
409
+
410
+ Now you are ready to use the `sign_in` and `sign_out` methods. Such methods have the same signature as in controllers:
411
+
412
+ ```ruby
413
+ sign_in :user, @user # sign_in(scope, resource)
414
+ sign_in @user # sign_in(resource)
415
+
416
+ sign_out :user # sign_out(scope)
417
+ sign_out @user # sign_out(resource)
418
+ ```
419
+
420
+ There are two things that are important to keep in mind:
421
+
422
+ 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;
423
+
424
+ 2. If you are testing Devise internal controllers or a controller that inherits from Devise's, you need to tell Devise which mapping should be used before a request. This is necessary because Devise gets this information from the router, but since functional tests do not pass through the router, it needs to be told explicitly. For example, if you are testing the user scope, simply do:
425
+
426
+ ```ruby
427
+ @request.env["devise.mapping"] = Devise.mappings[:user]
428
+ get :new
429
+ ```
430
+
431
+ ### Omniauth
432
+
433
+ 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`:
434
+
435
+ ```ruby
436
+ config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo'
437
+ ```
438
+
439
+ You can read more about Omniauth support in the wiki:
440
+
441
+ * https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview
442
+
443
+ ### Configuring multiple models
444
+
445
+ Devise allows you to set up as many Devise models as you want. If you want to have an Admin model with just authentication and timeout features, in addition to the User model above, just run:
446
+
447
+ ```ruby
448
+ # Create a migration with the required fields
449
+ create_table :admins do |t|
450
+ t.string :email
451
+ t.string :encrypted_password
452
+ t.timestamps
453
+ end
454
+
455
+ # Inside your Admin model
456
+ devise :database_authenticatable, :timeoutable
457
+
458
+ # Inside your routes
459
+ devise_for :admins
460
+
461
+ # Inside your protected controller
462
+ before_filter :authenticate_admin!
463
+
464
+ # Inside your controllers and views
465
+ admin_signed_in?
466
+ current_admin
467
+ admin_session
468
+ ```
469
+
470
+ Alternatively, you can simply run the Devise generator.
471
+
472
+ Keep in mind that those models will have completely different routes. They **do not** and **cannot** share the same controller for sign in, sign out and so on. In case you want to have different roles sharing the same actions, we recommend you to use a role-based approach, by either providing a role column or using a dedicated gem for authorization.
473
+
474
+ ### Other ORMs
475
+
476
+ Devise supports ActiveRecord (default) and Mongoid. To choose other ORM, you just need to require it in the initializer file.
477
+
478
+ ## Additional information
479
+
480
+ ### Heroku
481
+
482
+ Using Devise on Heroku with Ruby on Rails 3.1 requires setting:
483
+
484
+ ```ruby
485
+ config.assets.initialize_on_precompile = false
486
+ ```
487
+
488
+ Read more about the potential issues at http://guides.rubyonrails.org/asset_pipeline.html
489
+
490
+ ### Warden
491
+
492
+ 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:
493
+
494
+ https://github.com/hassox/warden
495
+
496
+ ### Contributors
497
+
498
+ We have a long list of valued contributors. Check them all at:
499
+
500
+ https://github.com/plataformatec/devise/graphs/contributors
501
+
502
+ ## License
503
+
504
+ MIT License. Copyright 2009-2014 Plataformatec. http://plataformatec.com.br
505
+
506
+ You are not granted rights or licenses to the trademarks of the Plataformatec, including without limitation the Devise name or logo.