1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
/*
* Copyright (C) 2012 Emweb bvba, Kessel-Lo, Belgium.
*
* See the LICENSE file for terms of use.
*/
#include "Session.h"
#include "Wt/Auth/AuthService"
#include "Wt/Auth/Dbo/AuthInfo"
#include "Wt/Auth/Dbo/UserDatabase"
namespace {
Wt::Auth::AuthService myAuthService;
}
void Session::configureAuth()
{
myAuthService.setAuthTokensEnabled(true, "logincookie");
}
Session::Session(const std::string& sqliteDb)
: connection_(sqliteDb)
{
connection_.setProperty("show-queries", "true");
setConnection(connection_);
mapClass<User>("user");
mapClass<AuthInfo>("auth_info");
mapClass<AuthInfo::AuthIdentityType>("auth_identity");
mapClass<AuthInfo::AuthTokenType>("auth_token");
try {
createTables();
std::cerr << "Created database." << std::endl;
} catch (std::exception& e) {
std::cerr << e.what() << std::endl;
std::cerr << "Using existing database";
}
users_ = new UserDatabase(*this);
}
Session::~Session()
{
delete users_;
}
Wt::Auth::AbstractUserDatabase& Session::users()
{
return *users_;
}
dbo::ptr<User> Session::user() const
{
if (login_.loggedIn()) {
dbo::ptr<AuthInfo> authInfo = users_->find(login_.user());
return authInfo->user();
} else
return dbo::ptr<User>();
}
const Wt::Auth::AuthService& Session::auth()
{
return myAuthService;
}
|