Sha256: 878d8d0da95f09f738e1bb93275c20458d519d91f2a26ccc200a7ec542af97b4

Contents?: true

Size: 1.85 KB

Versions: 6

Compression:

Stored size: 1.85 KB

Contents

module Anoubis
  module Output
    ##
    # Output subclass that represents data for login action
    class Login < Basic
      ##
      # Output subclass that represents data for login action

      # @!attribute [rw] token
      #   @return [String] the resulting login token.
      class_attribute :token

      # @!attribute [rw] name
      #   @return [String] the name of the user
      class_attribute :name

      # @!attribute [rw] surname
      #   @return [String] the surname of the user
      class_attribute :surname

      # @!attribute [rw] email
      #   @return [String] the email of the user
      class_attribute :email

      # @!attribute [rw] locale
      #   @return [String] the user's locale
      class_attribute :locale

      ##
      # Initializes login output data. Generates default values.
      def initialize
        super
        self.token = ''
        self.name = ''
        self.surname = ''
        self.email = ''
        self.locale = ''
      end

      ##
      # Generates hash representation of output class
      # @return [Hash] hash representation of all data
      def to_h
        result = super.to_h
        return result if self.result != 0
        result.merge!({
                          token: self.token,
                          name: self.name,
                          surname: self.surname,
                          email: self.email,
                          locale: self.locale
                      })
        result
      end

      ##
      # Generates output message based on {#result self.result} variable.
      # @return [String] output message
      def message
        case self.result
        when -1
          return I18n.t('errors.invalid_login_parameters')
        when -2
          return I18n.t('errors.invalid_login_or_password')
        else
          return super
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
anoubis-1.0.12 app/controllers/anoubis/output/login.rb
anoubis-1.0.11 app/controllers/anoubis/output/login.rb
anoubis-1.0.10 app/controllers/anoubis/output/login.rb
anoubis-1.0.8 app/controllers/anoubis/output/login.rb
anoubis-1.0.7 app/controllers/anoubis/output/login.rb
anoubis-1.0.1 app/controllers/anoubis/output/login.rb