1616#include " CustomLoginDialog.h"
1717#include " ui_CustomLoginDialog.h"
1818
19+ #include < QMessageBox>
1920#include < QPushButton>
2021#include < QUrl>
2122
2223#include " Application.h"
24+ #include " UrlUtils.h"
2325#include " net/Download.h"
2426
2527namespace {
@@ -108,6 +110,8 @@ void CustomLoginDialog::onUrlResolving()
108110 return ;
109111 }
110112
113+ m_resolvedUrl = m_loginUrl;
114+
111115 // modify url if header say so
112116 auto headers = m_requestTask->getRawHeaders ();
113117 if (const auto it =
@@ -116,14 +120,20 @@ void CustomLoginDialog::onUrlResolving()
116120 it != headers.end ()) {
117121 const QUrl location = QString::fromUtf8 (it->second );
118122 if (location.isRelative ()) {
119- m_loginUrl = m_requestTask->url ().resolved (location);
123+ m_resolvedUrl = m_requestTask->url ().resolved (location);
120124 } else {
121- m_loginUrl = location;
125+ m_resolvedUrl = location;
122126 }
123127 }
124128
129+ bool shouldContinue = showWarning ();
130+ if (!shouldContinue) {
131+ emit onTaskFailed (tr (" Aborted" ));
132+ return ;
133+ }
134+
125135 // Setup the login task and start it
126- m_account = CustomAccount::createCustom (ui->userTextBox ->text (), m_loginUrl .toString (QUrl::StripTrailingSlash),
136+ m_account = CustomAccount::createCustom (ui->userTextBox ->text (), m_resolvedUrl .toString (QUrl::StripTrailingSlash),
127137 ui->loginUrlTextBox ->text (), ui->refreshUrlTextBox ->text ());
128138 m_loginTask = m_account->login (ui->passTextBox ->text ());
129139 connect (m_loginTask.get (), &Task::failed, this , &CustomLoginDialog::onTaskFailed);
@@ -143,6 +153,22 @@ void CustomLoginDialog::setUserInputsEnabled(bool enable)
143153 ui->buttonBox ->setEnabled (enable);
144154}
145155
156+ bool CustomLoginDialog::showWarning ()
157+ {
158+ QString text = tr (" You entered:\n %1\n "
159+ " Your login credentials will be sent to:\n %2\n "
160+ " Do you want to continue?" )
161+ .arg (m_loginUrl.toString (), m_resolvedUrl.toString ());
162+
163+ if (UrlUtils::isUnsafe (m_loginUrl) || UrlUtils::isUnsafe (m_resolvedUrl)) {
164+ text.prepend (tr (" Please note that http:// is not secure, and your login credentials may be intercepted.\n " ));
165+ }
166+
167+ auto answer = QMessageBox::question (this , tr (" Warning" ), text);
168+
169+ return answer == QMessageBox::Yes;
170+ }
171+
146172// Enable the OK button only when both textboxes contain something.
147173void CustomLoginDialog::onTextBoxesChanged ()
148174{
0 commit comments