mirror of
https://github.com/Relintai/rcpp_framework.git
synced 2025-05-02 13:47:56 +02:00
Implemented loading all file based users.
This commit is contained in:
parent
11d1d7327a
commit
17498aaf1d
@ -3,10 +3,10 @@
|
|||||||
#include "rapidjson/document.h"
|
#include "rapidjson/document.h"
|
||||||
#include "rapidjson/filewritestream.h"
|
#include "rapidjson/filewritestream.h"
|
||||||
#include "rapidjson/rapidjson.h"
|
#include "rapidjson/rapidjson.h"
|
||||||
|
#include "user_manager.h"
|
||||||
#include <rapidjson/writer.h>
|
#include <rapidjson/writer.h>
|
||||||
#include <tinydir/tinydir.h>
|
#include <tinydir/tinydir.h>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include "user_manager.h"
|
|
||||||
|
|
||||||
std::string FileBasedUser::get_path() {
|
std::string FileBasedUser::get_path() {
|
||||||
return _path;
|
return _path;
|
||||||
@ -23,6 +23,7 @@ void FileBasedUser::set_path(const std::string &path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void FileBasedUser::save() {
|
void FileBasedUser::save() {
|
||||||
|
//todo sanitize name!
|
||||||
_file_path = _path + name;
|
_file_path = _path + name;
|
||||||
|
|
||||||
rapidjson::Document document;
|
rapidjson::Document document;
|
||||||
@ -30,7 +31,6 @@ void FileBasedUser::save() {
|
|||||||
|
|
||||||
document.AddMember("id", id, document.GetAllocator());
|
document.AddMember("id", id, document.GetAllocator());
|
||||||
|
|
||||||
|
|
||||||
document.AddMember("name", rapidjson::Value(name.c_str(), document.GetAllocator()), document.GetAllocator());
|
document.AddMember("name", rapidjson::Value(name.c_str(), document.GetAllocator()), document.GetAllocator());
|
||||||
document.AddMember("email", rapidjson::Value(email.c_str(), document.GetAllocator()), document.GetAllocator());
|
document.AddMember("email", rapidjson::Value(email.c_str(), document.GetAllocator()), document.GetAllocator());
|
||||||
document.AddMember("rank", rank, document.GetAllocator());
|
document.AddMember("rank", rank, document.GetAllocator());
|
||||||
@ -62,9 +62,8 @@ void FileBasedUser::save() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void FileBasedUser::load(const std::string &p_name) {
|
void FileBasedUser::load(const std::string &p_name) {
|
||||||
name = p_name;
|
//todo sanitize name!
|
||||||
|
_file_path = _path + p_name;
|
||||||
_file_path = _path + name;
|
|
||||||
|
|
||||||
load();
|
load();
|
||||||
}
|
}
|
||||||
@ -116,7 +115,32 @@ void FileBasedUser::load() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void FileBasedUser::load_all() {
|
void FileBasedUser::load_all() {
|
||||||
|
tinydir_dir dir;
|
||||||
|
if (tinydir_open(&dir, _path.c_str()) == -1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (dir.has_next) {
|
||||||
|
tinydir_file file;
|
||||||
|
if (tinydir_readfile(&dir, &file) == -1) {
|
||||||
|
tinydir_next(&dir);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!file.is_dir) {
|
||||||
|
std::string np = file.path;
|
||||||
|
np = np.substr(_path.size(), np.size() - _path.size());
|
||||||
|
|
||||||
|
FileBasedUser *u = new FileBasedUser();
|
||||||
|
u->load(np);
|
||||||
|
|
||||||
|
UserManager::get_singleton()->add_user(u);
|
||||||
|
}
|
||||||
|
|
||||||
|
tinydir_next(&dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
tinydir_close(&dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
FileBasedUser::FileBasedUser() :
|
FileBasedUser::FileBasedUser() :
|
||||||
|
Loading…
Reference in New Issue
Block a user