Class: Ooor::CommonService

Inherits:
Service
  • Object
show all
Defined in:
lib/ooor/services.rb

Instance Method Summary collapse

Methods inherited from Service

define_service, #initialize

Constructor Details

This class inherits a constructor from Ooor::Service

Instance Method Details

#login(db, username, password) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/ooor/services.rb', line 32

def (db, username, password)
  @session.logger.debug "OOOR login - db: #{db}, username: #{username}"

  if @session.config[:force_xml_rpc]
    send("ooor_alias_login", db, username, password)
  else
    conn = @session.get_client(:json, "#{@session.base_jsonrpc2_url}")
    response = conn.post do |req|
      req.url '/web/session/authenticate' 
      req.headers['Content-Type'] = 'application/json'
      req.body = {method: 'call', params: { db: db, login: username, password: password}}.to_json
    end
    @session.web_session[:cookie] = response.headers["set-cookie"]
    if response.status == 200
      sid_part1 = @session.web_session[:cookie].split("sid=")[1]
      if sid_part1
        @session.web_session[:sid] = @session.web_session[:cookie].split("sid=")[1].split(";")[0] # NOTE side is required on v7 but not on v8, this enables to sniff if we are on v7
      end
      json_response = JSON.parse(response.body)
      @session.web_session[:session_id] = json_response['result']['session_id']
      user_id = json_response['result']['uid']
      @session.config[:user_id] = user_id
      Ooor.session_handler.register_session(@session)
      user_id
    else
      raise Faraday::Error::ClientError.new(response.status, response)
    end
  end
end