devise-security 0.12.0 → 0.18.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.
Files changed (195) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +3 -1
  3. data/README.md +199 -65
  4. data/app/controllers/devise/paranoid_verification_code_controller.rb +28 -12
  5. data/app/controllers/devise/password_expired_controller.rb +34 -10
  6. data/app/views/devise/paranoid_verification_code/show.html.erb +4 -4
  7. data/app/views/devise/password_expired/show.html.erb +6 -6
  8. data/config/locales/bg.yml +42 -0
  9. data/config/locales/by.yml +50 -0
  10. data/config/locales/cs.yml +46 -0
  11. data/config/locales/de.yml +33 -7
  12. data/config/locales/en.yml +26 -1
  13. data/config/locales/es.yml +31 -6
  14. data/config/locales/fa.yml +42 -0
  15. data/config/locales/fr.yml +42 -0
  16. data/config/locales/hi.yml +43 -0
  17. data/config/locales/it.yml +36 -4
  18. data/config/locales/ja.yml +42 -0
  19. data/config/locales/nl.yml +42 -0
  20. data/config/locales/pt.yml +42 -0
  21. data/config/locales/ru.yml +50 -0
  22. data/config/locales/tr.yml +42 -0
  23. data/config/locales/uk.yml +50 -0
  24. data/config/locales/zh_CN.yml +42 -0
  25. data/config/locales/zh_TW.yml +42 -0
  26. data/lib/devise-security/controllers/helpers.rb +74 -51
  27. data/lib/devise-security/hooks/expirable.rb +6 -4
  28. data/lib/devise-security/hooks/paranoid_verification.rb +3 -3
  29. data/lib/devise-security/hooks/password_expirable.rb +5 -3
  30. data/lib/devise-security/hooks/session_limitable.rb +31 -14
  31. data/lib/devise-security/models/active_record/old_password.rb +5 -0
  32. data/lib/devise-security/models/compatibility/active_record_patch.rb +41 -0
  33. data/lib/devise-security/models/compatibility/mongoid_patch.rb +32 -0
  34. data/lib/devise-security/models/compatibility.rb +8 -15
  35. data/lib/devise-security/models/database_authenticatable_patch.rb +20 -10
  36. data/lib/devise-security/models/expirable.rb +14 -7
  37. data/lib/devise-security/models/mongoid/old_password.rb +21 -0
  38. data/lib/devise-security/models/paranoid_verification.rb +4 -2
  39. data/lib/devise-security/models/password_archivable.rb +19 -8
  40. data/lib/devise-security/models/password_expirable.rb +103 -48
  41. data/lib/devise-security/models/secure_validatable.rb +69 -12
  42. data/lib/devise-security/models/security_questionable.rb +2 -0
  43. data/lib/devise-security/models/session_limitable.rb +19 -2
  44. data/lib/devise-security/orm/mongoid.rb +7 -0
  45. data/lib/devise-security/patches/controller_captcha.rb +2 -0
  46. data/lib/devise-security/patches/controller_security_question.rb +3 -1
  47. data/lib/devise-security/patches.rb +16 -8
  48. data/lib/devise-security/rails.rb +2 -0
  49. data/lib/devise-security/routes.rb +4 -3
  50. data/lib/devise-security/validators/password_complexity_validator.rb +62 -0
  51. data/lib/devise-security/version.rb +3 -1
  52. data/lib/devise-security.rb +23 -11
  53. data/lib/generators/devise_security/install_generator.rb +6 -6
  54. data/lib/generators/templates/devise_security.rb +52 -0
  55. data/test/{test_captcha_controller.rb → controllers/test_captcha_controller.rb} +2 -0
  56. data/test/controllers/test_paranoid_verification_code_controller.rb +133 -0
  57. data/test/controllers/test_password_expired_controller.rb +164 -0
  58. data/test/controllers/test_security_question_controller.rb +66 -0
  59. data/test/dummy/Rakefile +3 -1
  60. data/test/dummy/app/assets/config/manifest.js +3 -0
  61. data/test/dummy/app/controllers/application_controller.rb +2 -0
  62. data/test/dummy/app/controllers/captcha/sessions_controller.rb +2 -0
  63. data/test/dummy/app/controllers/overrides/paranoid_verification_code_controller.rb +7 -0
  64. data/test/dummy/app/controllers/overrides/password_expired_controller.rb +17 -0
  65. data/test/dummy/app/controllers/security_question/unlocks_controller.rb +2 -0
  66. data/test/dummy/app/controllers/widgets_controller.rb +9 -0
  67. data/test/dummy/app/models/application_record.rb +10 -2
  68. data/test/dummy/app/models/application_user_record.rb +12 -0
  69. data/test/dummy/app/models/captcha_user.rb +7 -2
  70. data/test/dummy/app/models/mongoid/confirmable_fields.rb +15 -0
  71. data/test/dummy/app/models/mongoid/database_authenticable_fields.rb +18 -0
  72. data/test/dummy/app/models/mongoid/expirable_fields.rb +13 -0
  73. data/test/dummy/app/models/mongoid/lockable_fields.rb +15 -0
  74. data/test/dummy/app/models/mongoid/mappings.rb +15 -0
  75. data/test/dummy/app/models/mongoid/omniauthable_fields.rb +13 -0
  76. data/test/dummy/app/models/mongoid/paranoid_verification_fields.rb +12 -0
  77. data/test/dummy/app/models/mongoid/password_archivable_fields.rb +11 -0
  78. data/test/dummy/app/models/mongoid/password_expirable_fields.rb +12 -0
  79. data/test/dummy/app/models/mongoid/recoverable_fields.rb +13 -0
  80. data/test/dummy/app/models/mongoid/registerable_fields.rb +21 -0
  81. data/test/dummy/app/models/mongoid/rememberable_fields.rb +12 -0
  82. data/test/dummy/app/models/mongoid/secure_validatable_fields.rb +13 -0
  83. data/test/dummy/app/models/mongoid/security_questionable_fields.rb +15 -0
  84. data/test/dummy/app/models/mongoid/session_limitable_fields.rb +12 -0
  85. data/test/dummy/app/models/mongoid/timeoutable_fields.rb +11 -0
  86. data/test/dummy/app/models/mongoid/trackable_fields.rb +16 -0
  87. data/test/dummy/app/models/mongoid/validatable_fields.rb +9 -0
  88. data/test/dummy/app/models/paranoid_verification_user.rb +26 -0
  89. data/test/dummy/app/models/password_expired_user.rb +26 -0
  90. data/test/dummy/app/models/security_question_user.rb +9 -4
  91. data/test/dummy/app/models/user.rb +16 -1
  92. data/test/dummy/app/models/widget.rb +4 -0
  93. data/test/dummy/app/mongoid/admin.rb +31 -0
  94. data/test/dummy/app/mongoid/one_user.rb +58 -0
  95. data/test/dummy/app/mongoid/shim.rb +25 -0
  96. data/test/dummy/app/mongoid/user_on_engine.rb +41 -0
  97. data/test/dummy/app/mongoid/user_on_main_app.rb +41 -0
  98. data/test/dummy/app/mongoid/user_with_validations.rb +37 -0
  99. data/test/dummy/app/mongoid/user_without_email.rb +38 -0
  100. data/test/dummy/config/application.rb +13 -11
  101. data/test/dummy/config/boot.rb +3 -1
  102. data/test/dummy/config/environment.rb +3 -1
  103. data/test/dummy/config/environments/test.rb +6 -13
  104. data/test/dummy/config/initializers/devise.rb +6 -3
  105. data/test/dummy/config/initializers/migration_class.rb +3 -6
  106. data/test/dummy/config/locales/en.yml +10 -0
  107. data/test/dummy/config/mongoid.yml +6 -0
  108. data/test/dummy/config/routes.rb +8 -3
  109. data/test/dummy/config.ru +3 -1
  110. data/test/dummy/db/migrate/20120508165529_create_tables.rb +17 -6
  111. data/test/dummy/db/migrate/20150402165590_add_verification_columns.rb +2 -0
  112. data/test/dummy/db/migrate/20150407162345_add_verification_attempt_column.rb +2 -0
  113. data/test/dummy/db/migrate/20160320162345_add_security_questions_fields.rb +2 -0
  114. data/test/dummy/db/migrate/20180318103603_add_expireable_columns.rb +2 -0
  115. data/test/dummy/db/migrate/20180318105329_add_confirmable_columns.rb +2 -0
  116. data/test/dummy/db/migrate/20180318105732_add_rememberable_columns.rb +2 -0
  117. data/test/dummy/db/migrate/20180318111336_add_recoverable_columns.rb +2 -0
  118. data/test/dummy/db/migrate/20180319114023_add_widget.rb +2 -0
  119. data/test/dummy/lib/shared_expirable_columns.rb +15 -0
  120. data/test/dummy/lib/shared_security_questions_fields.rb +17 -0
  121. data/test/dummy/lib/shared_user.rb +43 -0
  122. data/test/dummy/lib/shared_user_with_password_verification.rb +13 -0
  123. data/test/dummy/lib/shared_user_without_omniauth.rb +24 -0
  124. data/test/dummy/lib/shared_verification_fields.rb +16 -0
  125. data/test/dummy/log/test.log +45240 -0
  126. data/test/i18n_test.rb +22 -0
  127. data/test/integration/test_paranoid_verification_code_workflow.rb +53 -0
  128. data/test/integration/test_password_expirable_workflow.rb +53 -0
  129. data/test/integration/test_session_limitable_workflow.rb +69 -0
  130. data/test/orm/active_record.rb +15 -0
  131. data/test/orm/mongoid.rb +13 -0
  132. data/test/support/integration_helpers.rb +35 -0
  133. data/test/support/mongoid.yml +6 -0
  134. data/test/test_compatibility.rb +15 -0
  135. data/test/test_complexity_validator.rb +282 -0
  136. data/test/test_database_authenticatable_patch.rb +146 -0
  137. data/test/test_helper.rb +41 -9
  138. data/test/test_install_generator.rb +20 -3
  139. data/test/test_paranoid_verification.rb +10 -9
  140. data/test/test_password_archivable.rb +37 -13
  141. data/test/test_password_expirable.rb +72 -9
  142. data/test/test_secure_validatable.rb +289 -55
  143. data/test/test_secure_validatable_overrides.rb +185 -0
  144. data/test/test_session_limitable.rb +57 -0
  145. data/test/tmp/config/initializers/devise_security.rb +52 -0
  146. data/test/tmp/config/locales/devise.security_extension.by.yml +50 -0
  147. data/test/tmp/config/locales/devise.security_extension.cs.yml +46 -0
  148. data/test/tmp/config/locales/devise.security_extension.de.yml +42 -0
  149. data/test/tmp/config/locales/devise.security_extension.en.yml +42 -0
  150. data/test/tmp/config/locales/devise.security_extension.es.yml +42 -0
  151. data/test/tmp/config/locales/devise.security_extension.fa.yml +42 -0
  152. data/test/tmp/config/locales/devise.security_extension.fr.yml +42 -0
  153. data/test/tmp/config/locales/devise.security_extension.hi.yml +43 -0
  154. data/test/tmp/config/locales/devise.security_extension.it.yml +42 -0
  155. data/test/tmp/config/locales/devise.security_extension.ja.yml +42 -0
  156. data/test/tmp/config/locales/devise.security_extension.nl.yml +42 -0
  157. data/test/tmp/config/locales/devise.security_extension.pt.yml +42 -0
  158. data/test/tmp/config/locales/devise.security_extension.ru.yml +50 -0
  159. data/test/tmp/config/locales/devise.security_extension.tr.yml +42 -0
  160. data/test/tmp/config/locales/devise.security_extension.uk.yml +50 -0
  161. data/test/tmp/config/locales/devise.security_extension.zh_CN.yml +42 -0
  162. data/test/tmp/config/locales/devise.security_extension.zh_TW.yml +42 -0
  163. metadata +290 -124
  164. data/.circleci/config.yml +0 -41
  165. data/.document +0 -5
  166. data/.gitignore +0 -40
  167. data/.rubocop.yml +0 -63
  168. data/.ruby-version +0 -1
  169. data/.travis.yml +0 -25
  170. data/Appraisals +0 -19
  171. data/Gemfile +0 -3
  172. data/Rakefile +0 -28
  173. data/devise-security.gemspec +0 -44
  174. data/gemfiles/rails_4.1_stable.gemfile +0 -8
  175. data/gemfiles/rails_4.2_stable.gemfile +0 -8
  176. data/gemfiles/rails_5.0_stable.gemfile +0 -8
  177. data/gemfiles/rails_5.1_stable.gemfile +0 -8
  178. data/gemfiles/rails_5.2_rc1.gemfile +0 -8
  179. data/lib/devise-security/models/old_password.rb +0 -4
  180. data/lib/devise-security/orm/active_record.rb +0 -18
  181. data/lib/devise-security/patches/confirmations_controller_captcha.rb +0 -21
  182. data/lib/devise-security/patches/confirmations_controller_security_question.rb +0 -24
  183. data/lib/devise-security/patches/passwords_controller_captcha.rb +0 -20
  184. data/lib/devise-security/patches/passwords_controller_security_question.rb +0 -23
  185. data/lib/devise-security/patches/registrations_controller_captcha.rb +0 -33
  186. data/lib/devise-security/patches/sessions_controller_captcha.rb +0 -24
  187. data/lib/devise-security/patches/unlocks_controller_captcha.rb +0 -20
  188. data/lib/devise-security/patches/unlocks_controller_security_question.rb +0 -23
  189. data/lib/devise-security/schema.rb +0 -64
  190. data/lib/generators/templates/devise-security.rb +0 -38
  191. data/test/dummy/app/controllers/foos_controller.rb +0 -0
  192. data/test/dummy/app/models/.gitkeep +0 -0
  193. data/test/dummy/app/models/secure_user.rb +0 -3
  194. data/test/test_password_expired_controller.rb +0 -44
  195. data/test/test_security_question_controller.rb +0 -84
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ExpirableFields
4
+ extend ::ActiveSupport::Concern
5
+
6
+ included do
7
+ include Mongoid::Document
8
+
9
+ ## Expirable
10
+ field :expired_at, type: Time
11
+ field :last_activity_at, type: Time
12
+ end
13
+ end
@@ -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,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniauthableFields
4
+ extend ::ActiveSupport::Concern
5
+
6
+ included do
7
+ include Mongoid::Document
8
+
9
+ ## Omniautable
10
+ field :username, type: String
11
+ field :facebook_token, type: String
12
+ end
13
+ 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,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PasswordArchivableFields
4
+ extend ::ActiveSupport::Concern
5
+
6
+ included do
7
+ include Mongoid::Document
8
+
9
+ ## PasswordArchivableFields
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PasswordExpirableFields
4
+ extend ::ActiveSupport::Concern
5
+
6
+ included do
7
+ include Mongoid::Document
8
+
9
+ field :expired_at, type: Time
10
+ field :last_activity_at, type: Time
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,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RememberableFields
4
+ extend ::ActiveSupport::Concern
5
+
6
+ included do
7
+ include Mongoid::Document
8
+
9
+ ## Rememberable
10
+ field :remember_created_at, type: Time
11
+ end
12
+ 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,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SessionLimitableFields
4
+ extend ::ActiveSupport::Concern
5
+
6
+ included do
7
+ include Mongoid::Document
8
+
9
+ ## Session Limitable
10
+ field :unique_session_id, type: String
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TimeoutableFields
4
+ extend ::ActiveSupport::Concern
5
+
6
+ included do
7
+ include Mongoid::Document
8
+
9
+ ## Timeoutable
10
+ end
11
+ 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,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ValidatableFields
4
+ extend ::ActiveSupport::Concern
5
+
6
+ included do
7
+ include Mongoid::Document
8
+ end
9
+ 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
- class SecurityQuestionUser < ActiveRecord::Base
2
- self.table_name = 'users'
3
- devise :database_authenticatable, :password_archivable, :lockable,
4
- :paranoid_verification, :password_expirable, :security_questionable
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
- class User < ApplicationRecord
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
@@ -1,4 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Widget < ApplicationRecord
2
4
  belongs_to :user
3
5
  validates_associated :user
6
+
7
+ field :name, type: String if DEVISE_ORM == :mongoid
4
8
  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
- require File.expand_path('../boot', __FILE__)
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.assets.enabled = true
21
+ config.autoload_paths += ["#{config.root}/app/#{DEVISE_ORM}"]
22
+ config.autoload_paths += ["#{config.root}/lib"]
20
23
 
21
- config.assets.version = '1.0'
22
- config.secret_key_base = 'fuuuuuuuuuuu'
24
+ config.secret_key_base = 'foobar'
23
25
  end
24
26
  end
@@ -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('../../Gemfile', __FILE__)
6
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
5
7
 
6
8
  require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])