Sha256: 2d671ce1f2e323119f7fdda1eaf0fce4949a972d323960ae145f25aa1751fc2d

Contents?: true

Size: 810 Bytes

Versions: 56

Compression:

Stored size: 810 Bytes

Contents

require 'active_model'
module EtFakeCcd
  module Command
    class LoginUserCommand
      include ActiveModel::Model
      include ActiveModel::Attributes

      def initialize(config: ::EtFakeCcd::Config.instance, **args)
        self.config = config
        super(**args)
      end

      attribute :username
      attribute :password

      def self.from_json(json)
        new username: json['username'], password: json['password']
      end

      validate :validate_username_and_password

      private

      attr_accessor :config

      def validate_username_and_password
        return if config.valid_credentials.any? do |cred|
          username == cred[:username] && password == cred[:password]
        end
        errors.add(:username, "Invalid username or password")
      end

    end
  end
end

Version data entries

56 entries across 56 versions & 1 rubygems

Version Path
et_fake_ccd-1.0.1 lib/et_fake_ccd/command/login_user_command.rb
et_fake_ccd-1.0.0 lib/et_fake_ccd/command/login_user_command.rb
et_fake_ccd-0.1.39 lib/et_fake_ccd/command/login_user_command.rb
et_fake_ccd-0.1.38 lib/et_fake_ccd/command/login_user_command.rb
et_fake_ccd-0.1.37 lib/et_fake_ccd/command/login_user_command.rb
et_fake_ccd-0.1.36 lib/et_fake_ccd/command/login_user_command.rb
et_fake_ccd-0.1.35 lib/et_fake_ccd/command/login_user_command.rb
et_fake_ccd-0.1.34 lib/et_fake_ccd/command/login_user_command.rb
et_fake_ccd-0.1.33 lib/et_fake_ccd/command/login_user_command.rb
et_fake_ccd-0.1.32 lib/et_fake_ccd/command/login_user_command.rb
et_fake_ccd-0.1.31 lib/et_fake_ccd/command/login_user_command.rb
et_fake_ccd-0.1.30 lib/et_fake_ccd/command/login_user_command.rb
et_fake_ccd-0.1.29 lib/et_fake_ccd/command/login_user_command.rb
et_fake_ccd-0.1.28 lib/et_fake_ccd/command/login_user_command.rb
et_fake_ccd-0.1.27 lib/et_fake_ccd/command/login_user_command.rb
et_fake_ccd-0.1.26 lib/et_fake_ccd/command/login_user_command.rb
et_fake_ccd-0.1.25 lib/et_fake_ccd/command/login_user_command.rb
et_fake_ccd-0.1.24 lib/et_fake_ccd/command/login_user_command.rb
et_fake_ccd-0.1.23 lib/et_fake_ccd/command/login_user_command.rb
et_fake_ccd-0.1.22 lib/et_fake_ccd/command/login_user_command.rb