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

0.4.0 - refactor_user #559

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"angular-bootstrap": "~0.11.0",
"angular-ui-utils": "~0.1.1",
"angular-ui-router": "~0.2.10",
"angular-file-upload": "~1.1.5"
"angular-file-upload": "~1.1.5",
"angular-json-tree": "*"
}
}
6 changes: 4 additions & 2 deletions config/assets/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ module.exports = {
lib: {
css: [
'public/lib/bootstrap/dist/css/bootstrap.css',
'public/lib/bootstrap/dist/css/bootstrap-theme.css'
'public/lib/bootstrap/dist/css/bootstrap-theme.css',
'public/lib/angular-json-tree/build/angular-json-tree.css'
],
js: [
'public/lib/angular/angular.js',
Expand All @@ -14,7 +15,8 @@ module.exports = {
'public/lib/angular-ui-router/release/angular-ui-router.js',
'public/lib/angular-ui-utils/ui-utils.js',
'public/lib/angular-bootstrap/ui-bootstrap-tpls.js',
'public/lib/angular-file-upload/angular-file-upload.js'
'public/lib/angular-file-upload/angular-file-upload.js',
'public/lib/angular-json-tree/build/angular-json-tree.min.js'
],
tests: ['public/lib/angular-mocks/angular-mocks.js']
},
Expand Down
48 changes: 24 additions & 24 deletions config/env/development.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,30 @@ module.exports = {
title: 'MEAN.JS - Development Environment'
},
facebook: {
clientID: process.env.FACEBOOK_ID || 'APP_ID',
clientSecret: process.env.FACEBOOK_SECRET || 'APP_SECRET',
callbackURL: '/api/auth/facebook/callback'
},
twitter: {
clientID: process.env.TWITTER_KEY || 'CONSUMER_KEY',
clientSecret: process.env.TWITTER_SECRET || 'CONSUMER_SECRET',
callbackURL: '/api/auth/twitter/callback'
},
google: {
clientID: process.env.GOOGLE_ID || 'APP_ID',
clientSecret: process.env.GOOGLE_SECRET || 'APP_SECRET',
callbackURL: '/api/auth/google/callback'
},
linkedin: {
clientID: process.env.LINKEDIN_ID || 'APP_ID',
clientSecret: process.env.LINKEDIN_SECRET || 'APP_SECRET',
callbackURL: '/api/auth/linkedin/callback'
},
github: {
clientID: process.env.GITHUB_ID || 'APP_ID',
clientSecret: process.env.GITHUB_SECRET || 'APP_SECRET',
callbackURL: '/api/auth/github/callback'
},
clientID: process.env.FACEBOOK_ID || 'APP_ID',
clientSecret: process.env.FACEBOOK_SECRET || 'APP_SECRET',
callbackURL: '/api/auth/facebook/callback'
},
twitter: {
clientID: process.env.TWITTER_KEY || 'CONSUMER_KEY',
clientSecret: process.env.TWITTER_SECRET || 'CONSUMER_SECRET',
callbackURL: '/api/auth/twitter/callback'
},
google: {
clientID: process.env.GOOGLE_ID || 'APP_ID',
clientSecret: process.env.GOOGLE_SECRET || 'APP_SECRET',
callbackURL: '/api/auth/google/callback'
},
linkedin: {
clientID: process.env.LINKEDIN_ID || 'APP_ID',
clientSecret: process.env.LINKEDIN_SECRET || 'APP_SECRET',
callbackURL: '/api/auth/linkedin/callback'
},
github: {
clientID: process.env.GITHUB_ID || 'APP_ID',
clientSecret: process.env.GITHUB_SECRET || 'APP_SECRET',
callbackURL: '/api/auth/github/callback'
},
mailer: {
from: process.env.MAILER_FROM || 'MAILER_FROM',
options: {
Expand Down
14 changes: 7 additions & 7 deletions gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ module.exports = function (grunt) {
expand: true,
src: defaultAssets.client.sass,
ext: '.css',
rename: function(base, src) {
return src.replace('/scss/', '/css/');
rename: function (base, src) {
return src.replace('/scss/', '/css/');
}
}]
}
Expand All @@ -150,8 +150,8 @@ module.exports = function (grunt) {
expand: true,
src: defaultAssets.client.less,
ext: '.css',
rename: function(base, src) {
return src.replace('/less/', '/css/');
rename: function (base, src) {
return src.replace('/less/', '/css/');
}
}]
}
Expand Down Expand Up @@ -203,22 +203,22 @@ module.exports = function (grunt) {
}
});

// Load NPM tasks
// Load NPM tasks
require('load-grunt-tasks')(grunt);

// Making grunt default to force in order not to break the project.
grunt.option('force', true);

// Connect to the MongoDB instance and load the models
grunt.task.registerTask('mongoose', 'Task that connects to the MongoDB instance and loads the application models.', function() {
grunt.task.registerTask('mongoose', 'Task that connects to the MongoDB instance and loads the application models.', function () {
// Get the callback
var done = this.async();

// Use mongoose configuration
var mongoose = require('./config/lib/mongoose.js');

// Connect to database
mongoose.connect(function(db) {
mongoose.connect(function (db) {
done();
});
});
Expand Down
11 changes: 7 additions & 4 deletions modules/core/server/controllers/errors.server.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
/**
* Get unique error field name
*/
var getUniqueErrorMessage = function(err) {
var getUniqueErrorMessage = function (err) {
var output;

try {
var fieldName = err.err.substring(err.err.lastIndexOf('.$') + 2, err.err.lastIndexOf('_1'));
output = fieldName.charAt(0).toUpperCase() + fieldName.slice(1) + ' already exist';

} catch(ex) {
} catch (ex) {
output = 'Unique field already exist';
}

Expand All @@ -20,9 +20,9 @@ var getUniqueErrorMessage = function(err) {
/**
* Get the error message from error object
*/
exports.getErrorMessage = function(err) {
exports.getErrorMessage = function (err) {
var message = '';

if (err.code) {
switch (err.code) {
case 11000:
Expand All @@ -33,6 +33,9 @@ exports.getErrorMessage = function(err) {
message = 'Something went wrong';
}
} else {
if (!err.errors && err.message) {
return err.message;
}
for (var errName in err.errors) {
if (err.errors[errName].message) message = err.errors[errName].message;
}
Expand Down
9 changes: 9 additions & 0 deletions modules/users/client/config/users.client.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ angular.module('users').config(['$stateProvider',
state('password.reset.form', {
url: '/:token',
templateUrl: 'modules/users/views/password/reset-password.client.view.html'
}).
state('admin', {
abstract: true,
url: '/admin',
template: '<ui-view/>'
}).
state('admin.users', {
url: '/users',
templateUrl: 'modules/users/views/admin/users.list.client.view.html'
});
}
]);
13 changes: 13 additions & 0 deletions modules/users/client/controllers/admin/users.client.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

angular.module('users').controller('AdminUsersController', ['$scope', 'Users', 'Authentication',
function ($scope, Users, Authentication) {

$scope.rows = Users.query();

$scope.identityToLink = function (identity) {
return 'noneYet';
};

}
]);
79 changes: 64 additions & 15 deletions modules/users/client/controllers/settings.client.controller.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,49 @@
'use strict';

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

// If user is not signed in then redirect back home
if (!$scope.user) $location.path('/');

$scope.user.identities.forEach(function (identity) {
if (identity.provider === 'username') {
$scope.user.username = identity.id;
}
});

$scope.identitiesToEmails = function () {
$scope.user.emails = [];
if ($scope.user.identities) {
$scope.user.identities.forEach(function (identity, idx) {
if (identity.provider === 'email') {
$scope.user.identities.splice(idx, 1);
$scope.user.emails.push(identity);
}
});
}
};
$scope.identitiesToEmails();

$scope.removeEmail = function (emailIndex) {
$scope.user.emails.splice(emailIndex, 1);
return false;
};

$scope.addEmail = function () {
if (!$scope.user.identities) {
$scope.user.identities = [];
}
$scope.user.emails.push({
provider: 'email',
id: ''
});
};

// Check if there are additional accounts
$scope.hasConnectedAdditionalSocialAccounts = function(provider) {
$scope.hasConnectedAdditionalSocialAccounts = function (provider) {
for (var i in $scope.user.additionalProvidersData) {
return true;
}
Expand All @@ -17,37 +52,51 @@ angular.module('users').controller('SettingsController', ['$scope', '$http', '$l
};

// Check if provider is already in use with current user
$scope.isConnectedSocialAccount = function(provider) {
return $scope.user.provider === provider || ($scope.user.additionalProvidersData && $scope.user.additionalProvidersData[provider]);
$scope.isConnectedSocialAccount = function (provider) {
var connected = false;
angular.forEach($scope.user.identities, function (identity) {
if (identity.provider === provider) {
connected = true;
$scope.linkedProviders.push(provider);
}
});
return connected;
};

// Remove a user social account
$scope.removeUserSocialAccount = function(provider) {
$scope.removeUserSocialAccount = function (provider) {
$scope.success = $scope.error = null;

$http.delete('/api/users/accounts', {
params: {
provider: provider
}
}).success(function(response) {
}).success(function (response) {
// If successful show success message and clear form
$scope.success = true;
$scope.user = Authentication.user = response;
}).error(function(response) {
}).error(function (response) {
$scope.error = response.message;
});
};

// Update a user profile
$scope.updateUserProfile = function(isValid) {
if (isValid){
$scope.updateUserProfile = function (isValid) {
if (isValid) {
$scope.success = $scope.error = null;

$scope.user.emails.forEach(function (email) {
$scope.user.identities.push(email);
});
delete $scope.user.emails;

var user = new Users($scope.user);
user.$update(function(response) {

user.$update(function (response) {
$scope.success = true;
Authentication.user = response;
}, function(response) {
$scope.identitiesToEmails();
}, function (response) {
$scope.error = response.data.message;
});
} else {
Expand All @@ -56,14 +105,14 @@ angular.module('users').controller('SettingsController', ['$scope', '$http', '$l
};

// Change user password
$scope.changeUserPassword = function() {
$scope.changeUserPassword = function () {
$scope.success = $scope.error = null;

$http.post('/api/users/password', $scope.passwordDetails).success(function(response) {
$http.post('/api/users/password', $scope.passwordDetails).success(function (response) {
// If successful show success message and clear form
$scope.success = true;
$scope.passwordDetails = null;
}).error(function(response) {
}).error(function (response) {
$scope.error = response.message;
});
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,52 @@
'use strict';

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

// Update a user profile
$scope.updateUserProfile = function(isValid) {
if (isValid){
$scope.updateUserProfile = function (isValid) {
if (isValid) {
$scope.success = $scope.error = null;
var user = new Users($scope.user);

user.$update(function(response) {
user.$update(function (response) {
$scope.success = true;
Authentication.user = response;
}, function(response) {
}, function (response) {
$scope.error = response.data.message;
});
} else {
$scope.submitted = true;
}
};

$scope.identitiesToEmails = function () {
$scope.user.emails = [];
if ($scope.user.identities) {
$scope.user.identities.forEach(function (identity, idx) {
if (identity.provider === 'email') {
$scope.user.identities.splice(idx, 1);
$scope.user.emails.push(identity);
}
});
}
};
$scope.identitiesToEmails();

$scope.removeEmail = function (emailIndex) {
$scope.user.emails.splice(emailIndex, 1);
return false;
};

$scope.addEmail = function () {
if (!$scope.user.identities) {
$scope.user.identities = [];
}
$scope.user.emails.push({
provider: 'email',
id: ''
});
};
}
]);
Loading