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