Sha256: 00ac827687d7e11d0ee1cf2bac30f864b564b49682a62ac78829884d1a8bd00e

Contents?: true

Size: 1.75 KB

Versions: 5

Compression:

Stored size: 1.75 KB

Contents

# frozen-string-literal: true

module Rodauth
  Feature.define(:email_base, :EmailBase) do
    translatable_method :email_subject_prefix, ''
    auth_value_method :require_mail?, true
    auth_value_method :allow_raw_email_token?, false

    redirect :default_post_email

    auth_value_methods(
      :email_from
    )

    auth_methods(
      :create_email,
      :email_to,
      :send_email
    )

    def post_configure
      super
      require 'mail' if require_mail?
    end

    def email_from
      "webmaster@#{domain}"
    end

    def email_to
      account[login_column]
    end

    private

    def send_email(email)
      email.deliver!
    end

    def create_email(subject, body)
      create_email_to(email_to, subject, body)
    end

    def create_email_to(to, subject, body)
      m = Mail.new
      m.from = email_from
      m.to = to
      m.subject = "#{email_subject_prefix}#{subject}"
      m.body = body
      m
    end

    def token_link(route, param, key)
      route_url(route, param => token_param_value(key))
    end

    def token_param_value(key)
      "#{account_id}#{token_separator}#{convert_email_token_key(key)}"
    end

    def convert_email_token_key(key)
      convert_token_key(key)
    end

    def account_from_key(token, status_id=nil)
      id, key = split_token(token)
      id = convert_token_id(id)
      return unless id && key

      return unless actual = yield(id)

      unless timing_safe_eql?(key, convert_email_token_key(actual))
        if hmac_secret && allow_raw_email_token?
          return unless timing_safe_eql?(key, actual)
        else
          return
        end
      end
      ds = account_ds(id)
      ds = ds.where(account_status_column=>status_id) if status_id && !skip_status_checks?
      ds.first
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rodauth-2.31.0 lib/rodauth/features/email_base.rb
rodauth-2.30.0 lib/rodauth/features/email_base.rb
rodauth-2.29.0 lib/rodauth/features/email_base.rb
rodauth-2.28.0 lib/rodauth/features/email_base.rb
rodauth-2.27.0 lib/rodauth/features/email_base.rb