fixed warnings

This commit is contained in:
Bartosz Wieczorek 2018-01-25 11:10:53 +01:00
parent 73f4b636fb
commit db8809a87e
38 changed files with 114 additions and 130 deletions

View File

@ -9,6 +9,7 @@ HunterGate(
project(eedb)
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
set(HUNTER_BUILD_SHARED_LIBS TRUE)
include(cmake/Compiler.cmake)

View File

@ -1 +1 @@
add_definitions( -std=c++1z )
add_definitions( -std=c++17 )

View File

@ -20,7 +20,7 @@ Wt::WApplication * createApplication(const Wt::WEnvironment & env) {
using std::unique_ptr;
auto dbConfig = make_unique< eedb::db::PgConfig >(env);
// auto dbConnection = make_unique< eedb::db::PgConnection >(move(dbConfig));
auto dbConnection = make_unique< eedb::db::PgConnection >(move(dbConfig));
// auto session = unique_ptr< eedb::Session >(make_unique< eedb::WebSession >(move(dbConnection), env));
// auto authPageFactory = [_session = session.get()]()->std::unique_ptr< eedb::AuthPage > {

View File

@ -67,4 +67,4 @@ void EEDB::authEventLogout() {
redirect(url());
quit();
}
}
} // namespace eedb

View File

@ -35,4 +35,4 @@ class EEDB : public Wt::WApplication {
HomePageFactory _homePageFactory;
std::unique_ptr< eedb::HomePage > _homePage;
};
}
} // namespace eedb

View File

@ -4,8 +4,7 @@
#include <eedb/db/connection.hpp>
namespace eedb {
WebSession::WebSession(std::unique_ptr< eedb::db::PgConnection > dbConnection,
const Wt::WEnvironment & env)
WebSession::WebSession(std::unique_ptr< eedb::db::PgConnection > dbConnection, const Wt::WEnvironment & env)
: _dbConnection(std::move(dbConnection)), _env(env) {}
db::PgConnection & WebSession::db() {
@ -19,4 +18,4 @@ const Wt::WEnvironment & WebSession::enviroment() const {
Wt::Auth::Login & WebSession::login() {
return _login;
}
}
} // namespace eedb

View File

@ -38,4 +38,4 @@ class WebSession final : public Session {
Wt::Auth::Login _login;
const Wt::WEnvironment & _env;
};
}
} // namespace eedb

View File

@ -17,6 +17,7 @@
#include <iostream>
#include <random>
#include <string>
#include <experimental/string_view>
#include <Wt/Auth/AuthService.h>
#include <Wt/Auth/Dbo/AuthInfo.h>
@ -30,15 +31,15 @@ using namespace Wt::Auth;
// enum LoginActions { Login, Logout };
// static std::array< std::string_view, 2 > UserActionNames = {{"login", "logout"}};
std::string RandomString(int len) {
std::string RandomString(uint len) {
using namespace std;
srand(time(0));
string str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
srand(static_cast< unsigned int >(time(nullptr)));
experimental::string_view str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
string newstr;
int pos;
std::size_t pos;
while(newstr.size() != len) {
pos = ((rand() % (str.size() - 1)));
newstr += str.substr(pos, 1);
pos = ((rand() % (static_cast< int >(str.size()) - 1)));
newstr += str.substr(pos, 1).to_string();
}
return newstr;
}
@ -53,8 +54,7 @@ struct TransactionGuard : public Wt::Auth::AbstractUserDatabase::Transaction {
_c.native()->commit_transaction();
}
void rollback() override {
///FIXME
// _c.native()->rollback_transaction();
_c.native()->rollback_transaction(false);
}
private:
@ -85,8 +85,6 @@ namespace {
.limit(1u);
} // namespace
PgUserAuth::~PgUserAuth() {}
PgUserAuth::PgUserAuth(eedb::db::PgConnection & _db, const Wt::WEnvironment & env) : db(_db), _env(env) {
this->setAuthService(eedb::auth::Services::authService());
}
@ -106,7 +104,7 @@ User PgUserAuth::findWithId(const std::string & id) const {
User PgUserAuth::findWithIdentity(const std::string & provider, const Wt::WString & identity) const {
auto _identity = identity.toUTF8();
if(_authService && _authService->identityPolicy() == Wt::Auth::IdentityPolicy::EmailAddress ) {
if(_authService && _authService->identityPolicy() == Wt::Auth::IdentityPolicy::EmailAddress) {
std::transform(_identity.begin(), _identity.end(), _identity.begin(), ::tolower);
}

View File

@ -22,7 +22,6 @@ class PgUserAuth : public Wt::Auth::AbstractUserDatabase {
_authService = s;
}
virtual ~PgUserAuth();
PgUserAuth(eedb::db::PgConnection & db, const Wt::WEnvironment & env);
Transaction * startTransaction() override;

View File

@ -18,15 +18,16 @@ namespace {
class MyOAuth : public std::vector< const Wt::Auth::OAuthService * > {
public:
~MyOAuth() {
for(unsigned i = 0; i < size(); ++i)
for(unsigned i = 0; i < size(); ++i) {
delete(*this)[i];
}
}
};
Wt::Auth::AuthService myAuthService;
Wt::Auth::PasswordService myPasswordService(myAuthService);
MyOAuth myOAuthServices;
}
} // namespace
namespace eedb::auth {
Wt::Auth::AuthService * Services::authService() {
@ -46,7 +47,7 @@ void Services::configureAuth() {
myAuthService.setEmailVerificationEnabled(true);
myAuthService.setEmailVerificationRequired(true);
{
auto verifier = std::unique_ptr<Wt::Auth::PasswordVerifier>();
auto verifier = std::unique_ptr< Wt::Auth::PasswordVerifier >();
verifier->addHashFunction(std::make_unique< Wt::Auth::BCryptHashFunction >(7));
myPasswordService.setVerifier(std::move(verifier));
}
@ -54,13 +55,16 @@ void Services::configureAuth() {
myPasswordService.setAttemptThrottlingEnabled(true);
myPasswordService.setStrengthValidator(std::make_unique< Wt::Auth::PasswordStrengthValidator >());
if(Wt::Auth::GoogleService::configured())
if(Wt::Auth::GoogleService::configured()) {
myOAuthServices.push_back(new Wt::Auth::GoogleService(myAuthService));
}
if(Wt::Auth::FacebookService::configured())
if(Wt::Auth::FacebookService::configured()) {
myOAuthServices.push_back(new Wt::Auth::FacebookService(myAuthService));
}
for(unsigned i = 0; i < myOAuthServices.size(); ++i)
for(unsigned i = 0; i < myOAuthServices.size(); ++i) {
myOAuthServices[i]->generateRedirectEndpoint();
}
}
};
} // namespace eedb::auth

View File

@ -19,4 +19,4 @@ class Services {
static std::vector< const Wt::Auth::OAuthService * > oAuthServices();
};
}
} // namespace eedb::auth

View File

@ -4,4 +4,4 @@ namespace eedb {
class Category {
public:
};
}
} // namespace eedb

View File

@ -27,4 +27,4 @@ class IUserRepository {
virtual void remove(User);
};
}
} // namespace eedb

View File

@ -28,12 +28,11 @@ auto auth = t_user.join(t_info).on(t_user.uid == t_info.user_uid).join(t_identit
auto auth_info_identity = t_info.join(t_identity).on(t_info.id == t_identity.auth_info_id);
auto user_auth_info = t_user.join(t_info).on(t_info.user_uid == t_user.uid);
auto auth_token_info = user_auth_info.join(authToken).on(authToken.auth_info_id == t_info.id);
}
} // namespace
namespace eedb {
PgUserIdentity::PgUserIdentity(db::PgConnection & con, int uid, string provider)
: _db(con), _provider(std::move(provider)), _email("") {
PgUserIdentity::PgUserIdentity(db::PgConnection & con, int uid, string provider) : _db(con), _provider(std::move(provider)), _email("") {
select(all_of(t_identity)) //
.from(auth_info_identity) //
.where(t_info.user_uid == uid);
@ -50,12 +49,11 @@ AuthIdentity::string_view PgUserIdentity::identity() const {
if(res.empty())
return {};
// _name = res.front().identity;
// _name = res.front().identity;
return _name;
}
AuthIdentity::string_view PgUserIdentity::provider() const {}
const AuthIdentity & PgUser::identity() const {}
@ -69,4 +67,4 @@ void PgUser::changePassword(UserPassword & password) {}
void PgUser::login(UserPassword & password) {}
void PgUser::logout() {}
}
} // namespace eedb

View File

@ -15,6 +15,7 @@ class PgUserIdentity : public AuthIdentity {
string_view identity() const override;
string_view provider() const override;
private:
eedb::db::PgConnection & _db;
string _name;
@ -34,4 +35,4 @@ class PgUser : public User {
void login(UserPassword & password) override;
void logout() override;
};
}
} // namespace eedb

View File

@ -1,8 +1,8 @@
#include <eedb/data/PgUsers.hpp>
#include <eedb/data/PgUser.hpp>
#include <eedb/data/PgUsers.hpp>
#include <eedb/model/auth_info.h>
#include <eedb/model/auth_identity.h>
#include <eedb/model/auth_info.h>
#include <eedb/model/auth_token.h>
namespace eedb {
@ -10,24 +10,14 @@ namespace eedb {
template < typename T >
using shared_ptr = PgUsers::shared_ptr< T >;
shared_ptr< User > PgUsers::findWith(int) const {
shared_ptr< User > PgUsers::findWith(int) const {}
}
shared_ptr< User > PgUsers::findWith(const AuthIdentity & identity) const {}
shared_ptr< User > PgUsers::findWith(const AuthIdentity & identity) const {
shared_ptr< User > PgUsers::findWith(const Email & email) const {}
}
shared_ptr< User > PgUsers::findWith(const Users::AuthToken & token) const {}
shared_ptr< User > PgUsers::findWith(const Email & email) const {
shared_ptr< User > PgUsers::addUser(unique_ptr< AuthIdentity >) {}
}
shared_ptr< User > PgUsers::findWith(const Users::AuthToken & token) const {
}
shared_ptr< User > PgUsers::addUser(unique_ptr< AuthIdentity >) {
}
}
} // namespace eedb

View File

@ -13,4 +13,4 @@ class PgUsers : public Users {
shared_ptr< User > addUser(unique_ptr< AuthIdentity >) override;
};
}
} // namespace eedb

View File

@ -1,7 +1,3 @@
#include "User.hpp"
namespace eedb {
}
namespace eedb {}

View File

@ -139,4 +139,4 @@ class User {
virtual void login(UserPassword & password) = 0;
virtual void logout() = 0;
};
}
} // namespace eedb

View File

@ -27,4 +27,4 @@ class Users {
// adds new user into users
virtual shared_ptr< User > addUser(unique_ptr< AuthIdentity >) = 0;
};
}
} // namespace eedb

View File

@ -3,5 +3,6 @@
namespace eedb::db {
PgConnection::PgConnection(std::shared_ptr<eedb::db::PgConfig> config) : _conn(std::make_unique< sqlpp::postgresql::connection >(config)) {}
}
PgConnection::PgConnection(std::shared_ptr< eedb::db::PgConfig > config)
: _conn(std::make_unique< sqlpp::postgresql::connection >(config)) {}
} // namespace eedb::db

View File

@ -23,4 +23,4 @@ class PgConnection {
private:
std::unique_ptr< sqlpp::postgresql::connection > _conn;
};
}
} // namespace eedb::db

View File

@ -21,4 +21,4 @@ class AuthPage {
virtual void registerOnUserStrongLogin(std::function< void() > f) = 0;
virtual void registerOnUserLogout(std::function< void() > f) = 0;
};
}
} // namespace eedb

View File

@ -4,12 +4,12 @@
namespace eedb {
std::shared_ptr<Wt::WTheme> BootstrapTheme::create() const {
auto theme = std::shared_ptr<Wt::WBootstrapTheme>();
std::shared_ptr< Wt::WTheme > BootstrapTheme::create() const {
auto theme = std::shared_ptr< Wt::WBootstrapTheme >();
theme->setVersion(Wt::WBootstrapTheme::Version::v3);
// theme->setResponsive(true);
return theme;
}
Theme::~Theme() = default;
}
} // namespace eedb

View File

@ -11,4 +11,4 @@ class BootstrapTheme final : public Theme {
std::shared_ptr< Wt::WTheme > create() const override;
};
}
} // namespace eedb

View File

@ -18,4 +18,4 @@ class CategoriesTree {
virtual void registerOnCategoryChanged(std::function< void(const Category &) >) = 0;
};
}
} // namespace eedb

View File

@ -11,9 +11,10 @@ namespace std {
template <>
struct default_delete< Wt::Auth::AuthWidget > {
void operator()(Wt::Auth::AuthWidget * ptr) {
if(ptr && !ptr->parent())
if(ptr && !ptr->parent()) {
delete ptr;
}
}
};
} // namespace std
@ -23,7 +24,7 @@ struct DefaultAuthPage::DefaultAuthPagePriv {
DefaultAuthPagePriv(const auth::Services & baseAuth,
std::unique_ptr< Wt::Auth::AbstractUserDatabase > userDatabase,
Wt::Auth::Login & _login)
: _authWidget(std::make_unique< Wt::Auth::AuthWidget >(*baseAuth.authService(), *userDatabase.get(), _login)),
: _authWidget(std::make_unique< Wt::Auth::AuthWidget >(*baseAuth.authService(), *userDatabase, _login)),
_userDatabase(std::move(userDatabase)) {
_authWidget->model()->addPasswordAuth(eedb::auth::Services::passwordService());
_authWidget->model()->addOAuth(eedb::auth::Services::oAuthServices());
@ -43,18 +44,18 @@ DefaultAuthPage::DefaultAuthPage(const auth::Services & baseAuth,
std::unique_ptr< Wt::Auth::AbstractUserDatabase > userDatabase,
Wt::Auth::Login & _login)
: _priv(std::make_unique< DefaultAuthPagePriv >(baseAuth, std::move(userDatabase), _login)) {
///FIXME
/// FIXME
// _priv->_authWidget->login().changed().connect([this](auto...) {
// if(_priv->_authWidget->login().state() == Wt::Auth::LoginState::Strong) {
// this->notifyUserStrongLogin();
// } else if(_priv->_authWidget->login().state() == Wt::Auth::LoginState::Weak) {
// this->notifyUserWeakLogin();
// } else if(_priv->_authWidget->login().state() == Wt::Auth::LoginState::Disabled) {
// this->notifyNeedEmailVerification();
// } else {
// this->notifyUserLogout();
// }
// });
// if(_priv->_authWidget->login().state() == Wt::Auth::LoginState::Strong) {
// this->notifyUserStrongLogin();
// } else if(_priv->_authWidget->login().state() == Wt::Auth::LoginState::Weak) {
// this->notifyUserWeakLogin();
// } else if(_priv->_authWidget->login().state() == Wt::Auth::LoginState::Disabled) {
// this->notifyNeedEmailVerification();
// } else {
// this->notifyUserLogout();
// }
// });
}
DefaultAuthPage::DefaultAuthPage(DefaultAuthPage && rhs) : _priv(std::move(rhs._priv)) {}
@ -64,15 +65,15 @@ DefaultAuthPage & DefaultAuthPage::operator=(DefaultAuthPage && rhs) {
return *this;
}
DefaultAuthPage::~DefaultAuthPage() = default;
void DefaultAuthPage::attachTo(Wt::WContainerWidget * parent) {
parent->addWidget(std::move(_priv->_authWidget));
}
void DefaultAuthPage::detach() {
auto parent = dynamic_cast< Wt::WContainerWidget * >(_priv->_authWidget->parent());
if(parent)
if(parent) {
parent->removeWidget(_priv->_authWidget.get());
}
}
void DefaultAuthPage::processEnvironment() {

View File

@ -7,7 +7,7 @@
namespace Wt::Auth {
class AbstractUserDatabase;
class Login;
}
} // namespace Wt::Auth
namespace eedb::auth {
class Services;
@ -27,7 +27,6 @@ class DefaultAuthPage final : public AuthPage {
DefaultAuthPage & operator=(DefaultAuthPage &&);
// clang-format on
~DefaultAuthPage();
void attachTo(Wt::WContainerWidget * parent) override;
void detach() override;
void processEnvironment() override;
@ -47,4 +46,4 @@ class DefaultAuthPage final : public AuthPage {
struct DefaultAuthPagePriv;
std::unique_ptr< DefaultAuthPagePriv > _priv;
};
}
} // namespace eedb

View File

@ -7,14 +7,16 @@
namespace std {
/// TODO remove
template <>
struct default_delete< Wt::WTreeView > {
void operator()(Wt::WTreeView * ptr) {
if(ptr && !ptr->parent())
if(ptr && !ptr->parent()) {
delete ptr;
}
}
};
}
} // namespace std
namespace eedb {
@ -34,4 +36,4 @@ void DefaultCategoriesTree::attachTo(Wt::WContainerWidget * parent) {
}
void DefaultCategoriesTree::registerOnCategoryChanged(std::function< void(const Category &) >) {}
}
} // namespace eedb

View File

@ -10,7 +10,7 @@ class DefaultCategoriesTree final : public CategoriesTree {
// CategoriesTree interface
public:
DefaultCategoriesTree();
~DefaultCategoriesTree();
~DefaultCategoriesTree() override;
DefaultCategoriesTree(const DefaultCategoriesTree &) = delete;
DefaultCategoriesTree(DefaultCategoriesTree &&);
@ -28,4 +28,4 @@ class DefaultCategoriesTree final : public CategoriesTree {
struct DefaultCategoriesTreePriv;
std::unique_ptr< DefaultCategoriesTreePriv > _priv;
};
}
} // namespace eedb

View File

@ -8,7 +8,7 @@ namespace Wt {
class WContainerWidget;
class WTreeView;
class WNavigationBar;
}
} // namespace Wt
namespace eedb {
class Session;
@ -17,7 +17,7 @@ class NavigationBar;
class DefaultHomePage final : public HomePage {
public:
DefaultHomePage(Session & session, std::unique_ptr< NavigationBar > navigationBar);
~DefaultHomePage();
~DefaultHomePage() override;
void attachTo(Wt::WContainerWidget * parent) override;
@ -28,4 +28,4 @@ class DefaultHomePage final : public HomePage {
std::unique_ptr< NavigationBar > _navigationBar;
Wt::WTreeView * _categoryTree;
};
}
} // namespace eedb

View File

@ -17,8 +17,8 @@ struct DefaultNavigationBar::DefaultNavigationBarPriv {
auto mainTabs = std::make_unique< Wt::WMenu >();
auto homeItem = mainTabs->addItem("Home");
homeItem->setObjectName("navigation_bar.home_menu");
///FIXME
// homeItem->triggered().connect([=](auto...) {});
/// FIXME
// homeItem->triggered().connect([=](auto...) {});
// Setup a Right-aligned menu.
// Create a popup submenu for the Help menu.

View File

@ -5,7 +5,7 @@
namespace Wt::Auth {
class AbstractUserDatabase;
class Login;
}
} // namespace Wt::Auth
namespace eedb {
class DefaultNavigationBar final : public NavigationBar {
@ -19,7 +19,7 @@ class DefaultNavigationBar final : public NavigationBar {
DefaultNavigationBar & operator=(const DefaultNavigationBar &) = delete;
DefaultNavigationBar & operator=(DefaultNavigationBar &&);
// clang-format on
~DefaultNavigationBar();
~DefaultNavigationBar() override;
void attachTo(Wt::WContainerWidget * parent) override;
void detach() override;
@ -30,4 +30,4 @@ class DefaultNavigationBar final : public NavigationBar {
struct DefaultNavigationBarPriv;
std::unique_ptr< DefaultNavigationBarPriv > _priv;
};
}
} // namespace eedb

View File

@ -4,7 +4,6 @@ namespace Wt {
class WContainerWidget;
}
namespace eedb {
class HomePage {
@ -14,4 +13,4 @@ class HomePage {
virtual void attachTo(Wt::WContainerWidget * parent) = 0;
};
}
} // namespace eedb

View File

@ -10,7 +10,7 @@
void eedb::MenuTree::createTree() {
using namespace eedb::db;
// using namespace sqlpp;
// using namespace sqlpp;
Wt::WTree * tree = new Wt::WTree();
@ -23,14 +23,14 @@ void eedb::MenuTree::createTree() {
tree->setTreeRoot(std::move(node));
node->label()->setTextFormat(Wt::TextFormat::Plain);
node->setLoadPolicy(Wt::ContentLoading::Lazy);
///FIXME
// const eedb::category cat;
/// FIXME
// const eedb::category cat;
// auto r = _db(sqlpp::select(sqlpp::all_of(cat)).from(cat).where(cat.parent_path < 'root'));
// auto r = _db(sqlpp::select(sqlpp::all_of(cat)).from(cat).where(cat.parent_path < 'root'));
// for(const auto & row : r) {
// node->addChildNode(new Wt::WTreeNode(row.Name));
// }
// for(const auto & row : r) {
// node->addChildNode(new Wt::WTreeNode(row.Name));
// }
// if (_db.is_open()){
// auto sql = "SELECT * FROM category WHERE parent_path <@ 'root'";

View File

@ -9,16 +9,13 @@ namespace eedb::db {
class PgConnection;
}
namespace eedb {
class MenuTree{
public:
MenuTree(db::PgConnection & con):
_db(con)
{}
class MenuTree {
public:
MenuTree(db::PgConnection & con) : _db(con) {}
private:
private:
void createTree();
eedb::db::PgConnection & _db;
};
}
} // namespace eedb

View File

@ -17,4 +17,4 @@ class NavigationBar {
virtual void registerLogoutAction(std::function< void() > f) = 0;
};
}
} // namespace eedb

View File

@ -14,8 +14,7 @@ class Theme {
virtual ~Theme();
virtual std::shared_ptr<Wt::WTheme> create() const = 0;
virtual std::shared_ptr< Wt::WTheme > create() const = 0;
};
}
} // namespace eedb