From fb027741236416ec87aa6d2cb2fa20d18040b5c3 Mon Sep 17 00:00:00 2001 From: Wieczorek Bartosz Date: Wed, 1 Mar 2017 10:45:59 +0100 Subject: [PATCH] add method extracting name of column in query --- CMakeLists.txt.user | 959 ----------------------------------- sql/schema.sql | 5 +- src/eedb/auth/PgUserAuth.cpp | 42 +- 3 files changed, 26 insertions(+), 980 deletions(-) delete mode 100644 CMakeLists.txt.user diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user deleted file mode 100644 index 53beadd..0000000 --- a/CMakeLists.txt.user +++ /dev/null @@ -1,959 +0,0 @@ - - - - - - EnvironmentId - {16e47ff4-5a57-423d-b2bd-70f884db1c66} - - - ProjectExplorer.Project.ActiveTarget - 0 - - - ProjectExplorer.Project.EditorSettings - - true - false - true - - Cpp - - CppGlobal - - - - QmlJS - - QmlJSGlobal - - - 2 - UTF-8 - false - 4 - false - 80 - true - true - 1 - true - false - 0 - true - true - 0 - 8 - true - 1 - true - true - false - false - - - - ProjectExplorer.Project.PluginSettings - - - - ProjectExplorer.Project.Target.0 - - GCC6 - GCC6 - {4a2180cc-3e19-4a04-98f7-740914a4ed65} - 1 - 0 - 0 - - - /home/bwieczor/src/__BUILDS__/eedb-GCC6-Domyślna - - - - - all - - true - Make - - CMakeProjectManager.MakeStep - - 1 - budowania - - ProjectExplorer.BuildSteps.Build - - - - - - clean - - true - Make - - CMakeProjectManager.MakeStep - - 1 - czyszczenia - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Domyślna - Domyślna - CMakeProjectManager.CMakeBuildConfiguration - - - - CMAKE_BUILD_TYPE:STRING=Debug - - /home/bwieczor/src/__BUILDS__/eedb-GCC6-Debug - - - - - all - - true - Make - - CMakeProjectManager.MakeStep - - 1 - budowania - - ProjectExplorer.BuildSteps.Build - - - - - - all - - true - Make - - CMakeProjectManager.MakeStep - - 1 - czyszczenia - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Debug - Debug - CMakeProjectManager.CMakeBuildConfiguration - - - - CMAKE_BUILD_TYPE:STRING=Release - - /home/bwieczor/src/__BUILDS__/eedb-GCC6-Release - - - - - all - - true - Make - - CMakeProjectManager.MakeStep - - 1 - budowania - - ProjectExplorer.BuildSteps.Build - - - - - - all - - true - Make - - CMakeProjectManager.MakeStep - - 1 - czyszczenia - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release - Release - CMakeProjectManager.CMakeBuildConfiguration - - - - CMAKE_BUILD_TYPE:STRING=RelWithDebInfo - - /home/bwieczor/src/__BUILDS__/eedb-GCC6-Wersja z informacją debugową - - - - - - - true - Make - - CMakeProjectManager.MakeStep - - 1 - budowania - - ProjectExplorer.BuildSteps.Build - - - - - - clean - - true - Make - - CMakeProjectManager.MakeStep - - 1 - czyszczenia - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Wersja z informacją debugową - Wersja z informacją debugową - CMakeProjectManager.CMakeBuildConfiguration - - - - CMAKE_BUILD_TYPE:STRING=MinSizeRel - - /home/bwieczor/src/__BUILDS__/eedb-GCC6-Wersja o minimalnym rozmiarze (kosztem prędkości) - - - - - all - - true - Make - - CMakeProjectManager.MakeStep - - 1 - budowania - - ProjectExplorer.BuildSteps.Build - - - - - - clean - - true - Make - - CMakeProjectManager.MakeStep - - 1 - czyszczenia - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Wersja o minimalnym rozmiarze (kosztem prędkości) - Wersja o minimalnym rozmiarze (kosztem prędkości) - CMakeProjectManager.CMakeBuildConfiguration - - 5 - - - 0 - instalacji - - ProjectExplorer.BuildSteps.Deploy - - 1 - Zainstaluj lokalnie - - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - eedb - --docroot=/home/bwieczor/src/wt/ --http-port 8080 --http-addr 0.0.0.0 - false - - /home/bwieczor/src/__BUILDS__/eedb-GCC6-Debug/src/app - 2 - - eedb (nieaktywny) - - CMakeProjectManager.CMakeRunConfiguration.eedb - 3768 - false - true - false - false - true - - 1 - - - - ProjectExplorer.Project.Target.1 - - G++ 4.9 (x86 64bit in /usr/bin) Qt 5.6.1 dla System - G++ 4.9 (x86 64bit in /usr/bin) Qt 5.6.1 dla System - {602cff39-296a-4766-9f33-4598f11014c8} - 1 - 0 - 0 - - - /home/bwieczor/src/__BUILDS__/eedb-G_4_9_x86_64bit_in_usr_bin_Qt_5_6_1_dla_System-Domyślna - - - - - all - - true - Make - - CMakeProjectManager.MakeStep - - 1 - budowania - - ProjectExplorer.BuildSteps.Build - - - - - - all - - true - Make - - CMakeProjectManager.MakeStep - - 1 - czyszczenia - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Domyślna - Domyślna - CMakeProjectManager.CMakeBuildConfiguration - - - - CMAKE_BUILD_TYPE:STRING=Debug - - /home/bwieczor/src/__BUILDS__/eedb-G_4_9_x86_64bit_in_usr_bin_Qt_5_6_1_dla_System-Debug - - - - - all - - true - Make - - CMakeProjectManager.MakeStep - - 1 - budowania - - ProjectExplorer.BuildSteps.Build - - - - - - clean - - true - Make - - CMakeProjectManager.MakeStep - - 1 - czyszczenia - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Debug - Debug - CMakeProjectManager.CMakeBuildConfiguration - - - - CMAKE_BUILD_TYPE:STRING=Release - - /home/bwieczor/src/__BUILDS__/eedb-G_4_9_x86_64bit_in_usr_bin_Qt_5_6_1_dla_System-Release - - - - - - - true - Make - - CMakeProjectManager.MakeStep - - 1 - budowania - - ProjectExplorer.BuildSteps.Build - - - - - - clean - - true - Make - - CMakeProjectManager.MakeStep - - 1 - czyszczenia - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release - Release - CMakeProjectManager.CMakeBuildConfiguration - - - - CMAKE_BUILD_TYPE:STRING=RelWithDebInfo - - /home/bwieczor/src/__BUILDS__/eedb-G_4_9_x86_64bit_in_usr_bin_Qt_5_6_1_dla_System-Wersja z informacją debugową - - - - - - - true - Make - - CMakeProjectManager.MakeStep - - 1 - budowania - - ProjectExplorer.BuildSteps.Build - - - - - - clean - - true - Make - - CMakeProjectManager.MakeStep - - 1 - czyszczenia - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Wersja z informacją debugową - Wersja z informacją debugową - CMakeProjectManager.CMakeBuildConfiguration - - - - CMAKE_BUILD_TYPE:STRING=MinSizeRel - - /home/bwieczor/src/__BUILDS__/eedb-G_4_9_x86_64bit_in_usr_bin_Qt_5_6_1_dla_System-Wersja o minimalnym rozmiarze (kosztem prędkości) - - - - - - - true - Make - - CMakeProjectManager.MakeStep - - 1 - budowania - - ProjectExplorer.BuildSteps.Build - - - - - - clean - - true - Make - - CMakeProjectManager.MakeStep - - 1 - czyszczenia - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Wersja o minimalnym rozmiarze (kosztem prędkości) - Wersja o minimalnym rozmiarze (kosztem prędkości) - CMakeProjectManager.CMakeBuildConfiguration - - 5 - - - 0 - instalacji - - ProjectExplorer.BuildSteps.Deploy - - 1 - Zainstaluj lokalnie - - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - eedb - - - /home/bwieczor/src/__BUILDS__/eedb-G_4_9_x86_64bit_in_usr_bin_Qt_5_6_1_dla_System-Debug/src/app - 2 - - eedb - - CMakeProjectManager.CMakeRunConfiguration.eedb - 3768 - false - true - false - false - true - - 1 - - - - ProjectExplorer.Project.Target.2 - - Clang 3.9 - Clang 3.9 - {2e62a059-0116-4322-b158-5f8f59318894} - 0 - 0 - 0 - - - /home/bwieczor/src/__BUILDS__/eedb-Clang_3_9-Domyślna - - - - - - - true - Make - - CMakeProjectManager.MakeStep - - 1 - budowania - - ProjectExplorer.BuildSteps.Build - - - - - - clean - - true - Make - - CMakeProjectManager.MakeStep - - 1 - czyszczenia - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Domyślna - Domyślna - CMakeProjectManager.CMakeBuildConfiguration - - - - CMAKE_BUILD_TYPE:STRING=Debug - - /home/bwieczor/src/__BUILDS__/eedb-Clang_3_9-Debug - - - - - - - true - Make - - CMakeProjectManager.MakeStep - - 1 - budowania - - ProjectExplorer.BuildSteps.Build - - - - - - clean - - true - Make - - CMakeProjectManager.MakeStep - - 1 - czyszczenia - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Debug - Debug - CMakeProjectManager.CMakeBuildConfiguration - - - - CMAKE_BUILD_TYPE:STRING=Release - - /home/bwieczor/src/__BUILDS__/eedb-Clang_3_9-Release - - - - - - - true - Make - - CMakeProjectManager.MakeStep - - 1 - budowania - - ProjectExplorer.BuildSteps.Build - - - - - - clean - - true - Make - - CMakeProjectManager.MakeStep - - 1 - czyszczenia - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release - Release - CMakeProjectManager.CMakeBuildConfiguration - - - - CMAKE_BUILD_TYPE:STRING=RelWithDebInfo - - /home/bwieczor/src/__BUILDS__/eedb-Clang_3_9-Wersja z informacją debugową - - - - - - - true - Make - - CMakeProjectManager.MakeStep - - 1 - budowania - - ProjectExplorer.BuildSteps.Build - - - - - - clean - - true - Make - - CMakeProjectManager.MakeStep - - 1 - czyszczenia - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Wersja z informacją debugową - Wersja z informacją debugową - CMakeProjectManager.CMakeBuildConfiguration - - - - CMAKE_BUILD_TYPE:STRING=MinSizeRel - - /home/bwieczor/src/__BUILDS__/eedb-Clang_3_9-Wersja o minimalnym rozmiarze (kosztem prędkości) - - - - - - - true - Make - - CMakeProjectManager.MakeStep - - 1 - budowania - - ProjectExplorer.BuildSteps.Build - - - - - - clean - - true - Make - - CMakeProjectManager.MakeStep - - 1 - czyszczenia - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Wersja o minimalnym rozmiarze (kosztem prędkości) - Wersja o minimalnym rozmiarze (kosztem prędkości) - CMakeProjectManager.CMakeBuildConfiguration - - 5 - - - 0 - instalacji - - ProjectExplorer.BuildSteps.Deploy - - 1 - Zainstaluj lokalnie - - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - - - %{buildDir} - Własny plik wykonywalny - - ProjectExplorer.CustomExecutableRunConfiguration - 3768 - false - true - false - false - true - - 1 - - - - ProjectExplorer.Project.TargetCount - 3 - - - ProjectExplorer.Project.Updater.FileVersion - 18 - - - Version - 18 - - diff --git a/sql/schema.sql b/sql/schema.sql index cf527e2..3d7a5cf 100644 --- a/sql/schema.sql +++ b/sql/schema.sql @@ -239,7 +239,7 @@ create table "user_audit" ( "user_id" int not null, "action_id" int not null, "data" jsonb, - "when" timestamp DEFAULT(now()), + "_when" timestamp DEFAULT(now()), constraint "pk_user_history_id" primary key ("id"), constraint "fk_user_history_user_uid" foreign key ("user_id") references "user"("uid") on delete cascade deferrable initially deferred, constraint "fk_user_history_user_action" foreign key ("action_id") references "user_audit_action"("id") on delete cascade deferrable initially deferred @@ -357,6 +357,9 @@ comment on column parameters.ptype IS '''stored'' parameter is a parameter whic */ +create table "item_namespaces"( +) + create table "item"( "category_id" int not null, "symbol" text not null, diff --git a/src/eedb/auth/PgUserAuth.cpp b/src/eedb/auth/PgUserAuth.cpp index 5118562..51ced6d 100644 --- a/src/eedb/auth/PgUserAuth.cpp +++ b/src/eedb/auth/PgUserAuth.cpp @@ -199,16 +199,12 @@ User PgUserAuth::registerNew() { .front() .uid; - db(sqlpp::postgresql::insert_into(authInfo) - .set( // - authInfo.password_hash = "NONE", // - authInfo.password_method = "NONE", // - authInfo.password_salt = "NONE", // - authInfo.user_uid = user_id, // - authInfo.email = RandomString(20) + "@random.org") // - .returning(authInfo.id)) - .front() - .id; + db(insert_into(authInfo).set( // + authInfo.password_hash = "NONE", // + authInfo.password_method = "NONE", // + authInfo.password_salt = "NONE", // + authInfo.user_uid = user_id, // + authInfo.email = RandomString(20) + "@NONE.org")); return User{std::to_string(user_id), *this}; } @@ -441,17 +437,23 @@ void PgUserAuth::setFailedLoginAttempts(const User & user, int count) { t_user_history.data = tao::json::to_string(data))); } +template < typename T > +inline std::string name_of(const T&) { + static_assert(sqlpp::is_column_t< T >::value, "T should by a calumn"); + return std::string{sqlpp::name_of< typename T::_table >::char_ptr()} + '.' + sqlpp::name_of< T >::char_ptr(); +} + int PgUserAuth::failedLoginAttempts(const User & user) const { - auto res = db(select(count(t_user_history.id)) // - .from(t_user_history) // - .where(t_user_history.user_id == std::atoi(user.id().c_str()) and // - t_user_history.action_id == select_login_action_id and // - sqlpp::verbatim< sqlpp::boolean >("user_history.data->>'status' = 'failed'") and // - t_user_history.id > select(t_user_history.id) // - .from(t_user_history) // - .where(t_user_history.user_id == std::atoi(user.id().c_str()) and // - t_user_history.action_id == select_login_action_id and // - sqlpp::verbatim< sqlpp::boolean >("user_history.data->>'status' = 'success'")) // + auto res = db(select(count(t_user_history.id)) // + .from(t_user_history) // + .where(t_user_history.user_id == std::atoi(user.id().c_str()) and // + t_user_history.action_id == select_login_action_id and // + sqlpp::verbatim< sqlpp::boolean >(name_of(t_user_history.data) + "->>'status' = 'failed'") and // + t_user_history.id > select(t_user_history.id) // + .from(t_user_history) // + .where(t_user_history.user_id == std::atoi(user.id().c_str()) and // + t_user_history.action_id == select_login_action_id and // + sqlpp::verbatim< sqlpp::boolean >(name_of(t_user_history.data) + "->>'status' = 'success'")) // .limit(1u))); return static_cast< int >(res.front().count); }