Sha256: a2d3c92ad11cd0f27dbe7eb8f42dc58e316790024f29efbfb9a7a60aff8b926b

Contents?: true

Size: 1.87 KB

Versions: 23

Compression:

Stored size: 1.87 KB

Contents

#
# SMTP Configuration for an account
#
class SmtpConfiguration
  include StandardModel

  field :email_address, type: String
  field :reply_to_address, type: String
  field :domain, type: String
  field :port, type: Integer, default: 587
  field :authentication_method, type: String
  field :confirmation_token, type: String
  field :confirmed, type: Mongoid::Boolean, default: false
  field :verification_message, type: String
  field :active, type: Mongoid::Boolean, default: false
  field :ssl, type: Mongoid::Boolean, default: false
  field :server_name, type: String
  field :username, type: String
  field :password, type: String
  #
  # Relationships
  #
  embedded_in :account
  #
  # Validations
  validates :server_name, :username, :email_address, :port, presence: true
  #
  # Callbacks
  #
  before_save :update_token

  #
  # If we can use this SMTP configuration or not, it must be confirmed and
  # activate. Otherwise we return false.
  #
  def use?
    confirmed? && active?
  end

  #
  # Which fields to protect
  #
  def secure_fields
    super + %i[password]
  end

  #
  # Validate the token, returning true of false if valid
  #
  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

  #
  # Update the token on save if we are active and the token is not already set.
  #
  def update_token
    if active?
      set(confirmation_token: Digest::SHA256.hexdigest("#{id}_#{account.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
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
web47core-3.2.20 lib/app/models/smtp_configuration.rb
web47core-3.2.19 lib/app/models/smtp_configuration.rb
web47core-3.2.18 lib/app/models/smtp_configuration.rb
web47core-3.2.17 lib/app/models/smtp_configuration.rb
web47core-3.2.16 lib/app/models/smtp_configuration.rb
web47core-3.2.15 lib/app/models/smtp_configuration.rb
web47core-3.2.14 lib/app/models/smtp_configuration.rb
web47core-3.2.13 lib/app/models/smtp_configuration.rb
web47core-3.2.12 lib/app/models/smtp_configuration.rb
web47core-3.2.9 lib/app/models/smtp_configuration.rb
web47core-3.2.8 lib/app/models/smtp_configuration.rb
web47core-3.2.7 lib/app/models/smtp_configuration.rb
web47core-3.2.6 lib/app/models/smtp_configuration.rb
web47core-3.2.5 lib/app/models/smtp_configuration.rb
web47core-3.2.4 lib/app/models/smtp_configuration.rb
web47core-3.2.3 lib/app/models/smtp_configuration.rb
web47core-3.2.2 lib/app/models/smtp_configuration.rb
web47core-3.0.6 lib/app/models/smtp_configuration.rb
web47core-3.0.5 lib/app/models/smtp_configuration.rb
web47core-3.0.4 lib/app/models/smtp_configuration.rb