cloudfoundry-devise 1.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (210) hide show
  1. data/.gitignore +12 -0
  2. data/.travis.yml +13 -0
  3. data/CHANGELOG.rdoc +755 -0
  4. data/Gemfile +35 -0
  5. data/MIT-LICENSE +20 -0
  6. data/README.rdoc +366 -0
  7. data/Rakefile +34 -0
  8. data/app/controllers/devise/confirmations_controller.rb +46 -0
  9. data/app/controllers/devise/omniauth_callbacks_controller.rb +26 -0
  10. data/app/controllers/devise/passwords_controller.rb +50 -0
  11. data/app/controllers/devise/registrations_controller.rb +114 -0
  12. data/app/controllers/devise/sessions_controller.rb +49 -0
  13. data/app/controllers/devise/unlocks_controller.rb +34 -0
  14. data/app/helpers/devise_helper.rb +25 -0
  15. data/app/mailers/devise/mailer.rb +15 -0
  16. data/app/views/devise/confirmations/new.html.erb +12 -0
  17. data/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
  18. data/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
  19. data/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
  20. data/app/views/devise/passwords/edit.html.erb +16 -0
  21. data/app/views/devise/passwords/new.html.erb +12 -0
  22. data/app/views/devise/registrations/edit.html.erb +25 -0
  23. data/app/views/devise/registrations/new.html.erb +18 -0
  24. data/app/views/devise/sessions/new.html.erb +17 -0
  25. data/app/views/devise/shared/_links.erb +25 -0
  26. data/app/views/devise/unlocks/new.html.erb +12 -0
  27. data/cloudfoundry-devise.gemspec +25 -0
  28. data/config/locales/en.yml +59 -0
  29. data/lib/devise.rb +453 -0
  30. data/lib/devise/controllers/helpers.rb +260 -0
  31. data/lib/devise/controllers/internal_helpers.rb +161 -0
  32. data/lib/devise/controllers/rememberable.rb +52 -0
  33. data/lib/devise/controllers/scoped_views.rb +33 -0
  34. data/lib/devise/controllers/shared_helpers.rb +26 -0
  35. data/lib/devise/controllers/url_helpers.rb +53 -0
  36. data/lib/devise/delegator.rb +16 -0
  37. data/lib/devise/encryptors/authlogic_sha512.rb +19 -0
  38. data/lib/devise/encryptors/base.rb +20 -0
  39. data/lib/devise/encryptors/clearance_sha1.rb +17 -0
  40. data/lib/devise/encryptors/restful_authentication_sha1.rb +22 -0
  41. data/lib/devise/encryptors/sha1.rb +25 -0
  42. data/lib/devise/encryptors/sha512.rb +25 -0
  43. data/lib/devise/failure_app.rb +149 -0
  44. data/lib/devise/hooks/activatable.rb +11 -0
  45. data/lib/devise/hooks/forgetable.rb +9 -0
  46. data/lib/devise/hooks/rememberable.rb +6 -0
  47. data/lib/devise/hooks/timeoutable.rb +24 -0
  48. data/lib/devise/hooks/trackable.rb +9 -0
  49. data/lib/devise/mailers/helpers.rb +86 -0
  50. data/lib/devise/mapping.rb +175 -0
  51. data/lib/devise/models.rb +91 -0
  52. data/lib/devise/models/authenticatable.rb +181 -0
  53. data/lib/devise/models/confirmable.rb +220 -0
  54. data/lib/devise/models/database_authenticatable.rb +122 -0
  55. data/lib/devise/models/encryptable.rb +72 -0
  56. data/lib/devise/models/lockable.rb +169 -0
  57. data/lib/devise/models/omniauthable.rb +23 -0
  58. data/lib/devise/models/recoverable.rb +136 -0
  59. data/lib/devise/models/registerable.rb +21 -0
  60. data/lib/devise/models/rememberable.rb +114 -0
  61. data/lib/devise/models/serializable.rb +43 -0
  62. data/lib/devise/models/timeoutable.rb +45 -0
  63. data/lib/devise/models/token_authenticatable.rb +72 -0
  64. data/lib/devise/models/trackable.rb +30 -0
  65. data/lib/devise/models/validatable.rb +62 -0
  66. data/lib/devise/modules.rb +30 -0
  67. data/lib/devise/omniauth.rb +28 -0
  68. data/lib/devise/omniauth/config.rb +45 -0
  69. data/lib/devise/omniauth/url_helpers.rb +33 -0
  70. data/lib/devise/orm/active_record.rb +44 -0
  71. data/lib/devise/orm/mongoid.rb +31 -0
  72. data/lib/devise/param_filter.rb +41 -0
  73. data/lib/devise/path_checker.rb +18 -0
  74. data/lib/devise/rails.rb +73 -0
  75. data/lib/devise/rails/routes.rb +385 -0
  76. data/lib/devise/rails/warden_compat.rb +120 -0
  77. data/lib/devise/schema.rb +109 -0
  78. data/lib/devise/strategies/authenticatable.rb +155 -0
  79. data/lib/devise/strategies/base.rb +15 -0
  80. data/lib/devise/strategies/database_authenticatable.rb +21 -0
  81. data/lib/devise/strategies/rememberable.rb +53 -0
  82. data/lib/devise/strategies/token_authenticatable.rb +57 -0
  83. data/lib/devise/test_helpers.rb +90 -0
  84. data/lib/devise/version.rb +3 -0
  85. data/lib/generators/active_record/devise_generator.rb +71 -0
  86. data/lib/generators/active_record/templates/migration.rb +29 -0
  87. data/lib/generators/active_record/templates/migration_existing.rb +26 -0
  88. data/lib/generators/devise/devise_generator.rb +22 -0
  89. data/lib/generators/devise/install_generator.rb +24 -0
  90. data/lib/generators/devise/orm_helpers.rb +31 -0
  91. data/lib/generators/devise/views_generator.rb +98 -0
  92. data/lib/generators/mongoid/devise_generator.rb +60 -0
  93. data/lib/generators/templates/README +32 -0
  94. data/lib/generators/templates/devise.rb +215 -0
  95. data/lib/generators/templates/markerb/confirmation_instructions.markerb +5 -0
  96. data/lib/generators/templates/markerb/reset_password_instructions.markerb +8 -0
  97. data/lib/generators/templates/markerb/unlock_instructions.markerb +7 -0
  98. data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +15 -0
  99. data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +19 -0
  100. data/lib/generators/templates/simple_form_for/passwords/new.html.erb +15 -0
  101. data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +22 -0
  102. data/lib/generators/templates/simple_form_for/registrations/new.html.erb +17 -0
  103. data/lib/generators/templates/simple_form_for/sessions/new.html.erb +15 -0
  104. data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +15 -0
  105. data/test/controllers/helpers_test.rb +254 -0
  106. data/test/controllers/internal_helpers_test.rb +96 -0
  107. data/test/controllers/sessions_controller_test.rb +16 -0
  108. data/test/controllers/url_helpers_test.rb +59 -0
  109. data/test/delegator_test.rb +19 -0
  110. data/test/devise_test.rb +72 -0
  111. data/test/encryptors_test.rb +30 -0
  112. data/test/failure_app_test.rb +207 -0
  113. data/test/generators/active_record_generator_test.rb +47 -0
  114. data/test/generators/devise_generator_test.rb +39 -0
  115. data/test/generators/install_generator_test.rb +13 -0
  116. data/test/generators/mongoid_generator_test.rb +23 -0
  117. data/test/generators/views_generator_test.rb +52 -0
  118. data/test/helpers/devise_helper_test.rb +51 -0
  119. data/test/indifferent_hash.rb +33 -0
  120. data/test/integration/authenticatable_test.rb +590 -0
  121. data/test/integration/confirmable_test.rb +262 -0
  122. data/test/integration/database_authenticatable_test.rb +82 -0
  123. data/test/integration/http_authenticatable_test.rb +82 -0
  124. data/test/integration/lockable_test.rb +212 -0
  125. data/test/integration/omniauthable_test.rb +133 -0
  126. data/test/integration/recoverable_test.rb +287 -0
  127. data/test/integration/registerable_test.rb +335 -0
  128. data/test/integration/rememberable_test.rb +158 -0
  129. data/test/integration/timeoutable_test.rb +98 -0
  130. data/test/integration/token_authenticatable_test.rb +148 -0
  131. data/test/integration/trackable_test.rb +92 -0
  132. data/test/mailers/confirmation_instructions_test.rb +95 -0
  133. data/test/mailers/reset_password_instructions_test.rb +83 -0
  134. data/test/mailers/unlock_instructions_test.rb +77 -0
  135. data/test/mapping_test.rb +128 -0
  136. data/test/models/confirmable_test.rb +334 -0
  137. data/test/models/database_authenticatable_test.rb +167 -0
  138. data/test/models/encryptable_test.rb +67 -0
  139. data/test/models/lockable_test.rb +225 -0
  140. data/test/models/recoverable_test.rb +198 -0
  141. data/test/models/rememberable_test.rb +168 -0
  142. data/test/models/serializable_test.rb +38 -0
  143. data/test/models/timeoutable_test.rb +42 -0
  144. data/test/models/token_authenticatable_test.rb +49 -0
  145. data/test/models/trackable_test.rb +5 -0
  146. data/test/models/validatable_test.rb +113 -0
  147. data/test/models_test.rb +109 -0
  148. data/test/omniauth/config_test.rb +57 -0
  149. data/test/omniauth/url_helpers_test.rb +58 -0
  150. data/test/orm/active_record.rb +9 -0
  151. data/test/orm/mongoid.rb +14 -0
  152. data/test/rails_app/Rakefile +10 -0
  153. data/test/rails_app/app/active_record/admin.rb +6 -0
  154. data/test/rails_app/app/active_record/shim.rb +2 -0
  155. data/test/rails_app/app/active_record/user.rb +6 -0
  156. data/test/rails_app/app/controllers/admins/sessions_controller.rb +6 -0
  157. data/test/rails_app/app/controllers/admins_controller.rb +6 -0
  158. data/test/rails_app/app/controllers/application_controller.rb +8 -0
  159. data/test/rails_app/app/controllers/home_controller.rb +25 -0
  160. data/test/rails_app/app/controllers/publisher/registrations_controller.rb +2 -0
  161. data/test/rails_app/app/controllers/publisher/sessions_controller.rb +2 -0
  162. data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +14 -0
  163. data/test/rails_app/app/controllers/users_controller.rb +23 -0
  164. data/test/rails_app/app/helpers/application_helper.rb +3 -0
  165. data/test/rails_app/app/mailers/users/mailer.rb +3 -0
  166. data/test/rails_app/app/mongoid/admin.rb +24 -0
  167. data/test/rails_app/app/mongoid/shim.rb +24 -0
  168. data/test/rails_app/app/mongoid/user.rb +45 -0
  169. data/test/rails_app/app/views/admins/index.html.erb +1 -0
  170. data/test/rails_app/app/views/admins/sessions/new.html.erb +2 -0
  171. data/test/rails_app/app/views/home/admin_dashboard.html.erb +1 -0
  172. data/test/rails_app/app/views/home/index.html.erb +1 -0
  173. data/test/rails_app/app/views/home/join.html.erb +1 -0
  174. data/test/rails_app/app/views/home/private.html.erb +1 -0
  175. data/test/rails_app/app/views/home/user_dashboard.html.erb +1 -0
  176. data/test/rails_app/app/views/layouts/application.html.erb +24 -0
  177. data/test/rails_app/app/views/users/index.html.erb +1 -0
  178. data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +1 -0
  179. data/test/rails_app/app/views/users/sessions/new.html.erb +1 -0
  180. data/test/rails_app/config.ru +4 -0
  181. data/test/rails_app/config/application.rb +41 -0
  182. data/test/rails_app/config/boot.rb +8 -0
  183. data/test/rails_app/config/database.yml +18 -0
  184. data/test/rails_app/config/environment.rb +5 -0
  185. data/test/rails_app/config/environments/development.rb +18 -0
  186. data/test/rails_app/config/environments/production.rb +33 -0
  187. data/test/rails_app/config/environments/test.rb +33 -0
  188. data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
  189. data/test/rails_app/config/initializers/devise.rb +197 -0
  190. data/test/rails_app/config/initializers/inflections.rb +2 -0
  191. data/test/rails_app/config/initializers/secret_token.rb +2 -0
  192. data/test/rails_app/config/routes.rb +87 -0
  193. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +71 -0
  194. data/test/rails_app/db/schema.rb +52 -0
  195. data/test/rails_app/lib/shared_admin.rb +10 -0
  196. data/test/rails_app/lib/shared_user.rb +26 -0
  197. data/test/rails_app/public/404.html +26 -0
  198. data/test/rails_app/public/422.html +26 -0
  199. data/test/rails_app/public/500.html +26 -0
  200. data/test/rails_app/public/favicon.ico +0 -0
  201. data/test/rails_app/script/rails +10 -0
  202. data/test/routes_test.rb +240 -0
  203. data/test/support/assertions.rb +27 -0
  204. data/test/support/helpers.rb +109 -0
  205. data/test/support/integration.rb +88 -0
  206. data/test/support/locale/en.yml +4 -0
  207. data/test/support/webrat/integrations/rails.rb +24 -0
  208. data/test/test_helper.rb +27 -0
  209. data/test/test_helpers_test.rb +134 -0
  210. metadata +295 -0
@@ -0,0 +1,18 @@
1
+ <h2>Sign up</h2>
2
+
3
+ <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
4
+ <%= devise_error_messages! %>
5
+
6
+ <div><%= f.label :email %><br />
7
+ <%= f.email_field :email %></div>
8
+
9
+ <div><%= f.label :password %><br />
10
+ <%= f.password_field :password %></div>
11
+
12
+ <div><%= f.label :password_confirmation %><br />
13
+ <%= f.password_field :password_confirmation %></div>
14
+
15
+ <div><%= f.submit "Sign up" %></div>
16
+ <% end %>
17
+
18
+ <%= render :partial => "devise/shared/links" %>
@@ -0,0 +1,17 @@
1
+ <h2>Sign in</h2>
2
+
3
+ <%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
4
+ <div><%= f.label :email %><br />
5
+ <%= f.email_field :email %></div>
6
+
7
+ <div><%= f.label :password %><br />
8
+ <%= f.password_field :password %></div>
9
+
10
+ <% if devise_mapping.rememberable? -%>
11
+ <div><%= f.check_box :remember_me %> <%= f.label :remember_me %></div>
12
+ <% end -%>
13
+
14
+ <div><%= f.submit "Sign in" %></div>
15
+ <% end %>
16
+
17
+ <%= render :partial => "devise/shared/links" %>
@@ -0,0 +1,25 @@
1
+ <%- if controller_name != 'sessions' %>
2
+ <%= link_to "Sign in", new_session_path(resource_name) %><br />
3
+ <% end -%>
4
+
5
+ <%- if devise_mapping.registerable? && controller_name != 'registrations' %>
6
+ <%= link_to "Sign up", new_registration_path(resource_name) %><br />
7
+ <% end -%>
8
+
9
+ <%- if devise_mapping.recoverable? && controller_name != 'passwords' %>
10
+ <%= link_to "Forgot your password?", new_password_path(resource_name) %><br />
11
+ <% end -%>
12
+
13
+ <%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
14
+ <%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %><br />
15
+ <% end -%>
16
+
17
+ <%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %>
18
+ <%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %><br />
19
+ <% end -%>
20
+
21
+ <%- if devise_mapping.omniauthable? %>
22
+ <%- resource_class.omniauth_providers.each do |provider| %>
23
+ <%= link_to "Sign in with #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider) %><br />
24
+ <% end -%>
25
+ <% end -%>
@@ -0,0 +1,12 @@
1
+ <h2>Resend unlock instructions</h2>
2
+
3
+ <%= form_for(resource, :as => resource_name, :url => unlock_path(resource_name), :html => { :method => :post }) do |f| %>
4
+ <%= devise_error_messages! %>
5
+
6
+ <div><%= f.label :email %><br />
7
+ <%= f.email_field :email %></div>
8
+
9
+ <div><%= f.submit "Resend unlock instructions" %></div>
10
+ <% end %>
11
+
12
+ <%= render :partial => "devise/shared/links" %>
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "devise/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "cloudfoundry-devise"
7
+ s.version = Devise::VERSION.dup
8
+ s.platform = Gem::Platform::RUBY
9
+ s.summary = "Flexible authentication solution for Rails with Warden"
10
+ s.email = "contact@plataformatec.com.br"
11
+ s.homepage = "http://github.com/plataformatec/devise"
12
+ s.description = "Flexible authentication solution for Rails with Warden"
13
+ s.authors = ['Jose Valim', 'Carlos Antonio']
14
+
15
+ s.rubyforge_project = "devise"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency("warden", "~> 1.1")
23
+ s.add_dependency("orm_adapter", "~> 0.0.3")
24
+ s.add_dependency("bcrypt-ruby", "~> 3.0")
25
+ end
@@ -0,0 +1,59 @@
1
+ # Additional translations at https://github.com/plataformatec/devise/wiki/I18n
2
+
3
+ en:
4
+ errors:
5
+ messages:
6
+ expired: "has expired, please request a new one"
7
+ not_found: "not found"
8
+ already_confirmed: "was already confirmed, please try signing in"
9
+ not_locked: "was not locked"
10
+ not_saved:
11
+ one: "1 error prohibited this %{resource} from being saved:"
12
+ other: "%{count} errors prohibited this %{resource} from being saved:"
13
+
14
+ devise:
15
+ failure:
16
+ already_authenticated: 'You are already signed in.'
17
+ unauthenticated: 'You need to sign in or sign up before continuing.'
18
+ unconfirmed: 'You have to confirm your account before continuing.'
19
+ locked: 'Your account is locked.'
20
+ invalid: 'Invalid email or password.'
21
+ invalid_token: 'Invalid authentication token.'
22
+ timeout: 'Your session expired, please sign in again to continue.'
23
+ inactive: 'Your account was not activated yet.'
24
+ sessions:
25
+ signed_in: 'Signed in successfully.'
26
+ signed_out: 'Signed out successfully.'
27
+ passwords:
28
+ send_instructions: 'You will receive an email with instructions about how to reset your password in a few minutes.'
29
+ updated: 'Your password was changed successfully. You are now signed in.'
30
+ updated_not_active: 'Your password was changed successfully.'
31
+ send_paranoid_instructions: "If your e-mail exists on our database, you will receive a password recovery link on your e-mail"
32
+ confirmations:
33
+ send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.'
34
+ send_paranoid_instructions: 'If your e-mail exists on our database, you will receive an email with instructions about how to confirm your account in a few minutes.'
35
+ confirmed: 'Your account was successfully confirmed. You are now signed in.'
36
+ registrations:
37
+ signed_up: 'Welcome! You have signed up successfully.'
38
+ inactive_signed_up: 'You have signed up successfully. However, we could not sign you in because your account is %{reason}.'
39
+ updated: 'You updated your account successfully.'
40
+ update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and click on the confirm link to finalize confirming your new email address."
41
+ destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.'
42
+ reasons:
43
+ inactive: 'inactive'
44
+ unconfirmed: 'unconfirmed'
45
+ locked: 'locked'
46
+ unlocks:
47
+ send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.'
48
+ unlocked: 'Your account was successfully unlocked. You are now signed in.'
49
+ send_paranoid_instructions: 'If your account exists, you will receive an email with instructions about how to unlock it in a few minutes.'
50
+ omniauth_callbacks:
51
+ success: 'Successfully authorized from %{kind} account.'
52
+ failure: 'Could not authorize you from %{kind} because "%{reason}".'
53
+ mailer:
54
+ confirmation_instructions:
55
+ subject: 'Confirmation instructions'
56
+ reset_password_instructions:
57
+ subject: 'Reset password instructions'
58
+ unlock_instructions:
59
+ subject: 'Unlock Instructions'
@@ -0,0 +1,453 @@
1
+ require 'rails'
2
+ require 'active_support/core_ext/numeric/time'
3
+ require 'active_support/dependencies'
4
+ require 'orm_adapter'
5
+ require 'set'
6
+ require 'securerandom'
7
+
8
+ module Devise
9
+ autoload :Delegator, 'devise/delegator'
10
+ autoload :FailureApp, 'devise/failure_app'
11
+ autoload :OmniAuth, 'devise/omniauth'
12
+ autoload :ParamFilter, 'devise/param_filter'
13
+ autoload :PathChecker, 'devise/path_checker'
14
+ autoload :Schema, 'devise/schema'
15
+ autoload :TestHelpers, 'devise/test_helpers'
16
+
17
+ module Controllers
18
+ autoload :Helpers, 'devise/controllers/helpers'
19
+ autoload :InternalHelpers, 'devise/controllers/internal_helpers'
20
+ autoload :Rememberable, 'devise/controllers/rememberable'
21
+ autoload :ScopedViews, 'devise/controllers/scoped_views'
22
+ autoload :SharedHelpers, 'devise/controllers/shared_helpers'
23
+ autoload :UrlHelpers, 'devise/controllers/url_helpers'
24
+ end
25
+
26
+ module Encryptors
27
+ autoload :Base, 'devise/encryptors/base'
28
+ autoload :AuthlogicSha512, 'devise/encryptors/authlogic_sha512'
29
+ autoload :ClearanceSha1, 'devise/encryptors/clearance_sha1'
30
+ autoload :RestfulAuthenticationSha1, 'devise/encryptors/restful_authentication_sha1'
31
+ autoload :Sha512, 'devise/encryptors/sha512'
32
+ autoload :Sha1, 'devise/encryptors/sha1'
33
+ end
34
+
35
+ module Mailers
36
+ autoload :Helpers, 'devise/mailers/helpers'
37
+ end
38
+
39
+ module Strategies
40
+ autoload :Base, 'devise/strategies/base'
41
+ autoload :Authenticatable, 'devise/strategies/authenticatable'
42
+ end
43
+
44
+ # Constants which holds devise configuration for extensions. Those should
45
+ # not be modified by the "end user" (this is why they are constants).
46
+ ALL = []
47
+ CONTROLLERS = ActiveSupport::OrderedHash.new
48
+ ROUTES = ActiveSupport::OrderedHash.new
49
+ STRATEGIES = ActiveSupport::OrderedHash.new
50
+ URL_HELPERS = ActiveSupport::OrderedHash.new
51
+
52
+ # Strategies that do not require user input.
53
+ NO_INPUT = []
54
+
55
+ # True values used to check params
56
+ TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE']
57
+
58
+ # Declare encryptors length which are used in migrations.
59
+ ENCRYPTORS_LENGTH = {
60
+ :sha1 => 40,
61
+ :sha512 => 128,
62
+ :clearance_sha1 => 40,
63
+ :restful_authentication_sha1 => 40,
64
+ :authlogic_sha512 => 128
65
+ }
66
+
67
+ # Custom domain for cookies. Not set by default
68
+ mattr_accessor :cookie_options
69
+ @@cookie_options = {}
70
+
71
+ # The number of times to encrypt password.
72
+ mattr_accessor :stretches
73
+ @@stretches = 10
74
+
75
+ # Keys used when authenticating a user.
76
+ mattr_accessor :authentication_keys
77
+ @@authentication_keys = [ :email ]
78
+
79
+ # Request keys used when authenticating a user.
80
+ mattr_accessor :request_keys
81
+ @@request_keys = []
82
+
83
+ # Keys that should be case-insensitive.
84
+ # False by default for backwards compatibility.
85
+ mattr_accessor :case_insensitive_keys
86
+ @@case_insensitive_keys = false
87
+
88
+ # Keys that should have whitespace stripped.
89
+ # False by default for backwards compatibility.
90
+ mattr_accessor :strip_whitespace_keys
91
+ @@strip_whitespace_keys = false
92
+
93
+ # If http authentication is enabled by default.
94
+ mattr_accessor :http_authenticatable
95
+ @@http_authenticatable = false
96
+
97
+ # If http headers should be returned for ajax requests. True by default.
98
+ mattr_accessor :http_authenticatable_on_xhr
99
+ @@http_authenticatable_on_xhr = true
100
+
101
+ # If params authenticatable is enabled by default.
102
+ mattr_accessor :params_authenticatable
103
+ @@params_authenticatable = true
104
+
105
+ # The realm used in Http Basic Authentication.
106
+ mattr_accessor :http_authentication_realm
107
+ @@http_authentication_realm = "Application"
108
+
109
+ # Email regex used to validate email formats. It simply asserts that
110
+ # an one (and only one) @ exists in the given string. This is mainly
111
+ # to give user feedback and not to assert the e-mail validity.
112
+ mattr_accessor :email_regexp
113
+ @@email_regexp = /\A[^@]+@([^@\.]+\.)+[^@\.]+\z/
114
+
115
+ # Range validation for password length
116
+ mattr_accessor :password_length
117
+ @@password_length = 6..128
118
+
119
+ # The time the user will be remembered without asking for credentials again.
120
+ mattr_accessor :remember_for
121
+ @@remember_for = 2.weeks
122
+
123
+ # If true, extends the user's remember period when remembered via cookie.
124
+ mattr_accessor :extend_remember_period
125
+ @@extend_remember_period = false
126
+
127
+ # Time interval you can access your account before confirming your account.
128
+ mattr_accessor :confirm_within
129
+ @@confirm_within = 0.days
130
+
131
+ # Defines which key will be used when confirming an account.
132
+ mattr_accessor :confirmation_keys
133
+ @@confirmation_keys = [ :email ]
134
+
135
+ # Defines if email should be reconfirmable.
136
+ # False by default for backwards compatibility.
137
+ mattr_accessor :reconfirmable
138
+ @@reconfirmable = false
139
+
140
+ # Time interval to timeout the user session without activity.
141
+ mattr_accessor :timeout_in
142
+ @@timeout_in = 30.minutes
143
+
144
+ # Used to encrypt password. Please generate one with rake secret.
145
+ mattr_accessor :pepper
146
+ @@pepper = nil
147
+
148
+ # Used to define the password encryption algorithm.
149
+ mattr_accessor :encryptor
150
+ @@encryptor = nil
151
+
152
+ # Scoped views. Since it relies on fallbacks to render default views, it's
153
+ # turned off by default.
154
+ mattr_accessor :scoped_views
155
+ @@scoped_views = false
156
+
157
+ # Defines which strategy can be used to lock an account.
158
+ # Values: :failed_attempts, :none
159
+ mattr_accessor :lock_strategy
160
+ @@lock_strategy = :failed_attempts
161
+
162
+ # Defines which key will be used when locking and unlocking an account
163
+ mattr_accessor :unlock_keys
164
+ @@unlock_keys = [ :email ]
165
+
166
+ # Defines which strategy can be used to unlock an account.
167
+ # Values: :email, :time, :both
168
+ mattr_accessor :unlock_strategy
169
+ @@unlock_strategy = :both
170
+
171
+ # Number of authentication tries before locking an account
172
+ mattr_accessor :maximum_attempts
173
+ @@maximum_attempts = 20
174
+
175
+ # Time interval to unlock the account if :time is defined as unlock_strategy.
176
+ mattr_accessor :unlock_in
177
+ @@unlock_in = 1.hour
178
+
179
+ # Defines which key will be used when recovering the password for an account
180
+ mattr_accessor :reset_password_keys
181
+ @@reset_password_keys = [ :email ]
182
+
183
+ # Time interval you can reset your password with a reset password key
184
+ # Nil by default for backwards compatibility.
185
+ mattr_accessor :reset_password_within
186
+ @@reset_password_within = nil
187
+
188
+ # The default scope which is used by warden.
189
+ mattr_accessor :default_scope
190
+ @@default_scope = nil
191
+
192
+ # Address which sends Devise e-mails.
193
+ mattr_accessor :mailer_sender
194
+ @@mailer_sender = nil
195
+
196
+ # Authentication token params key name of choice. E.g. /users/sign_in?some_key=...
197
+ mattr_accessor :token_authentication_key
198
+ @@token_authentication_key = :auth_token
199
+
200
+ # If true, authentication through token does not store user in session
201
+ mattr_accessor :stateless_token
202
+ @@stateless_token = false
203
+
204
+ # Which formats should be treated as navigational.
205
+ # We need both :"*/*" and "*/*" to work on different Rails versions.
206
+ mattr_accessor :navigational_formats
207
+ @@navigational_formats = [:"*/*", "*/*", :html]
208
+
209
+ # When set to true, signing out a user signs out all other scopes.
210
+ mattr_accessor :sign_out_all_scopes
211
+ @@sign_out_all_scopes = true
212
+
213
+ # The default method used while signing out
214
+ mattr_accessor :sign_out_via
215
+ @@sign_out_via = :get
216
+
217
+ # DEPRECATED CONFIG
218
+
219
+ # If true, uses salt as remember token and does not create it in the database.
220
+ # By default is false for backwards compatibility.
221
+ mattr_accessor :use_salt_as_remember_token
222
+ @@use_salt_as_remember_token = false
223
+
224
+ # Tells if devise should apply the schema in ORMs where devise declaration
225
+ # and schema belongs to the same class (as Datamapper and Mongoid).
226
+ mattr_accessor :apply_schema
227
+ @@apply_schema = true
228
+
229
+ def self.remember_across_browsers=(value)
230
+ puts "\n[DEVISE] Devise.remember_across_browsers is deprecated and has no effect. Please remove it."
231
+ end
232
+
233
+ # PRIVATE CONFIGURATION
234
+
235
+ # Store scopes mappings.
236
+ mattr_reader :mappings
237
+ @@mappings = ActiveSupport::OrderedHash.new
238
+
239
+ # Omniauth configurations.
240
+ mattr_reader :omniauth_configs
241
+ @@omniauth_configs = ActiveSupport::OrderedHash.new
242
+
243
+ # Define a set of modules that are called when a mapping is added.
244
+ mattr_reader :helpers
245
+ @@helpers = Set.new
246
+ @@helpers << Devise::Controllers::Helpers
247
+
248
+ # Private methods to interface with Warden.
249
+ mattr_accessor :warden_config
250
+ @@warden_config = nil
251
+ @@warden_config_block = nil
252
+
253
+ # When true, enter in paranoid mode to avoid user enumeration.
254
+ mattr_accessor :paranoid
255
+ @@paranoid = false
256
+
257
+ # Default way to setup Devise. Run rails generate devise_install to create
258
+ # a fresh initializer with all configuration values.
259
+ def self.setup
260
+ yield self
261
+ end
262
+
263
+ class Getter
264
+ def initialize name
265
+ @name = name
266
+ end
267
+
268
+ def get
269
+ ActiveSupport::Dependencies.constantize(@name)
270
+ end
271
+ end
272
+
273
+ def self.ref(arg)
274
+ if defined?(ActiveSupport::Dependencies::ClassCache)
275
+ ActiveSupport::Dependencies::reference(arg)
276
+ Getter.new(arg)
277
+ else
278
+ ActiveSupport::Dependencies.ref(arg)
279
+ end
280
+ end
281
+
282
+ def self.omniauth_providers
283
+ omniauth_configs.keys
284
+ end
285
+
286
+ # Get the mailer class from the mailer reference object.
287
+ def self.mailer
288
+ @@mailer_ref.get
289
+ end
290
+
291
+ # Set the mailer reference object to access the mailer.
292
+ def self.mailer=(class_name)
293
+ @@mailer_ref = ref(class_name)
294
+ end
295
+ self.mailer = "Devise::Mailer"
296
+
297
+ # Small method that adds a mapping to Devise.
298
+ def self.add_mapping(resource, options)
299
+ mapping = Devise::Mapping.new(resource, options)
300
+ @@mappings[mapping.name] = mapping
301
+ @@default_scope ||= mapping.name
302
+ @@helpers.each { |h| h.define_helpers(mapping) }
303
+ mapping
304
+ end
305
+
306
+ # Make Devise aware of an 3rd party Devise-module (like invitable). For convenience.
307
+ #
308
+ # == Options:
309
+ #
310
+ # +model+ - String representing the load path to a custom *model* for this module (to autoload.)
311
+ # +controller+ - Symbol representing the name of an exisiting or custom *controller* for this module.
312
+ # +route+ - Symbol representing the named *route* helper for this module.
313
+ # +strategy+ - Symbol representing if this module got a custom *strategy*.
314
+ #
315
+ # All values, except :model, accept also a boolean and will have the same name as the given module
316
+ # name.
317
+ #
318
+ # == Examples:
319
+ #
320
+ # Devise.add_module(:party_module)
321
+ # Devise.add_module(:party_module, :strategy => true, :controller => :sessions)
322
+ # Devise.add_module(:party_module, :model => 'party_module/model')
323
+ #
324
+ def self.add_module(module_name, options = {})
325
+ ALL << module_name
326
+ options.assert_valid_keys(:strategy, :model, :controller, :route)
327
+
328
+ if strategy = options[:strategy]
329
+ strategy = (strategy == true ? module_name : strategy)
330
+ STRATEGIES[module_name] = strategy
331
+ end
332
+
333
+ if controller = options[:controller]
334
+ controller = (controller == true ? module_name : controller)
335
+ CONTROLLERS[module_name] = controller
336
+ end
337
+
338
+ NO_INPUT << strategy if strategy && controller != :sessions
339
+
340
+ if route = options[:route]
341
+ case route
342
+ when TrueClass
343
+ key, value = module_name, []
344
+ when Symbol
345
+ key, value = route, []
346
+ when Hash
347
+ key, value = route.keys.first, route.values.flatten
348
+ else
349
+ raise ArgumentError, ":route should be true, a Symbol or a Hash"
350
+ end
351
+
352
+ URL_HELPERS[key] ||= []
353
+ URL_HELPERS[key].concat(value)
354
+ URL_HELPERS[key].uniq!
355
+
356
+ ROUTES[module_name] = key
357
+ end
358
+
359
+ if options[:model]
360
+ path = (options[:model] == true ? "devise/models/#{module_name}" : options[:model])
361
+ camelized = ActiveSupport::Inflector.camelize(module_name.to_s)
362
+ Devise::Models.send(:autoload, camelized.to_sym, path)
363
+ end
364
+
365
+ Devise::Mapping.add_module module_name
366
+ end
367
+
368
+ # Sets warden configuration using a block that will be invoked on warden
369
+ # initialization.
370
+ #
371
+ # Devise.initialize do |config|
372
+ # config.confirm_within = 2.days
373
+ #
374
+ # config.warden do |manager|
375
+ # # Configure warden to use other strategies, like oauth.
376
+ # manager.oauth(:twitter)
377
+ # end
378
+ # end
379
+ def self.warden(&block)
380
+ @@warden_config_block = block
381
+ end
382
+
383
+ # Specify an omniauth provider.
384
+ #
385
+ # config.omniauth :github, APP_ID, APP_SECRET
386
+ #
387
+ def self.omniauth(provider, *args)
388
+ @@helpers << Devise::OmniAuth::UrlHelpers
389
+ config = Devise::OmniAuth::Config.new(provider, args)
390
+ @@omniauth_configs[config.strategy_name.to_sym] = config
391
+ end
392
+
393
+ # Include helpers in the given scope to AC and AV.
394
+ def self.include_helpers(scope)
395
+ ActiveSupport.on_load(:action_controller) do
396
+ include scope::Helpers if defined?(scope::Helpers)
397
+ include scope::UrlHelpers
398
+ end
399
+
400
+ ActiveSupport.on_load(:action_view) do
401
+ include scope::UrlHelpers
402
+ end
403
+ end
404
+
405
+ # Returns true if Rails version is bigger than 3.0.x
406
+ def self.rack_session?
407
+ Rails::VERSION::STRING[0,3] != "3.0"
408
+ end
409
+
410
+ # Regenerates url helpers considering Devise.mapping
411
+ def self.regenerate_helpers!
412
+ Devise::Controllers::UrlHelpers.remove_helpers!
413
+ Devise::Controllers::UrlHelpers.generate_helpers!
414
+ end
415
+
416
+ # A method used internally to setup warden manager from the Rails initialize
417
+ # block.
418
+ def self.configure_warden! #:nodoc:
419
+ @@warden_configured ||= begin
420
+ warden_config.failure_app = Devise::Delegator.new
421
+ warden_config.default_scope = Devise.default_scope
422
+ warden_config.intercept_401 = false
423
+
424
+ Devise.mappings.each_value do |mapping|
425
+ warden_config.scope_defaults mapping.name, :strategies => mapping.strategies
426
+ end
427
+
428
+ @@warden_config_block.try :call, Devise.warden_config
429
+ true
430
+ end
431
+ end
432
+
433
+ # Generate a friendly string randomically to be used as token.
434
+ def self.friendly_token
435
+ SecureRandom.base64(15).tr('+/=lIO0', 'pqrsxyz')
436
+ end
437
+
438
+ # constant-time comparison algorithm to prevent timing attacks
439
+ def self.secure_compare(a, b)
440
+ return false if a.blank? || b.blank? || a.bytesize != b.bytesize
441
+ l = a.unpack "C#{a.bytesize}"
442
+
443
+ res = 0
444
+ b.each_byte { |byte| res |= byte ^ l.shift }
445
+ res == 0
446
+ end
447
+ end
448
+
449
+ require 'warden'
450
+ require 'devise/mapping'
451
+ require 'devise/models'
452
+ require 'devise/modules'
453
+ require 'devise/rails'