Skip to content

Commit

Permalink
Update 0.1.1
Browse files Browse the repository at this point in the history
-  Work with Meteor release 0.8.2
-  Update example code
-  Update README
  • Loading branch information
yubozhao committed Jul 19, 2014
1 parent b1a545d commit f702ff4
Show file tree
Hide file tree
Showing 15 changed files with 79 additions and 45 deletions.
25 changes: 9 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion example/.meteor/release
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.8.1.3
0.8.2
14 changes: 8 additions & 6 deletions example/tett.html → example/exampl.html
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
<head>
<title>tett</title>
<title>Link Account example</title>
</head>

<body>
<div>
<h2>1. Log in with a non Github service through login button</h2>
{{> loginButtons}}
Use twitter account to login.
</div>

<div>

{{> linkTemplate}}
</div>
</body>

<template name="linkTemplate">
List of connected services.
<h2>2. Link Github account</h2>

<button class="link-github">Link Github Account</button>

<h2>3. List out services that are associated with current user.</h2>

<ul>
{{#each services}}
<li>{{this}}</li>
{{/each}}
</ul>

<button class="link-github">Link Github Account</button>
</template>
7 changes: 3 additions & 4 deletions example/tett.js → example/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
});
})
}
4 changes: 2 additions & 2 deletions example/smart.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
"dependencies": {
"basePackages": {
"link-accounts": {
"path": "../../meteor-packages/link-accounts"
"path": ".."
}
},
"packages": {
"link-accounts": {
"path": "../../meteor-packages/link-accounts"
"path": ".."
}
}
}
Expand Down
1 change: 0 additions & 1 deletion example/tett.css

This file was deleted.

9 changes: 7 additions & 2 deletions facebook.js
Original file line number Diff line number Diff line change
@@ -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);
};
}
6 changes: 5 additions & 1 deletion github.js
Original file line number Diff line number Diff line change
@@ -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);
};
}
6 changes: 5 additions & 1 deletion google.js
Original file line number Diff line number Diff line change
@@ -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);
};
}
21 changes: 16 additions & 5 deletions link_accounts_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -51,7 +64,5 @@ Accounts.LinkUserFromExternalService = function (serviceName, serviceData, optio
type: serviceName,
userId: user._id
};
} else {
return new Error('User not found for LinkUserFromExternalService');
}
};
6 changes: 5 additions & 1 deletion meetup.js
Original file line number Diff line number Diff line change
@@ -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);
};
}
9 changes: 7 additions & 2 deletions meteor_developer.js
Original file line number Diff line number Diff line change
@@ -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);
};
}
2 changes: 1 addition & 1 deletion smart.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"description": "Link social network accounts to existing Meteor user.",
"homepage": "https://github.com/yubozhao/meteor-link-accounts",
"author": "Bozhao Yu <[email protected]>",
"version": "0.1.0",
"version": "0.1.1",
"git": "https://github.com/yubozhao/meteor-link-accounts.git"
}
6 changes: 5 additions & 1 deletion twitter.js
Original file line number Diff line number Diff line change
@@ -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);
};
}
6 changes: 5 additions & 1 deletion weibo.js
Original file line number Diff line number Diff line change
@@ -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);
};
}

0 comments on commit f702ff4

Please sign in to comment.