diff --git a/DataBaseLMS/interfacedatabaselms.cpp b/DataBaseLMS/interfacedatabaselms.cpp index 6c8c0eb..1cea546 100644 --- a/DataBaseLMS/interfacedatabaselms.cpp +++ b/DataBaseLMS/interfacedatabaselms.cpp @@ -37,16 +37,32 @@ bool InterfaceDataBaseLMS::DBisConnected() //Инструкторы -bool InterfaceDataBaseLMS::authorizationInstructor(QString login, QString password) +bool InterfaceDataBaseLMS::authorizationInstructor(QString login, QString password, ErrorAuth& error) { + error = ErrorAuth::errNo; + if(int id = selectUserID(DataBaseLMS::TypeUserDBInstructor, login, password)) { - if(selectUserArchived(DataBaseLMS::TypeUserDBInstructor, id) || selectUserLoggedIn(DataBaseLMS::TypeUserDBInstructor, id)) + if(selectUserArchived(DataBaseLMS::TypeUserDBInstructor, id)) + { + error = ErrorAuth::errArchived; return false; + } + + if(selectUserLoggedIn(DataBaseLMS::TypeUserDBInstructor, id)) + { + error = ErrorAuth::errAlreadyLogIn; + return false; + } if(updateUserLoggedIn(DataBaseLMS::TypeUserDBInstructor, id, true)) return true; + else + error = ErrorAuth::errDB; } + else + error = ErrorAuth::errLoginOrPassword; + return false; } @@ -118,16 +134,32 @@ bool InterfaceDataBaseLMS::isLoggedInInstructor(int id) //Инструкторы -bool InterfaceDataBaseLMS::authorizationTrainee(QString login, QString password, QString classroom_name, QString computer_name) +bool InterfaceDataBaseLMS::authorizationTrainee(QString login, QString password, ErrorAuth& error, QString classroom_name, QString computer_name) { + error = ErrorAuth::errNo; + if(int id = selectUserID(DataBaseLMS::TypeUserDBTrainee, login, password)) { - if(selectUserArchived(DataBaseLMS::TypeUserDBTrainee, id) || selectUserLoggedIn(DataBaseLMS::TypeUserDBTrainee, id)) + if(selectUserArchived(DataBaseLMS::TypeUserDBTrainee, id)) + { + error = ErrorAuth::errArchived; return false; + } + + if(selectUserLoggedIn(DataBaseLMS::TypeUserDBTrainee, id)) + { + error = ErrorAuth::errAlreadyLogIn; + return false; + } if(updateUserLoggedIn(DataBaseLMS::TypeUserDBTrainee, id, true)) return true; + else + error = ErrorAuth::errDB; } + else + error = ErrorAuth::errLoginOrPassword; + return false; } diff --git a/DataBaseLMS/interfacedatabaselms.h b/DataBaseLMS/interfacedatabaselms.h index 5ad17a4..a63f7c4 100644 --- a/DataBaseLMS/interfacedatabaselms.h +++ b/DataBaseLMS/interfacedatabaselms.h @@ -10,6 +10,15 @@ class DATABASELMS_EXPORT InterfaceDataBaseLMS : public DataBaseLMS { +public: + enum ErrorAuth + { + errNo = 0, + errDB, + errLoginOrPassword, + errArchived, + errAlreadyLogIn + }; public: InterfaceDataBaseLMS(QWidget *ownerWidget, QObject *parent = nullptr); @@ -22,7 +31,7 @@ public: //Инструкторы - bool authorizationInstructor(QString login, QString password); + bool authorizationInstructor(QString login, QString password, ErrorAuth& error); bool deAuthorizationInstructor(QString login); bool deAuthorizationAllInstructors(); @@ -43,7 +52,7 @@ public: //Обучаемые - bool authorizationTrainee(QString login, QString password, QString classroom_name, QString computer_name); + bool authorizationTrainee(QString login, QString password, ErrorAuth& error, QString classroom_name, QString computer_name); bool deAuthorizationTrainee(QString login); bool deAuthorizationAllTrainees(); diff --git a/InstructorsAndTrainees/connectorToServer/Core/recognizesystem.cpp b/InstructorsAndTrainees/connectorToServer/Core/recognizesystem.cpp index 3d4dab8..8705ca1 100644 --- a/InstructorsAndTrainees/connectorToServer/Core/recognizesystem.cpp +++ b/InstructorsAndTrainees/connectorToServer/Core/recognizesystem.cpp @@ -456,16 +456,33 @@ void RecognizeSystem::xmlParser(QByteArray array) if(name == "Code") { - if (value == "END") + if (value == NOTIFY_SERVER_END) { emit sigSocketDisabled(); } - if(value == "BLOCKED") + if(value == NOTIFY_SERVER_BLOCKED) { emit sigServerBlocked(); } + if(value == NOTIFY_ERROR_AUTH_DB) + { + emit sigErrorAuth(value); + } + if(value == NOTIFY_ERROR_AUTH_LOGINORPASSWORD) + { + emit sigErrorAuth(value); + } + if(value == NOTIFY_ERROR_AUTH_ARCHIVED) + { + emit sigErrorAuth(value); + } + if(value == NOTIFY_ERROR_AUTH_ALREADYLOGIN) + { + emit sigErrorAuth(value); + } + if(value == "HASHSENDCOMPLETE") { emit sigStartCompare(); diff --git a/InstructorsAndTrainees/connectorToServer/Core/recognizesystem.h b/InstructorsAndTrainees/connectorToServer/Core/recognizesystem.h index 60f232c..f679249 100644 --- a/InstructorsAndTrainees/connectorToServer/Core/recognizesystem.h +++ b/InstructorsAndTrainees/connectorToServer/Core/recognizesystem.h @@ -34,6 +34,7 @@ signals: void sigSendDebugLog(QString message); void sigSocketDisabled(); void sigServerBlocked(); + void sigErrorAuth(QString error); void sigAuth(ServerAuthorization *serverAuth); void sigDeAuth(ServerDeAuthorization *serverDeAuth); void sigAnswerQueryToDB(QList* listInstructors, diff --git a/InstructorsAndTrainees/connectorToServer/Core/tools.h b/InstructorsAndTrainees/connectorToServer/Core/tools.h index 622badb..25c1152 100644 --- a/InstructorsAndTrainees/connectorToServer/Core/tools.h +++ b/InstructorsAndTrainees/connectorToServer/Core/tools.h @@ -71,6 +71,14 @@ enum PacketType{ FREE = 155 }; +#define NOTIFY_ERROR_AUTH_DB "ERROR_AUTH_DB" +#define NOTIFY_ERROR_AUTH_LOGINORPASSWORD "ERROR_AUTH_LOGINORPASSWORD" +#define NOTIFY_ERROR_AUTH_ARCHIVED "ERROR_AUTH_ARCHIVED" +#define NOTIFY_ERROR_AUTH_ALREADYLOGIN "ERROR_AUTH_ALREADYLOGIN" +#define NOTIFY_SERVER_END "END" +#define NOTIFY_SERVER_BLOCKED "BLOCKED" +#define SERVER_HELLO "NewConnection. I am server LMS!" + //Q_DECLARE_METATYPE(PacketType) class Tools { diff --git a/InstructorsAndTrainees/connectorToServer/connectortoserver.cpp b/InstructorsAndTrainees/connectorToServer/connectortoserver.cpp index d82e95b..839809e 100644 --- a/InstructorsAndTrainees/connectorToServer/connectortoserver.cpp +++ b/InstructorsAndTrainees/connectorToServer/connectortoserver.cpp @@ -90,6 +90,11 @@ void ConnectorToServer::slot_ServerBlocked() emit sigServerBlocked(); } +void ConnectorToServer::slot_ErrorAuth(QString error) +{ + emit sigErrorAuth(error); +} + void ConnectorToServer::slot_SendDeleteVersion(StreamingVersionData *streaming) { emit signal_SendDeleteVersion(streaming); @@ -133,6 +138,7 @@ void ConnectorToServer::bindConnection() connect(recognizeSystem,&RecognizeSystem::sigDeAuth,this,&ConnectorToServer::sigDeLoginResult); connect(recognizeSystem,&RecognizeSystem::sigServerBlocked,this,&ConnectorToServer::slot_ServerBlocked); + connect(recognizeSystem,&RecognizeSystem::sigErrorAuth,this,&ConnectorToServer::slot_ErrorAuth); connect(recognizeSystem,&RecognizeSystem::signal_ReceiveMessage,this,&ConnectorToServer::signal_receiveMessage,Qt::AutoConnection); connect(recognizeSystem,&RecognizeSystem::sigShowServerDataList,this,&ConnectorToServer::slot_showServerList); diff --git a/InstructorsAndTrainees/connectorToServer/connectortoserver.h b/InstructorsAndTrainees/connectorToServer/connectortoserver.h index d4663bb..be5d2db 100644 --- a/InstructorsAndTrainees/connectorToServer/connectortoserver.h +++ b/InstructorsAndTrainees/connectorToServer/connectortoserver.h @@ -108,6 +108,7 @@ public slots: void slot_HashReady(); void slot_Auth(ServerAuthorization * serverAuth); void slot_ServerBlocked(); + void slot_ErrorAuth(QString error); void slot_SendDeleteVersion(StreamingVersionData *streaming); void slot_SendSwitchVersion(StreamingVersionData *selectVersion); @@ -125,6 +126,7 @@ signals: void sigLoginResult(ServerAuthorization * serverAuth); void sigDeLoginResult(ServerDeAuthorization * serverDeAuth); void sigServerBlocked(); + void sigErrorAuth(QString error); void signal_UpdateDB(bool treeInstructor, bool treeTrainee); diff --git a/InstructorsAndTrainees/instructorsandtraineeswidget.cpp b/InstructorsAndTrainees/instructorsandtraineeswidget.cpp index 6bac7e4..ec8ec36 100644 --- a/InstructorsAndTrainees/instructorsandtraineeswidget.cpp +++ b/InstructorsAndTrainees/instructorsandtraineeswidget.cpp @@ -54,6 +54,7 @@ InstructorsAndTraineesWidget::InstructorsAndTraineesWidget(QWidget *parent) : connect(connectorToServer, &ConnectorToServer::sigLoginResult, this, &InstructorsAndTraineesWidget::slot_checkLoginResult); connect(connectorToServer, &ConnectorToServer::sigDeLoginResult, this, &InstructorsAndTraineesWidget::slot_checkDeLoginResult); connect(connectorToServer, &ConnectorToServer::sigServerBlocked, this, &InstructorsAndTraineesWidget::slot_ServerBlocked); + connect(connectorToServer, &ConnectorToServer::sigErrorAuth, this, &InstructorsAndTraineesWidget::slot_ErrorAuth); connect(connectorToServer,&ConnectorToServer::signal_AnswerDocsChanged,this, &InstructorsAndTraineesWidget::slot_AnswerDocsChanged); messangerController = new MessangerController(connectorToServer, this); @@ -239,16 +240,14 @@ void InstructorsAndTraineesWidget::slot_checkLoginResult(ServerAuthorization *se viewerInstructors->activate(); waitAnimationWidget->hideWithStop(); + + flTryLogin = false; } else { - waitAnimationWidget->hideWithStop(); - - ui->btnAuthorizationInstructor->setChecked(false); - SpecialMessageBox(this, SpecialMessageBox::TypeSpecMsgBox::critical, tr("Instructor authorization.") + "\n" + tr("Invalid login or password!")).exec(); + //waitAnimationWidget->hideWithStop(); + //ui->btnAuthorizationInstructor->setChecked(false); } - - flTryLogin = false; } void InstructorsAndTraineesWidget::slot_checkDeLoginResult(ServerDeAuthorization *serverDeAuth) @@ -285,7 +284,39 @@ void InstructorsAndTraineesWidget::slot_ServerBlocked() waitAnimationWidget->hideWithStop(); ui->btnAuthorizationInstructor->setChecked(false); - SpecialMessageBox(this, SpecialMessageBox::TypeSpecMsgBox::warningClose, tr("Server blocked!")).exec(); + SpecialMessageBox(this, SpecialMessageBox::TypeSpecMsgBox::warningClose, tr("Instructor authorization.") + "\n" + tr("Server blocked!")).exec(); + } +} + +void InstructorsAndTraineesWidget::slot_ErrorAuth(QString error) +{ + if(flTryLogin) + { + flTryLogin = false; + waitAnimationWidget->hideWithStop(); + + ui->btnAuthorizationInstructor->setChecked(false); + + QString errorTextMsg = ""; + + if(error == NOTIFY_ERROR_AUTH_DB) + { + errorTextMsg = tr("Database error!"); + } + else if(error == NOTIFY_ERROR_AUTH_ARCHIVED) + { + errorTextMsg = tr("The user is archived!"); + } + else if(error == NOTIFY_ERROR_AUTH_ALREADYLOGIN) + { + errorTextMsg = tr("The user is already logged in!"); + } + else if(error == NOTIFY_ERROR_AUTH_LOGINORPASSWORD) + { + errorTextMsg = tr("Login or password error!"); + } + + SpecialMessageBox(this, SpecialMessageBox::TypeSpecMsgBox::warningClose, tr("Instructor authorization.") + "\n" + errorTextMsg).exec(); } } diff --git a/InstructorsAndTrainees/instructorsandtraineeswidget.h b/InstructorsAndTrainees/instructorsandtraineeswidget.h index 307754b..2cd5624 100644 --- a/InstructorsAndTrainees/instructorsandtraineeswidget.h +++ b/InstructorsAndTrainees/instructorsandtraineeswidget.h @@ -54,6 +54,7 @@ public Q_SLOTS: void slot_checkDeLoginResult(ServerDeAuthorization * serverDeAuth); void slot_ServerBlocked(); + void slot_ErrorAuth(QString error); //Слот обработки результата подключения к серверу void slot_ConnectedToServer(bool state); diff --git a/ServerLMS/Data/typesDataServerClient.h b/ServerLMS/Data/typesDataServerClient.h index 7135dff..7a6ab49 100644 --- a/ServerLMS/Data/typesDataServerClient.h +++ b/ServerLMS/Data/typesDataServerClient.h @@ -5,9 +5,13 @@ #include #include "typeQueryToDB.h" -#define NOTIFY_SERVER_END "END" -#define NOTIFY_SERVER_BLOCKED "BLOCKED" -#define SERVER_HELLO "NewConnection. I am server LMS!" +#define NOTIFY_ERROR_AUTH_DB "ERROR_AUTH_DB" +#define NOTIFY_ERROR_AUTH_LOGINORPASSWORD "ERROR_AUTH_LOGINORPASSWORD" +#define NOTIFY_ERROR_AUTH_ARCHIVED "ERROR_AUTH_ARCHIVED" +#define NOTIFY_ERROR_AUTH_ALREADYLOGIN "ERROR_AUTH_ALREADYLOGIN" +#define NOTIFY_SERVER_END "END" +#define NOTIFY_SERVER_BLOCKED "BLOCKED" +#define SERVER_HELLO "NewConnection. I am server LMS!" enum EStateServer{started, stoped}; enum EStateBlockAutorization{blocked, unblocked}; diff --git a/ServerLMS/Systems/processingsystem.cpp b/ServerLMS/Systems/processingsystem.cpp index 61d5997..96b15e9 100644 --- a/ServerLMS/Systems/processingsystem.cpp +++ b/ServerLMS/Systems/processingsystem.cpp @@ -39,8 +39,6 @@ void ProcessingSystem::processingClientAutorization(ClientHandler *client, Clien { QByteArray arrayAnswer = dataParser->ClientAnswer()->notify(NOTIFY_SERVER_BLOCKED); client->sendXmlAnswer(arrayAnswer); - - QString str = QString(arrayAnswer); return; } @@ -50,8 +48,10 @@ void ProcessingSystem::processingClientAutorization(ClientHandler *client, Clien QByteArray arrayAnswer; int clientID = 0; + InterfaceDataBaseLMS::ErrorAuth errorAuth = InterfaceDataBaseLMS::ErrorAuth::errNo; - if(providerDBLMS->authorizationInstructor(clientAutorization.Login, clientAutorization.Password)) + + if(providerDBLMS->authorizationInstructor(clientAutorization.Login, clientAutorization.Password, errorAuth)) {//Авторизуется инструктор client->getClient()->setLogin(clientAutorization.Login); @@ -67,7 +67,7 @@ void ProcessingSystem::processingClientAutorization(ClientHandler *client, Clien } else if(clientAutorization.TypeClient != TypeClientAutorization::TYPE_GUI) { - if(providerDBLMS->authorizationTrainee(clientAutorization.Login, clientAutorization.Password, "", "")) + if(providerDBLMS->authorizationTrainee(clientAutorization.Login, clientAutorization.Password, errorAuth, "", "")) {//Авторизуется обучаемый client->getClient()->setLogin(clientAutorization.Login); @@ -91,15 +91,42 @@ void ProcessingSystem::processingClientAutorization(ClientHandler *client, Clien arrayAnswer = dataParser->ClientAnswer()->authorization(false, "", "", "", "", 0); } client->sendXmlAnswer(arrayAnswer); - client->sendVersion(); - //client->sendPacketType(PacketType::BUSY); - //client->sendPacketType(PacketType::FREE); + if(errorAuth == InterfaceDataBaseLMS::ErrorAuth::errNo) + { + client->sendVersion(); - QString str = QString(arrayAnswer); - //logger->addTextToLogger("To Client: " + str); - //Извещаем об изменениях в авторизации - emit sigListsInstructorsTraineesChanged(); + //client->sendPacketType(PacketType::BUSY); + //client->sendPacketType(PacketType::FREE); + + //Извещаем об изменениях в авторизации + emit sigListsInstructorsTraineesChanged(); + } + else + { + QString notifyText = ""; + + switch (errorAuth) + { + case InterfaceDataBaseLMS::ErrorAuth::errDB: + notifyText = NOTIFY_ERROR_AUTH_DB; + break; + case InterfaceDataBaseLMS::ErrorAuth::errArchived: + notifyText = NOTIFY_ERROR_AUTH_ARCHIVED; + break; + case InterfaceDataBaseLMS::ErrorAuth::errAlreadyLogIn: + notifyText = NOTIFY_ERROR_AUTH_ALREADYLOGIN; + break; + case InterfaceDataBaseLMS::ErrorAuth::errLoginOrPassword: + notifyText = NOTIFY_ERROR_AUTH_LOGINORPASSWORD; + break; + default: + break; + } + + QByteArray arrayAnswer = dataParser->ClientAnswer()->notify(notifyText); + client->sendXmlAnswer(arrayAnswer); + } } void ProcessingSystem::processingClientDeAutorization(ClientHandler *client, ClientDeAutorization clientDeAutorization) @@ -129,6 +156,10 @@ void ProcessingSystem::processingClientDeAutorization(ClientHandler *client, Cli emit sigUpdateListClients(); arrayAnswer = dataParser->ClientAnswer()->deAuthorization(true, clientDeAutorization.Login); + client->sendXmlAnswer(arrayAnswer); + + //Извещаем об изменениях в авторизации + emit sigListsInstructorsTraineesChanged(); } else if(providerDBLMS->deAuthorizationInstructor(clientDeAutorization.Login)) {//ДеАвторизуется инструктор @@ -139,18 +170,16 @@ void ProcessingSystem::processingClientDeAutorization(ClientHandler *client, Cli emit sigUpdateListClients(); arrayAnswer = dataParser->ClientAnswer()->deAuthorization(true, clientDeAutorization.Login); + client->sendXmlAnswer(arrayAnswer); + + //Извещаем об изменениях в авторизации + emit sigListsInstructorsTraineesChanged(); } else {//Никто не ДеАвторизовался arrayAnswer = dataParser->ClientAnswer()->deAuthorization(false, ""); + client->sendXmlAnswer(arrayAnswer); } - client->sendXmlAnswer(arrayAnswer); - - QString str = QString(arrayAnswer); - //logger->addTextToLogger("To Client: " + str); - - //Извещаем об изменениях в авторизации - emit sigListsInstructorsTraineesChanged(); } void ProcessingSystem::processingClientBlockAuth(ClientHandler *client, bool block) diff --git a/ServerLMS/providerdblms/providerdblms.cpp b/ServerLMS/providerdblms/providerdblms.cpp index 1a2a57e..8707b58 100644 --- a/ServerLMS/providerdblms/providerdblms.cpp +++ b/ServerLMS/providerdblms/providerdblms.cpp @@ -108,7 +108,7 @@ QString ProviderDBLMS::getMainInstructorName() return QStringLiteral(""); } -bool ProviderDBLMS::authorizationTrainee(QString login, QString password, QString classroom_name, QString computer_name) +bool ProviderDBLMS::authorizationTrainee(QString login, QString password, InterfaceDataBaseLMS::ErrorAuth& error, QString classroom_name, QString computer_name) { mtxAccess.lock(); @@ -120,7 +120,7 @@ bool ProviderDBLMS::authorizationTrainee(QString login, QString password, QStrin //Q_EMIT signal_BlockAutorization(true); - bool res = dbLMS->authorizationTrainee(login, password, classroom_name, computer_name); + bool res = dbLMS->authorizationTrainee(login, password, error, classroom_name, computer_name); //Q_EMIT signal_BlockAutorization(false); @@ -164,7 +164,7 @@ QString ProviderDBLMS::getNameTraineeByLogin(QString login) return res; } -bool ProviderDBLMS::authorizationInstructor(QString login, QString password) +bool ProviderDBLMS::authorizationInstructor(QString login, QString password, InterfaceDataBaseLMS::ErrorAuth& error) { mtxAccess.lock(); @@ -176,7 +176,7 @@ bool ProviderDBLMS::authorizationInstructor(QString login, QString password) //Q_EMIT signal_BlockAutorization(true); - bool res = dbLMS->authorizationInstructor(login, password); + bool res = dbLMS->authorizationInstructor(login, password, error); //Q_EMIT signal_BlockAutorization(false); diff --git a/ServerLMS/providerdblms/providerdblms.h b/ServerLMS/providerdblms/providerdblms.h index 2c58257..bda33fb 100644 --- a/ServerLMS/providerdblms/providerdblms.h +++ b/ServerLMS/providerdblms/providerdblms.h @@ -16,12 +16,12 @@ public: QString getMainInstructorName(); //Авторизация обучаемого на клиенте - bool authorizationTrainee(QString login, QString password, QString classroom_name = QStringLiteral(""), QString computer_name = QStringLiteral("")); + bool authorizationTrainee(QString login, QString password, InterfaceDataBaseLMS::ErrorAuth& error, QString classroom_name = QStringLiteral(""), QString computer_name = QStringLiteral("")); bool deAuthorizationTrainee(QString login); QString getNameTraineeByLogin(QString login); //Авторизация инструктора на клиенте - bool authorizationInstructor(QString login, QString password); + bool authorizationInstructor(QString login, QString password, InterfaceDataBaseLMS::ErrorAuth& error); bool deAuthorizationInstructor(QString login); QString getNameInstructorByLogin(QString login);