mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-28 11:45:40 +08:00
refs #768, authentication component improved
* access to user object * show database name in UI * init UI with user object at startup
This commit is contained in:
@@ -50,6 +50,17 @@ namespace BlackCore
|
|||||||
this->logoff();
|
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 CDatabaseAuthenticationService::login(const QString &username, const QString &password)
|
||||||
{
|
{
|
||||||
CStatusMessageList msgs;
|
CStatusMessageList msgs;
|
||||||
|
|||||||
@@ -39,6 +39,12 @@ namespace BlackCore
|
|||||||
//! Shutdown
|
//! Shutdown
|
||||||
void gracefulShutdown();
|
void gracefulShutdown();
|
||||||
|
|
||||||
|
//! DB user
|
||||||
|
BlackMisc::Network::CAuthenticatedUser getDbUser() const;
|
||||||
|
|
||||||
|
//! User authenticated
|
||||||
|
bool isUserAuthenticated() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
//! Try to login to authentication web service
|
//! Try to login to authentication web service
|
||||||
BlackMisc::CStatusMessageList login(const QString &id, const QString &password);
|
BlackMisc::CStatusMessageList login(const QString &id, const QString &password);
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ namespace BlackGui
|
|||||||
QFrame(parent),
|
QFrame(parent),
|
||||||
ui(new Ui::CDbLoginComponent)
|
ui(new Ui::CDbLoginComponent)
|
||||||
{
|
{
|
||||||
|
Q_ASSERT_X(sGui, Q_FUNC_INFO, "Missing sGui");
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
this->setModeLogin(true);
|
this->setModeLogin(true);
|
||||||
CUrl url(sGui->getGlobalSetup().getDbHomePageUrl());
|
CUrl url(sGui->getGlobalSetup().getDbHomePageUrl());
|
||||||
@@ -54,16 +55,30 @@ namespace BlackGui
|
|||||||
|
|
||||||
const bool devEnv = sGui->isRunningInDeveloperEnvironment();
|
const bool devEnv = sGui->isRunningInDeveloperEnvironment();
|
||||||
ui->comp_DebugSetup->setVisible(devEnv);
|
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_Login, &QPushButton::clicked, this, &CDbLoginComponent::ps_onLoginClicked);
|
||||||
connect(ui->pb_Logoff, &QPushButton::clicked, this, &CDbLoginComponent::ps_onLogoffClicked);
|
connect(ui->pb_Logoff, &QPushButton::clicked, this, &CDbLoginComponent::ps_onLogoffClicked);
|
||||||
connect(&m_loginService, &CDatabaseAuthenticationService::userAuthenticationFinished, this, &CDbLoginComponent::ps_authenticationFinished);
|
connect(&m_loginService, &CDatabaseAuthenticationService::userAuthenticationFinished, this, &CDbLoginComponent::ps_authenticationFinished);
|
||||||
connect(ui->le_Password, &QLineEdit::returnPressed, this, &CDbLoginComponent::ps_onLoginClicked);
|
connect(ui->le_Password, &QLineEdit::returnPressed, this, &CDbLoginComponent::ps_onLoginClicked);
|
||||||
|
|
||||||
|
// init GUI
|
||||||
|
this->setUserInfo(this->getDbUser());
|
||||||
}
|
}
|
||||||
|
|
||||||
CDbLoginComponent::~CDbLoginComponent()
|
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)
|
void CDbLoginComponent::displayOverlayMessages(const CStatusMessageList &msgs)
|
||||||
{
|
{
|
||||||
if (msgs.isEmpty()) { return; }
|
if (msgs.isEmpty()) { return; }
|
||||||
@@ -97,10 +112,25 @@ namespace BlackGui
|
|||||||
this->setModeLogin(true);
|
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();
|
this->setUserInfo(user);
|
||||||
if (ok)
|
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();
|
CLogMessage(this).info("User authenticated: %1") << user.toQString();
|
||||||
this->setModeLogin(false);
|
this->setModeLogin(false);
|
||||||
@@ -118,15 +148,7 @@ namespace BlackGui
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
this->setModeLogin(true);
|
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
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -23,7 +23,6 @@
|
|||||||
|
|
||||||
namespace BlackMisc { namespace Network { class CAuthenticatedUser; } }
|
namespace BlackMisc { namespace Network { class CAuthenticatedUser; } }
|
||||||
namespace Ui { class CDbLoginComponent; }
|
namespace Ui { class CDbLoginComponent; }
|
||||||
|
|
||||||
namespace BlackGui
|
namespace BlackGui
|
||||||
{
|
{
|
||||||
namespace Components
|
namespace Components
|
||||||
@@ -42,6 +41,12 @@ namespace BlackGui
|
|||||||
//! Destructor
|
//! Destructor
|
||||||
~CDbLoginComponent();
|
~CDbLoginComponent();
|
||||||
|
|
||||||
|
//! DB user
|
||||||
|
BlackMisc::Network::CAuthenticatedUser getDbUser() const;
|
||||||
|
|
||||||
|
//! Is user authenticated?
|
||||||
|
bool isUserAuthenticated() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QScopedPointer<Ui::CDbLoginComponent> ui;
|
QScopedPointer<Ui::CDbLoginComponent> ui;
|
||||||
BlackCore::Db::CDatabaseAuthenticationService m_loginService {this}; //!< login service
|
BlackCore::Db::CDatabaseAuthenticationService m_loginService {this}; //!< login service
|
||||||
@@ -52,6 +57,9 @@ namespace BlackGui
|
|||||||
//! Mode login
|
//! Mode login
|
||||||
void setModeLogin(bool modeLogin);
|
void setModeLogin(bool modeLogin);
|
||||||
|
|
||||||
|
//! Set the user fields
|
||||||
|
void setUserInfo(const BlackMisc::Network::CAuthenticatedUser &user);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
//! Login
|
//! Login
|
||||||
void ps_onLoginClicked();
|
void ps_onLoginClicked();
|
||||||
@@ -60,7 +68,7 @@ namespace BlackGui
|
|||||||
void ps_onLogoffClicked();
|
void ps_onLogoffClicked();
|
||||||
|
|
||||||
//! User authentication completed
|
//! 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
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -88,47 +88,55 @@
|
|||||||
<property name="spacing">
|
<property name="spacing">
|
||||||
<number>6</number>
|
<number>6</number>
|
||||||
</property>
|
</property>
|
||||||
<item row="0" column="1">
|
<item row="5" column="0" colspan="3">
|
||||||
<widget class="QLineEdit" name="le_Username">
|
<widget class="BlackGui::Components::CDbDebugDatabaseSetup" name="comp_DebugSetup">
|
||||||
<property name="maxLength">
|
<property name="minimumSize">
|
||||||
<number>40</number>
|
<size>
|
||||||
</property>
|
<width>0</width>
|
||||||
<property name="placeholderText">
|
<height>40</height>
|
||||||
<string>user name or id</string>
|
</size>
|
||||||
</property>
|
|
||||||
<property name="clearButtonEnabled">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="3" column="2">
|
||||||
|
<widget class="QWidget" name="wi_Button" native="true">
|
||||||
|
<layout class="QHBoxLayout" name="hl_LoginFrame">
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>2</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>2</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>2</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>2</number>
|
||||||
|
</property>
|
||||||
|
<item alignment="Qt::AlignRight">
|
||||||
|
<widget class="QPushButton" name="pb_Login">
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>150</width>
|
||||||
|
<height>16777215</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>login</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QLabel" name="lbl_User">
|
<widget class="QLabel" name="lbl_Database">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Name:</string>
|
<string>Database:</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="3" column="0">
|
||||||
<widget class="QLineEdit" name="le_Password">
|
|
||||||
<property name="echoMode">
|
|
||||||
<enum>QLineEdit::PasswordEchoOnEdit</enum>
|
|
||||||
</property>
|
|
||||||
<property name="placeholderText">
|
|
||||||
<string>password</string>
|
|
||||||
</property>
|
|
||||||
<property name="clearButtonEnabled">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="1">
|
|
||||||
<widget class="QPushButton" name="pb_Login">
|
|
||||||
<property name="text">
|
|
||||||
<string>login</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="0">
|
|
||||||
<spacer name="hs_Login">
|
<spacer name="hs_Login">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
@@ -144,24 +152,7 @@
|
|||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0">
|
<item row="6" column="0">
|
||||||
<widget class="QLabel" name="lbl_Password">
|
|
||||||
<property name="text">
|
|
||||||
<string>Password:</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="3" column="0" colspan="2">
|
|
||||||
<widget class="BlackGui::Components::CDbDebugDatabaseSetup" name="comp_DebugSetup">
|
|
||||||
<property name="minimumSize">
|
|
||||||
<size>
|
|
||||||
<width>0</width>
|
|
||||||
<height>40</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="4" column="0">
|
|
||||||
<spacer name="vs_FrameLogin">
|
<spacer name="vs_FrameLogin">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Vertical</enum>
|
<enum>Qt::Vertical</enum>
|
||||||
@@ -174,6 +165,53 @@
|
|||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QLabel" name="lbl_User">
|
||||||
|
<property name="text">
|
||||||
|
<string>Name:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0">
|
||||||
|
<widget class="QLabel" name="lbl_Password">
|
||||||
|
<property name="text">
|
||||||
|
<string>Password:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="2">
|
||||||
|
<widget class="QLineEdit" name="le_Password">
|
||||||
|
<property name="echoMode">
|
||||||
|
<enum>QLineEdit::PasswordEchoOnEdit</enum>
|
||||||
|
</property>
|
||||||
|
<property name="placeholderText">
|
||||||
|
<string>password</string>
|
||||||
|
</property>
|
||||||
|
<property name="clearButtonEnabled">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="2">
|
||||||
|
<widget class="QLineEdit" name="le_Username">
|
||||||
|
<property name="maxLength">
|
||||||
|
<number>40</number>
|
||||||
|
</property>
|
||||||
|
<property name="placeholderText">
|
||||||
|
<string>user name or id</string>
|
||||||
|
</property>
|
||||||
|
<property name="clearButtonEnabled">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="2">
|
||||||
|
<widget class="QLabel" name="lbl_DatabaseName">
|
||||||
|
<property name="text">
|
||||||
|
<string>Database URL will go here</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@@ -395,7 +433,6 @@ p, li { white-space: pre-wrap; }
|
|||||||
<tabstops>
|
<tabstops>
|
||||||
<tabstop>le_Username</tabstop>
|
<tabstop>le_Username</tabstop>
|
||||||
<tabstop>le_Password</tabstop>
|
<tabstop>le_Password</tabstop>
|
||||||
<tabstop>pb_Login</tabstop>
|
|
||||||
<tabstop>le_Name</tabstop>
|
<tabstop>le_Name</tabstop>
|
||||||
<tabstop>te_Roles</tabstop>
|
<tabstop>te_Roles</tabstop>
|
||||||
<tabstop>le_Info</tabstop>
|
<tabstop>le_Info</tabstop>
|
||||||
|
|||||||
Reference in New Issue
Block a user