Sha256: 954ae5eaf27076c371279782851641b18655c867b1b1024b5f7df43f4d18d22c

Contents?: true

Size: 1.29 KB

Versions: 9

Compression:

Stored size: 1.29 KB

Contents

require 'typus/orm/active_record/user/instance_methods'
require 'bcrypt'

module Typus
  module Orm
    module ActiveRecord
      module AdminUserV2

        module ClassMethods

          def has_admin

            attr_reader   :password
            attr_accessor :password_confirmation

            validates :email, :presence => true, :uniqueness => true, :format => { :with => Typus::Regex::Email }
            validates :password, :confirmation => true, :length => { :within => 6..40 }
            validates :password_digest, :presence => true

            include InstanceMethodsOnActivation
            include Typus::Orm::ActiveRecord::User::InstanceMethods

          end

        end

        module InstanceMethodsOnActivation

          # Returns self if the password is correct, otherwise false.
          def authenticate(unencrypted_password)
            if BCrypt::Password.new(password_digest) == unencrypted_password
              self
            else
              false
            end
          end

          # Encrypts the password into the password_digest attribute.
          def password=(unencrypted_password)
            @password = unencrypted_password
            self.password_digest = BCrypt::Password.create(unencrypted_password)
          end

        end

      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
typus-3.0.12 lib/typus/orm/active_record/admin_user_v2.rb
typus-3.0.11 lib/typus/orm/active_record/admin_user_v2.rb
typus-3.0.11.rc5 lib/typus/orm/active_record/admin_user_v2.rb
typus-3.0.11.rc4 lib/typus/orm/active_record/admin_user_v2.rb
typus-3.0.11.rc3 lib/typus/orm/active_record/admin_user_v2.rb
typus-3.0.11.rc2 lib/typus/orm/active_record/admin_user_v2.rb
typus-3.0.11.rc1 lib/typus/orm/active_record/admin_user_v2.rb
typus-3.0.10 lib/typus/orm/active_record/admin_user_v2.rb
typus-3.0.9 lib/typus/orm/active_record/admin_user_v2.rb