Show view for web registration if out-of-band URL is provided

master
Melvin Keskin 2021-04-17 11:58:21 +02:00 committed by Linus Jahn
parent 53135d81f9
commit a3d2aab7f2
No known key found for this signature in database
GPG Key ID: 4663231A91A1E27B
8 changed files with 56 additions and 13 deletions

View File

@ -42,6 +42,7 @@
{
"jid": "dismail.de",
"supportsInBandRegistration": false,
"registrationWebPage": "https://dismail.de/register.html",
"hosting": "professional",
"passwordReset": false,
"mucSupport": true,

View File

@ -217,6 +217,14 @@ signals:
*/
void registrationFormReceived(DataFormModel *dataFormModel);
/**
* Emitted when an out-of-band URL for registration is received from the
* server.
*
* @param outOfBandUrl URL used for out-of-band registration
*/
void registrationOutOfBandUrlReceived(const QString &outOfBandUrl);
/**
* Emitted to request a registration form from the server which is set as the
* currently used JID.

View File

@ -121,8 +121,27 @@ void RegistrationManager::handleRegistrationFormReceived(const QXmppRegisterIq &
bool isFakeForm;
QXmppDataForm newDataForm = extractFormFromRegisterIq(iq, isFakeForm);
// If the data form is not set, there is a problem with the server.
// If there is no registration data form, try to use an out-of-band URL.
if (newDataForm.fields().isEmpty()) {
#if QXMPP_VERSION >= QT_VERSION_CHECK(1, 5, 0)
// If there is a standardized out-of-band URL, use that.
if (!iq.outOfBandUrl().isEmpty()) {
emit Kaidan::instance()->registrationOutOfBandUrlReceived(iq.outOfBandUrl());
return;
}
#endif
// Try to find an out-of-band URL within the instructions element.
// Most servers include a text with a link to the website.
const auto words = iq.instructions().split(u' ');
for (const auto &instructionPart : words) {
if (instructionPart.startsWith(u"https://")) {
emit Kaidan::instance()->registrationOutOfBandUrlReceived(instructionPart);
return;
}
}
// If no URL has been found in the instructions, there is a
// problem with the server.
emit m_clientWorker->connectionErrorChanged(ClientWorker::RegistrationUnsupported);
return;
}

View File

@ -102,6 +102,10 @@ RegistrationPage {
removeLoadingView()
}
function onRegistrationOutOfBandUrlReceived(outOfBandUrl) {
requestRegistrationFormFromAnotherServer(qsTr("The server does currently not support registration via this app."))
}
function onRegistrationFailed(error, errorMessage) {
switch (error) {
case RegistrationManager.InBandRegistrationNotSupported:

View File

@ -120,10 +120,6 @@ RegistrationPage {
jumpToPreviousView()
removeLoadingView()
}
}
Connections {
target: Kaidan
function onRegistrationFormReceived(dataFormModel) {
formModel = dataFormModel
@ -175,6 +171,11 @@ RegistrationPage {
focusFieldViews()
}
function onRegistrationOutOfBandUrlReceived(outOfBandUrl) {
serverView.outOfBandUrl = outOfBandUrl
handleInBandRegistrationNotSupported()
}
// Depending on the error, the swipe view jumps to the view where the input should be corrected.
// For all remaining errors, the swipe view jumps to the server view.
function onRegistrationFailed(error, errorMessage) {
@ -182,7 +183,7 @@ RegistrationPage {
switch(error) {
case RegistrationManager.InBandRegistrationNotSupported:
handleInBandRegistrationNotSupportedError()
handleInBandRegistrationNotSupported()
break
case RegistrationManager.UsernameConflict:
requestRegistrationForm()
@ -229,14 +230,14 @@ RegistrationPage {
}
/**
* Shows a passive notification if the server does not support In-Band Registration.
* Shows a passive notification regarding the missing support of In-Band Registration.
* If the server supports web registration, the corresponding view is opened.
* If the server does not support web registration and it is not a custom server, another one is automatically selected.
*/
function handleInBandRegistrationNotSupportedError() {
function handleInBandRegistrationNotSupported() {
var notificationText = serverView.customServerSelected ? qsTr("The server does not support registration via this app.") : qsTr("The server does currently not support registration via this app.")
if (serverView.inBandRegistrationSupported) {
if (serverView.registrationWebPage || serverView.outOfBandUrl) {
addWebRegistrationView()
notificationText += " " + qsTr("But you can use the server's web registration.")
} else {
@ -283,7 +284,7 @@ RegistrationPage {
function addWebRegistrationView() {
removeDynamicallyLoadedInBandRegistrationViews()
webRegistrationView = webRegistrationViewComponent.createObject(webRegistrationView)
webRegistrationView = webRegistrationViewComponent.createObject(swipeView)
swipeView.insertItem(serverView.Controls.SwipeView.index + 1, webRegistrationView)
}

View File

@ -51,6 +51,7 @@ FieldView {
property bool inBandRegistrationSupported: serverListModel.data(comboBox.currentIndex, ServerListModel.SupportsInBandRegistrationRole)
property string registrationWebPage: serverListModel.data(comboBox.currentIndex, ServerListModel.RegistrationWebPageRole)
property bool shouldWebRegistrationViewBeShown: !customServerSelected && !inBandRegistrationSupported
property string outOfBandUrl
property alias customConnectionSettings: customConnectionSettings
@ -106,6 +107,13 @@ FieldView {
}
]
onTextChanged: {
if (outOfBandUrl && customServerSelected) {
outOfBandUrl = ""
removeWebRegistrationView()
}
}
// Focus the customConnectionSettings on confirmation.
Keys.onPressed: {
if (customConnectionSettings.visible) {

View File

@ -47,12 +47,12 @@ View {
CenteredAdaptiveHighlightedButton {
text: qsTr("Open registration web page")
onClicked: Qt.openUrlExternally(serverView.registrationWebPage)
onClicked: Qt.openUrlExternally(serverView.registrationWebPage ? serverView.registrationWebPage : serverView.outOfBandUrl)
}
CenteredAdaptiveButton {
text: qsTr("Copy registration web page address")
onClicked: Utils.copyToClipboard(serverView.registrationWebPage)
onClicked: Utils.copyToClipboard(serverView.registrationWebPage ? serverView.registrationWebPage : serverView.outOfBandUrl)
}
CenteredAdaptiveHighlightedButton {

View File

@ -40,7 +40,9 @@ import "../elements/fields"
RowLayout {
property alias hostField: hostField
property alias portField: portField
property Button confirmationButton
// The type Item is used because the type Button does not work for buttons of type RoundButton.
property Item confirmationButton
Field {
id: hostField