devbootsrap 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b546c5b0fed21e4497c59ec6ba484e41313be864
4
- data.tar.gz: 6663447f3c73507cfd8f50be12774815643d70f9
3
+ metadata.gz: 6e6a5308a0dee71b837fea06b36fb1d214eeefc0
4
+ data.tar.gz: 48504b0fdae32bf92abd8be87f8ef9b7d24bc1f1
5
5
  SHA512:
6
- metadata.gz: 3692340299e3150b36ad516cf85ea9f502ce16993fdd4739bdc7197d92ee63a4f2cc2ddbcc2eda654b03e150f86eac40e828b45dbf3a5b525d436694b59f863d
7
- data.tar.gz: 33f34a407a96e3a0302d9d33a98f0ad44243e5d99c83fdf3cde22d4410440a5b9f7a88d4c7f6c6e7ad43fe4288174c46e2479cfbe5a0d2745158900a23cba51a
6
+ metadata.gz: 18452c35d3054798003a2d59a2cd73b17cd4de0a733d9fc727527ad4812c2931c0abd5f4910ec56ae3db5f304a808165dc63c6425844b66391105f18bc066533
7
+ data.tar.gz: 4402ad8ae31979d145e042f574941769d983f663a366e2c7d57131dcc8bef27dabb4edca812d2fa5a0a0b3b55d2bbd49e7c9cc7ebf64ac353c05f36eb37fd48f
@@ -1,3 +1,3 @@
1
1
  module Devbootsrap
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/devbootsrap.rb CHANGED
@@ -1,5 +1,499 @@
1
1
  require "devbootsrap/version"
2
2
 
3
- module Devbootsrap
4
- # Your code goes here...
3
+ # module Devbootsrap
4
+ # # Your code goes here...
5
+ # end
6
+
7
+
8
+ require 'rails'
9
+ require 'active_support/core_ext/numeric/time'
10
+ require 'active_support/dependencies'
11
+ require 'orm_adapter'
12
+ require 'set'
13
+ require 'securerandom'
14
+
15
+ module Devise
16
+ autoload :Delegator, 'devise/delegator'
17
+ autoload :FailureApp, 'devise/failure_app'
18
+ autoload :OmniAuth, 'devise/omniauth'
19
+ autoload :ParameterFilter, 'devise/parameter_filter'
20
+ autoload :BaseSanitizer, 'devise/parameter_sanitizer'
21
+ autoload :ParameterSanitizer, 'devise/parameter_sanitizer'
22
+ autoload :TestHelpers, 'devise/test_helpers'
23
+ autoload :TimeInflector, 'devise/time_inflector'
24
+ autoload :TokenGenerator, 'devise/token_generator'
25
+
26
+ module Controllers
27
+ autoload :Helpers, 'devise/controllers/helpers'
28
+ autoload :Rememberable, 'devise/controllers/rememberable'
29
+ autoload :ScopedViews, 'devise/controllers/scoped_views'
30
+ autoload :SignInOut, 'devise/controllers/sign_in_out'
31
+ autoload :StoreLocation, 'devise/controllers/store_location'
32
+ autoload :UrlHelpers, 'devise/controllers/url_helpers'
33
+ end
34
+
35
+ module Hooks
36
+ autoload :Proxy, 'devise/hooks/proxy'
37
+ end
38
+
39
+ module Mailers
40
+ autoload :Helpers, 'devise/mailers/helpers'
41
+ end
42
+
43
+ module Strategies
44
+ autoload :Base, 'devise/strategies/base'
45
+ autoload :Authenticatable, 'devise/strategies/authenticatable'
46
+ end
47
+
48
+ # Constants which holds devise configuration for extensions. Those should
49
+ # not be modified by the "end user" (this is why they are constants).
50
+ ALL = []
51
+ CONTROLLERS = ActiveSupport::OrderedHash.new
52
+ ROUTES = ActiveSupport::OrderedHash.new
53
+ STRATEGIES = ActiveSupport::OrderedHash.new
54
+ URL_HELPERS = ActiveSupport::OrderedHash.new
55
+
56
+ # Strategies that do not require user input.
57
+ NO_INPUT = []
58
+
59
+ # True values used to check params
60
+ TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE']
61
+
62
+ # Secret key used by the key generator
63
+ mattr_accessor :secret_key
64
+ @@secret_key = nil
65
+
66
+ [ :allow_insecure_token_lookup,
67
+ :allow_insecure_sign_in_after_confirmation,
68
+ :token_authentication_key ].each do |method|
69
+ class_eval <<-RUBY
70
+ def self.#{method}
71
+ ActiveSupport::Deprecation.warn "Devise.#{method} is deprecated " \
72
+ "and has no effect"
73
+ end
74
+
75
+ def self.#{method}=(val)
76
+ ActiveSupport::Deprecation.warn "Devise.#{method}= is deprecated " \
77
+ "and has no effect"
78
+ end
79
+ RUBY
80
+ end
81
+
82
+ # Custom domain or key for cookies. Not set by default
83
+ mattr_accessor :rememberable_options
84
+ @@rememberable_options = {}
85
+
86
+ # The number of times to encrypt password.
87
+ mattr_accessor :stretches
88
+ @@stretches = 10
89
+
90
+ # The default key used when authenticating over http auth.
91
+ mattr_accessor :http_authentication_key
92
+ @@http_authentication_key = nil
93
+
94
+ # Keys used when authenticating a user.
95
+ mattr_accessor :authentication_keys
96
+ @@authentication_keys = [ :email ]
97
+
98
+ # Request keys used when authenticating a user.
99
+ mattr_accessor :request_keys
100
+ @@request_keys = []
101
+
102
+ # Keys that should be case-insensitive.
103
+ mattr_accessor :case_insensitive_keys
104
+ @@case_insensitive_keys = [ :email ]
105
+
106
+ # Keys that should have whitespace stripped.
107
+ mattr_accessor :strip_whitespace_keys
108
+ @@strip_whitespace_keys = []
109
+
110
+ # If http authentication is enabled by default.
111
+ mattr_accessor :http_authenticatable
112
+ @@http_authenticatable = false
113
+
114
+ # If http headers should be returned for ajax requests. True by default.
115
+ mattr_accessor :http_authenticatable_on_xhr
116
+ @@http_authenticatable_on_xhr = true
117
+
118
+ # If params authenticatable is enabled by default.
119
+ mattr_accessor :params_authenticatable
120
+ @@params_authenticatable = true
121
+
122
+ # The realm used in Http Basic Authentication.
123
+ mattr_accessor :http_authentication_realm
124
+ @@http_authentication_realm = "Application"
125
+
126
+ # Email regex used to validate email formats. It simply asserts that
127
+ # an one (and only one) @ exists in the given string. This is mainly
128
+ # to give user feedback and not to assert the e-mail validity.
129
+ mattr_accessor :email_regexp
130
+ @@email_regexp = /\A[^@\s]+@([^@\s]+\.)+[^@\s]+\z/
131
+
132
+ # Range validation for password length
133
+ mattr_accessor :password_length
134
+ @@password_length = 6..128
135
+
136
+ # The time the user will be remembered without asking for credentials again.
137
+ mattr_accessor :remember_for
138
+ @@remember_for = 2.weeks
139
+
140
+ # If true, extends the user's remember period when remembered via cookie.
141
+ mattr_accessor :extend_remember_period
142
+ @@extend_remember_period = false
143
+
144
+ # Time interval you can access your account before confirming your account.
145
+ # nil - allows unconfirmed access for unlimited time
146
+ mattr_accessor :allow_unconfirmed_access_for
147
+ @@allow_unconfirmed_access_for = 0.days
148
+
149
+ # Time interval the confirmation token is valid. nil = unlimited
150
+ mattr_accessor :confirm_within
151
+ @@confirm_within = nil
152
+
153
+ # Defines which key will be used when confirming an account.
154
+ mattr_accessor :confirmation_keys
155
+ @@confirmation_keys = [ :email ]
156
+
157
+ # Defines if email should be reconfirmable.
158
+ # False by default for backwards compatibility.
159
+ mattr_accessor :reconfirmable
160
+ @@reconfirmable = false
161
+
162
+ # Time interval to timeout the user session without activity.
163
+ mattr_accessor :timeout_in
164
+ @@timeout_in = 30.minutes
165
+
166
+ # Authentication token expiration on timeout
167
+ mattr_accessor :expire_auth_token_on_timeout
168
+ @@expire_auth_token_on_timeout = false
169
+
170
+ # Used to encrypt password. Please generate one with rake secret.
171
+ mattr_accessor :pepper
172
+ @@pepper = nil
173
+
174
+ # Scoped views. Since it relies on fallbacks to render default views, it's
175
+ # turned off by default.
176
+ mattr_accessor :scoped_views
177
+ @@scoped_views = false
178
+
179
+ # Defines which strategy can be used to lock an account.
180
+ # Values: :failed_attempts, :none
181
+ mattr_accessor :lock_strategy
182
+ @@lock_strategy = :failed_attempts
183
+
184
+ # Defines which key will be used when locking and unlocking an account
185
+ mattr_accessor :unlock_keys
186
+ @@unlock_keys = [ :email ]
187
+
188
+ # Defines which strategy can be used to unlock an account.
189
+ # Values: :email, :time, :both
190
+ mattr_accessor :unlock_strategy
191
+ @@unlock_strategy = :both
192
+
193
+ # Number of authentication tries before locking an account
194
+ mattr_accessor :maximum_attempts
195
+ @@maximum_attempts = 20
196
+
197
+ # Time interval to unlock the account if :time is defined as unlock_strategy.
198
+ mattr_accessor :unlock_in
199
+ @@unlock_in = 1.hour
200
+
201
+ # Defines which key will be used when recovering the password for an account
202
+ mattr_accessor :reset_password_keys
203
+ @@reset_password_keys = [ :email ]
204
+
205
+ # Time interval you can reset your password with a reset password key
206
+ mattr_accessor :reset_password_within
207
+ @@reset_password_within = 6.hours
208
+
209
+ # The default scope which is used by warden.
210
+ mattr_accessor :default_scope
211
+ @@default_scope = nil
212
+
213
+ # Address which sends Devise e-mails.
214
+ mattr_accessor :mailer_sender
215
+ @@mailer_sender = nil
216
+
217
+ # Skip session storage for the following strategies
218
+ mattr_accessor :skip_session_storage
219
+ @@skip_session_storage = []
220
+
221
+ # Which formats should be treated as navigational.
222
+ mattr_accessor :navigational_formats
223
+ @@navigational_formats = ["*/*", :html]
224
+
225
+ # When set to true, signing out a user signs out all other scopes.
226
+ mattr_accessor :sign_out_all_scopes
227
+ @@sign_out_all_scopes = true
228
+
229
+ # The default method used while signing out
230
+ mattr_accessor :sign_out_via
231
+ @@sign_out_via = :get
232
+
233
+ # The parent controller all Devise controllers inherits from.
234
+ # Defaults to ApplicationController. This should be set early
235
+ # in the initialization process and should be set to a string.
236
+ mattr_accessor :parent_controller
237
+ @@parent_controller = "ApplicationController"
238
+
239
+ # The parent mailer all Devise mailers inherit from.
240
+ # Defaults to ActionMailer::Base. This should be set early
241
+ # in the initialization process and should be set to a string.
242
+ mattr_accessor :parent_mailer
243
+ @@parent_mailer = "ActionMailer::Base"
244
+
245
+ # The router Devise should use to generate routes. Defaults
246
+ # to :main_app. Should be overridden by engines in order
247
+ # to provide custom routes.
248
+ mattr_accessor :router_name
249
+ @@router_name = nil
250
+
251
+ # Set the omniauth path prefix so it can be overridden when
252
+ # Devise is used in a mountable engine
253
+ mattr_accessor :omniauth_path_prefix
254
+ @@omniauth_path_prefix = nil
255
+
256
+ # Set if we should clean up the CSRF Token on authentication
257
+ mattr_accessor :clean_up_csrf_token_on_authentication
258
+ @@clean_up_csrf_token_on_authentication = true
259
+
260
+ # PRIVATE CONFIGURATION
261
+
262
+ # Store scopes mappings.
263
+ mattr_reader :mappings
264
+ @@mappings = ActiveSupport::OrderedHash.new
265
+
266
+ # Omniauth configurations.
267
+ mattr_reader :omniauth_configs
268
+ @@omniauth_configs = ActiveSupport::OrderedHash.new
269
+
270
+ # Define a set of modules that are called when a mapping is added.
271
+ mattr_reader :helpers
272
+ @@helpers = Set.new
273
+ @@helpers << Devise::Controllers::Helpers
274
+
275
+ # Private methods to interface with Warden.
276
+ mattr_accessor :warden_config
277
+ @@warden_config = nil
278
+ @@warden_config_block = nil
279
+
280
+ # When true, enter in paranoid mode to avoid user enumeration.
281
+ mattr_accessor :paranoid
282
+ @@paranoid = false
283
+
284
+ # When true, warn user if they just used next-to-last attempt of authentication
285
+ mattr_accessor :last_attempt_warning
286
+ @@last_attempt_warning = false
287
+
288
+ # Stores the token generator
289
+ mattr_accessor :token_generator
290
+ @@token_generator = nil
291
+
292
+ # Default way to setup Devise. Run rails generate devise_install to create
293
+ # a fresh initializer with all configuration values.
294
+ def self.setup
295
+ yield self
296
+ end
297
+
298
+ class Getter
299
+ def initialize name
300
+ @name = name
301
+ end
302
+
303
+ def get
304
+ ActiveSupport::Dependencies.constantize(@name)
305
+ end
306
+ end
307
+
308
+ def self.ref(arg)
309
+ if defined?(ActiveSupport::Dependencies::ClassCache)
310
+ ActiveSupport::Dependencies::reference(arg)
311
+ Getter.new(arg)
312
+ else
313
+ ActiveSupport::Dependencies.ref(arg)
314
+ end
315
+ end
316
+
317
+ def self.available_router_name
318
+ router_name || :main_app
319
+ end
320
+
321
+ def self.omniauth_providers
322
+ omniauth_configs.keys
323
+ end
324
+
325
+ # Get the mailer class from the mailer reference object.
326
+ def self.mailer
327
+ @@mailer_ref.get
328
+ end
329
+
330
+ # Set the mailer reference object to access the mailer.
331
+ def self.mailer=(class_name)
332
+ @@mailer_ref = ref(class_name)
333
+ end
334
+ self.mailer = "Devise::Mailer"
335
+
336
+ # Small method that adds a mapping to Devise.
337
+ def self.add_mapping(resource, options)
338
+ mapping = Devise::Mapping.new(resource, options)
339
+ @@mappings[mapping.name] = mapping
340
+ @@default_scope ||= mapping.name
341
+ @@helpers.each { |h| h.define_helpers(mapping) }
342
+ mapping
343
+ end
344
+
345
+ # Make Devise aware of an 3rd party Devise-module (like invitable). For convenience.
346
+ #
347
+ # == Options:
348
+ #
349
+ # +model+ - String representing the load path to a custom *model* for this module (to autoload.)
350
+ # +controller+ - Symbol representing the name of an existing or custom *controller* for this module.
351
+ # +route+ - Symbol representing the named *route* helper for this module.
352
+ # +strategy+ - Symbol representing if this module got a custom *strategy*.
353
+ #
354
+ # All values, except :model, accept also a boolean and will have the same name as the given module
355
+ # name.
356
+ #
357
+ # == Examples:
358
+ #
359
+ # Devise.add_module(:party_module)
360
+ # Devise.add_module(:party_module, strategy: true, controller: :sessions)
361
+ # Devise.add_module(:party_module, model: 'party_module/model')
362
+ #
363
+ def self.add_module(module_name, options = {})
364
+ ALL << module_name
365
+ options.assert_valid_keys(:strategy, :model, :controller, :route, :no_input)
366
+
367
+ if strategy = options[:strategy]
368
+ strategy = (strategy == true ? module_name : strategy)
369
+ STRATEGIES[module_name] = strategy
370
+ end
371
+
372
+ if controller = options[:controller]
373
+ controller = (controller == true ? module_name : controller)
374
+ CONTROLLERS[module_name] = controller
375
+ end
376
+
377
+ NO_INPUT << strategy if options[:no_input]
378
+
379
+ if route = options[:route]
380
+ case route
381
+ when TrueClass
382
+ key, value = module_name, []
383
+ when Symbol
384
+ key, value = route, []
385
+ when Hash
386
+ key, value = route.keys.first, route.values.flatten
387
+ else
388
+ raise ArgumentError, ":route should be true, a Symbol or a Hash"
389
+ end
390
+
391
+ URL_HELPERS[key] ||= []
392
+ URL_HELPERS[key].concat(value)
393
+ URL_HELPERS[key].uniq!
394
+
395
+ ROUTES[module_name] = key
396
+ end
397
+
398
+ if options[:model]
399
+ path = (options[:model] == true ? "devise/models/#{module_name}" : options[:model])
400
+ camelized = ActiveSupport::Inflector.camelize(module_name.to_s)
401
+ Devise::Models.send(:autoload, camelized.to_sym, path)
402
+ end
403
+
404
+ Devise::Mapping.add_module module_name
405
+ end
406
+
407
+ # Sets warden configuration using a block that will be invoked on warden
408
+ # initialization.
409
+ #
410
+ # Devise.initialize do |config|
411
+ # config.allow_unconfirmed_access_for = 2.days
412
+ #
413
+ # config.warden do |manager|
414
+ # # Configure warden to use other strategies, like oauth.
415
+ # manager.oauth(:twitter)
416
+ # end
417
+ # end
418
+ def self.warden(&block)
419
+ @@warden_config_block = block
420
+ end
421
+
422
+ # Specify an omniauth provider.
423
+ #
424
+ # config.omniauth :github, APP_ID, APP_SECRET
425
+ #
426
+ def self.omniauth(provider, *args)
427
+ @@helpers << Devise::OmniAuth::UrlHelpers
428
+ config = Devise::OmniAuth::Config.new(provider, args)
429
+ @@omniauth_configs[config.strategy_name.to_sym] = config
430
+ end
431
+
432
+ # Include helpers in the given scope to AC and AV.
433
+ def self.include_helpers(scope)
434
+ ActiveSupport.on_load(:action_controller) do
435
+ include scope::Helpers if defined?(scope::Helpers)
436
+ include scope::UrlHelpers
437
+ end
438
+
439
+ ActiveSupport.on_load(:action_view) do
440
+ include scope::UrlHelpers
441
+ end
442
+ end
443
+
444
+ # Regenerates url helpers considering Devise.mapping
445
+ def self.regenerate_helpers!
446
+ Devise::Controllers::UrlHelpers.remove_helpers!
447
+ Devise::Controllers::UrlHelpers.generate_helpers!
448
+ end
449
+
450
+ # A method used internally to setup warden manager from the Rails initialize
451
+ # block.
452
+ def self.configure_warden! #:nodoc:
453
+ @@warden_configured ||= begin
454
+ warden_config.failure_app = Devise::Delegator.new
455
+ warden_config.default_scope = Devise.default_scope
456
+ warden_config.intercept_401 = false
457
+
458
+ Devise.mappings.each_value do |mapping|
459
+ warden_config.scope_defaults mapping.name, strategies: mapping.strategies
460
+
461
+ warden_config.serialize_into_session(mapping.name) do |record|
462
+ mapping.to.serialize_into_session(record)
463
+ end
464
+
465
+ warden_config.serialize_from_session(mapping.name) do |key|
466
+ # Previous versions contained an additional entry at the beginning of
467
+ # key with the record's class name.
468
+ args = key[-2, 2]
469
+ mapping.to.serialize_from_session(*args)
470
+ end
471
+ end
472
+
473
+ @@warden_config_block.try :call, Devise.warden_config
474
+ true
475
+ end
476
+ end
477
+
478
+ # Generate a friendly string randomly to be used as token.
479
+ def self.friendly_token
480
+ SecureRandom.urlsafe_base64(15).tr('lIO0', 'sxyz')
481
+ end
482
+
483
+ # constant-time comparison algorithm to prevent timing attacks
484
+ def self.secure_compare(a, b)
485
+ return false if a.blank? || b.blank? || a.bytesize != b.bytesize
486
+ l = a.unpack "C#{a.bytesize}"
487
+
488
+ res = 0
489
+ b.each_byte { |byte| res |= byte ^ l.shift }
490
+ res == 0
491
+ end
5
492
  end
493
+
494
+ require 'warden'
495
+ require 'devise/mapping'
496
+ require 'devise/models'
497
+ require 'devise/modules'
498
+ require 'devise/rails'
499
+
@@ -1,3 +1,3 @@
1
- module Devise
2
- VERSION = "3.2.4".freeze
3
- end
1
+ # module Devise
2
+ # VERSION = "3.2.4".freeze
3
+ # end