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

#clear_cache, included, #remove_blank_secure_fields, #update, #update!

Methods included from App47Logger

#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