Compare commits

..

16 Commits

Author SHA1 Message Date
yakovlevanton
f6c649f9db Удалил лишние файлы chatSettings 2024-09-14 03:45:45 +03:00
yakovlevanton
9f0331ed62 Merge remote-tracking branch 'origin/anton_branch_2.0' 2024-09-14 03:43:33 +03:00
Fedor_Kitanin
16a6ee963a inaccuracies have been eliminated 2024-09-12 18:24:03 +03:00
Fedor_Kitanin
febf3af534 убраны два файла для мерджа 2024-09-12 17:00:45 +03:00
Fedor_Kitanin
61ef791c89 rooms are centralized 2024-09-12 16:52:18 +03:00
Fedor_Kitanin
14a8c1755e что-то 2024-09-12 15:46:17 +03:00
Fedor_Kitanin
1eb3f08b2c changed the rooms page 2024-09-12 14:43:53 +03:00
Fedor_Kitanin
5d4d1149d4 many folders have been updated, and html, js, and css extension files have also been changed 2024-09-12 10:47:29 +03:00
d1bfe44d0d Merge pull request 'Added registration' (#5) from fed into master
Reviewed-on: #5
2024-09-11 08:52:35 +00:00
Fedor Kitanin
bc2c7d31c9 Added registration 2024-09-11 11:46:35 +03:00
Fedor_Kitanin
91d88dc06c добавлены новые файлы 2024-08-31 21:26:12 +03:00
yakovlevanton
29e06059d5 Добавлена реализация http-запросов на странице chatSettings.nytl.html 2024-08-31 17:53:38 +03:00
yakovlevanton
d7aaeccfa2 Добавлена страница настроек чата 2024-08-29 18:43:36 +03:00
Fedor_Kitanin
d328acfb93 сделан кривой преход на страницу после нажатия кнопки 2024-08-29 13:43:04 +03:00
Fedor_Kitanin
a04a791ff2 изменен login.css 2024-08-29 00:54:56 +03:00
Fedor_Kitanin
5ba48ff58f добавлены новые файлы 2024-08-25 17:58:18 +03:00
13 changed files with 352 additions and 38 deletions

View File

@ -44,7 +44,6 @@
</div>
<div id="chat-renunciation-win" class="popup-window">
<!-- header will actually be rewritten before showing the window to include chat nickname -->
<h1 id="chat-renunciation-win-title" class="popup-window-msg">||||||||||</h1>
<button class="popup-window-btn-yes" id="chat-renunciation-win-yes">{%w pres.list-rooms.yes-leave %}</button>
<button class="popup-window-btn-no" id="chat-renunciation-win-no">{%w pres.list-rooms.no-leave %}</button>

View 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%}

View File

@ -1,51 +1,166 @@
#CL-bacbe {
margin-top: 6px;
margin-bottom: 4px;
/* Общие стили */
body {
font-family: 'Roboto', sans-serif;
background-color: #f7f9fc;
color: #333;
margin: 0;
padding: 0;
box-sizing: border-box;
}
/* Панель навигации */
.panel {
background-color: #007bff;
padding: 10px;
color: white;
display: flex;
align-items: center;
}
.panel-thing {
margin-right: 20px;
text-decoration: none;
color: white;
}
.panel-header-txt {
font-size: 18px;
font-weight: bold;
}
/* Стили динамических блоков */
.dynamic-block-list {
display: flex;
flex-direction: column;
align-items: center;
padding: 20px;
}
.dynamic-block-list-el-container {
width: 100%;
max-width: 600px;
margin-top: 20px;
}
/* Кнопка добавления */
.button-add {
width: 50px;
height: 50px;
cursor: pointer;
transition: transform 0.2s;
}
.button-add:hover {
transform: scale(1.1);
}
/* Всплывающие окна */
.popup-window {
background-color: white;
border-radius: 8px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
padding: 20px;
max-width: 500px;
margin: 0 auto;
}
.popup-window-msg {
font-size: 20px;
margin-bottom: 15px;
color: #333;
}
.popup-window-btn-yes, .popup-window-btn-no {
padding: 10px 20px;
border: none;
border-radius: 5px;
font-size: 16px;
cursor: pointer;
}
.popup-window-btn-yes {
background-color: #28a745;
color: white;
margin-right: 10px;
}
.popup-window-btn-no {
background-color: #dc3545;
color: white;
}
/* Таблица ввода */
table.id-str-input-table {
width: 100%;
border-collapse: collapse;
margin-bottom: 20px;
}
.id-str-input-td1, .id-str-input-td2 {
border: none;
padding: 10px;
}
.id-str-input-td1 {
text-align: left;
padding-right: 10px;
font-weight: bold;
color: #555;
white-space: nowrap;
}
.id-str-input-td2 {
width: 100%;
}
.one-line-input {
width: 100%;
padding: 8px 12px;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 14px;
}
/* Стили комнат */
.CL-my-chat-box {
display: flex;
flex-direction: row;
position: relative;
padding: 10px;
background-color: #e0f7fa;
border-radius: 8px;
margin-bottom: 10px;
align-items: center;
min-height: 40px;
width: 100%;
}
.CL-my-chat-box-nickname {
/* Текст внутри блока комнаты */
.CL-my-chat-box-nickname, .CL-my-chat-box-name, .CL-my-chat-box-my-role {
margin-left: 8px;
justify-self: flex-start;
}
.CL-my-chat-box-name {
margin-left: 14px;
justify-self: flex-start;
}
.CL-my-chat-box-my-role {
margin-left: auto;
justify-self: flex-end;
}
/* Крестик в правом верхнем углу */
.CL-my-chat-box-leave-btn {
margin-left: 10px;
margin-right: 8px;
justify-self: flex-end;
position: absolute;
top: 8px;
right: 8px;
width: 16px;
height: 16px;
background: url('/assets/img/close.svg') no-repeat center;
background-size: cover;
cursor: pointer;
border: none;
transition: transform 0.2s;
}
/* The morbid thing */
table.id-str-input-table {
width: 100%;
border-collapse: collapse; /* Combine borders */
.CL-my-chat-box-leave-btn:hover {
transform: scale(1.2);
}
.id-str-input-td1, .id-str-input-td2 {
border: none;
/* Дизайн списка комнат остается таким же */
#CL-bacbe {
margin-top: 6px;
margin-bottom: 4px;
}
.id-str-input-td1 {
text-align: left;
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 */
}
.id-str-input-td2 {
width: 100%;
}

View File

@ -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%;

45
assets/css/register.css Normal file
View 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%;
}

View File

@ -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"
}
}

View File

@ -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"
}
}

View File

@ -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",

View File

@ -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<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 ============================== */
std::string when_internalapi_chatpollevents(WorkerGuestData& wgd, const een9::ClientRequest& req, int64_t uid);

View File

@ -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});
}
}

View File

@ -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);
}

View File

@ -76,7 +76,7 @@ namespace iu9cawebchat {
int ret = sqlite3_prepare_v2(connection.hand, req_statement.c_str(), -1, &stmt_obj, NULL);
if (ret != 0) {
int err_pos = sqlite3_error_offset(connection.hand);
int err_pos = -1;
een9_THROW("Compilation of request\n" + req_statement + "\nfailed" +
((err_pos >= 0) ? " with offset " + std::to_string(err_pos) : ""));
}

View File

@ -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) {