add code.
This commit is contained in:
parent
b6e0681489
commit
e1273a3eb9
21
.vscode/launch.json
vendored
Normal file
21
.vscode/launch.json
vendored
Normal file
@ -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",
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -11,9 +11,10 @@ set(MBEDTLS_ROOT ${Libraries_ROOT}/mbedtls-3.6.2)
|
|||||||
set(MBEDTLS_INCLUDE_DIR ${MBEDTLS_ROOT}/include)
|
set(MBEDTLS_INCLUDE_DIR ${MBEDTLS_ROOT}/include)
|
||||||
set(MBEDTLS_LIBRARY_DIRS ${MBEDTLS_ROOT}/lib)
|
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_INCLUDE_DIR ${WT_ROOT}/include)
|
||||||
set(WT_LIBRARY_DIRS ${WT_ROOT}/lib)
|
set(WT_LIBRARY_DIRS ${WT_ROOT}/lib)
|
||||||
|
set(WT_LIBRARIES wtd wttestd wthttpd wtdbod wtdbosqlite3d)
|
||||||
|
|
||||||
set(OPENSSL_LIBRARIES ssl crypto)
|
set(OPENSSL_LIBRARIES ssl crypto)
|
||||||
|
|
||||||
|
@ -30,10 +30,6 @@ target_link_directories(WebApplication
|
|||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(WebApplication
|
target_link_libraries(WebApplication
|
||||||
PUBLIC wt
|
PRIVATE ${WT_LIBRARIES}
|
||||||
PUBLIC wttest
|
|
||||||
PUBLIC wthttp
|
|
||||||
PUBLIC wtdbo
|
|
||||||
PUBLIC wtdbosqlite3
|
|
||||||
PUBLIC Universal
|
PUBLIC Universal
|
||||||
)
|
)
|
@ -38,6 +38,11 @@ Wt::Dbo::ptr<User> BlogUserDatabase::find(const Wt::Auth::User &user) const {
|
|||||||
return m_user;
|
return m_user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Wt::Auth::User BlogUserDatabase::find(Wt::Dbo::ptr<User> user) const {
|
||||||
|
m_user = user;
|
||||||
|
return Wt::Auth::User(std::to_string(m_user.id()), *this);
|
||||||
|
}
|
||||||
|
|
||||||
BlogUserDatabase::Transaction *BlogUserDatabase::startTransaction() {
|
BlogUserDatabase::Transaction *BlogUserDatabase::startTransaction() {
|
||||||
return new TransactionImpl(m_session);
|
return new TransactionImpl(m_session);
|
||||||
}
|
}
|
||||||
@ -109,6 +114,11 @@ void BlogUserDatabase::setLastLoginAttempt(const Wt::Auth::User &user, const Wt:
|
|||||||
m_user.modify()->lastLoginAttempt = t;
|
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)
|
BlogUserDatabase::WithUser::WithUser(const BlogUserDatabase &self, const Wt::Auth::User &user)
|
||||||
: transaction(self.m_session) {
|
: transaction(self.m_session) {
|
||||||
self.getUser(user.id());
|
self.getUser(user.id());
|
||||||
|
@ -12,6 +12,7 @@ public:
|
|||||||
BlogUserDatabase(Wt::Dbo::Session &session);
|
BlogUserDatabase(Wt::Dbo::Session &session);
|
||||||
~BlogUserDatabase();
|
~BlogUserDatabase();
|
||||||
Wt::Dbo::ptr<User> find(const Wt::Auth::User &user) const;
|
Wt::Dbo::ptr<User> find(const Wt::Auth::User &user) const;
|
||||||
|
Wt::Auth::User find(Wt::Dbo::ptr<User> user) const;
|
||||||
|
|
||||||
Transaction *startTransaction() final;
|
Transaction *startTransaction() final;
|
||||||
Wt::Auth::User findWithId(const std::string &id) const 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;
|
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;
|
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;
|
void setLastLoginAttempt(const Wt::Auth::User &user, const Wt::WDateTime &t) final;
|
||||||
|
Wt::Auth::PasswordHash password(const Wt::Auth::User &user) const final;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
struct WithUser {
|
struct WithUser {
|
||||||
|
@ -23,8 +23,13 @@ public:
|
|||||||
Posts allPosts(Post::State state) const;
|
Posts allPosts(Post::State state) const;
|
||||||
Wt::WString name;
|
Wt::WString name;
|
||||||
Role role;
|
Role role;
|
||||||
|
|
||||||
|
std::string password;
|
||||||
|
std::string passwordMethod;
|
||||||
|
std::string passwordSalt;
|
||||||
int failedLoginAttempts;
|
int failedLoginAttempts;
|
||||||
Wt::WDateTime lastLoginAttempt;
|
Wt::WDateTime lastLoginAttempt;
|
||||||
|
|
||||||
std::string oAuthId;
|
std::string oAuthId;
|
||||||
std::string oAuthProvider;
|
std::string oAuthProvider;
|
||||||
|
|
||||||
@ -35,6 +40,10 @@ public:
|
|||||||
template <class Action>
|
template <class Action>
|
||||||
void persist(Action &a) {
|
void persist(Action &a) {
|
||||||
Wt::Dbo::field(a, name, "name");
|
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, failedLoginAttempts, "failed_login_attempts");
|
||||||
Wt::Dbo::field(a, lastLoginAttempt, "last_login_attempt");
|
Wt::Dbo::field(a, lastLoginAttempt, "last_login_attempt");
|
||||||
Wt::Dbo::field(a, oAuthId, "oauth_id");
|
Wt::Dbo::field(a, oAuthId, "oauth_id");
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#include "BlogLoginWidget.h"
|
#include "BlogLoginWidget.h"
|
||||||
#include "model/BlogSession.h"
|
#include "model/BlogSession.h"
|
||||||
#include <Wt/Auth/PasswordService.h>
|
#include <Wt/Auth/PasswordService.h>
|
||||||
|
#include <Wt/WLineEdit.h>
|
||||||
|
#include <Wt/WText.h>
|
||||||
|
|
||||||
BlogLoginWidget::BlogLoginWidget(BlogSession &session, const std::string &basePath) : AuthWidget(session.login()) {
|
BlogLoginWidget::BlogLoginWidget(BlogSession &session, const std::string &basePath) : AuthWidget(session.login()) {
|
||||||
setInline(true);
|
setInline(true);
|
||||||
@ -13,3 +15,26 @@ BlogLoginWidget::BlogLoginWidget(BlogSession &session, const std::string &basePa
|
|||||||
|
|
||||||
setInternalBasePath(basePath + "login");
|
setInternalBasePath(basePath + "login");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BlogLoginWidget::createLoginView() {
|
||||||
|
AuthWidget::createLoginView();
|
||||||
|
|
||||||
|
setTemplateText(tr("blog-login"));
|
||||||
|
|
||||||
|
Wt::WLineEdit *userName = resolve<Wt::WLineEdit *>("user-name");
|
||||||
|
userName->setPlaceholderText("login");
|
||||||
|
userName->setToolTip("login");
|
||||||
|
|
||||||
|
Wt::WLineEdit *password = resolve<Wt::WLineEdit *>("password");
|
||||||
|
password->setPlaceholderText("password");
|
||||||
|
password->setToolTip("password");
|
||||||
|
}
|
||||||
|
|
||||||
|
void BlogLoginWidget::createLoggedInView() {
|
||||||
|
AuthWidget::createLoggedInView();
|
||||||
|
|
||||||
|
auto logout = std::make_unique<Wt::WText>(tr("logout"));
|
||||||
|
logout->setStyleClass("link");
|
||||||
|
logout->clicked().connect(&login(), &Wt::Auth::Login::logout);
|
||||||
|
bindWidget("logout", std::move(logout));
|
||||||
|
}
|
||||||
|
@ -8,5 +8,7 @@ class BlogSession;
|
|||||||
class BlogLoginWidget : public Wt::Auth::AuthWidget {
|
class BlogLoginWidget : public Wt::Auth::AuthWidget {
|
||||||
public:
|
public:
|
||||||
BlogLoginWidget(BlogSession &session, const std::string &basePath);
|
BlogLoginWidget(BlogSession &session, const std::string &basePath);
|
||||||
|
void createLoginView() final;
|
||||||
|
void createLoggedInView() final;
|
||||||
};
|
};
|
||||||
#endif // __BLOGLOGINWIDGET_H__
|
#endif // __BLOGLOGINWIDGET_H__
|
@ -39,7 +39,7 @@ public:
|
|||||||
auto loginLink = std::make_unique<Wt::WText>(tr("login"));
|
auto loginLink = std::make_unique<Wt::WText>(tr("login"));
|
||||||
auto lPtr = loginLink.get();
|
auto lPtr = loginLink.get();
|
||||||
loginLink->setStyleClass("link");
|
loginLink->setStyleClass("link");
|
||||||
loginLink->clicked().connect(m_loginWidget, &WWidget::show);
|
loginLink->clicked().connect(m_loginWidget, &BlogLoginWidget::show);
|
||||||
loginLink->clicked().connect(lPtr, &WWidget::hide);
|
loginLink->clicked().connect(lPtr, &WWidget::hide);
|
||||||
|
|
||||||
auto registerLink = std::make_unique<Wt::WText>(tr("Wt.Auth.register"));
|
auto registerLink = std::make_unique<Wt::WText>(tr("Wt.Auth.register"));
|
||||||
|
@ -21,8 +21,9 @@ function cmake_scan() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function build() {
|
function build() {
|
||||||
# pkill -9 HttpServer
|
reset
|
||||||
# cp -r /opt/Libraries/wt-4.11.0/share/Wt/* ./build
|
pkill -9 HttpServer
|
||||||
|
cp -r /opt/Libraries/wt-4.11.0/share/Wt/* ./build
|
||||||
|
|
||||||
if [ ! -f "${build_path}/CMakeCache.txt" ]; then
|
if [ ! -f "${build_path}/CMakeCache.txt" ]; then
|
||||||
cmake_scan
|
cmake_scan
|
||||||
@ -34,6 +35,11 @@ function build() {
|
|||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
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
|
build/UnitTest/UnitTest
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user