return proper authtokens object from pguser

This commit is contained in:
Bartosz Wieczorek 2018-02-05 08:23:24 +01:00
parent cdf31fc1bf
commit a5a3893415
3 changed files with 26 additions and 22 deletions

View File

@ -1,5 +1,8 @@
#include <eedb/db/data/PgUser.hpp> #include <eedb/db/data/PgUser.hpp>
#include <eedb/db/data/PgAuthToken.hpp>
//#include <eedb/db/data/Pg
#include <eedb/db/connection.hpp> #include <eedb/db/connection.hpp>
#include <sqlpp11/sqlpp11.h> #include <sqlpp11/sqlpp11.h>
@ -35,14 +38,21 @@ auto auth_token_info = user_auth_info.join(authToken).on(authToken.auth_info_
namespace eedb { namespace eedb {
struct PgUser::PgUserPriv { struct PgUser::PgUserPriv {
PgUserPriv(db::PgConnection & db, int uid, PgUser * owner) : _db{db}, id{uid}, self{owner} {}
void initAuthTokens() {
_authTokens = std::make_unique< PgAuthTokens >(_db, self);
}
db::PgConnection & _db;
int id; int id;
PgUser *self;
UserConfig config; UserConfig config;
std::unique_ptr< PgAuthTokens > _authTokens;
}; };
PgUser::PgUser(int uid) : _priv{spimpl::make_unique_impl< PgUserPriv >()} { PgUser::PgUser(db::PgConnection & db, int uid) : _priv{spimpl::make_unique_impl< PgUserPriv >(db, uid, this)} {}
_priv->id = uid;
}
int PgUser::uid() const { int PgUser::uid() const {
return _priv->id; return _priv->id;
@ -55,11 +65,14 @@ const UserConfig & PgUser::config() const {
void PgUser::logout() { void PgUser::logout() {
// //
} }
AuthTokens & PgUser::authTokens() const {} AuthTokens & PgUser::authTokens() const {
if(!_priv->_authTokens)
_priv->initAuthTokens();
return *(_priv->_authTokens.get());
}
AuthIdentities &PgUser::authIdentities() const {} AuthIdentities & PgUser::authIdentities() const {}
AuthInfo & PgUser::authInfo() const {} AuthInfo & PgUser::authInfo() const {}
} // namespace eedb } // namespace eedb

View File

@ -12,7 +12,7 @@ namespace eedb {
class PgUser : public User { class PgUser : public User {
public: public:
PgUser(int uid); PgUser(db::PgConnection & db, int uid);
int uid() const override; int uid() const override;
@ -21,17 +21,11 @@ class PgUser : public User {
void logout() override; void logout() override;
AuthTokens & authTokens() const override; AuthTokens & authTokens() const override;
AuthIdentities &authIdentities() const override;
AuthInfo &authInfo() const override;
private: private:
struct PgUserPriv; struct PgUserPriv;
spimpl::unique_impl_ptr< PgUserPriv > _priv; spimpl::unique_impl_ptr< PgUserPriv > _priv;
// User interface
public:
AuthIdentities &authIdentities() const override;
// User interface
public:
AuthInfo &authInfo() const override;
}; };
} // namespace eedb } // namespace eedb

View File

@ -44,7 +44,7 @@ unique_ptr< User > PgUsers::findWith(const AuthIdentity & identity) const {
if(result.empty()) { if(result.empty()) {
return {}; return {};
} }
return std::make_unique< PgUser >(result.front().user_uid); return std::make_unique< PgUser >(_priv->_db, result.front().user_uid);
} }
unique_ptr< User > PgUsers::findWith(const Email & email) const { unique_ptr< User > PgUsers::findWith(const Email & email) const {
@ -56,13 +56,10 @@ unique_ptr< User > PgUsers::findWith(const Email & email) const {
if(result.empty()) { if(result.empty()) {
return {}; return {};
} }
return std::make_unique< PgUser >(result.front().user_uid); return std::make_unique< PgUser >(_priv->_db, result.front().user_uid);
} }
unique_ptr<User> PgUsers::findWith(const EmailToken &token) const unique_ptr< User > PgUsers::findWith(const EmailToken & token) const {}
{
}
// unique_ptr< User > PgUsers::findWith(const Users::AuthToken & token) const { // unique_ptr< User > PgUsers::findWith(const Users::AuthToken & token) const {
// return {}; // return {};
@ -103,7 +100,7 @@ unique_ptr< User > PgUsers::addUser(unique_ptr< AuthInfo > authInfo, unique_ptr<
t_auth_identity.identity = std::string{authIdentity->identity()}, t_auth_identity.identity = std::string{authIdentity->identity()},
t_auth_identity.provider = std::string{authIdentity->provider()})); t_auth_identity.provider = std::string{authIdentity->provider()}));
return std::make_unique< eedb::PgUser >(user_id); return std::make_unique< eedb::PgUser >(_priv->_db, user_id);
} }
} // namespace eedb } // namespace eedb