2021-08-22 20:20:30 +02:00
|
|
|
#ifndef USER_CONTROLLER_H
|
|
|
|
#define USER_CONTROLLER_H
|
|
|
|
|
2021-11-01 18:00:34 +01:00
|
|
|
#include "core/containers/vector.h"
|
2022-01-07 17:50:39 +01:00
|
|
|
#include "core/string.h"
|
2021-11-01 18:00:34 +01:00
|
|
|
|
2022-01-07 17:50:39 +01:00
|
|
|
#include "core/http/web_node.h"
|
2021-08-22 20:20:30 +02:00
|
|
|
|
2021-08-22 22:03:35 +02:00
|
|
|
#include "user.h"
|
2022-01-08 12:25:52 +01:00
|
|
|
#include "core/http/middleware.h"
|
2021-08-22 20:20:30 +02:00
|
|
|
|
2021-08-22 22:03:35 +02:00
|
|
|
class Request;
|
|
|
|
class FormValidator;
|
2021-08-22 20:20:30 +02:00
|
|
|
|
2022-01-07 17:50:39 +01:00
|
|
|
class UserController : public WebNode {
|
|
|
|
RCPP_OBJECT(UserController, WebNode);
|
|
|
|
|
2021-08-22 20:20:30 +02:00
|
|
|
public:
|
2022-01-08 12:49:34 +01:00
|
|
|
void handle_request_main(Request *request);
|
2021-08-22 22:03:35 +02:00
|
|
|
|
2021-10-31 02:10:47 +02:00
|
|
|
struct LoginRequestData {
|
2021-11-01 19:14:55 +01:00
|
|
|
String error_str;
|
|
|
|
String uname_val;
|
|
|
|
String pass_val;
|
2021-10-31 02:10:47 +02:00
|
|
|
};
|
|
|
|
|
2021-08-22 22:03:35 +02:00
|
|
|
virtual void handle_login_request_default(Request *request);
|
2021-10-31 02:10:47 +02:00
|
|
|
virtual void render_login_request_default(Request *request, LoginRequestData *data);
|
|
|
|
|
|
|
|
struct RegisterRequestData {
|
2021-11-01 19:14:55 +01:00
|
|
|
String error_str;
|
|
|
|
String uname_val;
|
|
|
|
String email_val;
|
|
|
|
String pass_val;
|
|
|
|
String pass_check_val;
|
2021-10-31 02:10:47 +02:00
|
|
|
};
|
|
|
|
|
2021-08-22 22:03:35 +02:00
|
|
|
virtual void handle_register_request_default(Request *request);
|
2021-10-31 02:10:47 +02:00
|
|
|
virtual void render_register_request_default(Request *request, RegisterRequestData *data);
|
2021-10-31 10:27:28 +01:00
|
|
|
virtual void render_register_success(Request *request);
|
2021-10-31 02:10:47 +02:00
|
|
|
|
|
|
|
virtual void render_already_logged_in_error(Request *request);
|
2021-10-31 10:27:28 +01:00
|
|
|
virtual void render_login_success(Request *request);
|
2021-08-22 22:03:35 +02:00
|
|
|
|
|
|
|
virtual void handle_request(Ref<User> &user, Request *request);
|
|
|
|
virtual void handle_main_page_request(Ref<User> &user, Request *request);
|
2021-10-31 02:10:47 +02:00
|
|
|
|
|
|
|
struct SettingsRequestData {
|
2021-11-01 19:14:55 +01:00
|
|
|
String error_str;
|
2021-10-31 02:10:47 +02:00
|
|
|
|
2021-11-01 19:14:55 +01:00
|
|
|
String uname_val;
|
|
|
|
String email_val;
|
|
|
|
String pass_val;
|
|
|
|
String pass_check_val;
|
2021-10-31 02:10:47 +02:00
|
|
|
};
|
|
|
|
|
2021-08-22 22:03:35 +02:00
|
|
|
virtual void handle_settings_request(Ref<User> &user, Request *request);
|
2021-10-31 02:10:47 +02:00
|
|
|
virtual void render_settings_request(Ref<User> &user, Request *request, SettingsRequestData *data);
|
|
|
|
|
2021-08-22 22:03:35 +02:00
|
|
|
virtual void handle_password_reset_request(Ref<User> &user, Request *request);
|
|
|
|
virtual void handle_logout_request(Ref<User> &user, Request *request);
|
|
|
|
virtual void handle_delete_request(Ref<User> &user, Request *request);
|
|
|
|
|
2021-08-22 22:28:46 +02:00
|
|
|
virtual void create_validators();
|
|
|
|
|
2022-01-07 17:50:39 +01:00
|
|
|
// db
|
|
|
|
|
|
|
|
virtual Ref<User> db_get_user(const int id);
|
|
|
|
virtual Ref<User> db_get_user(const String &user_name_input);
|
|
|
|
virtual void db_save_user(Ref<User> &user);
|
|
|
|
|
|
|
|
virtual Vector<Ref<User> > db_get_all();
|
|
|
|
|
|
|
|
virtual Ref<User> create_user();
|
|
|
|
|
|
|
|
bool is_username_taken(const String &user_name_input);
|
|
|
|
bool is_email_taken(const String &email_input);
|
|
|
|
|
|
|
|
virtual bool check_password(const Ref<User> &user, const String &p_password);
|
|
|
|
virtual void create_password(Ref<User> &user, const String &p_password);
|
|
|
|
virtual String hash_password(const Ref<User> &user, const String &p_password);
|
|
|
|
|
|
|
|
virtual void create_table();
|
|
|
|
virtual void drop_table();
|
2022-01-13 23:45:38 +01:00
|
|
|
virtual void create_default_entries();
|
2022-01-07 17:50:39 +01:00
|
|
|
|
2021-08-22 20:20:30 +02:00
|
|
|
static UserController *get_singleton();
|
|
|
|
|
|
|
|
UserController();
|
|
|
|
~UserController();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static UserController *_self;
|
2021-08-22 22:03:35 +02:00
|
|
|
|
|
|
|
static FormValidator *_login_validator;
|
|
|
|
static FormValidator *_registration_validator;
|
|
|
|
static FormValidator *_profile_validator;
|
2022-01-07 17:50:39 +01:00
|
|
|
|
|
|
|
String _file_path;
|
|
|
|
|
|
|
|
static String _path;
|
|
|
|
static String _table_name;
|
2021-08-22 20:20:30 +02:00
|
|
|
};
|
|
|
|
|
2022-01-08 12:25:52 +01:00
|
|
|
// just session setup
|
|
|
|
class UserSessionSetupMiddleware : public Middleware {
|
|
|
|
RCPP_OBJECT(UserSessionSetupMiddleware, Middleware);
|
|
|
|
|
|
|
|
public:
|
|
|
|
//returnring true means handled, false means continue
|
|
|
|
bool on_before_handle_request_main(Request *request);
|
|
|
|
|
|
|
|
UserSessionSetupMiddleware();
|
|
|
|
~UserSessionSetupMiddleware();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-08-22 20:20:30 +02:00
|
|
|
#endif
|