base viewmodel and interactions

This commit is contained in:
Andrew nuark G 2020-12-21 23:39:04 +07:00
parent 50aa95e659
commit d69b18f083
14 changed files with 228 additions and 77 deletions

View file

@ -2,9 +2,8 @@
#include "ui_authwindow.h"
AuthWindow::AuthWindow(QWidget *parent, bool fr) : QMainWindow(parent), ui(new Ui::AuthWindow) {
AuthWindow::AuthWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::AuthWindow) {
ui->setupUi(this);
this->firstRun = fr;
connect(ui->btn_login, &QPushButton::clicked, this, &AuthWindow::on_auth_requested);
}
@ -24,37 +23,38 @@ void AuthWindow::on_auth_requested() {
bool success = false;
auto a = apparatus::instance()->get_auth_subsystem();
if (this->firstRun) {
if (apparatus::isFirstRun()) {
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();
QMessageBox::information(this, "Info", "You are the first user of system. "
"Your account type is administrator");
}
}
auto user = *a.get_user(login, success);
auto user = a.get_user(login, success);
if (!success) {
QMessageBox::critical(this, "Error", "User not found");
return;
}
success = user.verify_password(passw);
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();
if (user->role() == UserRole::ADMINISTRATOR) {
AdminPanel(nullptr).set_user(*user).showNormal();
}
else if (user.role() == UserRole::DISPATCHER) {
else if (user->role() == UserRole::DISPATCHER) {
// DispatcherPanel(nullptr, user).set_user(user).show();
}
else if (user.role() == UserRole::SKIPPER) {
else if (user->role() == UserRole::SKIPPER) {
// SkipperPanel(nullptr, user).set_user(user).show();
}
else {
@ -62,5 +62,4 @@ void AuthWindow::on_auth_requested() {
"It may mean corruption of data.");
return;
}
close();
}