diff --git a/assets/HypertextPages/register.nytl.html b/assets/HypertextPages/register.nytl.html new file mode 100644 index 0000000..70d2fe6 --- /dev/null +++ b/assets/HypertextPages/register.nytl.html @@ -0,0 +1,51 @@ +{% ELDEF main JSON pres JSON userinfo JSON messages %} + + + + + + + + + {% W pres.register.header %} + + + {% FOR error IN messages %} +
+ {% W error.text %} +
+ {% ENDFOR %} + +
+

{% W pres.register.header %}

+
+ + + + + + + + + + + + + +
+ +
+ +
+ +
+ +
+
+ + + +{%ENDELDEF%} \ No newline at end of file diff --git a/assets/css/login.css b/assets/css/login.css index 1d35fbb..27971b4 100644 --- a/assets/css/login.css +++ b/assets/css/login.css @@ -8,13 +8,25 @@ body { } .form-container { - background-color: #ffffff; /* Brighter box color */ + background-color: #ffffff; padding: 20px; border-radius: 10px; box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1); - width: 50%; /* Set width of the form */ } +@media (orientation: landscape) { + .form-container{ + width: 50%; + } +} + +@media (orientation: portrait){ + .form-container{ + width: 85%; + } +} + + /* The morbid thing */ table.logins-input-table { width: 100%; diff --git a/assets/css/register.css b/assets/css/register.css new file mode 100644 index 0000000..3a4893c --- /dev/null +++ b/assets/css/register.css @@ -0,0 +1,45 @@ +body { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + height: 100vh; /* Full viewport height */ + margin: 0; +} + +.form-container { + background-color: #ffffff; + padding: 20px; + border-radius: 10px; + box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1); +} + +@media (orientation: landscape) { + .form-container{ + width: 60%; + } +} + +@media (orientation: portrait){ + .form-container{ + width: 90%; + } +} + +/* The morbid thing */ +table.reg-input-table { + width: 100%; + border-collapse: collapse; /* Combine borders */ +} +.reg-input-td1, .reg-input-td2 { + border: none; +} +.reg-input-td1 { + padding-right: 5px; + white-space: nowrap; /* Prevent text wrap, keeping it in one line */ + overflow: hidden; /* Hide overflow content */ + text-overflow: ellipsis; /* Show ellipsis for overflowing text */ +} +.reg-input-td2 { + width: 100%; +} diff --git a/assets/lang/en-US.lang.json b/assets/lang/en-US.lang.json index 166587f..bb41154 100644 --- a/assets/lang/en-US.lang.json +++ b/assets/lang/en-US.lang.json @@ -72,5 +72,20 @@ }, "failed-delete-message": "Failed to delete message", "failed-send-message": "Failed to send message" + }, + "register": { + "header": "Admin control - Registration", + "directive-nickname": "Nickname for new user", + "placeholder-nickname": "Nickname", + "directive-name": "Name for new user:", + "placeholder-name": "Name", + "directive-password": "Temporary password:", + "placeholder-password": "Password", + "act": "Register him", + "incorrect-nickname": "Incorrect nickname", + "incorrect-name": "Incorrect name", + "incorrect-password": "Incorrect password", + "nickname-taken": "Nickname already taken", + "add_user_error": "add_user failed" } } diff --git a/assets/lang/ru-RU.lang.json b/assets/lang/ru-RU.lang.json index 49ab7f9..154f0c4 100644 --- a/assets/lang/ru-RU.lang.json +++ b/assets/lang/ru-RU.lang.json @@ -72,5 +72,20 @@ }, "failed-delete-message": "Не смог удалить сообщение", "failed-send-message": "Не смог отправить сообщение" + }, + "register": { + "header": "Admin control - Регистрация", + "directive-nickname": "Никнейм для нового пользователя:", + "placeholder-nickname": "Никнейм", + "directive-name": "Имя для нового пользователя:", + "placeholder-name": "Имя", + "directive-password": "Временный пароль:", + "placeholder-password": "Пароль", + "act": "Зарегистрируй его", + "incorrect-nickname": "Плохой никнейм", + "incorrect-name": "Плохое имя", + "incorrect-password": "Плохой пароль", + "nickname-taken": "Никнейм уже занят", + "add_user_error": "add_user failed" } } diff --git a/building/main.cpp b/building/main.cpp index 2e87dfe..5cc83b5 100644 --- a/building/main.cpp +++ b/building/main.cpp @@ -157,6 +157,7 @@ struct CAWebChat { "backend_logic/when_list_rooms.cpp", "backend_logic/when_chat.cpp", "backend_logic/when_user.cpp", + "backend_logic/when_register.cpp", "backend_logic/polling.cpp", "backend_logic/api_sendmessage.cpp", "backend_logic/api_deletemessage.cpp", diff --git a/src/web_chat/iu9_ca_web_chat_lib/backend_logic/client_server_interact.h b/src/web_chat/iu9_ca_web_chat_lib/backend_logic/client_server_interact.h index 70fbeec..13fa046 100644 --- a/src/web_chat/iu9_ca_web_chat_lib/backend_logic/client_server_interact.h +++ b/src/web_chat/iu9_ca_web_chat_lib/backend_logic/client_server_interact.h @@ -55,6 +55,8 @@ namespace iu9cawebchat { std::string when_page_user(WorkerGuestData& wgd, const json::JSON& config_presentation, const een9::ClientRequest& req, const std::vector& login_cookies, const json::JSON& userinfo); + std::string when_page_register(WorkerGuestData& wgd, const json::JSON& config_presentation, + const een9::ClientRequest& req, const json::JSON& userinfo); /* ======================== API ============================== */ std::string when_internalapi_chatpollevents(WorkerGuestData& wgd, const een9::ClientRequest& req, int64_t uid); diff --git a/src/web_chat/iu9_ca_web_chat_lib/backend_logic/when_register.cpp b/src/web_chat/iu9_ca_web_chat_lib/backend_logic/when_register.cpp new file mode 100644 index 0000000..2fbc733 --- /dev/null +++ b/src/web_chat/iu9_ca_web_chat_lib/backend_logic/when_register.cpp @@ -0,0 +1,56 @@ +#include "client_server_interact.h" +#include +#include +#include +#include "../str_fields.h" + +namespace iu9cawebchat { + std::string when_page_register(WorkerGuestData& wgd, const json::JSON& config_presentation, + const een9::ClientRequest& req, const json::JSON& userinfo) { + + const json::JSON& reg_pres = config_presentation["register"]; + json::JSON msg_list = json::JSON(json::array); + if (req.method == "POST") { + if (userinfo.isNull() || userinfo["uid"].asInteger().get_int() != 0) + een9_THROW("Unauthorized access"); + // Kod dlya dobaldal lkslkfjgk + std::vector> query = een9::split_html_query(req.body); + std::string nickname; + std::string name; + std::string password; + std::vector problems; // We explain problem to root + for (const std::pair& cmp: query) { + if (cmp.first == "nickname") + nickname = cmp.second; + if (cmp.first == "name") + name = cmp.second; + if (cmp.first == "password") + password = cmp.second; + } + if (!check_nickname(nickname)) { + problems.push_back({"", reg_pres["incorrect-nickname"].asString()}); + } + if (!check_name(name)) { + problems.push_back({"", reg_pres["incorrect-name"].asString()}); + } + if (!check_strong_password(password)) { + problems.push_back({"", reg_pres["incorrect-password"].asString()}); + } + if (is_nickname_taken(*wgd.db, nickname)) { + problems.push_back({"", reg_pres["nickname-taken"].asString()}); + } + if (problems.empty()) { + try { + add_user(*wgd.db, nickname, name, password, ""); + } catch (std::exception& err) { + problems.push_back({"", reg_pres["add_user_error"].asString()}); + } + } + msg_list = jsonify_html_message_list(problems); + return http_R200("register", wgd, {&config_presentation, &userinfo, &msg_list}); + } + if (userinfo.isNull() || userinfo["uid"].asInteger().get_int() != 0) + return page_E404(wgd); + return http_R200("register", wgd, {&config_presentation, &userinfo, &msg_list}); + } +} diff --git a/src/web_chat/iu9_ca_web_chat_lib/run.cpp b/src/web_chat/iu9_ca_web_chat_lib/run.cpp index 7162740..5c7340e 100644 --- a/src/web_chat/iu9_ca_web_chat_lib/run.cpp +++ b/src/web_chat/iu9_ca_web_chat_lib/run.cpp @@ -111,6 +111,9 @@ namespace iu9cawebchat { if (een9::beginsWith(req.uri_path, "/user/")) { return when_page_user(wgd, pres, req, login_cookies, userinfo); } + if (req.uri_path == "/register") { + return when_page_register(wgd, pres, req, userinfo); + } if (req.uri_path == "/api/chatPollEvents") { return when_internalapi_chatpollevents(wgd, req, logged_in_user); } diff --git a/src/web_chat/iu9_ca_web_chat_lib/str_fields.cpp b/src/web_chat/iu9_ca_web_chat_lib/str_fields.cpp index 9f77d40..6a502b1 100644 --- a/src/web_chat/iu9_ca_web_chat_lib/str_fields.cpp +++ b/src/web_chat/iu9_ca_web_chat_lib/str_fields.cpp @@ -36,7 +36,7 @@ namespace iu9cawebchat { } bool check_name(const std::string &name) { - return is_orthodox_string(name) && name.size() <= 150; + return is_orthodox_string(name) && name.size() <= 150 && !name.empty(); } bool check_nickname(const std::string &nickname) {