/** Auth method @access public @throws Exception object !@Service.ContentType = json !@Service.Validate.RequestMethod = POST */ public function auth() { try { $login = Application::config("service->auth_name_label"); $password = Application::config("service->auth_password_label"); $addDatetime = Utility::get_datetime(); $apiBC = new ApiBC(); $apiUserTokenVO = new ApiUserTokenVO(); $apiUserTokenVO->User = new UserVO(); $apiUserTokenVO->User->Email = $this->Post->{$login}; $apiUserTokenVO->User->Password = $this->Post->{$password}; $apiUserTokenVO->UserAgent = $this->Headers->{'Client-User-Agent'}; $apiUserTokenVO->ClientIp = $this->Headers->{'Client-Ip'}; $apiUserTokenVO->AddDatetime = $addDatetime; //Params for logging $params = ["user_table_label" => $this->Application->config("service->user_table"), "auth_user_id_label" => $this->Application->config("service->auth_user_id_label"), "user_active_label" => $this->Application->config("service->user_active_label"), "entity" => $this->Application->request_structure("entity"), "service" => $this->Application->request_structure("webMethod"), "parameter" => $this->Application->request_structure("parameter"), "http_verb" => $this->Application->Url->RequestMethod, "client_ip" => $this->Headers->{"Client-Ip"}, "server_ip" => Utility::get_client_ip(), "api_key" => $this->Headers->{"Api-Key"}, "content" => json_encode($this->Post), "add_datetime" => $addDatetime]; parent::response(["token" => $apiBC->auth_user($apiUserTokenVO, $params)]); } catch (Exception $ex) { parent::response($ex); } }
/** Check authorization token @access public @throws Exception object @param array $param @return void */ public function check_authorization_token($param = []) { try { $apiToken = explode(" ", $param["user_token"]); if ($apiToken[0] != Application::config("service->authorization_prefix")) { HttpHandler::header(401); } $apiToken[1] = $apiToken[1]; $param["user_token"] = $apiToken[1]; $result = $this->ApiDAO->check_authorization_token($param); if ($result->UserId == 0) { HttpHandler::header(401); } else { $param["user_id"] = $result->UserId; $param["add_datetime"] = Utility::get_datetime(); $this->ApiDAO->insert_system_log($param); $result->ApiToken = $apiToken[1]; } return $result; } catch (Exception $e) { throw $e; } }