Sha256: e8a78b6c8a5a1c55bb94b8164d37f13825b064d6e7231adb57500ad2aa3f89af

Contents?: true

Size: 1.69 KB

Versions: 1

Compression:

Stored size: 1.69 KB

Contents


module Zetto::Extension::ActiveRecord
  extend ActiveSupport::Concern
  require "zetto/modules/load"
  require "zetto/services/encryption/load"

  included do

    protected

    def password_confirmed
      begin
        password_field  = Zetto::Config::Params.user_class_password
        password_value  = send(password_field).to_s
        errors.add(password_field.intern, I18n.t('validate.password_confirm')) unless password_value == password_confirmation

        password_confirmation
      rescue Exception => e
        Zetto::Services::Info.error_message I18n.t('exseptions.undefined_field', field: password_field), e
      end
    end

    def password_encryption
      begin
        password_field  = Zetto::Config::Params.user_class_password
        password_value  = send(password_field)
        hashed_password = Zetto::Services::Encryption::PasswordHashing.new(password_value).execute
        send(password_field+'=', hashed_password)
      rescue Exception => e
        Zetto::Services::Info.error_message I18n.t('exseptions.undefined_field', field: password_field), e
      end
    end

  end

  class_methods do

    def zetto(method)
      method_name = 'zetto_' + method.to_s
      self.send(method_name) if 'zetto_authentication' == method_name
    end

    protected

    def zetto_authentication
      attr_accessor :password_confirmation
      validates      Zetto::Config::Params.user_class_name.intern, uniqueness:true
      validates      Zetto::Config::Params.user_class_password.intern, presence: true,
                     length: { minimum: Zetto::Config::Params.user_class_password_length_larger }

      validate      :password_confirmed
      before_save   :password_encryption
    end

  end

end


Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
zetto-2.2.0 lib/zetto/extension/active_record.rb