summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2018-03-04 17:58:41 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2018-03-04 17:58:41 +0000
commit2bfbddea8ea72c0eaa9ab7196702554f0ba7d84e (patch)
tree220048f1a9c07aec2abbb0e496617c468d17a860
parentRefactor timer task setup to make it simplier, more generic (diff)
downloadgentoobrowse-api-2bfbddea8ea72c0eaa9ab7196702554f0ba7d84e.tar.bz2
gentoobrowse-api-2bfbddea8ea72c0eaa9ab7196702554f0ba7d84e.tar.xz
gentoobrowse-api-2bfbddea8ea72c0eaa9ab7196702554f0ba7d84e.zip
Purge out unverified users after a period of time.
-rw-r--r--gentoobrowse-api/api/users.ice1
-rw-r--r--gentoobrowse-api/service/maintenanceCommon.cpp11
-rw-r--r--gentoobrowse-api/service/sql/users/prune.sql3
-rw-r--r--gentoobrowse-api/service/usersimpl.cpp12
-rw-r--r--gentoobrowse-api/service/usersimpl.h1
-rw-r--r--gentoobrowse-api/unittests/testUsers.cpp11
6 files changed, 39 insertions, 0 deletions
diff --git a/gentoobrowse-api/api/users.ice b/gentoobrowse-api/api/users.ice
index ef9de92..8dd72a2 100644
--- a/gentoobrowse-api/api/users.ice
+++ b/gentoobrowse-api/api/users.ice
@@ -17,6 +17,7 @@ module Gentoo {
NewUser create(string username, string password, string realname, string email) throws DuplicateDetails;
void mailshotsent(int id);
void remove(int id, string password) throws Slicer::NoRowsReturned;
+ void prune();
void track(int userId, int packageId);
void untrack(int userId, int packageId);
diff --git a/gentoobrowse-api/service/maintenanceCommon.cpp b/gentoobrowse-api/service/maintenanceCommon.cpp
index 8b0c810..ab8317f 100644
--- a/gentoobrowse-api/service/maintenanceCommon.cpp
+++ b/gentoobrowse-api/service/maintenanceCommon.cpp
@@ -41,10 +41,21 @@ namespace Gentoo {
}
};
+ class UserMaintenance : public BaseScheduledTask {
+ public:
+ UserMaintenance(Ice::CommunicatorPtr i) : BaseScheduledTask(i) { }
+
+ void runTimerTask() override {
+ auto u = getProxy<UsersPrx>("users");
+ u->prune();
+ }
+ };
+
Maintenance::Maintenance(IceTray::DatabasePoolPtr d, Ice::CommunicatorPtr ic, Ice::PropertiesPtr p) :
Maintenance::Maintenance(d)
{
addTask<AutoUpdatePackages>(ic, p, "SyncTime");
+ addTask<UserMaintenance>(ic, p, "UserMaintenanceTime");
}
Maintenance::Maintenance(IceTray::DatabasePoolPtr d) :
diff --git a/gentoobrowse-api/service/sql/users/prune.sql b/gentoobrowse-api/service/sql/users/prune.sql
new file mode 100644
index 0000000..72c78a3
--- /dev/null
+++ b/gentoobrowse-api/service/sql/users/prune.sql
@@ -0,0 +1,3 @@
+DELETE FROM gentoobrowse.users
+WHERE verifyguid IS NOT NULL
+AND signedup < now() - ?::INTERVAL
diff --git a/gentoobrowse-api/service/usersimpl.cpp b/gentoobrowse-api/service/usersimpl.cpp
index 8071bf9..13b5112 100644
--- a/gentoobrowse-api/service/usersimpl.cpp
+++ b/gentoobrowse-api/service/usersimpl.cpp
@@ -9,6 +9,7 @@
#include <sql/users/getNew.sql.h>
#include <sql/users/find.sql.h>
#include <sql/users/safeDelete.sql.h>
+#include <sql/users/prune.sql.h>
#include <sql/users/track.sql.h>
#include <sql/users/untrack.sql.h>
#include <sql/users/tracked.sql.h>
@@ -102,6 +103,17 @@ Users::remove(Ice::Int id, const std::string & password, const Ice::Current &)
}
void
+Users::prune(const Ice::Current & current)
+{
+ auto properties = current.adapter->getCommunicator()->getProperties();
+ auto prunePeriod = properties->getPropertyWithDefault("GentooBrowseAPI.Users.PrunePeriod", "8 weeks");
+ auto dbc = db->get();
+ auto prune = sql::users::prune.modify(dbc.get());
+ prune->bindParamS(0, prunePeriod);
+ prune->execute();
+}
+
+void
Users::track(Ice::Int userId, Ice::Int packageId, const Ice::Current &)
{
auto dbc = db->get();
diff --git a/gentoobrowse-api/service/usersimpl.h b/gentoobrowse-api/service/usersimpl.h
index ac2a62b..57e0d79 100644
--- a/gentoobrowse-api/service/usersimpl.h
+++ b/gentoobrowse-api/service/usersimpl.h
@@ -20,6 +20,7 @@ class DLL_PUBLIC Users : public Gentoo::Users, IceTray::AbstractCachingDatabaseC
Gentoo::NewUserPtr create(const std::string &, const std::string &, const std::string &, const std::string &, const Ice::Current &) override;
void mailshotsent(Ice::Int id, const Ice::Current &) override;
void remove(Ice::Int id, const std::string &, const Ice::Current &) override;
+ void prune(const Ice::Current &) override;
void track(Ice::Int, Ice::Int, const Ice::Current &) override;
void untrack(Ice::Int, Ice::Int, const Ice::Current &) override;
diff --git a/gentoobrowse-api/unittests/testUsers.cpp b/gentoobrowse-api/unittests/testUsers.cpp
index c3380ed..0c8683e 100644
--- a/gentoobrowse-api/unittests/testUsers.cpp
+++ b/gentoobrowse-api/unittests/testUsers.cpp
@@ -113,6 +113,17 @@ BOOST_AUTO_TEST_CASE( createAgain )
BOOST_REQUIRE_EQUAL(36, user->verifyguid.length());
}
+BOOST_AUTO_TEST_CASE( prune )
+{
+ BOOST_REQUIRE(u->get(1)); // Verified
+ BOOST_REQUIRE(u->getNew("dontverify", "p@55w0rd")); // Old, not verified
+ BOOST_REQUIRE(u->getNew("testuser", "testpass")); // New, not verified
+ u->prune();
+ BOOST_REQUIRE(u->get(1)); // Not deleted, verified
+ BOOST_REQUIRE_THROW(u->getNew("dontverify", "p@55w0rd"), Slicer::NoRowsReturned); // Delete; Old, not verified
+ BOOST_REQUIRE(u->getNew("testuser", "testpass")); // Not delete; New, not verified
+}
+
BOOST_AUTO_TEST_CASE( verify )
{
auto user = u->getNew("testuser", "testpass");