2021-07-07 12:20:05 +02:00
|
|
|
#ifndef USER_H
|
|
|
|
#define USER_H
|
|
|
|
|
2021-08-21 16:38:06 +02:00
|
|
|
#include "core/resource.h"
|
2021-07-07 12:20:05 +02:00
|
|
|
|
2021-08-21 18:28:29 +02:00
|
|
|
#include <mutex>
|
2021-07-07 12:20:05 +02:00
|
|
|
#include <string>
|
2021-08-03 21:10:24 +02:00
|
|
|
#include <vector>
|
2021-07-07 12:20:05 +02:00
|
|
|
|
2021-08-05 01:19:54 +02:00
|
|
|
class Request;
|
2021-08-20 18:00:50 +02:00
|
|
|
class FormValidator;
|
2021-08-05 01:19:54 +02:00
|
|
|
|
2021-08-21 16:38:06 +02:00
|
|
|
class User : public Resource {
|
|
|
|
RCPP_OBJECT(User, Resource);
|
2021-08-05 01:19:54 +02:00
|
|
|
|
2021-07-07 12:20:05 +02:00
|
|
|
public:
|
2021-08-22 13:46:39 +02:00
|
|
|
std::string name_user_input;
|
|
|
|
std::string email_user_input;
|
|
|
|
int rank;
|
|
|
|
std::string pre_salt;
|
|
|
|
std::string post_salt;
|
|
|
|
std::string password_hash;
|
|
|
|
bool banned;
|
|
|
|
std::vector<std::string> sessions;
|
|
|
|
std::string password_reset_token;
|
|
|
|
bool locked;
|
2021-08-03 21:10:24 +02:00
|
|
|
|
|
|
|
virtual void save();
|
|
|
|
virtual void load();
|
|
|
|
virtual void load(const std::string &p_name);
|
2021-08-19 23:55:36 +02:00
|
|
|
virtual void load(const int p_id);
|
2021-08-03 21:10:24 +02:00
|
|
|
virtual void changed();
|
|
|
|
virtual void update();
|
2021-07-07 12:20:05 +02:00
|
|
|
|
2021-08-22 13:37:28 +02:00
|
|
|
void migrate();
|
|
|
|
|
|
|
|
static void db_load_all();
|
|
|
|
|
2021-08-05 19:35:15 +02:00
|
|
|
virtual bool check_password(const std::string &p_password);
|
|
|
|
virtual void create_password(const std::string &p_password);
|
|
|
|
virtual std::string hash_password(const std::string &p_password);
|
|
|
|
|
2021-08-05 01:19:54 +02:00
|
|
|
static void handle_request_default(Request *request);
|
|
|
|
|
|
|
|
static void handle_login_request_default(Request *request);
|
|
|
|
static void handle_register_request_default(Request *request);
|
|
|
|
|
|
|
|
virtual void handle_request(Request *request);
|
|
|
|
virtual void handle_main_page_request(Request *request);
|
|
|
|
virtual void handle_settings_request(Request *request);
|
|
|
|
virtual void handle_password_reset_request(Request *request);
|
|
|
|
virtual void handle_logout_request(Request *request);
|
|
|
|
virtual void handle_delete_request(Request *request);
|
|
|
|
|
2021-08-20 19:18:26 +02:00
|
|
|
static void create_validators();
|
2021-08-20 18:00:50 +02:00
|
|
|
|
2021-08-04 21:29:19 +02:00
|
|
|
void register_sessions();
|
|
|
|
void unregister_sessions();
|
|
|
|
|
2021-08-22 13:30:58 +02:00
|
|
|
void file_save();
|
|
|
|
void file_load();
|
|
|
|
void file_ensure_directory_exist();
|
|
|
|
std::string file_get_base_path();
|
|
|
|
static void file_load_all();
|
|
|
|
static std::string file_get_path();
|
|
|
|
static void file_set_path(const std::string &path);
|
|
|
|
|
2021-08-21 20:15:29 +02:00
|
|
|
std::string to_json(rapidjson::Document *into = nullptr);
|
|
|
|
void from_json(const std::string &data);
|
2021-08-21 18:28:29 +02:00
|
|
|
|
2021-07-07 12:20:05 +02:00
|
|
|
User();
|
|
|
|
~User();
|
2021-08-20 18:00:50 +02:00
|
|
|
|
2021-08-21 18:28:29 +02:00
|
|
|
protected:
|
2021-08-20 19:18:26 +02:00
|
|
|
static FormValidator *_login_validator;
|
|
|
|
static FormValidator *_registration_validator;
|
2021-08-20 20:32:40 +02:00
|
|
|
static FormValidator *_profile_validator;
|
2021-08-22 13:30:58 +02:00
|
|
|
|
|
|
|
std::string _file_path;
|
|
|
|
|
|
|
|
static std::string _path;
|
2021-08-22 13:37:28 +02:00
|
|
|
static std::string _table_name;
|
2021-07-07 12:20:05 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|