diff --git a/src/blackcore/db/databaseauthentication.cpp b/src/blackcore/db/databaseauthentication.cpp index a9e5fc04d..19750fe0b 100644 --- a/src/blackcore/db/databaseauthentication.cpp +++ b/src/blackcore/db/databaseauthentication.cpp @@ -11,7 +11,6 @@ #include "blackcore/db/databaseauthentication.h" #include "blackmisc/json.h" #include "blackmisc/logcategory.h" -#include "blackmisc/logcategorylist.h" #include "blackmisc/logmessage.h" #include "blackmisc/network/authenticateduser.h" #include "blackmisc/network/networkutils.h" @@ -36,6 +35,12 @@ namespace BlackCore { namespace Db { + const CLogCategoryList &CDatabaseAuthenticationService::getLogCategories() + { + static const CLogCategoryList cats { CLogCategory::swiftDbWebservice() }; + return cats; + } + CDatabaseAuthenticationService::CDatabaseAuthenticationService(QObject *parent) : QObject(parent) { @@ -63,9 +68,9 @@ namespace BlackCore CStatusMessageList CDatabaseAuthenticationService::login(const QString &username, const QString &password) { CStatusMessageList msgs; - static const CLogCategoryList cats(CLogCategoryList(this).join({ CLogCategory::validation()})); + static const CLogCategoryList cats(getLogCategories().join({ CLogCategory::validation() })); - if (m_shutdown) { msgs.push_back(CStatusMessage(cats, CStatusMessage::SeverityError, u"Shutdown in progress")); return msgs; } + if (!sApp || m_shutdown) { msgs.push_back(CStatusMessage(cats, CStatusMessage::SeverityError, u"Shutdown in progress")); return msgs; } const QString un(username.trimmed()); const QString pw(password.trimmed()); @@ -96,6 +101,7 @@ namespace BlackCore void CDatabaseAuthenticationService::logoff() { + if (!sApp) { return; } CUrl url(sApp->getGlobalSetup().getDbLoginServiceUrl()); url.setQuery("logoff=true"); QNetworkRequest request(CNetworkUtils::getSwiftNetworkRequest(url)); @@ -133,7 +139,7 @@ namespace BlackCore static const CLogCategoryList cats(CLogCategoryList(this).join({ CLogCategory::validation()})); const QJsonObject jsonObj(Json::jsonObjectFromString(json)); - const CAuthenticatedUser user = CAuthenticatedUser::fromDatabaseJson(jsonObj.contains("user") ? jsonObj["user"].toObject() : jsonObj); + CAuthenticatedUser user = CAuthenticatedUser::fromDatabaseJson(jsonObj.contains("user") ? jsonObj["user"].toObject() : jsonObj); CStatusMessageList msgs; if (jsonObj.contains("messages")) { @@ -141,6 +147,16 @@ namespace BlackCore msgs.setCategories(cats); } + // allow auto enabled for SSO users + if (user.isValid() && !user.isEnabled()) + { + if (user.getRoles().hasRole("VATSIMUSER")) + { + user.setEnabled(true); + msgs.push_back(CStatusMessage(cats, CStatusMessage::SeverityInfo, u"Auto enabled SSO user")); + } + } + if (!user.isAuthenticated() || !user.isValid()) { if (!msgs.hasErrorMessages()) diff --git a/src/blackcore/db/databaseauthentication.h b/src/blackcore/db/databaseauthentication.h index feb2bd7ca..d9b8def7e 100644 --- a/src/blackcore/db/databaseauthentication.h +++ b/src/blackcore/db/databaseauthentication.h @@ -11,9 +11,10 @@ #ifndef BLACKCORE_DATABASE_CDATABASEUATHENTICATIONSERVICE_H #define BLACKCORE_DATABASE_CDATABASEUATHENTICATIONSERVICE_H -#include "blackcore/blackcoreexport.h" #include "blackcore/data/authenticateduser.h" +#include "blackcore/blackcoreexport.h" #include "blackmisc/datacache.h" +#include "blackmisc/logcategorylist.h" #include "blackmisc/statusmessagelist.h" #include @@ -32,6 +33,9 @@ namespace BlackCore Q_OBJECT public: + //! Log categories + static const BlackMisc::CLogCategoryList &getLogCategories(); + //! Constructor CDatabaseAuthenticationService(QObject *parent = nullptr); @@ -64,7 +68,7 @@ namespace BlackCore //! User object changed void userChanged(); - BlackMisc::CData m_swiftDbUser {this, &CDatabaseAuthenticationService::userChanged}; + BlackMisc::CData m_swiftDbUser { this, &CDatabaseAuthenticationService::userChanged }; bool m_shutdown = false; }; } // ns diff --git a/src/blackgui/components/dblogincomponent.cpp b/src/blackgui/components/dblogincomponent.cpp index 21c131329..a54f16917 100644 --- a/src/blackgui/components/dblogincomponent.cpp +++ b/src/blackgui/components/dblogincomponent.cpp @@ -7,17 +7,18 @@ */ #include "ui_dblogincomponent.h" -#include "blackcore/data/globalsetup.h" #include "blackgui/components/dblogincomponent.h" #include "blackgui/guiapplication.h" #include "blackgui/guiutility.h" #include "blackgui/overlaymessagesframe.h" +#include "blackcore/data/globalsetup.h" #include "blackmisc/network/authenticateduser.h" #include "blackmisc/network/url.h" #include "blackmisc/htmlutils.h" #include "blackmisc/logmessage.h" #include "blackmisc/statusmessage.h" #include "blackmisc/verify.h" +#include "blackconfig/buildconfig.h" #include #include @@ -31,6 +32,7 @@ using namespace BlackCore; using namespace BlackCore::Db; using namespace BlackGui; +using namespace BlackConfig; using namespace BlackMisc; using namespace BlackMisc::Network; @@ -64,10 +66,16 @@ namespace BlackGui ui->lbl_DatabaseName->setTextInteractionFlags(Qt::TextBrowserInteraction); ui->lbl_DatabaseName->setOpenExternalLinks(true); - connect(ui->pb_Login, &QPushButton::clicked, this, &CDbLoginComponent::onLoginClicked); + connect(ui->pb_Login, &QPushButton::clicked, this, &CDbLoginComponent::onLoginClicked); connect(ui->pb_Logoff, &QPushButton::clicked, this, &CDbLoginComponent::onLogoffClicked); - connect(&m_loginService, &CDatabaseAuthenticationService::userAuthenticationFinished, this, &CDbLoginComponent::onAuthenticationFinished); connect(ui->le_Password, &QLineEdit::returnPressed, this, &CDbLoginComponent::onLoginClicked); + connect(&m_loginService, &CDatabaseAuthenticationService::userAuthenticationFinished, this, &CDbLoginComponent::onAuthenticationFinished, Qt::QueuedConnection); + + if (CBuildConfig::isLocalDeveloperDebugBuild()) + { + const QString url = sApp->getGlobalSetup().getDbLoginServiceUrl().toQString(); + ui->pb_Login->setToolTip(url); + } // init GUI this->setUserInfo(this->getDbUser()); diff --git a/src/blackgui/components/dblogincomponent.h b/src/blackgui/components/dblogincomponent.h index 4abf0f14f..efc4c7bcf 100644 --- a/src/blackgui/components/dblogincomponent.h +++ b/src/blackgui/components/dblogincomponent.h @@ -29,6 +29,7 @@ namespace BlackGui { /** * Login to DB + * \sa BlackCore::Db::CDatabaseAuthenticationService */ class BLACKGUI_EXPORT CDbLoginComponent : public QFrame, @@ -41,7 +42,7 @@ namespace BlackGui explicit CDbLoginComponent(QWidget *parent = nullptr); //! Destructor - virtual ~CDbLoginComponent(); + virtual ~CDbLoginComponent() override; //! DB user BlackMisc::Network::CAuthenticatedUser getDbUser() const; diff --git a/src/blackmisc/network/role.h b/src/blackmisc/network/role.h index 3a3baadcb..886778514 100644 --- a/src/blackmisc/network/role.h +++ b/src/blackmisc/network/role.h @@ -31,13 +31,13 @@ namespace BlackMisc */ class BLACKMISC_EXPORT CRole : public CValueObject, - public BlackMisc::Db::IDatastoreObjectWithIntegerKey + public Db::IDatastoreObjectWithIntegerKey { public: //! Properties by index enum ColumnIndex { - IndexName = BlackMisc::CPropertyIndex::GlobalIndexCRole, + IndexName = CPropertyIndex::GlobalIndexCRole, IndexDescription };