diff options
author | alex-z <blackslayer4@gmail.com> | 2022-01-05 13:14:23 +0300 |
---|---|---|
committer | Matthieu Gallien (Rebase PR Action) <matthieu_gallien@yahoo.fr> | 2022-01-12 13:36:25 +0300 |
commit | 4a8433d29798642bc28203b03fbf0233ad48b610 (patch) | |
tree | aa7ad08cd4cff1689dd84b55bc708306b76174bb /src | |
parent | f2d075f3ca081847f081382f9d2ec0984291397c (diff) |
Display error message when creating a link share with compromised password.
Signed-off-by: alex-z <blackslayer4@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/gui/passwordinputdialog.cpp | 43 | ||||
-rw-r--r-- | src/gui/passwordinputdialog.h | 39 | ||||
-rw-r--r-- | src/gui/passwordinputdialog.ui | 115 | ||||
-rw-r--r-- | src/gui/sharedialog.cpp | 32 | ||||
-rw-r--r-- | src/gui/sharedialog.h | 2 |
6 files changed, 214 insertions, 19 deletions
diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index d2d05fe94..744d6501a 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -43,6 +43,7 @@ set(client_UI_SRCS shareuserline.ui sslerrordialog.ui addcertificatedialog.ui + passwordinputdialog.ui proxyauthdialog.ui mnemonicdialog.ui wizard/flow2authwidget.ui @@ -92,6 +93,7 @@ set(client_SRCS openfilemanager.cpp owncloudgui.cpp owncloudsetupwizard.cpp + passwordinputdialog.cpp selectivesyncdialog.cpp settingsdialog.cpp sharedialog.cpp diff --git a/src/gui/passwordinputdialog.cpp b/src/gui/passwordinputdialog.cpp new file mode 100644 index 000000000..8fd114c2d --- /dev/null +++ b/src/gui/passwordinputdialog.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (C) by Oleksandr Zolotov <alex@nextcloud.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#include "passwordinputdialog.h" +#include "ui_passwordinputdialog.h" + +namespace OCC { + +PasswordInputDialog::PasswordInputDialog(const QString &description, const QString &error, QWidget *parent) + : QDialog(parent) + , ui(new Ui::PasswordInputDialog) +{ + ui->setupUi(this); + + ui->passwordLineEditLabel->setText(description); + ui->passwordLineEditLabel->setVisible(!description.isEmpty()); + + ui->labelErrorMessage->setText(error); + ui->labelErrorMessage->setVisible(!error.isEmpty()); + + setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); +} + +PasswordInputDialog::~PasswordInputDialog() +{ + delete ui; +} +QString PasswordInputDialog::password() const +{ + return ui->passwordLineEdit->text(); +} +} diff --git a/src/gui/passwordinputdialog.h b/src/gui/passwordinputdialog.h new file mode 100644 index 000000000..151e7df74 --- /dev/null +++ b/src/gui/passwordinputdialog.h @@ -0,0 +1,39 @@ +/* + * Copyright (C) by Oleksandr Zolotov <alex@nextcloud.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#pragma once + +#include <QDialog> + +namespace OCC { + +namespace Ui { +class PasswordInputDialog; +} + +class PasswordInputDialog : public QDialog +{ + Q_OBJECT + +public: + explicit PasswordInputDialog(const QString &description, const QString &error, QWidget *parent = nullptr); + ~PasswordInputDialog() override; + + QString password() const; + +private: + Ui::PasswordInputDialog *ui; +}; + +} diff --git a/src/gui/passwordinputdialog.ui b/src/gui/passwordinputdialog.ui new file mode 100644 index 000000000..02cad4fa1 --- /dev/null +++ b/src/gui/passwordinputdialog.ui @@ -0,0 +1,115 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>OCC::PasswordInputDialog</class> + <widget class="QDialog" name="OCC::PasswordInputDialog"> + <property name="windowModality"> + <enum>Qt::WindowModal</enum> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>276</width> + <height>125</height> + </rect> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Maximum" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="windowTitle"> + <string>Password for share required</string> + </property> + <property name="sizeGripEnabled"> + <bool>false</bool> + </property> + <property name="modal"> + <bool>true</bool> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QLabel" name="passwordLineEditLabel"> + <property name="text"> + <string>Please enter a password for your share:</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="passwordLineEdit"> + <property name="inputMask"> + <string notr="true"/> + </property> + <property name="echoMode"> + <enum>QLineEdit::Password</enum> + </property> + <property name="placeholderText"> + <string/> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="labelErrorMessage"> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="styleSheet"> + <string notr="true">color: rgb(255, 0, 0)</string> + </property> + <property name="text"> + <string/> + </property> + <property name="wordWrap"> + <bool>true</bool> + </property> + </widget> + </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>OCC::PasswordInputDialog</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>OCC::PasswordInputDialog</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> diff --git a/src/gui/sharedialog.cpp b/src/gui/sharedialog.cpp index 6f5e2837d..6ecb579e5 100644 --- a/src/gui/sharedialog.cpp +++ b/src/gui/sharedialog.cpp @@ -17,6 +17,7 @@ #include "sharee.h" #include "sharelinkwidget.h" #include "shareusergroupwidget.h" +#include "passwordinputdialog.h" #include "sharemanager.h" @@ -359,26 +360,21 @@ void ShareDialog::slotCreatePasswordForLinkShareProcessed() } } -void ShareDialog::slotLinkShareRequiresPassword() +void ShareDialog::slotLinkShareRequiresPassword(const QString &message) { - bool ok = false; - QString password = QInputDialog::getText(this, - tr("Password for share required"), - tr("Please enter a password for your link share:"), - QLineEdit::Password, - QString(), - &ok); - - if (!ok) { - // The dialog was canceled so no need to do anything + const auto passwordInputDialog = new PasswordInputDialog(tr("Please enter a password for your link share:"), message, this); + passwordInputDialog->setWindowTitle(tr("Password for share required")); + passwordInputDialog->setAttribute(Qt::WA_DeleteOnClose); + passwordInputDialog->open(); + + connect(passwordInputDialog, &QDialog::finished, this, [this, passwordInputDialog](const int result) { + if (result == QDialog::Accepted && _manager) { + // Try to create the link share again with the newly entered password + _manager->createLinkShare(_sharePath, QString(), passwordInputDialog->password()); + return; + } emit toggleShareLinkAnimation(false); - return; - } - - if(_manager) { - // Try to create the link share again with the newly entered password - _manager->createLinkShare(_sharePath, QString(), password); - } + }); } void ShareDialog::slotDeleteShare() diff --git a/src/gui/sharedialog.h b/src/gui/sharedialog.h index 6431cb131..5e58480e0 100644 --- a/src/gui/sharedialog.h +++ b/src/gui/sharedialog.h @@ -66,7 +66,7 @@ private slots: void slotCreateLinkShare(); void slotCreatePasswordForLinkShare(const QString &password); void slotCreatePasswordForLinkShareProcessed(); - void slotLinkShareRequiresPassword(); + void slotLinkShareRequiresPassword(const QString &message); void slotAdjustScrollWidgetSize(); signals: |