Mercurial: Handle HTTP authentication, auth dialog

Make it possible to pull and push into online repositories with http
authorization.
Changes:
* Separated dialogs for entering username and password are merge
together
* Do not show dialog for local repos
* Prohibit passwords for ssh scheme

Task-number: QTCREATORBUG-5104
Change-Id: I22fe3d778bb43d25ccd3ee423f98b22dd2019c24
Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
Nikita Baryshnikov
2013-06-10 00:57:54 +03:00
committed by Tobias Hunger
parent 8ba09eabca
commit bc29c67183
6 changed files with 237 additions and 16 deletions

View File

@@ -0,0 +1,62 @@
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "authenticationdialog.h"
#include "ui_authenticationdialog.h"
using namespace Mercurial::Internal;
AuthenticationDialog::AuthenticationDialog(const QString &username, const QString &password, QWidget *parent) :
QDialog(parent),
ui(new Ui::AuthenticationDialog)
{
ui->setupUi(this);
ui->username->setText(username);
ui->password->setText(password);
}
AuthenticationDialog::~AuthenticationDialog()
{
delete ui;
}
void AuthenticationDialog::setPasswordEnabled(bool enabled)
{
ui->password->setEnabled(enabled);
}
QString AuthenticationDialog::getUserName()
{
return ui->username->text();
}
QString AuthenticationDialog::getPassword()
{
return ui->password->text();
}

View File

@@ -0,0 +1,58 @@
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef AUTHENTICATIONDIALOG_H
#define AUTHENTICATIONDIALOG_H
#include <QDialog>
namespace Mercurial {
namespace Internal {
namespace Ui { class AuthenticationDialog; }
class AuthenticationDialog : public QDialog
{
Q_OBJECT
public:
explicit AuthenticationDialog(const QString &username, const QString &password, QWidget *parent = 0);
~AuthenticationDialog();
void setPasswordEnabled(bool enabled);
QString getUserName();
QString getPassword();
private:
Ui::AuthenticationDialog *ui;
};
} // namespace Internal
} // namespace Mercurial
#endif // AUTHENTICATIONDIALOG_H

View File

@@ -0,0 +1,92 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Mercurial::Internal::AuthenticationDialog</class>
<widget class="QDialog" name="Mercurial::Internal::AuthenticationDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>312</width>
<height>116</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="usernameLabel">
<property name="text">
<string>User name:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="username"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="passwordLabel">
<property name="text">
<string>Password:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="password">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>Mercurial::Internal::AuthenticationDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>Mercurial::Internal::AuthenticationDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@@ -11,7 +11,8 @@ SOURCES += mercurialplugin.cpp \
commiteditor.cpp \ commiteditor.cpp \
clonewizardpage.cpp \ clonewizardpage.cpp \
clonewizard.cpp \ clonewizard.cpp \
mercurialsettings.cpp mercurialsettings.cpp \
authenticationdialog.cpp
HEADERS += mercurialplugin.h \ HEADERS += mercurialplugin.h \
constants.h \ constants.h \
optionspage.h \ optionspage.h \
@@ -25,9 +26,11 @@ HEADERS += mercurialplugin.h \
commiteditor.h \ commiteditor.h \
clonewizardpage.h \ clonewizardpage.h \
clonewizard.h \ clonewizard.h \
mercurialsettings.h mercurialsettings.h \
authenticationdialog.h
FORMS += optionspage.ui \ FORMS += optionspage.ui \
revertdialog.ui \ revertdialog.ui \
srcdestdialog.ui \ srcdestdialog.ui \
mercurialcommitpanel.ui mercurialcommitpanel.ui \
authenticationdialog.ui
RESOURCES += mercurial.qrc RESOURCES += mercurial.qrc

View File

@@ -15,6 +15,9 @@ QtcPlugin {
files: [ files: [
"annotationhighlighter.cpp", "annotationhighlighter.cpp",
"annotationhighlighter.h", "annotationhighlighter.h",
"authenticationdialog.cpp",
"authenticationdialog.h",
"authenticationdialog.ui",
"clonewizard.cpp", "clonewizard.cpp",
"clonewizard.h", "clonewizard.h",
"clonewizardpage.cpp", "clonewizardpage.cpp",

View File

@@ -27,11 +27,11 @@
** **
****************************************************************************/ ****************************************************************************/
#include "authenticationdialog.h"
#include "mercurialplugin.h"
#include "srcdestdialog.h" #include "srcdestdialog.h"
#include "ui_srcdestdialog.h" #include "ui_srcdestdialog.h"
#include "mercurialplugin.h"
#include <QInputDialog>
#include <QSettings> #include <QSettings>
#include <QUrl> #include <QUrl>
@@ -67,18 +67,21 @@ QString SrcDestDialog::getRepositoryString() const
{ {
if (m_ui->defaultButton->isChecked()) { if (m_ui->defaultButton->isChecked()) {
QUrl repoUrl(getRepoUrl()); QUrl repoUrl(getRepoUrl());
if (m_ui->promptForCredentials && (repoUrl.userName().isEmpty() || repoUrl.password().isEmpty())) { if (m_ui->promptForCredentials->isChecked() && !repoUrl.scheme().isEmpty() && repoUrl.scheme() != QLatin1String("file")) {
if (repoUrl.userName().isEmpty()) { QScopedPointer<AuthenticationDialog> authDialog(new AuthenticationDialog(repoUrl.userName(), repoUrl.password()));
QString user = QInputDialog::getText(0, tr("Enter user name"), tr("User name:")); authDialog->setPasswordEnabled(repoUrl.scheme() != QLatin1String("ssh"));
if (authDialog->exec()== 0)
return repoUrl.toString();
QString user = authDialog->getUserName();
if (user.isEmpty()) if (user.isEmpty())
return repoUrl.toString(); return repoUrl.toString();
if (user != repoUrl.userName())
repoUrl.setUserName(user); repoUrl.setUserName(user);
}
if (repoUrl.password().isEmpty()) { QString pass = authDialog->getPassword();
QString password = QInputDialog::getText(0, tr("Enter password"), tr("Password:"), QLineEdit::Password); if (!pass.isEmpty() && pass != repoUrl.password())
if (!password.isEmpty()) repoUrl.setPassword(pass);
repoUrl.setPassword(password);
}
} }
return repoUrl.toString(); return repoUrl.toString();
} }