10 from __future__ import unicode_literals |
10 from __future__ import unicode_literals |
11 |
11 |
12 import json |
12 import json |
13 |
13 |
14 from PyQt5.QtCore import pyqtSignal, QByteArray |
14 from PyQt5.QtCore import pyqtSignal, QByteArray |
15 from PyQt5.QtWidgets import QDialog |
15 from PyQt5.QtWidgets import qApp, QStyle, QDialog |
16 from PyQt5.QtNetwork import QNetworkAccessManager, QNetworkProxy, \ |
16 from PyQt5.QtNetwork import QNetworkAccessManager, QNetworkProxy, \ |
17 QNetworkRequest |
17 QNetworkRequest |
|
18 from PyQt5.QtWebEngineWidgets import QWebEnginePage |
18 |
19 |
19 from E5Gui import E5MessageBox |
20 from E5Gui import E5MessageBox |
20 |
21 |
21 from E5Network.E5NetworkProxyFactory import proxyAuthenticationRequired |
22 from E5Network.E5NetworkProxyFactory import proxyAuthenticationRequired |
22 try: |
23 try: |
242 auth.setUser(username) |
244 auth.setUser(username) |
243 auth.setPassword(password) |
245 auth.setPassword(password) |
244 if Preferences.getUser("SavePasswords") and dlg.shallSave(): |
246 if Preferences.getUser("SavePasswords") and dlg.shallSave(): |
245 WebBrowser.WebBrowserWindow.WebBrowserWindow.passwordManager()\ |
247 WebBrowser.WebBrowserWindow.WebBrowserWindow.passwordManager()\ |
246 .setLogin(url, realm, username, password) |
248 .setLogin(url, realm, username, password) |
|
249 else: |
|
250 page = self.sender() |
|
251 if isinstance(page, QWebEnginePage): |
|
252 self.__showAuthenticationErrorPage(page, url) |
|
253 |
|
254 def __showAuthenticationErrorPage(self, page, url): |
|
255 """ |
|
256 Private method to show an authentication error page. |
|
257 |
|
258 @param page reference to the page |
|
259 @type QWebEnginePage |
|
260 @param url reference to the URL requesting authentication |
|
261 @type QUrl |
|
262 """ |
|
263 html = readAllFileContents(":/html/authenticationErrorPage.html") |
|
264 html = html.replace("@IMAGE@", pixmapToDataUrl( |
|
265 qApp.style().standardIcon(QStyle.SP_MessageBoxCritical).pixmap( |
|
266 48, 48)).toString()) |
|
267 html = html.replace("@FAVICON@", pixmapToDataUrl( |
|
268 qApp.style() .standardIcon(QStyle.SP_MessageBoxCritical).pixmap( |
|
269 16, 16)).toString()) |
|
270 html = html.replace("@TITLE@", self.tr("Authentication required")) |
|
271 html = html.replace("@H1@", self.tr("Authentication required")) |
|
272 html = html.replace( |
|
273 "@LI-1@", |
|
274 self.tr("Authentication is required to access:")) |
|
275 html = html.replace( |
|
276 "@LI-2@", |
|
277 '<a href="{0}">{0}</a>'.format(url.toString())) |
|
278 page.setHtml(html, url) |
247 |
279 |
248 def proxyAuthentication(self, requestUrl, auth, proxyHost): |
280 def proxyAuthentication(self, requestUrl, auth, proxyHost): |
249 """ |
281 """ |
250 Public slot to handle a proxy authentication request. |
282 Public slot to handle a proxy authentication request. |
251 |
283 |