Changeset 16537


Ignore:
Timestamp:
Aug 12, 2016, 5:11:54 PM (3 years ago)
Author:
dcorreia
Message:

Changed read card logic to depend on button click event.
Added checks to page validation:

  • configuration already exists
  • current card is different from card that was read

Changed user list combobox design.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • internals/2016/linuxloginsmartcardwizard/trunk/proto1/carduser.py

    r16520 r16537  
    11from PyQt5 import QtCore, QtGui, QtWidgets
     2from PyQt5.QtWidgets import QMessageBox
    23import main, config, cardHelper
     4
    35
    46class CardUserPage(QtWidgets.QWizardPage):
     
    810
    911        self.layoutWidget2 = QtWidgets.QWidget(self)
    10         self.layoutWidget2.setGeometry(QtCore.QRect(40, 20, 260, 130))
     12        self.layoutWidget2.setGeometry(QtCore.QRect(40, 20, 260, 150))
    1113        self.layoutWidget2.setObjectName("layoutWidget2")
    1214        self.cardVLayout = QtWidgets.QVBoxLayout(self.layoutWidget2)
     
    2426        self.goodCardLabel = QtWidgets.QLabel(self)
    2527        self.goodCardLabel.setEnabled(True)
    26         self.goodCardLabel.setGeometry(QtCore.QRect(315, 85, 45, 45))
     28        self.goodCardLabel.setGeometry(QtCore.QRect(315, 95, 45, 45))
    2729        self.goodCardLabel.setPixmap(QtGui.QPixmap("img/green-checkmark.png"))
    2830        self.goodCardLabel.setScaledContents(True)
    2931        self.goodCardLabel.setObjectName("goodCardLabel")
    3032
     33        self.readCardButton = QtWidgets.QPushButton(self)
     34        self.readCardButton.setGeometry(QtCore.QRect(280, 35, 150, 30))
     35        self.readCardButton.setText("Read smartcard again")
     36        self.readCardButton.hide()
     37        self.readCardButton.clicked.connect(self.buildCardSubjectInfo)
     38
    3139        self.layoutWidget3 = QtWidgets.QWidget(self)
    32         self.layoutWidget3.setGeometry(QtCore.QRect(40, 170, 230, 80))
     40        self.layoutWidget3.setGeometry(QtCore.QRect(40, 190, 230, 60))
    3341        self.layoutWidget3.setObjectName("layoutWidget3")
    3442        self.userVLayout = QtWidgets.QVBoxLayout(self.layoutWidget3)
     
    4250        self.userListBox.setEditable(False)
    4351        self.userListBox.setObjectName("userListBox")
     52        self.userListBox.setView(QtWidgets.QListView())
     53        self.userListBox.view().setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
     54        self.userListBox.setStyleSheet("QComboBox QAbstractItemView::item { "
     55                                       "min-height: 25px}"
     56                                       "QComboBox { combobox-popup: 0; }")
     57        self.userListBox.setMaxVisibleItems(3)
    4458        self.userVLayout.addWidget(self.userListBox)
    4559
     
    5771        self.cardErrorLabel.setText("Troubleshooting details")
    5872
    59         self.userListBox.currentIndexChanged.connect(self.checkCurrentBoxOption)
    60 
    6173        self.helpMessage = "This is the third screen of the wizard.\n\n" \
    6274                           "The wizard needs you to select a username from the list \n" \
     
    6779
    6880        self.cardSubjectInfo = ""
     81        self.currentCardNumber = QtWidgets.QLabel()
     82        self.currentCardNumber.hide()
    6983
    7084        self.timer = QtCore.QTimer()
    71 
     85        self.messageBox = QtWidgets.QMessageBox()
    7286        self.registerField("username", self.userListBox, "currentText")
    73 
    74     def checkCurrentBoxOption(self):
    75         print("Current option -> ", self.getCurrentBoxOption())
    76         if self.getCurrentBoxOption() != "List of usernames":
    77             self.goodUserLabel.show()
    78         else:
    79             self.goodUserLabel.hide()
    80         self.completeChanged.emit()
     87        self.registerField("cardNumber", self.currentCardNumber, "text")
    8188
    8289    def getCurrentBoxOption(self):
     
    99106                self.cardErrorLabel.setText(self.cardErrorLabel.text() +
    100107                                            "\n\nSmartcard detected.")
     108                cardNumber, fullName = cardHelper.getCardNumber(), cardHelper.getCardFullName()
     109                self.cardErrorLabel.setText(self.cardErrorLabel.text() +
     110                                            "\n\nCard Number: " + cardNumber +
     111                                            "\n\nCard Owner: " + fullName.title())
     112                self.cardSubjectInfo = config.getCardSubject()
    101113                self.cardErrorLabel.repaint()
    102                 self.cardSubjectInfo = config.getCardSubject()
    103                 self.cardErrorLabel.setText(self.cardErrorLabel.text() +
    104                                             "\n\nSmartcard reading finished.")
    105                 if self.hasCardSubjectInfo():
    106                     self.checkCardSubjectInfo()
    107                 else:
    108                     print("Starting timer again...")
    109                     self.timer.singleShot(1000, self.buildCardSubjectInfo)
     114                self.goodCardLabel.show()
     115                self.completeChanged.emit()
    110116            else:
     117                self.goodCardLabel.hide()
     118                self.completeChanged.emit()
    111119                self.cardErrorLabel.setText(self.cardErrorLabel.text() +
    112120                                            "\n\nNo smartcard detected.\n\nPlease insert it in the reader.")
    113                 self.timer.singleShot(1000, self.buildCardSubjectInfo)
    114121        else:
     122            self.goodCardLabel.hide()
     123            self.completeChanged.emit()
    115124            self.cardErrorLabel.setText("No smartcard reader detected")
    116             self.timer.singleShot(1000, self.buildCardSubjectInfo)
     125        self.readCardButton.show()
    117126
    118127    def isComplete(self):
     
    121130    def fillUserListBox(self):
    122131        users = config.listLocalUsers()
    123         self.userListBox.addItem("List of usernames")
    124132        for user in users:
    125133            self.userListBox.addItem(user)
     
    128136        print("Run card+user scripts...")
    129137        self.goodCardLabel.hide()
    130         self.goodUserLabel.hide()
    131138        self.fillUserListBox()
    132139        self.timer.singleShot(1000, self.buildCardSubjectInfo)
    133140
     141    def checkPageValidation(self):
     142        self.currentCardNumber.setText(cardHelper.getCardNumber())
     143        if main.configureUserMapping(self.getCurrentBoxOption(), self.cardSubjectInfo):
     144            return True
     145        else:
     146            self.messageBox.critical(self, "Title", "The chosen configuration already exists.\n\n" +
     147                                     "   Card Number: " + cardHelper.getCardNumber() + "\n" +
     148                                     "   Username: " + self.getCurrentBoxOption() + "\n\n"
     149                                     "Please insert a new card or choose a different username.")
     150            return False
     151
    134152    def validatePage(self):
    135         return main.configureUserMapping(self.getCurrentBoxOption(), self.cardSubjectInfo)
     153        currentCardSubject = config.getCardSubject()
     154        if currentCardSubject == "":
     155            self.buildCardSubjectInfo()
     156            return False
     157        elif currentCardSubject != self.cardSubjectInfo:
     158            message = "The current smartcard inserted in the reader is different \n" \
     159                      "from the one that was read by the wizard.\n\n" \
     160                      "   Current Card Number: " + cardHelper.getCardNumber() + "\n" \
     161                      "   Username: " + self.getCurrentBoxOption() + "\n\n" \
     162                      "Would you like to add this new configuration instead?"
     163            self.buildCardSubjectInfo()
     164            reply = self.messageBox.warning(self, "Title", message, QMessageBox.No, QMessageBox.Yes)
     165            if reply == QMessageBox.Yes:
     166                return self.checkPageValidation()
     167        else:
     168            return self.checkPageValidation()
Note: See TracChangeset for help on using the changeset viewer.