From f702ff422307808b6dd40d8786310787b237e930 Mon Sep 17 00:00:00 2001 From: Bozhao Yu Date: Fri, 18 Jul 2014 18:06:33 -0700 Subject: [PATCH] Update 0.1.1 - Work with Meteor release 0.8.2 - Update example code - Update README --- README.md | 25 +++++++++---------------- example/.meteor/release | 2 +- example/{tett.html => exampl.html} | 14 ++++++++------ example/{tett.js => example.js} | 7 +++---- example/smart.lock | 4 ++-- example/tett.css | 1 - facebook.js | 9 +++++++-- github.js | 6 +++++- google.js | 6 +++++- link_accounts_server.js | 21 ++++++++++++++++----- meetup.js | 6 +++++- meteor_developer.js | 9 +++++++-- smart.json | 2 +- twitter.js | 6 +++++- weibo.js | 6 +++++- 15 files changed, 79 insertions(+), 45 deletions(-) rename example/{tett.html => exampl.html} (57%) rename example/{tett.js => example.js} (71%) delete mode 100644 example/tett.css diff --git a/README.md b/README.md index 47ae853..9f69c83 100644 --- a/README.md +++ b/README.md @@ -2,29 +2,22 @@ A Meteor package designed to links social network accounts without any hassles. ##Goals -* Link additional social network accounts to our Meteor app. -* Don't want to modify any Meteor core packages. -* Don't want to do any additional works. +* Link additional social network accounts. +* Don't modify any Meteor core packages. * Don't force users to add additional Meteor packages that they are not going to use. -##Useage +##Usage Call Meteor.linkWith[ServiceName] in place instead of loginWith +##Design: +1. Piggyback on existing Meteor oauth login system. Use login handler. -##Notes: -1. Piggyback on existing Meteor oauth login system. +2. We do not allow link different account from same service for now. For example, you + could not link with 2 different github accounts. -2. Does not link password account. - -3. We don't allow link without current user in Meteor app. - -4. We do not allow link different account from same service. For example, you - could not login the application with 2 different github accounts. - -5. Save the linked service info on user.services, instead of creating new field - on user object. This allow user logins the application from either - services. +3. Save the linked service info on user.services, instead of creating new field + on user object. This allow user logins the application from linked services. ##License MIT diff --git a/example/.meteor/release b/example/.meteor/release index db5f2c7..100435b 100644 --- a/example/.meteor/release +++ b/example/.meteor/release @@ -1 +1 @@ -0.8.1.3 +0.8.2 diff --git a/example/tett.html b/example/exampl.html similarity index 57% rename from example/tett.html rename to example/exampl.html index 60d063b..bcf0ca1 100644 --- a/example/tett.html +++ b/example/exampl.html @@ -1,26 +1,28 @@ - tett + Link Account example
+

1. Log in with a non Github service through login button

{{> loginButtons}} - Use twitter account to login.
- {{> linkTemplate}}
diff --git a/example/tett.js b/example/example.js similarity index 71% rename from example/tett.js rename to example/example.js index 39846bf..c3f0903 100644 --- a/example/tett.js +++ b/example/example.js @@ -7,13 +7,12 @@ if (Meteor.isClient) { Template.linkTemplate.helpers({ services: function () { - var user = Meteor.user(); + var user = Meteor.user(); if (user) { - var services = _.keys(user.services); - return services; + return _.keys(user.services); } else { return; } } - }); + }) } diff --git a/example/smart.lock b/example/smart.lock index 5ca81ab..48feea2 100644 --- a/example/smart.lock +++ b/example/smart.lock @@ -3,12 +3,12 @@ "dependencies": { "basePackages": { "link-accounts": { - "path": "../../meteor-packages/link-accounts" + "path": ".." } }, "packages": { "link-accounts": { - "path": "../../meteor-packages/link-accounts" + "path": ".." } } } diff --git a/example/tett.css b/example/tett.css deleted file mode 100644 index b6b4052..0000000 --- a/example/tett.css +++ /dev/null @@ -1 +0,0 @@ -/* CSS declarations go here */ diff --git a/facebook.js b/facebook.js index ce153ba..0a42788 100644 --- a/facebook.js +++ b/facebook.js @@ -1,11 +1,16 @@ if (Meteor.isClient) { Meteor.linkWithFacebook = function (options, callback) { + if (!Meteor.userId()) { + throw new Meteor.Error(402, 'Please login to an existing account before link.'); + } + if (! callback && typeof options === "function") { callback = options; options = null; } - var credentialRequestCompleteCallback = Accounts.oauth.linkCredentialRequestCompleteHandler(callback); - Facebook.requestCredential(credentialRequestCompleteCallback); + var credentialRequestCompleteCallback = + Accounts.oauth.linkCredentialRequestCompleteHandler(callback); + Facebook.requestCredential(options, credentialRequestCompleteCallback); }; } diff --git a/github.js b/github.js index 26c1836..37e3867 100644 --- a/github.js +++ b/github.js @@ -1,11 +1,15 @@ if (Meteor.isClient) { Meteor.linkWithGithub = function (options, callback) { + if (!Meteor.userId()) { + throw new Meteor.Error(402, 'Please login to an existing account before link.'); + } + if (! callback && typeof options === "function") { callback = options; options = null; } var credentialRequestCompleteCallback = Accounts.oauth.linkCredentialRequestCompleteHandler(callback); - Github.requestCredential(credentialRequestCompleteCallback); + Github.requestCredential(options, credentialRequestCompleteCallback); }; } diff --git a/google.js b/google.js index df3299b..d7056f1 100644 --- a/google.js +++ b/google.js @@ -1,11 +1,15 @@ if (Meteor.isClient) { Meteor.linkWithGoogle = function (options, callback) { + if (!Meteor.userId()) { + throw new Meteor.Error(402, 'Please login to an existing account before link.'); + } + if (! callback && typeof options === "function") { callback = options; options = null; } var credentialRequestCompleteCallback = Accounts.oauth.linkCredentialRequestCompleteHandler(callback); - Google.requestCredential(credentialRequestCompleteCallback); + Google.requestCredential(options, credentialRequestCompleteCallback); }; } diff --git a/link_accounts_server.js b/link_accounts_server.js index 091c94c..27a79ea 100644 --- a/link_accounts_server.js +++ b/link_accounts_server.js @@ -13,6 +13,13 @@ Accounts.registerLoginHandler(function (options) { var result = OAuth.retrieveCredential(options.link.credentialToken, options.link.credentialSecret); + if (!result) { + return { type: "link", + error: new Meteor.Error( + Accounts.LoginCancelledError.numericError, + "No matching link attempt found") }; + } + if (result instanceof Error) throw result; else @@ -37,10 +44,16 @@ Accounts.LinkUserFromExternalService = function (serviceName, serviceData, optio var user = Meteor.user(); + if (!user) { + return new Error('User not found for LinkUserFromExternalService.'); + } + //we do not allow link another account from existing service. - if (user.services[serviceName] && user.services[serviceName].id !== serviceData.id) { - return new Meteor.Error('User can not link a service that is already actived'); - } else if (!user.services[serviceName]){ + if (user.services && user.services[serviceName] && + user.services[serviceName].id !== serviceData.id) { + + return new Meteor.Error('User can not link a service that is already actived.'); + } else { var setAttrs = {}; _.each(serviceData, function(value, key) { setAttrs["services." + serviceName + "." + key] = value; @@ -51,7 +64,5 @@ Accounts.LinkUserFromExternalService = function (serviceName, serviceData, optio type: serviceName, userId: user._id }; - } else { - return new Error('User not found for LinkUserFromExternalService'); } }; diff --git a/meetup.js b/meetup.js index 518e3fb..c6e71fe 100644 --- a/meetup.js +++ b/meetup.js @@ -1,11 +1,15 @@ if (Meteor.isClient) { Meteor.linkWithMeetup = function (options, callback) { + if (!Meteor.userId()) { + throw new Meteor.Error(402, 'Please login to an existing account before link.'); + } + if (! callback && typeof options === "function") { callback = options; options = null; } var credentialRequestCompleteCallback = Accounts.oauth.linkCredentialRequestCompleteHandler(callback); - Meetup.requestCredential(credentialRequestCompleteCallback); + Meetup.requestCredential(options, credentialRequestCompleteCallback); }; } diff --git a/meteor_developer.js b/meteor_developer.js index fb96fc4..bf33113 100644 --- a/meteor_developer.js +++ b/meteor_developer.js @@ -1,11 +1,16 @@ if (Meteor.isClient) { Meteor.linkWithMeteorDeveloperAccount = function (options, callback) { + if (!Meteor.userId()) { + throw new Meteor.Error(402, 'Please login to an existing account before link.'); + } + if (! callback && typeof options === "function") { callback = options; options = null; } - var credentialRequestCompleteCallback = Accounts.oauth.linkCredentialRequestCompleteHandler(callback); - MeteorDeveloperAccounts.requestCredential(credentialRequestCompleteCallback); + var credentialRequestCompleteCallback = + Accounts.oauth.linkCredentialRequestCompleteHandler(callback); + MeteorDeveloperAccounts.requestCredential(options, credentialRequestCompleteCallback); }; } diff --git a/smart.json b/smart.json index e5d2163..c112ac4 100644 --- a/smart.json +++ b/smart.json @@ -3,6 +3,6 @@ "description": "Link social network accounts to existing Meteor user.", "homepage": "https://github.com/yubozhao/meteor-link-accounts", "author": "Bozhao Yu ", - "version": "0.1.0", + "version": "0.1.1", "git": "https://github.com/yubozhao/meteor-link-accounts.git" } diff --git a/twitter.js b/twitter.js index a329aea..8e75399 100644 --- a/twitter.js +++ b/twitter.js @@ -1,11 +1,15 @@ if (Meteor.isClient) { Meteor.linkWithTwitter = function (options, callback) { + if (!Meteor.userId()) { + throw new Meteor.Error(402, 'Please login to an existing account before link.'); + } + if (! callback && typeof options === "function") { callback = options; options = null; } var credentialRequestCompleteCallback = Accounts.oauth.linkCredentialRequestCompleteHandler(callback); - Twitter.requestCredential(credentialRequestCompleteCallback); + Twitter.requestCredential(options, credentialRequestCompleteCallback); }; } diff --git a/weibo.js b/weibo.js index 1619e2c..53fe68d 100644 --- a/weibo.js +++ b/weibo.js @@ -1,11 +1,15 @@ if (Meteor.isClient) { Meteor.linkWithWeibo = function (options, callback) { + if (!Meteor.userId()) { + throw new Meteor.Error(402, 'Please login to an existing account before link.'); + } + if (! callback && typeof options === "function") { callback = options; options = null; } var credentialRequestCompleteCallback = Accounts.oauth.linkCredentialRequestCompleteHandler(callback); - Weibo.requestCredential(credentialRequestCompleteCallback); + Weibo.requestCredential(options, credentialRequestCompleteCallback); }; }