Sha256: da7e3bd211267683728b2b92fbf4916b6f372755c67863449ef469f7ebe53d91

Contents?: true

Size: 1.27 KB

Versions: 33

Compression:

Stored size: 1.27 KB

Contents

module RailsBase::Authentication
  class DestroyUser < RailsBase::ServiceBase
    delegate :current_user, to: :context
    delegate :data, to: :context

    include RailsBase::UserSettingsHelper

    def call
      datum = get_short_lived_datum(data)
      validate_datum?(datum)
      # sign_out(current_user)
      destroy_user!
    end

    def destroy_user!
      log(level: :warn, msg: "Destroying user: #{current_user.id}")

      # delete the user
      current_user.soft_destroy_user!
    end

    def validate_datum?(datum)
      return true if datum[:valid]

      if datum[:found]
        msg = "Errors with Destroy User token: #{datum[:invalid_reason].join(", ")}. Please try again"
        log(level: :warn, msg: msg)
        context.fail!(message: msg)
      end

      log(level: :warn, msg: "Could not find datum code. User may be doing Fishyyyyy things")

      context.fail!(message: "Invalid Data Code. Please retry action")
    end

    def get_short_lived_datum(data)
      ShortLivedData.find_datum(data: data, reason: DATUM_REASON)
    end

    def validate!
      raise "Expected data to be a String. Received #{data.class}" unless data.is_a? String
      raise "Expected current_user to be a User. Received #{current_user.class}" unless current_user.is_a? User
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
rails_base-0.82.0 app/services/rails_base/authentication/destroy_user.rb
rails_base-0.81.1 app/services/rails_base/authentication/destroy_user.rb
rails_base-0.81.0 app/services/rails_base/authentication/destroy_user.rb
rails_base-0.80.0 app/services/rails_base/authentication/destroy_user.rb
rails_base-0.75.6 app/services/rails_base/authentication/destroy_user.rb
rails_base-0.75.5 app/services/rails_base/authentication/destroy_user.rb
rails_base-0.75.4 app/services/rails_base/authentication/destroy_user.rb
rails_base-0.75.3 app/services/rails_base/authentication/destroy_user.rb
rails_base-0.75.2 app/services/rails_base/authentication/destroy_user.rb
rails_base-0.75.1 app/services/rails_base/authentication/destroy_user.rb
rails_base-0.75.0 app/services/rails_base/authentication/destroy_user.rb
rails_base-0.74.0 app/services/rails_base/authentication/destroy_user.rb
rails_base-0.73.1 app/services/rails_base/authentication/destroy_user.rb
rails_base-0.73.0 app/services/rails_base/authentication/destroy_user.rb
rails_base-0.72.1 app/services/rails_base/authentication/destroy_user.rb
rails_base-0.72.0 app/services/rails_base/authentication/destroy_user.rb
rails_base-0.71.0 app/services/rails_base/authentication/destroy_user.rb
rails_base-0.70.1.pre app/services/rails_base/authentication/destroy_user.rb
rails_base-0.70.0 app/services/rails_base/authentication/destroy_user.rb
rails_base-0.61.0 app/services/rails_base/authentication/destroy_user.rb