LoginPage.qml 7.99 KB
Newer Older
armin's avatar
armin committed
1
2
3
4
5
6
7
8
9
10
11
import QtQuick 2.8
import QtQuick.Controls 2.1
import QtQuick.Layouts 1.3

import "qrc:/qml/style"

import "qrc:/qml/various"
import "qrc:/javascript/print.js" as Print

Item {
    id: loginPage
armin's avatar
armin committed
12

armin's avatar
armin committed
13

armin's avatar
armin committed
14
15
16
    // KDAB_TODO: This should be bound to a property of the RocketChat class
    property bool showLoginForm: false

armin's avatar
armin committed
17

armin's avatar
armin committed
18
19
20
    function login() {
        rocketChatController.login("default", loginUsername.text,
                                   loginPassword.text)
armin's avatar
armin committed
21
        showLoginForm = false
armin's avatar
armin committed
22
        connectionIndicator.visible = true
armin's avatar
armin committed
23
        loginStatus.text = ""
24
        switchServerButton.visible = false
armin's avatar
armin committed
25
    }
armin's avatar
armin committed
26
27

    function checkConnectionState() {
armin's avatar
armin committed
28
        console.log("Checking connection state")
armin's avatar
armin committed
29

armin's avatar
armin committed
30
31
        loginPage.showLoginForm = rocketChatController.getDdpConnectionEstablished();
        connectionIndicator.visible = false
armin's avatar
armin committed
32
33
    }

armin's avatar
armin committed
34
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
    Column {
        anchors.centerIn: parent
        width: 400
        height: 400
        spacing: 21
        Image {
            mipmap: true

            width: 120
            smooth: true
            anchors.horizontalCenter: parent.horizontalCenter
            fillMode: Image.PreserveAspectFit
            source: "qrc:/res/images/ucom_logo_square_trans.svg"
        }

        Column {
            //anchors.verticalCenter: parent.verticalCenter
            anchors.left: parent.left
            anchors.right: parent.right
            anchors.leftMargin: 65
            anchors.rightMargin: 65
            spacing: 40
            width: 340
            height: 190

            Text {
                id: connectStatus
                visible: debug
                text: {
                    if (rocketChatController.getDdpConnectionEstablished())
                        return "connected"
                    else
                        return "not connected"
                }
            }
            TextField {
                id: loginUsername
                width: parent.width
                color: Colors.white
armin's avatar
armin committed
73
                visible: loginPage.showLoginForm
armin's avatar
armin committed
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
                font.pointSize: Fonts.largeFontSize
                leftPadding: 5
                rightPadding: 5
                bottomPadding: 5
                horizontalAlignment: TextField.AlignLeft
                verticalAlignment:  TextField.AlignBottom
                selectByMouse: true
                text: ""
                inputMethodHints: Qt.ImhNoAutoUppercase | Qt.ImhNoPredictiveText|
                                  Qt.ImhPreferLowercase
                focus: true
                placeholderText: qsTr("username or e-mail")
                background: Rectangle {
                    //                        anchors.horizontalCenter: parent
                    implicitWidth: parent.width
                    implicitHeight: 30


                    color: "transparent"
                    Rectangle {
                        height: 1
                        width: parent.width
                        color: Colors.white
                        anchors.bottom: parent.bottom
                    }
                }

            }

            TextField {
                id: loginPassword
                width: parent.width
armin's avatar
armin committed
106
                visible: loginPage.showLoginForm
armin's avatar
armin committed
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
                text: ""
                color: Colors.white
                font.pointSize: Fonts.largeFontSize
                leftPadding: 5
                rightPadding: 5
                bottomPadding: 5
                horizontalAlignment: TextField.AlignLeft
                verticalAlignment:  TextField.AlignBottom
                inputMethodHints: Qt.ImhNoAutoUppercase | Qt.ImhNoPredictiveText
                                  | Qt.ImhSensitiveData |
                                  Qt.ImhPreferLowercase
                echoMode: TextInput.Password
                selectByMouse: true

                placeholderText: qsTr("password")

                background: Rectangle {

                    //                        anchors.horizontalCenter: parent
                    implicitWidth: parent.width
                    implicitHeight: 30
                    color: "transparent"
                    Rectangle {
                        height: 1
                        width: parent.width
                        color: Colors.white
                        anchors.bottom: parent.bottom
                    }
                }


            }

            StdButton {
                id: loginButton
                anchors.left: parent.left
                anchors.right: parent.right
                text: qsTr("login")
                checked: false
                checkable: false
armin's avatar
armin committed
147
                visible: loginPage.showLoginForm
armin's avatar
armin committed
148
149
150
                color: Colors.white
                textColor: Colors.primary
            }
151
152
153
154
155
156
157
158
159
160
161
162
163
164
            StdButton {
                id: switchServerButton
                anchors.left: parent.left
                anchors.right: parent.right
                text: qsTr("switch Server")
                checked: false
                checkable: false
                color: Colors.white
                textColor: Colors.primary
                onPressed: {
                    mainStack.pop()
                }
            }

armin's avatar
armin committed
165
166
            BusyIndicator {
                id: connectionIndicator
armin's avatar
armin committed
167
                visible: true
armin's avatar
armin committed
168
169
170
171
172
173
174
175
                anchors.horizontalCenter: parent.horizontalCenter
            }
            Label {
                id: loginStatus
                Layout.alignment: Qt.AlignCenter
                color: "red"
                text: ""
            }
armin's avatar
armin committed
176
177
178
179
180
181

            // KDAB_TODO: This should all be done differently
            Connections{
                target: rocketChatController
                onServerReady: checkConnectionState()
            }
armin's avatar
armin committed
182
            Component.onCompleted: {
armin's avatar
armin committed
183
                checkConnectionState()
armin's avatar
armin committed
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
217
218
219
            }
        }

    }
    Connections {
        target: loginPassword
        onAccepted: {
            loginUsername.focus = false
            loginPassword.focus = false
            loginPage.login()
        }
    }

    Connections {
        target: loginButton
        onPressed: {
            loginUsername.focus = false
            loginPassword.focus = false
            loginPage.login()
        }
    }
    Connections {
        target: rocketChatController
        onLoggedIn: {
            Print.log("logged in")
            //if (sessionCheckbox.checked)

            mainStack.toMainView()
        }
        onHashLoggedIn:{
            welcomePopup.open()
        }

        onLoginError: {
            Print.log("error login")
            loginStatus.text = qsTr("username or password wrong")
armin's avatar
armin committed
220
221
            connectionIndicator.visible = false
            loginPage.showLoginForm = true
222
223
            switchServerButton.visible = true

armin's avatar
armin committed
224
225
226
227
228
229
230
231
232
        }
        onServerConnected: {
            connectStatus.text = "connected"

            if (rocketChatController.getPassword("default") != "" && rocketChatController.getUsername("default") != "") {
                rocketChatController.login("default", rocketChatController.getUsername("default"),
                                           rocketChatController.getPassword("default"))
                mainStack.toMainView()
            } else {
armin's avatar
armin committed
233
                loginPage.showLoginForm = true
armin's avatar
armin committed
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
            }
        }


        onStorageReady:{
            setUserData();
        }
    }
    function setUserData(){
        var username = rocketChatController.getUsername("default")
        var password = rocketChatController.getPassword("default")
        if(username != "" && password != ""){
            loginPassword.text = password
            loginUsername.text = username
            mainStack.toMainView()
        }
    }
    Component.onCompleted: {
        rocketChatController.setStatusBarColor(Colors.secondary)
        if(rocketChatController.isStorageReady()){
            setUserData();
        }

    }
}