master #6
							
								
								
									
										51
									
								
								assets/HypertextPages/register.nytl.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								assets/HypertextPages/register.nytl.html
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,51 @@ | |||||||
|  | {% ELDEF main JSON pres JSON userinfo JSON messages %} | ||||||
|  | <!DOCTYPE html> | ||||||
|  | <html lang="en"> | ||||||
|  | <head> | ||||||
|  |     <meta charset="UTF-8"> | ||||||
|  |     <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||||||
|  |     <link rel="icon" type="image/png" href="/assets/img/favicon.png"> | ||||||
|  |     <link rel="stylesheet" href="/assets/css/common.css"> | ||||||
|  |     <link rel="stylesheet" href="/assets/css/register.css"> | ||||||
|  |     <title>{% W pres.register.header %}</title> | ||||||
|  | </head> | ||||||
|  | <body> | ||||||
|  |     {% FOR error IN messages %} | ||||||
|  |     <div class="server-notif-error-msg-box"> | ||||||
|  |         {% W error.text %} | ||||||
|  |     </div> | ||||||
|  |     {% ENDFOR %} | ||||||
|  | 
 | ||||||
|  |     <div class="form-container"> | ||||||
|  |         <h1 class="wide-centered-header">{% W pres.register.header %}</h1> | ||||||
|  |         <form action="/register" method="post" enctype="application/x-www-form-urlencoded"> | ||||||
|  |             <table class="reg-input-table"> | ||||||
|  |                 <tr> | ||||||
|  |                     <td class="reg-input-td1"><label for="input-nickname">{% W pres.register.directive-nickname %}</label></td> | ||||||
|  |                     <td class="reg-input-td2"> | ||||||
|  |                         <input type="text" name="nickname" id="input-nickname" | ||||||
|  |                                placeholder="{% W pres.register.placeholder-nickname %}" class="one-line-input" required> | ||||||
|  |                     </td> | ||||||
|  |                 </tr> | ||||||
|  |                 <tr> | ||||||
|  |                     <td class="reg-input-td1"><label for="input-name">{% W pres.register.directive-name %}</label></td> | ||||||
|  |                     <td class="reg-input-td2"> | ||||||
|  |                         <input type="text" name="name" id="input-name" | ||||||
|  |                                placeholder="{% W pres.register.placeholder-name %}" class="one-line-input" required> | ||||||
|  |                     </td> | ||||||
|  |                 </tr> | ||||||
|  |                 <tr> | ||||||
|  |                     <td class="reg-input-td1"><label for="input-password">{% W pres.register.directive-password %}</label></td> | ||||||
|  |                     <td class="reg-input-td2"> | ||||||
|  |                         <input name="password" id="input-password" type="password" | ||||||
|  |                                placeholder="{% W pres.register.placeholder-password %}" class="one-line-input" required> | ||||||
|  |                     </td> | ||||||
|  |                 </tr> | ||||||
|  |             </table> | ||||||
|  |             <button class="action-button centered-block-el" type="submit">{% W pres.register.act %}</button> | ||||||
|  |         </form> | ||||||
|  |     </div> | ||||||
|  | 
 | ||||||
|  | </body> | ||||||
|  | </html> | ||||||
|  | {%ENDELDEF%} | ||||||
| @ -8,13 +8,25 @@ body { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| .form-container { | .form-container { | ||||||
|     background-color: #ffffff; /* Brighter box color */ |     background-color: #ffffff; | ||||||
|     padding: 20px; |     padding: 20px; | ||||||
|     border-radius: 10px; |     border-radius: 10px; | ||||||
|     box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1); |     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 */ | /* The morbid thing */ | ||||||
| table.logins-input-table { | table.logins-input-table { | ||||||
|     width: 100%; |     width: 100%; | ||||||
|  | |||||||
							
								
								
									
										45
									
								
								assets/css/register.css
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								assets/css/register.css
									
									
									
									
									
										Normal file
									
								
							| @ -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%; | ||||||
|  | } | ||||||
| @ -72,5 +72,20 @@ | |||||||
|     }, |     }, | ||||||
|     "failed-delete-message": "Failed to delete message", |     "failed-delete-message": "Failed to delete message", | ||||||
|     "failed-send-message": "Failed to send 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" | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  | |||||||
| @ -72,5 +72,20 @@ | |||||||
|     }, |     }, | ||||||
|     "failed-delete-message": "Не смог удалить сообщение", |     "failed-delete-message": "Не смог удалить сообщение", | ||||||
|     "failed-send-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" | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  | |||||||
| @ -157,6 +157,7 @@ struct CAWebChat { | |||||||
|                 "backend_logic/when_list_rooms.cpp", |                 "backend_logic/when_list_rooms.cpp", | ||||||
|                 "backend_logic/when_chat.cpp", |                 "backend_logic/when_chat.cpp", | ||||||
|                 "backend_logic/when_user.cpp", |                 "backend_logic/when_user.cpp", | ||||||
|  |                 "backend_logic/when_register.cpp", | ||||||
|                 "backend_logic/polling.cpp", |                 "backend_logic/polling.cpp", | ||||||
|                 "backend_logic/api_sendmessage.cpp", |                 "backend_logic/api_sendmessage.cpp", | ||||||
|                 "backend_logic/api_deletemessage.cpp", |                 "backend_logic/api_deletemessage.cpp", | ||||||
|  | |||||||
| @ -55,6 +55,8 @@ namespace iu9cawebchat { | |||||||
|     std::string when_page_user(WorkerGuestData& wgd, const json::JSON& config_presentation, |     std::string when_page_user(WorkerGuestData& wgd, const json::JSON& config_presentation, | ||||||
|             const een9::ClientRequest& req, const std::vector<LoginCookie>& login_cookies, const json::JSON& userinfo); |             const een9::ClientRequest& req, const std::vector<LoginCookie>& 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  ============================== */ |     /* ========================  API  ============================== */ | ||||||
|     std::string when_internalapi_chatpollevents(WorkerGuestData& wgd, const een9::ClientRequest& req, int64_t uid); |     std::string when_internalapi_chatpollevents(WorkerGuestData& wgd, const een9::ClientRequest& req, int64_t uid); | ||||||
|  | |||||||
| @ -0,0 +1,56 @@ | |||||||
|  | #include "client_server_interact.h" | ||||||
|  | #include <engine_engine_number_9/form_data_structure/urlencoded_query.h> | ||||||
|  | #include <engine_engine_number_9/baza_throw.h> | ||||||
|  | #include <string.h> | ||||||
|  | #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<std::pair<std::string, std::string>> query = een9::split_html_query(req.body); | ||||||
|  |             std::string nickname; | ||||||
|  |             std::string name; | ||||||
|  |             std::string password; | ||||||
|  |             std::vector<HtmlMsgBox> problems;  // We explain problem to root
 | ||||||
|  |             for (const std::pair<std::string, std::string>& 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}); | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -111,6 +111,9 @@ namespace iu9cawebchat { | |||||||
|                 if (een9::beginsWith(req.uri_path, "/user/")) { |                 if (een9::beginsWith(req.uri_path, "/user/")) { | ||||||
|                     return when_page_user(wgd, pres, req, login_cookies, userinfo); |                     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") { |                 if (req.uri_path == "/api/chatPollEvents") { | ||||||
|                     return when_internalapi_chatpollevents(wgd, req, logged_in_user); |                     return when_internalapi_chatpollevents(wgd, req, logged_in_user); | ||||||
|                 } |                 } | ||||||
|  | |||||||
| @ -36,7 +36,7 @@ namespace iu9cawebchat { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     bool check_name(const std::string &name) { |     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) { |     bool check_nickname(const std::string &nickname) { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user