diff --git a/sea_transport/adminpanel.cpp b/sea_transport/adminpanel.cpp new file mode 100644 index 0000000..f368ea0 --- /dev/null +++ b/sea_transport/adminpanel.cpp @@ -0,0 +1,16 @@ +#include "adminpanel.h" +#include "ui_adminpanel.h" + +AdminPanel::AdminPanel(QWidget *parent) : QMainWindow(parent), ui(new Ui::AdminPanel) +{ + ui->setupUi(this); +} + +AdminPanel::~AdminPanel() { + delete ui; +} + +AdminPanel& AdminPanel::set_user(const user_entity &user) { + this->user = user; + return *this; +} diff --git a/sea_transport/adminpanel.h b/sea_transport/adminpanel.h new file mode 100644 index 0000000..1444919 --- /dev/null +++ b/sea_transport/adminpanel.h @@ -0,0 +1,28 @@ +#ifndef ADMINPANEL_H +#define ADMINPANEL_H + +#include + +#include "entities/user_entity.h" + +namespace Ui { + class AdminPanel; +} + +class AdminPanel : public QMainWindow +{ + Q_OBJECT + + user_entity user; + +public: + explicit AdminPanel(QWidget *parent = nullptr); + ~AdminPanel(); + + AdminPanel& set_user(const user_entity &user); + +private: + Ui::AdminPanel *ui; +}; + +#endif // ADMINPANEL_H diff --git a/sea_transport/adminpanel.ui b/sea_transport/adminpanel.ui new file mode 100644 index 0000000..196027d --- /dev/null +++ b/sea_transport/adminpanel.ui @@ -0,0 +1,162 @@ + + + AdminPanel + + + + 0 + 0 + 1200 + 600 + + + + MainWindow + + + + + + + + + Storages + + + + + + + + + + + + Add + + + + + + + Remove + + + + + + + + + + + + + Delivery points + + + + + + + + + + + + Add + + + + + + + Remove + + + + + + + + + + + + + Vessels + + + + + + + + + + + + Add + + + + + + + Remove + + + + + + + + + + + + + Users + + + + + + + + + + + + Add + + + + + + + Remove + + + + + + + + + + + + + 0 + 0 + 1200 + 21 + + + + + + + + diff --git a/sea_transport/authwindow.cpp b/sea_transport/authwindow.cpp index f895a75..5f8712c 100644 --- a/sea_transport/authwindow.cpp +++ b/sea_transport/authwindow.cpp @@ -1,14 +1,64 @@ #include "authwindow.h" #include "ui_authwindow.h" -AuthWindow::AuthWindow(QWidget *parent) : - QMainWindow(parent), - ui(new Ui::AuthWindow) -{ + +AuthWindow::AuthWindow(QWidget *parent, bool fr) : QMainWindow(parent), ui(new Ui::AuthWindow) { ui->setupUi(this); + this->firstRun = fr; + + connect(ui->btn_login, &QPushButton::clicked, this, &AuthWindow::on_auth_requested); } -AuthWindow::~AuthWindow() -{ +AuthWindow::~AuthWindow() { delete ui; } + +void AuthWindow::on_auth_requested() { + auto login = ui->et_login->text().trimmed(); + auto passw = ui->et_password->text().trimmed(); + + if (login.isEmpty() || passw.isEmpty()) { + QMessageBox::critical(this, "Error", "Login nor password cannot be empty!"); + return; + } + + bool success = false; + auto a = apparatus::instance()->get_auth_subsystem(); + if (this->firstRun) { + success = a.register_user(login, passw, UserRole::ADMINISTRATOR); + if (!success) { + QMessageBox::critical(this, "Error", "Cannot register you. Check filesystem permission"); + return; + } + else { + apparatus::instance()->serialize_data(); + } + } + + auto user = *a.get_user(login, success); + if (!success) { + QMessageBox::critical(this, "Error", "User not found"); + return; + } + + success = user.verify_password(passw); + if (!success) { + QMessageBox::critical(this, "Error", "Wrong password"); + return; + } + + + if (user.role() == UserRole::ADMINISTRATOR) { + AdminPanel(nullptr).set_user(user).show(); + } + else if (user.role() == UserRole::DISPATCHER) { + // DispatcherPanel(nullptr, user).set_user(user).show(); + } + else if (user.role() == UserRole::SKIPPER) { + // SkipperPanel(nullptr, user).set_user(user).show(); + } + else { + QMessageBox::critical(this, "Error", "Deserialized user have wrong type. " + "It may mean corruption of data."); + } +} diff --git a/sea_transport/authwindow.h b/sea_transport/authwindow.h index 5f5a356..c3fbe2a 100644 --- a/sea_transport/authwindow.h +++ b/sea_transport/authwindow.h @@ -1,7 +1,12 @@ #ifndef AUTHWINDOW_H #define AUTHWINDOW_H +#include + +#include "adminpanel.h" + #include +#include namespace Ui { class AuthWindow; @@ -10,11 +15,16 @@ class AuthWindow; class AuthWindow : public QMainWindow { Q_OBJECT + bool firstRun; public: - explicit AuthWindow(QWidget *parent = nullptr); + explicit AuthWindow(QWidget *parent = nullptr, bool fr = false); ~AuthWindow(); + +private slots: + void on_auth_requested(); + private: Ui::AuthWindow *ui; }; diff --git a/sea_transport/sea_transport.pro b/sea_transport/sea_transport.pro index d5e4f66..23e96ba 100644 --- a/sea_transport/sea_transport.pro +++ b/sea_transport/sea_transport.pro @@ -9,6 +9,7 @@ CONFIG += c++11 #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ + adminpanel.cpp \ authwindow.cpp \ cargoeditdialog.cpp \ deliverypointeditdialog.cpp \ @@ -26,6 +27,7 @@ SOURCES += \ vesseleditdialog.cpp HEADERS += \ + adminpanel.h \ authwindow.h \ cargoeditdialog.h \ deliverypointeditdialog.h \ @@ -44,6 +46,7 @@ HEADERS += \ vesseleditdialog.h FORMS += \ + adminpanel.ui \ authwindow.ui \ cargoeditdialog.ui \ deliverypointeditdialog.ui \