Display error message when creating a link share with compromised password.
authoralex-z <blackslayer4@gmail.com>
Wed, 5 Jan 2022 10:14:23 +0000 (12:14 +0200)
committerMatthieu Gallien (Rebase PR Action) <matthieu_gallien@yahoo.fr>
Wed, 12 Jan 2022 10:36:25 +0000 (10:36 +0000)
Signed-off-by: alex-z <blackslayer4@gmail.com>
src/gui/CMakeLists.txt
src/gui/passwordinputdialog.cpp [new file with mode: 0644]
src/gui/passwordinputdialog.h [new file with mode: 0644]
src/gui/passwordinputdialog.ui [new file with mode: 0644]
src/gui/sharedialog.cpp
src/gui/sharedialog.h

index d2d05fe94a66a5fda7818505ec935c25bc9d15a2..744d6501a24db30f86ee84ec0cc8560256532463 100644 (file)
@@ -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 (file)
index 0000000..8fd114c
--- /dev/null
@@ -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 (file)
index 0000000..151e7df
--- /dev/null
@@ -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 (file)
index 0000000..02cad4f
--- /dev/null
@@ -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>
index 6f5e2837d2ebf81d306f7fd1903b245b1173a7fd..6ecb579e595c3cedfd868a76879b55b0814c7da7 100644 (file)
@@ -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()
index 6431cb13194af4385c6983adb8871e8019a4a1f2..5e58480e041db003bde269941e778df7697496e8 100644 (file)
@@ -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: