PageSettingsAccount.qml 15.3 KB
Newer Older
1
/*
2
 * Copyright (C) 2014-2018 CZ.NIC
3 4 5 6 7 8 9 10
 *
 * 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 3 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
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 13 14 15 16 17 18 19 20 21 22 23
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 * In addition, as a special exception, the copyright holders give
 * permission to link the code of portions of this program with the
 * OpenSSL library under certain conditions as described in each
 * individual source file, and distribute linked combinations including
 * the two.
 */

24
import QtQuick 2.7
25 26
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.1
27
import QtQuick.Dialogs 1.2
28
import cz.nic.mobileDatovka 1.0
29

30 31
Item {
    id: pageSettingsAccount
32

33 34 35 36 37 38
    /* These properties must be set by caller. */
    property var pageView
    property var statusBar
    property string acntName
    property string userName
    property var accountModel: null
39

40 41
    property bool isNewAccount: (userName == "")
    property string sLoginMethod: "pwd"
42
    property string oldUserName
43

44 45 46 47 48
    Component.onCompleted: {
            if (!isNewAccount) {
                accounts.getAccountData(userName)
            }
    }
49 50 51

    FileDialogue {
        id: fileDialogue
52
        multiSelect: false
53
        onFinished: {
54 55 56 57 58 59 60 61 62 63
            var listLength = pathListModel.count
            // set last selected certificate path
            if (listLength > 0) {
                if (pathListModel.get(listLength-1).path === "") {
                    if (certPathLabelId.text === "") {
                        certPathLabelId.visible = false
                    }
                } else {
                    certPathLabelId.visible = true
                    certPathLabelId.text = pathListModel.get(listLength-1).path
64
                }
65 66 67 68
            }
        }
    }

69 70
    PageHeader {
        id: headerBar
71
        title: qsTr("New account")
72 73
        onBackClicked: {
            pageView.pop(StackView.Immediate)
74
        }
75 76 77 78 79
        Row {
            anchors.verticalCenter: parent.verticalCenter
            spacing: defaultMargin
            anchors.right: parent.right
            anchors.rightMargin: defaultMargin
80
            AccessibleImageButton {
81 82
                id: actionButton
                anchors.verticalCenter: parent.verticalCenter
Martin Straka's avatar
Martin Straka committed
83
                sourceSize.height: imgHeightHeader
84
                source: "qrc:/ui/checkbox-marked-circle.svg"
85 86 87 88 89 90 91 92 93 94 95 96 97 98
                accessibleName: qsTr("Accept changes")
                onClicked: {
                    if (isNewAccount) {
                        // Create a new account context data and add to model.
                        if (accounts.createAccount(accountModel, sLoginMethod,
                            accountNameTextField.text.toString(),
                            userNameTextField.text.toString(),
                            passwordTextField.text.toString(),
                            testAccount.checked, rememberPassword.checked,
                            useLS.checked, certPathLabelId.text.toString())) {
                                // Login to new account.
                                isds.doIsdsAction("addNewAccount", userNameTextField.text.toString())
                         }
                    } else {
99 100
                        // Change account user name.
                        if (userNameTextField.text.toString() !== oldUserName) {
Martin Straka's avatar
Martin Straka committed
101
                            // Create temporary account with a new user name.
102
                            if (accounts.prepareChangeUserName(accountModel, sLoginMethod,
103 104 105 106 107
                                  accountNameTextField.text.toString(),
                                  userNameTextField.text.toString(),
                                  passwordTextField.text.toString(),
                                  testAccount.checked, rememberPassword.checked,
                                  useLS.checked, certPathLabelId.text.toString(), oldUserName)) {
Martin Straka's avatar
Martin Straka committed
108
                                    // Login to isds with the new user name.
109 110 111 112 113
                                    isds.doIsdsAction("changeUserName", userNameTextField.text.toString())
                                }
                        } else {
                            // Update account context data.
                            if (accounts.updateAccount(accountModel, sLoginMethod,
114 115 116 117 118
                                  accountNameTextField.text.toString(),
                                  userNameTextField.text.toString(),
                                  passwordTextField.text.toString(),
                                  testAccount.checked, rememberPassword.checked,
                                  useLS.checked, certPathLabelId.text.toString())) {
119
                                    settings.saveAllSettings(accountModel)
120
                            }
121
                        }
122
                        pageView.pop(StackView.Immediate)
123 124
                    }
                }
125
                Connections {
126
                    // Connection is activated when account info was downloaded.
127 128
                    target: isds
                    onDownloadAccountInfoFinishedSig: {
129 130 131 132 133
                        settings.saveAllSettings(accountModel)
                        pageView.pop(StackView.Immediate)
                    }
                    onUnsuccessedLoginToIsdsSig: {
                        if (accounts.removeAccount(accountModel, userName, false)) {
134 135 136
                            settings.saveAllSettings(accountModel)
                        }
                    }
137 138 139 140
                    onRunGetAccountInfoSig: {
                         settings.saveAllSettings(accountModel)
                         isds.getAccountInfo(userName)
                    }
141
                    onRunChangeUserNameSig: {
Martin Straka's avatar
Martin Straka committed
142 143
                        // Login to isds with new user name has been succeeded.
                        // Get databox ID of new user name.
144
                        var dbId = isds.getAccountDbId(userName)
Martin Straka's avatar
Martin Straka committed
145
                        // Change username and rename databases.
146 147 148 149 150 151 152 153
                        if (accounts.changeAccountUserName(accountModel,
                            accountNameTextField.text.toString(),
                            userNameTextField.text.toString(),
                            useLS.checked, oldUserName, dbId)) {
                                settings.saveAllSettings(accountModel)
                                isds.getAccountInfo(userName)
                        }
                    }
154
                }
155 156
            }
        }
157 158 159 160 161 162 163 164 165 166 167 168
    } // PageHeader
    Flickable {
        id: flickable
        z: 0
        anchors.top: headerBar.bottom
        anchors.right: parent.right
        anchors.left: parent.left
        anchors.bottom: parent.bottom
        contentHeight: flickContent.implicitHeight
        Pane {
            id: flickContent
            anchors.fill: parent
169
            Column {
170 171
                anchors.right: parent.right
                anchors.left: parent.left
172
                spacing: formItemVerticalSpacing
173
                AccessibleText {
174 175 176 177
                    id: loginMethodLabel
                    color: datovkaPalette.text
                    text: qsTr("Login method")
                }
178
                AccessibleComboBox {
179
                    id: loginMethodComboBox
180
                    width: parent.width
181
                    accessibleDescription: qsTr("Select login method")
182 183
                    model: ListModel {
                        id: loginMethodModel
184 185 186 187 188
                        /* Key values must be equivalent to constants defined in C++ code! */
                        ListElement { label: qsTr("Username + Password"); key: "pwd" } // USERNAME_PWD_ONLY
                        ListElement { label: qsTr("Certificate + Password"); key: "cert" } // USERNAME_PWD_CERT
                        ListElement { label: qsTr("Password + Security code"); key: "hotp" } // USERNAME_PWD_HOTP
                        ListElement { label: qsTr("Password + Security SMS"); key: "totp" } // USERNAME_PWD_TOTP
189
                    }
190
                    onCurrentIndexChanged: {
191
                        sLoginMethod = currentKey()
192 193 194
                        if (sLoginMethod === "cert") {
                             certificateLabel.visible = true
                             certPathButtonId.visible = true
195
                             certPathLabelId.visible = (certPathLabelId.text !== "")
196 197 198 199
                        } else {
                             certificateLabel.visible = false
                             certPathLabelId.visible = false
                             certPathButtonId.visible = false
200
                        }
201
                    }
202
                }
203
                AccessibleText {
204 205 206 207 208
                    id: certificateLabel
                    visible: false
                    color: datovkaPalette.text
                    text: qsTr("Certificate")
                }
209
                AccessibleText {
210 211 212 213 214 215 216
                    id: certPathLabelId
                    visible: false
                    color: datovkaPalette.text
                    width: parent.width
                    wrapMode: Text.WrapAnywhere
                    text: ""
                }
217
                AccessibleButton {
218 219 220 221 222 223
                    id: certPathButtonId
                    visible: false
                    text: qsTr("Choose file")
                    height: inputItemHeight
                    font.pointSize: defaultTextFont.font.pointSize
                    onClicked: {
224
                        fileDialogue.raise("Select certificate file", ["*.pem","*.p12","*.pfx"], true, "")
225
                    }
226
                }
227
                AccessibleText {
228
                    color: datovkaPalette.text
Karel Slaný's avatar
Karel Slaný committed
229
                    text: qsTr("Account title")
230
                }
231
                AccessibleTextField {
232
                    id: accountNameTextField
233
                    width: parent.width
234 235
                    height: inputItemHeight
                    font.pointSize: defaultTextFont.font.pointSize
Karel Slaný's avatar
Karel Slaný committed
236
                    placeholderText: qsTr("Enter custom account name")
237 238 239 240
                    InputLineMenu {
                        id: accountNameMenu
                        inputTextControl: accountNameTextField
                        isPassword: false
241
                    }
242 243 244 245
                    onPressAndHold: {
                        if (settings.useExplicitClipboardOperations()) {
                            accountNameMenu.implicitWidth = computeMenuWidth(accountNameMenu)
                            accountNameMenu.open()
246
                        }
247
                    }
248
                }
249
                AccessibleText {
250 251 252
                    color: datovkaPalette.text
                    text: qsTr("Username")
                }
253
                AccessibleTextField {
254
                    id: userNameTextField
255
                    width: parent.width
256 257 258
                    height: inputItemHeight
                    font.pointSize: defaultTextFont.font.pointSize
                    inputMethodHints: Qt.ImhLowercaseOnly
259
                    placeholderText: qsTr("Enter the login name")
260 261 262 263 264 265 266 267 268
                    InputLineMenu {
                        id: userNameMenu
                        inputTextControl: userNameTextField
                        isPassword: false
                    }
                    onPressAndHold: {
                        if (settings.useExplicitClipboardOperations()) {
                            userNameMenu.implicitWidth = computeMenuWidth(userNameMenu)
                            userNameMenu.open()
269 270
                        }
                    }
271
                }
272
                AccessibleText {
273 274 275
                    color: datovkaPalette.text
                    text: qsTr("Password")
                }
276
                AccessibleTextField {
277
                    id: passwordTextField
278
                    width: parent.width
279 280 281 282
                    height: inputItemHeight
                    font.pointSize: defaultTextFont.font.pointSize
                    echoMode: TextInput.Password
                    passwordMaskDelay: 500 // milliseconds
283
                    placeholderText: qsTr("Enter the password")
284 285 286 287 288 289 290 291 292
                    InputLineMenu {
                        id: passwordMenu
                        inputTextControl: passwordTextField
                        isPassword: true
                    }
                    onPressAndHold: {
                        if (settings.useExplicitClipboardOperations()) {
                            passwordMenu.implicitWidth = computeMenuWidth(passwordMenu)
                            passwordMenu.open()
293 294 295
                        }
                    }
                }
296
                AccessibleSwitch {
297 298 299 300 301
                    id: rememberPassword
                    text: qsTr("Remember password")
                    font.pointSize: defaultTextFont.font.pointSize
                    checked: true
                }
302
                AccessibleSwitch {
303 304 305 306
                    id: testAccount
                    text: qsTr("Test account")
                    font.pointSize: defaultTextFont.font.pointSize
                }
307
                AccessibleText {
308 309
                    id: testAccountLabel
                    color: datovkaPalette.mid
310
                    width: parent.width
311 312 313
                    text: qsTr("Test accounts are used to access the ISDS testing environment.")
                    wrapMode: Text.Wrap
                }
314
                AccessibleSwitch {
315 316 317 318 319
                    id: useLS
                    font.pointSize: defaultTextFont.font.pointSize
                    text: qsTr("Use local storage (database)")
                    checked: true
                }
320
                AccessibleText {
321
                    color: datovkaPalette.mid
322
                    width: parent.width
323 324 325 326 327 328
                    text: (useLS.checked ?
                           qsTr("Messages and attachments will be locally stored. No active internet connection is needed to access locally stored data.") :
                           qsTr("Messages and attachments will be stored only temporarily in memory. These data will be lost on application exit."))
                    wrapMode: Text.Wrap
                }
                Connections {
329
                    // Connection is activated when settings of exists account is shown.
330 331 332 333 334 335 336 337 338
                    target: accounts
                    onSendAccountData: {
                        accountNameTextField.text = acntName
                        userNameTextField.text = userName
                        passwordTextField.text = password
                        rememberPassword.checked = rememberPwd
                        testAccount.checked = isTestAccount
                        useLS.checked = storeToDisk
                        certPathLabelId.text = certPath
339
                        loginMethodComboBox.selectCurrentKey(loginMethod)
340
                        oldUserName = userName
341
                        testAccount.enabled = false
342
                        headerBar.title = qsTr("Account settings")
343 344 345 346 347 348 349
                    }
                } // Connection
            } // Column layout
        } // Pane
        ScrollIndicator.vertical: ScrollIndicator {}
    } // Flickable
} // Item