-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1501 from Nheko-Reborn/qmlRecaptcha
QML the reCAPTCHA dialog
- Loading branch information
Showing
10 changed files
with
154 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// SPDX-FileCopyrightText: Nheko Contributors | ||
// | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
import QtQuick | ||
import QtQuick.Controls | ||
import im.nheko | ||
|
||
ApplicationWindow { | ||
id: recaptchaRoot | ||
|
||
required property ReCaptcha recaptcha | ||
|
||
function accept() { | ||
recaptcha.confirm(); | ||
recaptchaRoot.close(); | ||
} | ||
|
||
function reject() { | ||
recaptcha.cancel(); | ||
recaptchaRoot.close(); | ||
} | ||
|
||
color: palette.window | ||
title: recaptcha.context | ||
flags: Qt.Tool | Qt.WindowStaysOnTopHint | Qt.WindowCloseButtonHint | Qt.WindowTitleHint | ||
height: msg.implicitHeight + footer.implicitHeight | ||
width: Math.max(msg.implicitWidth, footer.implicitWidth) | ||
|
||
Shortcut { | ||
sequence: StandardKey.Cancel | ||
onActivated: recaptchaRoot.reject() | ||
} | ||
|
||
Label { | ||
id: msg | ||
|
||
anchors.fill: parent | ||
padding: 8 | ||
text: qsTr("Solve the reCAPTCHA and press the confirm button") | ||
} | ||
|
||
footer: DialogButtonBox { | ||
onAccepted: recaptchaRoot.accept() | ||
onRejected: recaptchaRoot.reject() | ||
|
||
Button { | ||
text: qsTr("Open reCAPTCHA") | ||
onClicked: recaptcha.openReCaptcha() | ||
} | ||
|
||
Button { | ||
text: qsTr("Cancel") | ||
DialogButtonBox.buttonRole: DialogButtonBox.RejectRole | ||
} | ||
|
||
Button { | ||
text: qsTr("Confirm") | ||
DialogButtonBox.buttonRole: DialogButtonBox.AcceptRole | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// SPDX-FileCopyrightText: Nheko Contributors | ||
// | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
#include "ReCaptcha.h" | ||
|
||
#include <QDesktopServices> | ||
#include <QUrl> | ||
|
||
#include "MatrixClient.h" | ||
|
||
ReCaptcha::ReCaptcha(const QString &session, const QString &context, QObject *parent) | ||
: QObject{parent} | ||
, m_session{session} | ||
, m_context{context} | ||
{ | ||
} | ||
|
||
void | ||
ReCaptcha::openReCaptcha() | ||
{ | ||
const auto url = QString("https://%1:%2/_matrix/client/r0/auth/m.login.recaptcha/" | ||
"fallback/web?session=%3") | ||
.arg(QString::fromStdString(http::client()->server())) | ||
.arg(http::client()->port()) | ||
.arg(m_session); | ||
|
||
QDesktopServices::openUrl(url); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// SPDX-FileCopyrightText: Nheko Contributors | ||
// | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
#pragma once | ||
|
||
#include <QQmlEngine> | ||
|
||
class ReCaptcha : public QObject | ||
{ | ||
Q_OBJECT | ||
QML_ELEMENT | ||
QML_UNCREATABLE("") | ||
|
||
Q_PROPERTY(QString context MEMBER m_context CONSTANT) | ||
Q_PROPERTY(QString session MEMBER m_session CONSTANT) | ||
|
||
public: | ||
ReCaptcha(const QString &session, const QString &context, QObject *parent = nullptr); | ||
|
||
Q_INVOKABLE void openReCaptcha(); | ||
Q_INVOKABLE void confirm() { emit confirmation(); } | ||
Q_INVOKABLE void cancel() { emit cancelled(); } | ||
|
||
signals: | ||
void confirmation(); | ||
void cancelled(); | ||
|
||
private: | ||
QString m_session; | ||
QString m_context; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters