devise-bootstrap 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +31 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +29 -0
  6. data/Rakefile +1 -0
  7. data/app/controllers/devise/confirmations_controller.rb +47 -0
  8. data/app/controllers/devise/omniauth_callbacks_controller.rb +30 -0
  9. data/app/controllers/devise/passwords_controller.rb +70 -0
  10. data/app/controllers/devise/registrations_controller.rb +137 -0
  11. data/app/controllers/devise/sessions_controller.rb +53 -0
  12. data/app/controllers/devise/unlocks_controller.rb +46 -0
  13. data/app/controllers/devise_controller.rb +176 -0
  14. data/app/helpers/devise_helper.rb +25 -0
  15. data/app/mailers/devise/mailer.rb +20 -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 +29 -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/config/locales/en.yml +59 -0
  28. data/devise-bootstrap.gemspec +30 -0
  29. data/gemfiles/Gemfile.rails-3.2-stable +29 -0
  30. data/gemfiles/Gemfile.rails-4.0-stable +29 -0
  31. data/gemfiles/Gemfile.rails-head +29 -0
  32. data/lib/devise/bootstrap.rb +7 -0
  33. data/lib/devise/bootstrap/version.rb +5 -0
  34. data/lib/devise/devise.rb +491 -0
  35. data/lib/devise/devise/controllers/helpers.rb +213 -0
  36. data/lib/devise/devise/controllers/rememberable.rb +47 -0
  37. data/lib/devise/devise/controllers/scoped_views.rb +17 -0
  38. data/lib/devise/devise/controllers/sign_in_out.rb +103 -0
  39. data/lib/devise/devise/controllers/store_location.rb +50 -0
  40. data/lib/devise/devise/controllers/url_helpers.rb +67 -0
  41. data/lib/devise/devise/delegator.rb +16 -0
  42. data/lib/devise/devise/failure_app.rb +205 -0
  43. data/lib/devise/devise/hooks/activatable.rb +11 -0
  44. data/lib/devise/devise/hooks/csrf_cleaner.rb +5 -0
  45. data/lib/devise/devise/hooks/forgetable.rb +9 -0
  46. data/lib/devise/devise/hooks/lockable.rb +7 -0
  47. data/lib/devise/devise/hooks/proxy.rb +21 -0
  48. data/lib/devise/devise/hooks/rememberable.rb +7 -0
  49. data/lib/devise/devise/hooks/timeoutable.rb +28 -0
  50. data/lib/devise/devise/hooks/trackable.rb +9 -0
  51. data/lib/devise/devise/mailers/helpers.rb +90 -0
  52. data/lib/devise/devise/mapping.rb +172 -0
  53. data/lib/devise/devise/models.rb +119 -0
  54. data/lib/devise/devise/models/authenticatable.rb +284 -0
  55. data/lib/devise/devise/models/confirmable.rb +295 -0
  56. data/lib/devise/devise/models/database_authenticatable.rb +164 -0
  57. data/lib/devise/devise/models/lockable.rb +196 -0
  58. data/lib/devise/devise/models/omniauthable.rb +27 -0
  59. data/lib/devise/devise/models/recoverable.rb +131 -0
  60. data/lib/devise/devise/models/registerable.rb +25 -0
  61. data/lib/devise/devise/models/rememberable.rb +129 -0
  62. data/lib/devise/devise/models/timeoutable.rb +49 -0
  63. data/lib/devise/devise/models/trackable.rb +35 -0
  64. data/lib/devise/devise/models/validatable.rb +66 -0
  65. data/lib/devise/devise/modules.rb +28 -0
  66. data/lib/devise/devise/omniauth.rb +28 -0
  67. data/lib/devise/devise/omniauth/config.rb +45 -0
  68. data/lib/devise/devise/omniauth/url_helpers.rb +18 -0
  69. data/lib/devise/devise/orm/active_record.rb +3 -0
  70. data/lib/devise/devise/orm/mongoid.rb +3 -0
  71. data/lib/devise/devise/parameter_filter.rb +40 -0
  72. data/lib/devise/devise/parameter_sanitizer.rb +99 -0
  73. data/lib/devise/devise/rails.rb +56 -0
  74. data/lib/devise/devise/rails/routes.rb +496 -0
  75. data/lib/devise/devise/rails/warden_compat.rb +22 -0
  76. data/lib/devise/devise/strategies/authenticatable.rb +167 -0
  77. data/lib/devise/devise/strategies/base.rb +20 -0
  78. data/lib/devise/devise/strategies/database_authenticatable.rb +23 -0
  79. data/lib/devise/devise/strategies/rememberable.rb +55 -0
  80. data/lib/devise/devise/test_helpers.rb +132 -0
  81. data/lib/devise/devise/time_inflector.rb +14 -0
  82. data/lib/devise/devise/token_generator.rb +70 -0
  83. data/lib/devise/devise/version.rb +3 -0
  84. data/lib/devise/generators/active_record/devise_generator.rb +73 -0
  85. data/lib/devise/generators/active_record/templates/migration.rb +18 -0
  86. data/lib/devise/generators/active_record/templates/migration_existing.rb +25 -0
  87. data/lib/devise/generators/devise/devise_generator.rb +26 -0
  88. data/lib/devise/generators/devise/install_generator.rb +29 -0
  89. data/lib/devise/generators/devise/orm_helpers.rb +51 -0
  90. data/lib/devise/generators/devise/views_generator.rb +135 -0
  91. data/lib/devise/generators/mongoid/devise_generator.rb +55 -0
  92. data/lib/devise/generators/templates/README +35 -0
  93. data/lib/devise/generators/templates/devise.rb +260 -0
  94. data/lib/devise/generators/templates/markerb/confirmation_instructions.markerb +5 -0
  95. data/lib/devise/generators/templates/markerb/reset_password_instructions.markerb +8 -0
  96. data/lib/devise/generators/templates/markerb/unlock_instructions.markerb +7 -0
  97. data/lib/devise/generators/templates/simple_form_for/confirmations/new.html.erb +16 -0
  98. data/lib/devise/generators/templates/simple_form_for/passwords/edit.html.erb +19 -0
  99. data/lib/devise/generators/templates/simple_form_for/passwords/new.html.erb +15 -0
  100. data/lib/devise/generators/templates/simple_form_for/registrations/edit.html.erb +27 -0
  101. data/lib/devise/generators/templates/simple_form_for/registrations/new.html.erb +17 -0
  102. data/lib/devise/generators/templates/simple_form_for/sessions/new.html.erb +15 -0
  103. data/lib/devise/generators/templates/simple_form_for/unlocks/new.html.erb +16 -0
  104. metadata +250 -0
@@ -0,0 +1,59 @@
1
+ # Additional translations at https://github.com/plataformatec/devise/wiki/I18n
2
+
3
+ en:
4
+ devise:
5
+ confirmations:
6
+ confirmed: "Your email address has been successfully confirmed."
7
+ send_instructions: "You will receive an email with instructions for how to confirm your email address in a few minutes."
8
+ send_paranoid_instructions: "If your email address exists in our database, you will receive an email with instructions for how to confirm your email address in a few minutes."
9
+ failure:
10
+ already_authenticated: "You are already signed in."
11
+ inactive: "Your account is not activated yet."
12
+ invalid: "Invalid email or password."
13
+ locked: "Your account is locked."
14
+ last_attempt: "You have one more attempt before your account is locked."
15
+ not_found_in_database: "Invalid email address or password."
16
+ timeout: "Your session expired. Please sign in again to continue."
17
+ unauthenticated: "You need to sign in or sign up before continuing."
18
+ unconfirmed: "You have to confirm your email address before continuing."
19
+ mailer:
20
+ confirmation_instructions:
21
+ subject: "Confirmation instructions"
22
+ reset_password_instructions:
23
+ subject: "Reset password instructions"
24
+ unlock_instructions:
25
+ subject: "Unlock instructions"
26
+ omniauth_callbacks:
27
+ failure: "Could not authenticate you from %{kind} because \"%{reason}\"."
28
+ success: "Successfully authenticated from %{kind} account."
29
+ passwords:
30
+ no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided."
31
+ send_instructions: "You will receive an email with instructions on how to reset your password in a few minutes."
32
+ send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes."
33
+ updated: "Your password has been changed successfully. You are now signed in."
34
+ updated_not_active: "Your password has been changed successfully."
35
+ registrations:
36
+ destroyed: "Bye! Your account has been successfully cancelled. We hope to see you again soon."
37
+ signed_up: "Welcome! You have signed up successfully."
38
+ signed_up_but_inactive: "You have signed up successfully. However, we could not sign you in because your account is not yet activated."
39
+ signed_up_but_locked: "You have signed up successfully. However, we could not sign you in because your account is locked."
40
+ signed_up_but_unconfirmed: "A message with a confirmation link has been sent to your email address. Please follow the link to activate your account."
41
+ update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and follow the confirm link to confirm your new email address."
42
+ updated: "Your account has been updated successfully."
43
+ sessions:
44
+ signed_in: "Signed in successfully."
45
+ signed_out: "Signed out successfully."
46
+ unlocks:
47
+ send_instructions: "You will receive an email with instructions for how to unlock your account in a few minutes."
48
+ send_paranoid_instructions: "If your account exists, you will receive an email with instructions for how to unlock it in a few minutes."
49
+ unlocked: "Your account has been unlocked successfully. Please sign in to continue."
50
+ errors:
51
+ messages:
52
+ already_confirmed: "was already confirmed, please try signing in"
53
+ confirmation_period_expired: "needs to be confirmed within %{period}, please request a new one"
54
+ expired: "has expired, please request a new one"
55
+ not_found: "not found"
56
+ not_locked: "was not locked"
57
+ not_saved:
58
+ one: "1 error prohibited this %{resource} from being saved:"
59
+ other: "%{count} errors prohibited this %{resource} from being saved:"
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'devise/bootstrap/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "devise-bootstrap"
8
+ spec.version = Devise::Bootstrap::VERSION
9
+ spec.authors = ["ratnakar"]
10
+ spec.email = ["ratnakarrao_nyros@yahoo.com"]
11
+ spec.description = %q{deveise with bootstrap}
12
+ spec.summary = %q{deveise with bootstrap}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ #spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_dependency("warden", "~> 1.2.3")
25
+ spec.add_dependency("orm_adapter", "~> 0.1")
26
+ spec.add_dependency("bcrypt", "~> 3.0")
27
+ spec.add_dependency("thread_safe", "~> 0.1")
28
+ spec.add_dependency("railties", ">= 3.2.6", "< 5")
29
+ end
30
+
@@ -0,0 +1,29 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec path: '..'
4
+
5
+ gem "rails", github: 'rails/rails', branch: '3-2-stable'
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.3", require: false
14
+ gem "mocha", "~> 1.0.0", require: false
15
+ end
16
+
17
+ platforms :jruby do
18
+ gem "activerecord-jdbc-adapter"
19
+ gem "activerecord-jdbcsqlite3-adapter"
20
+ gem "jruby-openssl"
21
+ end
22
+
23
+ platforms :ruby do
24
+ gem "sqlite3"
25
+ end
26
+
27
+ group :mongoid do
28
+ gem "mongoid", "~> 3.0"
29
+ end
@@ -0,0 +1,29 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec path: '..'
4
+
5
+ gem "rails", github: 'rails/rails', branch: '4-0-stable'
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.3", require: false
14
+ gem "mocha", "~> 1.0.0", require: false
15
+ end
16
+
17
+ platforms :jruby do
18
+ gem "activerecord-jdbc-adapter"
19
+ gem "activerecord-jdbcsqlite3-adapter"
20
+ gem "jruby-openssl"
21
+ end
22
+
23
+ platforms :ruby do
24
+ gem "sqlite3"
25
+ end
26
+
27
+ group :mongoid do
28
+ gem "mongoid", github: "mongoid/mongoid", branch: "master"
29
+ end
@@ -0,0 +1,29 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec path: '..'
4
+
5
+ gem "rails", github: 'rails/rails'
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.3", require: false
14
+ gem "mocha", "~> 1.0.0", require: false
15
+ end
16
+
17
+ platforms :jruby do
18
+ gem "activerecord-jdbc-adapter"
19
+ gem "activerecord-jdbcsqlite3-adapter"
20
+ gem "jruby-openssl"
21
+ end
22
+
23
+ platforms :ruby do
24
+ gem "sqlite3"
25
+ end
26
+
27
+ group :mongoid do
28
+ gem "mongoid", github: "mongoid/mongoid", branch: "master"
29
+ end
@@ -0,0 +1,7 @@
1
+ require "devise/bootstrap/version"
2
+
3
+ module Devise
4
+ module Bootstrap
5
+ # Your code goes here...
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module Devise
2
+ module Bootstrap
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,491 @@
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 :ParameterFilter, 'devise/parameter_filter'
13
+ autoload :BaseSanitizer, 'devise/parameter_sanitizer'
14
+ autoload :ParameterSanitizer, 'devise/parameter_sanitizer'
15
+ autoload :TestHelpers, 'devise/test_helpers'
16
+ autoload :TimeInflector, 'devise/time_inflector'
17
+ autoload :TokenGenerator, 'devise/token_generator'
18
+
19
+ module Controllers
20
+ autoload :Helpers, 'devise/controllers/helpers'
21
+ autoload :Rememberable, 'devise/controllers/rememberable'
22
+ autoload :ScopedViews, 'devise/controllers/scoped_views'
23
+ autoload :SignInOut, 'devise/controllers/sign_in_out'
24
+ autoload :StoreLocation, 'devise/controllers/store_location'
25
+ autoload :UrlHelpers, 'devise/controllers/url_helpers'
26
+ end
27
+
28
+ module Hooks
29
+ autoload :Proxy, 'devise/hooks/proxy'
30
+ end
31
+
32
+ module Mailers
33
+ autoload :Helpers, 'devise/mailers/helpers'
34
+ end
35
+
36
+ module Strategies
37
+ autoload :Base, 'devise/strategies/base'
38
+ autoload :Authenticatable, 'devise/strategies/authenticatable'
39
+ end
40
+
41
+ # Constants which holds devise configuration for extensions. Those should
42
+ # not be modified by the "end user" (this is why they are constants).
43
+ ALL = []
44
+ CONTROLLERS = ActiveSupport::OrderedHash.new
45
+ ROUTES = ActiveSupport::OrderedHash.new
46
+ STRATEGIES = ActiveSupport::OrderedHash.new
47
+ URL_HELPERS = ActiveSupport::OrderedHash.new
48
+
49
+ # Strategies that do not require user input.
50
+ NO_INPUT = []
51
+
52
+ # True values used to check params
53
+ TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE']
54
+
55
+ # Secret key used by the key generator
56
+ mattr_accessor :secret_key
57
+ @@secret_key = nil
58
+
59
+ [ :allow_insecure_token_lookup,
60
+ :allow_insecure_sign_in_after_confirmation,
61
+ :token_authentication_key ].each do |method|
62
+ class_eval <<-RUBY
63
+ def self.#{method}
64
+ ActiveSupport::Deprecation.warn "Devise.#{method} is deprecated " \
65
+ "and has no effect"
66
+ end
67
+
68
+ def self.#{method}=(val)
69
+ ActiveSupport::Deprecation.warn "Devise.#{method}= is deprecated " \
70
+ "and has no effect"
71
+ end
72
+ RUBY
73
+ end
74
+
75
+ # Custom domain or key for cookies. Not set by default
76
+ mattr_accessor :rememberable_options
77
+ @@rememberable_options = {}
78
+
79
+ # The number of times to encrypt password.
80
+ mattr_accessor :stretches
81
+ @@stretches = 10
82
+
83
+ # The default key used when authenticating over http auth.
84
+ mattr_accessor :http_authentication_key
85
+ @@http_authentication_key = nil
86
+
87
+ # Keys used when authenticating a user.
88
+ mattr_accessor :authentication_keys
89
+ @@authentication_keys = [ :email ]
90
+
91
+ # Request keys used when authenticating a user.
92
+ mattr_accessor :request_keys
93
+ @@request_keys = []
94
+
95
+ # Keys that should be case-insensitive.
96
+ mattr_accessor :case_insensitive_keys
97
+ @@case_insensitive_keys = [ :email ]
98
+
99
+ # Keys that should have whitespace stripped.
100
+ mattr_accessor :strip_whitespace_keys
101
+ @@strip_whitespace_keys = []
102
+
103
+ # If http authentication is enabled by default.
104
+ mattr_accessor :http_authenticatable
105
+ @@http_authenticatable = false
106
+
107
+ # If http headers should be returned for ajax requests. True by default.
108
+ mattr_accessor :http_authenticatable_on_xhr
109
+ @@http_authenticatable_on_xhr = true
110
+
111
+ # If params authenticatable is enabled by default.
112
+ mattr_accessor :params_authenticatable
113
+ @@params_authenticatable = true
114
+
115
+ # The realm used in Http Basic Authentication.
116
+ mattr_accessor :http_authentication_realm
117
+ @@http_authentication_realm = "Application"
118
+
119
+ # Email regex used to validate email formats. It simply asserts that
120
+ # an one (and only one) @ exists in the given string. This is mainly
121
+ # to give user feedback and not to assert the e-mail validity.
122
+ mattr_accessor :email_regexp
123
+ @@email_regexp = /\A[^@\s]+@([^@\s]+\.)+[^@\s]+\z/
124
+
125
+ # Range validation for password length
126
+ mattr_accessor :password_length
127
+ @@password_length = 6..128
128
+
129
+ # The time the user will be remembered without asking for credentials again.
130
+ mattr_accessor :remember_for
131
+ @@remember_for = 2.weeks
132
+
133
+ # If true, extends the user's remember period when remembered via cookie.
134
+ mattr_accessor :extend_remember_period
135
+ @@extend_remember_period = false
136
+
137
+ # Time interval you can access your account before confirming your account.
138
+ # nil - allows unconfirmed access for unlimited time
139
+ mattr_accessor :allow_unconfirmed_access_for
140
+ @@allow_unconfirmed_access_for = 0.days
141
+
142
+ # Time interval the confirmation token is valid. nil = unlimited
143
+ mattr_accessor :confirm_within
144
+ @@confirm_within = nil
145
+
146
+ # Defines which key will be used when confirming an account.
147
+ mattr_accessor :confirmation_keys
148
+ @@confirmation_keys = [ :email ]
149
+
150
+ # Defines if email should be reconfirmable.
151
+ # False by default for backwards compatibility.
152
+ mattr_accessor :reconfirmable
153
+ @@reconfirmable = false
154
+
155
+ # Time interval to timeout the user session without activity.
156
+ mattr_accessor :timeout_in
157
+ @@timeout_in = 30.minutes
158
+
159
+ # Authentication token expiration on timeout
160
+ mattr_accessor :expire_auth_token_on_timeout
161
+ @@expire_auth_token_on_timeout = false
162
+
163
+ # Used to encrypt password. Please generate one with rake secret.
164
+ mattr_accessor :pepper
165
+ @@pepper = nil
166
+
167
+ # Scoped views. Since it relies on fallbacks to render default views, it's
168
+ # turned off by default.
169
+ mattr_accessor :scoped_views
170
+ @@scoped_views = false
171
+
172
+ # Defines which strategy can be used to lock an account.
173
+ # Values: :failed_attempts, :none
174
+ mattr_accessor :lock_strategy
175
+ @@lock_strategy = :failed_attempts
176
+
177
+ # Defines which key will be used when locking and unlocking an account
178
+ mattr_accessor :unlock_keys
179
+ @@unlock_keys = [ :email ]
180
+
181
+ # Defines which strategy can be used to unlock an account.
182
+ # Values: :email, :time, :both
183
+ mattr_accessor :unlock_strategy
184
+ @@unlock_strategy = :both
185
+
186
+ # Number of authentication tries before locking an account
187
+ mattr_accessor :maximum_attempts
188
+ @@maximum_attempts = 20
189
+
190
+ # Time interval to unlock the account if :time is defined as unlock_strategy.
191
+ mattr_accessor :unlock_in
192
+ @@unlock_in = 1.hour
193
+
194
+ # Defines which key will be used when recovering the password for an account
195
+ mattr_accessor :reset_password_keys
196
+ @@reset_password_keys = [ :email ]
197
+
198
+ # Time interval you can reset your password with a reset password key
199
+ mattr_accessor :reset_password_within
200
+ @@reset_password_within = 6.hours
201
+
202
+ # The default scope which is used by warden.
203
+ mattr_accessor :default_scope
204
+ @@default_scope = nil
205
+
206
+ # Address which sends Devise e-mails.
207
+ mattr_accessor :mailer_sender
208
+ @@mailer_sender = nil
209
+
210
+ # Skip session storage for the following strategies
211
+ mattr_accessor :skip_session_storage
212
+ @@skip_session_storage = []
213
+
214
+ # Which formats should be treated as navigational.
215
+ mattr_accessor :navigational_formats
216
+ @@navigational_formats = ["*/*", :html]
217
+
218
+ # When set to true, signing out a user signs out all other scopes.
219
+ mattr_accessor :sign_out_all_scopes
220
+ @@sign_out_all_scopes = true
221
+
222
+ # The default method used while signing out
223
+ mattr_accessor :sign_out_via
224
+ @@sign_out_via = :get
225
+
226
+ # The parent controller all Devise controllers inherits from.
227
+ # Defaults to ApplicationController. This should be set early
228
+ # in the initialization process and should be set to a string.
229
+ mattr_accessor :parent_controller
230
+ @@parent_controller = "ApplicationController"
231
+
232
+ # The parent mailer all Devise mailers inherit from.
233
+ # Defaults to ActionMailer::Base. This should be set early
234
+ # in the initialization process and should be set to a string.
235
+ mattr_accessor :parent_mailer
236
+ @@parent_mailer = "ActionMailer::Base"
237
+
238
+ # The router Devise should use to generate routes. Defaults
239
+ # to :main_app. Should be overridden by engines in order
240
+ # to provide custom routes.
241
+ mattr_accessor :router_name
242
+ @@router_name = nil
243
+
244
+ # Set the omniauth path prefix so it can be overridden when
245
+ # Devise is used in a mountable engine
246
+ mattr_accessor :omniauth_path_prefix
247
+ @@omniauth_path_prefix = nil
248
+
249
+ # Set if we should clean up the CSRF Token on authentication
250
+ mattr_accessor :clean_up_csrf_token_on_authentication
251
+ @@clean_up_csrf_token_on_authentication = true
252
+
253
+ # PRIVATE CONFIGURATION
254
+
255
+ # Store scopes mappings.
256
+ mattr_reader :mappings
257
+ @@mappings = ActiveSupport::OrderedHash.new
258
+
259
+ # Omniauth configurations.
260
+ mattr_reader :omniauth_configs
261
+ @@omniauth_configs = ActiveSupport::OrderedHash.new
262
+
263
+ # Define a set of modules that are called when a mapping is added.
264
+ mattr_reader :helpers
265
+ @@helpers = Set.new
266
+ @@helpers << Devise::Controllers::Helpers
267
+
268
+ # Private methods to interface with Warden.
269
+ mattr_accessor :warden_config
270
+ @@warden_config = nil
271
+ @@warden_config_block = nil
272
+
273
+ # When true, enter in paranoid mode to avoid user enumeration.
274
+ mattr_accessor :paranoid
275
+ @@paranoid = false
276
+
277
+ # When true, warn user if they just used next-to-last attempt of authentication
278
+ mattr_accessor :last_attempt_warning
279
+ @@last_attempt_warning = false
280
+
281
+ # Stores the token generator
282
+ mattr_accessor :token_generator
283
+ @@token_generator = nil
284
+
285
+ # Default way to setup Devise. Run rails generate devise_install to create
286
+ # a fresh initializer with all configuration values.
287
+ def self.setup
288
+ yield self
289
+ end
290
+
291
+ class Getter
292
+ def initialize name
293
+ @name = name
294
+ end
295
+
296
+ def get
297
+ ActiveSupport::Dependencies.constantize(@name)
298
+ end
299
+ end
300
+
301
+ def self.ref(arg)
302
+ if defined?(ActiveSupport::Dependencies::ClassCache)
303
+ ActiveSupport::Dependencies::reference(arg)
304
+ Getter.new(arg)
305
+ else
306
+ ActiveSupport::Dependencies.ref(arg)
307
+ end
308
+ end
309
+
310
+ def self.available_router_name
311
+ router_name || :main_app
312
+ end
313
+
314
+ def self.omniauth_providers
315
+ omniauth_configs.keys
316
+ end
317
+
318
+ # Get the mailer class from the mailer reference object.
319
+ def self.mailer
320
+ @@mailer_ref.get
321
+ end
322
+
323
+ # Set the mailer reference object to access the mailer.
324
+ def self.mailer=(class_name)
325
+ @@mailer_ref = ref(class_name)
326
+ end
327
+ self.mailer = "Devise::Mailer"
328
+
329
+ # Small method that adds a mapping to Devise.
330
+ def self.add_mapping(resource, options)
331
+ mapping = Devise::Mapping.new(resource, options)
332
+ @@mappings[mapping.name] = mapping
333
+ @@default_scope ||= mapping.name
334
+ @@helpers.each { |h| h.define_helpers(mapping) }
335
+ mapping
336
+ end
337
+
338
+ # Make Devise aware of an 3rd party Devise-module (like invitable). For convenience.
339
+ #
340
+ # == Options:
341
+ #
342
+ # +model+ - String representing the load path to a custom *model* for this module (to autoload.)
343
+ # +controller+ - Symbol representing the name of an existing or custom *controller* for this module.
344
+ # +route+ - Symbol representing the named *route* helper for this module.
345
+ # +strategy+ - Symbol representing if this module got a custom *strategy*.
346
+ #
347
+ # All values, except :model, accept also a boolean and will have the same name as the given module
348
+ # name.
349
+ #
350
+ # == Examples:
351
+ #
352
+ # Devise.add_module(:party_module)
353
+ # Devise.add_module(:party_module, strategy: true, controller: :sessions)
354
+ # Devise.add_module(:party_module, model: 'party_module/model')
355
+ #
356
+ def self.add_module(module_name, options = {})
357
+ ALL << module_name
358
+ options.assert_valid_keys(:strategy, :model, :controller, :route, :no_input)
359
+
360
+ if strategy = options[:strategy]
361
+ strategy = (strategy == true ? module_name : strategy)
362
+ STRATEGIES[module_name] = strategy
363
+ end
364
+
365
+ if controller = options[:controller]
366
+ controller = (controller == true ? module_name : controller)
367
+ CONTROLLERS[module_name] = controller
368
+ end
369
+
370
+ NO_INPUT << strategy if options[:no_input]
371
+
372
+ if route = options[:route]
373
+ case route
374
+ when TrueClass
375
+ key, value = module_name, []
376
+ when Symbol
377
+ key, value = route, []
378
+ when Hash
379
+ key, value = route.keys.first, route.values.flatten
380
+ else
381
+ raise ArgumentError, ":route should be true, a Symbol or a Hash"
382
+ end
383
+
384
+ URL_HELPERS[key] ||= []
385
+ URL_HELPERS[key].concat(value)
386
+ URL_HELPERS[key].uniq!
387
+
388
+ ROUTES[module_name] = key
389
+ end
390
+
391
+ if options[:model]
392
+ path = (options[:model] == true ? "devise/models/#{module_name}" : options[:model])
393
+ camelized = ActiveSupport::Inflector.camelize(module_name.to_s)
394
+ Devise::Models.send(:autoload, camelized.to_sym, path)
395
+ end
396
+
397
+ Devise::Mapping.add_module module_name
398
+ end
399
+
400
+ # Sets warden configuration using a block that will be invoked on warden
401
+ # initialization.
402
+ #
403
+ # Devise.initialize do |config|
404
+ # config.allow_unconfirmed_access_for = 2.days
405
+ #
406
+ # config.warden do |manager|
407
+ # # Configure warden to use other strategies, like oauth.
408
+ # manager.oauth(:twitter)
409
+ # end
410
+ # end
411
+ def self.warden(&block)
412
+ @@warden_config_block = block
413
+ end
414
+
415
+ # Specify an omniauth provider.
416
+ #
417
+ # config.omniauth :github, APP_ID, APP_SECRET
418
+ #
419
+ def self.omniauth(provider, *args)
420
+ @@helpers << Devise::OmniAuth::UrlHelpers
421
+ config = Devise::OmniAuth::Config.new(provider, args)
422
+ @@omniauth_configs[config.strategy_name.to_sym] = config
423
+ end
424
+
425
+ # Include helpers in the given scope to AC and AV.
426
+ def self.include_helpers(scope)
427
+ ActiveSupport.on_load(:action_controller) do
428
+ include scope::Helpers if defined?(scope::Helpers)
429
+ include scope::UrlHelpers
430
+ end
431
+
432
+ ActiveSupport.on_load(:action_view) do
433
+ include scope::UrlHelpers
434
+ end
435
+ end
436
+
437
+ # Regenerates url helpers considering Devise.mapping
438
+ def self.regenerate_helpers!
439
+ Devise::Controllers::UrlHelpers.remove_helpers!
440
+ Devise::Controllers::UrlHelpers.generate_helpers!
441
+ end
442
+
443
+ # A method used internally to setup warden manager from the Rails initialize
444
+ # block.
445
+ def self.configure_warden! #:nodoc:
446
+ @@warden_configured ||= begin
447
+ warden_config.failure_app = Devise::Delegator.new
448
+ warden_config.default_scope = Devise.default_scope
449
+ warden_config.intercept_401 = false
450
+
451
+ Devise.mappings.each_value do |mapping|
452
+ warden_config.scope_defaults mapping.name, strategies: mapping.strategies
453
+
454
+ warden_config.serialize_into_session(mapping.name) do |record|
455
+ mapping.to.serialize_into_session(record)
456
+ end
457
+
458
+ warden_config.serialize_from_session(mapping.name) do |key|
459
+ # Previous versions contained an additional entry at the beginning of
460
+ # key with the record's class name.
461
+ args = key[-2, 2]
462
+ mapping.to.serialize_from_session(*args)
463
+ end
464
+ end
465
+
466
+ @@warden_config_block.try :call, Devise.warden_config
467
+ true
468
+ end
469
+ end
470
+
471
+ # Generate a friendly string randomly to be used as token.
472
+ def self.friendly_token
473
+ SecureRandom.urlsafe_base64(15).tr('lIO0', 'sxyz')
474
+ end
475
+
476
+ # constant-time comparison algorithm to prevent timing attacks
477
+ def self.secure_compare(a, b)
478
+ return false if a.blank? || b.blank? || a.bytesize != b.bytesize
479
+ l = a.unpack "C#{a.bytesize}"
480
+
481
+ res = 0
482
+ b.each_byte { |byte| res |= byte ^ l.shift }
483
+ res == 0
484
+ end
485
+ end
486
+
487
+ require 'warden'
488
+ require 'devise/mapping'
489
+ require 'devise/models'
490
+ require 'devise/modules'
491
+ require 'devise/rails'