Warning, /network/tokodon/src/content/ui/LoginFlow/RegistrationPage.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
0002 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0003 
0004 import QtQuick
0005 import org.kde.kirigami 2 as Kirigami
0006 import QtQuick.Controls 2 as QQC2
0007 import QtQuick.Layouts
0008 import QtQml.Models
0009 
0010 import org.kde.kirigamiaddons.formcard 1 as FormCard
0011 import org.kde.kirigamiaddons.components 1 as Components
0012 
0013 import org.kde.tokodon
0014 
0015 MastoPage {
0016     id: root
0017 
0018     title: i18nc("@title:window", "Registration")
0019 
0020     required property var account
0021 
0022     data: [
0023         Connections {
0024             target: Controller
0025             function onNetworkErrorOccurred(error) {
0026                 message.text = i18nc("@info:status Network status", "Failed to contact server: %1. Please check your proxy settings.", error)
0027                 message.visible = true;
0028             }
0029         },
0030         Connections {
0031             target: root.account
0032 
0033             function onRegistrationError(json) {
0034                 const obj = JSON.parse(json);
0035 
0036                 if (obj.error) {
0037                     message.text = i18nc("@info:status Network status", "Failed to contact server: %1. Please check your proxy settings.", obj.error)
0038                     message.visible = true;
0039                     return;
0040                 }
0041 
0042                 const details = obj.details;
0043 
0044                 for (const key in details) {
0045                     let targetItem;
0046                     let targetName;
0047                     if (key === "email") {
0048                         targetItem = usernameField;
0049                         targetName = usernameField.label;
0050                     } else if (key === "email") {
0051                         targetItem = emailField;
0052                         targetName = emailField.label;
0053                     } else if (key === "password") {
0054                         targetItem = passwordField;
0055                         targetName = passwordField.label;
0056                     } else if (key === "reason") {
0057                         targetItem = reasonField;
0058                         targetName = reasonField.label;
0059                     }
0060 
0061                     let errorMessage = "";
0062 
0063                     for (const error in details[key]) {
0064                         if (error > 0) {
0065                             errorMessage += "\n";
0066                         }
0067                         errorMessage += targetName + " " + details[key][error].description;
0068                     }
0069 
0070                     targetItem.status = Kirigami.MessageType.Error;
0071                     targetItem.statusMessage = errorMessage;
0072                 }
0073             }
0074         }
0075     ]
0076 
0077     header: Components.Banner {
0078         id: message
0079         type: Kirigami.MessageType.Error
0080         width: parent.width
0081 
0082         showCloseButton: true
0083 
0084         actions: Kirigami.Action {
0085             text: i18n("Proxy Settings")
0086             icon.name: "settings-configure"
0087             onTriggered: pageStack.pushDialogLayer(Qt.createComponent("org.kde.tokodon", "NetworkProxyPage"))
0088         }
0089     }
0090 
0091     Component.onCompleted: usernameField.forceActiveFocus()
0092 
0093     FormCard.FormHeader {
0094         title: i18nc("@title:group", "Register")
0095     }
0096 
0097     FormCard.FormCard {
0098         FormCard.FormTextFieldDelegate {
0099             id: usernameField
0100             label: i18n("Username")
0101             inputMethodHints: Qt.ImhNoPredictiveText | Qt.ImhNoAutoUppercase
0102             onAccepted: emailField.forceActiveFocus()
0103         }
0104 
0105         FormCard.FormDelegateSeparator {}
0106 
0107         FormCard.FormTextFieldDelegate {
0108             id: emailField
0109             label: i18n("Email Address")
0110             inputMethodHints: Qt.ImhNoPredictiveText | Qt.ImhNoAutoUppercase
0111             onAccepted: passwordField.forceActiveFocus()
0112         }
0113 
0114         FormCard.FormDelegateSeparator {}
0115 
0116         FormCard.FormTextFieldDelegate {
0117             id: passwordField
0118             label: i18n("Password")
0119             echoMode: TextInput.Password
0120             inputMethodHints: Qt.ImhHiddenText | Qt.ImhSensitiveData | Qt.ImhNoPredictiveText
0121             onAccepted: reasonField.forceActiveFocus()
0122         }
0123 
0124         FormCard.FormDelegateSeparator {}
0125 
0126         FormCard.FormTextFieldDelegate {
0127             id: reasonField
0128             label: i18n("Reason")
0129         }
0130     }
0131 
0132     FormCard.FormCard {
0133         Layout.topMargin: Kirigami.Units.largeSpacing
0134 
0135         FormCard.FormButtonDelegate {
0136             id: continueButton
0137             text: i18n("Register")
0138             onClicked: {
0139                 root.account.registerAccount(usernameField.text, emailField.text, passwordField.text, true, "en", reasonField.text);
0140 
0141                 account.authenticated.connect(() => {
0142                     pageStack.layers.clear();
0143                     pageStack.replace(mainTimeline, {
0144                         name: "home"
0145                     });
0146                     Window.window.close();
0147                 });
0148             }
0149         }
0150     }
0151 }