From 9c0dfd170e10ffd8a1f789a2fba2a014d65fcb9c Mon Sep 17 00:00:00 2001 From: Albert S Date: Fri, 3 May 2019 15:58:22 +0200 Subject: [PATCH] save anon-user permissions from config in database on startup (interim solution) --- qswiki.cpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/qswiki.cpp b/qswiki.cpp index d67b397..682453a 100644 --- a/qswiki.cpp +++ b/qswiki.cpp @@ -86,15 +86,29 @@ int main(int argc, char **argv) logstream.open(config.logfile, std::fstream::out | std::fstream::app); Logger::setStream(&logstream); - User anon; - anon.login = config.anon_username; - anon.permissions = config.anon_permissions; - User::setAnon(anon); - auto database = createDatabase(config); + + //TODO: quite ugly, anon-handling must be rethought + auto userdao = database->createUserDao(); + std::optional anon = userdao->find(config.anon_username); + if(!anon) + { + throw std::runtime_error("No such anon user in database"); + } + if(!anon->enabled) + { + throw std::runtime_error("Anon user cannot be enabled"); + } + anon->permissions = config.anon_permissions; + userdao->save(anon.value()); + User::setAnon(anon.value()); + Template siteTemplate { config }; UrlProvider urlprovider { config }; + + + auto cache = createCache(config); cache->clear(); RequestWorker requestWorker (*database, siteTemplate, urlprovider, *cache );