Class: Mongoid::Generators::DeviseTwoFactorGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Includes:
Devise::Generators::OrmHelpers
Defined in:
lib/generators/mongoid/devise_two_factor_generator.rb

Instance Method Summary collapse

Instance Method Details

#inject_field_typesObject



9
10
11
# File 'lib/generators/mongoid/devise_two_factor_generator.rb', line 9

def inject_field_types
  inject_into_file model_path, migration_data, after: "include Mongoid::Document\n" if model_exists?
end

#migration_dataObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/generators/mongoid/devise_two_factor_generator.rb', line 13

def migration_data
<<RUBY
  # Devise TwoFactor
  field :encrypted_otp_auth_secret,       type: String, encrypted: true
  field :encrypted_otp_recovery_secret,   type: String, encrypted: true
  field :otp_enabled,                     type: Boolean, default: false
  field :otp_mandatory,                   type: Boolean, default: false
  field :otp_enabled_on,                  type: DateTime
  field :otp_failed_attempts,             type: Integer, default: 0
  field :otp_recovery_counter,            type: Integer, default: 0
  field :otp_persistence_seed,            type: String
  field :otp_session_challenge,           type: String
  field :otp_challenge_expires,           type: DateTime

  index({ otp_session_challenge: 1 }, background: true)
  index({ otp_challenge_expires: 1 }, background: true)

RUBY
end