Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 478 lines (388 sloc) 15.071 kb
bca43a7 Jo Liss Require 'rails' in devise.rb.
joliss authored
1 require 'rails'
829c856 José Valim Aim for Rails 3.0.0.beta1 compatibility. A few issues are still pending ...
josevalim authored
2 require 'active_support/core_ext/numeric/time'
a2f8485 José Valim Allow the mailer class to be configured.
josevalim authored
3 require 'active_support/dependencies'
8a8ba6c José Valim Depend on ORM Adapter.
josevalim authored
4 require 'orm_adapter'
1a9db03 José Valim Do not rely on load time anymore. Instead, provide a helper that is call...
josevalim authored
5 require 'set'
4c8cc5e Wael M. Nasreddine SecureRandom is available since Ruby 1.8.7, remove the unnecessary defin...
eMxyzptlk authored
6 require 'securerandom'
829c856 José Valim Aim for Rails 3.0.0.beta1 compatibility. A few issues are still pending ...
josevalim authored
7
9051d84 José Valim Allow devise :all, :except => :foo to be given.
josevalim authored
8 module Devise
4629bee José Valim Cache failure_app action builder and pipe call through delegator.
josevalim authored
9 autoload :Delegator, 'devise/delegator'
10 autoload :FailureApp, 'devise/failure_app'
11 autoload :OmniAuth, 'devise/omniauth'
dc8aa9e José Valim Move param filtering to its own object and make all finder methods pass ...
josevalim authored
12 autoload :ParamFilter, 'devise/param_filter'
4629bee José Valim Cache failure_app action builder and pipe call through delegator.
josevalim authored
13 autoload :Schema, 'devise/schema'
3432c9e José Valim Simplify autoload stack.
josevalim authored
14 autoload :TestHelpers, 'devise/test_helpers'
15
16 module Controllers
17 autoload :Helpers, 'devise/controllers/helpers'
2e43944 José Valim Move rememberable back to a hook.
josevalim authored
18 autoload :Rememberable, 'devise/controllers/rememberable'
02e8c04 José Valim Update views generator and now have scoped views.
josevalim authored
19 autoload :ScopedViews, 'devise/controllers/scoped_views'
3432c9e José Valim Simplify autoload stack.
josevalim authored
20 autoload :UrlHelpers, 'devise/controllers/url_helpers'
21 end
22
23 module Encryptors
35838b0 José Valim Ensure bcrypt works and move salt generation to encryptors (needed for b...
josevalim authored
24 autoload :Base, 'devise/encryptors/base'
3432c9e José Valim Simplify autoload stack.
josevalim authored
25 autoload :AuthlogicSha512, 'devise/encryptors/authlogic_sha512'
9203651 Moved BCrypt logic to a encryptor
Rodrigo Flores authored
26 autoload :BCrypt, 'devise/encryptors/bcrypt'
3435c53 Carlos Antonio da Silva Fix typo: autoload Clearance encryptor and not Authlogic one.
carlosantoniodasilva authored
27 autoload :ClearanceSha1, 'devise/encryptors/clearance_sha1'
3432c9e José Valim Simplify autoload stack.
josevalim authored
28 autoload :RestfulAuthenticationSha1, 'devise/encryptors/restful_authentication_sha1'
29 autoload :Sha512, 'devise/encryptors/sha512'
30 autoload :Sha1, 'devise/encryptors/sha1'
31 end
32
42f0285 José Valim Extract mailer functionality, closes #1164
josevalim authored
33 module Mailers
34 autoload :Helpers, 'devise/mailers/helpers'
35 end
36
1d65a76 José Valim Move remember_me hook inside strategies.
josevalim authored
37 module Strategies
38 autoload :Base, 'devise/strategies/base'
39 autoload :Authenticatable, 'devise/strategies/authenticatable'
40 end
41
0386275 José Valim Keep modules definition in a different file.
josevalim authored
42 # Constants which holds devise configuration for extensions. Those should
faf771c José Valim Add OAuth url helpers.
josevalim authored
43 # not be modified by the "end user" (this is why they are constants).
b974b7b José Valim Move failure messages from devise.sessions to devise.failure.
josevalim authored
44 ALL = []
45 CONTROLLERS = ActiveSupport::OrderedHash.new
46 ROUTES = ActiveSupport::OrderedHash.new
47 STRATEGIES = ActiveSupport::OrderedHash.new
bd8294a José Valim More OAuth setup.
josevalim authored
48 URL_HELPERS = ActiveSupport::OrderedHash.new
e1440fb Jonas Grimfelt Initial support for authorization using "authentication token" (a.k.a. "...
grimen authored
49
4fd866d José Valim User cannot access sign up and similar pages if he is already signed in ...
josevalim authored
50 # Strategies that do not require user input.
51 NO_INPUT = []
52
0386275 José Valim Keep modules definition in a different file.
josevalim authored
53 # True values used to check params
d164768 José Valim Do not freeze arrays, allowing other plugins to extend Devise
josevalim authored
54 TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE']
9051d84 José Valim Allow devise :all, :except => :foo to be given.
josevalim authored
55
6d09eb6 José Valim Tidying up encryptors.
josevalim authored
56 # Declare encryptors length which are used in migrations.
57 ENCRYPTORS_LENGTH = {
58 :sha1 => 40,
59 :sha512 => 128,
60 :clearance_sha1 => 40,
61 :restful_authentication_sha1 => 40,
0908870 José Valim Extract encryptors into their own module for better bcrypt support.
josevalim authored
62 :authlogic_sha512 => 128
6d09eb6 José Valim Tidying up encryptors.
josevalim authored
63 }
64
21129ae Mantas Masalskis custom domain cookie support
mantas authored
65 # Custom domain for cookies. Not set by default
df8ac1c José Valim Clean up remember token related config.
josevalim authored
66 mattr_accessor :rememberable_options
67 @@rememberable_options = {}
21129ae Mantas Masalskis custom domain cookie support
mantas authored
68
80699c5 Ensure user config is not overwriten by default config.
José Valim authored
69 # The number of times to encrypt password.
70 mattr_accessor :stretches
71 @@stretches = 10
512397b Cyril Mougel add capability to define other orm compatible with Devise. Add MongoMapp...
shingara authored
72
e911abf Andrew Dahl changed case_insensitive_keys config setting to an array and added downc...
adahl authored
73 # Keys used when authenticating a user.
b70b293 José Valim Add authentication_keys.
josevalim authored
74 mattr_accessor :authentication_keys
75 @@authentication_keys = [ :email ]
65b8908 José Valim Create authenticatable base model and strategy.
josevalim authored
76
e911abf Andrew Dahl changed case_insensitive_keys config setting to an array and added downc...
adahl authored
77 # Request keys used when authenticating a user.
b2066cc José Valim Add request_keys support. Closes #401.
josevalim authored
78 mattr_accessor :request_keys
79 @@request_keys = []
80
e911abf Andrew Dahl changed case_insensitive_keys config setting to an array and added downc...
adahl authored
81 # Keys that should be case-insensitive.
74166e2 José Valim Faster uniqueness queries, closes #917
josevalim authored
82 # False by default for backwards compatibility.
94c666e Andrew Dahl first attempt
adahl authored
83 mattr_accessor :case_insensitive_keys
74166e2 José Valim Faster uniqueness queries, closes #917
josevalim authored
84 @@case_insensitive_keys = false
bd27bf7 José Valim Deprecate and disable old behavior accumulated with time.
josevalim authored
85
8e87a2d Add strip_whitespace_keys which works like case_insensitive_keys but str...
Stefan Wrobel authored
86 # Keys that should have whitespace stripped.
87 # False by default for backwards compatibility.
88 mattr_accessor :strip_whitespace_keys
89 @@strip_whitespace_keys = false
94c666e Andrew Dahl first attempt
adahl authored
90
65b8908 José Valim Create authenticatable base model and strategy.
josevalim authored
91 # If http authentication is enabled by default.
92 mattr_accessor :http_authenticatable
b8ab9a8 José Valim Disable HTTP Authentication by default. You can turn it on in the initia...
josevalim authored
93 @@http_authenticatable = false
65b8908 José Valim Create authenticatable base model and strategy.
josevalim authored
94
b8ab9a8 José Valim Disable HTTP Authentication by default. You can turn it on in the initia...
josevalim authored
95 # If http headers should be returned for ajax requests. True by default.
9f29ca4 James Pellow Add http_authenticatable_on_xhr option
james-pellow authored
96 mattr_accessor :http_authenticatable_on_xhr
97 @@http_authenticatable_on_xhr = true
98
f5d01c2 José Valim TokenAuthenticatable now works with HTTP Basic Auth by default (take a l...
josevalim authored
99 # If params authenticatable is enabled by default.
100 mattr_accessor :params_authenticatable
101 @@params_authenticatable = true
102
65b8908 José Valim Create authenticatable base model and strategy.
josevalim authored
103 # The realm used in Http Basic Authentication.
104 mattr_accessor :http_authentication_realm
105 @@http_authentication_realm = "Application"
106
a8d9695 José Valim Simplify regexp and ensure it runs against UTF8 chars, closes #1235
josevalim authored
107 # Email regex used to validate email formats. It simply asserts that
108 # an one (and only one) @ exists in the given string. This is mainly
109 # to give user feedback and not to assert the e-mail validity.
ea71be8 José Valim More compatibility with Rails master.
josevalim authored
110 mattr_accessor :email_regexp
7b1418b José Valim Improve the regexp a bit more.
josevalim authored
111 @@email_regexp = /\A[^@]+@([^@\.]+\.)+[^@\.]+\z/
65b8908 José Valim Create authenticatable base model and strategy.
josevalim authored
112
113 # Range validation for password length
114 mattr_accessor :password_length
8db00ee Matias Korhonen Bump the password maximum length to 128 characters.
matiaskorhonen authored
115 @@password_length = 6..128
65b8908 José Valim Create authenticatable base model and strategy.
josevalim authored
116
2939a61 Trevor Turk documentation tweaks for extend_remember_period
trevorturk authored
117 # The time the user will be remembered without asking for credentials again.
80699c5 Ensure user config is not overwriten by default config.
José Valim authored
118 mattr_accessor :remember_for
119 @@remember_for = 2.weeks
512397b Cyril Mougel add capability to define other orm compatible with Devise. Add MongoMapp...
shingara authored
120
2939a61 Trevor Turk documentation tweaks for extend_remember_period
trevorturk authored
121 # If true, extends the user's remember period when remembered via cookie.
058d433 José Valim Add extend_remember_period, closes #340.
josevalim authored
122 mattr_accessor :extend_remember_period
123 @@extend_remember_period = false
124
80699c5 Ensure user config is not overwriten by default config.
José Valim authored
125 # Time interval you can access your account before confirming your account.
930b324 José Valim Usage of confirm_within was deprecated in favor allow_unconfirmed_access...
josevalim authored
126 mattr_accessor :allow_unconfirmed_access_for
127 @@allow_unconfirmed_access_for = 0.days
c9fe888 Carlos Antonio da Silva Spaces
carlosantoniodasilva authored
128
bd27bf7 José Valim Deprecate and disable old behavior accumulated with time.
josevalim authored
129 # Defines which key will be used when confirming an account.
7a1852e John Plummer Allow send confirmation to change keys used
JohnPlummer authored
130 mattr_accessor :confirmation_keys
131 @@confirmation_keys = [ :email ]
e5be532 José Valim Ensure options can be configured even if models were not loaded yet
josevalim authored
132
bd27bf7 José Valim Deprecate and disable old behavior accumulated with time.
josevalim authored
133 # Defines if email should be reconfirmable.
134 # False by default for backwards compatibility.
6469cbc Mandaryn renamed confirmation_on_email_change property to reconfirmable and added...
Mandaryn authored
135 mattr_accessor :reconfirmable
136 @@reconfirmable = false
1961de6 Mandaryn Add email confirmation when it is changed by a user
Mandaryn authored
137
099c77e Carlos Antonio da Silva Introducing timeoutable to timeout sessions without activity.
carlosantoniodasilva authored
138 # Time interval to timeout the user session without activity.
c05b8cf José Valim Rename :timeout to :timeout_in and release gem again.
josevalim authored
139 mattr_accessor :timeout_in
140 @@timeout_in = 30.minutes
099c77e Carlos Antonio da Silva Introducing timeoutable to timeout sessions without activity.
carlosantoniodasilva authored
141
0908870 José Valim Extract encryptors into their own module for better bcrypt support.
josevalim authored
142 # Used to encrypt password. Please generate one with rake secret.
143 mattr_accessor :pepper
144 @@pepper = nil
145
6d09eb6 José Valim Tidying up encryptors.
josevalim authored
146 # Used to define the password encryption algorithm.
a016819 José Valim Ensure all encryptor returns a symbol. Get the class using encryptor_cla...
josevalim authored
147 mattr_accessor :encryptor
0908870 José Valim Extract encryptors into their own module for better bcrypt support.
josevalim authored
148 @@encryptor = nil
6d09eb6 José Valim Tidying up encryptors.
josevalim authored
149
415bcdc José Valim Added scoped views support. Just turn it on in your Devise.setup.
josevalim authored
150 # Scoped views. Since it relies on fallbacks to render default views, it's
151 # turned off by default.
152 mattr_accessor :scoped_views
153 @@scoped_views = false
154
6cc32db José Valim Add lock_strategy.
josevalim authored
155 # Defines which strategy can be used to lock an account.
156 # Values: :failed_attempts, :none
157 mattr_accessor :lock_strategy
158 @@lock_strategy = :failed_attempts
d2fa737 Marcelo Silveira introducing lockable implementation
mhfs authored
159
038eb32 Richard Aday Allowing reset_password_keys and unlock_keys to be set through the confi...
richardaday authored
160 # Defines which key will be used when locking and unlocking an account
161 mattr_accessor :unlock_keys
162 @@unlock_keys = [ :email ]
163
d2fa737 Marcelo Silveira introducing lockable implementation
mhfs authored
164 # Defines which strategy can be used to unlock an account.
165 # Values: :email, :time, :both
166 mattr_accessor :unlock_strategy
167 @@unlock_strategy = :both
168
6cc32db José Valim Add lock_strategy.
josevalim authored
169 # Number of authentication tries before locking an account
170 mattr_accessor :maximum_attempts
171 @@maximum_attempts = 20
172
d2fa737 Marcelo Silveira introducing lockable implementation
mhfs authored
173 # Time interval to unlock the account if :time is defined as unlock_strategy.
174 mattr_accessor :unlock_in
175 @@unlock_in = 1.hour
176
038eb32 Richard Aday Allowing reset_password_keys and unlock_keys to be set through the confi...
richardaday authored
177 # Defines which key will be used when recovering the password for an account
178 mattr_accessor :reset_password_keys
179 @@reset_password_keys = [ :email ]
180
0b598cf Changed the e-mail validation regex
Rodrigo Flores authored
181 # Time interval you can reset your password with a reset password key
bd27bf7 José Valim Deprecate and disable old behavior accumulated with time.
josevalim authored
182 # Nil by default for backwards compatibility.
be2aeee Add reset_password_within configuration variable.
Jean-Daniel Guyot authored
183 mattr_accessor :reset_password_within
ed51fc7 José Valim Tidy up previous commits.
josevalim authored
184 @@reset_password_within = nil
be2aeee Add reset_password_within configuration variable.
Jean-Daniel Guyot authored
185
4d8f5ea José Valim Add an easy way to configure an application to sign in users through "/s...
josevalim authored
186 # The default scope which is used by warden.
543fe07 José Valim Update to work with Warden 0.8.0.
josevalim authored
187 mattr_accessor :default_scope
188 @@default_scope = nil
189
4d8f5ea José Valim Add an easy way to configure an application to sign in users through "/s...
josevalim authored
190 # Address which sends Devise e-mails.
a789f08 José Valim Cleaning up README to be more compatible with the latest stuff.
josevalim authored
191 mattr_accessor :mailer_sender
9798ad7 José Valim Allow scoped views to be customized per controller/mailer class.
josevalim authored
192 @@mailer_sender = nil
a789f08 José Valim Cleaning up README to be more compatible with the latest stuff.
josevalim authored
193
e1440fb Jonas Grimfelt Initial support for authorization using "authentication token" (a.k.a. "...
grimen authored
194 # Authentication token params key name of choice. E.g. /users/sign_in?some_key=...
3781a0f José Valim Tidy up token authentication implementation.
josevalim authored
195 mattr_accessor :token_authentication_key
196 @@token_authentication_key = :auth_token
e1440fb Jonas Grimfelt Initial support for authorization using "authentication token" (a.k.a. "...
grimen authored
197
5a11c65 José Valim Usage of Devise.stateless_token= is deprecated in favor of appending :to...
josevalim authored
198 # Skip session storage for the following strategies
199 mattr_accessor :skip_session_storage
200 @@skip_session_storage = []
531f221 José Valim Allow :stateless_token to be set to true avoiding users to be stored in ...
josevalim authored
201
2103a67 José Valim Allow devise_for to be scoped with the scope method. This commit require...
josevalim authored
202 # Which formats should be treated as navigational.
bff64a6 José Valim Added navigational formats to specify when it should return a 302 and wh...
josevalim authored
203 mattr_accessor :navigational_formats
0b55ebb José Valim Remove 3.0 related code.
josevalim authored
204 @@navigational_formats = ["*/*", :html]
bff64a6 José Valim Added navigational formats to specify when it should return a 302 and wh...
josevalim authored
205
f06bed2 corrected 'an user' to 'a user' in comments and docs
Nico Ritsche authored
206 # When set to true, signing out a user signs out all other scopes.
6c5be8d José Valim Initial routes and module setup.
josevalim authored
207 mattr_accessor :sign_out_all_scopes
617b95f José Valim sign_out_all_scopes is true by default.
josevalim authored
208 @@sign_out_all_scopes = true
6c5be8d José Valim Initial routes and module setup.
josevalim authored
209
ab7f3bc José Valim Added Devise.sign_out_via.
josevalim authored
210 # The default method used while signing out
211 mattr_accessor :sign_out_via
212 @@sign_out_via = :get
213
c3f864f José Valim Allow parent controller to be customizable.
josevalim authored
214 # The parent controller all Devise controllers inherits from.
0b55ebb José Valim Remove 3.0 related code.
josevalim authored
215 # Defaults to ApplicationController. This should be set early
216 # in the initialization process and should be set to a string.
c3f864f José Valim Allow parent controller to be customizable.
josevalim authored
217 mattr_accessor :parent_controller
218 @@parent_controller = "ApplicationController"
219
897c1c6 José Valim Allow router_name to be customizable via Devise.router_name, useful for ...
josevalim authored
220 # The router Devise should use to generate routes. Defaults
221 # to :main_app. Should be overriden by engines in order
222 # to provide custom routes.
223 mattr_accessor :router_name
dc37b82 José Valim Show a warning message in case routes are not mounted in the main app.
josevalim authored
224 @@router_name = nil
897c1c6 José Valim Allow router_name to be customizable via Devise.router_name, useful for ...
josevalim authored
225
bd27bf7 José Valim Deprecate and disable old behavior accumulated with time.
josevalim authored
226 # DEPRECATED CONFIG
227
228 # If true, uses salt as remember token and does not create it in the database.
229 # By default is false for backwards compatibility.
230 mattr_accessor :use_salt_as_remember_token
231 @@use_salt_as_remember_token = false
232
233 # Tells if devise should apply the schema in ORMs where devise declaration
234 # and schema belongs to the same class (as Datamapper and Mongoid).
235 mattr_accessor :apply_schema
236 @@apply_schema = true
237
238 def self.remember_across_browsers=(value)
273c5e9 José Valim Add space between messages.
josevalim authored
239 warn "\n[DEVISE] Devise.remember_across_browsers is deprecated and has no effect. Please remove it.\n"
bd27bf7 José Valim Deprecate and disable old behavior accumulated with time.
josevalim authored
240 end
241
930b324 José Valim Usage of confirm_within was deprecated in favor allow_unconfirmed_access...
josevalim authored
242 def self.confirm_within=(value)
273c5e9 José Valim Add space between messages.
josevalim authored
243 warn "\n[DEVISE] Devise.confirm_within= is deprecated. Please set Devise.allow_unconfirmed_access_for= instead.\n"
5a11c65 José Valim Usage of Devise.stateless_token= is deprecated in favor of appending :to...
josevalim authored
244 Devise.allow_unconfirmed_access_for = value
245 end
246
df8ac1c José Valim Clean up remember token related config.
josevalim authored
247 def self.cookie_options=(value)
248 warn "\n[DEVISE] Devise.cookie_options= is deprecated. Please set Devise.rememberable_options= instead.\n"
249 Devise.rememberable_options = value
250 end
251
5a11c65 José Valim Usage of Devise.stateless_token= is deprecated in favor of appending :to...
josevalim authored
252 def self.stateless_token=(value)
7ba37b5 José Valim Improve messages.
josevalim authored
253 warn "\n[DEVISE] Devise.stateless_token= is deprecated. Please append :token_auth to Devise.skip_session_storage " \
273c5e9 José Valim Add space between messages.
josevalim authored
254 "instead, for example: Devise.skip_session_storage << :token_auth\n"
5a11c65 José Valim Usage of Devise.stateless_token= is deprecated in favor of appending :to...
josevalim authored
255 Devise.skip_session_storage << :token_auth
930b324 José Valim Usage of confirm_within was deprecated in favor allow_unconfirmed_access...
josevalim authored
256 end
257
6c5be8d José Valim Initial routes and module setup.
josevalim authored
258 # PRIVATE CONFIGURATION
259
faf771c José Valim Add OAuth url helpers.
josevalim authored
260 # Store scopes mappings.
261 mattr_reader :mappings
262 @@mappings = ActiveSupport::OrderedHash.new
263
21d5e50 José Valim Basic omniauth support.
josevalim authored
264 # Omniauth configurations.
265 mattr_reader :omniauth_configs
266 @@omniauth_configs = ActiveSupport::OrderedHash.new
267
1a9db03 José Valim Do not rely on load time anymore. Instead, provide a helper that is call...
josevalim authored
268 # Define a set of modules that are called when a mapping is added.
269 mattr_reader :helpers
270 @@helpers = Set.new
271 @@helpers << Devise::Controllers::Helpers
272
033db1c José Valim Do not depend on silence_missing_strategies! anymore. This speeds up str...
josevalim authored
273 # Private methods to interface with Warden.
6cc32db José Valim Add lock_strategy.
josevalim authored
274 mattr_accessor :warden_config
033db1c José Valim Do not depend on silence_missing_strategies! anymore. This speeds up str...
josevalim authored
275 @@warden_config = nil
276 @@warden_config_block = nil
277
62e11dd José Valim Update CHANGELOG.
josevalim authored
278 # When true, enter in paranoid mode to avoid user enumeration.
004fe2a Paranoid mode for recoverable
Rodrigo Flores authored
279 mattr_accessor :paranoid
280 @@paranoid = false
281
0386275 José Valim Keep modules definition in a different file.
josevalim authored
282 # Default way to setup Devise. Run rails generate devise_install to create
283 # a fresh initializer with all configuration values.
284 def self.setup
285 yield self
286 end
371a9bb José Valim Major refactoring. Allow Warden::Manager to be configured through Devise...
josevalim authored
287
0fbe4cb pechkin fix reference storage to support new and old class cache api
pechkin authored
288 class Getter
289 def initialize name
290 @name = name
291 end
292
293 def get
294 ActiveSupport::Dependencies.constantize(@name)
295 end
296 end
297
30b35e3 José Valim Fix syntax error.
josevalim authored
298 def self.ref(arg)
fbd35ec jack dempsey new cache api requires passing a key to get
jackdempsey authored
299 if defined?(ActiveSupport::Dependencies::ClassCache)
0fbe4cb pechkin fix reference storage to support new and old class cache api
pechkin authored
300 ActiveSupport::Dependencies::reference(arg)
301 Getter.new(arg)
fbd35ec jack dempsey new cache api requires passing a key to get
jackdempsey authored
302 else
303 ActiveSupport::Dependencies.ref(arg)
304 end
30b35e3 José Valim Fix syntax error.
josevalim authored
305 end
306
27a83f3 José Valim Ensure Devise.available_router_name is never nil, closes #1648
josevalim authored
307 def self.available_router_name
308 router_name || :main_app
309 end
310
21d5e50 José Valim Basic omniauth support.
josevalim authored
311 def self.omniauth_providers
312 omniauth_configs.keys
313 end
314
a2f8485 José Valim Allow the mailer class to be configured.
josevalim authored
315 # Get the mailer class from the mailer reference object.
316 def self.mailer
0fbe4cb pechkin fix reference storage to support new and old class cache api
pechkin authored
317 @@mailer_ref.get
a2f8485 José Valim Allow the mailer class to be configured.
josevalim authored
318 end
319
320 # Set the mailer reference object to access the mailer.
321 def self.mailer=(class_name)
30b35e3 José Valim Fix syntax error.
josevalim authored
322 @@mailer_ref = ref(class_name)
a2f8485 José Valim Allow the mailer class to be configured.
josevalim authored
323 end
324 self.mailer = "Devise::Mailer"
325
ae6322e José Valim No longer retrieve the user from paths, but use the env hash. This chang...
josevalim authored
326 # Small method that adds a mapping to Devise.
327 def self.add_mapping(resource, options)
033db1c José Valim Do not depend on silence_missing_strategies! anymore. This speeds up str...
josevalim authored
328 mapping = Devise::Mapping.new(resource, options)
1a9db03 José Valim Do not rely on load time anymore. Instead, provide a helper that is call...
josevalim authored
329 @@mappings[mapping.name] = mapping
330 @@default_scope ||= mapping.name
ef841ca José Valim Start to add helpers for OAuth tests.
josevalim authored
331 @@helpers.each { |h| h.define_helpers(mapping) }
033db1c José Valim Do not depend on silence_missing_strategies! anymore. This speeds up str...
josevalim authored
332 mapping
333 end
334
bd8294a José Valim More OAuth setup.
josevalim authored
335 # Make Devise aware of an 3rd party Devise-module (like invitable). For convenience.
0386275 José Valim Keep modules definition in a different file.
josevalim authored
336 #
337 # == Options:
338 #
033db1c José Valim Do not depend on silence_missing_strategies! anymore. This speeds up str...
josevalim authored
339 # +model+ - String representing the load path to a custom *model* for this module (to autoload.)
340 # +controller+ - Symbol representing the name of an exisiting or custom *controller* for this module.
341 # +route+ - Symbol representing the named *route* helper for this module.
342 # +strategy+ - Symbol representing if this module got a custom *strategy*.
343 #
344 # All values, except :model, accept also a boolean and will have the same name as the given module
345 # name.
0386275 José Valim Keep modules definition in a different file.
josevalim authored
346 #
347 # == Examples:
348 #
349 # Devise.add_module(:party_module)
350 # Devise.add_module(:party_module, :strategy => true, :controller => :sessions)
033db1c José Valim Do not depend on silence_missing_strategies! anymore. This speeds up str...
josevalim authored
351 # Devise.add_module(:party_module, :model => 'party_module/model')
0386275 José Valim Keep modules definition in a different file.
josevalim authored
352 #
353 def self.add_module(module_name, options = {})
354 ALL << module_name
fd0e929 José Valim Generate session routes for token authentication, but mark it as no_inpu...
josevalim authored
355 options.assert_valid_keys(:strategy, :model, :controller, :route, :no_input)
033db1c José Valim Do not depend on silence_missing_strategies! anymore. This speeds up str...
josevalim authored
356
bd8294a José Valim More OAuth setup.
josevalim authored
357 if strategy = options[:strategy]
4fd866d José Valim User cannot access sign up and similar pages if he is already signed in ...
josevalim authored
358 strategy = (strategy == true ? module_name : strategy)
359 STRATEGIES[module_name] = strategy
bd8294a José Valim More OAuth setup.
josevalim authored
360 end
0386275 José Valim Keep modules definition in a different file.
josevalim authored
361
bd8294a José Valim More OAuth setup.
josevalim authored
362 if controller = options[:controller]
4fd866d José Valim User cannot access sign up and similar pages if he is already signed in ...
josevalim authored
363 controller = (controller == true ? module_name : controller)
364 CONTROLLERS[module_name] = controller
bd8294a José Valim More OAuth setup.
josevalim authored
365 end
1c6f18c José Valim Since Devise::FailureApp is now a metal, we can get rid of this default_...
josevalim authored
366
fd0e929 José Valim Generate session routes for token authentication, but mark it as no_inpu...
josevalim authored
367 NO_INPUT << strategy if options[:no_input]
4fd866d José Valim User cannot access sign up and similar pages if he is already signed in ...
josevalim authored
368
bd8294a José Valim More OAuth setup.
josevalim authored
369 if route = options[:route]
370 case route
371 when TrueClass
372 key, value = module_name, []
373 when Symbol
374 key, value = route, []
375 when Hash
376 key, value = route.keys.first, route.values.flatten
033db1c José Valim Do not depend on silence_missing_strategies! anymore. This speeds up str...
josevalim authored
377 else
bd8294a José Valim More OAuth setup.
josevalim authored
378 raise ArgumentError, ":route should be true, a Symbol or a Hash"
033db1c José Valim Do not depend on silence_missing_strategies! anymore. This speeds up str...
josevalim authored
379 end
bd8294a José Valim More OAuth setup.
josevalim authored
380
381 URL_HELPERS[key] ||= []
382 URL_HELPERS[key].concat(value)
383 URL_HELPERS[key].uniq!
384
385 ROUTES[module_name] = key
f0eb434 José Valim Deprecate Devise.orm. This allows you to use several ORMs with Devise an...
josevalim authored
386 end
387
0386275 José Valim Keep modules definition in a different file.
josevalim authored
388 if options[:model]
6c5be8d José Valim Initial routes and module setup.
josevalim authored
389 path = (options[:model] == true ? "devise/models/#{module_name}" : options[:model])
fa6c8ab José Valim Use inflector to avoid conflicts.
josevalim authored
390 camelized = ActiveSupport::Inflector.camelize(module_name.to_s)
391 Devise::Models.send(:autoload, camelized.to_sym, path)
371a9bb José Valim Major refactoring. Allow Warden::Manager to be configured through Devise...
josevalim authored
392 end
393
033db1c José Valim Do not depend on silence_missing_strategies! anymore. This speeds up str...
josevalim authored
394 Devise::Mapping.add_module module_name
0386275 José Valim Keep modules definition in a different file.
josevalim authored
395 end
371a9bb José Valim Major refactoring. Allow Warden::Manager to be configured through Devise...
josevalim authored
396
0386275 José Valim Keep modules definition in a different file.
josevalim authored
397 # Sets warden configuration using a block that will be invoked on warden
398 # initialization.
399 #
400 # Devise.initialize do |config|
930b324 José Valim Usage of confirm_within was deprecated in favor allow_unconfirmed_access...
josevalim authored
401 # config.allow_unconfirmed_access_for = 2.days
0386275 José Valim Keep modules definition in a different file.
josevalim authored
402 #
403 # config.warden do |manager|
404 # # Configure warden to use other strategies, like oauth.
405 # manager.oauth(:twitter)
406 # end
407 # end
408 def self.warden(&block)
033db1c José Valim Do not depend on silence_missing_strategies! anymore. This speeds up str...
josevalim authored
409 @@warden_config_block = block
0386275 José Valim Keep modules definition in a different file.
josevalim authored
410 end
512397b Cyril Mougel add capability to define other orm compatible with Devise. Add MongoMapp...
shingara authored
411
21d5e50 José Valim Basic omniauth support.
josevalim authored
412 # Specify an omniauth provider.
413 #
414 # config.omniauth :github, APP_ID, APP_SECRET
415 #
416 def self.omniauth(provider, *args)
417 @@helpers << Devise::OmniAuth::UrlHelpers
58f8c7c Sergey Kojin support for named omniauth open_id strategies
skojin authored
418 config = Devise::OmniAuth::Config.new(provider, args)
419 @@omniauth_configs[config.strategy_name.to_sym] = config
21d5e50 José Valim Basic omniauth support.
josevalim authored
420 end
421
8bf6a66 José Valim Make Devise::Oauth follow the same conventions as Devise::controllers.
josevalim authored
422 # Include helpers in the given scope to AC and AV.
423 def self.include_helpers(scope)
424 ActiveSupport.on_load(:action_controller) do
21d5e50 José Valim Basic omniauth support.
josevalim authored
425 include scope::Helpers if defined?(scope::Helpers)
fac02b5 José Valim Another attempt to fix the misterious loading helpers bug.
josevalim authored
426 include scope::UrlHelpers
427 end
428
429 ActiveSupport.on_load(:action_view) do
430 include scope::UrlHelpers
8bf6a66 José Valim Make Devise::Oauth follow the same conventions as Devise::controllers.
josevalim authored
431 end
432 end
433
c95ca15 José Valim Edited lib/devise.rb via GitHub
josevalim authored
434 # Regenerates url helpers considering Devise.mapping
f21d05a José Valim Only generate helpers for the used mappings, closes #1288
josevalim authored
435 def self.regenerate_helpers!
436 Devise::Controllers::UrlHelpers.remove_helpers!
437 Devise::Controllers::UrlHelpers.generate_helpers!
438 end
439
0386275 José Valim Keep modules definition in a different file.
josevalim authored
440 # A method used internally to setup warden manager from the Rails initialize
441 # block.
3d1a04f José Valim Fix warden configuration.
josevalim authored
442 def self.configure_warden! #:nodoc:
e905762 José Valim Clean up the whole loading mess and closes #247. This commit depends on ...
josevalim authored
443 @@warden_configured ||= begin
4629bee José Valim Cache failure_app action builder and pipe call through delegator.
josevalim authored
444 warden_config.failure_app = Devise::Delegator.new
e905762 José Valim Clean up the whole loading mess and closes #247. This commit depends on ...
josevalim authored
445 warden_config.default_scope = Devise.default_scope
c7efb68 José Valim Devise does not intercept 401 returned from applications anymore
josevalim authored
446 warden_config.intercept_401 = false
4da63c5 José Valim Ensure routes are loaded before application classes are eager loaded, cl...
josevalim authored
447
e905762 José Valim Clean up the whole loading mess and closes #247. This commit depends on ...
josevalim authored
448 Devise.mappings.each_value do |mapping|
449 warden_config.scope_defaults mapping.name, :strategies => mapping.strategies
450 end
4da63c5 José Valim Ensure routes are loaded before application classes are eager loaded, cl...
josevalim authored
451
e905762 José Valim Clean up the whole loading mess and closes #247. This commit depends on ...
josevalim authored
452 @@warden_config_block.try :call, Devise.warden_config
453 true
4da63c5 José Valim Ensure routes are loaded before application classes are eager loaded, cl...
josevalim authored
454 end
371a9bb José Valim Major refactoring. Allow Warden::Manager to be configured through Devise...
josevalim authored
455 end
a7e25f1 José Valim Detail loading process.
josevalim authored
456
0386275 José Valim Keep modules definition in a different file.
josevalim authored
457 # Generate a friendly string randomically to be used as token.
458 def self.friendly_token
6d65c28 remove hard-to-distinguish characters from friendly_token
David Turner authored
459 SecureRandom.base64(15).tr('+/=lIO0', 'pqrsxyz')
0386275 José Valim Keep modules definition in a different file.
josevalim authored
460 end
dd721f1 José Valim Use secure compare as well.
josevalim authored
461
462 # constant-time comparison algorithm to prevent timing attacks
463 def self.secure_compare(a, b)
e4cae20 Guilherme Silveira simplifying comparisons (avoind too much negatives) and adding unit test...
guilhermesilveira authored
464 return false if a.blank? || b.blank? || a.bytesize != b.bytesize
dd721f1 José Valim Use secure compare as well.
josevalim authored
465 l = a.unpack "C#{a.bytesize}"
466
467 res = 0
468 b.each_byte { |byte| res |= byte ^ l.shift }
469 res == 0
470 end
7ffd090 José Valim Rely on Warden new serializers.
josevalim authored
471 end
472
0386275 José Valim Keep modules definition in a different file.
josevalim authored
473 require 'warden'
345bf15 José Valim Add latest commities entries to CHANGELOG.
josevalim authored
474 require 'devise/mapping'
0386275 José Valim Keep modules definition in a different file.
josevalim authored
475 require 'devise/models'
476 require 'devise/modules'
6b837cb Carlos Antonio da Silva Introducing Registerable module, allowing users to sign up.
carlosantoniodasilva authored
477 require 'devise/rails'
Something went wrong with that request. Please try again.