Sha256: 376bb8f51f823c223ad321fe6ca029e3bea6ed6e05096a8d054100b7263289f9

Contents?: true

Size: 922 Bytes

Versions: 7

Compression:

Stored size: 922 Bytes

Contents

module Outpost
  module Model
    module Authentication
      extend ActiveSupport::Concern

      included do
        has_secure_password

        before_validation :downcase_email, if: -> { self.email_changed? }

        validates :name, presence: true
        validates Outpost.config.authentication_attribute,
          :presence     => true,
          :uniqueness   => true
      end

      module ClassMethods
        def authenticate(login, unencrypted_password)
          if user = self.send(
          "find_by_#{Outpost.config.authentication_attribute}", login)
            user.authenticate(unencrypted_password)
          else
            false
          end
        end
      end

      # Private: Downcase the user's e-mail
      #
      # Returns String of the e-mail
      def downcase_email
        if self.email.present?
          self.email = self.email.downcase
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
outpost-cms-0.1.4 lib/outpost/model/authentication.rb
outpost-cms-0.1.3 lib/outpost/model/authentication.rb
outpost-cms-0.1.2 lib/outpost/model/authentication.rb
outpost-cms-0.1.1 lib/outpost/model/authentication.rb
outpost-cms-0.1.0 lib/outpost/model/authentication.rb
outpost-cms-0.0.5 lib/outpost/model/authentication.rb
outpost-cms-0.0.4 lib/outpost/model/authentication.rb