Skip to content

Server: client-server logic implementation#17

Open
mirotvoretts wants to merge 63 commits intomainfrom
client-server
Open

Server: client-server logic implementation#17
mirotvoretts wants to merge 63 commits intomainfrom
client-server

Conversation

@mirotvoretts
Copy link
Collaborator

No description provided.

@mirotvoretts mirotvoretts requested a review from Copilot June 3, 2025 12:40
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements several changes related to the client‐server logic and UI improvements. Key updates include renaming UI widget object names for consistency and clarity, introducing a new theme switch button (“switch_theme”), and adding/integrating gRPC client logic with authentication and update requests in the CMake configuration.

Reviewed Changes

Copilot reviewed 98 out of 98 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
client/ui/authorization-windows/ui/login_window.ui Renamed widgets and updated geometries; added new “switch_theme” button.
client/ui/authorization-windows/src/registration_window.cpp Updated UI elements and added theming logic; refactored widget names and event handling.
client/ui/authorization-windows/src/login_window.cpp Updated login UI with widget renames and theming support.
client/ui/authorization-windows/include/registration_window.h
client/ui/authorization-windows/include/login_window.h
Added final specifiers, counter initialization, and method adjustments to support new theme logic.
Various CMakeLists.txt files Updated linking and sanitizer options; added dependencies such as ThemeManager and Client modules.
client/client/src/update_requests.cpp
client/client/src/auth_requests.cpp
client/client/src/client_implementation.cpp
Integrated and adjusted gRPC client calls for updating and authenticating users; improved logging.
client/client/include/* Added and adjusted header definitions for gRPC client call abstractions.

Comment on lines +139 to +194
void RegistrationWindow::on_push_registration_clicked() {
if (this->counter_on_switch_theme_clicks++ % 2) {
const QString created_login = ui->create_login->text();
const QString created_password = ui->create_password->text();
const QString repeated_password = ui->repeat_password->text();

if (!created_login.isEmpty() && !created_password.isEmpty() &&
!repeated_password.isEmpty()) {
if (created_password != repeated_password) {
QMessageBox::warning(this, "Ошибка", "Пароли не совпадают!");
} else if (created_login.size() > 50) {
QMessageBox::warning(
this, "Ошибка",
"Длина логина не должна превышать пятидесяти символов"
);
} else if (created_password.size() > 50) {
QMessageBox::warning(
this, "Ошибка",
"Длина пароля не должна превышать пятидесяти символов"
);
} else if (is_strong_and_valid_password(created_password)) {
auto user = new User();
user->set_login(created_login.toStdString());
user->set_hashed_password(created_password.toStdString());

const int try_register_user =
ClientImplementation::get_instance().try_register_user(user
);
if (try_register_user == 0) {
QMessageBox::warning(
this, "Ошибка",
"Извините, внутренняя ошибка с базами данных."
);
} else if (try_register_user == -1) {
QMessageBox::warning(
this, "Ошибка",
"Пользователь с таким именем уже существует. "
"Пожалуйста, "
"придумайте другое!"
);
} else {
QMessageBox::information(
this, "Регистрация",
"Вы успешно зарегистрировались! Пожалуйста, выполните "
"вход."
);
on_switch_mode_clicked();
}
}
} else {
QMessageBox::warning(
this, "Ошибка", "Пожалуйста, заполните все поля."
);
}
}
}
Copy link

Copilot AI Jun 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of counter_on_switch_theme_clicks to gate execution in on_push_registration_clicked may unintentionally block registration logic on every alternate click. Consider using a dedicated mechanism or removing the modulo check if the intent is to process every click.

Suggested change
void RegistrationWindow::on_push_registration_clicked() {
if (this->counter_on_switch_theme_clicks++ % 2) {
const QString created_login = ui->create_login->text();
const QString created_password = ui->create_password->text();
const QString repeated_password = ui->repeat_password->text();
if (!created_login.isEmpty() && !created_password.isEmpty() &&
!repeated_password.isEmpty()) {
if (created_password != repeated_password) {
QMessageBox::warning(this, "Ошибка", "Пароли не совпадают!");
} else if (created_login.size() > 50) {
QMessageBox::warning(
this, "Ошибка",
"Длина логина не должна превышать пятидесяти символов"
);
} else if (created_password.size() > 50) {
QMessageBox::warning(
this, "Ошибка",
"Длина пароля не должна превышать пятидесяти символов"
);
} else if (is_strong_and_valid_password(created_password)) {
auto user = new User();
user->set_login(created_login.toStdString());
user->set_hashed_password(created_password.toStdString());
const int try_register_user =
ClientImplementation::get_instance().try_register_user(user
);
if (try_register_user == 0) {
QMessageBox::warning(
this, "Ошибка",
"Извините, внутренняя ошибка с базами данных."
);
} else if (try_register_user == -1) {
QMessageBox::warning(
this, "Ошибка",
"Пользователь с таким именем уже существует. "
"Пожалуйста, "
"придумайте другое!"
);
} else {
QMessageBox::information(
this, "Регистрация",
"Вы успешно зарегистрировались! Пожалуйста, выполните "
"вход."
);
on_switch_mode_clicked();
}
}
} else {
QMessageBox::warning(
this, "Ошибка", "Пожалуйста, заполните все поля."
);
}
}
}
void RegistrationWindow::on_push_registration_clicked() {
const QString created_login = ui->create_login->text();
const QString created_password = ui->create_password->text();
const QString repeated_password = ui->repeat_password->text();
if (!created_login.isEmpty() && !created_password.isEmpty() &&
!repeated_password.isEmpty()) {
if (created_password != repeated_password) {
QMessageBox::warning(this, "Ошибка", "Пароли не совпадают!");
} else if (created_login.size() > 50) {
QMessageBox::warning(
this, "Ошибка",
"Длина логина не должна превышать пятидесяти символов"
);
} else if (created_password.size() > 50) {
QMessageBox::warning(
this, "Ошибка",
"Длина пароля не должна превышать пятидесяти символов"
);
} else if (is_strong_and_valid_password(created_password)) {
auto user = new User();
user->set_login(created_login.toStdString());
user->set_hashed_password(created_password.toStdString());
const int try_register_user =
ClientImplementation::get_instance().try_register_user(user
);
if (try_register_user == 0) {
QMessageBox::warning(
this, "Ошибка",
"Извините, внутренняя ошибка с базами данных."
);
} else if (try_register_user == -1) {
QMessageBox::warning(
this, "Ошибка",
"Пользователь с таким именем уже существует. "
"Пожалуйста, "
"придумайте другое!"
);
} else {
QMessageBox::information(
this, "Регистрация",
"Вы успешно зарегистрировались! Пожалуйста, выполните "
"вход."
);
on_switch_mode_clicked();
}
}
} else {
QMessageBox::warning(
this, "Ошибка", "Пожалуйста, заполните все поля."
);
}
}

Copilot uses AI. Check for mistakes.
Comment on lines +87 to +133
void LoginWindow::on_push_enter_clicked() {
if (this->counter_on_switch_theme_clicks++ % 2) {
const QString login = ui->input_login->text();
const QString password = ui->input_password->text();

auto user = new User();
user->set_login(login.toStdString());
user->set_hashed_password(password.toStdString());

if (!login.isEmpty() && !password.isEmpty()) {
if (login.size() > 50) {
QMessageBox::warning(
this, "Ошибка",
"Длина логина не должна превышать пятидесяти символов"
);
} else if (password.size() > 50) {
QMessageBox::warning(
this, "Ошибка",
"Длина пароля не должна превышать пятидесяти символов"
);
} else if (ClientImplementation::get_instance()
.try_authenticate_user(user)) {
QMessageBox::information(
this, "Вход", "Вы успешно вошли! Добро пожаловать :)"
);
QWidget *parent = this->parentWidget();

const QMainWindow *app_window =
qobject_cast<QMainWindow *>(parent);

if (QWidget *old = app_window->centralWidget()) {
old->deleteLater();
}

this->close();
} else {
QMessageBox::warning(
this, "Ошибка ввода данных", "Неверный логин или пароль!"
);
}
} else {
QMessageBox::warning(
this, "Ошибка ввода данных", "Пожалуйста, заполните все поля!"
);
}
}
}
Copy link

Copilot AI Jun 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gating the on_push_enter_clicked action with a counter modulo check may result in inconsistent login behavior. It is recommended to remove or separate this counter from the login event handling.

Suggested change
void LoginWindow::on_push_enter_clicked() {
if (this->counter_on_switch_theme_clicks++ % 2) {
const QString login = ui->input_login->text();
const QString password = ui->input_password->text();
auto user = new User();
user->set_login(login.toStdString());
user->set_hashed_password(password.toStdString());
if (!login.isEmpty() && !password.isEmpty()) {
if (login.size() > 50) {
QMessageBox::warning(
this, "Ошибка",
"Длина логина не должна превышать пятидесяти символов"
);
} else if (password.size() > 50) {
QMessageBox::warning(
this, "Ошибка",
"Длина пароля не должна превышать пятидесяти символов"
);
} else if (ClientImplementation::get_instance()
.try_authenticate_user(user)) {
QMessageBox::information(
this, "Вход", "Вы успешно вошли! Добро пожаловать :)"
);
QWidget *parent = this->parentWidget();
const QMainWindow *app_window =
qobject_cast<QMainWindow *>(parent);
if (QWidget *old = app_window->centralWidget()) {
old->deleteLater();
}
this->close();
} else {
QMessageBox::warning(
this, "Ошибка ввода данных", "Неверный логин или пароль!"
);
}
} else {
QMessageBox::warning(
this, "Ошибка ввода данных", "Пожалуйста, заполните все поля!"
);
}
}
}
void LoginWindow::on_push_enter_clicked() {
const QString login = ui->input_login->text();
const QString password = ui->input_password->text();
auto user = new User();
user->set_login(login.toStdString());
user->set_hashed_password(password.toStdString());
if (!login.isEmpty() && !password.isEmpty()) {
if (login.size() > 50) {
QMessageBox::warning(
this, "Ошибка",
"Длина логина не должна превышать пятидесяти символов"
);
} else if (password.size() > 50) {
QMessageBox::warning(
this, "Ошибка",
"Длина пароля не должна превышать пятидесяти символов"
);
} else if (ClientImplementation::get_instance()
.try_authenticate_user(user)) {
QMessageBox::information(
this, "Вход", "Вы успешно вошли! Добро пожаловать :)"
);
QWidget *parent = this->parentWidget();
const QMainWindow *app_window =
qobject_cast<QMainWindow *>(parent);
if (QWidget *old = app_window->centralWidget()) {
old->deleteLater();
}
this->close();
} else {
QMessageBox::warning(
this, "Ошибка ввода данных", "Неверный логин или пароль!"
);
}
} else {
QMessageBox::warning(
this, "Ошибка ввода данных", "Пожалуйста, заполните все поля!"
);
}
}

Copilot uses AI. Check for mistakes.
Comment on lines +185 to +186
) {
1 + 1;
Copy link

Copilot AI Jun 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The placeholder expression '1 + 1;' in the CreateNoteClientCall constructor indicates an incomplete implementation; replace it with the intended note creation logic.

Suggested change
) {
1 + 1;
)
: responder_(stub->AsyncCreateNote(&context, request, cq)) {
context.set_deadline(
std::chrono::system_clock::now() + std::chrono::seconds(5)
);
responder_->Finish(&reply_, &status, this);
std::cout << "[CLIENT]: CREATE NOTE REQUEST SENT\n";

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants