diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..1f527f2 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,21 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "AppDebug", + "type": "cppdbg", + "request": "launch", + "miDebuggerPath": "gdb", + "program": "${workspaceFolder}/build/Server/HttpServer", + "args": [], + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "environment": [], + "externalConsole": false, + "logging": { + "engineLogging": false + }, + "MIMode": "gdb", + } + ] +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index bba3d00..74757cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,9 +11,10 @@ set(MBEDTLS_ROOT ${Libraries_ROOT}/mbedtls-3.6.2) set(MBEDTLS_INCLUDE_DIR ${MBEDTLS_ROOT}/include) set(MBEDTLS_LIBRARY_DIRS ${MBEDTLS_ROOT}/lib) -set(WT_ROOT ${Libraries_ROOT}/wt-4.11.0) +set(WT_ROOT ${Libraries_ROOT}/wt-4.11.0_debug) set(WT_INCLUDE_DIR ${WT_ROOT}/include) set(WT_LIBRARY_DIRS ${WT_ROOT}/lib) +set(WT_LIBRARIES wtd wttestd wthttpd wtdbod wtdbosqlite3d) set(OPENSSL_LIBRARIES ssl crypto) diff --git a/WebApplication/CMakeLists.txt b/WebApplication/CMakeLists.txt index 5e9c680..e2c6498 100644 --- a/WebApplication/CMakeLists.txt +++ b/WebApplication/CMakeLists.txt @@ -30,10 +30,6 @@ target_link_directories(WebApplication ) target_link_libraries(WebApplication - PUBLIC wt - PUBLIC wttest - PUBLIC wthttp - PUBLIC wtdbo - PUBLIC wtdbosqlite3 + PRIVATE ${WT_LIBRARIES} PUBLIC Universal ) \ No newline at end of file diff --git a/WebApplication/model/BlogUserDatabase.cpp b/WebApplication/model/BlogUserDatabase.cpp index 09011bf..73d4f8d 100644 --- a/WebApplication/model/BlogUserDatabase.cpp +++ b/WebApplication/model/BlogUserDatabase.cpp @@ -38,6 +38,11 @@ Wt::Dbo::ptr BlogUserDatabase::find(const Wt::Auth::User &user) const { return m_user; } +Wt::Auth::User BlogUserDatabase::find(Wt::Dbo::ptr user) const { + m_user = user; + return Wt::Auth::User(std::to_string(m_user.id()), *this); +} + BlogUserDatabase::Transaction *BlogUserDatabase::startTransaction() { return new TransactionImpl(m_session); } @@ -109,6 +114,11 @@ void BlogUserDatabase::setLastLoginAttempt(const Wt::Auth::User &user, const Wt: m_user.modify()->lastLoginAttempt = t; } +Wt::Auth::PasswordHash BlogUserDatabase::password(const Wt::Auth::User &user) const { + WithUser find(*this, user); + return Wt::Auth::PasswordHash(m_user->passwordMethod, m_user->passwordSalt, m_user->password); +} + BlogUserDatabase::WithUser::WithUser(const BlogUserDatabase &self, const Wt::Auth::User &user) : transaction(self.m_session) { self.getUser(user.id()); diff --git a/WebApplication/model/BlogUserDatabase.h b/WebApplication/model/BlogUserDatabase.h index 6156258..5ce3b1c 100644 --- a/WebApplication/model/BlogUserDatabase.h +++ b/WebApplication/model/BlogUserDatabase.h @@ -12,6 +12,7 @@ public: BlogUserDatabase(Wt::Dbo::Session &session); ~BlogUserDatabase(); Wt::Dbo::ptr find(const Wt::Auth::User &user) const; + Wt::Auth::User find(Wt::Dbo::ptr user) const; Transaction *startTransaction() final; Wt::Auth::User findWithId(const std::string &id) const final; @@ -20,6 +21,7 @@ public: void removeIdentity(const Wt::Auth::User &user, const std::string &provider) final; Wt::WString identity(const Wt::Auth::User &user, const std::string &provider) const final; void setLastLoginAttempt(const Wt::Auth::User &user, const Wt::WDateTime &t) final; + Wt::Auth::PasswordHash password(const Wt::Auth::User &user) const final; protected: struct WithUser { diff --git a/WebApplication/model/User.h b/WebApplication/model/User.h index 5336569..9d5573f 100644 --- a/WebApplication/model/User.h +++ b/WebApplication/model/User.h @@ -23,8 +23,13 @@ public: Posts allPosts(Post::State state) const; Wt::WString name; Role role; + + std::string password; + std::string passwordMethod; + std::string passwordSalt; int failedLoginAttempts; Wt::WDateTime lastLoginAttempt; + std::string oAuthId; std::string oAuthProvider; @@ -35,6 +40,10 @@ public: template void persist(Action &a) { Wt::Dbo::field(a, name, "name"); + Wt::Dbo::field(a, password, "password"); + Wt::Dbo::field(a, passwordMethod, "password_method"); + Wt::Dbo::field(a, passwordSalt, "password_salt"); + Wt::Dbo::field(a, role, "role"); Wt::Dbo::field(a, failedLoginAttempts, "failed_login_attempts"); Wt::Dbo::field(a, lastLoginAttempt, "last_login_attempt"); Wt::Dbo::field(a, oAuthId, "oauth_id"); diff --git a/WebApplication/view/BlogLoginWidget.cpp b/WebApplication/view/BlogLoginWidget.cpp index dc035dc..2bc4a8c 100644 --- a/WebApplication/view/BlogLoginWidget.cpp +++ b/WebApplication/view/BlogLoginWidget.cpp @@ -1,6 +1,8 @@ #include "BlogLoginWidget.h" #include "model/BlogSession.h" #include +#include +#include BlogLoginWidget::BlogLoginWidget(BlogSession &session, const std::string &basePath) : AuthWidget(session.login()) { setInline(true); @@ -13,3 +15,26 @@ BlogLoginWidget::BlogLoginWidget(BlogSession &session, const std::string &basePa setInternalBasePath(basePath + "login"); } + +void BlogLoginWidget::createLoginView() { + AuthWidget::createLoginView(); + + setTemplateText(tr("blog-login")); + + Wt::WLineEdit *userName = resolve("user-name"); + userName->setPlaceholderText("login"); + userName->setToolTip("login"); + + Wt::WLineEdit *password = resolve("password"); + password->setPlaceholderText("password"); + password->setToolTip("password"); +} + +void BlogLoginWidget::createLoggedInView() { + AuthWidget::createLoggedInView(); + + auto logout = std::make_unique(tr("logout")); + logout->setStyleClass("link"); + logout->clicked().connect(&login(), &Wt::Auth::Login::logout); + bindWidget("logout", std::move(logout)); +} diff --git a/WebApplication/view/BlogLoginWidget.h b/WebApplication/view/BlogLoginWidget.h index e497ef9..3270459 100644 --- a/WebApplication/view/BlogLoginWidget.h +++ b/WebApplication/view/BlogLoginWidget.h @@ -8,5 +8,7 @@ class BlogSession; class BlogLoginWidget : public Wt::Auth::AuthWidget { public: BlogLoginWidget(BlogSession &session, const std::string &basePath); + void createLoginView() final; + void createLoggedInView() final; }; #endif // __BLOGLOGINWIDGET_H__ \ No newline at end of file diff --git a/WebApplication/view/BlogView.cpp b/WebApplication/view/BlogView.cpp index f00c76d..cd000ab 100644 --- a/WebApplication/view/BlogView.cpp +++ b/WebApplication/view/BlogView.cpp @@ -39,7 +39,7 @@ public: auto loginLink = std::make_unique(tr("login")); auto lPtr = loginLink.get(); loginLink->setStyleClass("link"); - loginLink->clicked().connect(m_loginWidget, &WWidget::show); + loginLink->clicked().connect(m_loginWidget, &BlogLoginWidget::show); loginLink->clicked().connect(lPtr, &WWidget::hide); auto registerLink = std::make_unique(tr("Wt.Auth.register")); diff --git a/resources/build.sh b/resources/build.sh index 982c6f9..894ca12 100755 --- a/resources/build.sh +++ b/resources/build.sh @@ -21,8 +21,9 @@ function cmake_scan() { } function build() { - # pkill -9 HttpServer - # cp -r /opt/Libraries/wt-4.11.0/share/Wt/* ./build + reset + pkill -9 HttpServer + cp -r /opt/Libraries/wt-4.11.0/share/Wt/* ./build if [ ! -f "${build_path}/CMakeCache.txt" ]; then cmake_scan @@ -34,6 +35,11 @@ function build() { if [ $? -ne 0 ]; then exit 1 fi + cp WebApplication/blog.xml ./build/ + mkdir -p ${build_path}/css; cp WebApplication/blog.css ./build/css/ + cp WebApplication/rss.png ./build/css/ + cp WebApplication/blogexample.css ./build/css/ + cp WebApplication/asciidoc.css ./build/css/ build/UnitTest/UnitTest }