LoginView.qml 11 KB
Newer Older
1
2
3
4
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Controls.Material 2.12
import QtQuick.Layouts 1.12
Leander Schulten's avatar
Leander Schulten committed
5
import custom.licht 1.0
Leander Schulten's avatar
Leander Schulten committed
6
import "components"
Leander Schulten's avatar
Leander Schulten committed
7
8
9

Item{
    property alias currentItem : listView.currentItem
10
11
12
13
14
15
16
17
18
19
20
21
    ColumnLayout{
        anchors.fill: parent
        ListView{
            id:listView
            Layout.fillWidth: true
            Layout.fillHeight: true
            Layout.preferredHeight: model.rowCount() * 50
            clip: true
            highlightMoveDuration: 100
            highlightResizeDuration: 100
            model:userModel
            highlightFollowsCurrentItem: true
22
            delegate: SwipeDelegate{
23
24
25
26
27
28
29
30
31
                swipe.left: Label {
                    id: deleteLabel
                    text: qsTr("Delete")
                    color: "white"
                    verticalAlignment: Label.AlignVCenter
                    padding: 12
                    height: parent.height
                    //SwipeDelegate.onClicked:
                    background: Rectangle {
32
33
34
35
36
37
38
                        color: deleteMouseArea.pressed ? Qt.darker("tomato", 1.1) : "tomato"
                    }
                    MouseArea{
                        id: deleteMouseArea
                        anchors.fill: parent
                        acceptedButtons: Qt.LeftButton
                        onClicked: askToDeletePopup.deleteUser(modelData)
39
                    }
Leander Schulten's avatar
Leander Schulten committed
40
                }
41
42
43
44
                Timer{
                    id:closeTimer
                    interval: 2000
                    onTriggered: parent.swipe.close()
Leander Schulten's avatar
Leander Schulten committed
45
                }
46
47
48
                swipe.onOpened: {
                    closeTimer.running = true;
                }
49
                swipe.enabled: modelData !== UserManagment.defaultUser && UserManagment.currentUser.havePermission(Permission.Admin);
50
51
52
53
                anchors.margins: 5
                clip:true
                width: parent.width
                Component.onCompleted: {
54
                    background.color = Qt.binding(function(){ return UserManagment.currentUser === modelData ? Qt.rgba(0,0,1,.7) : "transparent"; });
55
56
57
58
59
                }
                Behavior on height {
                    NumberAnimation{
                        duration: 500
                        easing.type: Easing.OutQuart
Leander Schulten's avatar
Leander Schulten committed
60
61
                    }
                }
62
63
64
                TextInputField{
                    anchors.verticalCenter: parent.contentItem.verticalCenter
                    x: parent.contentItem.x + 10
65
                    text: modelData.name
66
                    width: Math.max(implicitWidth+20,70)
67
                    enabled: (UserManagment.currentUser.havePermission(Permission.Admin) || modelData === UserManagment.currentUser)&&modelData!==UserManagment.defaultUser
68
69
70
                }
                Button{
                    visible: UserManagment.currentUser.havePermission(Permission.Admin);
71
                    text:"Change Permissions and Auto-Login"
72
73
74
75
76
                    anchors.right: buttonChangePassword.left
                    anchors.top: buttonChangePassword.top
                    anchors.bottom: buttonChangePassword.bottom
                    anchors.rightMargin: 5
                    onClicked: {
77
                        userSettingsPopup.show(modelData);
78
79
80
81
                    }
                }
                Button{
                    id:buttonChangePassword
82
                    visible: modelData === UserManagment.currentUser && modelData !== UserManagment.defaultUser;
83
84
85
86
87
88
89
90
91
                    text: "Change Password"
                    anchors.right: buttonLogin.left
                    anchors.top: buttonLogin.top
                    anchors.bottom: buttonLogin.bottom
                    anchors.rightMargin: 5
                }
                Button{
                    width: 80
                    id:buttonLogin
92
93
                    enabled: !(modelData===UserManagment.defaultUser&&modelData===UserManagment.currentUser)
                    text: modelData===UserManagment.currentUser?"Logout":"Login"
94
95
96
97
98
                    anchors.right: parent.right
                    anchors.top:parent.top
                    anchors.bottom: parent.bottom
                    anchors.rightMargin: 5
                    onClicked: {
99
                        if(modelData===UserManagment.defaultUser){
100
                            UserManagment.logout();
101
                        }else if(modelData===UserManagment.currentUser){
102
103
                            UserManagment.logout()
                        }else{
104
                            dialog.user = modelData;
105
106
107
108
                            dialog.visible = true;
                        }
                    }
                }
Leander Schulten's avatar
Leander Schulten committed
109
110
111
            }
        }

112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
        Button{
            Layout.fillWidth: true
            Layout.leftMargin: 5
            Layout.rightMargin: 5
            id: buttonAdd
            text:"+"
            font.pixelSize: 15
            onClicked: addUserDialog.visible=true;
            enabled: UserManagment.currentUser.havePermission(Permission.Admin);
        }
        Label{
            Layout.topMargin: 10
            Layout.leftMargin: 5
            text: "Known Spotify Accounts"
            font.pixelSize: 18
        }
        Rectangle{
            color: "lightgrey"
            Layout.fillWidth: true
            height: 1
        }
Leander Schulten's avatar
Leander Schulten committed
133
134


135
136
137
138
139
140
        SpotifyLoginView{
            id: spotifyLoginView
            Layout.fillHeight: true
            Layout.fillWidth: true
            implicitHeight: 200;
        }
Leander Schulten's avatar
Leander Schulten committed
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
    }


    function login(){

        if(UserManagment.login(dialog.user,password.text)){
            dialog.visible = false;
        }else{
            password.underlineColor = "red";
            cosAni.from = dialog.x+30;
            cosAni.to = dialog.x-30;
            fromToAni.to = dialog.x;
            cosAni.start();
            fromToAni.start();
        }

    }
    NumberAnimation {
        id:cosAni
        target: dialog
        property: "x"
        duration: 150
        easing.type: Easing.CosineCurve
        onStopped: if(from!==to)running=true
    }
    NumberAnimation {
        id:fromToAni
        target: cosAni
        properties: "to,from"
        duration: 500
        easing.type: Easing.Linear
    }

174
175
    Popup{
        modal: true
Leander Schulten's avatar
Leander Schulten committed
176
177
        id:dialog
        width:300
178
179
        x: (parent.width - width) / 2
        y: (parent.height - height) / 2
Leander Schulten's avatar
Leander Schulten committed
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
        property var user;
        onVisibleChanged: {
            if(visible)
                password.forceActiveFocus()
            password.text="";
        }
        contentItem:Pane{
            ColumnLayout{
                anchors.fill: parent
                RowLayout{
                    Label{
                        text:"Passwort:"
                    }
                    TextInputField{
                        echoMode: TextInput.Password
                        Layout.fillWidth: true
                        id: password
                        onAccepted: login();
                        KeyNavigation.tab:  loginButton
                    }
                }
                RowLayout{
                    Button{
                        Layout.fillWidth: true
                        text:"Abbrechen"
                        onClicked: dialog.visible = false
                    }
                    Button{
                        id:loginButton
                        Layout.fillWidth: true
                        text:"Einloggen"
                        onClicked: login()
                    }
                }
            }
        }
    }
217
218
    Popup{
        modal: true
Leander Schulten's avatar
Leander Schulten committed
219
220
        id:addUserDialog
        width:300
221
222
        x: (parent.width - width) / 2
        y: (parent.height - height) / 2
Leander Schulten's avatar
Leander Schulten committed
223
224
225
226
227
228
229
230
231
232
233
234
        onVisibleChanged:{
            if(visible){
                username.text = "";;
                password1.text = "";
                password2.text = "";
            }
        }
        contentItem:
            Pane{
            GridLayout{
                anchors.fill: parent
                columns: 2
235
236
237
238
239
240
241
242
                Label{
                    text: "Create new user"
                    font.pointSize: 15
                    font.bold: true
                    Layout.bottomMargin: 10
                    Layout.columnSpan: 2
                }

Leander Schulten's avatar
Leander Schulten committed
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
                Label{
                    text:"Username : "
                }
                TextInputField{
                    Layout.fillWidth: true
                    id:username
                    KeyNavigation.tab: password1
                    onAccepted: password1.forceActiveFocus()
                }
                Label{
                    text:"Password : "
                }
                TextInputField{
                    Layout.fillWidth: true
                    id:password1
                    echoMode: TextInput.Password
                    KeyNavigation.tab: password2
                    onAccepted: password2.forceActiveFocus()
                }
                Label{
                    text:"Password : "
                }
                TextInputField{
                    Layout.fillWidth: true
                    id:password2
                    echoMode: TextInput.Password
                    KeyNavigation.tab: createUser
                    onAccepted: createUser.forceActiveFocus()
                }

                Button{
                    id:dontCreateUser
                    text:"Abbrechen"
                    KeyNavigation.tab: createUser
                    onClicked: addUserDialog.visible = false
                }
                Button{
                    id:createUser
                    KeyNavigation.tab: dontCreateUser
                    Layout.fillWidth: true
                    text:"Create"
                    onClicked:{
                        if(username.text.length<3){
                            username.underlineColor = "red";
                            return;
                        }else{
                            username.underlineColor = "lightgreen";
                        }
                        if(password1.length<5){
                            password1.underlineColor = "red";
                            return;
                        }else{
                            password1.underlineColor="lightgreen";
                        }
                        if(password1.text!==password2.text){
                            password2.underlineColor="red";
                            return;
                        }else{
                            password2.underlineColor="lightgreen";
                        }
                        UserManagment.addUser(username.text,password1.text);
                        addUserDialog.visible=false;
                    }
                }
            }
        }
    }

311
312
313
314
315
316
317
318
319
320
    AskWhenRemovePopup{
        id: askToDeletePopup
        property var _user
        text: "Do you really want to delete the user " + (_user ? '"' + _user.name + '"' : "error")
        function deleteUser(user){
            _user = user;
            open();
        }
        onYesClicked: UserManagment.removeUser(_user);
    }
Leander Schulten's avatar
Leander Schulten committed
321

322
323
    UserSettingsPopup{
        id: userSettingsPopup
324
        modal: true
Leander Schulten's avatar
Leander Schulten committed
325
326
327
    }

}