Method: QBWC::Controller#authenticate

Defined in:
lib/qbwc/controller.rb

#authenticateObject



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/qbwc/controller.rb', line 103

def authenticate
  username = params[:strUserName]
  password = params[:strPassword]
  if !QBWC.authenticator.nil?
    company_file_path = QBWC.authenticator.call(username, password)
  elsif username == QBWC.username && password == QBWC.password
    company_file_path = QBWC.company_file_path
  else
    company_file_path = nil
  end

  ticket = nil
  if company_file_path.nil?
    QBWC.logger.info "Authentication of user '#{username}' failed."
    company_file_path = AUTHENTICATE_NOT_VALID_USER
  else
    ticket = QBWC.storage_module::Session.new(username, company_file_path).ticket
    session = get_session(ticket)

    if !QBWC.pending_jobs(company_file_path, session).present?
      QBWC.logger.info "Authentication of user '#{username}' succeeded, but no jobs pending for '#{company_file_path}'."
      company_file_path = AUTHENTICATE_NO_WORK
    else
      QBWC.logger.info "Authentication of user '#{username}' succeeded, jobs are pending for '#{company_file_path}'."
      QBWC.session_initializer.call(session) unless QBWC.session_initializer.nil?
    end
  end
  render :soap => {"tns:authenticateResult" => {"tns:string" => [ticket || '', company_file_path]}}
end