mirror of
https://github.com/Relintai/rcpp_framework.git
synced 2024-11-14 04:57:21 +01:00
107 lines
2.8 KiB
C++
107 lines
2.8 KiB
C++
#ifndef USER_CONTROLLER_H
|
|
#define USER_CONTROLLER_H
|
|
|
|
#include "core/containers/vector.h"
|
|
#include "core/string.h"
|
|
|
|
#include "core/http/web_node.h"
|
|
|
|
#include "user.h"
|
|
|
|
class Request;
|
|
class FormValidator;
|
|
|
|
class UserController : public WebNode {
|
|
RCPP_OBJECT(UserController, WebNode);
|
|
|
|
public:
|
|
virtual void handle_request_default(Request *request);
|
|
|
|
struct LoginRequestData {
|
|
String error_str;
|
|
String uname_val;
|
|
String pass_val;
|
|
};
|
|
|
|
virtual void handle_login_request_default(Request *request);
|
|
virtual void render_login_request_default(Request *request, LoginRequestData *data);
|
|
|
|
struct RegisterRequestData {
|
|
String error_str;
|
|
String uname_val;
|
|
String email_val;
|
|
String pass_val;
|
|
String pass_check_val;
|
|
};
|
|
|
|
virtual void handle_register_request_default(Request *request);
|
|
virtual void render_register_request_default(Request *request, RegisterRequestData *data);
|
|
virtual void render_register_success(Request *request);
|
|
|
|
virtual void render_already_logged_in_error(Request *request);
|
|
virtual void render_login_success(Request *request);
|
|
|
|
virtual void handle_request(Ref<User> &user, Request *request);
|
|
virtual void handle_main_page_request(Ref<User> &user, Request *request);
|
|
|
|
struct SettingsRequestData {
|
|
String error_str;
|
|
|
|
String uname_val;
|
|
String email_val;
|
|
String pass_val;
|
|
String pass_check_val;
|
|
};
|
|
|
|
virtual void handle_settings_request(Ref<User> &user, Request *request);
|
|
virtual void render_settings_request(Ref<User> &user, Request *request, SettingsRequestData *data);
|
|
|
|
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);
|
|
|
|
virtual void create_validators();
|
|
|
|
static void user_session_setup_middleware(Object *instance, Request *request);
|
|
|
|
// 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();
|
|
virtual void migrate();
|
|
virtual void create_test_users();
|
|
|
|
static UserController *get_singleton();
|
|
|
|
UserController();
|
|
~UserController();
|
|
|
|
protected:
|
|
static UserController *_self;
|
|
|
|
static FormValidator *_login_validator;
|
|
static FormValidator *_registration_validator;
|
|
static FormValidator *_profile_validator;
|
|
|
|
String _file_path;
|
|
|
|
static String _path;
|
|
static String _table_name;
|
|
};
|
|
|
|
#endif |