src/eric7/WebBrowser/WebAuth/Fido2PinDialog.py

branch
eric7
changeset 10856
b19cefceca15
parent 10854
30c45bd597e6
child 11090
f5f5f5803935
equal deleted inserted replaced
10855:9082eb8f6571 10856:b19cefceca15
29 class Fido2PinDialog(QDialog, Ui_Fido2PinDialog): 29 class Fido2PinDialog(QDialog, Ui_Fido2PinDialog):
30 """ 30 """
31 Class implementing a dialog to enter the current and potentially new PIN. 31 Class implementing a dialog to enter the current and potentially new PIN.
32 """ 32 """
33 33
34 def __init__(self, mode, title, message, minLength, parent=None): 34 def __init__(self, mode, title, message, minLength, retries, parent=None):
35 """ 35 """
36 Constructor 36 Constructor
37 37
38 @param mode mode of the dialog 38 @param mode mode of the dialog
39 @type Fido2PinDialogMode 39 @type Fido2PinDialogMode
40 @param title header title to be shown 40 @param title header title to be shown
41 @type str 41 @type str
42 @param message more decriptive text to be shown 42 @param message more decriptive text to be shown
43 @type str 43 @type str
44 @param minLength minimum PIN length 44 @param minLength minimum PIN length
45 @type int
46 @param retries number of attempts remaining before the security key get locked
45 @type int 47 @type int
46 @param parent reference to the parent widget (defaults to None) 48 @param parent reference to the parent widget (defaults to None)
47 @type QWidget (optional) 49 @type QWidget (optional)
48 """ 50 """
49 super().__init__(parent) 51 super().__init__(parent)
61 self.headerLabel.setVisible(False) 63 self.headerLabel.setVisible(False)
62 if message: 64 if message:
63 self.descriptionLabel.setText(message) 65 self.descriptionLabel.setText(message)
64 else: 66 else:
65 self.descriptionLabel.setVisible(False) 67 self.descriptionLabel.setVisible(False)
68 if self.__mode == Fido2PinDialogMode.SET:
69 self.remainingWidget.setVisible(False)
70 else:
71 self.remainingWidget.setVisible(True)
72 self.remainingLabel.setText(str(retries))
66 self.pinErrorLabel.setVisible(False) 73 self.pinErrorLabel.setVisible(False)
67 74
68 if mode == Fido2PinDialogMode.GET: 75 if mode == Fido2PinDialogMode.GET:
69 self.newPinGroupBox.setVisible(False) 76 self.newPinGroupBox.setVisible(False)
70 elif mode == Fido2PinDialogMode.SET: 77 elif mode == Fido2PinDialogMode.SET:
89 Appropriate error messages are shown in case of issues and the state of 96 Appropriate error messages are shown in case of issues and the state of
90 the OK button is set accordingly. 97 the OK button is set accordingly.
91 """ 98 """
92 messages = [] 99 messages = []
93 100
94 if (
95 self.__mode in (Fido2PinDialogMode.GET, Fido2PinDialogMode.CHANGE)
96 and not self.pinEdit.text()
97 ):
98 messages.append(self.tr("PIN must not be empty."))
99 if self.__mode in (Fido2PinDialogMode.SET, Fido2PinDialogMode.CHANGE): 101 if self.__mode in (Fido2PinDialogMode.SET, Fido2PinDialogMode.CHANGE):
100 if len(self.newPinEdit.text()) < self.__minLength: 102 if len(self.newPinEdit.text()) < self.__minLength:
101 messages.append( 103 messages.append(
102 self.tr("New PIN is TOO short (minimum length: {0}).").format( 104 self.tr("New PIN is too short (minimum length: {0}).").format(
103 self.__minLength 105 self.__minLength
104 ) 106 )
105 ) 107 )
106 if ( 108 if (
107 self.confirmNewPinEdit.isVisible() 109 self.confirmNewPinEdit.isVisible()
131 self.pinErrorLabel.setVisible(False) 133 self.pinErrorLabel.setVisible(False)
132 else: 134 else:
133 if len(errorMessages) == 1: 135 if len(errorMessages) == 1:
134 msg = errorMessages[0] 136 msg = errorMessages[0]
135 else: 137 else:
136 msg = "<ul><li>{0}</li></ul>".format("</li><li>".join(errorMessages)) 138 msg = "- {0}".format("\n- ".join(errorMessages))
137 self.pinErrorLabel.setText(msg) 139 self.pinErrorLabel.setText(msg)
138 self.pinErrorLabel.setVisible(True) 140 self.pinErrorLabel.setVisible(True)
139 141
140 self.adjustSize() 142 self.adjustSize()
141 143
167 self.newPinEdit.setEchoMode(QLineEdit.EchoMode.Normal) 169 self.newPinEdit.setEchoMode(QLineEdit.EchoMode.Normal)
168 else: 170 else:
169 self.newPinButton.setIcon(EricPixmapCache.getIcon("showPassword")) 171 self.newPinButton.setIcon(EricPixmapCache.getIcon("showPassword"))
170 self.newPinEdit.setEchoMode(QLineEdit.EchoMode.Password) 172 self.newPinEdit.setEchoMode(QLineEdit.EchoMode.Password)
171 173
172 self.confirmnewPinLabel.setVisible(not checked) 174 self.confirmNewPinLabel.setVisible(not checked)
173 self.confirmPinnewEdit.setVisible(not checked) 175 self.confirmNewPinEdit.setVisible(not checked)
174 self.on_newPinEdit_textEdited(self.newPinEdit.text()) 176 self.__checkPins()
175 177
176 def getPins(self): 178 def getPins(self):
177 """ 179 """
178 Public method to get the entered PINs. 180 Public method to get the entered PINs.
179 181
182 """ 184 """
183 if self.__mode == Fido2PinDialogMode.GET: 185 if self.__mode == Fido2PinDialogMode.GET:
184 return self.pinEdit.text(), None 186 return self.pinEdit.text(), None
185 elif self.__mode == Fido2PinDialogMode.SET: 187 elif self.__mode == Fido2PinDialogMode.SET:
186 return None, self.newPinEdit.text() 188 return None, self.newPinEdit.text()
187 elif self.__mode == Fido2PinDialogMode.GET: 189 elif self.__mode == Fido2PinDialogMode.CHANGE:
188 return self.pinEdit.text(), self.newPinEdit.text() 190 return self.pinEdit.text(), self.newPinEdit.text()
189 else: 191 else:
190 return None, None 192 return None, None

eric ide

mercurial