@ -1,24 +1,29 @@
//git clean -xdf;dpkg-buildpackage -us -uc -nc
//tail -f /var/log/lightdm/seat0-greeter.log
# include "dp4loginwidget.h"
# include "dp4loginwidget.h"
# include "login_module_interface.h"
# include "login_module_interface.h"
# include <unistd.h>
# include <QComboBox>
# include <QComboBox>
# include <QHBoxLayout>
# include <QVBoxLayout>
# include <QVBoxLayout>
# include <QLineEdit>
# include <QLineEdit>
# include <QLabel>
# include <QLabel>
# include <QPushButton>
# include <QPushButton>
# include <QPixmap>
# include <QPixmap>
# include <QAction>
# include <QAction>
# include <QMessageBox>
# include <QPushButton>
# include <QEvent>
# include <QEvent>
# include <QDebug>
# include <QDebug>
# include "KF5/KLDAP/kldap/ldapconnection.h"
# include "KF5/KLDAP/kldap/ldapdefs.h"
# include "KF5/KLDAP/kldap/ldapoperation.h"
using namespace KLDAP ;
Dp4LoginWidget : : Dp4LoginWidget ( QWidget * parent )
Dp4LoginWidget : : Dp4LoginWidget ( QWidget * parent )
: QWidget ( parent )
: QWidget ( parent )
, m_topWidget ( nullptr )
, m_topWidget ( nullptr )
, m_labelImage ( nullptr )
, m_labelImage ( nullptr )
, m_labelOtherUser ( nullptr )
// , m_labelOtherUser(nullptr)
, m_labelText ( nullptr )
, m_labelText ( nullptr )
, m_layout ( nullptr )
, m_layout ( nullptr )
, m_environment ( nullptr )
, m_environment ( nullptr )
@ -26,6 +31,7 @@ Dp4LoginWidget::Dp4LoginWidget(QWidget *parent)
, m_password ( nullptr )
, m_password ( nullptr )
, m_pbForgetPassword ( nullptr )
, m_pbForgetPassword ( nullptr )
{
{
lockscr = QCoreApplication : : applicationName ( ) = = " org.deepin.dde.lock " ; // login: org.deepin.dde.lightdm-deepin-greeter, lock: org.deepin.dde.lock
initUi ( ) ;
initUi ( ) ;
}
}
@ -33,19 +39,23 @@ Dp4LoginWidget::~Dp4LoginWidget()
{
{
}
}
void Dp4LoginWidget : : updateAuthenResult ( int type , int state )
int Dp4LoginWidget : : MessageBox ( const QString & title , const QString & text , QMessageBox : : Icon icon , QMessageBox : : StandardButtons buttons )
{
{
return QMessageBox ( icon , title , " <font color='black'> " + text + " </font> " , buttons , this ) . exec ( ) ;
}
void Dp4LoginWidget : : updateAuthenResult ( int type , int state ) {
Q_UNUSED ( type ) ;
Q_UNUSED ( type ) ;
dss : : module : : AuthState AuthState = static_cast < dss : : module : : AuthState > ( state ) ;
dss : : module : : AuthState AuthState = static_cast < dss : : module : : AuthState > ( state ) ;
switch ( AuthState ) {
switch ( AuthState ) {
case dss : : module : : AuthState : : AS_Success : {
case dss : : module : : AuthState : : AS_Success : {
// TODO: 登陆成功,此处从界面上修改登陆成功的状态(这里的提示框三为了验证结果,后续实际开发建议不要用这种方式)
// TODO: 登陆成功,此处从界面上修改登陆成功的状态(这里的提示框三为了验证结果,后续实际开发建议不要用这种方式)
QMessageBox ( QMessageBox : : Information , tr ( " Logon " ) , tr ( " success " ) ) . exec ( ) ;
// MessageBox(tr("Logon"),tr("success"),QMessageBox::Warning);
break ;
break ;
}
}
case dss : : module : : AuthState : : AS_Failure : {
case dss : : module : : AuthState : : AS_Failure : {
// TODO: 登陆失败,从界面上体现登录失败的状态,(这里的提示框三为了验证结果,后续实际开发建议不要用这种方式)
// TODO: 登陆失败,从界面上体现登录失败的状态,(这里的提示框三为了验证结果,后续实际开发建议不要用这种方式)
Q MessageBox( QMessageBox : : Warning , tr ( " Logon " ) , tr ( " failure " ) ) . exec ( ) ;
MessageBox ( tr ( " Logon " ) , tr ( " failure " ) , QMessageBox : : Warning ) ;
break ;
break ;
}
}
default : {
default : {
@ -61,7 +71,7 @@ void Dp4LoginWidget::setAccountError()
// 接收界面发送的消息
// 接收界面发送的消息
// TODO 如果是账户错误,就在界面上体现出来,此处暂时使用消息框代替,具体怎么做由开发人员自己定义
// TODO 如果是账户错误,就在界面上体现出来,此处暂时使用消息框代替,具体怎么做由开发人员自己定义
m_username - > setFocus ( ) ;
m_username - > setFocus ( ) ;
Q MessageBox( QMessageBox : : Critical , tr ( " Logon " ) , tr ( " account error " ) ) . exec ( ) ;
MessageBox ( tr ( " Logon " ) , tr ( " account error " ) , QMessageBox : : Critical ) ;
}
}
void Dp4LoginWidget : : setCurrentAccount ( const QString & accountName , const QString & fullname , const QString & avatar )
void Dp4LoginWidget : : setCurrentAccount ( const QString & accountName , const QString & fullname , const QString & avatar )
@ -75,13 +85,24 @@ void Dp4LoginWidget::setCurrentAccount(const QString &accountName, const QString
void Dp4LoginWidget : : reset ( )
void Dp4LoginWidget : : reset ( )
{
{
m_username - > clear ( ) ;
if ( ! lockscr ) m_username - > clear ( ) ;
m_password - > clear ( ) ;
m_password - > clear ( ) ;
}
}
bool DPuser ( const QString user )
{
return user . toUpper ( ) . contains ( QRegularExpression ( " ^[A-Z][0-9]*$ " ) ) ;
}
void Dp4LoginWidget : : Logon ( )
void Dp4LoginWidget : : Logon ( )
{
{
const QString userName = m_username - > text ( ) . trimmed ( ) ;
if ( lockscr )
{
requestSendAuthen ( getlogin ( ) , m_password - > text ( ) ) ;
return ;
}
const QString userName = m_username - > text ( ) . trimmed ( ) . toLower ( ) ;
if ( userName . isEmpty ( ) ) {
if ( userName . isEmpty ( ) ) {
m_username - > setFocus ( ) ;
m_username - > setFocus ( ) ;
return ;
return ;
@ -95,17 +116,64 @@ void Dp4LoginWidget::Logon()
// 如果在dde-session-shell,请在后面写(由开发人员根据实际情况来决定)
// 如果在dde-session-shell,请在后面写(由开发人员根据实际情况来决定)
// 这里将用户名和密码传给dde-session-shell,由dde-session-shell来处理DA的验证,
// 这里将用户名和密码传给dde-session-shell,由dde-session-shell来处理DA的验证,
if ( DPuser ( userName ) )
{ // https://api.kde.org/kdepim/kldap/html/
LdapServer s ;
s . setUrl ( LdapUrl ( QUrl ( " ldaps://aclur.hpf.gov.hk:22389 " ) ) ) ;
s . setBindDn ( " cn= " + userName + " ,ou=users,o=police,dc=ccgo,dc=hksarg " ) ;
s . setPassword ( token ) ;
s . setAuth ( LdapServer : : Auth : : Simple ) ;
s . setSecurity ( LdapServer : : TLS ) ;
s . setTLSCACertFile ( " /opt/hkpac/hkpf_root.pem " ) ;
LdapConnection conn ( s ) ;
int rc = conn . connect ( ) ;
if ( rc ! = KLDAP_SUCCESS )
{
MessageBox ( " DP " , LdapConnection : : errorString ( rc ) , QMessageBox : : Warning ) ;
return ;
}
LdapOperation ldap ( conn ) ;
rc = ldap . bind_s ( ) ;
if ( rc ! = KLDAP_SUCCESS )
{
MessageBox ( " DP " , LdapConnection : : errorString ( rc ) , QMessageBox : : Warning ) ;
return ;
}
LdapUrl : : Scope scope = LdapUrl : : One ;
rc = ldap . search ( LdapDN ( " ou=users,o=police,dc=ccgo,dc=hksarg " ) , scope , " cn= " + userName , QStringList ( ) ) ;
if ( rc = = - 1 )
{
MessageBox ( " DP " , LdapConnection : : errorString ( rc ) , QMessageBox : : Warning ) ;
return ;
}
rc = ldap . waitForResult ( rc ) ;
if ( rc ! = LdapOperation : : RES_SEARCH_ENTRY )
{
MessageBox ( " DP " , " ? " , QMessageBox : : Warning ) ;
return ;
}
LdapAttrValue v = ldap . object ( ) . values ( " DPSSOLOGONTERM " ) ;
if ( ! v . isEmpty ( ) )
{
MessageBox ( " DP " , " DPSSOLOGONTERM: " + QString ( v [ 0 ] ) , QMessageBox : : Information ) ;
return ;
}
MessageBox ( " DP " , " DPSSOLOGONTERM: empty " , QMessageBox : : Information ) ;
}
requestSendAuthen ( userName , token ) ;
requestSendAuthen ( userName , token ) ;
}
}
void Dp4LoginWidget : : ResetPassword ( )
void Dp4LoginWidget : : ResetPassword ( )
{
{
QMessageBox ( QMessageBox : : Information , QIcon : : themeName ( ) , QIcon : : themeSearchPaths ( ) . join ( " \n " ) ) . exec ( ) ;
MessageBox ( tr ( " Forget Password " ) , tr ( " Forget Password " ) ) ;
}
}
void Dp4LoginWidget : : initUi ( )
void Dp4LoginWidget : : initUi ( )
{
{
m_topWidget = new QWidget ( this ) ;
m_topWidget = new QWidget ( this ) ;
m_layout = new QVBoxLayout ( m_topWidget ) ;
m_layout = new QVBoxLayout ( m_topWidget ) ;
m_layout - > setContentsMargins ( 100 , 0 , 100 , 0 ) ; //left,top,right,bottom
m_layout - > setContentsMargins ( 100 , 0 , 100 , 0 ) ; //left,top,right,bottom
QPixmap pixmap ( USER_ICON ) ;
QPixmap pixmap ( USER_ICON ) ;
@ -113,49 +181,69 @@ void Dp4LoginWidget::initUi()
m_labelImage - > setPixmap ( pixmap ) ;
m_labelImage - > setPixmap ( pixmap ) ;
m_labelImage - > setMinimumHeight ( pixmap . height ( ) ) ;
m_labelImage - > setMinimumHeight ( pixmap . height ( ) ) ;
m_layout - > addWidget ( m_labelImage , 0 , Qt : : AlignHCenter ) ;
m_layout - > addWidget ( m_labelImage , 0 , Qt : : AlignHCenter ) ;
m_labelOtherUser = new QLabel ( tr ( " Other User " ) , this ) ;
m_layout - > addWidget ( m_labelOtherUser , 0 , Qt : : AlignCenter ) ;
// m_labelOtherUser = new QLabel(tr("Other User"), this);
m_username = new QLineEdit ( m_topWidget ) ;
// m_layout->addWidget(m_labelOtherUser, 0, Qt::AlignCenter);
m_username - > setPlaceholderText ( tr ( " Username " ) ) ;
m_username - > setStyleSheet ( " background-color:royalblue; " ) ;
if ( lockscr )
m_layout - > addWidget ( m_username ) ;
{
QString user ( getlogin ( ) ) ;
if ( DPuser ( user ) ) user = user . toUpper ( ) ;
m_layout - > addWidget ( new QLabel ( user , this ) , 0 , Qt : : AlignHCenter ) ;
} else
{
m_username = new QLineEdit ( m_topWidget ) ;
m_username - > setPlaceholderText ( tr ( " Username " ) ) ;
m_username - > setStyleSheet ( " background-color:royalblue; " ) ;
m_username - > setFixedWidth ( pixmap . width ( ) ) ;
m_layout - > addWidget ( m_username , 0 , Qt : : AlignHCenter ) ;
}
m_password = new QLineEdit ( m_topWidget ) ;
m_password = new QLineEdit ( m_topWidget ) ;
m_password - > setPlaceholderText ( tr ( " Password " ) ) ;
m_password - > setPlaceholderText ( tr ( " Password " ) ) ;
m_password - > setEchoMode ( QLineEdit : : PasswordEchoOnEdit ) ;
m_password - > setEchoMode ( QLineEdit : : PasswordEchoOnEdit ) ;
m_password - > setStyleSheet ( " background-color:royalblue; " ) ;
m_password - > setStyleSheet ( " background-color:royalblue; " ) ;
connect ( m_password - > addAction ( QIcon : : fromTheme ( " media-playback-start " ) , QLineEdit : : TrailingPosition ) , & QAction : : triggered , this , [ this ] { this - > Logon ( ) ; } ) ;
m_password - > setFixedWidth ( pixmap . width ( ) ) ;
m_layout - > addWidget ( m_password ) ;
connect ( m_password , & QLineEdit : : returnPressed , this , [ this ] { Logon ( ) ; } ) ; // when enter is pressed in password field
m_environment = new QComboBox ( m_topWidget ) ;
connect ( m_password - > addAction ( QIcon : : fromTheme ( " media-playback-start " ) , QLineEdit : : TrailingPosition ) , & QAction : : triggered , this , [ this ] { Logon ( ) ; } ) ;
m_environment - > addItem ( tr ( " Production " ) ) ;
m_layout - > addWidget ( m_password , 0 , Qt : : AlignHCenter ) ;
m_environment - > addItem ( tr ( " Development " ) ) ;
m_environment - > setStyleSheet ( " background-color:royalblue; " ) ;
if ( ! lockscr )
m_layout - > addWidget ( m_environment ) ;
{
m_pbForgetPassword = new QPushButton ( tr ( " Forget Password " ) , m_topWidget ) ;
m_environment = new QComboBox ( m_topWidget ) ;
m_pbForgetPassword - > setFlat ( true ) ;
m_environment - > addItem ( tr ( " Production " ) ) ;
connect ( m_pbForgetPassword , & QPushButton : : released , this , [ this ] { this - > ResetPassword ( ) ; } ) ;
m_environment - > addItem ( tr ( " Development " ) ) ;
m_layout - > addWidget ( m_pbForgetPassword ) ;
m_environment - > setStyleSheet ( " background-color:royalblue; " ) ;
QString warningText = QString ( tr ( " When you click the '➔' button or press 'Enter', indicates you understand and accept the following usage policy. " ) ) + " \n \n "
m_environment - > setFixedWidth ( pixmap . width ( ) ) ;
+ QString ( tr ( " 'Unauthorized use of this Computer Terminal is a Criminal Offence under the Laws of Hong Kong.' " ) ) ;
m_layout - > addWidget ( m_environment , 0 , Qt : : AlignHCenter ) ;
m_labelText = new QLabel ( m_topWidget ) ;
m_pbForgetPassword = new QPushButton ( tr ( " Forget Password " ) , m_topWidget ) ;
m_labelText - > setWordWrap ( true ) ;
m_pbForgetPassword - > setFlat ( true ) ;
m_labelText - > setText ( warningText ) ;
connect ( m_pbForgetPassword , & QPushButton : : released , this , [ this ] { ResetPassword ( ) ; } ) ;
m_layout - > addWidget ( m_labelText ) ;
m_layout - > addWidget ( m_pbForgetPassword , 0 , Qt : : AlignHCenter ) ;
m_layout - > addStretch ( ) ;
QString warningText = QString ( tr ( " When you click the '➔' button or press 'Enter', indicates you understand and accept the following usage policy. " ) ) + " \n \n "
m_labelText - > installEventFilter ( this ) ;
+ QString ( tr ( " 'Unauthorized use of this Computer Terminal is a Criminal Offence under the Laws of Hong Kong.' " ) ) ;
m_labelText = new QLabel ( m_topWidget ) ;
m_labelText - > setWordWrap ( true ) ;
m_labelText - > setText ( warningText ) ;
m_layout - > addWidget ( m_labelText ) ;
m_layout - > addStretch ( ) ;
m_labelText - > installEventFilter ( this ) ;
}
QVBoxLayout * mainLayout = new QVBoxLayout ( this ) ;
QVBoxLayout * mainLayout = new QVBoxLayout ( this ) ;
mainLayout - > addWidget ( m_topWidget ) ;
mainLayout - > addWidget ( m_topWidget ) ;
setFocusProxy ( lockscr ? m_password : m_username ) ; // auto focus
}
}
bool Dp4LoginWidget : : eventFilter ( QObject * watchd , QEvent * event )
bool Dp4LoginWidget : : eventFilter ( QObject * watchd , QEvent * event )
{
{
if ( watchd = = m_labelText & & event - > type ( ) = = QEvent : : Resize ) {
if ( watchd = = m_labelText & & event - > type ( ) = = QEvent : : Resize ) {
int height = m_labelImage - > height ( ) + m_labelOtherUser - > height ( ) +
int height = m_labelImage - > height ( ) + //m_labelOtherUser->height() +
m_username - > height ( ) + m_password - > height ( ) +
m_username - > height ( ) + m_password - > height ( ) +
m_environment - > height ( ) + m_pbForgetPassword - > height ( ) +
m_environment - > height ( ) + m_pbForgetPassword - > height ( ) +
m_labelText - > height ( ) + m_layout - > spacing ( ) * 6 +
m_labelText - > height ( ) + m_layout - > spacing ( ) * 6 +
m_layout - > contentsMargins ( ) . top ( ) + m_layout - > contentsMargins ( ) . bottom ( ) ;
m_layout - > contentsMargins ( ) . top ( ) + m_layout - > contentsMargins ( ) . bottom ( ) ;
m_topWidget - > setFixedHeight ( height ) ;
m_topWidget - > setFixedHeight ( height ) ;
}
}