diff --git a/linkdrop/controllers/contacts.py b/linkdrop/controllers/contacts.py index 0392c19..f48e247 100644 --- a/linkdrop/controllers/contacts.py +++ b/linkdrop/controllers/contacts.py @@ -85,12 +85,13 @@ Name of the group to return. response={'type': 'object', 'doc': 'Portable Contacts Collection'} ) def get(self, domain): - username = request.params.get('username') - userid = request.params.get('userid') - group = request.params.get('group', None) - startIndex = int(request.params.get('startindex','0')) - maxResults = int(request.params.get('maxresults','25')) + username = request.POST.get('username') + userid = request.POST.get('userid') + group = request.POST.get('group', None) + startIndex = int(request.POST.get('startindex','0')) + maxResults = int(request.POST.get('maxresults','25')) keys = session.get('account_keys', '').split(',') + account_data = request.POST.get('account', None) if not keys: error = {'provider': domain, 'message': "no user session exists, auth required", @@ -101,12 +102,16 @@ Name of the group to return. # even if we have a session key, we must have an account for that # user for the specified domain. - acct = None - for k in keys: - a = session.get(k) - if a and a.get('domain') == domain and (not username or a.get('username')==username and not userid or a.get('userid')==userid): - acct = a - break + if account_data: + acct = json.loads(account_data) + else: + # support for old accounts in the session store + acct = None + for k in keys: + a = session.get(k) + if a and a.get('domain') == domain and (not username or a.get('username')==username and not userid or a.get('userid')==userid): + acct = a + break if not acct: error = {'provider': domain, 'message': "not logged in or no user account for that domain", diff --git a/linkdrop/controllers/send.py b/linkdrop/controllers/send.py index da7e2c8..8ae47f6 100644 --- a/linkdrop/controllers/send.py +++ b/linkdrop/controllers/send.py @@ -120,6 +120,7 @@ Site provided description of the shared item, not supported by all services. shorturl = request.POST.get('shorturl') userid = request.POST.get('userid') to = request.POST.get('to') + account_data = request.POST.get('account', None) if not domain: error = { 'message': "'domain' is not optional", @@ -138,12 +139,17 @@ Site provided description of the shared item, not supported by all services. provider = get_provider(domain) # even if we have a session key, we must have an account for that # user for the specified domain. - acct = None - for k in keys: - a = session.get(k) - if a and a.get('domain') == domain and (a.get('username')==username or a.get('userid')==userid): - acct = a - break + if account_data: + acct = json.loads(account_data) + else: + raise Exception('foobar') + # support for old account data in session store + acct = None + for k in keys: + a = session.get(k) + if a and a.get('domain') == domain and (a.get('username')==username or a.get('userid')==userid): + acct = a + break if not acct: error = {'provider': domain, 'message': "not logged in or no user account for that domain", diff --git a/web/dev/scripts/accounts.js b/web/dev/scripts/accounts.js index 5f4d96f..4b73695 100644 --- a/web/dev/scripts/accounts.js +++ b/web/dev/scripts/accounts.js @@ -26,8 +26,8 @@ localStorage: false, opener: false, setTimeout: false */ 'use strict'; -define([ 'storage', 'dispatch', 'rdapi'], -function (storage, dispatch, rdapi) { +define([ 'storage', 'dispatch', 'rdapi', 'services'], +function (storage, dispatch, rdapi, services) { var store = storage(), impl, changeTypes = { @@ -144,6 +144,11 @@ function (storage, dispatch, rdapi) { } store.accountCache = JSON.stringify(accountCache); } + + // clear the contacts cache + var svc = services.domains[domain]; + svc.clearCache(store); + impl.changed(); }, @@ -161,7 +166,7 @@ function (storage, dispatch, rdapi) { } return null; }, - + changed: function () { store.accountChanged = (new Date()).getTime(); //Force the onchange events to occur. Sometimes the storage @@ -246,7 +251,7 @@ function (storage, dispatch, rdapi) { * @param {string} account username */ accounts.getService = function (account, userid, username) { - impl.remove(account, userid, username); + return impl.getService(account, userid, username); }; /** diff --git a/web/dev/share/index.js b/web/dev/share/index.js index 076c285..88c81e1 100644 --- a/web/dev/share/index.js +++ b/web/dev/share/index.js @@ -215,6 +215,9 @@ function (require, $, fn, rdapi, oauth, jig, url, return; } + var svcData = accounts.getService(data.domain, data.userid, data.username); + sendData.account = JSON.stringify(svcData); + rdapi('send', { type: 'POST', data: sendData, @@ -297,13 +300,15 @@ function (require, $, fn, rdapi, oauth, jig, url, svc = services.domains[svcAccount.domain], contacts = svc.getContacts(store); if (!contacts) { + var svcData = accounts.getService(svcAccount.domain, svcAccount.userid, svcAccount.username); rdapi('contacts/' + svcAccount.domain, { type: 'POST', data: { username: svcAccount.username, userid: svcAccount.userid, startindex: 0, - maxresults: 500 + maxresults: 500, + account: JSON.stringify(svcData) }, success: function (json) { //Transform data to a form usable by autocomplete. diff --git a/web/dev/share/panel/index.js b/web/dev/share/panel/index.js index 363546f..f651f0d 100644 --- a/web/dev/share/panel/index.js +++ b/web/dev/share/panel/index.js @@ -138,6 +138,8 @@ function (require, $, fn, rdapi, oauth, jig, url, showStatus('statusSharing'); sendData = data; + var svcData = accounts.getService(data.domain, data.userid, data.username); + sendData.account = JSON.stringify(svcData); rdapi('send', { type: 'POST', diff --git a/web/dev/share/panel/scripts/widgets/AccountPanel.js b/web/dev/share/panel/scripts/widgets/AccountPanel.js index 983e92a..dbb615b 100644 --- a/web/dev/share/panel/scripts/widgets/AccountPanel.js +++ b/web/dev/share/panel/scripts/widgets/AccountPanel.js @@ -26,10 +26,10 @@ "use strict"; define([ 'blade/object', 'blade/Widget', 'jquery', 'text!./AccountPanel.html', - 'TextCounter', 'storage', 'module', 'placeholder', 'dispatch', + 'TextCounter', 'storage', 'module', 'placeholder', 'dispatch', 'accounts', 'AutoComplete', 'rdapi', 'blade/fn', './jigFuncs', 'jquery.textOverflow'], function (object, Widget, $, template, - TextCounter, storage, module, placeholder, dispatch, + TextCounter, storage, module, placeholder, dispatch, accounts, AutoComplete, rdapi, fn, jigFuncs) { var store = storage(), @@ -405,13 +405,15 @@ function (object, Widget, $, template, storeContacts: function () { var contacts = this.svc.getContacts(store); if (!contacts) { + var svcData = accounts.getService(this.svcAccount.domain, this.svcAccount.userid, this.svcAccount.username); rdapi('contacts/' + this.svcAccount.domain, { type: 'POST', data: { username: this.svcAccount.username, userid: this.svcAccount.userid, startindex: 0, - maxresults: 500 + maxresults: 500, + account: JSON.stringify(svcData) }, success: fn.bind(this, function (json) { //Transform data to a form usable by autocomplete. @@ -420,7 +422,6 @@ function (object, Widget, $, template, data = []; data = this.svc.getFormattedContacts(entries); - this.svc.setContacts(store, data); this.updateAutoComplete(this.svcAccount.domain); }