Merge lp:~mardy/account-plugins/owncloud-1570986 into lp:account-plugins

Proposed by Alberto Mardegan on 2016-04-20
Status: Merged
Approved by: David Barth on 2016-05-31
Approved revision: 161
Merged at revision: 159
Proposed branch: lp:~mardy/account-plugins/owncloud-1570986
Merge into: lp:account-plugins
Diff against target: 511 lines (+381/-2)
13 files modified
.bzrignore (+2/-0)
Makefile.am (+10/-0)
configure.ac (+10/-0)
data/providers/owncloud.provider.in.in (+13/-0)
data/providers/vk.provider.in.in (+26/-0)
debian/account-plugin-owncloud.install (+3/-0)
debian/account-plugin-vk.install (+3/-0)
debian/control (+15/-0)
debian/rules (+2/-1)
qml/Makefile.am (+4/-1)
qml/owncloud/Main.qml (+27/-0)
qml/owncloud/NewAccount.qml (+230/-0)
qml/vk/Main.qml (+36/-0)
To merge this branch: bzr merge lp:~mardy/account-plugins/owncloud-1570986
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve on 2016-04-20
Online Accounts 2016-04-20 Pending
Review via email: mp+292358@code.launchpad.net

Commit message

Add ownCloud plugin

Description of the change

Add ownCloud plugin

Testing instructions:
1) manually install the account-plugin-ownloud package
2) download and install the click package from http://www.mardy.it/archivos/owncloud-bookmarks.mardy_0.1_armhf.click
3) create an owncloud account from the system settings
4) if you have the bookmarks app enabled in your owncloud installation and some bookmarks saved in it, you can run the click package and it will show the list of bookmarks.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bzrignore'
2--- .bzrignore 2013-03-19 08:52:34 +0000
3+++ .bzrignore 2016-04-20 10:17:48 +0000
4@@ -27,10 +27,12 @@
5 /debian/account-plugin-google/
6 /debian/account-plugin-icons/
7 /debian/account-plugin-identica/
8+/debian/account-plugin-owncloud/
9 /debian/account-plugin-sina/
10 /debian/account-plugin-sohu/
11 /debian/account-plugin-tools/
12 /debian/account-plugin-twitter/
13+/debian/account-plugin-vk/
14 /debian/account-plugin-windows-live/
15 /debian/autoreconf.after
16 /debian/autoreconf.before
17
18=== modified file 'Makefile.am'
19--- Makefile.am 2015-04-17 08:53:11 +0000
20+++ Makefile.am 2016-04-20 10:17:48 +0000
21@@ -66,9 +66,11 @@
22 data/providers/identica.provider.in.in \
23 data/providers/linkedin.provider.in.in \
24 data/providers/instagram.provider.in.in \
25+ data/providers/owncloud.provider.in.in \
26 data/providers/sina.provider.in.in \
27 data/providers/sohu.provider.in.in \
28 data/providers/twitter.provider.in.in \
29+ data/providers/vk.provider.in.in \
30 data/providers/windows-live.provider.in.in
31
32 providers_DATA = \
33@@ -112,6 +114,14 @@
34 data/webkit-options/www.facebook.com.conf \
35 data/webkit-options/www.linkedin.com.conf
36
37+# Temporary until these bugs are fixed:
38+# https://bugs.launchpad.net/bugs/1567908
39+# https://bugs.launchpad.net/bugs/1571587
40+iconsdir = $(datadir)/icons/hicolor/32x32/apps
41+dist_icons_DATA = \
42+ data/icons/owncloud.png \
43+ data/icons/vk.png
44+
45 dist_bin_SCRIPTS = \
46 tools/account-console
47
48
49=== modified file 'configure.ac'
50--- configure.ac 2014-09-11 10:07:28 +0000
51+++ configure.ac 2016-04-20 10:17:48 +0000
52@@ -225,6 +225,14 @@
53 AC_SUBST(SOHU_CLIENT_ID, ["$sohu_client_id"])
54 AC_SUBST(SOHU_CLIENT_SECRET, ["$sohu_client_secret"])
55
56+# Set VK client id
57+AC_ARG_WITH(vk-client-id,
58+ [AS_HELP_STRING([--with-vk-client-id],
59+ [VK client ID])],
60+ [vk_client_id=$withval],
61+ [vk_client_id="5404010"])
62+AC_SUBST(VK_CLIENT_ID, ["$vk_client_id"])
63+
64 # Set Windows Live client id
65 AC_ARG_WITH(windows-live-client-id,
66 [AS_HELP_STRING([--with-windows-live-client-id],
67@@ -241,9 +249,11 @@
68 data/providers/identica.provider.in
69 data/providers/linkedin.provider.in
70 data/providers/instagram.provider.in
71+ data/providers/owncloud.provider.in
72 data/providers/sina.provider.in
73 data/providers/sohu.provider.in
74 data/providers/twitter.provider.in
75+ data/providers/vk.provider.in
76 data/providers/windows-live.provider.in
77 Makefile
78 po/Makefile.in
79
80=== added directory 'data/icons'
81=== added file 'data/icons/owncloud.png'
82Binary files data/icons/owncloud.png 1970-01-01 00:00:00 +0000 and data/icons/owncloud.png 2016-04-20 10:17:48 +0000 differ
83=== added file 'data/icons/vk.png'
84Binary files data/icons/vk.png 1970-01-01 00:00:00 +0000 and data/icons/vk.png 2016-04-20 10:17:48 +0000 differ
85=== added file 'data/providers/owncloud.provider.in.in'
86--- data/providers/owncloud.provider.in.in 1970-01-01 00:00:00 +0000
87+++ data/providers/owncloud.provider.in.in 2016-04-20 10:17:48 +0000
88@@ -0,0 +1,13 @@
89+<?xml version="1.0" encoding="UTF-8"?>
90+<provider id="owncloud">
91+ <name>ownCloud</name>
92+ <icon>owncloud.png</icon>
93+ <translations>account-plugins</translations>
94+
95+ <template>
96+ <group name="auth">
97+ <setting name="method">password</setting>
98+ <setting name="mechanism">password</setting>
99+ </group>
100+ </template>
101+</provider>
102
103=== added file 'data/providers/vk.provider.in.in'
104--- data/providers/vk.provider.in.in 1970-01-01 00:00:00 +0000
105+++ data/providers/vk.provider.in.in 2016-04-20 10:17:48 +0000
106@@ -0,0 +1,26 @@
107+<?xml version="1.0" encoding="UTF-8"?>
108+<provider id="vk">
109+ <name>VKontakte</name>
110+ <icon>vk</icon>
111+ <translations>account-plugins</translations>
112+ <domains>.*vk\.com</domains>
113+
114+ <template>
115+ <group name="auth">
116+ <setting name="method">oauth2</setting>
117+ <setting name="mechanism">user_agent</setting>
118+ <group name="oauth2">
119+ <group name="user_agent">
120+ <setting name="Host">oauth.vk.com</setting>
121+ <setting name="AuthPath">authorize</setting>
122+ <setting name="TokenPath">access_token</setting>
123+ <setting name="RedirectUri">https://oauth.vk.com/blank.html</setting>
124+ <setting name="ResponseType">token</setting>
125+ <setting name="ClientId">@VK_CLIENT_ID@</setting>
126+ <setting type="as" name="Scope">['offline']</setting>
127+ <setting type="s" name="v">5.50</setting>
128+ </group>
129+ </group>
130+ </group>
131+ </template>
132+</provider>
133
134=== added file 'debian/account-plugin-owncloud.install'
135--- debian/account-plugin-owncloud.install 1970-01-01 00:00:00 +0000
136+++ debian/account-plugin-owncloud.install 2016-04-20 10:17:48 +0000
137@@ -0,0 +1,3 @@
138+usr/share/accounts/providers/owncloud.provider
139+usr/share/accounts/qml-plugins/owncloud/*.qml
140+usr/share/icons/hicolor/32x32/apps/owncloud.png
141
142=== added file 'debian/account-plugin-vk.install'
143--- debian/account-plugin-vk.install 1970-01-01 00:00:00 +0000
144+++ debian/account-plugin-vk.install 2016-04-20 10:17:48 +0000
145@@ -0,0 +1,3 @@
146+usr/share/accounts/providers/vk.provider
147+usr/share/accounts/qml-plugins/vk/Main.qml
148+usr/share/icons/hicolor/32x32/apps/vk.png
149
150=== modified file 'debian/control'
151--- debian/control 2015-07-23 14:10:26 +0000
152+++ debian/control 2016-04-20 10:17:48 +0000
153@@ -121,6 +121,21 @@
154 Description: GNOME Control Center account plugin for single signon - Instagram
155 GNOME Control Center account plugins for single signon
156
157+Package: account-plugin-owncloud
158+Architecture: all
159+Depends: ${misc:Depends},
160+ ubuntu-system-settings-online-accounts,
161+Description: Account plugin for online accounts - ownCloud
162+ Online Accounts plugin provide the user interface to create accounts for
163+ third party services.
164+
165+Package: account-plugin-vk
166+Architecture: all
167+Depends: ${misc:Depends},
168+ libaccount-plugin-generic-oauth | ubuntu-system-settings-online-accounts,
169+Description: GNOME Control Center account plugin for single signon - VKontakte
170+ GNOME Control Center account plugins for single signon
171+
172 Package: account-plugin-tools
173 Architecture: all
174 Depends: ${misc:Depends},
175
176=== modified file 'debian/rules'
177--- debian/rules 2015-07-23 14:10:26 +0000
178+++ debian/rules 2016-04-20 10:17:48 +0000
179@@ -21,7 +21,8 @@
180 --with-linkedin-consumer-key="34gnzrg96iq5" \
181 --with-linkedin-consumer-secret="BazRki2LE8eZtcqh" \
182 --with-instagram-client-id="01c3df41a2274a14882adea8e8ebbd46" \
183- --with-instagram-client-secret="4751ccdc39c648719ea83cfb1c866c26"
184+ --with-instagram-client-secret="4751ccdc39c648719ea83cfb1c866c26" \
185+ --with-vk-client-id="5402699"
186
187 override_dh_install:
188 rm -f debian/*/usr/lib/*/*/*.la
189
190=== modified file 'qml/Makefile.am'
191--- qml/Makefile.am 2013-06-07 11:56:25 +0000
192+++ qml/Makefile.am 2016-04-20 10:17:48 +0000
193@@ -2,4 +2,7 @@
194 facebook/Main.qml \
195 flickr/Main.qml \
196 google/Main.qml \
197- twitter/Main.qml
198+ owncloud/Main.qml \
199+ owncloud/NewAccount.qml \
200+ twitter/Main.qml \
201+ vk/Main.qml
202
203=== added directory 'qml/owncloud'
204=== added file 'qml/owncloud/Main.qml'
205--- qml/owncloud/Main.qml 1970-01-01 00:00:00 +0000
206+++ qml/owncloud/Main.qml 2016-04-20 10:17:48 +0000
207@@ -0,0 +1,27 @@
208+import QtQuick 2.0
209+import Ubuntu.OnlineAccounts.Plugin 1.0
210+
211+Flickable {
212+ id: root
213+
214+ property int keyboardSize: Qt.inputMethod.visible ? Qt.inputMethod.keyboardRectangle.height : 0
215+ contentHeight: loader.item.height + keyboardSize
216+
217+ signal finished
218+
219+ Loader {
220+ id: loader
221+ anchors.fill: parent
222+ sourceComponent: newAccountComponent
223+
224+ Connections {
225+ target: loader.item
226+ onFinished: root.finished()
227+ }
228+ }
229+
230+ Component {
231+ id: newAccountComponent
232+ NewAccount {}
233+ }
234+}
235
236=== added file 'qml/owncloud/NewAccount.qml'
237--- qml/owncloud/NewAccount.qml 1970-01-01 00:00:00 +0000
238+++ qml/owncloud/NewAccount.qml 2016-04-20 10:17:48 +0000
239@@ -0,0 +1,230 @@
240+import QtQuick 2.0
241+import Ubuntu.Components 1.3
242+import Ubuntu.OnlineAccounts 0.1
243+
244+Item {
245+ id: root
246+
247+ signal finished
248+
249+ anchors.margins: units.gu(1)
250+ height: contents.height
251+
252+ property var __account: account
253+ property string __host: ""
254+ property bool __busy: false
255+ property string __hostError: i18n.dtr("account-plugins", "Invalid host URL")
256+
257+ Column {
258+ id: contents
259+ anchors { left: parent.left; right: parent.right }
260+ spacing: units.gu(1)
261+
262+ Label {
263+ id: errorLabel
264+ anchors { left: parent.left; right: parent.right }
265+ font.bold: true
266+ color: UbuntuColors.red
267+ wrapMode: Text.Wrap
268+ visible: !__busy && text != ""
269+ }
270+
271+ Label {
272+ anchors { left: parent.left; right: parent.right }
273+ text: i18n.dtr("account-plugins", "URL:")
274+ }
275+
276+ TextField {
277+ id: urlField
278+ anchors { left: parent.left; right: parent.right }
279+ placeholderText: i18n.dtr("account-plugins", "http://example.org")
280+ focus: true
281+ enabled: !__busy
282+
283+ inputMethodHints: Qt.ImhUrlCharactersOnly
284+ }
285+
286+ Label {
287+ anchors { left: parent.left; right: parent.right }
288+ text: i18n.dtr("account-plugins", "Username:")
289+ }
290+
291+ TextField {
292+ id: usernameField
293+ anchors { left: parent.left; right: parent.right }
294+ placeholderText: i18n.dtr("account-plugins", "Your username")
295+ enabled: !__busy
296+ inputMethodHints: Qt.ImhNoAutoUppercase + Qt.ImhNoPredictiveText + Qt.ImhPreferLowercase
297+
298+ KeyNavigation.tab: passwordField
299+ }
300+
301+ Label {
302+ anchors { left: parent.left; right: parent.right }
303+ text: i18n.dtr("account-plugins", "Password:")
304+ }
305+
306+ TextField {
307+ id: passwordField
308+ anchors { left: parent.left; right: parent.right }
309+ placeholderText: i18n.dtr("account-plugins", "Your password")
310+ echoMode: TextInput.Password
311+ enabled: !__busy
312+
313+ inputMethodHints: Qt.ImhSensitiveData
314+ Keys.onReturnPressed: login()
315+ }
316+
317+ Row {
318+ id: buttons
319+ anchors { left: parent.left; right: parent.right }
320+ height: units.gu(5)
321+ spacing: units.gu(1)
322+ Button {
323+ id: btnCancel
324+ text: i18n.dtr("account-plugins", "Cancel")
325+ height: parent.height
326+ width: (parent.width / 2) - 0.5 * parent.spacing
327+ onClicked: finished()
328+ }
329+ Button {
330+ id: btnContinue
331+ text: i18n.dtr("account-plugins", "Continue")
332+ color: UbuntuColors.green
333+ height: parent.height
334+ width: (parent.width / 2) - 0.5 * parent.spacing
335+ onClicked: login()
336+ enabled: !__busy
337+ }
338+ }
339+ }
340+
341+ ActivityIndicator {
342+ anchors.centerIn: parent
343+ running: __busy
344+ }
345+
346+ Credentials {
347+ id: creds
348+ caption: account.provider.id
349+ acl: [ "unconfined" ]
350+ storeSecret: true
351+ onCredentialsIdChanged: root.credentialsStored()
352+ }
353+
354+ AccountService {
355+ id: globalAccountSettings
356+ objectHandle: account.accountServiceHandle
357+ autoSync: false
358+ }
359+
360+ function login() {
361+ __host = cleanUrl(urlField.text)
362+ var username = usernameField.text
363+ var password = passwordField.text
364+
365+ errorLabel.text = ""
366+ __busy = true
367+ var host = __host
368+ var tryHttp = false
369+ if (__host.indexOf("http") != 0) {
370+ host = "https://" + __host
371+ tryHttp = true
372+ }
373+
374+ checkAccount(host, username, password, function cb(success) {
375+ console.log("callback called: " + success)
376+ if (success) {
377+ saveData(host, username, password)
378+ } else if (tryHttp) {
379+ host = "http://" + __host
380+ tryHttp = false
381+ checkAccount(host, username, password, cb)
382+ } else {
383+ __busy = false
384+ }
385+ })
386+ }
387+
388+ function saveData(host, username, password) {
389+ __host = host
390+ var strippedHost = __host.replace(/^https?:\/\//, '')
391+ account.updateDisplayName(username + '@' + strippedHost)
392+ creds.userName = username
393+ creds.secret = password
394+ creds.sync()
395+ }
396+
397+ function findChild(node, tagName) {
398+ if (!node) return node;
399+ var children = node.childNodes
400+ for (var i = 0; i < children.length; i++) {
401+ if (children[i].nodeName == tagName) {
402+ return children[i]
403+ }
404+ }
405+ return null
406+ }
407+
408+ function checkAccount(host, username, password, callback) {
409+ console.log("Trying host " + host + " as " + username + ':' + password)
410+ var request = new XMLHttpRequest();
411+ request.onreadystatechange = function() {
412+ if (request.readyState === XMLHttpRequest.DONE) {
413+ console.log("response: " + request.responseText)
414+ if (request.status == 200) {
415+ var root = request.responseXML ? request.responseXML.documentElement : null
416+ var metaElement = findChild(root, "meta")
417+ var statusElement = findChild(metaElement, "status")
418+ if (statusElement && statusElement.childNodes.length > 0 &&
419+ statusElement.childNodes[0].nodeValue == "ok") {
420+ callback(true)
421+ } else {
422+ var statusCodeElement = findChild(metaElement, "statuscode")
423+ var statusCode = (statusCodeElement && statusCodeElement.childNodes.length > 0) ?
424+ statusCodeElement.childNodes[0].nodeValue : "999"
425+ if (statusCode == "999") {
426+ showError(__hostError)
427+ } else {
428+ showError(i18n.dtr("account-plugins", "Invalid username or password"))
429+ }
430+ callback(false)
431+ }
432+ } else {
433+ showError(__hostError)
434+ callback(false)
435+ }
436+ }
437+ }
438+ request.open("POST", host + "/ocs/v1.php/person/check", true);
439+ request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
440+ var body = "login=" + username + "&password=" + password
441+ request.send(body);
442+ }
443+
444+ function showError(message) {
445+ if (!errorLabel.text) errorLabel.text = message
446+ }
447+
448+ function credentialsStored() {
449+ console.log("Credentials stored, id: " + creds.credentialsId)
450+ if (creds.credentialsId == 0) return
451+
452+ globalAccountSettings.updateServiceEnabled(true)
453+ globalAccountSettings.credentials = creds
454+ globalAccountSettings.updateSettings({
455+ "host": __host
456+ })
457+ account.synced.connect(finished)
458+ account.sync()
459+ __busy = false
460+ }
461+
462+ // check host url for http
463+ function cleanUrl(url) {
464+ var host = url.trim()
465+ // if the user typed trailing '/' or "index.php", strip that
466+ return host.replace(/\/(index.php)?\/*$/, '')
467+ }
468+
469+}
470
471=== added directory 'qml/vk'
472=== added file 'qml/vk/Main.qml'
473--- qml/vk/Main.qml 1970-01-01 00:00:00 +0000
474+++ qml/vk/Main.qml 2016-04-20 10:17:48 +0000
475@@ -0,0 +1,36 @@
476+import Ubuntu.OnlineAccounts.Plugin 1.0
477+
478+OAuthMain {
479+ creationComponent: OAuth {
480+ function completeCreation(reply) {
481+ console.log("Access token: " + reply.AccessToken)
482+ var http = new XMLHttpRequest()
483+ var url = "https://api.vk.com/method/users.get?access_token=" + reply.AccessToken + "&fields=nickname,first_name,last_name";
484+ http.open("GET", url, true);
485+ http.onreadystatechange = function() {
486+ if (http.readyState === 4){
487+ if (http.status == 200) {
488+ console.log("ok")
489+ console.log("response text: " + http.responseText)
490+ var response = JSON.parse(http.responseText)
491+ if (response.response && response.response.length > 0) {
492+ var data = response.response[0]
493+ var name = data.first_name + " " + data.last_name
494+ if (data.nickname) {
495+ name += " (" + data.nickname + ")"
496+ }
497+ account.updateDisplayName(name)
498+ }
499+ account.synced.connect(finished)
500+ account.sync()
501+ } else {
502+ console.log("error: " + http.status)
503+ cancel()
504+ }
505+ }
506+ };
507+
508+ http.send(null);
509+ }
510+ }
511+}

Subscribers

People subscribed via source and target branches

to all changes: