#include "usersimpl.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace Gentoo { namespace Service { Users::Users(boost::shared_ptr> d) : IceTray::AbstractCachingDatabaseClient(d) { } Gentoo::UserPtr Users::authenticate(const std::string & username, const std::string & password, const Ice::Current &) { return fetchCache(sql::users::authenticate, 30, username, password); } Gentoo::UserPtr Users::verify(const std::string & username, const std::string & verifyguid, const Ice::Current &) { return fetch(sql::users::verify, username, verifyguid); } Gentoo::UserPtr Users::get(Ice::Int id, const Ice::Current &) { return fetch(sql::users::get, id); } Gentoo::UserPtr Users::find(const std::string & username, const Ice::Current &) { return fetch(sql::users::find, username); } Gentoo::NewUserPtr Users::create(const std::string & username, const std::string & password, const std::string & realname, const std::string & email, const Ice::Current & current) { auto notifications = NotificationsPrx::checkedCast(current.adapter->getCommunicator()->stringToProxy("notifications")); notifications->ice_ping(); auto mailServer = MailServerPrx::checkedCast(current.adapter->getCommunicator()->stringToProxy("mailserver")); mailServer->ice_ping(); auto dbc = db->get(); DB::TransactionScope tx(dbc.get()); auto newUser = fetch(sql::users::create, username, password, realname, email); auto mail = notifications->getSignup(newUser); mailServer->sendEmail(mail); return newUser; } void Users::mailshotsent(Ice::Int id, const Ice::Current &) { auto dbc = db->get(); auto upd = sql::users::mailshotsent.modify(dbc.get()); upd->bindParamI(0, id); upd->execute(); } void Users::remove(Ice::Int id, const std::string & password, const Ice::Current &) { auto dbc = db->get(); auto del = dbc->modify(sql::users::safeDelete.getSql()); del->bindParamI(0, id); del->bindParamS(1, password); del->execute(); } void Users::track(Ice::Int userId, Ice::Int packageId, const Ice::Current &) { auto dbc = db->get(); auto track = dbc->modify(sql::users::track.getSql()); track->bindParamI(0, userId); track->bindParamI(1, packageId); track->execute(); } void Users::untrack(Ice::Int userId, Ice::Int packageId, const Ice::Current &) { auto dbc = db->get(); auto untrack = dbc->modify(sql::users::untrack.getSql()); untrack->bindParamI(0, userId); untrack->bindParamI(1, packageId); untrack->execute(); } Gentoo::PackageIds Users::tracked(Ice::Int userId, const Ice::Current &) { return fetchCache(sql::users::tracked, 10, userId); } } }