diff --git a/src/blackcore/db/databaseauthentication.cpp b/src/blackcore/db/databaseauthentication.cpp index 20ba89ac5..76aa9edeb 100644 --- a/src/blackcore/db/databaseauthentication.cpp +++ b/src/blackcore/db/databaseauthentication.cpp @@ -50,6 +50,17 @@ namespace BlackCore this->logoff(); } + CAuthenticatedUser CDatabaseAuthenticationService::getDbUser() const + { + return this->m_swiftDbUser.get(); + } + + bool CDatabaseAuthenticationService::isUserAuthenticated() const + { + const CAuthenticatedUser user(this->getDbUser()); + return user.isAuthenticated(); + } + CStatusMessageList CDatabaseAuthenticationService::login(const QString &username, const QString &password) { CStatusMessageList msgs; diff --git a/src/blackcore/db/databaseauthentication.h b/src/blackcore/db/databaseauthentication.h index 48e7d36e3..3c6f5519d 100644 --- a/src/blackcore/db/databaseauthentication.h +++ b/src/blackcore/db/databaseauthentication.h @@ -39,6 +39,12 @@ namespace BlackCore //! Shutdown void gracefulShutdown(); + //! DB user + BlackMisc::Network::CAuthenticatedUser getDbUser() const; + + //! User authenticated + bool isUserAuthenticated() const; + public slots: //! Try to login to authentication web service BlackMisc::CStatusMessageList login(const QString &id, const QString &password); diff --git a/src/blackgui/components/dblogincomponent.cpp b/src/blackgui/components/dblogincomponent.cpp index 12c33a201..465996f63 100644 --- a/src/blackgui/components/dblogincomponent.cpp +++ b/src/blackgui/components/dblogincomponent.cpp @@ -42,6 +42,7 @@ namespace BlackGui QFrame(parent), ui(new Ui::CDbLoginComponent) { + Q_ASSERT_X(sGui, Q_FUNC_INFO, "Missing sGui"); ui->setupUi(this); this->setModeLogin(true); CUrl url(sGui->getGlobalSetup().getDbHomePageUrl()); @@ -54,16 +55,30 @@ namespace BlackGui const bool devEnv = sGui->isRunningInDeveloperEnvironment(); ui->comp_DebugSetup->setVisible(devEnv); + ui->lbl_DatabaseName->setText(sGui->getGlobalSetup().getDbHomePageUrl().toQString()); connect(ui->pb_Login, &QPushButton::clicked, this, &CDbLoginComponent::ps_onLoginClicked); connect(ui->pb_Logoff, &QPushButton::clicked, this, &CDbLoginComponent::ps_onLogoffClicked); connect(&m_loginService, &CDatabaseAuthenticationService::userAuthenticationFinished, this, &CDbLoginComponent::ps_authenticationFinished); connect(ui->le_Password, &QLineEdit::returnPressed, this, &CDbLoginComponent::ps_onLoginClicked); + + // init GUI + this->setUserInfo(this->getDbUser()); } CDbLoginComponent::~CDbLoginComponent() { } + CAuthenticatedUser CDbLoginComponent::getDbUser() const + { + return this->m_loginService.getDbUser(); + } + + bool CDbLoginComponent::isUserAuthenticated() const + { + return this->m_loginService.isUserAuthenticated(); + } + void CDbLoginComponent::displayOverlayMessages(const CStatusMessageList &msgs) { if (msgs.isEmpty()) { return; } @@ -97,10 +112,25 @@ namespace BlackGui this->setModeLogin(true); } - void CDbLoginComponent::ps_authenticationFinished(const CAuthenticatedUser &user, const CStatusMessageList &status) + void CDbLoginComponent::ps_authenticationFinished(const CAuthenticatedUser &user, const CStatusMessageList &statusMsgs) { - bool ok = !status.hasErrorMessages(); - if (ok) + this->setUserInfo(user); + if (statusMsgs.hasWarningOrErrorMessages()) + { + this->displayOverlayMessages(statusMsgs); + CLogMessage::preformatted(statusMsgs); + ui->le_Info->setText("Authentication failed, see hints"); + } + } + + void CDbLoginComponent::setModeLogin(bool modeLogin) + { + ui->sw_LoginLogoff->setCurrentIndex(modeLogin ? 0 : 1); + } + + void CDbLoginComponent::setUserInfo(const CAuthenticatedUser &user) + { + if (user.isAuthenticated()) { CLogMessage(this).info("User authenticated: %1") << user.toQString(); this->setModeLogin(false); @@ -118,15 +148,7 @@ namespace BlackGui else { this->setModeLogin(true); - this->displayOverlayMessages(status); - CLogMessage::preformatted(status); - ui->le_Info->setText("Authentication failed, see hints"); } } - - void CDbLoginComponent::setModeLogin(bool modeLogin) - { - ui->sw_LoginLogoff->setCurrentIndex(modeLogin ? 0 : 1); - } } // ns } // ns diff --git a/src/blackgui/components/dblogincomponent.h b/src/blackgui/components/dblogincomponent.h index 6e1bf6a77..2442d7293 100644 --- a/src/blackgui/components/dblogincomponent.h +++ b/src/blackgui/components/dblogincomponent.h @@ -23,7 +23,6 @@ namespace BlackMisc { namespace Network { class CAuthenticatedUser; } } namespace Ui { class CDbLoginComponent; } - namespace BlackGui { namespace Components @@ -42,6 +41,12 @@ namespace BlackGui //! Destructor ~CDbLoginComponent(); + //! DB user + BlackMisc::Network::CAuthenticatedUser getDbUser() const; + + //! Is user authenticated? + bool isUserAuthenticated() const; + private: QScopedPointer ui; BlackCore::Db::CDatabaseAuthenticationService m_loginService {this}; //!< login service @@ -52,6 +57,9 @@ namespace BlackGui //! Mode login void setModeLogin(bool modeLogin); + //! Set the user fields + void setUserInfo(const BlackMisc::Network::CAuthenticatedUser &user); + private slots: //! Login void ps_onLoginClicked(); @@ -60,7 +68,7 @@ namespace BlackGui void ps_onLogoffClicked(); //! User authentication completed - void ps_authenticationFinished(const BlackMisc::Network::CAuthenticatedUser &user, const BlackMisc::CStatusMessageList &status); + void ps_authenticationFinished(const BlackMisc::Network::CAuthenticatedUser &user, const BlackMisc::CStatusMessageList &statusMsgs); }; } // ns } // ns diff --git a/src/blackgui/components/dblogincomponent.ui b/src/blackgui/components/dblogincomponent.ui index e736c7c94..729e0d36c 100644 --- a/src/blackgui/components/dblogincomponent.ui +++ b/src/blackgui/components/dblogincomponent.ui @@ -88,47 +88,55 @@ 6 - - - - 40 - - - user name or id - - - true + + + + + 0 + 40 + + + + + + 2 + + + 2 + + + 2 + + + 2 + + + + + + 150 + 16777215 + + + + login + + + + + + - + - Name: + Database: - - - - QLineEdit::PasswordEchoOnEdit - - - password - - - true - - - - - - - login - - - - + Qt::Horizontal @@ -144,24 +152,7 @@ - - - - Password: - - - - - - - - 0 - 40 - - - - - + Qt::Vertical @@ -174,6 +165,53 @@ + + + + Name: + + + + + + + Password: + + + + + + + QLineEdit::PasswordEchoOnEdit + + + password + + + true + + + + + + + 40 + + + user name or id + + + true + + + + + + + Database URL will go here + + + @@ -395,7 +433,6 @@ p, li { white-space: pre-wrap; } le_Username le_Password - pb_Login le_Name te_Roles le_Info