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-2.1.0 lib/et_fake_ccd/command/login_user_command.rb
et_fake_ccd-2.0.0 lib/et_fake_ccd/command/login_user_command.rb
et_fake_ccd-1.1.11 lib/et_fake_ccd/command/login_user_command.rb
et_fake_ccd-1.1.10 lib/et_fake_ccd/command/login_user_command.rb
et_fake_ccd-1.1.9 lib/et_fake_ccd/command/login_user_command.rb
et_fake_ccd-1.1.8 lib/et_fake_ccd/command/login_user_command.rb
et_fake_ccd-1.1.6 lib/et_fake_ccd/command/login_user_command.rb
et_fake_ccd-1.1.5 lib/et_fake_ccd/command/login_user_command.rb
et_fake_ccd-1.1.4 lib/et_fake_ccd/command/login_user_command.rb
et_fake_ccd-1.1.3 lib/et_fake_ccd/command/login_user_command.rb
et_fake_ccd-1.1.2 lib/et_fake_ccd/command/login_user_command.rb
et_fake_ccd-1.1.1 lib/et_fake_ccd/command/login_user_command.rb
et_fake_ccd-1.1.0 lib/et_fake_ccd/command/login_user_command.rb
et_fake_ccd-1.0.8 lib/et_fake_ccd/command/login_user_command.rb
et_fake_ccd-1.0.7 lib/et_fake_ccd/command/login_user_command.rb
et_fake_ccd-1.0.6 lib/et_fake_ccd/command/login_user_command.rb
et_fake_ccd-1.0.5 lib/et_fake_ccd/command/login_user_command.rb
et_fake_ccd-1.0.4 lib/et_fake_ccd/command/login_user_command.rb
et_fake_ccd-1.0.3 lib/et_fake_ccd/command/login_user_command.rb
et_fake_ccd-1.0.2 lib/et_fake_ccd/command/login_user_command.rb