From a09ca46fcfd7ce900c10e6d0af72819bc3b491d6 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Fri, 2 Feb 2018 21:56:14 -0600 Subject: [PATCH] Update: implement account not available or access not available in database When the account is not in the database or the account has insufficient privileges to access the database, an error needs to be reported. A new error category is created to handle this with a separate message. --- common/base/classes/base_error.php | 19 ++++++++++--------- common/base/classes/base_error_messages_english.php | 8 ++++++++ common/base/classes/base_error_messages_japanese.php | 8 ++++++++ common/standard/classes/standard_index.php | 9 ++++++--- 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/common/base/classes/base_error.php b/common/base/classes/base_error.php index f2ea8af..f40bcdc 100644 --- a/common/base/classes/base_error.php +++ b/common/base/classes/base_error.php @@ -592,15 +592,16 @@ interface i_base_error_messages { const NO_SESSION = 15; const NO_SUPPORT = 16; const POSTGRESQL_CONNECTION_FAILURE = 17; - const POSTGRESQL_NO_CONNECTION = 18; - const POSTGRESQL_NO_RESOURCE = 19; - const POSTGRESQL_ERROR = 20; - const SOCKET_FAILURE = 21; - const ACCESS_DENIED = 22; - const ACCESS_DENIED_UNAVAILABLE = 23; - const ACCESS_DENIED_USER = 24; - const ACCESS_DENIED_ADMINISTRATION = 25; - const SERVER_ERROR = 26; + const POSTGRESQL_NO_ACCOUNT = 18; + const POSTGRESQL_NO_CONNECTION = 19; + const POSTGRESQL_NO_RESOURCE = 20; + const POSTGRESQL_ERROR = 21; + const SOCKET_FAILURE = 22; + const ACCESS_DENIED = 23; + const ACCESS_DENIED_UNAVAILABLE = 24; + const ACCESS_DENIED_USER = 25; + const ACCESS_DENIED_ADMINISTRATION = 26; + const SERVER_ERROR = 27; /** diff --git a/common/base/classes/base_error_messages_english.php b/common/base/classes/base_error_messages_english.php index 33fd090..281b659 100644 --- a/common/base/classes/base_error_messages_english.php +++ b/common/base/classes/base_error_messages_english.php @@ -255,6 +255,14 @@ final class c_base_error_messages_english implements i_base_error_messages { return c_base_return_string::s_new('Failed to connect to the database.'); } } + elseif ($code === static::POSTGRESQL_NO_ACCOUNT) { + if ($arguments === TRUE) { + return c_base_return_string::s_new('Database access denied: the account :{database_account} does not exist or does not have the required access' . $function_name_string . '.'); + } + else { + return c_base_return_string::s_new('Database access denied: the account does not exist or does not have the required access.'); + } + } elseif ($code === static::POSTGRESQL_NO_CONNECTION) { if ($arguments === TRUE) { return c_base_return_string::s_new('The database, :{database_name}, is not connected' . $function_name_string . '.'); diff --git a/common/base/classes/base_error_messages_japanese.php b/common/base/classes/base_error_messages_japanese.php index db9403e..ca71ccb 100644 --- a/common/base/classes/base_error_messages_japanese.php +++ b/common/base/classes/base_error_messages_japanese.php @@ -260,6 +260,14 @@ final class c_base_error_messages_japanese implements i_base_error_messages { return c_base_return_string::s_new('データベースに接続できませんでした。'); } } + elseif ($code === static::POSTGRESQL_NO_ACCOUNT) { + if ($arguments === TRUE) { + return c_base_return_string::s_new('データベースアクセスが拒否されました:アカウント:{database_account}が存在しないか、必要なアクセス権' . (is_null($function_name_string) ? '' : '、') . $function_name_string . '。'); + } + else { + return c_base_return_string::s_new('データベースアクセスが拒否されました:アカウントが存在しないか、必要なアクセス権がありません '); + } + } elseif ($code === static::POSTGRESQL_NO_CONNECTION) { if ($arguments === TRUE) { return c_base_return_string::s_new('データベース :{database_name} は接続されていません' . (is_null($function_name_string) ? '' : '、') . $function_name_string . '。'); diff --git a/common/standard/classes/standard_index.php b/common/standard/classes/standard_index.php index fc405a3..299484f 100644 --- a/common/standard/classes/standard_index.php +++ b/common/standard/classes/standard_index.php @@ -545,7 +545,8 @@ class c_standard_index extends c_base_return { $this->session->set_user_current($user_current); } else { - // @todo: handle errors. + $error = c_base_error::s_log(NULL, ['arguments' => [':{account_name}' => $last_error, ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::POSTGRESQL_NO_ACCOUNT); + return c_base_return_error::s_false($error); } unset($user_current); @@ -601,9 +602,11 @@ class c_standard_index extends c_base_return { } if (c_base_return::s_has_error($connected)) { + $this->session->set_error($connected->get_error()); unset($connected); - - $executed = $paths->get_handler_server_error($this->http, $this->database, $this->session, $this->settings); + $error_page = $paths->get_handler_server_error($this->http, $this->database, $this->session, $this->settings); + $executed = $error_page->do_execute($this->http, $this->database, $this->session, $this->settings); + unset($error_page); } else { unset($connected); -- 1.8.3.1