verts-twmailer/user_handler.cpp
2023-10-17 17:18:19 +02:00

24 lines
646 B
C++

#include "user_handler.h"
#include "user.h"
#include <filesystem>
#include <string>
user_handler::user_handler()
{
for (const auto& entry : fs::directory_iterator()) {
if (entry.path().extension() == ".json") {
this->users.insert(std::pair<std::string, user*>(fs::path(entry.path()).replace_extension(), new user(entry)));
}
}
}
user* user_handler::getUser(std::string name)
{
if (this->users.find(name) == this->users.end()) {
this->users[name] = fs::exists(this->spool_dir/"users"/(name+".json")) ?
new user(this->spool_dir/"users"/(name+".json")) :
new user(name, this->spool_dir/"users");
}
return this->users[name];
}