Class: Anoubis::Output::Login

Inherits:
Basic
  • Object
show all
Defined in:
app/controllers/anoubis/output/login.rb

Overview

Output subclass that represents data for login action

Instance Attribute Summary collapse

Attributes inherited from Basic

#messages, #result, #tab, #title

Instance Method Summary collapse

Methods inherited from Basic

#hash_to_json, #options_to_json

Constructor Details

#initializeLogin

Initializes login output data. Generates default values.



31
32
33
34
35
36
37
38
# File 'app/controllers/anoubis/output/login.rb', line 31

def initialize
  super
  self.token = ''
  self.name = ''
  self.surname = ''
  self.email = ''
  self.locale = ''
end

Instance Attribute Details

#emailString

Returns the email of the user.

Returns:

  • (String)

    the email of the user



23
# File 'app/controllers/anoubis/output/login.rb', line 23

class_attribute :email

#localeString

Returns the user’s locale.

Returns:

  • (String)

    the user’s locale



27
# File 'app/controllers/anoubis/output/login.rb', line 27

class_attribute :locale

#nameString

Returns the name of the user.

Returns:

  • (String)

    the name of the user



15
# File 'app/controllers/anoubis/output/login.rb', line 15

class_attribute :name

#surnameString

Returns the surname of the user.

Returns:

  • (String)

    the surname of the user



19
# File 'app/controllers/anoubis/output/login.rb', line 19

class_attribute :surname

#tokenString

Returns the resulting login token.

Returns:

  • (String)

    the resulting login token.



11
# File 'app/controllers/anoubis/output/login.rb', line 11

class_attribute :token

Instance Method Details

#messageString

Generates output message based on self.result variable.

Returns:

  • (String)

    output message



59
60
61
62
63
64
65
66
67
68
# File 'app/controllers/anoubis/output/login.rb', line 59

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

#to_hHash

Generates hash representation of output class

Returns:

  • (Hash)

    hash representation of all data



43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/anoubis/output/login.rb', line 43

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