Sha256: cfefe3963e3039e2ce45ffcc2a5e93468efd0c14b4c2c0e06e1a432f9ffb5d34

Contents?: true

Size: 1.1 KB

Versions: 24

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/simple_cache'

module EacUsersSupport
  module Tasks
    class PasswordReset
      include ::EacRubyUtils::SimpleCache

      def initialize(email, administrator)
        @email = email
        @administrator = administrator
      end

      def run
        if found_user
          Rails.logger.info "Usuário encontrado com o email \"#{@email}\""
          found_user.update!(attributes_to_update)
        else
          Rails.logger.info "Usuário não encontrado com o email \"#{@email}\". Criando..."
          User.create!({ email: @email }.merge(attributes_to_update))
        end
        Rails.logger.info "Senha resetada para #{@email}"
      end

      private

      def attributes_to_update
        r = { password: @email, password_confirmation: @email }
        if found_user.present? && found_user.confirmed_at.blank?
          r.merge(confirmed_at: ::DateTime.now)
        end
        r[:administrator] = true if @administrator
        r
      end

      def found_user_uncached
        ::EacUsersSupport::User.find_by(email: @email)
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
eac_users_support-0.11.0 lib/eac_users_support/tasks/password_reset.rb
eac_users_support-0.10.1 lib/eac_users_support/tasks/password_reset.rb
eac_users_support-0.10.0 lib/eac_users_support/tasks/password_reset.rb
eac_users_support-0.9.8 lib/eac_users_support/tasks/password_reset.rb
eac_users_support-0.9.7 lib/eac_users_support/tasks/password_reset.rb
eac_users_support-0.9.6 lib/eac_users_support/tasks/password_reset.rb
eac_users_support-0.9.5 lib/eac_users_support/tasks/password_reset.rb
eac_users_support-0.9.4 lib/eac_users_support/tasks/password_reset.rb
eac_users_support-0.9.3 lib/eac_users_support/tasks/password_reset.rb
eac_users_support-0.9.2 lib/eac_users_support/tasks/password_reset.rb
eac_users_support-0.9.1 lib/eac_users_support/tasks/password_reset.rb
eac_users_support-0.9.0 lib/eac_users_support/tasks/password_reset.rb
eac_users_support-0.8.7 lib/eac_users_support/tasks/password_reset.rb
eac_users_support-0.8.6 lib/eac_users_support/tasks/password_reset.rb
eac_users_support-0.8.5 lib/eac_users_support/tasks/password_reset.rb
eac_users_support-0.8.4 lib/eac_users_support/tasks/password_reset.rb
eac_users_support-0.8.3 lib/eac_users_support/tasks/password_reset.rb
eac_users_support-0.8.2 lib/eac_users_support/tasks/password_reset.rb
eac_users_support-0.8.1 lib/eac_users_support/tasks/password_reset.rb
eac_users_support-0.8.0 lib/eac_users_support/tasks/password_reset.rb