Fix login, fix cmake linker variables
This commit is contained in:
parent
939e849901
commit
10e12c5d91
@ -18,7 +18,12 @@ include(cmake/Compiler.cmake)
|
||||
include(cmake/FindAllRequirements.cmake)
|
||||
include(cmake/cotire.cmake)
|
||||
|
||||
set(CMAKE_INSTALL_RPATH "${HUNTER_INSTALL_PREFIX}/lib")
|
||||
list(APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}/local/lib")
|
||||
link_directories(${CMAKE_BINARY_DIR}/local/lib)
|
||||
|
||||
list(APPEND CMAKE_INSTALL_RPATH "${HUNTER_INSTALL_PREFIX}/lib")
|
||||
list(APPEND CMAKE_INSTALL_RPATH "${CMAKE_BINARY_DIR}/local/lib")
|
||||
|
||||
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
|
||||
|
||||
include_directories(${CMAKE_BINARY_DIR}/local/include SYSTEM)
|
||||
|
||||
@ -32,13 +32,12 @@ execute_process(
|
||||
${Boost_LIBRARY_DIR_DEBUG}
|
||||
${CMAKE_BINARY_DIR}/local
|
||||
${CMAKE_BUILD_TYPE}
|
||||
# TIMEOUT <seconds>
|
||||
RESULT_VARIABLE rv
|
||||
OUTPUT_VARIABLE ov
|
||||
ERROR_VARIABLE ev
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/_3rdParty
|
||||
)
|
||||
|
||||
message("rv='${rv}'")
|
||||
message("ov='${ov}'")
|
||||
message("ev='${ev}'")
|
||||
#message("rv='${rv}'")
|
||||
#message("ov='${ov}'")
|
||||
#message("ev='${ev}'")
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
#include <eedb/auth/PgUserAuth.hpp>
|
||||
|
||||
#include <eedb/auth/Services.hpp>
|
||||
#include <eedb/AuthIdentities.hpp>
|
||||
#include <eedb/AuthIdentityConst.hpp>
|
||||
#include <eedb/AuthInfoConst.hpp>
|
||||
@ -8,6 +7,7 @@
|
||||
#include <eedb/Email.hpp>
|
||||
#include <eedb/Password.hpp>
|
||||
#include <eedb/Users.hpp>
|
||||
#include <eedb/auth/Services.hpp>
|
||||
|
||||
#include <Wt/Auth/AuthService.h>
|
||||
|
||||
@ -73,8 +73,7 @@ UserDatabase::UserDatabase(std::unique_ptr< eedb::Users > users)
|
||||
spdlog::get("default")->info("constructing userdatabase");
|
||||
}
|
||||
|
||||
UserDatabase::~UserDatabase()
|
||||
{
|
||||
UserDatabase::~UserDatabase() {
|
||||
spdlog::get("default")->info("destructing userdatabase");
|
||||
}
|
||||
|
||||
@ -153,7 +152,7 @@ void UserDatabase::addIdentity(const Wt::Auth::User & user, const std::string &
|
||||
//}
|
||||
// @registration
|
||||
Wt::WString UserDatabase::identity(const Wt::Auth::User & user, const std::string & provider) const {
|
||||
spdlog::get("default")->trace("user{} identity: '{}'", provider);
|
||||
spdlog::get("default")->trace("user{} identity: '{}'",user.id(), provider);
|
||||
if(user.id() == registration_id) {
|
||||
return Wt::WString{_priv->_identity.value_or("")};
|
||||
} else {
|
||||
@ -225,8 +224,6 @@ bool UserDatabase::setEmail(const Wt::Auth::User & user, const std::string & add
|
||||
|
||||
if(user.id() == registration_id) {
|
||||
_priv->_email = address;
|
||||
} else {
|
||||
assert(false); // email change not implemented
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -246,7 +243,8 @@ void UserDatabase::setUnverifiedEmail(const Wt::Auth::User & user, const std::st
|
||||
if(user.id() == registration_id) {
|
||||
_priv->_unverifiedEmail = address;
|
||||
} else {
|
||||
assert(false);
|
||||
///TODO after registration this is set to "" do something about that :)
|
||||
// assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -258,6 +256,11 @@ void UserDatabase::setEmailToken(const Wt::Auth::User & user, const Token & toke
|
||||
_priv->_emailToken = token.hash();
|
||||
_priv->_emailTokenExpire = exp;
|
||||
_priv->_emailTokenRole = static_cast< int >(role);
|
||||
} else if(token.empty()) {
|
||||
// after 'using' token app need to remove it from repo
|
||||
auto u = _priv->user(user);
|
||||
auto & tokens = u->authTokens();
|
||||
tokens.removeToken(tokens.find(AuthTokenRole::EmailToken)->token());
|
||||
} else {
|
||||
assert(false); // setting email token on existing user not supported
|
||||
}
|
||||
@ -269,7 +272,7 @@ std::string UserDatabase::unverifiedEmail(const Wt::Auth::User & user) const {
|
||||
assert(_priv->_unverifiedEmail.has_value());
|
||||
return _priv->_unverifiedEmail.value();
|
||||
} else {
|
||||
assert(false);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@ -289,7 +292,8 @@ Token UserDatabase::emailToken(const Wt::Auth::User & user) const {
|
||||
|
||||
EmailTokenRole UserDatabase::emailTokenRole(const Wt::Auth::User & user) const {
|
||||
spdlog::get("default")->trace("user{} get email token role", user.id());
|
||||
auto & tokens = _priv->_users->findWith(std::atoi(user.id().c_str()))->authTokens();
|
||||
auto u = _priv->user(user);
|
||||
auto & tokens = u->authTokens();
|
||||
if(tokens.find(AuthTokenRole::EmailToken)) {
|
||||
return EmailTokenRole::VerifyEmail;
|
||||
} else if(tokens.find(AuthTokenRole::PasswordReset)) {
|
||||
@ -327,6 +331,8 @@ void UserDatabase::setFailedLoginAttempts(const Wt::Auth::User & user, int count
|
||||
|
||||
int UserDatabase::failedLoginAttempts(const Wt::Auth::User & user) const {
|
||||
// return _userAuth.failedLoginAttempts({user.id()});
|
||||
/// TODO fixme set to true value
|
||||
return 0;
|
||||
}
|
||||
|
||||
void UserDatabase::setLastLoginAttempt(const Wt::Auth::User &, const Wt::WDateTime &) {}
|
||||
@ -346,22 +352,20 @@ void UserDatabase::logout(const Wt::Auth::User & user) {
|
||||
AbstractUserDatabase::Transaction * UserDatabase::startTransaction() {
|
||||
auto commit_create_user = [priv = _priv.get()]() {
|
||||
if(priv->_registration) {
|
||||
assert(priv->_email.has_value() || priv->_unverifiedEmail.has_value());
|
||||
assert(priv->_emailToken.has_value());
|
||||
assert(priv->_identity.has_value());
|
||||
assert(priv->_password.has_value());
|
||||
if((priv->_email.has_value() or priv->_unverifiedEmail.has_value()) and //
|
||||
priv->_emailToken.has_value() and //
|
||||
priv->_identity.has_value() and //
|
||||
priv->_password.has_value() and //
|
||||
priv->_emailTokenExpire.has_value()) {
|
||||
auto identity = std::make_unique< eedb::AuthIdentityConst >(priv->_identity.value(), priv->provider.value());
|
||||
auto password = eedb::Password{priv->_password->function(), priv->_password->salt(), priv->_password->value()};
|
||||
auto email = eedb::Email{priv->_email.value_or(priv->_unverifiedEmail.value())};
|
||||
|
||||
assert(priv->_emailTokenExpire.has_value());
|
||||
// assert(priv->_emailTokenRole.has_value());
|
||||
auto info = std::make_unique< AuthInfoConst >(std::move(password), std::move(email));
|
||||
|
||||
auto identity = std::make_unique< eedb::AuthIdentityConst >(priv->_identity.value(), priv->provider.value());
|
||||
|
||||
auto password = eedb::Password{priv->_password->function(), priv->_password->salt(), priv->_password->value()};
|
||||
auto email = eedb::Email{priv->_email.value_or(priv->_unverifiedEmail.value())};
|
||||
|
||||
auto info = std::make_unique< AuthInfoConst >(std::move(password), std::move(email));
|
||||
|
||||
priv->_users->addUser(std::move(info), std::move(identity));
|
||||
auto newUser = priv->_users->addUser(std::move(info), std::move(identity));
|
||||
newUser->authTokens().addToken(std::string{*(priv->_emailToken)}, eedb::AuthTokenRole::EmailToken);
|
||||
}
|
||||
}
|
||||
};
|
||||
return new TransactionGuard(_priv->_in_transaction, std::move(commit_create_user));
|
||||
|
||||
@ -6,7 +6,7 @@ file(GLOB ${LIB}_SOURCE src/*)
|
||||
find_package(Sqlpp-connector-postgresql REQUIRED)
|
||||
|
||||
# create library
|
||||
add_library(${LIB} ${${LIB}_SOURCE})
|
||||
add_library(${LIB} STATIC ${${LIB}_SOURCE})
|
||||
|
||||
# link all
|
||||
target_include_directories (${LIB}
|
||||
|
||||
@ -45,9 +45,9 @@ AuthTokenImpl::AuthTokenImpl(Connection & con,
|
||||
std::string hash,
|
||||
std::chrono::time_point< std::chrono::system_clock, std::chrono::microseconds > expirationtime)
|
||||
: _priv{spimpl::make_unique_impl< AuthTokenImplPriv >(con)} {
|
||||
_priv->id = uid;
|
||||
_priv->expire = expirationtime;
|
||||
_priv->hash = std::move(hash);
|
||||
_priv->id = uid;
|
||||
_priv->expire = expirationtime;
|
||||
_priv->hash = std::move(hash);
|
||||
_priv->updated = true;
|
||||
}
|
||||
|
||||
@ -56,8 +56,7 @@ std::string_view AuthTokenImpl::token() const {
|
||||
return _priv->hash;
|
||||
}
|
||||
|
||||
AuthToken::us_point AuthTokenImpl::expireTimepoint() const
|
||||
{
|
||||
AuthToken::us_point AuthTokenImpl::expireTimepoint() const {
|
||||
_priv->update();
|
||||
return _priv->expire;
|
||||
}
|
||||
@ -129,7 +128,7 @@ struct AuthTokensImpl::AuthTokensImplPriv {
|
||||
return iterator->second.get();
|
||||
}
|
||||
|
||||
AuthToken * add(std::string token) {
|
||||
AuthToken * add(std::string token, AuthTokenRole role) {
|
||||
/// FIXME role
|
||||
using namespace std::chrono;
|
||||
|
||||
@ -139,7 +138,7 @@ struct AuthTokensImpl::AuthTokensImplPriv {
|
||||
t_auth_token.value = token, //
|
||||
t_auth_token.auth_info_id = _owner->uid(), //
|
||||
t_auth_token.expires = exp,
|
||||
t_auth_token.role = 0) //
|
||||
t_auth_token.role = static_cast< int >(role)) //
|
||||
.returning(t_auth_token.id))
|
||||
.front()
|
||||
.id;
|
||||
@ -172,6 +171,6 @@ void AuthTokensImpl::removeToken(std::string_view token) {
|
||||
}
|
||||
|
||||
AuthToken * AuthTokensImpl::addToken(std::string hash, AuthTokenRole role) {
|
||||
return _priv->add(std::move(hash));
|
||||
return _priv->add(std::move(hash), role);
|
||||
}
|
||||
} // namespace eedb
|
||||
} // namespace eedb::pg
|
||||
|
||||
@ -36,7 +36,7 @@ struct UsersImpl::UsersImplPriv {
|
||||
|
||||
// where
|
||||
auto tokenNotExpired() const {
|
||||
return t_auth_token.expires < std::chrono::system_clock::now();
|
||||
return t_auth_token.expires > std::chrono::system_clock::now();
|
||||
}
|
||||
|
||||
auto tokenRole(AuthTokenRole role) const {
|
||||
|
||||
@ -6,6 +6,16 @@ file(GLOB_RECURSE ${LIB}_SOURCE src/*)
|
||||
find_package(wt)
|
||||
find_package(nlohmann_json CONFIG REQUIRED)
|
||||
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
set(Wt_LIBRARY wtd)
|
||||
set(Wt_HTTP_LIBRARY wthttpd)
|
||||
set(Wt_TEST_LIBRARY wttestd)
|
||||
else (CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||
set(Wt_LIBRARY wt)
|
||||
set(Wt_HTTP_LIBRARY wthttp)
|
||||
set(Wt_TEST_LIBRARY wttest)
|
||||
endif()
|
||||
|
||||
# create library
|
||||
add_library(${LIB} ${${LIB}_SOURCE})
|
||||
|
||||
@ -15,8 +25,8 @@ target_include_directories(${LIB}
|
||||
)
|
||||
|
||||
target_link_libraries(${LIB}
|
||||
PRIVATE wthttp # or {Wt_HTTP_DEBUG_LIBRARY}
|
||||
PRIVATE wt # or {Wt_DEBUG_LIBRARY}
|
||||
PRIVATE ${Wt_HTTP_LIBRARY}
|
||||
PRIVATE ${Wt_LIBRARY}
|
||||
PUBLIC auth
|
||||
PUBLIC eedb-api
|
||||
PUBLIC Boost::system
|
||||
|
||||
@ -14,10 +14,8 @@ class AuthPage;
|
||||
class HomePage;
|
||||
class IWebSession;
|
||||
|
||||
class User;
|
||||
|
||||
using AuthPageFactory = std::function< std::unique_ptr< AuthPage >() >;
|
||||
using HomePageFactory = std::function< std::unique_ptr< HomePage >(/*std::shared_ptr< User >*/) >;
|
||||
using HomePageFactory = std::function< std::unique_ptr< HomePage >() >;
|
||||
|
||||
class WebApplication : public Wt::WApplication {
|
||||
public:
|
||||
@ -31,9 +29,6 @@ class WebApplication : public Wt::WApplication {
|
||||
private:
|
||||
// application session
|
||||
std::unique_ptr< eedb::IWebSession > _session;
|
||||
|
||||
AuthPageFactory _authPageFactory;
|
||||
|
||||
HomePageFactory _homePageFactory;
|
||||
};
|
||||
} // namespace eedb
|
||||
|
||||
@ -7,6 +7,6 @@ class BootstrapTheme final : public Theme {
|
||||
public:
|
||||
~BootstrapTheme() override;
|
||||
|
||||
std::shared_ptr< Wt::WTheme > create() const override;
|
||||
std::unique_ptr< Wt::WTheme > create() const override;
|
||||
};
|
||||
} // namespace eedb
|
||||
|
||||
@ -19,7 +19,7 @@ class DefaultHomePage final : public HomePage {
|
||||
DefaultHomePage(Session & session, std::unique_ptr< NavigationBar > navigationBar);
|
||||
~DefaultHomePage() override;
|
||||
|
||||
void attachTo(Wt::WContainerWidget * parent) override;
|
||||
void attachTo(Wt::WContainerWidget * parent);
|
||||
|
||||
Wt::WNavigationBar * createNavigationBar(Wt::WContainerWidget * container);
|
||||
|
||||
|
||||
@ -1,16 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
namespace Wt {
|
||||
class WContainerWidget;
|
||||
}
|
||||
#include <Wt/WContainerWidget.h>
|
||||
|
||||
namespace eedb {
|
||||
|
||||
class HomePage {
|
||||
class HomePage : public Wt::WContainerWidget {
|
||||
public:
|
||||
virtual ~HomePage() = default;
|
||||
|
||||
virtual void attachTo(Wt::WContainerWidget * parent) = 0;
|
||||
};
|
||||
|
||||
} // namespace eedb
|
||||
|
||||
@ -14,7 +14,7 @@ class Theme {
|
||||
|
||||
virtual ~Theme() = default;
|
||||
|
||||
virtual std::shared_ptr< Wt::WTheme > create() const = 0;
|
||||
virtual std::unique_ptr< Wt::WTheme > create() const = 0;
|
||||
};
|
||||
|
||||
} // namespace eedb
|
||||
|
||||
@ -6,8 +6,8 @@ namespace eedb {
|
||||
|
||||
BootstrapTheme::~BootstrapTheme() = default;
|
||||
|
||||
std::shared_ptr< Wt::WTheme > BootstrapTheme::create() const {
|
||||
auto theme = std::make_shared< Wt::WBootstrapTheme >();
|
||||
std::unique_ptr< Wt::WTheme > BootstrapTheme::create() const {
|
||||
auto theme = std::make_unique< Wt::WBootstrapTheme >();
|
||||
theme->setVersion(Wt::WBootstrapTheme::Version::v3);
|
||||
theme->setResponsive(true);
|
||||
return theme;
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
#include <Wt/WStackedWidget.h>
|
||||
#include <Wt/WText.h>
|
||||
#include <Wt/WTextArea.h>
|
||||
#include <Wt/WTheme.h>
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
@ -30,17 +31,16 @@ using std::move;
|
||||
|
||||
namespace eedb {
|
||||
|
||||
WebApplication::WebApplication(std::unique_ptr<eedb::IWebSession> session, AuthPageFactory authPageFactory, HomePageFactory homePageFactory)
|
||||
: Wt::WApplication(session->enviroment()),
|
||||
_session(move(session)),
|
||||
_authPageFactory(move(authPageFactory)),
|
||||
_homePageFactory(move(homePageFactory)) {
|
||||
WebApplication::WebApplication(std::unique_ptr< eedb::IWebSession > session,
|
||||
AuthPageFactory authPageFactory,
|
||||
HomePageFactory homePageFactory)
|
||||
: Wt::WApplication(session->enviroment()), _session(move(session)), _homePageFactory(move(homePageFactory)) {
|
||||
useStyleSheet("/resources/style.css");
|
||||
setTheme(eedb::BootstrapTheme{}.create());
|
||||
|
||||
root()->addStyleClass("container");
|
||||
|
||||
auto authPage = _authPageFactory();
|
||||
auto authPage = authPageFactory();
|
||||
authPage->registerOnNeedVerification([] {});
|
||||
authPage->registerOnUserWeakLogin([=] { authEventLogin(LoginState::weak); });
|
||||
authPage->registerOnUserStrongLogin([=] { authEventLogin(LoginState::strong); });
|
||||
@ -50,21 +50,18 @@ WebApplication::WebApplication(std::unique_ptr<eedb::IWebSession> session, AuthP
|
||||
root()->addWidget(std::move(authPage));
|
||||
}
|
||||
|
||||
void WebApplication::authEventLogin(WebApplication::LoginState state) {
|
||||
// {
|
||||
// // auth widget must survive :)
|
||||
// auto authWidgetPtr = root()->findById("eedb.authWidget");
|
||||
// auto authWidget = root()->removeWidget(authWidgetPtr);
|
||||
// root()->clear();
|
||||
// root()->removeStyleClass("container");
|
||||
// if(authWidget)
|
||||
// root()->addWidget(std::move(authWidget));
|
||||
// }
|
||||
void WebApplication::authEventLogin(WebApplication::LoginState) {
|
||||
{
|
||||
// auth widget must survive :)
|
||||
auto authWidget = root()->removeWidget(root()->findById("eedb.authWidget"));
|
||||
root()->clear();
|
||||
root()->removeStyleClass("container");
|
||||
if(authWidget)
|
||||
root()->addWidget(std::move(authWidget));
|
||||
}
|
||||
|
||||
// _homePage = _homePageFactory();
|
||||
// _homePage->attachTo(root());
|
||||
|
||||
// new eedb::Home(container, &_authWidget->login());
|
||||
auto homePage = _homePageFactory();
|
||||
root()->addWidget(std::move(homePage));
|
||||
}
|
||||
|
||||
void WebApplication::authEventLogout() {
|
||||
|
||||
@ -10,7 +10,7 @@ file(GLOB_RECURSE TEST_FILES test_*.cpp )
|
||||
|
||||
add_executable( ${TEST_EXECUTABLE_NAME} ${TEST_FILES})
|
||||
target_link_libraries(${TEST_EXECUTABLE_NAME}
|
||||
PRIVATE wttest
|
||||
PRIVATE ${Wt_TEST_LIBRARY}
|
||||
PRIVATE eedb-api
|
||||
PRIVATE webapp
|
||||
PRIVATE webapp-mock
|
||||
|
||||
Loading…
Reference in New Issue
Block a user