devise-security 0.12.0 → 0.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +3 -1
- data/README.md +199 -65
- data/app/controllers/devise/paranoid_verification_code_controller.rb +28 -12
- data/app/controllers/devise/password_expired_controller.rb +34 -10
- data/app/views/devise/paranoid_verification_code/show.html.erb +4 -4
- data/app/views/devise/password_expired/show.html.erb +6 -6
- data/config/locales/bg.yml +42 -0
- data/config/locales/by.yml +50 -0
- data/config/locales/cs.yml +46 -0
- data/config/locales/de.yml +33 -7
- data/config/locales/en.yml +26 -1
- data/config/locales/es.yml +31 -6
- data/config/locales/fa.yml +42 -0
- data/config/locales/fr.yml +42 -0
- data/config/locales/hi.yml +43 -0
- data/config/locales/it.yml +36 -4
- data/config/locales/ja.yml +42 -0
- data/config/locales/nl.yml +42 -0
- data/config/locales/pt.yml +42 -0
- data/config/locales/ru.yml +50 -0
- data/config/locales/tr.yml +42 -0
- data/config/locales/uk.yml +50 -0
- data/config/locales/zh_CN.yml +42 -0
- data/config/locales/zh_TW.yml +42 -0
- data/lib/devise-security/controllers/helpers.rb +74 -51
- data/lib/devise-security/hooks/expirable.rb +6 -4
- data/lib/devise-security/hooks/paranoid_verification.rb +3 -3
- data/lib/devise-security/hooks/password_expirable.rb +5 -3
- data/lib/devise-security/hooks/session_limitable.rb +31 -14
- data/lib/devise-security/models/active_record/old_password.rb +5 -0
- data/lib/devise-security/models/compatibility/active_record_patch.rb +41 -0
- data/lib/devise-security/models/compatibility/mongoid_patch.rb +32 -0
- data/lib/devise-security/models/compatibility.rb +8 -15
- data/lib/devise-security/models/database_authenticatable_patch.rb +20 -10
- data/lib/devise-security/models/expirable.rb +14 -7
- data/lib/devise-security/models/mongoid/old_password.rb +21 -0
- data/lib/devise-security/models/paranoid_verification.rb +4 -2
- data/lib/devise-security/models/password_archivable.rb +19 -8
- data/lib/devise-security/models/password_expirable.rb +103 -48
- data/lib/devise-security/models/secure_validatable.rb +69 -12
- data/lib/devise-security/models/security_questionable.rb +2 -0
- data/lib/devise-security/models/session_limitable.rb +19 -2
- data/lib/devise-security/orm/mongoid.rb +7 -0
- data/lib/devise-security/patches/controller_captcha.rb +2 -0
- data/lib/devise-security/patches/controller_security_question.rb +3 -1
- data/lib/devise-security/patches.rb +16 -8
- data/lib/devise-security/rails.rb +2 -0
- data/lib/devise-security/routes.rb +4 -3
- data/lib/devise-security/validators/password_complexity_validator.rb +62 -0
- data/lib/devise-security/version.rb +3 -1
- data/lib/devise-security.rb +23 -11
- data/lib/generators/devise_security/install_generator.rb +6 -6
- data/lib/generators/templates/devise_security.rb +52 -0
- data/test/{test_captcha_controller.rb → controllers/test_captcha_controller.rb} +2 -0
- data/test/controllers/test_paranoid_verification_code_controller.rb +133 -0
- data/test/controllers/test_password_expired_controller.rb +164 -0
- data/test/controllers/test_security_question_controller.rb +66 -0
- data/test/dummy/Rakefile +3 -1
- data/test/dummy/app/assets/config/manifest.js +3 -0
- data/test/dummy/app/controllers/application_controller.rb +2 -0
- data/test/dummy/app/controllers/captcha/sessions_controller.rb +2 -0
- data/test/dummy/app/controllers/overrides/paranoid_verification_code_controller.rb +7 -0
- data/test/dummy/app/controllers/overrides/password_expired_controller.rb +17 -0
- data/test/dummy/app/controllers/security_question/unlocks_controller.rb +2 -0
- data/test/dummy/app/controllers/widgets_controller.rb +9 -0
- data/test/dummy/app/models/application_record.rb +10 -2
- data/test/dummy/app/models/application_user_record.rb +12 -0
- data/test/dummy/app/models/captcha_user.rb +7 -2
- data/test/dummy/app/models/mongoid/confirmable_fields.rb +15 -0
- data/test/dummy/app/models/mongoid/database_authenticable_fields.rb +18 -0
- data/test/dummy/app/models/mongoid/expirable_fields.rb +13 -0
- data/test/dummy/app/models/mongoid/lockable_fields.rb +15 -0
- data/test/dummy/app/models/mongoid/mappings.rb +15 -0
- data/test/dummy/app/models/mongoid/omniauthable_fields.rb +13 -0
- data/test/dummy/app/models/mongoid/paranoid_verification_fields.rb +12 -0
- data/test/dummy/app/models/mongoid/password_archivable_fields.rb +11 -0
- data/test/dummy/app/models/mongoid/password_expirable_fields.rb +12 -0
- data/test/dummy/app/models/mongoid/recoverable_fields.rb +13 -0
- data/test/dummy/app/models/mongoid/registerable_fields.rb +21 -0
- data/test/dummy/app/models/mongoid/rememberable_fields.rb +12 -0
- data/test/dummy/app/models/mongoid/secure_validatable_fields.rb +13 -0
- data/test/dummy/app/models/mongoid/security_questionable_fields.rb +15 -0
- data/test/dummy/app/models/mongoid/session_limitable_fields.rb +12 -0
- data/test/dummy/app/models/mongoid/timeoutable_fields.rb +11 -0
- data/test/dummy/app/models/mongoid/trackable_fields.rb +16 -0
- data/test/dummy/app/models/mongoid/validatable_fields.rb +9 -0
- data/test/dummy/app/models/paranoid_verification_user.rb +26 -0
- data/test/dummy/app/models/password_expired_user.rb +26 -0
- data/test/dummy/app/models/security_question_user.rb +9 -4
- data/test/dummy/app/models/user.rb +16 -1
- data/test/dummy/app/models/widget.rb +4 -0
- data/test/dummy/app/mongoid/admin.rb +31 -0
- data/test/dummy/app/mongoid/one_user.rb +58 -0
- data/test/dummy/app/mongoid/shim.rb +25 -0
- data/test/dummy/app/mongoid/user_on_engine.rb +41 -0
- data/test/dummy/app/mongoid/user_on_main_app.rb +41 -0
- data/test/dummy/app/mongoid/user_with_validations.rb +37 -0
- data/test/dummy/app/mongoid/user_without_email.rb +38 -0
- data/test/dummy/config/application.rb +13 -11
- data/test/dummy/config/boot.rb +3 -1
- data/test/dummy/config/environment.rb +3 -1
- data/test/dummy/config/environments/test.rb +6 -13
- data/test/dummy/config/initializers/devise.rb +6 -3
- data/test/dummy/config/initializers/migration_class.rb +3 -6
- data/test/dummy/config/locales/en.yml +10 -0
- data/test/dummy/config/mongoid.yml +6 -0
- data/test/dummy/config/routes.rb +8 -3
- data/test/dummy/config.ru +3 -1
- data/test/dummy/db/migrate/20120508165529_create_tables.rb +17 -6
- data/test/dummy/db/migrate/20150402165590_add_verification_columns.rb +2 -0
- data/test/dummy/db/migrate/20150407162345_add_verification_attempt_column.rb +2 -0
- data/test/dummy/db/migrate/20160320162345_add_security_questions_fields.rb +2 -0
- data/test/dummy/db/migrate/20180318103603_add_expireable_columns.rb +2 -0
- data/test/dummy/db/migrate/20180318105329_add_confirmable_columns.rb +2 -0
- data/test/dummy/db/migrate/20180318105732_add_rememberable_columns.rb +2 -0
- data/test/dummy/db/migrate/20180318111336_add_recoverable_columns.rb +2 -0
- data/test/dummy/db/migrate/20180319114023_add_widget.rb +2 -0
- data/test/dummy/lib/shared_expirable_columns.rb +15 -0
- data/test/dummy/lib/shared_security_questions_fields.rb +17 -0
- data/test/dummy/lib/shared_user.rb +43 -0
- data/test/dummy/lib/shared_user_with_password_verification.rb +13 -0
- data/test/dummy/lib/shared_user_without_omniauth.rb +24 -0
- data/test/dummy/lib/shared_verification_fields.rb +16 -0
- data/test/dummy/log/test.log +45240 -0
- data/test/i18n_test.rb +22 -0
- data/test/integration/test_paranoid_verification_code_workflow.rb +53 -0
- data/test/integration/test_password_expirable_workflow.rb +53 -0
- data/test/integration/test_session_limitable_workflow.rb +69 -0
- data/test/orm/active_record.rb +15 -0
- data/test/orm/mongoid.rb +13 -0
- data/test/support/integration_helpers.rb +35 -0
- data/test/support/mongoid.yml +6 -0
- data/test/test_compatibility.rb +15 -0
- data/test/test_complexity_validator.rb +282 -0
- data/test/test_database_authenticatable_patch.rb +146 -0
- data/test/test_helper.rb +41 -9
- data/test/test_install_generator.rb +20 -3
- data/test/test_paranoid_verification.rb +10 -9
- data/test/test_password_archivable.rb +37 -13
- data/test/test_password_expirable.rb +72 -9
- data/test/test_secure_validatable.rb +289 -55
- data/test/test_secure_validatable_overrides.rb +185 -0
- data/test/test_session_limitable.rb +57 -0
- data/test/tmp/config/initializers/devise_security.rb +52 -0
- data/test/tmp/config/locales/devise.security_extension.by.yml +50 -0
- data/test/tmp/config/locales/devise.security_extension.cs.yml +46 -0
- data/test/tmp/config/locales/devise.security_extension.de.yml +42 -0
- data/test/tmp/config/locales/devise.security_extension.en.yml +42 -0
- data/test/tmp/config/locales/devise.security_extension.es.yml +42 -0
- data/test/tmp/config/locales/devise.security_extension.fa.yml +42 -0
- data/test/tmp/config/locales/devise.security_extension.fr.yml +42 -0
- data/test/tmp/config/locales/devise.security_extension.hi.yml +43 -0
- data/test/tmp/config/locales/devise.security_extension.it.yml +42 -0
- data/test/tmp/config/locales/devise.security_extension.ja.yml +42 -0
- data/test/tmp/config/locales/devise.security_extension.nl.yml +42 -0
- data/test/tmp/config/locales/devise.security_extension.pt.yml +42 -0
- data/test/tmp/config/locales/devise.security_extension.ru.yml +50 -0
- data/test/tmp/config/locales/devise.security_extension.tr.yml +42 -0
- data/test/tmp/config/locales/devise.security_extension.uk.yml +50 -0
- data/test/tmp/config/locales/devise.security_extension.zh_CN.yml +42 -0
- data/test/tmp/config/locales/devise.security_extension.zh_TW.yml +42 -0
- metadata +290 -124
- data/.circleci/config.yml +0 -41
- data/.document +0 -5
- data/.gitignore +0 -40
- data/.rubocop.yml +0 -63
- data/.ruby-version +0 -1
- data/.travis.yml +0 -25
- data/Appraisals +0 -19
- data/Gemfile +0 -3
- data/Rakefile +0 -28
- data/devise-security.gemspec +0 -44
- data/gemfiles/rails_4.1_stable.gemfile +0 -8
- data/gemfiles/rails_4.2_stable.gemfile +0 -8
- data/gemfiles/rails_5.0_stable.gemfile +0 -8
- data/gemfiles/rails_5.1_stable.gemfile +0 -8
- data/gemfiles/rails_5.2_rc1.gemfile +0 -8
- data/lib/devise-security/models/old_password.rb +0 -4
- data/lib/devise-security/orm/active_record.rb +0 -18
- data/lib/devise-security/patches/confirmations_controller_captcha.rb +0 -21
- data/lib/devise-security/patches/confirmations_controller_security_question.rb +0 -24
- data/lib/devise-security/patches/passwords_controller_captcha.rb +0 -20
- data/lib/devise-security/patches/passwords_controller_security_question.rb +0 -23
- data/lib/devise-security/patches/registrations_controller_captcha.rb +0 -33
- data/lib/devise-security/patches/sessions_controller_captcha.rb +0 -24
- data/lib/devise-security/patches/unlocks_controller_captcha.rb +0 -20
- data/lib/devise-security/patches/unlocks_controller_security_question.rb +0 -23
- data/lib/devise-security/schema.rb +0 -64
- data/lib/generators/templates/devise-security.rb +0 -38
- data/test/dummy/app/controllers/foos_controller.rb +0 -0
- data/test/dummy/app/models/.gitkeep +0 -0
- data/test/dummy/app/models/secure_user.rb +0 -3
- data/test/test_password_expired_controller.rb +0 -44
- data/test/test_security_question_controller.rb +0 -84
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LockableFields
|
4
|
+
extend ::ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
include Mongoid::Document
|
8
|
+
|
9
|
+
field :failed_attempts, type: Integer, default: 0 # Only if lock strategy is :failed_attempts
|
10
|
+
field :unlock_token, type: String # Only if unlock strategy is :email or :both
|
11
|
+
field :locked_at, type: Time
|
12
|
+
include Mongoid::Timestamps
|
13
|
+
index({ unlock_token: 1 }, { unique: true })
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
Dir[File.expand_path('*_fields.rb', __dir__)].each { |f| require_relative f }
|
4
|
+
|
5
|
+
module Mongoid
|
6
|
+
module Mappings
|
7
|
+
extend ::ActiveSupport::Concern
|
8
|
+
|
9
|
+
included do
|
10
|
+
devise_modules.each do |devise_module_name|
|
11
|
+
include "#{devise_module_name.to_s.classify}Fields".constantize
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ParanoidVerificationFields
|
4
|
+
extend ::ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
include Mongoid::Document
|
8
|
+
field :paranoid_verification_code, type: String
|
9
|
+
field :paranoid_verified_at, type: Time
|
10
|
+
field :paranoid_verification_attempt, type: Integer, default: 0
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RecoverableFields
|
4
|
+
extend ::ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
include Mongoid::Document
|
8
|
+
|
9
|
+
## Recoverable
|
10
|
+
field :reset_password_token, type: String
|
11
|
+
field :reset_password_sent_at, type: Time
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RegisterableFields
|
4
|
+
extend ::ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
include Mongoid::Document
|
8
|
+
|
9
|
+
## Database authenticatable
|
10
|
+
field :email, type: String, default: ''
|
11
|
+
validates_presence_of :email
|
12
|
+
|
13
|
+
field :encrypted_password, type: String, default: ''
|
14
|
+
validates_presence_of :encrypted_password
|
15
|
+
|
16
|
+
field :password_changed_at, type: Time
|
17
|
+
index({ password_changed_at: 1 }, {})
|
18
|
+
index({ email: 1 }, {})
|
19
|
+
include Mongoid::Timestamps
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SecureValidatableFields
|
4
|
+
extend ::ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
include Mongoid::Document
|
8
|
+
|
9
|
+
field :password_changed_at, type: Time
|
10
|
+
index({ password_changed_at: 1 }, {})
|
11
|
+
include Mongoid::Timestamps
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SecurityQuestionableFields
|
4
|
+
extend ::ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
include Mongoid::Document
|
8
|
+
|
9
|
+
## Security Questionable
|
10
|
+
field :locked_at, type: Time
|
11
|
+
field :unlock_token, type: String
|
12
|
+
field :security_question_id, type: Integer
|
13
|
+
field :security_question_answer, type: String
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module TrackableFields
|
4
|
+
extend ::ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
include Mongoid::Document
|
8
|
+
|
9
|
+
## Trackable
|
10
|
+
field :sign_in_count, type: Integer, default: 0
|
11
|
+
field :current_sign_in_at, type: Time
|
12
|
+
field :last_sign_in_at, type: Time
|
13
|
+
field :current_sign_in_ip, type: String
|
14
|
+
field :last_sign_in_ip, type: String
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class ParanoidVerificationUser < ApplicationUserRecord
|
4
|
+
devise :database_authenticatable,
|
5
|
+
:confirmable,
|
6
|
+
:expirable,
|
7
|
+
:lockable,
|
8
|
+
:omniauthable,
|
9
|
+
:paranoid_verification,
|
10
|
+
:password_archivable,
|
11
|
+
:password_expirable,
|
12
|
+
:recoverable,
|
13
|
+
:registerable,
|
14
|
+
:rememberable,
|
15
|
+
:secure_validatable,
|
16
|
+
:security_questionable,
|
17
|
+
:session_limitable,
|
18
|
+
:timeoutable,
|
19
|
+
:trackable,
|
20
|
+
:validatable
|
21
|
+
|
22
|
+
if DEVISE_ORM == :mongoid
|
23
|
+
require './test/dummy/app/models/mongoid/mappings'
|
24
|
+
include ::Mongoid::Mappings
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class PasswordExpiredUser < ApplicationUserRecord
|
4
|
+
devise :database_authenticatable,
|
5
|
+
:confirmable,
|
6
|
+
:expirable,
|
7
|
+
:lockable,
|
8
|
+
:omniauthable,
|
9
|
+
:paranoid_verification,
|
10
|
+
:password_archivable,
|
11
|
+
:password_expirable,
|
12
|
+
:recoverable,
|
13
|
+
:registerable,
|
14
|
+
:rememberable,
|
15
|
+
:secure_validatable,
|
16
|
+
:security_questionable,
|
17
|
+
:session_limitable,
|
18
|
+
:timeoutable,
|
19
|
+
:trackable,
|
20
|
+
:validatable
|
21
|
+
|
22
|
+
if DEVISE_ORM == :mongoid
|
23
|
+
require './test/dummy/app/models/mongoid/mappings'
|
24
|
+
include ::Mongoid::Mappings
|
25
|
+
end
|
26
|
+
end
|
@@ -1,5 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class SecurityQuestionUser < ApplicationUserRecord
|
4
|
+
devise :database_authenticatable, :lockable, :security_questionable
|
5
|
+
if DEVISE_ORM == :mongoid
|
6
|
+
require './test/dummy/app/models/mongoid/mappings'
|
7
|
+
include ::Mongoid::Mappings
|
8
|
+
field :security_question_answer, type: String
|
9
|
+
end
|
5
10
|
end
|
@@ -1,5 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
+
class User < ApplicationRecord
|
3
4
|
devise :database_authenticatable,
|
4
5
|
:confirmable,
|
5
6
|
:expirable,
|
@@ -19,4 +20,18 @@ class User < ApplicationRecord
|
|
19
20
|
:validatable
|
20
21
|
|
21
22
|
has_many :widgets
|
23
|
+
|
24
|
+
case DEVISE_ORM
|
25
|
+
when :mongoid
|
26
|
+
require './test/dummy/app/models/mongoid/mappings'
|
27
|
+
include ::Mongoid::Mappings
|
28
|
+
|
29
|
+
def some_method_calling_mongoid
|
30
|
+
Mongoid.logger
|
31
|
+
end
|
32
|
+
when :active_record
|
33
|
+
def some_method_calling_active_record
|
34
|
+
ActiveRecord::Base.transaction { break; }
|
35
|
+
end
|
36
|
+
end
|
22
37
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'shared_admin'
|
4
|
+
|
5
|
+
class Admin
|
6
|
+
include Mongoid::Document
|
7
|
+
include Shim
|
8
|
+
include SharedAdmin
|
9
|
+
|
10
|
+
## Database authenticatable
|
11
|
+
field :email, type: String
|
12
|
+
field :encrypted_password, type: String
|
13
|
+
|
14
|
+
## Recoverable
|
15
|
+
field :reset_password_token, type: String
|
16
|
+
field :reset_password_sent_at, type: Time
|
17
|
+
|
18
|
+
## Rememberable
|
19
|
+
field :remember_created_at, type: Time
|
20
|
+
|
21
|
+
## Confirmable
|
22
|
+
field :confirmation_token, type: String
|
23
|
+
field :confirmed_at, type: Time
|
24
|
+
field :confirmation_sent_at, type: Time
|
25
|
+
field :unconfirmed_email, type: String # Only if using reconfirmable
|
26
|
+
|
27
|
+
## Lockable
|
28
|
+
field :locked_at, type: Time
|
29
|
+
|
30
|
+
field :active, type: Boolean, default: false
|
31
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'shared_user_with_password_verification'
|
4
|
+
|
5
|
+
class OneUser
|
6
|
+
include Mongoid::Document
|
7
|
+
include Shim
|
8
|
+
include SharedUserWithPasswordVerification
|
9
|
+
include SharedSecurityQuestionsFields
|
10
|
+
|
11
|
+
field :password_changed_at, type: Time
|
12
|
+
index({ password_changed_at: 1 }, {})
|
13
|
+
|
14
|
+
field :paranoid_verification_code, type: String
|
15
|
+
field :paranoid_verified_at, type: Time
|
16
|
+
field :paranoid_verification_attempt, type: Integer, default: 0
|
17
|
+
|
18
|
+
field :username, type: String
|
19
|
+
field :facebook_token, type: String
|
20
|
+
|
21
|
+
## Database authenticatable
|
22
|
+
field :email, type: String, default: ''
|
23
|
+
field :encrypted_password, type: String, default: ''
|
24
|
+
|
25
|
+
## Recoverable
|
26
|
+
field :reset_password_token, type: String
|
27
|
+
field :reset_password_sent_at, type: Time
|
28
|
+
|
29
|
+
## Rememberable
|
30
|
+
field :remember_created_at, type: Time
|
31
|
+
|
32
|
+
## Trackable
|
33
|
+
field :sign_in_count, type: Integer, default: 0
|
34
|
+
field :current_sign_in_at, type: Time
|
35
|
+
field :last_sign_in_at, type: Time
|
36
|
+
field :current_sign_in_ip, type: String
|
37
|
+
field :last_sign_in_ip, type: String
|
38
|
+
|
39
|
+
## Confirmable
|
40
|
+
field :confirmation_token, type: String
|
41
|
+
field :confirmed_at, type: Time
|
42
|
+
field :confirmation_sent_at, type: Time
|
43
|
+
# field :unconfirmed_email, type: String # Only if using reconfirmable
|
44
|
+
|
45
|
+
## Lockable
|
46
|
+
field :failed_attempts, type: Integer, default: 0 # Only if lock strategy is :failed_attempts
|
47
|
+
field :unlock_token, type: String # Only if unlock strategy is :email or :both
|
48
|
+
field :locked_at, type: Time
|
49
|
+
|
50
|
+
cattr_accessor :validations_performed
|
51
|
+
|
52
|
+
after_validation :after_validation_callback
|
53
|
+
|
54
|
+
def after_validation_callback
|
55
|
+
# used to check in our test if the validations were called
|
56
|
+
@@validations_performed = true
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Shim
|
4
|
+
extend ::ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
include ::Mongoid::Timestamps
|
8
|
+
field :created_at, type: DateTime
|
9
|
+
end
|
10
|
+
|
11
|
+
class_methods do
|
12
|
+
def order(attribute)
|
13
|
+
asc(attribute)
|
14
|
+
end
|
15
|
+
|
16
|
+
def find_by_email(email)
|
17
|
+
find_by(email: email)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# overwrite equality (because some devise tests use this for asserting model equality)
|
22
|
+
def ==(other)
|
23
|
+
other.is_a?(self.class) && _id == other._id
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'shared_user_without_omniauth'
|
4
|
+
|
5
|
+
class UserOnEngine
|
6
|
+
include Mongoid::Document
|
7
|
+
include Shim
|
8
|
+
include SharedUserWithoutOmniauth
|
9
|
+
|
10
|
+
field :username, type: String
|
11
|
+
field :facebook_token, type: String
|
12
|
+
|
13
|
+
## Database authenticatable
|
14
|
+
field :email, type: String, default: ''
|
15
|
+
field :encrypted_password, type: String, default: ''
|
16
|
+
|
17
|
+
## Recoverable
|
18
|
+
field :reset_password_token, type: String
|
19
|
+
field :reset_password_sent_at, type: Time
|
20
|
+
|
21
|
+
## Rememberable
|
22
|
+
field :remember_created_at, type: Time
|
23
|
+
|
24
|
+
## Trackable
|
25
|
+
field :sign_in_count, type: Integer, default: 0
|
26
|
+
field :current_sign_in_at, type: Time
|
27
|
+
field :last_sign_in_at, type: Time
|
28
|
+
field :current_sign_in_ip, type: String
|
29
|
+
field :last_sign_in_ip, type: String
|
30
|
+
|
31
|
+
## Confirmable
|
32
|
+
field :confirmation_token, type: String
|
33
|
+
field :confirmed_at, type: Time
|
34
|
+
field :confirmation_sent_at, type: Time
|
35
|
+
# field :unconfirmed_email, type: String # Only if using reconfirmable
|
36
|
+
|
37
|
+
## Lockable
|
38
|
+
field :failed_attempts, type: Integer, default: 0 # Only if lock strategy is :failed_attempts
|
39
|
+
field :unlock_token, type: String # Only if unlock strategy is :email or :both
|
40
|
+
field :locked_at, type: Time
|
41
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'shared_user_without_omniauth'
|
4
|
+
|
5
|
+
class UserOnMainApp
|
6
|
+
include Mongoid::Document
|
7
|
+
include Shim
|
8
|
+
include SharedUserWithoutOmniauth
|
9
|
+
|
10
|
+
field :username, type: String
|
11
|
+
field :facebook_token, type: String
|
12
|
+
|
13
|
+
## Database authenticatable
|
14
|
+
field :email, type: String, default: ''
|
15
|
+
field :encrypted_password, type: String, default: ''
|
16
|
+
|
17
|
+
## Recoverable
|
18
|
+
field :reset_password_token, type: String
|
19
|
+
field :reset_password_sent_at, type: Time
|
20
|
+
|
21
|
+
## Rememberable
|
22
|
+
field :remember_created_at, type: Time
|
23
|
+
|
24
|
+
## Trackable
|
25
|
+
field :sign_in_count, type: Integer, default: 0
|
26
|
+
field :current_sign_in_at, type: Time
|
27
|
+
field :last_sign_in_at, type: Time
|
28
|
+
field :current_sign_in_ip, type: String
|
29
|
+
field :last_sign_in_ip, type: String
|
30
|
+
|
31
|
+
## Confirmable
|
32
|
+
field :confirmation_token, type: String
|
33
|
+
field :confirmed_at, type: Time
|
34
|
+
field :confirmation_sent_at, type: Time
|
35
|
+
# field :unconfirmed_email, type: String # Only if using reconfirmable
|
36
|
+
|
37
|
+
## Lockable
|
38
|
+
field :failed_attempts, type: Integer, default: 0 # Only if lock strategy is :failed_attempts
|
39
|
+
field :unlock_token, type: String # Only if unlock strategy is :email or :both
|
40
|
+
field :locked_at, type: Time
|
41
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'shared_user'
|
4
|
+
|
5
|
+
class UserWithValidations
|
6
|
+
include Mongoid::Document
|
7
|
+
include Shim
|
8
|
+
include SharedUser
|
9
|
+
|
10
|
+
field :username, type: String
|
11
|
+
field :facebook_token, type: String
|
12
|
+
|
13
|
+
## Database authenticatable
|
14
|
+
field :email, type: String, default: ''
|
15
|
+
field :encrypted_password, type: String, default: ''
|
16
|
+
|
17
|
+
## Recoverable
|
18
|
+
field :reset_password_token, type: String
|
19
|
+
field :reset_password_sent_at, type: Time
|
20
|
+
|
21
|
+
## Rememberable
|
22
|
+
field :remember_created_at, type: Time
|
23
|
+
|
24
|
+
## Trackable
|
25
|
+
field :sign_in_count, type: Integer, default: 0
|
26
|
+
field :current_sign_in_at, type: Time
|
27
|
+
field :last_sign_in_at, type: Time
|
28
|
+
field :current_sign_in_ip, type: String
|
29
|
+
field :last_sign_in_ip, type: String
|
30
|
+
|
31
|
+
## Lockable
|
32
|
+
field :failed_attempts, type: Integer, default: 0 # Only if lock strategy is :failed_attempts
|
33
|
+
field :unlock_token, type: String # Only if unlock strategy is :email or :both
|
34
|
+
field :locked_at, type: Time
|
35
|
+
|
36
|
+
validates :email, presence: true
|
37
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'shared_user_without_email'
|
4
|
+
|
5
|
+
class UserWithoutEmail
|
6
|
+
include Mongoid::Document
|
7
|
+
include Shim
|
8
|
+
|
9
|
+
devise :database_authenticatable, :lockable, :recoverable,
|
10
|
+
:registerable, :rememberable, :timeoutable,
|
11
|
+
:trackable
|
12
|
+
|
13
|
+
field :username, type: String
|
14
|
+
field :facebook_token, type: String
|
15
|
+
|
16
|
+
## Database authenticatable
|
17
|
+
field :email, type: String, default: ''
|
18
|
+
field :encrypted_password, type: String, default: ''
|
19
|
+
|
20
|
+
## Recoverable
|
21
|
+
field :reset_password_token, type: String
|
22
|
+
field :reset_password_sent_at, type: Time
|
23
|
+
|
24
|
+
## Rememberable
|
25
|
+
field :remember_created_at, type: Time
|
26
|
+
|
27
|
+
## Trackable
|
28
|
+
field :sign_in_count, type: Integer, default: 0
|
29
|
+
field :current_sign_in_at, type: Time
|
30
|
+
field :last_sign_in_at, type: Time
|
31
|
+
field :current_sign_in_ip, type: String
|
32
|
+
field :last_sign_in_ip, type: String
|
33
|
+
|
34
|
+
## Lockable
|
35
|
+
field :failed_attempts, type: Integer, default: 0 # Only if lock strategy is :failed_attempts
|
36
|
+
field :unlock_token, type: String # Only if unlock strategy is :email or :both
|
37
|
+
field :locked_at, type: Time
|
38
|
+
end
|
@@ -1,24 +1,26 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path('boot', __dir__)
|
4
|
+
|
5
|
+
require 'action_mailer/railtie'
|
6
|
+
require 'rails/test_unit/railtie'
|
7
|
+
DEVISE_ORM = ENV.fetch('DEVISE_ORM', 'active_record').to_sym
|
8
|
+
|
9
|
+
Bundler.require :default, DEVISE_ORM
|
10
|
+
require "#{DEVISE_ORM}/railtie"
|
2
11
|
|
3
12
|
require 'rails/all'
|
4
13
|
require 'devise-security'
|
5
14
|
|
6
|
-
if defined?(Bundler)
|
7
|
-
# If you precompile assets before deploying to production, use this line
|
8
|
-
Bundler.require(*Rails.groups(assets: %w[development test]))
|
9
|
-
# If you want your assets lazily compiled in production, use this line
|
10
|
-
# Bundler.require(:default, :assets, Rails.env)
|
11
|
-
end
|
12
|
-
|
13
15
|
module RailsApp
|
14
16
|
class Application < Rails::Application
|
15
17
|
config.encoding = 'utf-8'
|
16
18
|
|
17
19
|
config.filter_parameters += [:password]
|
18
20
|
|
19
|
-
config.
|
21
|
+
config.autoload_paths += ["#{config.root}/app/#{DEVISE_ORM}"]
|
22
|
+
config.autoload_paths += ["#{config.root}/lib"]
|
20
23
|
|
21
|
-
config.
|
22
|
-
config.secret_key_base = 'fuuuuuuuuuuu'
|
24
|
+
config.secret_key_base = 'foobar'
|
23
25
|
end
|
24
26
|
end
|
data/test/dummy/config/boot.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rubygems'
|
2
4
|
|
3
5
|
# Set up gems listed in the Gemfile.
|
4
|
-
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('
|
6
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
|
5
7
|
|
6
8
|
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
|