Add admin panel
This commit is contained in:
parent
2c72beab6a
commit
9f2eb3c573
6 changed files with 276 additions and 7 deletions
16
sea_transport/adminpanel.cpp
Normal file
16
sea_transport/adminpanel.cpp
Normal file
|
|
@ -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;
|
||||
}
|
||||
28
sea_transport/adminpanel.h
Normal file
28
sea_transport/adminpanel.h
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#ifndef ADMINPANEL_H
|
||||
#define ADMINPANEL_H
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
#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
|
||||
162
sea_transport/adminpanel.ui
Normal file
162
sea_transport/adminpanel.ui
Normal file
|
|
@ -0,0 +1,162 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>AdminPanel</class>
|
||||
<widget class="QMainWindow" name="AdminPanel">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1200</width>
|
||||
<height>600</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>MainWindow</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Storages</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTableView" name="tableView"/>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="text">
|
||||
<string>Add</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_8">
|
||||
<property name="text">
|
||||
<string>Remove</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Delivery points</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTableView" name="tableView_2"/>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_2">
|
||||
<property name="text">
|
||||
<string>Add</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_5">
|
||||
<property name="text">
|
||||
<string>Remove</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Vessels</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTableView" name="tableView_3"/>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_3">
|
||||
<property name="text">
|
||||
<string>Add</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_7">
|
||||
<property name="text">
|
||||
<string>Remove</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Users</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTableView" name="tableView_4"/>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_4">
|
||||
<property name="text">
|
||||
<string>Add</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_6">
|
||||
<property name="text">
|
||||
<string>Remove</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menubar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1200</width>
|
||||
<height>21</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusbar"/>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
@ -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.");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,12 @@
|
|||
#ifndef AUTHWINDOW_H
|
||||
#define AUTHWINDOW_H
|
||||
|
||||
#include <system/apparatus.h>
|
||||
|
||||
#include "adminpanel.h"
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QMessageBox>
|
||||
|
||||
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;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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 \
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue