app/controllers/anoubis/tenant/index/actions.rb
##
# <i>Login</i> action of index controller. Procedure checks user credential. If credentials are correct than user enters
# into the system and procedure returns session token. If credentials are incorrect then procedure returns error.
#
# <b>API request:</b>
#   POST /api/<version>/login
# <b>Request body:</b>
#   {
#     "login": "login",
#     "password": "password",
#     "locale": "Country code"
#   }
# <b>Parameters:</b>
# - <b>login</b> (String) -- the login of the user
# - <b>password</b> (String) -- the password of the user
# - <b>locale</b> (String) -- the output language locale <i>(optional value)</i>
#
# <b>Request example:</b>
#   curl --header "Content-Type: application/json" --request POST --data '{"login":"<login>","password":"<password>"}' http://<server>:<port>/api/<api-version>/login
#
# <b>Results:</b><br>
#
# Resulting data is placed in self.output({Anoubis::OutputLogin}) class and returns in JSON format.
#
# <b>Examples:</b>
#
# <b>Success:</b> HTTP response code 200
#   {
#     "result": 0,
#     "message": "Successful",
#     "name": "Name",
#     "surname": "Surname",
#     "token": "Session token",
#     "email": "e-mail"
#   }
#
# <b>Error:</b> HTTP response code 422
#   {
#     "result": -1,
#     "message": "Incorrect user login or password"
#   }
Login action of index controller. Procedure checks user credential. If credentials are correct than user enters
into the system and procedure returns session token. If credentials are incorrect then procedure returns error.





Results:

Resulting data is placed in self.output({Anoubis::OutputLogin}) class and returns in JSON format.

Examples:




Login action of index controller . Procedure checks user credential . If credentials are correct than user enters into the system and procedure returns session token . If credentials are incorrect then procedure returns error . Results : Resulting data is placed in self . output ( { Anoubis :: OutputLogin } ) class and returns in JSON format . Examples :
def login
          self.output = Anoubis::Output::Login.new
          if params.has_key?(:login) && params.has_key?(:password)
            user = Anoubis::Tenant::User.where(login: params[:login].downcase, status: 0).first
            if !user
              tenant = Anoubis::Tenant::Tenant.where(state: Anoubis::Tenant::Tenant.states[:default]).first
              user = Anoubis::Tenant::User.where(login: (params[:login]+'.'+tenant.ident).downcase, status: 0).first
            end
            if !user
              tenant = Anoubis::Tenant::Tenant.find(1)
              user = Anoubis::Tenant::User.where(login: (params[:login]+'.'+tenant.ident).downcase, status: 0).first
            end
            if user && user.authenticate(params[:password])
              if !user.auth_key
                self.redis_save_user(user)
                self.output.token = new_session_id
                self.output.name = user.name
                self.output.surname = user.surname
                self.output.email = user.email
                self.output.locale = user.locale
                self.redis.set(self.redis_prefix + 'session:' + self.output.token, { uuid: user.uuid, login: Time.now, time: Time.now, ttl: Time.now + user.timeout}.to_json)
              else
                self.output.result = -2
              end
            else
              self.output.result = -2
            end
          else
            self.output.result = -1
          end
          respond_to do |format|
            if self.output.result == 0
              format.json { render json: self.output.to_h }
            else
              format.json { render json: self.output.to_h, status: :unprocessable_entity }
            end
          end
        end
def login self . output = Anoubis :: Output :: Login . new if params . has_key? ( :login ) && params . has_key? ( :password ) user = Anoubis :: Tenant :: User . where ( login : params [ :login ] . downcase , status : 0 ) . first if ! user tenant = Anoubis :: Tenant :: Tenant . where ( state : Anoubis :: Tenant :: Tenant . states [ :default ] ) . first user = Anoubis :: Tenant :: User . where ( login : ( params [ :login ] + '.' + tenant . ident ) . downcase , status : 0 ) . first end if ! user tenant = Anoubis :: Tenant :: Tenant . find ( 1 ) user = Anoubis :: Tenant :: User . where ( login : ( params [ :login ] + '.' + tenant . ident ) . downcase , status : 0 ) . first end if user && user . authenticate ( params [ :password ] ) if ! user . auth_key self . redis_save_user ( user ) self . output . token = new_session_id self . output . name = user . name self . output . surname = user . surname self . output . email = user . email self . output . locale = user . locale self . redis . set ( self . redis_prefix + 'session:' + self . output . token , { uuid : user . uuid , login : Time . now , time : Time . now , ttl : Time . now + user . timeout } . to_json ) else self . output . result = - 2 end else self . output . result = - 2 end else self . output . result = - 1 end respond_to do | format | if self . output . result == 0 format . json { render json : self . output . to_h } else format . json { render json : self . output . to_h , status : :unprocessable_entity } end end end
<i>Login</i> action of index controller.
<i > Login< / i > action of index controller .