Skip to content

Commit

Permalink
login error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
chrxh committed Oct 10, 2024
1 parent 4bda56b commit eec3c1e
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 19 deletions.
6 changes: 1 addition & 5 deletions source/Gui/BrowserWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1231,11 +1231,7 @@ void _BrowserWindow::processPendingRequestIds()

auto criticalErrors = _persisterController->fetchAllErrorInfos(SenderId{BrowserSenderId});
if (!criticalErrors.empty()) {
std::vector<std::string> errorMessages;
for (auto const& error : criticalErrors) {
errorMessages.emplace_back(error.message);
}
MessageDialog::getInstance().information("Error", boost::join(errorMessages, "\n\n"));
MessageDialog::getInstance().information("Error", criticalErrors);
}
}

Expand Down
8 changes: 1 addition & 7 deletions source/Gui/FileTransferController.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "FileTransferController.h"

#include <boost/algorithm/string.hpp>

#include <ImFileDialog.h>

#include "EngineInterface/SimulationController.h"
Expand Down Expand Up @@ -113,10 +111,6 @@ void FileTransferController::process()

auto criticalErrors = _persisterController->fetchAllErrorInfos(SenderId{FileTransferSenderId});
if (!criticalErrors.empty()) {
std::vector<std::string> errorMessages;
for (auto const& error : criticalErrors) {
errorMessages.emplace_back(error.message);
}
MessageDialog::getInstance().information("Error", boost::join(errorMessages, "\n\n"));
MessageDialog::getInstance().information("Error", criticalErrors);
}
}
18 changes: 11 additions & 7 deletions source/Gui/LoginController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "PersisterInterface/LoginRequestData.h"
#include "PersisterInterface/SenderInfo.h"

#include "MessageDialog.h"

namespace
{
auto constexpr LoginSenderId = "Login";
Expand All @@ -32,14 +34,8 @@ void LoginController::init(SimulationController const& simController, PersisterC

if (!userName.empty()) {
persisterController->scheduleLogin(
SenderInfo{.senderId = LoginSenderId, .wishResultData = false, .wishErrorInfo = true},
SenderInfo{.senderId = SenderId{LoginSenderId}, .wishResultData = false, .wishErrorInfo = true},
LoginRequestData{.userName = userName, .password = password, .userInfo = getUserInfo()});
//LoginErrorCode errorCode;
//if (!NetworkService::login(errorCode, _userName, _password, getUserInfo())) {
// if (errorCode != LoginErrorCode_UnknownUser) {
// MessageDialog::getInstance().information("Error", "Login failed.");
// }
//}
}
}
}
Expand All @@ -49,6 +45,14 @@ void LoginController::shutdown()
saveSettings();
}

void LoginController::process()
{
auto criticalErrors = _persisterController->fetchAllErrorInfos(SenderId{LoginSenderId});
if (!criticalErrors.empty()) {
MessageDialog::getInstance().information("Login failed", criticalErrors);
}
}

void LoginController::saveSettings()
{
auto& settings = GlobalSettings::getInstance();
Expand Down
2 changes: 2 additions & 0 deletions source/Gui/LoginController.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class LoginController
void init(SimulationController const& simController, PersisterController const& persisterController);
void shutdown();

void process();

void saveSettings();

bool shareGpuInfo() const;
Expand Down
1 change: 1 addition & 0 deletions source/Gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,7 @@ void _MainWindow::processControllers()
OverlayMessageController::get().process();
DelayedExecutionController::getInstance().process();
FileTransferController::get().process();
LoginController::get().process();
}

void _MainWindow::onRunSimulation()
Expand Down
11 changes: 11 additions & 0 deletions source/Gui/MessageDialog.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "MessageDialog.h"

#include <boost/algorithm/string.hpp>

#include <imgui.h>

#include "Base/LoggingService.h"
Expand Down Expand Up @@ -37,6 +39,15 @@ void MessageDialog::information(std::string const& title, std::string const& mes
log(Priority::Important, "message dialog showing: '" + message + "'");
}

void MessageDialog::information(std::string const& title, std::vector<PersisterErrorInfo> const& errors)
{
std::vector<std::string> errorMessages;
for (auto const& error : errors) {
errorMessages.emplace_back(error.message);
}
MessageDialog::getInstance().information(title, boost::join(errorMessages, "\n\n"));
}

void MessageDialog::yesNo(std::string const& title, std::string const& message, std::function<void()> const& yesFunction)
{
_show = true;
Expand Down
3 changes: 3 additions & 0 deletions source/Gui/MessageDialog.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once

#include "EngineInterface/Definitions.h"
#include "PersisterInterface/PersisterErrorInfo.h"

#include "Definitions.h"

class MessageDialog
Expand All @@ -11,6 +13,7 @@ class MessageDialog
void process();

void information(std::string const& title, std::string const& message);
void information(std::string const& title, std::vector<PersisterErrorInfo> const& errors);
void yesNo(std::string const& title, std::string const& message, std::function<void()> const& yesFunction);

private:
Expand Down

0 comments on commit eec3c1e

Please sign in to comment.