Merge lp:~mardy/account-plugins/nextcloud-1639175 into lp:account-plugins
- nextcloud-1639175
- Merge into trunk
Proposed by
Alberto Mardegan
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Alberto Mardegan | ||||
Approved revision: | 182 | ||||
Merged at revision: | 180 | ||||
Proposed branch: | lp:~mardy/account-plugins/nextcloud-1639175 | ||||
Merge into: | lp:account-plugins | ||||
Prerequisite: | lp:~gary-wzl77/account-plugins/onedrive_provider | ||||
Diff against target: |
433 lines (+312/-3) 11 files modified
.bzrignore (+10/-0) Makefile.am (+3/-2) configure.ac (+1/-0) data/providers/nextcloud.provider.in.in (+13/-0) debian/account-plugin-nextcloud.install (+3/-0) debian/account-plugin-owncloud.install (+0/-1) debian/changelog (+10/-0) debian/control (+9/-0) qml/Makefile.am (+2/-0) qml/nextcloud/Main.qml (+27/-0) qml/nextcloud/NewAccount.qml (+234/-0) |
||||
To merge this branch: | bzr merge lp:~mardy/account-plugins/nextcloud-1639175 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Online Accounts | Pending | ||
Review via email: mp+310522@code.launchpad.net |
Commit message
Description of the change
Add account plugin for Nextcloud
To post a comment you must log in.
- 183. By Alberto Mardegan
-
Improve nextcloud icon
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file '.bzrignore' | |||
2 | --- .bzrignore 2016-06-16 11:48:50 +0000 | |||
3 | +++ .bzrignore 2016-11-10 13:53:58 +0000 | |||
4 | @@ -21,6 +21,7 @@ | |||
5 | 21 | configure | 21 | configure |
6 | 22 | compile | 22 | compile |
7 | 23 | /data/providers/*.provider.in | 23 | /data/providers/*.provider.in |
8 | 24 | /debian/*-stamp | ||
9 | 24 | /debian/account-plugin-facebook/ | 25 | /debian/account-plugin-facebook/ |
10 | 25 | /debian/account-plugin-flickr/ | 26 | /debian/account-plugin-flickr/ |
11 | 26 | /debian/account-plugin-foursquare/ | 27 | /debian/account-plugin-foursquare/ |
12 | @@ -28,7 +29,11 @@ | |||
13 | 28 | /debian/account-plugin-google/ | 29 | /debian/account-plugin-google/ |
14 | 29 | /debian/account-plugin-icons/ | 30 | /debian/account-plugin-icons/ |
15 | 30 | /debian/account-plugin-identica/ | 31 | /debian/account-plugin-identica/ |
16 | 32 | /debian/account-plugin-instagram/ | ||
17 | 33 | /debian/account-plugin-linkedin/ | ||
18 | 31 | /debian/account-plugin-mcloud/ | 34 | /debian/account-plugin-mcloud/ |
19 | 35 | /debian/account-plugin-microsoft/ | ||
20 | 36 | /debian/account-plugin-nextcloud/ | ||
21 | 32 | /debian/account-plugin-owncloud/ | 37 | /debian/account-plugin-owncloud/ |
22 | 33 | /debian/account-plugin-sina/ | 38 | /debian/account-plugin-sina/ |
23 | 34 | /debian/account-plugin-sohu/ | 39 | /debian/account-plugin-sohu/ |
24 | @@ -39,6 +44,11 @@ | |||
25 | 39 | /debian/autoreconf.after | 44 | /debian/autoreconf.after |
26 | 40 | /debian/autoreconf.before | 45 | /debian/autoreconf.before |
27 | 41 | /debian/files | 46 | /debian/files |
28 | 47 | /debian/libaccount-plugin-facebook/ | ||
29 | 48 | /debian/libaccount-plugin-flickr/ | ||
30 | 49 | /debian/libaccount-plugin-generic-oauth/ | ||
31 | 50 | /debian/libaccount-plugin-google/ | ||
32 | 51 | /debian/libaccount-plugin-twitter/ | ||
33 | 42 | /debian/tmp/ | 52 | /debian/tmp/ |
34 | 43 | depcomp | 53 | depcomp |
35 | 44 | install-sh | 54 | install-sh |
36 | 45 | 55 | ||
37 | === modified file 'Makefile.am' | |||
38 | --- Makefile.am 2016-11-10 13:53:58 +0000 | |||
39 | +++ Makefile.am 2016-11-10 13:53:58 +0000 | |||
40 | @@ -91,6 +91,7 @@ | |||
41 | 91 | data/providers/instagram.provider.in.in \ | 91 | data/providers/instagram.provider.in.in \ |
42 | 92 | data/providers/mcloud.provider.in.in \ | 92 | data/providers/mcloud.provider.in.in \ |
43 | 93 | data/providers/microsoft.provider.in.in \ | 93 | data/providers/microsoft.provider.in.in \ |
44 | 94 | data/providers/nextcloud.provider.in.in \ | ||
45 | 94 | data/providers/owncloud.provider.in.in \ | 95 | data/providers/owncloud.provider.in.in \ |
46 | 95 | data/providers/sina.provider.in.in \ | 96 | data/providers/sina.provider.in.in \ |
47 | 96 | data/providers/sohu.provider.in.in \ | 97 | data/providers/sohu.provider.in.in \ |
48 | @@ -137,12 +138,12 @@ | |||
49 | 137 | 138 | ||
50 | 138 | # Temporary until these bugs are fixed: | 139 | # Temporary until these bugs are fixed: |
51 | 139 | # https://bugs.launchpad.net/bugs/1567908 | 140 | # https://bugs.launchpad.net/bugs/1567908 |
53 | 140 | # https://bugs.launchpad.net/bugs/1571587 | 141 | # https://bugs.launchpad.net/bugs/1640704 |
54 | 141 | iconsdir = $(datadir)/icons/hicolor/32x32/apps | 142 | iconsdir = $(datadir)/icons/hicolor/32x32/apps |
55 | 142 | dist_icons_DATA = \ | 143 | dist_icons_DATA = \ |
56 | 143 | data/icons/mcloud.png \ | 144 | data/icons/mcloud.png \ |
57 | 144 | data/icons/microsoft.png \ | 145 | data/icons/microsoft.png \ |
59 | 145 | data/icons/owncloud.png \ | 146 | data/icons/nextcloud.png \ |
60 | 146 | data/icons/vk.png | 147 | data/icons/vk.png |
61 | 147 | 148 | ||
62 | 148 | dist_bin_SCRIPTS = \ | 149 | dist_bin_SCRIPTS = \ |
63 | 149 | 150 | ||
64 | === modified file 'configure.ac' | |||
65 | --- configure.ac 2016-11-10 13:53:58 +0000 | |||
66 | +++ configure.ac 2016-11-10 13:53:58 +0000 | |||
67 | @@ -268,6 +268,7 @@ | |||
68 | 268 | data/providers/instagram.provider.in | 268 | data/providers/instagram.provider.in |
69 | 269 | data/providers/mcloud.provider.in | 269 | data/providers/mcloud.provider.in |
70 | 270 | data/providers/microsoft.provider.in | 270 | data/providers/microsoft.provider.in |
71 | 271 | data/providers/nextcloud.provider.in | ||
72 | 271 | data/providers/owncloud.provider.in | 272 | data/providers/owncloud.provider.in |
73 | 272 | data/providers/sina.provider.in | 273 | data/providers/sina.provider.in |
74 | 273 | data/providers/sohu.provider.in | 274 | data/providers/sohu.provider.in |
75 | 274 | 275 | ||
76 | === added file 'data/icons/nextcloud.png' | |||
77 | 275 | Binary files data/icons/nextcloud.png 1970-01-01 00:00:00 +0000 and data/icons/nextcloud.png 2016-11-10 13:53:58 +0000 differ | 276 | Binary files data/icons/nextcloud.png 1970-01-01 00:00:00 +0000 and data/icons/nextcloud.png 2016-11-10 13:53:58 +0000 differ |
78 | === added file 'data/providers/nextcloud.provider.in.in' | |||
79 | --- data/providers/nextcloud.provider.in.in 1970-01-01 00:00:00 +0000 | |||
80 | +++ data/providers/nextcloud.provider.in.in 2016-11-10 13:53:58 +0000 | |||
81 | @@ -0,0 +1,13 @@ | |||
82 | 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
83 | 2 | <provider id="nextcloud"> | ||
84 | 3 | <name>Nextcloud</name> | ||
85 | 4 | <icon>nextcloud</icon> | ||
86 | 5 | <translations>account-plugins</translations> | ||
87 | 6 | |||
88 | 7 | <template> | ||
89 | 8 | <group name="auth"> | ||
90 | 9 | <setting name="method">password</setting> | ||
91 | 10 | <setting name="mechanism">password</setting> | ||
92 | 11 | </group> | ||
93 | 12 | </template> | ||
94 | 13 | </provider> | ||
95 | 0 | 14 | ||
96 | === added file 'debian/account-plugin-nextcloud.install' | |||
97 | --- debian/account-plugin-nextcloud.install 1970-01-01 00:00:00 +0000 | |||
98 | +++ debian/account-plugin-nextcloud.install 2016-11-10 13:53:58 +0000 | |||
99 | @@ -0,0 +1,3 @@ | |||
100 | 1 | usr/share/accounts/providers/nextcloud.provider | ||
101 | 2 | usr/share/accounts/qml-plugins/nextcloud/*.qml | ||
102 | 3 | usr/share/icons/hicolor/32x32/apps/nextcloud.png | ||
103 | 0 | 4 | ||
104 | === modified file 'debian/account-plugin-owncloud.install' | |||
105 | --- debian/account-plugin-owncloud.install 2016-08-01 15:50:48 +0000 | |||
106 | +++ debian/account-plugin-owncloud.install 2016-11-10 13:53:58 +0000 | |||
107 | @@ -1,3 +1,2 @@ | |||
108 | 1 | usr/share/accounts/providers/owncloud.provider | 1 | usr/share/accounts/providers/owncloud.provider |
109 | 2 | usr/share/accounts/qml-plugins/owncloud/*.qml | 2 | usr/share/accounts/qml-plugins/owncloud/*.qml |
110 | 3 | usr/share/icons/hicolor/32x32/apps/owncloud.png | ||
111 | 4 | 3 | ||
112 | === modified file 'debian/changelog' | |||
113 | --- debian/changelog 2016-09-29 09:23:40 +0000 | |||
114 | +++ debian/changelog 2016-11-10 13:53:58 +0000 | |||
115 | @@ -1,3 +1,13 @@ | |||
116 | 1 | account-plugins (0.13+16.10.20160929.1-0ubuntu2) UNRELEASED; urgency=medium | ||
117 | 2 | |||
118 | 3 | * debian/account-plugin-owncloud.install: | ||
119 | 4 | - remove owncloud icon, it's now provided by the theme | ||
120 | 5 | * debian/control,debian/account-plugin-nextcloud.install: | ||
121 | 6 | - add Nextcloud account plugin | ||
122 | 7 | * Add account plugin for Nextcloud (LP: #1639175) | ||
123 | 8 | |||
124 | 9 | -- Alberto Mardegan <alberto.mardegan@canonical.com> Thu, 10 Nov 2016 11:43:37 +0300 | ||
125 | 10 | |||
126 | 1 | account-plugins (0.13+16.10.20160929.1-0ubuntu1) yakkety; urgency=medium | 11 | account-plugins (0.13+16.10.20160929.1-0ubuntu1) yakkety; urgency=medium |
127 | 2 | 12 | ||
128 | 3 | * Owncloud: properly encode username and password in POST request (LP: | 13 | * Owncloud: properly encode username and password in POST request (LP: |
129 | 4 | 14 | ||
130 | === modified file 'debian/control' | |||
131 | --- debian/control 2016-11-10 13:53:58 +0000 | |||
132 | +++ debian/control 2016-11-10 13:53:58 +0000 | |||
133 | @@ -163,6 +163,15 @@ | |||
134 | 163 | This plugin adds support for creating microsoft accounts in the Unity Control | 163 | This plugin adds support for creating microsoft accounts in the Unity Control |
135 | 164 | Center | 164 | Center |
136 | 165 | 165 | ||
137 | 166 | Package: account-plugin-nextcloud | ||
138 | 167 | Architecture: all | ||
139 | 168 | Depends: ${misc:Depends}, | ||
140 | 169 | signon-plugin-password, | ||
141 | 170 | ubuntu-system-settings-online-accounts, | ||
142 | 171 | Description: Online account plugin for Unity - Nextcloud | ||
143 | 172 | This plugin adds support for creating Nextcloud accounts in the Unity Control | ||
144 | 173 | Center | ||
145 | 174 | |||
146 | 166 | Package: account-plugin-owncloud | 175 | Package: account-plugin-owncloud |
147 | 167 | Architecture: all | 176 | Architecture: all |
148 | 168 | Depends: ${misc:Depends}, | 177 | Depends: ${misc:Depends}, |
149 | 169 | 178 | ||
150 | === modified file 'qml/Makefile.am' | |||
151 | --- qml/Makefile.am 2016-11-10 13:53:58 +0000 | |||
152 | +++ qml/Makefile.am 2016-11-10 13:53:58 +0000 | |||
153 | @@ -4,6 +4,8 @@ | |||
154 | 4 | google/Main.qml \ | 4 | google/Main.qml \ |
155 | 5 | mcloud/Main.qml \ | 5 | mcloud/Main.qml \ |
156 | 6 | microsoft/Main.qml \ | 6 | microsoft/Main.qml \ |
157 | 7 | nextcloud/Main.qml \ | ||
158 | 8 | nextcloud/NewAccount.qml \ | ||
159 | 7 | owncloud/Main.qml \ | 9 | owncloud/Main.qml \ |
160 | 8 | owncloud/NewAccount.qml \ | 10 | owncloud/NewAccount.qml \ |
161 | 9 | twitter/Main.qml \ | 11 | twitter/Main.qml \ |
162 | 10 | 12 | ||
163 | === added directory 'qml/nextcloud' | |||
164 | === added file 'qml/nextcloud/Main.qml' | |||
165 | --- qml/nextcloud/Main.qml 1970-01-01 00:00:00 +0000 | |||
166 | +++ qml/nextcloud/Main.qml 2016-11-10 13:53:58 +0000 | |||
167 | @@ -0,0 +1,27 @@ | |||
168 | 1 | import QtQuick 2.0 | ||
169 | 2 | import Ubuntu.OnlineAccounts.Plugin 1.0 | ||
170 | 3 | |||
171 | 4 | Flickable { | ||
172 | 5 | id: root | ||
173 | 6 | |||
174 | 7 | property int keyboardSize: Qt.inputMethod.visible ? Qt.inputMethod.keyboardRectangle.height : 0 | ||
175 | 8 | contentHeight: loader.item.height + keyboardSize | ||
176 | 9 | |||
177 | 10 | signal finished | ||
178 | 11 | |||
179 | 12 | Loader { | ||
180 | 13 | id: loader | ||
181 | 14 | anchors.fill: parent | ||
182 | 15 | sourceComponent: newAccountComponent | ||
183 | 16 | |||
184 | 17 | Connections { | ||
185 | 18 | target: loader.item | ||
186 | 19 | onFinished: root.finished() | ||
187 | 20 | } | ||
188 | 21 | } | ||
189 | 22 | |||
190 | 23 | Component { | ||
191 | 24 | id: newAccountComponent | ||
192 | 25 | NewAccount {} | ||
193 | 26 | } | ||
194 | 27 | } | ||
195 | 0 | 28 | ||
196 | === added file 'qml/nextcloud/NewAccount.qml' | |||
197 | --- qml/nextcloud/NewAccount.qml 1970-01-01 00:00:00 +0000 | |||
198 | +++ qml/nextcloud/NewAccount.qml 2016-11-10 13:53:58 +0000 | |||
199 | @@ -0,0 +1,234 @@ | |||
200 | 1 | import QtQuick 2.0 | ||
201 | 2 | import Ubuntu.Components 1.3 | ||
202 | 3 | import Ubuntu.OnlineAccounts 0.1 | ||
203 | 4 | |||
204 | 5 | Item { | ||
205 | 6 | id: root | ||
206 | 7 | |||
207 | 8 | signal finished | ||
208 | 9 | |||
209 | 10 | height: contents.height | ||
210 | 11 | |||
211 | 12 | property var __account: account | ||
212 | 13 | property string __host: "" | ||
213 | 14 | property bool __busy: false | ||
214 | 15 | property string __hostError: i18n.dtr("account-plugins", "Invalid host URL") | ||
215 | 16 | |||
216 | 17 | Column { | ||
217 | 18 | id: contents | ||
218 | 19 | anchors { | ||
219 | 20 | top: parent.top | ||
220 | 21 | left: parent.left | ||
221 | 22 | right: parent.right | ||
222 | 23 | margins: units.gu(2) | ||
223 | 24 | } | ||
224 | 25 | spacing: units.gu(2) | ||
225 | 26 | |||
226 | 27 | Label { | ||
227 | 28 | id: errorLabel | ||
228 | 29 | anchors { left: parent.left; right: parent.right } | ||
229 | 30 | font.bold: true | ||
230 | 31 | color: UbuntuColors.red | ||
231 | 32 | wrapMode: Text.Wrap | ||
232 | 33 | visible: !__busy && text != "" | ||
233 | 34 | } | ||
234 | 35 | |||
235 | 36 | Label { | ||
236 | 37 | anchors { left: parent.left; right: parent.right } | ||
237 | 38 | text: i18n.dtr("account-plugins", "URL:") | ||
238 | 39 | } | ||
239 | 40 | |||
240 | 41 | TextField { | ||
241 | 42 | id: urlField | ||
242 | 43 | anchors { left: parent.left; right: parent.right } | ||
243 | 44 | placeholderText: i18n.dtr("account-plugins", "http://myserver.com/nextcloud") | ||
244 | 45 | focus: true | ||
245 | 46 | enabled: !__busy | ||
246 | 47 | |||
247 | 48 | inputMethodHints: Qt.ImhUrlCharactersOnly | ||
248 | 49 | } | ||
249 | 50 | |||
250 | 51 | Label { | ||
251 | 52 | anchors { left: parent.left; right: parent.right } | ||
252 | 53 | text: i18n.dtr("account-plugins", "Username:") | ||
253 | 54 | } | ||
254 | 55 | |||
255 | 56 | TextField { | ||
256 | 57 | id: usernameField | ||
257 | 58 | anchors { left: parent.left; right: parent.right } | ||
258 | 59 | placeholderText: i18n.dtr("account-plugins", "Your username") | ||
259 | 60 | enabled: !__busy | ||
260 | 61 | inputMethodHints: Qt.ImhNoAutoUppercase + Qt.ImhNoPredictiveText + Qt.ImhPreferLowercase | ||
261 | 62 | |||
262 | 63 | KeyNavigation.tab: passwordField | ||
263 | 64 | } | ||
264 | 65 | |||
265 | 66 | Label { | ||
266 | 67 | anchors { left: parent.left; right: parent.right } | ||
267 | 68 | text: i18n.dtr("account-plugins", "Password:") | ||
268 | 69 | } | ||
269 | 70 | |||
270 | 71 | TextField { | ||
271 | 72 | id: passwordField | ||
272 | 73 | anchors { left: parent.left; right: parent.right } | ||
273 | 74 | placeholderText: i18n.dtr("account-plugins", "Your password") | ||
274 | 75 | echoMode: TextInput.Password | ||
275 | 76 | enabled: !__busy | ||
276 | 77 | |||
277 | 78 | inputMethodHints: Qt.ImhSensitiveData | ||
278 | 79 | Keys.onReturnPressed: login() | ||
279 | 80 | } | ||
280 | 81 | |||
281 | 82 | Row { | ||
282 | 83 | id: buttons | ||
283 | 84 | anchors { left: parent.left; right: parent.right } | ||
284 | 85 | height: units.gu(5) | ||
285 | 86 | spacing: units.gu(1) | ||
286 | 87 | Button { | ||
287 | 88 | id: btnCancel | ||
288 | 89 | text: i18n.dtr("account-plugins", "Cancel") | ||
289 | 90 | height: parent.height | ||
290 | 91 | width: (parent.width / 2) - 0.5 * parent.spacing | ||
291 | 92 | onClicked: finished() | ||
292 | 93 | } | ||
293 | 94 | Button { | ||
294 | 95 | id: btnContinue | ||
295 | 96 | text: i18n.dtr("account-plugins", "Continue") | ||
296 | 97 | color: UbuntuColors.green | ||
297 | 98 | height: parent.height | ||
298 | 99 | width: (parent.width / 2) - 0.5 * parent.spacing | ||
299 | 100 | onClicked: login() | ||
300 | 101 | enabled: !__busy | ||
301 | 102 | } | ||
302 | 103 | } | ||
303 | 104 | } | ||
304 | 105 | |||
305 | 106 | ActivityIndicator { | ||
306 | 107 | anchors.centerIn: parent | ||
307 | 108 | running: __busy | ||
308 | 109 | } | ||
309 | 110 | |||
310 | 111 | Credentials { | ||
311 | 112 | id: creds | ||
312 | 113 | caption: account.provider.id | ||
313 | 114 | acl: [ "unconfined" ] | ||
314 | 115 | storeSecret: true | ||
315 | 116 | onCredentialsIdChanged: root.credentialsStored() | ||
316 | 117 | } | ||
317 | 118 | |||
318 | 119 | AccountService { | ||
319 | 120 | id: globalAccountSettings | ||
320 | 121 | objectHandle: account.accountServiceHandle | ||
321 | 122 | autoSync: false | ||
322 | 123 | } | ||
323 | 124 | |||
324 | 125 | function login() { | ||
325 | 126 | __host = cleanUrl(urlField.text) | ||
326 | 127 | var username = usernameField.text | ||
327 | 128 | var password = passwordField.text | ||
328 | 129 | |||
329 | 130 | errorLabel.text = "" | ||
330 | 131 | __busy = true | ||
331 | 132 | var host = __host | ||
332 | 133 | var tryHttp = false | ||
333 | 134 | if (__host.indexOf("http") != 0) { | ||
334 | 135 | host = "https://" + __host | ||
335 | 136 | tryHttp = true | ||
336 | 137 | } | ||
337 | 138 | |||
338 | 139 | checkAccount(host, username, password, function cb(success) { | ||
339 | 140 | console.log("callback called: " + success) | ||
340 | 141 | if (success) { | ||
341 | 142 | saveData(host, username, password) | ||
342 | 143 | } else if (tryHttp) { | ||
343 | 144 | host = "http://" + __host | ||
344 | 145 | tryHttp = false | ||
345 | 146 | checkAccount(host, username, password, cb) | ||
346 | 147 | } else { | ||
347 | 148 | __busy = false | ||
348 | 149 | } | ||
349 | 150 | }) | ||
350 | 151 | } | ||
351 | 152 | |||
352 | 153 | function saveData(host, username, password) { | ||
353 | 154 | __host = host | ||
354 | 155 | var strippedHost = __host.replace(/^https?:\/\//, '') | ||
355 | 156 | account.updateDisplayName(username + '@' + strippedHost) | ||
356 | 157 | creds.userName = username | ||
357 | 158 | creds.secret = password | ||
358 | 159 | creds.sync() | ||
359 | 160 | } | ||
360 | 161 | |||
361 | 162 | function findChild(node, tagName) { | ||
362 | 163 | if (!node) return node; | ||
363 | 164 | var children = node.childNodes | ||
364 | 165 | for (var i = 0; i < children.length; i++) { | ||
365 | 166 | if (children[i].nodeName == tagName) { | ||
366 | 167 | return children[i] | ||
367 | 168 | } | ||
368 | 169 | } | ||
369 | 170 | return null | ||
370 | 171 | } | ||
371 | 172 | |||
372 | 173 | function checkAccount(host, username, password, callback) { | ||
373 | 174 | console.log("Trying host " + host + " as " + username + ':' + password) | ||
374 | 175 | var request = new XMLHttpRequest(); | ||
375 | 176 | request.onreadystatechange = function() { | ||
376 | 177 | if (request.readyState === XMLHttpRequest.DONE) { | ||
377 | 178 | console.log("response: " + request.responseText) | ||
378 | 179 | if (request.status == 200) { | ||
379 | 180 | var root = request.responseXML ? request.responseXML.documentElement : null | ||
380 | 181 | var metaElement = findChild(root, "meta") | ||
381 | 182 | var statusElement = findChild(metaElement, "status") | ||
382 | 183 | if (statusElement && statusElement.childNodes.length > 0 && | ||
383 | 184 | statusElement.childNodes[0].nodeValue == "ok") { | ||
384 | 185 | callback(true) | ||
385 | 186 | } else { | ||
386 | 187 | var statusCodeElement = findChild(metaElement, "statuscode") | ||
387 | 188 | var statusCode = (statusCodeElement && statusCodeElement.childNodes.length > 0) ? | ||
388 | 189 | statusCodeElement.childNodes[0].nodeValue : "999" | ||
389 | 190 | if (statusCode == "999") { | ||
390 | 191 | showError(__hostError) | ||
391 | 192 | } else { | ||
392 | 193 | showError(i18n.dtr("account-plugins", "Invalid username or password")) | ||
393 | 194 | } | ||
394 | 195 | callback(false) | ||
395 | 196 | } | ||
396 | 197 | } else { | ||
397 | 198 | showError(__hostError) | ||
398 | 199 | callback(false) | ||
399 | 200 | } | ||
400 | 201 | } | ||
401 | 202 | } | ||
402 | 203 | request.open("POST", host + "/ocs/v1.php/person/check", true); | ||
403 | 204 | request.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); | ||
404 | 205 | var body = "login=" + encodeURIComponent(username) + "&password=" + encodeURIComponent(password) | ||
405 | 206 | request.send(body); | ||
406 | 207 | } | ||
407 | 208 | |||
408 | 209 | function showError(message) { | ||
409 | 210 | if (!errorLabel.text) errorLabel.text = message | ||
410 | 211 | } | ||
411 | 212 | |||
412 | 213 | function credentialsStored() { | ||
413 | 214 | console.log("Credentials stored, id: " + creds.credentialsId) | ||
414 | 215 | if (creds.credentialsId == 0) return | ||
415 | 216 | |||
416 | 217 | globalAccountSettings.updateServiceEnabled(true) | ||
417 | 218 | globalAccountSettings.credentials = creds | ||
418 | 219 | globalAccountSettings.updateSettings({ | ||
419 | 220 | "host": __host | ||
420 | 221 | }) | ||
421 | 222 | account.synced.connect(finished) | ||
422 | 223 | account.sync() | ||
423 | 224 | __busy = false | ||
424 | 225 | } | ||
425 | 226 | |||
426 | 227 | // check host url for http | ||
427 | 228 | function cleanUrl(url) { | ||
428 | 229 | var host = url.trim() | ||
429 | 230 | // if the user typed trailing '/' or "index.php", strip that | ||
430 | 231 | return host.replace(/\/(index.php)?\/*$/, '') | ||
431 | 232 | } | ||
432 | 233 | |||
433 | 234 | } |