ChangePassword.qml 3.26 KB
Newer Older
Jan Blackquill's avatar
Jan Blackquill committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*
    Copyright 2020  Carson Black <uhhadd@gmail.com>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) version 3, or any
    later version accepted by the membership of KDE e.V. (or its
    successor approved by the membership of KDE e.V.), which shall
    act as a proxy defined in Section 6 of version 3 of the license.

    This library 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
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library.  If not, see <http://www.gnu.org/licenses/>.
*/

import QtQuick 2.6
import QtQuick.Dialogs 1.1
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.5 as QQC2

import org.kde.kirigami 2.8 as Kirigami

Kirigami.OverlaySheet {
    id: passwordRoot

    function openAndClear() {
        verifyField.text = ""
        passwordField.text = ""
34
        passwordField.forceActiveFocus()
Jan Blackquill's avatar
Jan Blackquill committed
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
        this.open()
    }

    property var account

    header: Kirigami.Heading {
        text: i18n("Change Password")
    }

    ColumnLayout {
        id: mainColumn
        spacing: Kirigami.Units.smallSpacing
        Layout.preferredWidth: Kirigami.Units.gridUnit * 15

        // We don't use a FormLayout here because layouting breaks at small widths.
        ColumnLayout {
            Layout.alignment: Qt.AlignHCenter
            Kirigami.PasswordField {
                id: passwordField
                placeholderText: i18n("Password")

                onAccepted: {
                    if (!passwordWarning.visible && verifyField.text && passwordField.text) {
                        passButton.apply()
                    }
                }

                Layout.alignment: Qt.AlignLeft
            }
            Kirigami.PasswordField {
                id: verifyField
                placeholderText: i18n("Confirm password")

                onAccepted: {
                    if (!passwordWarning.visible && verifyField.text && passwordField.text) {
                        passButton.apply()
                    }
                }

                Layout.alignment: Qt.AlignLeft
            }
            Kirigami.InlineMessage {
                id: passwordWarning

79
80
                Layout.fillWidth: true
                Layout.maximumWidth: verifyField.width
Jan Blackquill's avatar
Jan Blackquill committed
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
                type: Kirigami.MessageType.Error
                text: i18n("Passwords must match")
                visible: passwordField.text != "" && verifyField.text != "" && passwordField.text != verifyField.text
            }
            QQC2.Button {
                id: passButton
                text: i18n("Set Password")
                enabled: !passwordWarning.visible && verifyField.text && passwordField.text
                Layout.alignment: Qt.AlignLeft
                onClicked: apply()
                function apply() {
                    user.password = passwordField.text
                    passwordRoot.close()
                }
            }
        }
    }
}