Sha256: 337b7cfa092096827c38779ea381da1627a00d4ef60debda3540558f02c12043

Contents?: true

Size: 984 Bytes

Versions: 13

Compression:

Stored size: 984 Bytes

Contents

module MinimalistAuthentication
  module EmailVerification
    extend ActiveSupport::Concern

    included do
      before_save :clear_email_verification, if: ->(user) { user.email_changed? }

      scope :email_verified, -> { where('LENGTH(email) > 2').where.not(email_verified_at: nil) }
    end

    def needs_email_set?
      request_email_enabled? && email.blank?
    end

    def needs_email_verification?
      email_verification_enabled? && email.present? && email_verified_at.blank?
    end

    def email_verified?
      email.present? && email_verified_at.present?
    end

    def verify_email(token)
      secure_update(token, email_verified_at: Time.zone.now)
    end

    private

    def request_email_enabled?
      MinimalistAuthentication.configuration.request_email
    end

    def email_verification_enabled?
      MinimalistAuthentication.configuration.verify_email
    end

    def clear_email_verification
      self.email_verified_at = nil
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
minimalist_authentication-2.4.0 lib/minimalist_authentication/email_verification.rb
minimalist_authentication-2.3.0 lib/minimalist_authentication/email_verification.rb
minimalist_authentication-2.2.4 lib/minimalist_authentication/email_verification.rb
minimalist_authentication-2.2.3 lib/minimalist_authentication/email_verification.rb
minimalist_authentication-2.2.2 lib/minimalist_authentication/email_verification.rb
minimalist_authentication-2.2.1 lib/minimalist_authentication/email_verification.rb
minimalist_authentication-2.2.0 lib/minimalist_authentication/email_verification.rb
minimalist_authentication-2.1.5 lib/minimalist_authentication/email_verification.rb
minimalist_authentication-2.1.4 lib/minimalist_authentication/email_verification.rb
minimalist_authentication-2.1.3 lib/minimalist_authentication/email_verification.rb
minimalist_authentication-2.1.2 lib/minimalist_authentication/email_verification.rb
minimalist_authentication-2.1.1 lib/minimalist_authentication/email_verification.rb
minimalist_authentication-2.1.0 lib/minimalist_authentication/email_verification.rb