Module: Kiqr::Models::User

Extended by:
ActiveSupport::Concern
Defined in:
lib/kiqr/models/user.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#skip_password_validationObject

Virtual attribute to skip password validation while saving



41
42
43
# File 'lib/kiqr/models/user.rb', line 41

def skip_password_validation
  @skip_password_validation
end

Instance Method Details

#cancel_pending_email_change!Object

Reset unconfirmed email and confirmation sent at. This is useful when a user cancels their email change.



68
69
70
# File 'lib/kiqr/models/user.rb', line 68

def cancel_pending_email_change!
  update!(unconfirmed_email: nil, confirmation_sent_at: nil)
end

#create_password(params) ⇒ Object

Alternative to the devise update_with_password method to allow users to add a password without providing their current password.



59
60
61
62
63
64
# File 'lib/kiqr/models/user.rb', line 59

def create_password(params)
  params.delete(:current_password)
  result = update(params)
  clean_up_passwords
  result
end

#onboarded?Boolean

Check if the user has been onboarded successfully.

Returns:

  • (Boolean)


53
54
55
# File 'lib/kiqr/models/user.rb', line 53

def onboarded?
  &.persisted?
end

#otp_uriObject

Generate the user’s OTP provisioning URI.



47
48
49
50
# File 'lib/kiqr/models/user.rb', line 47

def otp_uri
  issuer = Kiqr::Config.app_name
  otp_provisioning_uri(email, issuer: issuer)
end

#reset_otp_secret!Object

Reset the user’s OTP secret and disable two-factor authentication.



79
80
81
82
83
84
85
86
# File 'lib/kiqr/models/user.rb', line 79

def reset_otp_secret!
  update!(
    otp_secret: generate_otp_secret,
    otp_required_for_login: false,
    consumed_timestep: nil,
    otp_backup_codes: nil
  )
end

#two_factor_enabled?Boolean

Helper method to allow for other two-factor methods to be added in the future.

Returns:

  • (Boolean)


74
75
76
# File 'lib/kiqr/models/user.rb', line 74

def two_factor_enabled?
  otp_required_for_login?
end