Class: SmtpConfiguration

Inherits:
Object
  • Object
show all
Includes:
StandardModel
Defined in:
lib/app/models/smtp_configuration.rb

Overview

SMTP Configuration for an account

Instance Method Summary collapse

Methods included from StandardModel

#audit_action, #auto_strip_attributes, #capture_user_info, #clear_cache, #created_by_display_name, #delete_and_log, #destroy_and_log, included, #last_modified_by_display_name, #log_change, #log_deletion, #remove_blank_secure_fields, #save_and_log, #save_and_log!, #update, #update!, #update_and_log, #update_and_log!

Methods included from App47Logger

clean_params, #clean_params, delete_parameter_keys, #log_controller_error, log_debug, #log_debug, log_error, #log_error, log_exception, #log_message, log_message, #log_warn, log_warn, mask_parameter_keys, #update_flash_messages

Instance Method Details

#secure_fieldsObject

Which fields to protect



43
44
45
# File 'lib/app/models/smtp_configuration.rb', line 43

def secure_fields
  super + %i[password]
end

#update_tokenObject

Update the token on save if we are active and the token is not already set.



64
65
66
67
68
69
70
71
72
# File 'lib/app/models/smtp_configuration.rb', line 64

def update_token
  if active?
    set(confirmation_token: Digest::SHA256.hexdigest("#{id}_#{.id}")) if confirmation_token.nil?
    set(confirmed: false)
    set(verification_message: 'Sending SMTP verification email(s) to SMTP admins.')
  else
    set(verification_message: 'SMTP Configuration is not active, no verification email will be sent.')
  end
end

#use?Boolean

If we can use this SMTP configuration or not, it must be confirmed and activate. Otherwise we return false.

Returns:

  • (Boolean)


36
37
38
# File 'lib/app/models/smtp_configuration.rb', line 36

def use?
  confirmed? && active?
end

#validate_token(token) ⇒ Object

Validate the token, returning true of false if valid



50
51
52
53
54
55
56
57
58
59
# File 'lib/app/models/smtp_configuration.rb', line 50

def validate_token(token)
  valid = if confirmation_token.present? && confirmation_token.eql?(token)
            unset(:confirmation_token, :verification_message)
            true
          else
            false
          end
  set(confirmed: valid)
  valid
end