Added request handling methods to the user.

This commit is contained in:
Relintai 2021-08-05 01:19:54 +02:00
parent f31052ff76
commit 00f9be5f59
2 changed files with 104 additions and 0 deletions

View File

@ -1,6 +1,7 @@
#include "user.h" #include "user.h"
#include "core/http/http_session.h" #include "core/http/http_session.h"
#include "core/http/request.h"
#include "core/http/session_manager.h" #include "core/http/session_manager.h"
void User::save() { void User::save() {
@ -63,6 +64,93 @@ void User::unregister_sessions() {
} }
} }
void User::handle_request_default(Request *request) {
if (request->session) {
User *u = dynamic_cast<User *>(request->session->get_object("user"));
if (u) {
u->handle_request(request);
return;
}
}
const std::string &segment = request->get_current_path_segment();
if (segment == "") {
handle_login_request_default(request);
return;
} else if (segment == "login") {
handle_login_request_default(request);
return;
} else if (segment == "register") {
handle_register_request_default(request);
return;
}
handle_login_request_default(request);
}
void User::handle_login_request_default(Request *request) {
request->body += "handle_login_request_default";
request->compile_and_send_body();
}
void User::handle_register_request_default(Request *request) {
request->body += "handle_register_request_default";
request->compile_and_send_body();
}
void User::handle_request(Request *request) {
const std::string &segment = request->get_current_path_segment();
if (segment == "") {
handle_main_page_request(request);
} else if (segment == "settings") {
handle_settings_request(request);
} else if (segment == "password_reset") {
handle_password_reset_request(request);
} else if (segment == "logout") {
handle_logout_request(request);
} else if (segment == "delete") {
handle_delete_request(request);
} else {
request->send_error(404);
}
}
void User::handle_main_page_request(Request *request) {
request->body += "handle_main_page_request";
request->compile_and_send_body();
}
void User::handle_settings_request(Request *request) {
request->body += "handle_settings_request";
request->compile_and_send_body();
}
void User::handle_password_reset_request(Request *request) {
request->body += "handle_password_reset_request";
request->compile_and_send_body();
}
void User::handle_logout_request(Request *request) {
request->body += "handle_logout_request";
request->compile_and_send_body();
}
void User::handle_delete_request(Request *request) {
request->body += "handle_delete_request";
request->compile_and_send_body();
}
User::User() : User::User() :
Object() { Object() {

View File

@ -6,7 +6,11 @@
#include <string> #include <string>
#include <vector> #include <vector>
class Request;
class User : public Object { class User : public Object {
RCPP_OBJECT(User, Object);
public: public:
int id; int id;
std::string name; std::string name;
@ -26,6 +30,18 @@ public:
virtual void changed(); virtual void changed();
virtual void update(); virtual void update();
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);
void register_sessions(); void register_sessions();
void unregister_sessions(); void unregister_sessions();