Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Commit

Permalink
Merge pull request #634 from Gym/0.4.0
Browse files Browse the repository at this point in the history
[Bug]: Remove social account.
  • Loading branch information
lirantal committed Jul 10, 2015
2 parents ade074c + 786c546 commit e8c79e4
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 117 deletions.
71 changes: 0 additions & 71 deletions modules/users/client/controllers/settings.client.controller.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

angular.module('users').controller('ChangePasswordController', ['$scope', '$http', '$location', 'Users', 'Authentication',
function($scope, $http, $location, Users, Authentication) {
angular.module('users').controller('ChangePasswordController', ['$scope', '$http', 'Authentication',
function($scope, $http, Authentication) {
$scope.user = Authentication.user;

// Change user password
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

angular.module('users').controller('SocialAccountsController', ['$scope', '$http', '$location', 'Users', 'Authentication',
function($scope, $http, $location, Users, Authentication) {
angular.module('users').controller('SocialAccountsController', ['$scope', '$http', 'Authentication',
function($scope, $http, Authentication) {
$scope.user = Authentication.user;

// Check if there are additional accounts
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

angular.module('users').controller('SettingsController', ['$scope', '$http', '$location', 'Users', 'Authentication',
function($scope, $http, $location, Users, Authentication) {
angular.module('users').controller('SettingsController', ['$scope', '$location', 'Authentication',
function($scope, $location, Authentication) {
$scope.user = Authentication.user;

// If user is not signed in then redirect back home
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var path = require('path'),
/**
* Signup
*/
exports.signup = function(req, res) {
exports.signup = function (req, res) {
// For security measurement we remove the roles from the req.body object
delete req.body.roles;

Expand All @@ -25,7 +25,7 @@ exports.signup = function(req, res) {
user.displayName = user.firstName + ' ' + user.lastName;

// Then save the user
user.save(function(err) {
user.save(function (err) {
if (err) {
return res.status(400).send({
message: errorHandler.getErrorMessage(err)
Expand All @@ -35,7 +35,7 @@ exports.signup = function(req, res) {
user.password = undefined;
user.salt = undefined;

req.login(user, function(err) {
req.login(user, function (err) {
if (err) {
res.status(400).send(err);
} else {
Expand All @@ -49,16 +49,16 @@ exports.signup = function(req, res) {
/**
* Signin after passport authentication
*/
exports.signin = function(req, res, next) {
passport.authenticate('local', function(err, user, info) {
exports.signin = function (req, res, next) {
passport.authenticate('local', function (err, user, info) {
if (err || !user) {
res.status(400).send(info);
} else {
// Remove sensitive data before login
user.password = undefined;
user.salt = undefined;

req.login(user, function(err) {
req.login(user, function (err) {
if (err) {
res.status(400).send(err);
} else {
Expand All @@ -72,21 +72,21 @@ exports.signin = function(req, res, next) {
/**
* Signout
*/
exports.signout = function(req, res) {
exports.signout = function (req, res) {
req.logout();
res.redirect('/');
};

/**
* OAuth callback
*/
exports.oauthCallback = function(strategy) {
return function(req, res, next) {
passport.authenticate(strategy, function(err, user, redirectURL) {
exports.oauthCallback = function (strategy) {
return function (req, res, next) {
passport.authenticate(strategy, function (err, user, redirectURL) {
if (err || !user) {
return res.redirect('/#!/signin');
}
req.login(user, function(err) {
req.login(user, function (err) {
if (err) {
return res.redirect('/#!/signin');
}
Expand All @@ -100,7 +100,7 @@ exports.oauthCallback = function(strategy) {
/**
* Helper function to save or update a OAuth user profile
*/
exports.saveOAuthUserProfile = function(req, providerUserProfile, done) {
exports.saveOAuthUserProfile = function (req, providerUserProfile, done) {
if (!req.user) {
// Define a search query fields
var searchMainProviderIdentifierField = 'providerData.' + providerUserProfile.providerIdentifierField;
Expand All @@ -120,14 +120,14 @@ exports.saveOAuthUserProfile = function(req, providerUserProfile, done) {
$or: [mainProviderSearchQuery, additionalProviderSearchQuery]
};

User.findOne(searchQuery, function(err, user) {
User.findOne(searchQuery, function (err, user) {
if (err) {
return done(err);
} else {
if (!user) {
var possibleUsername = providerUserProfile.username || ((providerUserProfile.email) ? providerUserProfile.email.split('@')[0] : '');

User.findUniqueUsername(possibleUsername, null, function(availableUsername) {
User.findUniqueUsername(possibleUsername, null, function (availableUsername) {
user = new User({
firstName: providerUserProfile.firstName,
lastName: providerUserProfile.lastName,
Expand All @@ -140,7 +140,7 @@ exports.saveOAuthUserProfile = function(req, providerUserProfile, done) {
});

// And save the user
user.save(function(err) {
user.save(function (err) {
return done(err, user);
});
});
Expand All @@ -163,7 +163,7 @@ exports.saveOAuthUserProfile = function(req, providerUserProfile, done) {
user.markModified('additionalProvidersData');

// And save the user
user.save(function(err) {
user.save(function (err) {
return done(err, user, '/#!/settings/accounts');
});
} else {
Expand All @@ -175,33 +175,39 @@ exports.saveOAuthUserProfile = function(req, providerUserProfile, done) {
/**
* Remove OAuth provider
*/
exports.removeOAuthProvider = function(req, res, next) {
exports.removeOAuthProvider = function (req, res, next) {
var user = req.user;
var provider = req.params.provider;
var provider = req.query.provider;

if (user && provider) {
// Delete the additional provider
if (user.additionalProvidersData[provider]) {
delete user.additionalProvidersData[provider];
if (!user) {
return res.status(401).json({
message: 'User is not authenticated'
});
} else if (!provider) {
return res.status(400).send();
}

// Then tell mongoose that we've updated the additionalProvidersData field
user.markModified('additionalProvidersData');
}
// Delete the additional provider
if (user.additionalProvidersData[provider]) {
delete user.additionalProvidersData[provider];

user.save(function(err) {
if (err) {
return res.status(400).send({
message: errorHandler.getErrorMessage(err)
});
} else {
req.login(user, function(err) {
if (err) {
res.status(400).send(err);
} else {
res.json(user);
}
});
}
});
// Then tell mongoose that we've updated the additionalProvidersData field
user.markModified('additionalProvidersData');
}

user.save(function (err) {
if (err) {
return res.status(400).send({
message: errorHandler.getErrorMessage(err)
});
} else {
req.login(user, function (err) {
if (err) {
return res.status(400).send(err);
} else {
return res.json(user);
}
});
}
});
};

0 comments on commit e8c79e4

Please sign in to comment.