Module: QuoVadis

Defined in:
lib/quo_vadis/hmacable.rb,
lib/quo_vadis.rb,
lib/quo_vadis/crypt.rb,
lib/quo_vadis/model.rb,
lib/quo_vadis/engine.rb,
lib/quo_vadis/version.rb,
app/models/quo_vadis/log.rb,
lib/quo_vadis/controller.rb,
lib/quo_vadis/ip_masking.rb,
app/models/quo_vadis/totp.rb,
app/mailers/quo_vadis/mailer.rb,
app/models/quo_vadis/account.rb,
app/models/quo_vadis/session.rb,
lib/quo_vadis/encrypted_type.rb,
app/models/quo_vadis/password.rb,
app/models/quo_vadis/recovery_code.rb,
lib/quo_vadis/current_request_details.rb,
app/controllers/quo_vadis/logs_controller.rb,
app/controllers/quo_vadis/totps_controller.rb,
lib/generators/quo_vadis/install_generator.rb,
app/controllers/quo_vadis/twofas_controller.rb,
app/controllers/quo_vadis/sessions_controller.rb,
app/controllers/quo_vadis/passwords_controller.rb,
app/controllers/quo_vadis/quo_vadis_controller.rb,
app/controllers/quo_vadis/confirmations_controller.rb,
app/controllers/quo_vadis/recovery_codes_controller.rb,
app/controllers/quo_vadis/password_resets_controller.rb

Overview

Much of this comes from Rodauth.

Defined Under Namespace

Modules: Controller, Hmacable, IpMasking, Model Classes: Account, ConfirmationsController, Crypt, CurrentRequestDetails, EncryptedType, Engine, InstallGenerator, Log, LogsController, Mailer, Password, PasswordResetsController, PasswordsController, QuoVadisController, RecoveryCode, RecoveryCodesController, Session, SessionsController, Totp, TotpsController, TwofasController

Constant Summary collapse

Error =
Class.new StandardError
PasswordExistsError =
Class.new QuoVadis::Error
VERSION =
'2.2.1'

Class Method Summary collapse

Class Method Details

.accessor(*names) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/quo_vadis.rb', line 8

def self.accessor(*names)
  names.each do |name|
    define_singleton_method name do |val = nil|
      if !val.nil?
        instance_variable_set :"@#{name}", val
      else
        instance_variable_get :"@#{name}"
      end
    end
  end
end

.configure(&block) ⇒ Object



38
39
40
# File 'lib/quo_vadis.rb', line 38

def configure(&block)
  module_eval &block
end

.deliver(action, params, later: QuoVadis.enqueue_transactional_emails) ⇒ Object



80
81
82
83
84
85
86
87
# File 'lib/quo_vadis.rb', line 80

def deliver(action, params, later: QuoVadis.enqueue_transactional_emails)
  mail = QuoVadis::Mailer
    .with(params.merge(ip: QuoVadis::CurrentRequestDetails.ip, timestamp: Time.now))
    .send(action)
  later ?
    mail.deliver_later :
    mail.deliver_now
end

.find_account_by_identifier_in_params(params) ⇒ Object



48
49
50
# File 'lib/quo_vadis.rb', line 48

def (params)
  Account.find_by identifier: identifier_value_in_params(params)
end

.humanise_identifier(model) ⇒ Object

model - string class name, e.g. ‘User’ returns string humanised name for the model’s identifier, e.g. “Username”



59
60
61
62
# File 'lib/quo_vadis.rb', line 59

def humanise_identifier(model)
  klass = model.constantize
  klass.human_attribute_name identifier(model)
end

.identifier(model) ⇒ Object

model - string class name, e.g. ‘User’ returns attribute symbol, e.g. :username



91
92
93
# File 'lib/quo_vadis.rb', line 91

def identifier(model)
  models[model]
end

.identifier_value_in_params(params) ⇒ Object



52
53
54
55
# File 'lib/quo_vadis.rb', line 52

def identifier_value_in_params(params)
  identifier = detect_identifier params.keys
  params[identifier]
end

.notify(action, params) ⇒ Object



76
77
78
# File 'lib/quo_vadis.rb', line 76

def notify(action, params)
  deliver(action, params, later: true)
end

.register_model(name, identifier) ⇒ Object

name - string class name, e.g. ‘User’ identifier - attribute symbol, e.g. :username



44
45
46
# File 'lib/quo_vadis.rb', line 44

def register_model(name, identifier)
  models[name] = identifier
end

.table_name_prefixObject



5
6
7
# File 'lib/quo_vadis/engine.rb', line 5

def self.table_name_prefix
  'qv_'
end

.translate(key, **options) ⇒ Object

Translates the key in the :quo_vadis scope, returning nil if it does not exist. This allows applications to suppress a QuoVadis translation. For example:

en:
  quo_vadis:
    require_authentication:


72
73
74
# File 'lib/quo_vadis.rb', line 72

def translate(key, **options)
  I18n.t key, **options.merge(scope: :quo_vadis, raise: true) rescue nil
end