Reimplemented UserRegisterWebPage.

This commit is contained in:
Relintai 2022-07-23 22:08:07 +02:00
parent abb875f8a5
commit a5a327ad35
2 changed files with 26 additions and 11 deletions

View File

@ -14,7 +14,14 @@
#include "modules/web/http/web_server_cookie.h" #include "modules/web/http/web_server_cookie.h"
#include "modules/web/http/web_server_request.h" #include "modules/web/http/web_server_request.h"
void UserRegisterWebPage::handle_register_request_default(Ref<WebServerRequest> request) { String UserRegisterWebPage::get_redirect_on_success_url() {
return _redirect_on_success_url;
}
void UserRegisterWebPage::set_redirect_on_success_url(const String &val) {
_redirect_on_success_url = val;
}
void UserRegisterWebPage::_render_index(Ref<WebServerRequest> request) {
RegisterRequestData data; RegisterRequestData data;
if (request->get_method() == HTTPServerEnums::HTTP_METHOD_POST) { if (request->get_method() == HTTPServerEnums::HTTP_METHOD_POST) {
@ -69,7 +76,7 @@ void UserRegisterWebPage::render_register_success(Ref<WebServerRequest> request)
{ {
b.w("Registration successful! You can now log in!"); b.w("Registration successful! You can now log in!");
b.br(); b.br();
b.a()->href("/user/login"); b.a()->href(_redirect_on_success_url);
b.w(">> Login <<"); b.w(">> Login <<");
b.ca(); b.ca();
} }
@ -139,12 +146,6 @@ void UserRegisterWebPage::render_register_request_default(Ref<WebServerRequest>
request->compile_and_send_body(); request->compile_and_send_body();
} }
void UserRegisterWebPage::render_already_logged_in_error(Ref<WebServerRequest> request) {
request->body += "You are already logged in.";
request->compile_and_send_body();
}
UserRegisterWebPage::UserRegisterWebPage() { UserRegisterWebPage::UserRegisterWebPage() {
// Registration // Registration
_registration_validator.instance(); _registration_validator.instance();
@ -160,7 +161,16 @@ UserRegisterWebPage::UserRegisterWebPage() {
_registration_validator->new_field("password_check", "Password check")->need_to_match("password"); _registration_validator->new_field("password_check", "Password check")->need_to_match("password");
_registration_validator->new_field("email", "Email")->need_to_exist()->need_to_be_email(); _registration_validator->new_field("email", "Email")->need_to_exist()->need_to_be_email();
_logged_out_render_type = RENDER_TYPE_RENDER;
_logged_in_render_type = RENDER_TYPE_ERROR;
} }
UserRegisterWebPage::~UserRegisterWebPage() { UserRegisterWebPage::~UserRegisterWebPage() {
} }
void UserRegisterWebPage::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_redirect_on_success_url"), &UserRegisterWebPage::get_redirect_on_success_url);
ClassDB::bind_method(D_METHOD("set_redirect_on_success_url", "val"), &UserRegisterWebPage::set_redirect_on_success_url);
ADD_PROPERTY(PropertyInfo(Variant::STRING, "redirect_on_success_url"), "set_redirect_on_success_url", "get_redirect_on_success_url");
}

View File

@ -15,6 +15,9 @@ class UserRegisterWebPage : public UserWebPage {
GDCLASS(UserRegisterWebPage, UserWebPage); GDCLASS(UserRegisterWebPage, UserWebPage);
public: public:
String get_redirect_on_success_url();
void set_redirect_on_success_url(const String &val);
struct RegisterRequestData { struct RegisterRequestData {
String error_str; String error_str;
String uname_val; String uname_val;
@ -23,18 +26,20 @@ public:
String pass_check_val; String pass_check_val;
}; };
virtual void handle_register_request_default(Ref<WebServerRequest> request); void _render_index(Ref<WebServerRequest> request);
virtual void render_register_request_default(Ref<WebServerRequest> request, RegisterRequestData *data); virtual void render_register_request_default(Ref<WebServerRequest> request, RegisterRequestData *data);
virtual void render_register_success(Ref<WebServerRequest> request); virtual void render_register_success(Ref<WebServerRequest> request);
virtual void render_already_logged_in_error(Ref<WebServerRequest> request);
UserRegisterWebPage(); UserRegisterWebPage();
~UserRegisterWebPage(); ~UserRegisterWebPage();
protected: protected:
static void _bind_methods();
Ref<FormValidator> _registration_validator; Ref<FormValidator> _registration_validator;
Ref<FormValidator> _profile_validator; Ref<FormValidator> _profile_validator;
String _redirect_on_success_url;
}; };
#endif #endif