Google linking and unlinking works successfully now

This commit is contained in:
Sahat Yalkabov
2013-12-13 01:12:59 -05:00
parent 9de1748bc2
commit 7175005e2c
3 changed files with 7 additions and 7 deletions

2
app.js
View File

@ -58,7 +58,7 @@ app.get('/account', passportConf.isAuthenticated, user.getAccount);
app.post('/account/profile', passportConf.isAuthenticated, user.postAccountProfile); app.post('/account/profile', passportConf.isAuthenticated, user.postAccountProfile);
app.post('/account/settings', passportConf.isAuthenticated, user.postAccountSettings); app.post('/account/settings', passportConf.isAuthenticated, user.postAccountSettings);
app.post('/account/delete', passportConf.isAuthenticated, user.postDeleteAccount); app.post('/account/delete', passportConf.isAuthenticated, user.postDeleteAccount);
app.post('/account/unlink/:provider', passportConf.isAuthenticated, user.getOauthUnlink); app.get('/account/unlink/:provider', passportConf.isAuthenticated, user.getOauthUnlink);
app.get('/api', api.getApi); app.get('/api', api.getApi);
app.get('/api/foursquare', passportConf.isAuthenticated, passportConf.isAuthorized, api.getFoursquare); app.get('/api/foursquare', passportConf.isAuthenticated, passportConf.isAuthorized, api.getFoursquare);

View File

@ -156,8 +156,8 @@ exports.getOauthUnlink = function(req, res) {
console.log('unlinking oauth2'); console.log('unlinking oauth2');
var provider = req.params.provider; var provider = req.params.provider;
User.findById(req.user.id, function(err, user) { User.findById(req.user.id, function(err, user) {
delete user[provider]; user[provider] = undefined;
user.tokens = _.reject(x.tokens, function(tok) { return tok.kind === 'google'; }); user.tokens = _.reject(user.tokens, function(token) { return token.kind === 'google'; });
user.save(function(err) { user.save(function(err) {
console.log('Successfully unlinked:', provider); console.log('Successfully unlinked:', provider);
res.redirect('/account#settings'); res.redirect('/account#settings');

View File

@ -74,22 +74,22 @@ block content
h3 Linked Accounts h3 Linked Accounts
if user.google if user.google
p: a.text-danger(href='/auth/google') Unlink your Google account p: a.text-danger(href='/account/unlink/google') Unlink your Google account
else else
p: a(href='/auth/google') Link your Google account p: a(href='/auth/google') Link your Google account
if user.facebook if user.facebook
p: a.text-danger(href='/auth/facebook') Unlink your Facebook account p: a.text-danger(href='/account/unlink/') Unlink your Facebook account
else else
p: a(href='/auth/facebook') Link your Facebook account p: a(href='/auth/facebook') Link your Facebook account
if user.twitter if user.twitter
p: a.text-danger(href='/auth/twitter') Unlink your Twitter account p: a.text-danger(href='/account/unlink/') Unlink your Twitter account
else else
p: a(href='/auth/twitter') Link your Twitter account p: a(href='/auth/twitter') Link your Twitter account
if user.github if user.github
p: a.text-danger(href='/auth/github') Unlink your GitHub account p: a.text-danger(href='/account/unlink/') Unlink your GitHub account
else else
p: a(href='/auth/github') Link your GitHub account p: a(href='/auth/github') Link your GitHub account