Moved the register success and login success responses to 2 new virtual methods.

This commit is contained in:
Relintai 2021-10-31 10:27:28 +01:00
parent 4aa9a28ed5
commit f883b4d678
2 changed files with 29 additions and 20 deletions

View File

@ -71,11 +71,7 @@ void UserController::handle_login_request_default(Request *request) {
request->add_cookie(c); request->add_cookie(c);
//todo implement redirect! render_login_success(request);
request->body += "Login Success!<br>";
request->compile_and_send_body();
return; return;
} }
@ -177,21 +173,7 @@ void UserController::handle_register_request_default(Request *request) {
UserModel::get_singleton()->create_password(user, data.pass_val); UserModel::get_singleton()->create_password(user, data.pass_val);
UserModel::get_singleton()->save_user(user); UserModel::get_singleton()->save_user(user);
HTMLBuilder b; render_register_success(request);
b.div()->cls("success");
{
b.w("Registration successful! You can now log in!");
b.br();
b.a()->href("/user/login");
b.w(">> Login <<");
b.ca();
}
b.cdiv();
request->body += b.result;
request->compile_and_send_body();
return; return;
} }
} }
@ -199,6 +181,24 @@ void UserController::handle_register_request_default(Request *request) {
render_register_request_default(request, &data); render_register_request_default(request, &data);
} }
void UserController::render_register_success(Request *request) {
HTMLBuilder b;
b.div()->cls("success");
{
b.w("Registration successful! You can now log in!");
b.br();
b.a()->href("/user/login");
b.w(">> Login <<");
b.ca();
}
b.cdiv();
request->body += b.result;
request->compile_and_send_body();
}
void UserController::render_register_request_default(Request *request, RegisterRequestData *data) { void UserController::render_register_request_default(Request *request, RegisterRequestData *data) {
HTMLBuilder b; HTMLBuilder b;
@ -262,6 +262,13 @@ void UserController::render_already_logged_in_error(Request *request) {
request->compile_and_send_body(); request->compile_and_send_body();
} }
void UserController::render_login_success(Request *request) {
request->body = "Login Success!<br>";
//request->compile_and_send_body();
request->send_redirect("/user/settings");
}
void UserController::handle_request(Ref<User> &user, Request *request) { void UserController::handle_request(Ref<User> &user, Request *request) {
const std::string &segment = request->get_current_path_segment(); const std::string &segment = request->get_current_path_segment();

View File

@ -34,8 +34,10 @@ public:
virtual void handle_register_request_default(Request *request); virtual void handle_register_request_default(Request *request);
virtual void render_register_request_default(Request *request, RegisterRequestData *data); 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_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_request(Ref<User> &user, Request *request);
virtual void handle_main_page_request(Ref<User> &user, Request *request); virtual void handle_main_page_request(Ref<User> &user, Request *request);