mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 09:15:34 +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:
@@ -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
|
||||
|
||||
@@ -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::CDbLoginComponent> 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
|
||||
|
||||
@@ -88,47 +88,55 @@
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item row="0" column="1">
|
||||
<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>
|
||||
<item row="5" column="0" colspan="3">
|
||||
<widget class="BlackGui::Components::CDbDebugDatabaseSetup" name="comp_DebugSetup">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</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">
|
||||
<widget class="QLabel" name="lbl_User">
|
||||
<widget class="QLabel" name="lbl_Database">
|
||||
<property name="text">
|
||||
<string>Name:</string>
|
||||
<string>Database:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<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">
|
||||
<item row="3" column="0">
|
||||
<spacer name="hs_Login">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
@@ -144,24 +152,7 @@
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" 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">
|
||||
<item row="6" column="0">
|
||||
<spacer name="vs_FrameLogin">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
@@ -174,6 +165,53 @@
|
||||
</property>
|
||||
</spacer>
|
||||
</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>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -395,7 +433,6 @@ p, li { white-space: pre-wrap; }
|
||||
<tabstops>
|
||||
<tabstop>le_Username</tabstop>
|
||||
<tabstop>le_Password</tabstop>
|
||||
<tabstop>pb_Login</tabstop>
|
||||
<tabstop>le_Name</tabstop>
|
||||
<tabstop>te_Roles</tabstop>
|
||||
<tabstop>le_Info</tabstop>
|
||||
|
||||
Reference in New Issue
Block a user