diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..6ed36dd
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/backend/.cargo/config.toml b/backend/.cargo/config.toml
new file mode 100644
index 0000000..33306ab
--- /dev/null
+++ b/backend/.cargo/config.toml
@@ -0,0 +1,3 @@
+[build]
+rustflags = ["--cfg", "tokio_unstable"]
+incremental = true
diff --git a/backend/.env b/backend/.env
new file mode 100644
index 0000000..c773194
--- /dev/null
+++ b/backend/.env
@@ -0,0 +1 @@
+DATABASE_URL=sqlite.db
\ No newline at end of file
diff --git a/backend/.gitignore b/backend/.gitignore
new file mode 100644
index 0000000..a792953
--- /dev/null
+++ b/backend/.gitignore
@@ -0,0 +1,133 @@
+# Created by https://www.toptal.com/developers/gitignore/api/clion,rust
+# Edit at https://www.toptal.com/developers/gitignore?templates=clion,rust
+
+### CLion ###
+# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
+# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
+
+# User-specific stuff
+.idea/**/workspace.xml
+.idea/**/tasks.xml
+.idea/**/usage.statistics.xml
+.idea/**/dictionaries
+.idea/**/shelf
+
+# AWS User-specific
+.idea/**/aws.xml
+
+# Generated files
+.idea/**/contentModel.xml
+
+# Sensitive or high-churn files
+.idea/**/dataSources/
+.idea/**/dataSources.ids
+.idea/**/dataSources.local.xml
+.idea/**/sqlDataSources.xml
+.idea/**/dynamic.xml
+.idea/**/uiDesigner.xml
+.idea/**/dbnavigator.xml
+
+# Gradle
+.idea/**/gradle.xml
+.idea/**/libraries
+
+# Gradle and Maven with auto-import
+# When using Gradle or Maven with auto-import, you should exclude module files,
+# since they will be recreated, and may cause churn. Uncomment if using
+# auto-import.
+# .idea/artifacts
+# .idea/compiler.xml
+# .idea/jarRepositories.xml
+# .idea/modules.xml
+# .idea/*.iml
+# .idea/modules
+# *.iml
+# *.ipr
+
+# CMake
+cmake-build-*/
+
+# Mongo Explorer plugin
+.idea/**/mongoSettings.xml
+
+# File-based project format
+*.iws
+
+# IntelliJ
+out/
+
+# mpeltonen/sbt-idea plugin
+.idea_modules/
+
+# JIRA plugin
+atlassian-ide-plugin.xml
+
+# Cursive Clojure plugin
+.idea/replstate.xml
+
+# SonarLint plugin
+.idea/sonarlint/
+
+# Crashlytics plugin (for Android Studio and IntelliJ)
+com_crashlytics_export_strings.xml
+crashlytics.properties
+crashlytics-build.properties
+fabric.properties
+
+# Editor-based Rest Client
+.idea/httpRequests
+
+# Android studio 3.1+ serialized cache file
+.idea/caches/build_file_checksums.ser
+
+### CLion Patch ###
+# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
+
+# *.iml
+# modules.xml
+# .idea/misc.xml
+# *.ipr
+
+# Sonarlint plugin
+# https://plugins.jetbrains.com/plugin/7973-sonarlint
+.idea/**/sonarlint/
+
+# SonarQube Plugin
+# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
+.idea/**/sonarIssues.xml
+
+# Markdown Navigator plugin
+# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
+.idea/**/markdown-navigator.xml
+.idea/**/markdown-navigator-enh.xml
+.idea/**/markdown-navigator/
+
+# Cache file creation bug
+# See https://youtrack.jetbrains.com/issue/JBR-2257
+.idea/$CACHE_FILE$
+
+# CodeStream plugin
+# https://plugins.jetbrains.com/plugin/12206-codestream
+.idea/codestream.xml
+
+# Azure Toolkit for IntelliJ plugin
+# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij
+.idea/**/azureSettings.xml
+
+### Rust ###
+# Generated by Cargo
+# will have compiled files and executables
+debug/
+target/
+
+# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
+# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
+Cargo.lock
+
+# These are backup files generated by rustfmt
+**/*.rs.bk
+
+# MSVC Windows builds of rustc generate these, which store debugging information
+*.pdb
+
+# End of https://www.toptal.com/developers/gitignore/api/clion,rust
diff --git a/backend/.idea/.gitignore b/backend/.idea/.gitignore
deleted file mode 100644
index 13566b8..0000000
--- a/backend/.idea/.gitignore
+++ /dev/null
@@ -1,8 +0,0 @@
-# Default ignored files
-/shelf/
-/workspace.xml
-# Editor-based HTTP Client requests
-/httpRequests/
-# Datasource local storage ignored files
-/dataSources/
-/dataSources.local.xml
diff --git a/backend/.idea/.name b/backend/.idea/.name
deleted file mode 100644
index 98cd9e7..0000000
--- a/backend/.idea/.name
+++ /dev/null
@@ -1 +0,0 @@
-backend
\ No newline at end of file
diff --git a/backend/.idea/backend.iml b/backend/.idea/backend.iml
index f08604b..c254557 100644
--- a/backend/.idea/backend.iml
+++ b/backend/.idea/backend.iml
@@ -1,2 +1,11 @@
-
\ No newline at end of file
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/backend/.idea/cmake.xml b/backend/.idea/cmake.xml
deleted file mode 100644
index f5374c0..0000000
--- a/backend/.idea/cmake.xml
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/backend/.idea/dataSources.xml b/backend/.idea/dataSources.xml
deleted file mode 100644
index 78eab0c..0000000
--- a/backend/.idea/dataSources.xml
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-
-
- sqlite.xerial
- true
- org.sqlite.JDBC
- jdbc:sqlite:$PROJECT_DIR$/../run/sqlite.db
- $ProjectFileDir$
-
-
-
\ No newline at end of file
diff --git a/backend/.idea/file_server.iml b/backend/.idea/file_server.iml
deleted file mode 100644
index f08604b..0000000
--- a/backend/.idea/file_server.iml
+++ /dev/null
@@ -1,2 +0,0 @@
-
-
\ No newline at end of file
diff --git a/backend/.idea/misc.xml b/backend/.idea/misc.xml
deleted file mode 100644
index 72b029a..0000000
--- a/backend/.idea/misc.xml
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/backend/.idea/modules.xml b/backend/.idea/modules.xml
index 064f412..e066844 100644
--- a/backend/.idea/modules.xml
+++ b/backend/.idea/modules.xml
@@ -2,7 +2,7 @@
-
+
\ No newline at end of file
diff --git a/backend/.idea/runConfigurations/backend.xml b/backend/.idea/runConfigurations/backend.xml
deleted file mode 100644
index 0e1cbe1..0000000
--- a/backend/.idea/runConfigurations/backend.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/backend/CMakeLists.txt b/backend/CMakeLists.txt
deleted file mode 100644
index 6bc1a4f..0000000
--- a/backend/CMakeLists.txt
+++ /dev/null
@@ -1,96 +0,0 @@
-cmake_minimum_required(VERSION 3.21)
-
-if (WIN32 AND (NOT VCPKG_TARGET_TRIPLET))
- set(VCPKG_TARGET_TRIPLET x64-windows-static)
-endif (WIN32 AND (NOT VCPKG_TARGET_TRIPLET))
-#set(VCPKG_LIBRARY_LINKAGE static)
-
-project(backend)
-
-set(CMAKE_CXX_STANDARD 20)
-set(CMAKE_CXX_STANDARD_REQUIRED YES)
-
-add_executable(backend
- src/main.cpp
-
- src/dto/dto.h
- src/dto/responses.cpp
-
- src/db/db.h
- src/db/db.cpp
-
- src/controllers/controllers.h
- src/controllers/admin.cpp
- src/controllers/user.cpp
-
- src/controllers/fs/fs_routes.cpp
- src/controllers/fs/fs_functions.cpp
-
- src/controllers/auth/auth_common.cpp
- src/controllers/auth/auth_basic.cpp
- src/controllers/auth/auth_2fa.cpp
- src/controllers/auth/auth_gitlab.cpp
-
- src/filters/filters.h
- src/filters/filters.cpp
-
- model/Inode.cc
- model/Inode.h
- model/Tokens.cc
- model/Tokens.h
- model/User.cc
- model/User.h
-
- SMTPMail-drogon-master/SMTPMail.cc
-)
-
-
-
-find_package(Drogon CONFIG REQUIRED)
-find_package(OpenSSL REQUIRED)
-find_package(OpenCV CONFIG REQUIRED)
-find_package(kubazip CONFIG REQUIRED)
-find_path(JWT_CPP_INCLUDE_DIRS "jwt-cpp/base.h")
-find_path(BOTAN_INCLUDE_DIRS "botan/botan.h")
-find_path(QR_INCLUDE_DIRS "qrcodegen.hpp")
-find_library(BOTAN_LIBRARY NAMES botan-2 botan)
-find_library(QR_LIBRARY nayuki-qr-code-generator)
-
-target_include_directories(backend PRIVATE
- src
- model
- shl
- SMTPMail-drogon-master
- ${OpenCV_INCLUDE_DIRS}
- ${JWT_CPP_INCLUDE_DIRS}
- ${BOTAN_INCLUDE_DIRS}
- ${QR_INCLUDE_DIRS}
-)
-
-target_link_libraries(backend
- Drogon::Drogon
- OpenSSL::SSL
- kubazip::kubazip
- ${OpenCV_LIBS}
- ${BOTAN_LIBRARY}
- ${QR_LIBRARY}
-)
-
-set_property(TARGET backend PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>")
-
-install(TARGETS backend RUNTIME_DEPENDENCY_SET backend_deps DESTINATION .)
-install(RUNTIME_DEPENDENCY_SET backend_deps)
-
-if(NOT MSVC)
- target_compile_options(backend PRIVATE
- $<$:-g -Wall -Wno-unknown-pragmas>
- $<$:-O3>
- )
-else()
- target_compile_options(backend PRIVATE /W4 /wd4068)
-endif(NOT MSVC)
-
-if(WIN32)
- target_link_libraries(backend iphlpapi)
- target_compile_definitions(backend PRIVATE NOMINMAX _WIN32_WINNT=0x0A00)
-endif()
diff --git a/backend/Cargo.toml b/backend/Cargo.toml
new file mode 100644
index 0000000..a55cde2
--- /dev/null
+++ b/backend/Cargo.toml
@@ -0,0 +1,44 @@
+[package]
+name = "backend_rust"
+version = "0.1.0"
+edition = "2021"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+rusqlite = { version = "0.28.0", features = ["bundled"] }
+diesel = { version = "2.0.1", features = ["sqlite", "r2d2", "returning_clauses_for_sqlite_3_35"] }
+diesel_migrations = "2.0.0"
+r2d2_sqlite = "0.21.0"
+
+warp = { version = "0.3.3", features = ["compression", "compression-brotli", "compression-gzip"] }
+headers = "0.3"
+tokio = { version = "1.21.2", features = ["full", "tracing"] }
+tokio-util = { version = "0.7.4", features = ["codec"] }
+console-subscriber = "0.1.8"
+futures = "0.3.24"
+bytes = "1.2.1"
+tracing = { version = "0.1.37", features = ["log-always"] }
+log = "0.4.17"
+
+serde = { version = "1.0.145", features = ["derive"] }
+serde_repr = "0.1.9"
+
+pretty_env_logger = "0.4"
+lazy_static = "1.4.0"
+json = "0.12.4"
+
+jsonwebtoken = "8.1.1"
+thiserror = "1.0.37"
+chrono = "0.4.22"
+rust-argon2 = "1.0.0"
+lettre = "0.10.1"
+ureq = { version = "2.5.0", features = ["json"] }
+totp-rs = { version = "3.0.1", features = ["qr"] }
+ring = { version = "0.16.20", default-features = false }
+mime_guess = "2.0.4"
+zip = "0.6.2"
+base64 = "0.13.0"
+image = "0.24.4"
+cached = "0.39.0"
+stretto = "0.7.1"
diff --git a/backend/SMTPMail-drogon-master/LICENSE b/backend/SMTPMail-drogon-master/LICENSE
deleted file mode 100644
index bd8c790..0000000
--- a/backend/SMTPMail-drogon-master/LICENSE
+++ /dev/null
@@ -1,21 +0,0 @@
-MIT License
-
-Copyright (c) 2020 ihmc3jn09hk
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
diff --git a/backend/SMTPMail-drogon-master/README.md b/backend/SMTPMail-drogon-master/README.md
deleted file mode 100644
index 5463867..0000000
--- a/backend/SMTPMail-drogon-master/README.md
+++ /dev/null
@@ -1,79 +0,0 @@
-# SMTPMail-drogon
-Simple Mail for the Drogon framework.
-
-It is made as a plugin for the [drogon](https://github.com/an-tao/drogon) framework.
-It can be included into the drogon build with little
-modification of the class declaration.
-## Updates
-- **[ 13-06-2022 ] Fixed vulnerability issues reported by [Sam](https://snoopysecurity.github.io/about).**
-- [ 13-09-2021 ] Added [HTML content support](https://github.com/ihmc3jn09hk/SMTPMail-drogon/pull/1).
-- [ 23-12-2020 ] Added DNS support.
-
-## Acknowledgement
-* The implementation takes SMTPClient for Qt from [kelvins](https://github.com/kelvins/SMTPClient) as reference.
-* There requires a delay SSL encryption from the Tcp-socket (named TcpClient in trantor/drogon) and the major
-author of drogon [reponsed](https://github.com/an-tao/drogon/issues/346) quickly.
-
-## Usage
-Download to the plugin directory of the target drogon app, E.g. ~/drogon-app/plugins
-```bash
-$ git clone https://github.com/ihmc3jn09hk/SMTPMail-drogon.git
-$ cp SMTPMail-drogon/SMTPMail.* ~/drogon-app/plugins
-```
-
-* _Be aware of add the plugin into the config.json. Set the "name" field to "SMTPMail"_
-
-Add the reference header and get the plugin from the app(), E.g.
-
-```c++
-...
-#include "../plugins/SMTPMail.h"
-...
-
-//Inside some function, E.g. A controller function.
-...
-//Send an email
-auto *smtpmailPtr = app().getPlugin();
-auto id = smtpmailPtr->sendEmail(
- "127.0.0.1", //The server IP/DNS
- 587, //The port
- "mailer@something.com", //Who send the email
- "receiver@otherthing.com", //Send to whom
- "Testing SMTPMail Function", //Email Subject/Title
- "Hello from drogon plugin", //Content
- "mailer@something.com", //Login user
- "123456", //User password
- false //Is HTML content
- );
-...
-//Or get noted when email is sent
-...
-void callback(const std::string &msg)
-{
- LOG_INFO << msg; /*Output e.g. "EMail sent. ID : 96ESERVDDFH17588ECF0C7B00326E3"*/
- /*Do whatever you like*/
-}
-...
-auto *smtpmailPtr = app().getPlugin();
-auto id = smtpmailPtr->sendEmail(
- "127.0.0.1", //The server IP/DNS
- 587, //The port
- "mailer@something.com", //Who send the email
- "receiver@otherthing.com", //Send to whom
- "Testing SMTPMail Function", //Email Subject/Title
- "Hello from drogon plugin", //Content
- "mailer@something.com", //Login user
- "123456", //User password
- false, //Is HTML content
- callback //Callback
- );
-```
-
-```bash
-$ cd ~/drogon-app/build
-$ make
-```
-
-## Licence
-* Feel free to use, thanks to open-source.
-* For the sake of concern on commercial usage, a simple licence is included in each of the files.
diff --git a/backend/SMTPMail-drogon-master/SMTPMail.cc b/backend/SMTPMail-drogon-master/SMTPMail.cc
deleted file mode 100644
index 8b105c2..0000000
--- a/backend/SMTPMail-drogon-master/SMTPMail.cc
+++ /dev/null
@@ -1,400 +0,0 @@
-/**
-*
-* SMTPMail.cc *
-*
-* This plugin is for SMTP mail delivery for the Drogon web-framework.
-Implementation
-* reference from the project "SMTPClient" with Qt5 by kelvins. Please check out
-* https://github.com/kelvins/SMTPClient.
-
-Feel free to use the code. For the sake of any concern, the following licence is
-attached.
-
- Copyright 2020 ihmc3jn09hk
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
- */
-
-#include "SMTPMail.h"
-#include
-#include
-#include
-#include
-
-using namespace drogon;
-using namespace trantor;
-
-struct EMail {
- enum states {
- Init,
- HandShake,
- Tls,
- Auth,
- User,
- Pass,
- Mail,
- Rcpt,
- Data,
- Body,
- Quit,
- Close
- };
- std::string m_from;
- std::string m_to;
- std::string m_subject;
- std::string m_content;
- std::string m_user;
- std::string m_passwd;
- states m_status;
- std::string m_uuid;
- bool m_isHTML{false};
- std::shared_ptr m_socket;
-
- EMail(std::string from, std::string to, std::string subject,
- std::string content, std::string user, std::string passwd, bool isHTML,
- std::shared_ptr socket)
- : m_from(std::move(from)), m_to(std::move(to)),
- m_subject(std::move(subject)), m_content(std::move(content)),
- m_user(std::move(user)), m_passwd(std::move(passwd)),
- m_socket(std::move(socket)), m_isHTML(isHTML),
- m_uuid(drogon::utils::getUuid()) {
- m_status = Init;
- }
-
- ~EMail() = default;
-
- static std::unordered_map>
- m_emails; // Container for processing emails
-};
-
-std::unordered_map> EMail::m_emails;
-
-void SMTPMail::initAndStart(const Json::Value &config) {
- /// Initialize and start the plugin
- LOG_INFO << "SMTPMail initialized and started";
-}
-
-void SMTPMail::shutdown() {
- /// Shutdown the plugin
- LOG_INFO << "STMPMail shutdown";
-}
-
-void messagesHandle(const trantor::TcpConnectionPtr &connPtr,
- trantor::MsgBuffer *msg,
- const std::shared_ptr &email,
- const std::function &cb) {
- std::string receivedMsg;
- while (msg->readableBytes() > 0) {
- std::string buf(msg->peek(), msg->readableBytes());
- receivedMsg.append(buf);
- // LOG_INFO << buf;
- msg->retrieveAll();
- }
- LOG_TRACE << "receive: " << receivedMsg;
- std::string responseCode(receivedMsg.begin(), receivedMsg.begin() + 3);
- // std::string responseMsg(receivedMsg.begin() + 4, receivedMsg.end());
-
- if (email->m_status == EMail::Init && responseCode == "220") {
- std::string outMsg;
- trantor::MsgBuffer out;
-
- outMsg.append("EHLO smtpclient.qw");
- outMsg.append("\r\n");
-
- out.append(outMsg.data(), outMsg.size());
-
- connPtr->send(std::move(out));
-
- email->m_status = EMail::HandShake;
- } else if (email->m_status == EMail::HandShake && responseCode == "220") {
- std::string outMsg;
- trantor::MsgBuffer out;
-
- outMsg.append("EHLO smtpclient.qw");
- outMsg.append("\r\n");
-
- out.append(outMsg.data(), outMsg.size());
-
- connPtr->startClientEncryption(
- [connPtr, out]() {
- // LOG_TRACE << "SSL established";
- connPtr->send(out);
- },
- false, false);
-
- email->m_status = EMail::Auth;
- } else if (email->m_status == EMail::HandShake && responseCode == "250") {
- std::string outMsg;
- trantor::MsgBuffer out;
-
- outMsg.append("STARTTLS");
- outMsg.append("\r\n");
-
- out.append(outMsg.data(), outMsg.size());
-
- connPtr->send(std::move(out));
-
- email->m_status = EMail::HandShake;
- } else if (email->m_status == EMail::Auth && responseCode == "250") {
- trantor::MsgBuffer out;
- std::string outMsg;
-
- outMsg.append("AUTH LOGIN");
- outMsg.append("\r\n");
-
- out.append(outMsg.data(), outMsg.size());
-
- connPtr->send(std::move(out));
-
- email->m_status = EMail::User;
- } else if (email->m_status == EMail::User && responseCode == "334") {
- trantor::MsgBuffer out;
- std::string outMsg;
-
- std::string secret(email->m_user);
-
- // outMsg.append(base64_encode(reinterpret_cast(secret.c_str()), secret.length()));
- outMsg.append(drogon::utils::base64Encode(
- reinterpret_cast(secret.c_str()),
- secret.length()));
-
- outMsg.append("\r\n");
-
- out.append(outMsg.data(), outMsg.size());
-
- connPtr->send(std::move(out));
-
- email->m_status = EMail::Pass;
- } else if (email->m_status == EMail::Pass && responseCode == "334") {
- trantor::MsgBuffer out;
- std::string outMsg;
-
- std::string secret(email->m_passwd);
-
- outMsg.append(drogon::utils::base64Encode(
- reinterpret_cast(secret.c_str()),
- secret.length()));
- outMsg.append("\r\n");
-
- out.append(outMsg.data(), outMsg.size());
-
- connPtr->send(std::move(out));
-
- email->m_status = EMail::Mail;
- } else if (email->m_status == EMail::Mail && responseCode == "235") {
- trantor::MsgBuffer out;
- std::string outMsg;
-
- outMsg.append("MAIL FROM:<");
- outMsg.append(email->m_from);
- outMsg.append(">\r\n");
-
- out.append(outMsg.data(), outMsg.size());
-
- connPtr->send(std::move(out));
-
- email->m_status = EMail::Rcpt;
- } else if (email->m_status == EMail::Rcpt && responseCode == "250") {
- trantor::MsgBuffer out;
- std::string outMsg;
-
- outMsg.append("RCPT TO:<");
- outMsg.append(email->m_to);
- outMsg.append(">\r\n");
-
- out.append(outMsg.data(), outMsg.size());
-
- connPtr->send(std::move(out));
-
- email->m_status = EMail::Data;
- } else if (email->m_status == EMail::Data && responseCode == "250") {
- trantor::MsgBuffer out;
- std::string outMsg;
-
- outMsg.append("DATA");
- outMsg.append("\r\n");
-
- out.append(outMsg.data(), outMsg.size());
-
- connPtr->send(std::move(out));
-
- email->m_status = EMail::Body;
- } else if (email->m_status == EMail::Body && responseCode == "354") {
- trantor::MsgBuffer out;
- std::string outMsg;
- std::time_t t = std::time(nullptr);
- char buf[100];
- std::strftime(buf, 100, "%a, %d %b %Y %T %z", std::localtime(&t));
-
- outMsg.append("To: " + email->m_to + "\r\n");
- outMsg.append("From: " + email->m_from + "\r\n");
- outMsg.append("Date: " + std::string(buf) + "\r\n");
- if (email->m_isHTML) {
- outMsg.append("Content-Type: text/html;\r\n");
- }
- outMsg.append("Subject: " + email->m_subject + "\r\n\r\n");
-
- outMsg.append(email->m_content);
- outMsg.append("\r\n.\r\n");
-
- out.append(outMsg.data(), outMsg.size());
-
- connPtr->send(std::move(out));
-
- email->m_status = EMail::Quit;
- } else if (email->m_status == EMail::Quit && responseCode == "250") {
- trantor::MsgBuffer out;
- std::string outMsg;
-
- outMsg.append("QUIT");
- outMsg.append("\r\n");
-
- out.append(outMsg.data(), outMsg.size());
-
- connPtr->send(std::move(out));
-
- email->m_status = EMail::Close;
- } else if (email->m_status == EMail::Close) {
- /*Callback here for succeed delivery is probable*/
- cb("EMail sent. ID : " + email->m_uuid);
- return;
- } else {
- email->m_status = EMail::Close;
- /*Callback here for notification is probable*/
- cb(receivedMsg);
- }
-}
-
-std::string
-SMTPMail::sendEmail(const std::string &mailServer, const uint16_t &port,
- const std::string &from, const std::string &to,
- const std::string &subject, const std::string &content,
- const std::string &user, const std::string &passwd,
- bool isHTML,
- const std::function &cb) {
- if (mailServer.empty() || from.empty() || to.empty() || subject.empty() ||
- user.empty() || passwd.empty()) {
- LOG_WARN << "Invalid input(s) - "
- << "\nServer : " << mailServer << "\nPort : " << port
- << "\nfrom : " << from << "\nto : " << to
- << "\nsubject : " << subject << "\nuser : " << user
- << "\npasswd : " << passwd;
- return {};
- }
-
- static auto hasLineBreak = [](const std::string &msg) {
- if (std::string::npos != msg.find_first_of("\n") ||
- std::string::npos != msg.find_first_of("\r")) {
- return true;
- }
- return false;
- };
-
- if (hasLineBreak(from)) {
- LOG_WARN << "Invalid \"FROM\" data : " << from;
- return {};
- }
- if (hasLineBreak(to)) {
- LOG_WARN << "Invalid \"TO\" data : " << to;
- return {};
- }
- if (hasLineBreak(subject)) {
- LOG_WARN << "Invalid \"SUBJECT\" data : " << subject.data();
- return {};
- }
-
- LOG_TRACE << "New TcpClient : " << mailServer << ":" << port;
-
- // Create the email
- auto email = std::make_shared(from, to, subject, content, user, passwd,
- isHTML, nullptr);
-
- auto resolver = app().getResolver();
- resolver->resolve(
- mailServer, [email, port, cb](const trantor::InetAddress &addr) {
- constexpr size_t defaultLoopIdA = 10;
- constexpr size_t defaultLoopIdB = 9;
- auto loopA = app().getIOLoop(defaultLoopIdA);
- auto loopB = app().getIOLoop(defaultLoopIdB);
-
- if ( loopA == loopB ) {
- LOG_WARN << "Please provide at least 2 threads for this plugin";
- return;
- }
-
- auto loop = loopA->isInLoopThread() ? loopB : loopA;
-
- assert(loop); // Should never be null
- trantor::InetAddress addr_(addr.toIp(), port, false);
- auto tcpSocket =
- std::make_shared(loop, addr_, "SMTPMail");
-
- email->m_socket = tcpSocket;
-
- std::weak_ptr email_wptr = email;
-
- EMail::m_emails.emplace(email->m_uuid,
- email); // Assuming there is no uuid collision
- tcpSocket->setConnectionCallback(
- [email_wptr](const trantor::TcpConnectionPtr &connPtr) {
- auto email_ptr = email_wptr.lock();
- if (!email_ptr) {
- LOG_WARN << "EMail pointer gone";
- return;
- }
- if (connPtr->connected()) {
- // send request;
- LOG_TRACE << "Connection established!";
- } else {
- LOG_TRACE << "Connection disconnect";
- EMail::m_emails.erase(
- email_ptr->m_uuid); // Remove the email in list
- // thisPtr->onError(std::string("ReqResult::NetworkFailure"));
- }
- });
- tcpSocket->setConnectionErrorCallback([email_wptr]() {
- auto email_ptr = email_wptr.lock();
- if (!email_ptr) {
- LOG_ERROR << "EMail pointer gone";
- return;
- }
- // can't connect to server
- LOG_ERROR << "Bad Server address";
- EMail::m_emails.erase(email_ptr->m_uuid); // Remove the email in list
- // thisPtr->onError(std::string("ReqResult::BadServerAddress"));
- });
- auto cb_(cb ? cb : [](const std::string &msg) {
- LOG_INFO << "Default email callback : " << msg;
- });
- tcpSocket->setMessageCallback(
- [email_wptr, cb_](const trantor::TcpConnectionPtr &connPtr,
- trantor::MsgBuffer *msg) {
- auto email_ptr = email_wptr.lock();
- if (!email_ptr) {
- LOG_ERROR << "EMail pointer gone";
- return;
- }
- // email->m_socket->disconnect();
- messagesHandle(connPtr, msg, email_ptr, cb_);
- });
- tcpSocket->connect(); // Start trying to send the email
- });
- return email->m_uuid;
-}
diff --git a/backend/SMTPMail-drogon-master/SMTPMail.h b/backend/SMTPMail-drogon-master/SMTPMail.h
deleted file mode 100644
index 2170bb4..0000000
--- a/backend/SMTPMail-drogon-master/SMTPMail.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/**
- *
- * SMTPMail.h
- *
- * This plugin is for SMTP mail delievery for the Drogon web-framework.
-Implementation
- * reference from the project "SMTPClient" with Qt5 by kelvins. Please check out
- * https://github.com/kelvins/SMTPClient.
-
-Copyright 2020 ihmc3jn09hk
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
- */
-
-#pragma once
-
-#include
-
-class SMTPMail : public drogon::Plugin {
-public:
- SMTPMail() = default;
- /// This method must be called by drogon to initialize and start the plugin.
- /// It must be implemented by the user.
- void initAndStart(const Json::Value &config) override;
-
- /// This method must be called by drogon to shutdown the plugin.
- /// It must be implemented by the user.
- void shutdown() override;
-
- /** Send an email
- * return : An ID of the email.
- */
- std::string sendEmail(
- const std::string
- &mailServer, // Mail server address/dns E.g. 127.0.0.1/smtp.mail.com
- const uint16_t &port, // Port E.g. 587
- const std::string &from, // Send from whom E.g. drogon@gmail.com
- const std::string &to, // Reciever E.g. drogon@yahoo.com
- const std::string &subject, // The email title/subject
- const std::string &content, // The email content.
- const std::string &user, // User (Usually same as "from")
- const std::string &passwd, // Password
- bool isHTML, // content type
- const std::function &cb = {}
- // The callback for email sent notification
- );
-};
diff --git a/backend/default_config.json b/backend/default_config.json
deleted file mode 100644
index 847bb4b..0000000
--- a/backend/default_config.json
+++ /dev/null
@@ -1,11 +0,0 @@
-{
- "gitlab_id": "",
- "gitlab_secret": "",
- "gitlab_url": "",
- "gitlab_api_url": "",
- "gitlab_redirect_url": "",
- "smtp_server": "",
- "smtp_port": 25,
- "smtp_user": "",
- "smtp_password": ""
-}
\ No newline at end of file
diff --git a/backend/diesel.toml b/backend/diesel.toml
new file mode 100644
index 0000000..35a12ff
--- /dev/null
+++ b/backend/diesel.toml
@@ -0,0 +1,8 @@
+# For documentation on how to configure this file,
+# see https://diesel.rs/guides/configuring-diesel-cli
+
+[print_schema]
+file = "src/schema.rs"
+
+[migrations_directory]
+dir = "migrations"
diff --git a/backend/migrations/.keep b/backend/migrations/.keep
new file mode 100644
index 0000000..e69de29
diff --git a/backend/migrations/2022-10-05-145523_init/down.sql b/backend/migrations/2022-10-05-145523_init/down.sql
new file mode 100644
index 0000000..6700746
--- /dev/null
+++ b/backend/migrations/2022-10-05-145523_init/down.sql
@@ -0,0 +1,3 @@
+DROP TABLE inode;
+DROP TABLE user;
+DROP TABLE tokens
\ No newline at end of file
diff --git a/backend/migrations/2022-10-05-145523_init/up.sql b/backend/migrations/2022-10-05-145523_init/up.sql
new file mode 100644
index 0000000..32f12ca
--- /dev/null
+++ b/backend/migrations/2022-10-05-145523_init/up.sql
@@ -0,0 +1,28 @@
+CREATE TABLE tokens (
+ 'id' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
+ 'owner_id' INTEGER NOT NULL,
+ 'exp' INT8 NOT NULL
+);
+
+CREATE TABLE user (
+ 'id' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
+ 'gitlab' BOOLEAN NOT NULL,
+ 'name' TEXT NOT NULL,
+ 'password' TEXT NOT NULL,
+ 'role' INT2 NOT NULL,
+ 'root_id' INTEGER NOT NULL,
+ 'tfa_type' INT2 NOT NULL,
+ 'tfa_secret' BLOB,
+ 'gitlab_at' TEXT,
+ 'gitlab_rt' TEXT
+);
+
+CREATE TABLE inode (
+ 'id' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
+ 'is_file' BOOLEAN NOT NULL,
+ 'name' TEXT NOT NULL,
+ 'parent_id' INTEGER,
+ 'owner_id' INTEGER NOT NULL,
+ 'size' INT8,
+ 'has_preview' BOOLEAN NOT NULL
+)
diff --git a/backend/model/Inode.cc b/backend/model/Inode.cc
deleted file mode 100644
index 5819a51..0000000
--- a/backend/model/Inode.cc
+++ /dev/null
@@ -1,1254 +0,0 @@
-/**
- *
- * Inode.cc
- * DO NOT EDIT. This file is generated by drogon_ctl
- *
- */
-
-#include "Inode.h"
-#include "drogon/utils/Utilities.h"
-#include
-
-using namespace drogon;
-using namespace drogon::orm;
-using namespace drogon_model::sqlite3;
-
-const std::string Inode::Cols::_id = "id";
-const std::string Inode::Cols::_is_file = "is_file";
-const std::string Inode::Cols::_name = "name";
-const std::string Inode::Cols::_parent_id = "parent_id";
-const std::string Inode::Cols::_owner_id = "owner_id";
-const std::string Inode::Cols::_size = "size";
-const std::string Inode::Cols::_has_preview = "has_preview";
-const std::string Inode::primaryKeyName = "id";
-const bool Inode::hasPrimaryKey = true;
-const std::string Inode::tableName = "inode";
-
-const std::vector Inode::metaData_={
-{"id","uint64_t","integer",8,1,1,1},
-{"is_file","uint64_t","integer",8,0,0,1},
-{"name","std::string","text",0,0,0,0},
-{"parent_id","uint64_t","integer",8,0,0,0},
-{"owner_id","uint64_t","integer",8,0,0,1},
-{"size","uint64_t","integer",8,0,0,0},
-{"has_preview","uint64_t","integer",8,0,0,1}
-};
-const std::string &Inode::getColumnName(size_t index) noexcept(false)
-{
- assert(index < metaData_.size());
- return metaData_[index].colName_;
-}
-Inode::Inode(const Row &r, const ssize_t indexOffset) noexcept
-{
- if(indexOffset < 0)
- {
- if(!r["id"].isNull())
- {
- id_=std::make_shared(r["id"].as());
- }
- if(!r["is_file"].isNull())
- {
- isFile_=std::make_shared(r["is_file"].as());
- }
- if(!r["name"].isNull())
- {
- name_=std::make_shared(r["name"].as());
- }
- if(!r["parent_id"].isNull())
- {
- parentId_=std::make_shared(r["parent_id"].as());
- }
- if(!r["owner_id"].isNull())
- {
- ownerId_=std::make_shared(r["owner_id"].as());
- }
- if(!r["size"].isNull())
- {
- size_=std::make_shared(r["size"].as());
- }
- if(!r["has_preview"].isNull())
- {
- hasPreview_=std::make_shared(r["has_preview"].as());
- }
- }
- else
- {
- size_t offset = (size_t)indexOffset;
- if(offset + 7 > r.size())
- {
- LOG_FATAL << "Invalid SQL result for this model";
- return;
- }
- size_t index;
- index = offset + 0;
- if(!r[index].isNull())
- {
- id_=std::make_shared(r[index].as());
- }
- index = offset + 1;
- if(!r[index].isNull())
- {
- isFile_=std::make_shared(r[index].as());
- }
- index = offset + 2;
- if(!r[index].isNull())
- {
- name_=std::make_shared(r[index].as());
- }
- index = offset + 3;
- if(!r[index].isNull())
- {
- parentId_=std::make_shared(r[index].as());
- }
- index = offset + 4;
- if(!r[index].isNull())
- {
- ownerId_=std::make_shared(r[index].as());
- }
- index = offset + 5;
- if(!r[index].isNull())
- {
- size_=std::make_shared(r[index].as());
- }
- index = offset + 6;
- if(!r[index].isNull())
- {
- hasPreview_=std::make_shared(r[index].as());
- }
- }
-
-}
-
-Inode::Inode(const Json::Value &pJson, const std::vector &pMasqueradingVector) noexcept(false)
-{
- if(pMasqueradingVector.size() != 7)
- {
- LOG_ERROR << "Bad masquerading vector";
- return;
- }
- if(!pMasqueradingVector[0].empty() && pJson.isMember(pMasqueradingVector[0]))
- {
- dirtyFlag_[0] = true;
- if(!pJson[pMasqueradingVector[0]].isNull())
- {
- id_=std::make_shared((uint64_t)pJson[pMasqueradingVector[0]].asUInt64());
- }
- }
- if(!pMasqueradingVector[1].empty() && pJson.isMember(pMasqueradingVector[1]))
- {
- dirtyFlag_[1] = true;
- if(!pJson[pMasqueradingVector[1]].isNull())
- {
- isFile_=std::make_shared((uint64_t)pJson[pMasqueradingVector[1]].asUInt64());
- }
- }
- if(!pMasqueradingVector[2].empty() && pJson.isMember(pMasqueradingVector[2]))
- {
- dirtyFlag_[2] = true;
- if(!pJson[pMasqueradingVector[2]].isNull())
- {
- name_=std::make_shared(pJson[pMasqueradingVector[2]].asString());
- }
- }
- if(!pMasqueradingVector[3].empty() && pJson.isMember(pMasqueradingVector[3]))
- {
- dirtyFlag_[3] = true;
- if(!pJson[pMasqueradingVector[3]].isNull())
- {
- parentId_=std::make_shared((uint64_t)pJson[pMasqueradingVector[3]].asUInt64());
- }
- }
- if(!pMasqueradingVector[4].empty() && pJson.isMember(pMasqueradingVector[4]))
- {
- dirtyFlag_[4] = true;
- if(!pJson[pMasqueradingVector[4]].isNull())
- {
- ownerId_=std::make_shared((uint64_t)pJson[pMasqueradingVector[4]].asUInt64());
- }
- }
- if(!pMasqueradingVector[5].empty() && pJson.isMember(pMasqueradingVector[5]))
- {
- dirtyFlag_[5] = true;
- if(!pJson[pMasqueradingVector[5]].isNull())
- {
- size_=std::make_shared((uint64_t)pJson[pMasqueradingVector[5]].asUInt64());
- }
- }
- if(!pMasqueradingVector[6].empty() && pJson.isMember(pMasqueradingVector[6]))
- {
- dirtyFlag_[6] = true;
- if(!pJson[pMasqueradingVector[6]].isNull())
- {
- hasPreview_=std::make_shared((uint64_t)pJson[pMasqueradingVector[6]].asUInt64());
- }
- }
-}
-
-Inode::Inode(const Json::Value &pJson) noexcept(false)
-{
- if(pJson.isMember("id"))
- {
- dirtyFlag_[0]=true;
- if(!pJson["id"].isNull())
- {
- id_=std::make_shared((uint64_t)pJson["id"].asUInt64());
- }
- }
- if(pJson.isMember("is_file"))
- {
- dirtyFlag_[1]=true;
- if(!pJson["is_file"].isNull())
- {
- isFile_=std::make_shared((uint64_t)pJson["is_file"].asUInt64());
- }
- }
- if(pJson.isMember("name"))
- {
- dirtyFlag_[2]=true;
- if(!pJson["name"].isNull())
- {
- name_=std::make_shared(pJson["name"].asString());
- }
- }
- if(pJson.isMember("parent_id"))
- {
- dirtyFlag_[3]=true;
- if(!pJson["parent_id"].isNull())
- {
- parentId_=std::make_shared((uint64_t)pJson["parent_id"].asUInt64());
- }
- }
- if(pJson.isMember("owner_id"))
- {
- dirtyFlag_[4]=true;
- if(!pJson["owner_id"].isNull())
- {
- ownerId_=std::make_shared((uint64_t)pJson["owner_id"].asUInt64());
- }
- }
- if(pJson.isMember("size"))
- {
- dirtyFlag_[5]=true;
- if(!pJson["size"].isNull())
- {
- size_=std::make_shared((uint64_t)pJson["size"].asUInt64());
- }
- }
- if(pJson.isMember("has_preview"))
- {
- dirtyFlag_[6]=true;
- if(!pJson["has_preview"].isNull())
- {
- hasPreview_=std::make_shared((uint64_t)pJson["has_preview"].asUInt64());
- }
- }
-}
-
-void Inode::updateByMasqueradedJson(const Json::Value &pJson,
- const std::vector &pMasqueradingVector) noexcept(false)
-{
- if(pMasqueradingVector.size() != 7)
- {
- LOG_ERROR << "Bad masquerading vector";
- return;
- }
- if(!pMasqueradingVector[0].empty() && pJson.isMember(pMasqueradingVector[0]))
- {
- if(!pJson[pMasqueradingVector[0]].isNull())
- {
- id_=std::make_shared((uint64_t)pJson[pMasqueradingVector[0]].asUInt64());
- }
- }
- if(!pMasqueradingVector[1].empty() && pJson.isMember(pMasqueradingVector[1]))
- {
- dirtyFlag_[1] = true;
- if(!pJson[pMasqueradingVector[1]].isNull())
- {
- isFile_=std::make_shared((uint64_t)pJson[pMasqueradingVector[1]].asUInt64());
- }
- }
- if(!pMasqueradingVector[2].empty() && pJson.isMember(pMasqueradingVector[2]))
- {
- dirtyFlag_[2] = true;
- if(!pJson[pMasqueradingVector[2]].isNull())
- {
- name_=std::make_shared(pJson[pMasqueradingVector[2]].asString());
- }
- }
- if(!pMasqueradingVector[3].empty() && pJson.isMember(pMasqueradingVector[3]))
- {
- dirtyFlag_[3] = true;
- if(!pJson[pMasqueradingVector[3]].isNull())
- {
- parentId_=std::make_shared((uint64_t)pJson[pMasqueradingVector[3]].asUInt64());
- }
- }
- if(!pMasqueradingVector[4].empty() && pJson.isMember(pMasqueradingVector[4]))
- {
- dirtyFlag_[4] = true;
- if(!pJson[pMasqueradingVector[4]].isNull())
- {
- ownerId_=std::make_shared((uint64_t)pJson[pMasqueradingVector[4]].asUInt64());
- }
- }
- if(!pMasqueradingVector[5].empty() && pJson.isMember(pMasqueradingVector[5]))
- {
- dirtyFlag_[5] = true;
- if(!pJson[pMasqueradingVector[5]].isNull())
- {
- size_=std::make_shared((uint64_t)pJson[pMasqueradingVector[5]].asUInt64());
- }
- }
- if(!pMasqueradingVector[6].empty() && pJson.isMember(pMasqueradingVector[6]))
- {
- dirtyFlag_[6] = true;
- if(!pJson[pMasqueradingVector[6]].isNull())
- {
- hasPreview_=std::make_shared((uint64_t)pJson[pMasqueradingVector[6]].asUInt64());
- }
- }
-}
-
-void Inode::updateByJson(const Json::Value &pJson) noexcept(false)
-{
- if(pJson.isMember("id"))
- {
- if(!pJson["id"].isNull())
- {
- id_=std::make_shared((uint64_t)pJson["id"].asUInt64());
- }
- }
- if(pJson.isMember("is_file"))
- {
- dirtyFlag_[1] = true;
- if(!pJson["is_file"].isNull())
- {
- isFile_=std::make_shared((uint64_t)pJson["is_file"].asUInt64());
- }
- }
- if(pJson.isMember("name"))
- {
- dirtyFlag_[2] = true;
- if(!pJson["name"].isNull())
- {
- name_=std::make_shared(pJson["name"].asString());
- }
- }
- if(pJson.isMember("parent_id"))
- {
- dirtyFlag_[3] = true;
- if(!pJson["parent_id"].isNull())
- {
- parentId_=std::make_shared((uint64_t)pJson["parent_id"].asUInt64());
- }
- }
- if(pJson.isMember("owner_id"))
- {
- dirtyFlag_[4] = true;
- if(!pJson["owner_id"].isNull())
- {
- ownerId_=std::make_shared((uint64_t)pJson["owner_id"].asUInt64());
- }
- }
- if(pJson.isMember("size"))
- {
- dirtyFlag_[5] = true;
- if(!pJson["size"].isNull())
- {
- size_=std::make_shared((uint64_t)pJson["size"].asUInt64());
- }
- }
- if(pJson.isMember("has_preview"))
- {
- dirtyFlag_[6] = true;
- if(!pJson["has_preview"].isNull())
- {
- hasPreview_=std::make_shared((uint64_t)pJson["has_preview"].asUInt64());
- }
- }
-}
-
-const uint64_t &Inode::getValueOfId() const noexcept
-{
- const static uint64_t defaultValue = uint64_t();
- if(id_)
- return *id_;
- return defaultValue;
-}
-const std::shared_ptr &Inode::getId() const noexcept
-{
- return id_;
-}
-void Inode::setId(const uint64_t &pId) noexcept
-{
- id_ = std::make_shared(pId);
- dirtyFlag_[0] = true;
-}
-const typename Inode::PrimaryKeyType & Inode::getPrimaryKey() const
-{
- assert(id_);
- return *id_;
-}
-
-const uint64_t &Inode::getValueOfIsFile() const noexcept
-{
- const static uint64_t defaultValue = uint64_t();
- if(isFile_)
- return *isFile_;
- return defaultValue;
-}
-const std::shared_ptr &Inode::getIsFile() const noexcept
-{
- return isFile_;
-}
-void Inode::setIsFile(const uint64_t &pIsFile) noexcept
-{
- isFile_ = std::make_shared(pIsFile);
- dirtyFlag_[1] = true;
-}
-
-const std::string &Inode::getValueOfName() const noexcept
-{
- const static std::string defaultValue = std::string();
- if(name_)
- return *name_;
- return defaultValue;
-}
-const std::shared_ptr &Inode::getName() const noexcept
-{
- return name_;
-}
-void Inode::setName(const std::string &pName) noexcept
-{
- name_ = std::make_shared(pName);
- dirtyFlag_[2] = true;
-}
-void Inode::setName(std::string &&pName) noexcept
-{
- name_ = std::make_shared(std::move(pName));
- dirtyFlag_[2] = true;
-}
-void Inode::setNameToNull() noexcept
-{
- name_.reset();
- dirtyFlag_[2] = true;
-}
-
-const uint64_t &Inode::getValueOfParentId() const noexcept
-{
- const static uint64_t defaultValue = uint64_t();
- if(parentId_)
- return *parentId_;
- return defaultValue;
-}
-const std::shared_ptr &Inode::getParentId() const noexcept
-{
- return parentId_;
-}
-void Inode::setParentId(const uint64_t &pParentId) noexcept
-{
- parentId_ = std::make_shared(pParentId);
- dirtyFlag_[3] = true;
-}
-void Inode::setParentIdToNull() noexcept
-{
- parentId_.reset();
- dirtyFlag_[3] = true;
-}
-
-const uint64_t &Inode::getValueOfOwnerId() const noexcept
-{
- const static uint64_t defaultValue = uint64_t();
- if(ownerId_)
- return *ownerId_;
- return defaultValue;
-}
-const std::shared_ptr &Inode::getOwnerId() const noexcept
-{
- return ownerId_;
-}
-void Inode::setOwnerId(const uint64_t &pOwnerId) noexcept
-{
- ownerId_ = std::make_shared(pOwnerId);
- dirtyFlag_[4] = true;
-}
-
-const uint64_t &Inode::getValueOfSize() const noexcept
-{
- const static uint64_t defaultValue = uint64_t();
- if(size_)
- return *size_;
- return defaultValue;
-}
-const std::shared_ptr &Inode::getSize() const noexcept
-{
- return size_;
-}
-void Inode::setSize(const uint64_t &pSize) noexcept
-{
- size_ = std::make_shared(pSize);
- dirtyFlag_[5] = true;
-}
-void Inode::setSizeToNull() noexcept
-{
- size_.reset();
- dirtyFlag_[5] = true;
-}
-
-const uint64_t &Inode::getValueOfHasPreview() const noexcept
-{
- const static uint64_t defaultValue = uint64_t();
- if(hasPreview_)
- return *hasPreview_;
- return defaultValue;
-}
-const std::shared_ptr &Inode::getHasPreview() const noexcept
-{
- return hasPreview_;
-}
-void Inode::setHasPreview(const uint64_t &pHasPreview) noexcept
-{
- hasPreview_ = std::make_shared(pHasPreview);
- dirtyFlag_[6] = true;
-}
-
-void Inode::updateId(const uint64_t id)
-{
- id_ = std::make_shared(id);
-}
-
-const std::vector &Inode::insertColumns() noexcept
-{
- static const std::vector inCols={
- "is_file",
- "name",
- "parent_id",
- "owner_id",
- "size",
- "has_preview"
- };
- return inCols;
-}
-
-void Inode::outputArgs(drogon::orm::internal::SqlBinder &binder) const
-{
- if(dirtyFlag_[1])
- {
- if(getIsFile())
- {
- binder << getValueOfIsFile();
- }
- else
- {
- binder << nullptr;
- }
- }
- if(dirtyFlag_[2])
- {
- if(getName())
- {
- binder << getValueOfName();
- }
- else
- {
- binder << nullptr;
- }
- }
- if(dirtyFlag_[3])
- {
- if(getParentId())
- {
- binder << getValueOfParentId();
- }
- else
- {
- binder << nullptr;
- }
- }
- if(dirtyFlag_[4])
- {
- if(getOwnerId())
- {
- binder << getValueOfOwnerId();
- }
- else
- {
- binder << nullptr;
- }
- }
- if(dirtyFlag_[5])
- {
- if(getSize())
- {
- binder << getValueOfSize();
- }
- else
- {
- binder << nullptr;
- }
- }
- if(dirtyFlag_[6])
- {
- if(getHasPreview())
- {
- binder << getValueOfHasPreview();
- }
- else
- {
- binder << nullptr;
- }
- }
-}
-
-const std::vector Inode::updateColumns() const
-{
- std::vector ret;
- if(dirtyFlag_[1])
- {
- ret.push_back(getColumnName(1));
- }
- if(dirtyFlag_[2])
- {
- ret.push_back(getColumnName(2));
- }
- if(dirtyFlag_[3])
- {
- ret.push_back(getColumnName(3));
- }
- if(dirtyFlag_[4])
- {
- ret.push_back(getColumnName(4));
- }
- if(dirtyFlag_[5])
- {
- ret.push_back(getColumnName(5));
- }
- if(dirtyFlag_[6])
- {
- ret.push_back(getColumnName(6));
- }
- return ret;
-}
-
-void Inode::updateArgs(drogon::orm::internal::SqlBinder &binder) const
-{
- if(dirtyFlag_[1])
- {
- if(getIsFile())
- {
- binder << getValueOfIsFile();
- }
- else
- {
- binder << nullptr;
- }
- }
- if(dirtyFlag_[2])
- {
- if(getName())
- {
- binder << getValueOfName();
- }
- else
- {
- binder << nullptr;
- }
- }
- if(dirtyFlag_[3])
- {
- if(getParentId())
- {
- binder << getValueOfParentId();
- }
- else
- {
- binder << nullptr;
- }
- }
- if(dirtyFlag_[4])
- {
- if(getOwnerId())
- {
- binder << getValueOfOwnerId();
- }
- else
- {
- binder << nullptr;
- }
- }
- if(dirtyFlag_[5])
- {
- if(getSize())
- {
- binder << getValueOfSize();
- }
- else
- {
- binder << nullptr;
- }
- }
- if(dirtyFlag_[6])
- {
- if(getHasPreview())
- {
- binder << getValueOfHasPreview();
- }
- else
- {
- binder << nullptr;
- }
- }
-}
-Json::Value Inode::toJson() const
-{
- Json::Value ret;
- if(getId())
- {
- ret["id"]=(Json::UInt64)getValueOfId();
- }
- else
- {
- ret["id"]=Json::Value();
- }
- if(getIsFile())
- {
- ret["is_file"]=(Json::UInt64)getValueOfIsFile();
- }
- else
- {
- ret["is_file"]=Json::Value();
- }
- if(getName())
- {
- ret["name"]=getValueOfName();
- }
- else
- {
- ret["name"]=Json::Value();
- }
- if(getParentId())
- {
- ret["parent_id"]=(Json::UInt64)getValueOfParentId();
- }
- else
- {
- ret["parent_id"]=Json::Value();
- }
- if(getOwnerId())
- {
- ret["owner_id"]=(Json::UInt64)getValueOfOwnerId();
- }
- else
- {
- ret["owner_id"]=Json::Value();
- }
- if(getSize())
- {
- ret["size"]=(Json::UInt64)getValueOfSize();
- }
- else
- {
- ret["size"]=Json::Value();
- }
- if(getHasPreview())
- {
- ret["has_preview"]=(Json::UInt64)getValueOfHasPreview();
- }
- else
- {
- ret["has_preview"]=Json::Value();
- }
- return ret;
-}
-
-Json::Value Inode::toMasqueradedJson(
- const std::vector &pMasqueradingVector) const
-{
- Json::Value ret;
- if(pMasqueradingVector.size() == 7)
- {
- if(!pMasqueradingVector[0].empty())
- {
- if(getId())
- {
- ret[pMasqueradingVector[0]]=(Json::UInt64)getValueOfId();
- }
- else
- {
- ret[pMasqueradingVector[0]]=Json::Value();
- }
- }
- if(!pMasqueradingVector[1].empty())
- {
- if(getIsFile())
- {
- ret[pMasqueradingVector[1]]=(Json::UInt64)getValueOfIsFile();
- }
- else
- {
- ret[pMasqueradingVector[1]]=Json::Value();
- }
- }
- if(!pMasqueradingVector[2].empty())
- {
- if(getName())
- {
- ret[pMasqueradingVector[2]]=getValueOfName();
- }
- else
- {
- ret[pMasqueradingVector[2]]=Json::Value();
- }
- }
- if(!pMasqueradingVector[3].empty())
- {
- if(getParentId())
- {
- ret[pMasqueradingVector[3]]=(Json::UInt64)getValueOfParentId();
- }
- else
- {
- ret[pMasqueradingVector[3]]=Json::Value();
- }
- }
- if(!pMasqueradingVector[4].empty())
- {
- if(getOwnerId())
- {
- ret[pMasqueradingVector[4]]=(Json::UInt64)getValueOfOwnerId();
- }
- else
- {
- ret[pMasqueradingVector[4]]=Json::Value();
- }
- }
- if(!pMasqueradingVector[5].empty())
- {
- if(getSize())
- {
- ret[pMasqueradingVector[5]]=(Json::UInt64)getValueOfSize();
- }
- else
- {
- ret[pMasqueradingVector[5]]=Json::Value();
- }
- }
- if(!pMasqueradingVector[6].empty())
- {
- if(getHasPreview())
- {
- ret[pMasqueradingVector[6]]=(Json::UInt64)getValueOfHasPreview();
- }
- else
- {
- ret[pMasqueradingVector[6]]=Json::Value();
- }
- }
- return ret;
- }
- LOG_ERROR << "Masquerade failed";
- if(getId())
- {
- ret["id"]=(Json::UInt64)getValueOfId();
- }
- else
- {
- ret["id"]=Json::Value();
- }
- if(getIsFile())
- {
- ret["is_file"]=(Json::UInt64)getValueOfIsFile();
- }
- else
- {
- ret["is_file"]=Json::Value();
- }
- if(getName())
- {
- ret["name"]=getValueOfName();
- }
- else
- {
- ret["name"]=Json::Value();
- }
- if(getParentId())
- {
- ret["parent_id"]=(Json::UInt64)getValueOfParentId();
- }
- else
- {
- ret["parent_id"]=Json::Value();
- }
- if(getOwnerId())
- {
- ret["owner_id"]=(Json::UInt64)getValueOfOwnerId();
- }
- else
- {
- ret["owner_id"]=Json::Value();
- }
- if(getSize())
- {
- ret["size"]=(Json::UInt64)getValueOfSize();
- }
- else
- {
- ret["size"]=Json::Value();
- }
- if(getHasPreview())
- {
- ret["has_preview"]=(Json::UInt64)getValueOfHasPreview();
- }
- else
- {
- ret["has_preview"]=Json::Value();
- }
- return ret;
-}
-
-bool Inode::validateJsonForCreation(const Json::Value &pJson, std::string &err)
-{
- if(pJson.isMember("id"))
- {
- if(!validJsonOfField(0, "id", pJson["id"], err, true))
- return false;
- }
- if(pJson.isMember("is_file"))
- {
- if(!validJsonOfField(1, "is_file", pJson["is_file"], err, true))
- return false;
- }
- else
- {
- err="The is_file column cannot be null";
- return false;
- }
- if(pJson.isMember("name"))
- {
- if(!validJsonOfField(2, "name", pJson["name"], err, true))
- return false;
- }
- if(pJson.isMember("parent_id"))
- {
- if(!validJsonOfField(3, "parent_id", pJson["parent_id"], err, true))
- return false;
- }
- if(pJson.isMember("owner_id"))
- {
- if(!validJsonOfField(4, "owner_id", pJson["owner_id"], err, true))
- return false;
- }
- else
- {
- err="The owner_id column cannot be null";
- return false;
- }
- if(pJson.isMember("size"))
- {
- if(!validJsonOfField(5, "size", pJson["size"], err, true))
- return false;
- }
- if(pJson.isMember("has_preview"))
- {
- if(!validJsonOfField(6, "has_preview", pJson["has_preview"], err, true))
- return false;
- }
- else
- {
- err="The has_preview column cannot be null";
- return false;
- }
- return true;
-}
-bool Inode::validateMasqueradedJsonForCreation(const Json::Value &pJson,
- const std::vector &pMasqueradingVector,
- std::string &err)
-{
- if(pMasqueradingVector.size() != 7)
- {
- err = "Bad masquerading vector";
- return false;
- }
- try {
- if(!pMasqueradingVector[0].empty())
- {
- if(pJson.isMember(pMasqueradingVector[0]))
- {
- if(!validJsonOfField(0, pMasqueradingVector[0], pJson[pMasqueradingVector[0]], err, true))
- return false;
- }
- }
- if(!pMasqueradingVector[1].empty())
- {
- if(pJson.isMember(pMasqueradingVector[1]))
- {
- if(!validJsonOfField(1, pMasqueradingVector[1], pJson[pMasqueradingVector[1]], err, true))
- return false;
- }
- else
- {
- err="The " + pMasqueradingVector[1] + " column cannot be null";
- return false;
- }
- }
- if(!pMasqueradingVector[2].empty())
- {
- if(pJson.isMember(pMasqueradingVector[2]))
- {
- if(!validJsonOfField(2, pMasqueradingVector[2], pJson[pMasqueradingVector[2]], err, true))
- return false;
- }
- }
- if(!pMasqueradingVector[3].empty())
- {
- if(pJson.isMember(pMasqueradingVector[3]))
- {
- if(!validJsonOfField(3, pMasqueradingVector[3], pJson[pMasqueradingVector[3]], err, true))
- return false;
- }
- }
- if(!pMasqueradingVector[4].empty())
- {
- if(pJson.isMember(pMasqueradingVector[4]))
- {
- if(!validJsonOfField(4, pMasqueradingVector[4], pJson[pMasqueradingVector[4]], err, true))
- return false;
- }
- else
- {
- err="The " + pMasqueradingVector[4] + " column cannot be null";
- return false;
- }
- }
- if(!pMasqueradingVector[5].empty())
- {
- if(pJson.isMember(pMasqueradingVector[5]))
- {
- if(!validJsonOfField(5, pMasqueradingVector[5], pJson[pMasqueradingVector[5]], err, true))
- return false;
- }
- }
- if(!pMasqueradingVector[6].empty())
- {
- if(pJson.isMember(pMasqueradingVector[6]))
- {
- if(!validJsonOfField(6, pMasqueradingVector[6], pJson[pMasqueradingVector[6]], err, true))
- return false;
- }
- else
- {
- err="The " + pMasqueradingVector[6] + " column cannot be null";
- return false;
- }
- }
- }
- catch(const Json::LogicError &e)
- {
- err = e.what();
- return false;
- }
- return true;
-}
-bool Inode::validateJsonForUpdate(const Json::Value &pJson, std::string &err)
-{
- if(pJson.isMember("id"))
- {
- if(!validJsonOfField(0, "id", pJson["id"], err, false))
- return false;
- }
- else
- {
- err = "The value of primary key must be set in the json object for update";
- return false;
- }
- if(pJson.isMember("is_file"))
- {
- if(!validJsonOfField(1, "is_file", pJson["is_file"], err, false))
- return false;
- }
- if(pJson.isMember("name"))
- {
- if(!validJsonOfField(2, "name", pJson["name"], err, false))
- return false;
- }
- if(pJson.isMember("parent_id"))
- {
- if(!validJsonOfField(3, "parent_id", pJson["parent_id"], err, false))
- return false;
- }
- if(pJson.isMember("owner_id"))
- {
- if(!validJsonOfField(4, "owner_id", pJson["owner_id"], err, false))
- return false;
- }
- if(pJson.isMember("size"))
- {
- if(!validJsonOfField(5, "size", pJson["size"], err, false))
- return false;
- }
- if(pJson.isMember("has_preview"))
- {
- if(!validJsonOfField(6, "has_preview", pJson["has_preview"], err, false))
- return false;
- }
- return true;
-}
-bool Inode::validateMasqueradedJsonForUpdate(const Json::Value &pJson,
- const std::vector &pMasqueradingVector,
- std::string &err)
-{
- if(pMasqueradingVector.size() != 7)
- {
- err = "Bad masquerading vector";
- return false;
- }
- try {
- if(!pMasqueradingVector[0].empty() && pJson.isMember(pMasqueradingVector[0]))
- {
- if(!validJsonOfField(0, pMasqueradingVector[0], pJson[pMasqueradingVector[0]], err, false))
- return false;
- }
- else
- {
- err = "The value of primary key must be set in the json object for update";
- return false;
- }
- if(!pMasqueradingVector[1].empty() && pJson.isMember(pMasqueradingVector[1]))
- {
- if(!validJsonOfField(1, pMasqueradingVector[1], pJson[pMasqueradingVector[1]], err, false))
- return false;
- }
- if(!pMasqueradingVector[2].empty() && pJson.isMember(pMasqueradingVector[2]))
- {
- if(!validJsonOfField(2, pMasqueradingVector[2], pJson[pMasqueradingVector[2]], err, false))
- return false;
- }
- if(!pMasqueradingVector[3].empty() && pJson.isMember(pMasqueradingVector[3]))
- {
- if(!validJsonOfField(3, pMasqueradingVector[3], pJson[pMasqueradingVector[3]], err, false))
- return false;
- }
- if(!pMasqueradingVector[4].empty() && pJson.isMember(pMasqueradingVector[4]))
- {
- if(!validJsonOfField(4, pMasqueradingVector[4], pJson[pMasqueradingVector[4]], err, false))
- return false;
- }
- if(!pMasqueradingVector[5].empty() && pJson.isMember(pMasqueradingVector[5]))
- {
- if(!validJsonOfField(5, pMasqueradingVector[5], pJson[pMasqueradingVector[5]], err, false))
- return false;
- }
- if(!pMasqueradingVector[6].empty() && pJson.isMember(pMasqueradingVector[6]))
- {
- if(!validJsonOfField(6, pMasqueradingVector[6], pJson[pMasqueradingVector[6]], err, false))
- return false;
- }
- }
- catch(const Json::LogicError &e)
- {
- err = e.what();
- return false;
- }
- return true;
-}
-bool Inode::validJsonOfField(size_t index,
- const std::string &fieldName,
- const Json::Value &pJson,
- std::string &err,
- bool isForCreation)
-{
- switch(index)
- {
- case 0:
- if(pJson.isNull())
- {
- err="The " + fieldName + " column cannot be null";
- return false;
- }
- if(isForCreation)
- {
- err="The automatic primary key cannot be set";
- return false;
- }
- if(!pJson.isUInt64())
- {
- err="Type error in the "+fieldName+" field";
- return false;
- }
- break;
- case 1:
- if(pJson.isNull())
- {
- err="The " + fieldName + " column cannot be null";
- return false;
- }
- if(!pJson.isUInt64())
- {
- err="Type error in the "+fieldName+" field";
- return false;
- }
- break;
- case 2:
- if(pJson.isNull())
- {
- return true;
- }
- if(!pJson.isString())
- {
- err="Type error in the "+fieldName+" field";
- return false;
- }
- break;
- case 3:
- if(pJson.isNull())
- {
- return true;
- }
- if(!pJson.isUInt64())
- {
- err="Type error in the "+fieldName+" field";
- return false;
- }
- break;
- case 4:
- if(pJson.isNull())
- {
- err="The " + fieldName + " column cannot be null";
- return false;
- }
- if(!pJson.isUInt64())
- {
- err="Type error in the "+fieldName+" field";
- return false;
- }
- break;
- case 5:
- if(pJson.isNull())
- {
- return true;
- }
- if(!pJson.isUInt64())
- {
- err="Type error in the "+fieldName+" field";
- return false;
- }
- break;
- case 6:
- if(pJson.isNull())
- {
- err="The " + fieldName + " column cannot be null";
- return false;
- }
- if(!pJson.isUInt64())
- {
- err="Type error in the "+fieldName+" field";
- return false;
- }
- break;
- default:
- err="Internal error in the server";
- return false;
- break;
- }
- return true;
-}
diff --git a/backend/model/Inode.h b/backend/model/Inode.h
deleted file mode 100644
index 684f179..0000000
--- a/backend/model/Inode.h
+++ /dev/null
@@ -1,295 +0,0 @@
-/**
- *
- * Inode.h
- * DO NOT EDIT. This file is generated by drogon_ctl
- *
- */
-
-#pragma once
-#include "drogon/orm/Result.h"
-#include "drogon/orm/Row.h"
-#include "drogon/orm/Field.h"
-#include "drogon/orm/SqlBinder.h"
-#include "drogon/orm/Mapper.h"
-#ifdef __cpp_impl_coroutine
-#include
-#endif
-#include "trantor/utils/Date.h"
-#include "trantor/utils/Logger.h"
-#include "json/json.h"
-#include
-#include
-#include
-#include
-#include
-#include
-
-namespace drogon
-{
-namespace orm
-{
-class DbClient;
-using DbClientPtr = std::shared_ptr;
-}
-}
-namespace drogon_model
-{
-namespace sqlite3
-{
-
-class Inode
-{
- public:
- struct Cols
- {
- static const std::string _id;
- static const std::string _is_file;
- static const std::string _name;
- static const std::string _parent_id;
- static const std::string _owner_id;
- static const std::string _size;
- static const std::string _has_preview;
- };
-
- const static int primaryKeyNumber;
- const static std::string tableName;
- const static bool hasPrimaryKey;
- const static std::string primaryKeyName;
- using PrimaryKeyType = uint64_t;
- const PrimaryKeyType &getPrimaryKey() const;
-
- /**
- * @brief constructor
- * @param r One row of records in the SQL query result.
- * @param indexOffset Set the offset to -1 to access all columns by column names,
- * otherwise access all columns by offsets.
- * @note If the SQL is not a style of 'select * from table_name ...' (select all
- * columns by an asterisk), please set the offset to -1.
- */
- explicit Inode(const drogon::orm::Row &r, const ssize_t indexOffset = 0) noexcept;
-
- /**
- * @brief constructor
- * @param pJson The json object to construct a new instance.
- */
- explicit Inode(const Json::Value &pJson) noexcept(false);
-
- /**
- * @brief constructor
- * @param pJson The json object to construct a new instance.
- * @param pMasqueradingVector The aliases of table columns.
- */
- Inode(const Json::Value &pJson, const std::vector &pMasqueradingVector) noexcept(false);
-
- Inode() = default;
-
- void updateByJson(const Json::Value &pJson) noexcept(false);
- void updateByMasqueradedJson(const Json::Value &pJson,
- const std::vector &pMasqueradingVector) noexcept(false);
- static bool validateJsonForCreation(const Json::Value &pJson, std::string &err);
- static bool validateMasqueradedJsonForCreation(const Json::Value &,
- const std::vector &pMasqueradingVector,
- std::string &err);
- static bool validateJsonForUpdate(const Json::Value &pJson, std::string &err);
- static bool validateMasqueradedJsonForUpdate(const Json::Value &,
- const std::vector &pMasqueradingVector,
- std::string &err);
- static bool validJsonOfField(size_t index,
- const std::string &fieldName,
- const Json::Value &pJson,
- std::string &err,
- bool isForCreation);
-
- /** For column id */
- ///Get the value of the column id, returns the default value if the column is null
- const uint64_t &getValueOfId() const noexcept;
- ///Return a shared_ptr object pointing to the column const value, or an empty shared_ptr object if the column is null
- const std::shared_ptr &getId() const noexcept;
- ///Set the value of the column id
- void setId(const uint64_t &pId) noexcept;
-
- /** For column is_file */
- ///Get the value of the column is_file, returns the default value if the column is null
- const uint64_t &getValueOfIsFile() const noexcept;
- ///Return a shared_ptr object pointing to the column const value, or an empty shared_ptr object if the column is null
- const std::shared_ptr &getIsFile() const noexcept;
- ///Set the value of the column is_file
- void setIsFile(const uint64_t &pIsFile) noexcept;
-
- /** For column name */
- ///Get the value of the column name, returns the default value if the column is null
- const std::string &getValueOfName() const noexcept;
- ///Return a shared_ptr object pointing to the column const value, or an empty shared_ptr object if the column is null
- const std::shared_ptr &getName() const noexcept;
- ///Set the value of the column name
- void setName(const std::string &pName) noexcept;
- void setName(std::string &&pName) noexcept;
- void setNameToNull() noexcept;
-
- /** For column parent_id */
- ///Get the value of the column parent_id, returns the default value if the column is null
- const uint64_t &getValueOfParentId() const noexcept;
- ///Return a shared_ptr object pointing to the column const value, or an empty shared_ptr object if the column is null
- const std::shared_ptr &getParentId() const noexcept;
- ///Set the value of the column parent_id
- void setParentId(const uint64_t &pParentId) noexcept;
- void setParentIdToNull() noexcept;
-
- /** For column owner_id */
- ///Get the value of the column owner_id, returns the default value if the column is null
- const uint64_t &getValueOfOwnerId() const noexcept;
- ///Return a shared_ptr object pointing to the column const value, or an empty shared_ptr object if the column is null
- const std::shared_ptr &getOwnerId() const noexcept;
- ///Set the value of the column owner_id
- void setOwnerId(const uint64_t &pOwnerId) noexcept;
-
- /** For column size */
- ///Get the value of the column size, returns the default value if the column is null
- const uint64_t &getValueOfSize() const noexcept;
- ///Return a shared_ptr object pointing to the column const value, or an empty shared_ptr object if the column is null
- const std::shared_ptr &getSize() const noexcept;
- ///Set the value of the column size
- void setSize(const uint64_t &pSize) noexcept;
- void setSizeToNull() noexcept;
-
- /** For column has_preview */
- ///Get the value of the column has_preview, returns the default value if the column is null
- const uint64_t &getValueOfHasPreview() const noexcept;
- ///Return a shared_ptr object pointing to the column const value, or an empty shared_ptr object if the column is null
- const std::shared_ptr &getHasPreview() const noexcept;
- ///Set the value of the column has_preview
- void setHasPreview(const uint64_t &pHasPreview) noexcept;
-
-
- static size_t getColumnNumber() noexcept { return 7; }
- static const std::string &getColumnName(size_t index) noexcept(false);
-
- Json::Value toJson() const;
- Json::Value toMasqueradedJson(const std::vector &pMasqueradingVector) const;
- /// Relationship interfaces
- private:
- friend drogon::orm::Mapper;
-#ifdef __cpp_impl_coroutine
- friend drogon::orm::CoroMapper;
-#endif
- static const std::vector &insertColumns() noexcept;
- void outputArgs(drogon::orm::internal::SqlBinder &binder) const;
- const std::vector updateColumns() const;
- void updateArgs(drogon::orm::internal::SqlBinder &binder) const;
- ///For mysql or sqlite3
- void updateId(const uint64_t id);
- std::shared_ptr id_;
- std::shared_ptr isFile_;
- std::shared_ptr name_;
- std::shared_ptr parentId_;
- std::shared_ptr ownerId_;
- std::shared_ptr size_;
- std::shared_ptr hasPreview_;
- struct MetaData
- {
- const std::string colName_;
- const std::string colType_;
- const std::string colDatabaseType_;
- const ssize_t colLength_;
- const bool isAutoVal_;
- const bool isPrimaryKey_;
- const bool notNull_;
- };
- static const std::vector metaData_;
- bool dirtyFlag_[7]={ false };
- public:
- static const std::string &sqlForFindingByPrimaryKey()
- {
- static const std::string sql="select * from " + tableName + " where id = ?";
- return sql;
- }
-
- static const std::string &sqlForDeletingByPrimaryKey()
- {
- static const std::string sql="delete from " + tableName + " where id = ?";
- return sql;
- }
- std::string sqlForInserting(bool &needSelection) const
- {
- std::string sql="insert into " + tableName + " (";
- size_t parametersCount = 0;
- needSelection = false;
- if(dirtyFlag_[1])
- {
- sql += "is_file,";
- ++parametersCount;
- }
- if(dirtyFlag_[2])
- {
- sql += "name,";
- ++parametersCount;
- }
- if(dirtyFlag_[3])
- {
- sql += "parent_id,";
- ++parametersCount;
- }
- if(dirtyFlag_[4])
- {
- sql += "owner_id,";
- ++parametersCount;
- }
- if(dirtyFlag_[5])
- {
- sql += "size,";
- ++parametersCount;
- }
- if(dirtyFlag_[6])
- {
- sql += "has_preview,";
- ++parametersCount;
- }
- if(parametersCount > 0)
- {
- sql[sql.length()-1]=')';
- sql += " values (";
- }
- else
- sql += ") values (";
-
- if(dirtyFlag_[1])
- {
- sql.append("?,");
-
- }
- if(dirtyFlag_[2])
- {
- sql.append("?,");
-
- }
- if(dirtyFlag_[3])
- {
- sql.append("?,");
-
- }
- if(dirtyFlag_[4])
- {
- sql.append("?,");
-
- }
- if(dirtyFlag_[5])
- {
- sql.append("?,");
-
- }
- if(dirtyFlag_[6])
- {
- sql.append("?,");
-
- }
- if(parametersCount > 0)
- {
- sql.resize(sql.length() - 1);
- }
- sql.append(1, ')');
- LOG_TRACE << sql;
- return sql;
- }
-};
-} // namespace sqlite3
-} // namespace drogon_model
diff --git a/backend/model/Tokens.cc b/backend/model/Tokens.cc
deleted file mode 100644
index 7b8311a..0000000
--- a/backend/model/Tokens.cc
+++ /dev/null
@@ -1,631 +0,0 @@
-/**
- *
- * Tokens.cc
- * DO NOT EDIT. This file is generated by drogon_ctl
- *
- */
-
-#include "Tokens.h"
-#include "drogon/utils/Utilities.h"
-#include
-
-using namespace drogon;
-using namespace drogon::orm;
-using namespace drogon_model::sqlite3;
-
-const std::string Tokens::Cols::_id = "id";
-const std::string Tokens::Cols::_owner_id = "owner_id";
-const std::string Tokens::Cols::_exp = "exp";
-const std::string Tokens::primaryKeyName = "id";
-const bool Tokens::hasPrimaryKey = true;
-const std::string Tokens::tableName = "tokens";
-
-const std::vector Tokens::metaData_={
-{"id","uint64_t","integer",8,1,1,1},
-{"owner_id","uint64_t","integer",8,0,0,1},
-{"exp","uint64_t","integer",8,0,0,1}
-};
-const std::string &Tokens::getColumnName(size_t index) noexcept(false)
-{
- assert(index < metaData_.size());
- return metaData_[index].colName_;
-}
-Tokens::Tokens(const Row &r, const ssize_t indexOffset) noexcept
-{
- if(indexOffset < 0)
- {
- if(!r["id"].isNull())
- {
- id_=std::make_shared(r["id"].as());
- }
- if(!r["owner_id"].isNull())
- {
- ownerId_=std::make_shared(r["owner_id"].as());
- }
- if(!r["exp"].isNull())
- {
- exp_=std::make_shared(r["exp"].as());
- }
- }
- else
- {
- size_t offset = (size_t)indexOffset;
- if(offset + 3 > r.size())
- {
- LOG_FATAL << "Invalid SQL result for this model";
- return;
- }
- size_t index;
- index = offset + 0;
- if(!r[index].isNull())
- {
- id_=std::make_shared(r[index].as());
- }
- index = offset + 1;
- if(!r[index].isNull())
- {
- ownerId_=std::make_shared(r[index].as());
- }
- index = offset + 2;
- if(!r[index].isNull())
- {
- exp_=std::make_shared(r[index].as());
- }
- }
-
-}
-
-Tokens::Tokens(const Json::Value &pJson, const std::vector &pMasqueradingVector) noexcept(false)
-{
- if(pMasqueradingVector.size() != 3)
- {
- LOG_ERROR << "Bad masquerading vector";
- return;
- }
- if(!pMasqueradingVector[0].empty() && pJson.isMember(pMasqueradingVector[0]))
- {
- dirtyFlag_[0] = true;
- if(!pJson[pMasqueradingVector[0]].isNull())
- {
- id_=std::make_shared((uint64_t)pJson[pMasqueradingVector[0]].asUInt64());
- }
- }
- if(!pMasqueradingVector[1].empty() && pJson.isMember(pMasqueradingVector[1]))
- {
- dirtyFlag_[1] = true;
- if(!pJson[pMasqueradingVector[1]].isNull())
- {
- ownerId_=std::make_shared((uint64_t)pJson[pMasqueradingVector[1]].asUInt64());
- }
- }
- if(!pMasqueradingVector[2].empty() && pJson.isMember(pMasqueradingVector[2]))
- {
- dirtyFlag_[2] = true;
- if(!pJson[pMasqueradingVector[2]].isNull())
- {
- exp_=std::make_shared((uint64_t)pJson[pMasqueradingVector[2]].asUInt64());
- }
- }
-}
-
-Tokens::Tokens(const Json::Value &pJson) noexcept(false)
-{
- if(pJson.isMember("id"))
- {
- dirtyFlag_[0]=true;
- if(!pJson["id"].isNull())
- {
- id_=std::make_shared((uint64_t)pJson["id"].asUInt64());
- }
- }
- if(pJson.isMember("owner_id"))
- {
- dirtyFlag_[1]=true;
- if(!pJson["owner_id"].isNull())
- {
- ownerId_=std::make_shared((uint64_t)pJson["owner_id"].asUInt64());
- }
- }
- if(pJson.isMember("exp"))
- {
- dirtyFlag_[2]=true;
- if(!pJson["exp"].isNull())
- {
- exp_=std::make_shared((uint64_t)pJson["exp"].asUInt64());
- }
- }
-}
-
-void Tokens::updateByMasqueradedJson(const Json::Value &pJson,
- const std::vector &pMasqueradingVector) noexcept(false)
-{
- if(pMasqueradingVector.size() != 3)
- {
- LOG_ERROR << "Bad masquerading vector";
- return;
- }
- if(!pMasqueradingVector[0].empty() && pJson.isMember(pMasqueradingVector[0]))
- {
- if(!pJson[pMasqueradingVector[0]].isNull())
- {
- id_=std::make_shared((uint64_t)pJson[pMasqueradingVector[0]].asUInt64());
- }
- }
- if(!pMasqueradingVector[1].empty() && pJson.isMember(pMasqueradingVector[1]))
- {
- dirtyFlag_[1] = true;
- if(!pJson[pMasqueradingVector[1]].isNull())
- {
- ownerId_=std::make_shared((uint64_t)pJson[pMasqueradingVector[1]].asUInt64());
- }
- }
- if(!pMasqueradingVector[2].empty() && pJson.isMember(pMasqueradingVector[2]))
- {
- dirtyFlag_[2] = true;
- if(!pJson[pMasqueradingVector[2]].isNull())
- {
- exp_=std::make_shared((uint64_t)pJson[pMasqueradingVector[2]].asUInt64());
- }
- }
-}
-
-void Tokens::updateByJson(const Json::Value &pJson) noexcept(false)
-{
- if(pJson.isMember("id"))
- {
- if(!pJson["id"].isNull())
- {
- id_=std::make_shared((uint64_t)pJson["id"].asUInt64());
- }
- }
- if(pJson.isMember("owner_id"))
- {
- dirtyFlag_[1] = true;
- if(!pJson["owner_id"].isNull())
- {
- ownerId_=std::make_shared((uint64_t)pJson["owner_id"].asUInt64());
- }
- }
- if(pJson.isMember("exp"))
- {
- dirtyFlag_[2] = true;
- if(!pJson["exp"].isNull())
- {
- exp_=std::make_shared((uint64_t)pJson["exp"].asUInt64());
- }
- }
-}
-
-const uint64_t &Tokens::getValueOfId() const noexcept
-{
- const static uint64_t defaultValue = uint64_t();
- if(id_)
- return *id_;
- return defaultValue;
-}
-const std::shared_ptr &Tokens::getId() const noexcept
-{
- return id_;
-}
-void Tokens::setId(const uint64_t &pId) noexcept
-{
- id_ = std::make_shared(pId);
- dirtyFlag_[0] = true;
-}
-const typename Tokens::PrimaryKeyType & Tokens::getPrimaryKey() const
-{
- assert(id_);
- return *id_;
-}
-
-const uint64_t &Tokens::getValueOfOwnerId() const noexcept
-{
- const static uint64_t defaultValue = uint64_t();
- if(ownerId_)
- return *ownerId_;
- return defaultValue;
-}
-const std::shared_ptr &Tokens::getOwnerId() const noexcept
-{
- return ownerId_;
-}
-void Tokens::setOwnerId(const uint64_t &pOwnerId) noexcept
-{
- ownerId_ = std::make_shared(pOwnerId);
- dirtyFlag_[1] = true;
-}
-
-const uint64_t &Tokens::getValueOfExp() const noexcept
-{
- const static uint64_t defaultValue = uint64_t();
- if(exp_)
- return *exp_;
- return defaultValue;
-}
-const std::shared_ptr &Tokens::getExp() const noexcept
-{
- return exp_;
-}
-void Tokens::setExp(const uint64_t &pExp) noexcept
-{
- exp_ = std::make_shared(pExp);
- dirtyFlag_[2] = true;
-}
-
-void Tokens::updateId(const uint64_t id)
-{
- id_ = std::make_shared(id);
-}
-
-const std::vector &Tokens::insertColumns() noexcept
-{
- static const std::vector inCols={
- "owner_id",
- "exp"
- };
- return inCols;
-}
-
-void Tokens::outputArgs(drogon::orm::internal::SqlBinder &binder) const
-{
- if(dirtyFlag_[1])
- {
- if(getOwnerId())
- {
- binder << getValueOfOwnerId();
- }
- else
- {
- binder << nullptr;
- }
- }
- if(dirtyFlag_[2])
- {
- if(getExp())
- {
- binder << getValueOfExp();
- }
- else
- {
- binder << nullptr;
- }
- }
-}
-
-const std::vector Tokens::updateColumns() const
-{
- std::vector ret;
- if(dirtyFlag_[1])
- {
- ret.push_back(getColumnName(1));
- }
- if(dirtyFlag_[2])
- {
- ret.push_back(getColumnName(2));
- }
- return ret;
-}
-
-void Tokens::updateArgs(drogon::orm::internal::SqlBinder &binder) const
-{
- if(dirtyFlag_[1])
- {
- if(getOwnerId())
- {
- binder << getValueOfOwnerId();
- }
- else
- {
- binder << nullptr;
- }
- }
- if(dirtyFlag_[2])
- {
- if(getExp())
- {
- binder << getValueOfExp();
- }
- else
- {
- binder << nullptr;
- }
- }
-}
-Json::Value Tokens::toJson() const
-{
- Json::Value ret;
- if(getId())
- {
- ret["id"]=(Json::UInt64)getValueOfId();
- }
- else
- {
- ret["id"]=Json::Value();
- }
- if(getOwnerId())
- {
- ret["owner_id"]=(Json::UInt64)getValueOfOwnerId();
- }
- else
- {
- ret["owner_id"]=Json::Value();
- }
- if(getExp())
- {
- ret["exp"]=(Json::UInt64)getValueOfExp();
- }
- else
- {
- ret["exp"]=Json::Value();
- }
- return ret;
-}
-
-Json::Value Tokens::toMasqueradedJson(
- const std::vector &pMasqueradingVector) const
-{
- Json::Value ret;
- if(pMasqueradingVector.size() == 3)
- {
- if(!pMasqueradingVector[0].empty())
- {
- if(getId())
- {
- ret[pMasqueradingVector[0]]=(Json::UInt64)getValueOfId();
- }
- else
- {
- ret[pMasqueradingVector[0]]=Json::Value();
- }
- }
- if(!pMasqueradingVector[1].empty())
- {
- if(getOwnerId())
- {
- ret[pMasqueradingVector[1]]=(Json::UInt64)getValueOfOwnerId();
- }
- else
- {
- ret[pMasqueradingVector[1]]=Json::Value();
- }
- }
- if(!pMasqueradingVector[2].empty())
- {
- if(getExp())
- {
- ret[pMasqueradingVector[2]]=(Json::UInt64)getValueOfExp();
- }
- else
- {
- ret[pMasqueradingVector[2]]=Json::Value();
- }
- }
- return ret;
- }
- LOG_ERROR << "Masquerade failed";
- if(getId())
- {
- ret["id"]=(Json::UInt64)getValueOfId();
- }
- else
- {
- ret["id"]=Json::Value();
- }
- if(getOwnerId())
- {
- ret["owner_id"]=(Json::UInt64)getValueOfOwnerId();
- }
- else
- {
- ret["owner_id"]=Json::Value();
- }
- if(getExp())
- {
- ret["exp"]=(Json::UInt64)getValueOfExp();
- }
- else
- {
- ret["exp"]=Json::Value();
- }
- return ret;
-}
-
-bool Tokens::validateJsonForCreation(const Json::Value &pJson, std::string &err)
-{
- if(pJson.isMember("id"))
- {
- if(!validJsonOfField(0, "id", pJson["id"], err, true))
- return false;
- }
- if(pJson.isMember("owner_id"))
- {
- if(!validJsonOfField(1, "owner_id", pJson["owner_id"], err, true))
- return false;
- }
- else
- {
- err="The owner_id column cannot be null";
- return false;
- }
- if(pJson.isMember("exp"))
- {
- if(!validJsonOfField(2, "exp", pJson["exp"], err, true))
- return false;
- }
- else
- {
- err="The exp column cannot be null";
- return false;
- }
- return true;
-}
-bool Tokens::validateMasqueradedJsonForCreation(const Json::Value &pJson,
- const std::vector &pMasqueradingVector,
- std::string &err)
-{
- if(pMasqueradingVector.size() != 3)
- {
- err = "Bad masquerading vector";
- return false;
- }
- try {
- if(!pMasqueradingVector[0].empty())
- {
- if(pJson.isMember(pMasqueradingVector[0]))
- {
- if(!validJsonOfField(0, pMasqueradingVector[0], pJson[pMasqueradingVector[0]], err, true))
- return false;
- }
- }
- if(!pMasqueradingVector[1].empty())
- {
- if(pJson.isMember(pMasqueradingVector[1]))
- {
- if(!validJsonOfField(1, pMasqueradingVector[1], pJson[pMasqueradingVector[1]], err, true))
- return false;
- }
- else
- {
- err="The " + pMasqueradingVector[1] + " column cannot be null";
- return false;
- }
- }
- if(!pMasqueradingVector[2].empty())
- {
- if(pJson.isMember(pMasqueradingVector[2]))
- {
- if(!validJsonOfField(2, pMasqueradingVector[2], pJson[pMasqueradingVector[2]], err, true))
- return false;
- }
- else
- {
- err="The " + pMasqueradingVector[2] + " column cannot be null";
- return false;
- }
- }
- }
- catch(const Json::LogicError &e)
- {
- err = e.what();
- return false;
- }
- return true;
-}
-bool Tokens::validateJsonForUpdate(const Json::Value &pJson, std::string &err)
-{
- if(pJson.isMember("id"))
- {
- if(!validJsonOfField(0, "id", pJson["id"], err, false))
- return false;
- }
- else
- {
- err = "The value of primary key must be set in the json object for update";
- return false;
- }
- if(pJson.isMember("owner_id"))
- {
- if(!validJsonOfField(1, "owner_id", pJson["owner_id"], err, false))
- return false;
- }
- if(pJson.isMember("exp"))
- {
- if(!validJsonOfField(2, "exp", pJson["exp"], err, false))
- return false;
- }
- return true;
-}
-bool Tokens::validateMasqueradedJsonForUpdate(const Json::Value &pJson,
- const std::vector &pMasqueradingVector,
- std::string &err)
-{
- if(pMasqueradingVector.size() != 3)
- {
- err = "Bad masquerading vector";
- return false;
- }
- try {
- if(!pMasqueradingVector[0].empty() && pJson.isMember(pMasqueradingVector[0]))
- {
- if(!validJsonOfField(0, pMasqueradingVector[0], pJson[pMasqueradingVector[0]], err, false))
- return false;
- }
- else
- {
- err = "The value of primary key must be set in the json object for update";
- return false;
- }
- if(!pMasqueradingVector[1].empty() && pJson.isMember(pMasqueradingVector[1]))
- {
- if(!validJsonOfField(1, pMasqueradingVector[1], pJson[pMasqueradingVector[1]], err, false))
- return false;
- }
- if(!pMasqueradingVector[2].empty() && pJson.isMember(pMasqueradingVector[2]))
- {
- if(!validJsonOfField(2, pMasqueradingVector[2], pJson[pMasqueradingVector[2]], err, false))
- return false;
- }
- }
- catch(const Json::LogicError &e)
- {
- err = e.what();
- return false;
- }
- return true;
-}
-bool Tokens::validJsonOfField(size_t index,
- const std::string &fieldName,
- const Json::Value &pJson,
- std::string &err,
- bool isForCreation)
-{
- switch(index)
- {
- case 0:
- if(pJson.isNull())
- {
- err="The " + fieldName + " column cannot be null";
- return false;
- }
- if(isForCreation)
- {
- err="The automatic primary key cannot be set";
- return false;
- }
- if(!pJson.isUInt64())
- {
- err="Type error in the "+fieldName+" field";
- return false;
- }
- break;
- case 1:
- if(pJson.isNull())
- {
- err="The " + fieldName + " column cannot be null";
- return false;
- }
- if(!pJson.isUInt64())
- {
- err="Type error in the "+fieldName+" field";
- return false;
- }
- break;
- case 2:
- if(pJson.isNull())
- {
- err="The " + fieldName + " column cannot be null";
- return false;
- }
- if(!pJson.isUInt64())
- {
- err="Type error in the "+fieldName+" field";
- return false;
- }
- break;
- default:
- err="Internal error in the server";
- return false;
- break;
- }
- return true;
-}
diff --git a/backend/model/Tokens.h b/backend/model/Tokens.h
deleted file mode 100644
index a6c0da4..0000000
--- a/backend/model/Tokens.h
+++ /dev/null
@@ -1,211 +0,0 @@
-/**
- *
- * Tokens.h
- * DO NOT EDIT. This file is generated by drogon_ctl
- *
- */
-
-#pragma once
-#include "drogon/orm/Result.h"
-#include "drogon/orm/Row.h"
-#include "drogon/orm/Field.h"
-#include "drogon/orm/SqlBinder.h"
-#include "drogon/orm/Mapper.h"
-#ifdef __cpp_impl_coroutine
-#include
-#endif
-#include "trantor/utils/Date.h"
-#include "trantor/utils/Logger.h"
-#include "json/json.h"
-#include
-#include
-#include
-#include
-#include
-#include
-
-namespace drogon
-{
-namespace orm
-{
-class DbClient;
-using DbClientPtr = std::shared_ptr;
-}
-}
-namespace drogon_model
-{
-namespace sqlite3
-{
-
-class Tokens
-{
- public:
- struct Cols
- {
- static const std::string _id;
- static const std::string _owner_id;
- static const std::string _exp;
- };
-
- const static int primaryKeyNumber;
- const static std::string tableName;
- const static bool hasPrimaryKey;
- const static std::string primaryKeyName;
- using PrimaryKeyType = uint64_t;
- const PrimaryKeyType &getPrimaryKey() const;
-
- /**
- * @brief constructor
- * @param r One row of records in the SQL query result.
- * @param indexOffset Set the offset to -1 to access all columns by column names,
- * otherwise access all columns by offsets.
- * @note If the SQL is not a style of 'select * from table_name ...' (select all
- * columns by an asterisk), please set the offset to -1.
- */
- explicit Tokens(const drogon::orm::Row &r, const ssize_t indexOffset = 0) noexcept;
-
- /**
- * @brief constructor
- * @param pJson The json object to construct a new instance.
- */
- explicit Tokens(const Json::Value &pJson) noexcept(false);
-
- /**
- * @brief constructor
- * @param pJson The json object to construct a new instance.
- * @param pMasqueradingVector The aliases of table columns.
- */
- Tokens(const Json::Value &pJson, const std::vector &pMasqueradingVector) noexcept(false);
-
- Tokens() = default;
-
- void updateByJson(const Json::Value &pJson) noexcept(false);
- void updateByMasqueradedJson(const Json::Value &pJson,
- const std::vector &pMasqueradingVector) noexcept(false);
- static bool validateJsonForCreation(const Json::Value &pJson, std::string &err);
- static bool validateMasqueradedJsonForCreation(const Json::Value &,
- const std::vector &pMasqueradingVector,
- std::string &err);
- static bool validateJsonForUpdate(const Json::Value &pJson, std::string &err);
- static bool validateMasqueradedJsonForUpdate(const Json::Value &,
- const std::vector &pMasqueradingVector,
- std::string &err);
- static bool validJsonOfField(size_t index,
- const std::string &fieldName,
- const Json::Value &pJson,
- std::string &err,
- bool isForCreation);
-
- /** For column id */
- ///Get the value of the column id, returns the default value if the column is null
- const uint64_t &getValueOfId() const noexcept;
- ///Return a shared_ptr object pointing to the column const value, or an empty shared_ptr object if the column is null
- const std::shared_ptr &getId() const noexcept;
- ///Set the value of the column id
- void setId(const uint64_t &pId) noexcept;
-
- /** For column owner_id */
- ///Get the value of the column owner_id, returns the default value if the column is null
- const uint64_t &getValueOfOwnerId() const noexcept;
- ///Return a shared_ptr object pointing to the column const value, or an empty shared_ptr object if the column is null
- const std::shared_ptr &getOwnerId() const noexcept;
- ///Set the value of the column owner_id
- void setOwnerId(const uint64_t &pOwnerId) noexcept;
-
- /** For column exp */
- ///Get the value of the column exp, returns the default value if the column is null
- const uint64_t &getValueOfExp() const noexcept;
- ///Return a shared_ptr object pointing to the column const value, or an empty shared_ptr object if the column is null
- const std::shared_ptr &getExp() const noexcept;
- ///Set the value of the column exp
- void setExp(const uint64_t &pExp) noexcept;
-
-
- static size_t getColumnNumber() noexcept { return 3; }
- static const std::string &getColumnName(size_t index) noexcept(false);
-
- Json::Value toJson() const;
- Json::Value toMasqueradedJson(const std::vector &pMasqueradingVector) const;
- /// Relationship interfaces
- private:
- friend drogon::orm::Mapper;
-#ifdef __cpp_impl_coroutine
- friend drogon::orm::CoroMapper;
-#endif
- static const std::vector &insertColumns() noexcept;
- void outputArgs(drogon::orm::internal::SqlBinder &binder) const;
- const std::vector updateColumns() const;
- void updateArgs(drogon::orm::internal::SqlBinder &binder) const;
- ///For mysql or sqlite3
- void updateId(const uint64_t id);
- std::shared_ptr id_;
- std::shared_ptr ownerId_;
- std::shared_ptr exp_;
- struct MetaData
- {
- const std::string colName_;
- const std::string colType_;
- const std::string colDatabaseType_;
- const ssize_t colLength_;
- const bool isAutoVal_;
- const bool isPrimaryKey_;
- const bool notNull_;
- };
- static const std::vector metaData_;
- bool dirtyFlag_[3]={ false };
- public:
- static const std::string &sqlForFindingByPrimaryKey()
- {
- static const std::string sql="select * from " + tableName + " where id = ?";
- return sql;
- }
-
- static const std::string &sqlForDeletingByPrimaryKey()
- {
- static const std::string sql="delete from " + tableName + " where id = ?";
- return sql;
- }
- std::string sqlForInserting(bool &needSelection) const
- {
- std::string sql="insert into " + tableName + " (";
- size_t parametersCount = 0;
- needSelection = false;
- if(dirtyFlag_[1])
- {
- sql += "owner_id,";
- ++parametersCount;
- }
- if(dirtyFlag_[2])
- {
- sql += "exp,";
- ++parametersCount;
- }
- if(parametersCount > 0)
- {
- sql[sql.length()-1]=')';
- sql += " values (";
- }
- else
- sql += ") values (";
-
- if(dirtyFlag_[1])
- {
- sql.append("?,");
-
- }
- if(dirtyFlag_[2])
- {
- sql.append("?,");
-
- }
- if(parametersCount > 0)
- {
- sql.resize(sql.length() - 1);
- }
- sql.append(1, ')');
- LOG_TRACE << sql;
- return sql;
- }
-};
-} // namespace sqlite3
-} // namespace drogon_model
diff --git a/backend/model/User.cc b/backend/model/User.cc
deleted file mode 100644
index 205b6fa..0000000
--- a/backend/model/User.cc
+++ /dev/null
@@ -1,1762 +0,0 @@
-/**
- *
- * User.cc
- * DO NOT EDIT. This file is generated by drogon_ctl
- *
- */
-
-#include "User.h"
-#include "drogon/utils/Utilities.h"
-#include
-
-using namespace drogon;
-using namespace drogon::orm;
-using namespace drogon_model::sqlite3;
-
-const std::string User::Cols::_id = "id";
-const std::string User::Cols::_gitlab = "gitlab";
-const std::string User::Cols::_name = "name";
-const std::string User::Cols::_password = "password";
-const std::string User::Cols::_role = "role";
-const std::string User::Cols::_root_id = "root_id";
-const std::string User::Cols::_tfa_type = "tfa_type";
-const std::string User::Cols::_tfa_secret = "tfa_secret";
-const std::string User::Cols::_gitlab_at = "gitlab_at";
-const std::string User::Cols::_gitlab_rt = "gitlab_rt";
-const std::string User::primaryKeyName = "id";
-const bool User::hasPrimaryKey = true;
-const std::string User::tableName = "user";
-
-const std::vector User::metaData_={
-{"id","uint64_t","integer",8,1,1,1},
-{"gitlab","uint64_t","integer",8,0,0,1},
-{"name","std::string","text",0,0,0,1},
-{"password","std::string","text",0,0,0,1},
-{"role","uint64_t","integer",8,0,0,1},
-{"root_id","uint64_t","integer",8,0,0,1},
-{"tfa_type","uint64_t","integer",8,0,0,1},
-{"tfa_secret","std::vector","blob",0,0,0,0},
-{"gitlab_at","std::string","text",0,0,0,0},
-{"gitlab_rt","std::string","text",0,0,0,0}
-};
-const std::string &User::getColumnName(size_t index) noexcept(false)
-{
- assert(index < metaData_.size());
- return metaData_[index].colName_;
-}
-User::User(const Row &r, const ssize_t indexOffset) noexcept
-{
- if(indexOffset < 0)
- {
- if(!r["id"].isNull())
- {
- id_=std::make_shared(r["id"].as());
- }
- if(!r["gitlab"].isNull())
- {
- gitlab_=std::make_shared(r["gitlab"].as());
- }
- if(!r["name"].isNull())
- {
- name_=std::make_shared(r["name"].as());
- }
- if(!r["password"].isNull())
- {
- password_=std::make_shared(r["password"].as());
- }
- if(!r["role"].isNull())
- {
- role_=std::make_shared(r["role"].as());
- }
- if(!r["root_id"].isNull())
- {
- rootId_=std::make_shared(r["root_id"].as());
- }
- if(!r["tfa_type"].isNull())
- {
- tfaType_=std::make_shared(r["tfa_type"].as());
- }
- if(!r["tfa_secret"].isNull())
- {
- tfaSecret_=std::make_shared>(r["tfa_secret"].as>());
- }
- if(!r["gitlab_at"].isNull())
- {
- gitlabAt_=std::make_shared(r["gitlab_at"].as());
- }
- if(!r["gitlab_rt"].isNull())
- {
- gitlabRt_=std::make_shared(r["gitlab_rt"].as());
- }
- }
- else
- {
- size_t offset = (size_t)indexOffset;
- if(offset + 10 > r.size())
- {
- LOG_FATAL << "Invalid SQL result for this model";
- return;
- }
- size_t index;
- index = offset + 0;
- if(!r[index].isNull())
- {
- id_=std::make_shared(r[index].as());
- }
- index = offset + 1;
- if(!r[index].isNull())
- {
- gitlab_=std::make_shared(r[index].as());
- }
- index = offset + 2;
- if(!r[index].isNull())
- {
- name_=std::make_shared(r[index].as());
- }
- index = offset + 3;
- if(!r[index].isNull())
- {
- password_=std::make_shared(r[index].as());
- }
- index = offset + 4;
- if(!r[index].isNull())
- {
- role_=std::make_shared(r[index].as());
- }
- index = offset + 5;
- if(!r[index].isNull())
- {
- rootId_=std::make_shared(r[index].as());
- }
- index = offset + 6;
- if(!r[index].isNull())
- {
- tfaType_=std::make_shared(r[index].as());
- }
- index = offset + 7;
- if(!r[index].isNull())
- {
- tfaSecret_=std::make_shared>(r[index].as>());
- }
- index = offset + 8;
- if(!r[index].isNull())
- {
- gitlabAt_=std::make_shared(r[index].as());
- }
- index = offset + 9;
- if(!r[index].isNull())
- {
- gitlabRt_=std::make_shared(r[index].as());
- }
- }
-
-}
-
-User::User(const Json::Value &pJson, const std::vector &pMasqueradingVector) noexcept(false)
-{
- if(pMasqueradingVector.size() != 10)
- {
- LOG_ERROR << "Bad masquerading vector";
- return;
- }
- if(!pMasqueradingVector[0].empty() && pJson.isMember(pMasqueradingVector[0]))
- {
- dirtyFlag_[0] = true;
- if(!pJson[pMasqueradingVector[0]].isNull())
- {
- id_=std::make_shared((uint64_t)pJson[pMasqueradingVector[0]].asUInt64());
- }
- }
- if(!pMasqueradingVector[1].empty() && pJson.isMember(pMasqueradingVector[1]))
- {
- dirtyFlag_[1] = true;
- if(!pJson[pMasqueradingVector[1]].isNull())
- {
- gitlab_=std::make_shared((uint64_t)pJson[pMasqueradingVector[1]].asUInt64());
- }
- }
- if(!pMasqueradingVector[2].empty() && pJson.isMember(pMasqueradingVector[2]))
- {
- dirtyFlag_[2] = true;
- if(!pJson[pMasqueradingVector[2]].isNull())
- {
- name_=std::make_shared(pJson[pMasqueradingVector[2]].asString());
- }
- }
- if(!pMasqueradingVector[3].empty() && pJson.isMember(pMasqueradingVector[3]))
- {
- dirtyFlag_[3] = true;
- if(!pJson[pMasqueradingVector[3]].isNull())
- {
- password_=std::make_shared(pJson[pMasqueradingVector[3]].asString());
- }
- }
- if(!pMasqueradingVector[4].empty() && pJson.isMember(pMasqueradingVector[4]))
- {
- dirtyFlag_[4] = true;
- if(!pJson[pMasqueradingVector[4]].isNull())
- {
- role_=std::make_shared