deviseOne 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.travis.yml +38 -0
- data/.yardopts +9 -0
- data/CHANGELOG.md +1117 -0
- data/CONTRIBUTING.md +14 -0
- data/Gemfile +29 -0
- data/Gemfile.lock +199 -0
- data/MIT-LICENSE +20 -0
- data/README.md +529 -0
- data/Rakefile +35 -0
- data/app/controllers/devise/confirmations_controller.rb +47 -0
- data/app/controllers/devise/omniauth_callbacks_controller.rb +30 -0
- data/app/controllers/devise/passwords_controller.rb +71 -0
- data/app/controllers/devise/registrations_controller.rb +143 -0
- data/app/controllers/devise/sessions_controller.rb +166 -0
- data/app/controllers/devise/unlocks_controller.rb +46 -0
- data/app/controllers/devise_controller.rb +193 -0
- data/app/helpers/devise_helper.rb +25 -0
- data/app/mailers/devise/mailer.rb +20 -0
- data/app/views/devise/confirmations/new.html.erb +16 -0
- data/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
- data/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
- data/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
- data/app/views/devise/passwords/edit.html.erb +25 -0
- data/app/views/devise/passwords/new.html.erb +16 -0
- data/app/views/devise/registrations/edit.html.erb +39 -0
- data/app/views/devise/registrations/new.html.erb +29 -0
- data/app/views/devise/sessions/new.html.erb +27 -0
- data/app/views/devise/shared/_links.html.erb +21 -0
- data/app/views/devise/unlocks/new.html.erb +16 -0
- data/config/locales/en.yml +70 -0
- data/devise.gemspec +33 -0
- data/devise.png +0 -0
- data/gemfiles/Gemfile.rails-3.2-stable +29 -0
- data/gemfiles/Gemfile.rails-3.2-stable.lock +169 -0
- data/gemfiles/Gemfile.rails-4.0-stable +29 -0
- data/gemfiles/Gemfile.rails-4.0-stable.lock +165 -0
- data/gemfiles/Gemfile.rails-4.1-stable +29 -0
- data/gemfiles/Gemfile.rails-4.1-stable.lock +170 -0
- data/lib/devise.rb +499 -0
- data/lib/devise/controllers/helpers.rb +284 -0
- data/lib/devise/controllers/rememberable.rb +47 -0
- data/lib/devise/controllers/scoped_views.rb +17 -0
- data/lib/devise/controllers/sign_in_out.rb +102 -0
- data/lib/devise/controllers/store_location.rb +58 -0
- data/lib/devise/controllers/url_helpers.rb +69 -0
- data/lib/devise/delegator.rb +16 -0
- data/lib/devise/failure_app.rb +212 -0
- data/lib/devise/hooks/activatable.rb +10 -0
- data/lib/devise/hooks/csrf_cleaner.rb +7 -0
- data/lib/devise/hooks/forgetable.rb +9 -0
- data/lib/devise/hooks/lockable.rb +7 -0
- data/lib/devise/hooks/proxy.rb +21 -0
- data/lib/devise/hooks/rememberable.rb +7 -0
- data/lib/devise/hooks/timeoutable.rb +35 -0
- data/lib/devise/hooks/trackable.rb +9 -0
- data/lib/devise/mailers/helpers.rb +90 -0
- data/lib/devise/mapping.rb +175 -0
- data/lib/devise/models.rb +119 -0
- data/lib/devise/models/authenticatable.rb +290 -0
- data/lib/devise/models/confirmable.rb +305 -0
- data/lib/devise/models/database_authenticatable.rb +164 -0
- data/lib/devise/models/lockable.rb +196 -0
- data/lib/devise/models/omniauthable.rb +27 -0
- data/lib/devise/models/recoverable.rb +157 -0
- data/lib/devise/models/registerable.rb +25 -0
- data/lib/devise/models/rememberable.rb +142 -0
- data/lib/devise/models/timeoutable.rb +49 -0
- data/lib/devise/models/trackable.rb +38 -0
- data/lib/devise/models/validatable.rb +66 -0
- data/lib/devise/modules.rb +28 -0
- data/lib/devise/omniauth.rb +28 -0
- data/lib/devise/omniauth/config.rb +45 -0
- data/lib/devise/omniauth/url_helpers.rb +18 -0
- data/lib/devise/orm/active_record.rb +3 -0
- data/lib/devise/orm/mongoid.rb +3 -0
- data/lib/devise/parameter_filter.rb +40 -0
- data/lib/devise/parameter_sanitizer.rb +99 -0
- data/lib/devise/rails.rb +56 -0
- data/lib/devise/rails/routes.rb +495 -0
- data/lib/devise/rails/warden_compat.rb +22 -0
- data/lib/devise/strategies/authenticatable.rb +173 -0
- data/lib/devise/strategies/base.rb +20 -0
- data/lib/devise/strategies/database_authenticatable.rb +24 -0
- data/lib/devise/strategies/rememberable.rb +59 -0
- data/lib/devise/test_helpers.rb +132 -0
- data/lib/devise/time_inflector.rb +14 -0
- data/lib/devise/token_generator.rb +70 -0
- data/lib/devise/version.rb +3 -0
- data/lib/generators/active_record/devise_generator.rb +91 -0
- data/lib/generators/active_record/templates/migration.rb +18 -0
- data/lib/generators/active_record/templates/migration_existing.rb +25 -0
- data/lib/generators/devise/controllers_generator.rb +44 -0
- data/lib/generators/devise/devise_generator.rb +26 -0
- data/lib/generators/devise/install_generator.rb +29 -0
- data/lib/generators/devise/orm_helpers.rb +51 -0
- data/lib/generators/devise/views_generator.rb +135 -0
- data/lib/generators/mongoid/devise_generator.rb +55 -0
- data/lib/generators/templates/README +35 -0
- data/lib/generators/templates/controllers/README +14 -0
- data/lib/generators/templates/controllers/confirmations_controller.rb +28 -0
- data/lib/generators/templates/controllers/omniauth_callbacks_controller.rb +28 -0
- data/lib/generators/templates/controllers/passwords_controller.rb +32 -0
- data/lib/generators/templates/controllers/registrations_controller.rb +60 -0
- data/lib/generators/templates/controllers/sessions_controller.rb +25 -0
- data/lib/generators/templates/controllers/unlocks_controller.rb +28 -0
- data/lib/generators/templates/devise.rb +263 -0
- data/lib/generators/templates/markerb/confirmation_instructions.markerb +5 -0
- data/lib/generators/templates/markerb/reset_password_instructions.markerb +8 -0
- data/lib/generators/templates/markerb/unlock_instructions.markerb +7 -0
- data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +16 -0
- data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +19 -0
- data/lib/generators/templates/simple_form_for/passwords/new.html.erb +15 -0
- data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +27 -0
- data/lib/generators/templates/simple_form_for/registrations/new.html.erb +17 -0
- data/lib/generators/templates/simple_form_for/sessions/new.html.erb +15 -0
- data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +16 -0
- data/script/cached-bundle +49 -0
- data/script/s3-put +71 -0
- data/test/controllers/custom_registrations_controller_test.rb +35 -0
- data/test/controllers/custom_strategy_test.rb +62 -0
- data/test/controllers/helpers_test.rb +316 -0
- data/test/controllers/internal_helpers_test.rb +129 -0
- data/test/controllers/load_hooks_controller_test.rb +19 -0
- data/test/controllers/passwords_controller_test.rb +31 -0
- data/test/controllers/sessions_controller_test.rb +102 -0
- data/test/controllers/url_helpers_test.rb +65 -0
- data/test/delegator_test.rb +19 -0
- data/test/devise_test.rb +107 -0
- data/test/failure_app_test.rb +275 -0
- data/test/generators/active_record_generator_test.rb +109 -0
- data/test/generators/controllers_generator_test.rb +48 -0
- data/test/generators/devise_generator_test.rb +39 -0
- data/test/generators/install_generator_test.rb +13 -0
- data/test/generators/mongoid_generator_test.rb +23 -0
- data/test/generators/views_generator_test.rb +96 -0
- data/test/helpers/devise_helper_test.rb +49 -0
- data/test/integration/authenticatable_test.rb +731 -0
- data/test/integration/confirmable_test.rb +324 -0
- data/test/integration/database_authenticatable_test.rb +94 -0
- data/test/integration/http_authenticatable_test.rb +105 -0
- data/test/integration/lockable_test.rb +239 -0
- data/test/integration/omniauthable_test.rb +133 -0
- data/test/integration/recoverable_test.rb +334 -0
- data/test/integration/registerable_test.rb +361 -0
- data/test/integration/rememberable_test.rb +176 -0
- data/test/integration/timeoutable_test.rb +189 -0
- data/test/integration/trackable_test.rb +92 -0
- data/test/mailers/confirmation_instructions_test.rb +115 -0
- data/test/mailers/reset_password_instructions_test.rb +96 -0
- data/test/mailers/unlock_instructions_test.rb +91 -0
- data/test/mapping_test.rb +128 -0
- data/test/models/authenticatable_test.rb +23 -0
- data/test/models/confirmable_test.rb +461 -0
- data/test/models/database_authenticatable_test.rb +249 -0
- data/test/models/lockable_test.rb +328 -0
- data/test/models/omniauthable_test.rb +7 -0
- data/test/models/recoverable_test.rb +205 -0
- data/test/models/registerable_test.rb +7 -0
- data/test/models/rememberable_test.rb +198 -0
- data/test/models/serializable_test.rb +49 -0
- data/test/models/timeoutable_test.rb +51 -0
- data/test/models/trackable_test.rb +41 -0
- data/test/models/validatable_test.rb +127 -0
- data/test/models_test.rb +144 -0
- data/test/omniauth/config_test.rb +57 -0
- data/test/omniauth/url_helpers_test.rb +54 -0
- data/test/orm/active_record.rb +10 -0
- data/test/orm/mongoid.rb +13 -0
- data/test/parameter_sanitizer_test.rb +81 -0
- data/test/rails_app/Rakefile +6 -0
- data/test/rails_app/app/active_record/admin.rb +6 -0
- data/test/rails_app/app/active_record/shim.rb +2 -0
- data/test/rails_app/app/active_record/user.rb +6 -0
- data/test/rails_app/app/active_record/user_on_engine.rb +7 -0
- data/test/rails_app/app/active_record/user_on_main_app.rb +7 -0
- data/test/rails_app/app/controllers/admins/sessions_controller.rb +6 -0
- data/test/rails_app/app/controllers/admins_controller.rb +11 -0
- data/test/rails_app/app/controllers/application_controller.rb +12 -0
- data/test/rails_app/app/controllers/application_with_fake_engine.rb +30 -0
- data/test/rails_app/app/controllers/custom/registrations_controller.rb +21 -0
- data/test/rails_app/app/controllers/home_controller.rb +25 -0
- data/test/rails_app/app/controllers/publisher/registrations_controller.rb +2 -0
- data/test/rails_app/app/controllers/publisher/sessions_controller.rb +2 -0
- data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +14 -0
- data/test/rails_app/app/controllers/users_controller.rb +31 -0
- data/test/rails_app/app/helpers/application_helper.rb +3 -0
- data/test/rails_app/app/mailers/users/from_proc_mailer.rb +3 -0
- data/test/rails_app/app/mailers/users/mailer.rb +3 -0
- data/test/rails_app/app/mailers/users/reply_to_mailer.rb +4 -0
- data/test/rails_app/app/mongoid/admin.rb +29 -0
- data/test/rails_app/app/mongoid/shim.rb +23 -0
- data/test/rails_app/app/mongoid/user.rb +39 -0
- data/test/rails_app/app/mongoid/user_on_engine.rb +39 -0
- data/test/rails_app/app/mongoid/user_on_main_app.rb +39 -0
- data/test/rails_app/app/views/admins/index.html.erb +1 -0
- data/test/rails_app/app/views/admins/sessions/new.html.erb +2 -0
- data/test/rails_app/app/views/home/admin_dashboard.html.erb +1 -0
- data/test/rails_app/app/views/home/index.html.erb +1 -0
- data/test/rails_app/app/views/home/join.html.erb +1 -0
- data/test/rails_app/app/views/home/private.html.erb +1 -0
- data/test/rails_app/app/views/home/user_dashboard.html.erb +1 -0
- data/test/rails_app/app/views/layouts/application.html.erb +24 -0
- data/test/rails_app/app/views/users/edit_form.html.erb +1 -0
- data/test/rails_app/app/views/users/index.html.erb +1 -0
- data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +1 -0
- data/test/rails_app/app/views/users/sessions/new.html.erb +1 -0
- data/test/rails_app/bin/bundle +3 -0
- data/test/rails_app/bin/rails +4 -0
- data/test/rails_app/bin/rake +4 -0
- data/test/rails_app/config.ru +4 -0
- data/test/rails_app/config/application.rb +40 -0
- data/test/rails_app/config/boot.rb +14 -0
- data/test/rails_app/config/database.yml +18 -0
- data/test/rails_app/config/environment.rb +5 -0
- data/test/rails_app/config/environments/development.rb +30 -0
- data/test/rails_app/config/environments/production.rb +80 -0
- data/test/rails_app/config/environments/test.rb +36 -0
- data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test/rails_app/config/initializers/devise.rb +180 -0
- data/test/rails_app/config/initializers/inflections.rb +2 -0
- data/test/rails_app/config/initializers/secret_token.rb +8 -0
- data/test/rails_app/config/initializers/session_store.rb +1 -0
- data/test/rails_app/config/routes.rb +122 -0
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +71 -0
- data/test/rails_app/db/schema.rb +55 -0
- data/test/rails_app/lib/shared_admin.rb +17 -0
- data/test/rails_app/lib/shared_user.rb +29 -0
- data/test/rails_app/lib/shared_user_without_omniauth.rb +13 -0
- data/test/rails_app/public/404.html +26 -0
- data/test/rails_app/public/422.html +26 -0
- data/test/rails_app/public/500.html +26 -0
- data/test/rails_app/public/favicon.ico +0 -0
- data/test/routes_test.rb +264 -0
- data/test/support/action_controller/record_identifier.rb +10 -0
- data/test/support/assertions.rb +39 -0
- data/test/support/helpers.rb +73 -0
- data/test/support/integration.rb +92 -0
- data/test/support/locale/en.yml +8 -0
- data/test/support/mongoid.yml +6 -0
- data/test/support/webrat/integrations/rails.rb +24 -0
- data/test/test_helper.rb +34 -0
- data/test/test_helpers_test.rb +163 -0
- data/test/test_models.rb +33 -0
- metadata +531 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
require 'devise/hooks/timeoutable'
|
|
2
|
+
|
|
3
|
+
module Devise
|
|
4
|
+
module Models
|
|
5
|
+
# Timeoutable takes care of verifying whether a user session has already
|
|
6
|
+
# expired or not. When a session expires after the configured time, the user
|
|
7
|
+
# will be asked for credentials again, it means, they will be redirected
|
|
8
|
+
# to the sign in page.
|
|
9
|
+
#
|
|
10
|
+
# == Options
|
|
11
|
+
#
|
|
12
|
+
# Timeoutable adds the following options to devise_for:
|
|
13
|
+
#
|
|
14
|
+
# * +timeout_in+: the interval to timeout the user session without activity.
|
|
15
|
+
#
|
|
16
|
+
# == Examples
|
|
17
|
+
#
|
|
18
|
+
# user.timedout?(30.minutes.ago)
|
|
19
|
+
#
|
|
20
|
+
module Timeoutable
|
|
21
|
+
extend ActiveSupport::Concern
|
|
22
|
+
|
|
23
|
+
def self.required_fields(klass)
|
|
24
|
+
[]
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Checks whether the user session has expired based on configured time.
|
|
28
|
+
def timedout?(last_access)
|
|
29
|
+
return false if remember_exists_and_not_expired?
|
|
30
|
+
!timeout_in.nil? && last_access && last_access <= timeout_in.ago
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def timeout_in
|
|
34
|
+
self.class.timeout_in
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
private
|
|
38
|
+
|
|
39
|
+
def remember_exists_and_not_expired?
|
|
40
|
+
return false unless respond_to?(:remember_created_at) && respond_to?(:remember_expired?)
|
|
41
|
+
remember_created_at && !remember_expired?
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
module ClassMethods
|
|
45
|
+
Devise::Models.config(self, :timeout_in)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require 'devise/hooks/trackable'
|
|
2
|
+
|
|
3
|
+
module Devise
|
|
4
|
+
module Models
|
|
5
|
+
# Track information about your user sign in. It tracks the following columns:
|
|
6
|
+
#
|
|
7
|
+
# * sign_in_count - Increased every time a sign in is made (by form, openid, oauth)
|
|
8
|
+
# * current_sign_in_at - A timestamp updated when the user signs in
|
|
9
|
+
# * last_sign_in_at - Holds the timestamp of the previous sign in
|
|
10
|
+
# * current_sign_in_ip - The remote ip updated when the user sign in
|
|
11
|
+
# * last_sign_in_ip - Holds the remote ip of the previous sign in
|
|
12
|
+
#
|
|
13
|
+
module Trackable
|
|
14
|
+
def self.required_fields(klass)
|
|
15
|
+
[:current_sign_in_at, :current_sign_in_ip, :last_sign_in_at, :last_sign_in_ip, :sign_in_count]
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def update_tracked_fields(request)
|
|
19
|
+
old_current, new_current = self.current_sign_in_at, Time.now.utc
|
|
20
|
+
self.last_sign_in_at = old_current || new_current
|
|
21
|
+
self.current_sign_in_at = new_current
|
|
22
|
+
|
|
23
|
+
old_current, new_current = self.current_sign_in_ip, request.remote_ip
|
|
24
|
+
self.last_sign_in_ip = old_current || new_current
|
|
25
|
+
self.current_sign_in_ip = new_current
|
|
26
|
+
|
|
27
|
+
self.sign_in_count ||= 0
|
|
28
|
+
self.sign_in_count += 1
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def update_tracked_fields!(request)
|
|
32
|
+
update_tracked_fields(request)
|
|
33
|
+
save(validate: false) or raise "Devise trackable could not save #{inspect}." \
|
|
34
|
+
"Please make sure a model using trackable can be saved at sign in."
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
module Devise
|
|
2
|
+
module Models
|
|
3
|
+
# Validatable creates all needed validations for a user email and password.
|
|
4
|
+
# It's optional, given you may want to create the validations by yourself.
|
|
5
|
+
# Automatically validate if the email is present, unique and its format is
|
|
6
|
+
# valid. Also tests presence of password, confirmation and length.
|
|
7
|
+
#
|
|
8
|
+
# == Options
|
|
9
|
+
#
|
|
10
|
+
# Validatable adds the following options to devise_for:
|
|
11
|
+
#
|
|
12
|
+
# * +email_regexp+: the regular expression used to validate e-mails;
|
|
13
|
+
# * +password_length+: a range expressing password length. Defaults to 8..72.
|
|
14
|
+
#
|
|
15
|
+
module Validatable
|
|
16
|
+
# All validations used by this module.
|
|
17
|
+
VALIDATIONS = [ :validates_presence_of, :validates_uniqueness_of, :validates_format_of,
|
|
18
|
+
:validates_confirmation_of, :validates_length_of ].freeze
|
|
19
|
+
|
|
20
|
+
def self.required_fields(klass)
|
|
21
|
+
[]
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def self.included(base)
|
|
25
|
+
base.extend ClassMethods
|
|
26
|
+
assert_validations_api!(base)
|
|
27
|
+
|
|
28
|
+
base.class_eval do
|
|
29
|
+
validates_presence_of :email, if: :email_required?
|
|
30
|
+
validates_uniqueness_of :email, allow_blank: true, if: :email_changed?
|
|
31
|
+
validates_format_of :email, with: email_regexp, allow_blank: true, if: :email_changed?
|
|
32
|
+
|
|
33
|
+
validates_presence_of :password, if: :password_required?
|
|
34
|
+
validates_confirmation_of :password, if: :password_required?
|
|
35
|
+
validates_length_of :password, within: password_length, allow_blank: true
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def self.assert_validations_api!(base) #:nodoc:
|
|
40
|
+
unavailable_validations = VALIDATIONS.select { |v| !base.respond_to?(v) }
|
|
41
|
+
|
|
42
|
+
unless unavailable_validations.empty?
|
|
43
|
+
raise "Could not use :validatable module since #{base} does not respond " <<
|
|
44
|
+
"to the following methods: #{unavailable_validations.to_sentence}."
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
protected
|
|
49
|
+
|
|
50
|
+
# Checks whether a password is needed or not. For validations only.
|
|
51
|
+
# Passwords are always required if it's a new record, or if the password
|
|
52
|
+
# or confirmation are being set somewhere.
|
|
53
|
+
def password_required?
|
|
54
|
+
!persisted? || !password.nil? || !password_confirmation.nil?
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def email_required?
|
|
58
|
+
true
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
module ClassMethods
|
|
62
|
+
Devise::Models.config(self, :email_regexp, :password_length)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require 'active_support/core_ext/object/with_options'
|
|
2
|
+
|
|
3
|
+
Devise.with_options model: true do |d|
|
|
4
|
+
# Strategies first
|
|
5
|
+
d.with_options strategy: true do |s|
|
|
6
|
+
routes = [nil, :new, :destroy]
|
|
7
|
+
s.add_module :database_authenticatable, controller: :sessions, route: { session: routes }
|
|
8
|
+
s.add_module :rememberable, no_input: true
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# Other authentications
|
|
12
|
+
d.add_module :omniauthable, controller: :omniauth_callbacks, route: :omniauth_callback
|
|
13
|
+
|
|
14
|
+
# Misc after
|
|
15
|
+
routes = [nil, :new, :edit]
|
|
16
|
+
d.add_module :recoverable, controller: :passwords, route: { password: routes }
|
|
17
|
+
d.add_module :registerable, controller: :registrations, route: { registration: (routes << :cancel) }
|
|
18
|
+
d.add_module :validatable
|
|
19
|
+
|
|
20
|
+
# The ones which can sign out after
|
|
21
|
+
routes = [nil, :new]
|
|
22
|
+
d.add_module :confirmable, controller: :confirmations, route: { confirmation: routes }
|
|
23
|
+
d.add_module :lockable, controller: :unlocks, route: { unlock: routes }
|
|
24
|
+
d.add_module :timeoutable
|
|
25
|
+
|
|
26
|
+
# Stats for last, so we make sure the user is really signed in
|
|
27
|
+
d.add_module :trackable
|
|
28
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
begin
|
|
2
|
+
require "omniauth"
|
|
3
|
+
require "omniauth/version"
|
|
4
|
+
rescue LoadError
|
|
5
|
+
warn "Could not load 'omniauth'. Please ensure you have the omniauth gem >= 1.0.0 installed and listed in your Gemfile."
|
|
6
|
+
raise
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
unless OmniAuth::VERSION =~ /^1\./
|
|
10
|
+
raise "You are using an old OmniAuth version, please ensure you have 1.0.0.pr2 version or later installed."
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Clean up the default path_prefix. It will be automatically set by Devise.
|
|
14
|
+
OmniAuth.config.path_prefix = nil
|
|
15
|
+
|
|
16
|
+
OmniAuth.config.on_failure = Proc.new do |env|
|
|
17
|
+
env['devise.mapping'] = Devise::Mapping.find_by_path!(env['PATH_INFO'], :path)
|
|
18
|
+
controller_name = ActiveSupport::Inflector.camelize(env['devise.mapping'].controllers[:omniauth_callbacks])
|
|
19
|
+
controller_klass = ActiveSupport::Inflector.constantize("#{controller_name}Controller")
|
|
20
|
+
controller_klass.action(:failure).call(env)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
module Devise
|
|
24
|
+
module OmniAuth
|
|
25
|
+
autoload :Config, "devise/omniauth/config"
|
|
26
|
+
autoload :UrlHelpers, "devise/omniauth/url_helpers"
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
module Devise
|
|
2
|
+
module OmniAuth
|
|
3
|
+
class StrategyNotFound < NameError
|
|
4
|
+
def initialize(strategy)
|
|
5
|
+
@strategy = strategy
|
|
6
|
+
super("Could not find a strategy with name `#{strategy}'. " \
|
|
7
|
+
"Please ensure it is required or explicitly set it using the :strategy_class option.")
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
class Config
|
|
12
|
+
attr_accessor :strategy
|
|
13
|
+
attr_reader :args, :options, :provider, :strategy_name
|
|
14
|
+
|
|
15
|
+
def initialize(provider, args)
|
|
16
|
+
@provider = provider
|
|
17
|
+
@args = args
|
|
18
|
+
@options = @args.last.is_a?(Hash) ? @args.last : {}
|
|
19
|
+
@strategy = nil
|
|
20
|
+
@strategy_name = options[:name] || @provider
|
|
21
|
+
@strategy_class = options.delete(:strategy_class)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def strategy_class
|
|
25
|
+
@strategy_class ||= find_strategy || autoload_strategy
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def find_strategy
|
|
29
|
+
::OmniAuth.strategies.find do |strategy_class|
|
|
30
|
+
strategy_class.to_s =~ /#{::OmniAuth::Utils.camelize(strategy_name)}$/ ||
|
|
31
|
+
strategy_class.default_options[:name] == strategy_name
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def autoload_strategy
|
|
36
|
+
name = ::OmniAuth::Utils.camelize(provider.to_s)
|
|
37
|
+
if ::OmniAuth::Strategies.const_defined?(name)
|
|
38
|
+
::OmniAuth::Strategies.const_get(name)
|
|
39
|
+
else
|
|
40
|
+
raise StrategyNotFound, name
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module Devise
|
|
2
|
+
module OmniAuth
|
|
3
|
+
module UrlHelpers
|
|
4
|
+
def self.define_helpers(mapping)
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def omniauth_authorize_path(resource_or_scope, *args)
|
|
8
|
+
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
|
9
|
+
_devise_route_context.send("#{scope}_omniauth_authorize_path", *args)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def omniauth_callback_path(resource_or_scope, *args)
|
|
13
|
+
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
|
14
|
+
_devise_route_context.send("#{scope}_omniauth_callback_path", *args)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
module Devise
|
|
2
|
+
class ParameterFilter
|
|
3
|
+
def initialize(case_insensitive_keys, strip_whitespace_keys)
|
|
4
|
+
@case_insensitive_keys = case_insensitive_keys || []
|
|
5
|
+
@strip_whitespace_keys = strip_whitespace_keys || []
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def filter(conditions)
|
|
9
|
+
conditions = stringify_params(conditions.dup)
|
|
10
|
+
|
|
11
|
+
conditions.merge!(filtered_hash_by_method_for_given_keys(conditions.dup, :downcase, @case_insensitive_keys))
|
|
12
|
+
conditions.merge!(filtered_hash_by_method_for_given_keys(conditions.dup, :strip, @strip_whitespace_keys))
|
|
13
|
+
|
|
14
|
+
conditions
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def filtered_hash_by_method_for_given_keys(conditions, method, condition_keys)
|
|
18
|
+
condition_keys.each do |k|
|
|
19
|
+
value = conditions[k]
|
|
20
|
+
conditions[k] = value.send(method) if value.respond_to?(method)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
conditions
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Force keys to be string to avoid injection on mongoid related database.
|
|
27
|
+
def stringify_params(conditions)
|
|
28
|
+
return conditions unless conditions.is_a?(Hash)
|
|
29
|
+
conditions.each do |k, v|
|
|
30
|
+
conditions[k] = v.to_s if param_requires_string_conversion?(v)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
private
|
|
35
|
+
|
|
36
|
+
def param_requires_string_conversion?(value)
|
|
37
|
+
true
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
module Devise
|
|
2
|
+
class BaseSanitizer
|
|
3
|
+
attr_reader :params, :resource_name, :resource_class
|
|
4
|
+
|
|
5
|
+
def initialize(resource_class, resource_name, params)
|
|
6
|
+
@resource_class = resource_class
|
|
7
|
+
@resource_name = resource_name
|
|
8
|
+
@params = params
|
|
9
|
+
@blocks = Hash.new
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def for(kind, &block)
|
|
13
|
+
if block_given?
|
|
14
|
+
@blocks[kind] = block
|
|
15
|
+
else
|
|
16
|
+
default_for(kind)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def sanitize(kind)
|
|
21
|
+
if block = @blocks[kind]
|
|
22
|
+
block.call(default_params)
|
|
23
|
+
else
|
|
24
|
+
default_sanitize(kind)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
def default_for(kind)
|
|
31
|
+
raise ArgumentError, "a block is expected in Devise base sanitizer"
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def default_sanitize(kind)
|
|
35
|
+
default_params
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def default_params
|
|
39
|
+
params.fetch(resource_name, {})
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
class ParameterSanitizer < BaseSanitizer
|
|
44
|
+
def initialize(*)
|
|
45
|
+
super
|
|
46
|
+
@permitted = Hash.new { |h,k| h[k] = attributes_for(k) }
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def sign_in
|
|
50
|
+
permit self.for(:sign_in)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def sign_up
|
|
54
|
+
permit self.for(:sign_up)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def account_update
|
|
58
|
+
permit self.for(:account_update)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
private
|
|
62
|
+
|
|
63
|
+
# TODO: We do need to flatten so it works with strong_parameters
|
|
64
|
+
# gem. We should drop it once we move to Rails 4 only support.
|
|
65
|
+
def permit(keys)
|
|
66
|
+
default_params.permit(*Array(keys))
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Change for(kind) to return the values in the @permitted
|
|
70
|
+
# hash, allowing the developer to customize at runtime.
|
|
71
|
+
def default_for(kind)
|
|
72
|
+
@permitted[kind] || raise("No sanitizer provided for #{kind}")
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def default_sanitize(kind)
|
|
76
|
+
if respond_to?(kind, true)
|
|
77
|
+
send(kind)
|
|
78
|
+
else
|
|
79
|
+
raise NotImplementedError, "Devise doesn't know how to sanitize parameters for #{kind}"
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def attributes_for(kind)
|
|
84
|
+
case kind
|
|
85
|
+
when :sign_in
|
|
86
|
+
auth_keys + [:password, :remember_me]
|
|
87
|
+
when :sign_up
|
|
88
|
+
auth_keys + [:password, :remember_me]
|
|
89
|
+
when :account_update
|
|
90
|
+
auth_keys + [:password, :current_password]
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def auth_keys
|
|
95
|
+
@auth_keys ||= @resource_class.authentication_keys.respond_to?(:keys) ?
|
|
96
|
+
@resource_class.authentication_keys.keys : @resource_class.authentication_keys
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
data/lib/devise/rails.rb
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
require 'devise/rails/routes'
|
|
2
|
+
require 'devise/rails/warden_compat'
|
|
3
|
+
|
|
4
|
+
module Devise
|
|
5
|
+
class Engine < ::Rails::Engine
|
|
6
|
+
config.devise = Devise
|
|
7
|
+
|
|
8
|
+
# Initialize Warden and copy its configurations.
|
|
9
|
+
config.app_middleware.use Warden::Manager do |config|
|
|
10
|
+
Devise.warden_config = config
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Force routes to be loaded if we are doing any eager load.
|
|
14
|
+
config.before_eager_load { |app| app.reload_routes! }
|
|
15
|
+
|
|
16
|
+
initializer "devise.url_helpers" do
|
|
17
|
+
Devise.include_helpers(Devise::Controllers)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
initializer "devise.omniauth" do |app|
|
|
21
|
+
Devise.omniauth_configs.each do |provider, config|
|
|
22
|
+
app.middleware.use config.strategy_class, *config.args do |strategy|
|
|
23
|
+
config.strategy = strategy
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
if Devise.omniauth_configs.any?
|
|
28
|
+
Devise.include_helpers(Devise::OmniAuth)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
initializer "devise.secret_key" do |app|
|
|
33
|
+
if app.respond_to?(:secrets)
|
|
34
|
+
Devise.secret_key ||= app.secrets.secret_key_base
|
|
35
|
+
elsif app.config.respond_to?(:secret_key_base)
|
|
36
|
+
Devise.secret_key ||= app.config.secret_key_base
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
Devise.token_generator ||=
|
|
40
|
+
if secret_key = Devise.secret_key
|
|
41
|
+
Devise::TokenGenerator.new(
|
|
42
|
+
Devise::CachingKeyGenerator.new(Devise::KeyGenerator.new(secret_key))
|
|
43
|
+
)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
initializer "devise.fix_routes_proxy_missing_respond_to_bug" do
|
|
48
|
+
# Deprecate: Remove once we move to Rails 4 only.
|
|
49
|
+
ActionDispatch::Routing::RoutesProxy.class_eval do
|
|
50
|
+
def respond_to?(method, include_private = false)
|
|
51
|
+
super || routes.url_helpers.respond_to?(method)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|