Ejemplo n.º 1
0
    def handleAuthenticationRequired(self, requestUrl: QUrl,
                                     auth: QAuthenticator):
        mainWindow = self.view().window()
        dialog = QDialog(mainWindow,
                         Qt.WindowFlags() & ~Qt.WindowContextHelpButtonHint)
        dialog.setModal(True)
        # dialog.setWindowFlags(dialog.windowFlags() & ~Qt.WindowContextHelpButtonHint)

        passwordDialog = Ui_PasswordDialog()
        passwordDialog.setupUi(dialog)

        passwordDialog.m_iconLabel.setText('')
        icon = QIcon(mainWindow.style().standardIcon(
            QStyle.SP_MessageBoxQuestion, widget=mainWindow))
        passwordDialog.m_iconLabel.setPixmap(icon.pixmap(32, 32))

        introMessage = self.tr(
            "Enter username and password for \"{}\" at {}").format(
                # auth.realm(), requestUrl.toString().toHtmlEscaped())
                auth.realm(),
                requestUrl.toString())  # TODO: toHtmlEscaped()?
        passwordDialog.m_infoLabel.setText(introMessage)
        passwordDialog.m_infoLabel.setWordWrap(True)

        if dialog.exec() == QDialog.Accepted:
            auth.setUser(passwordDialog.m_userNameLineEdit.text())
            auth.setPassword(passwordDialog.m_passwordLineEdit.text())
        else:
            # Set authenticator null if dialog is cancelled
            # auth = QAuthenticator()
            self.setHtml('auth canceled')  # TODO: proper workaround?
Ejemplo n.º 2
0
 def webAuthenticationRequired(self, uri: QUrl, cred: QAuthenticator):
     print("Authentication Request from " + uri.toString())
     if (args.enableAutoLogon):
         print("Using autologin credentials")
         cred.setUser(args.autoLogonUser)
         cred.setPassword(args.autoLogonPassword)