diff --git a/modules/users/client/config/users-admin.client.menus.js b/modules/users/client/config/users-admin.client.menus.js index 4ae2ed87ae..6e5e18c4e6 100644 --- a/modules/users/client/config/users-admin.client.menus.js +++ b/modules/users/client/config/users-admin.client.menus.js @@ -1,11 +1,17 @@ -'use strict'; +(function () { + 'use strict'; -// Configuring the Users module -angular.module('users.admin').run(['Menus', - function (Menus) { + angular + .module('users.admin') + .run(menuConfig); + + menuConfig.$inject = ['Menus']; + + // Configuring the Users module + function menuConfig(Menus) { Menus.addSubMenuItem('topbar', 'admin', { title: 'Manage Users', state: 'admin.users' }); } -]); +})(); diff --git a/modules/users/client/config/users-admin.client.routes.js b/modules/users/client/config/users-admin.client.routes.js index 426a7298d2..04f0d57bb9 100644 --- a/modules/users/client/config/users-admin.client.routes.js +++ b/modules/users/client/config/users-admin.client.routes.js @@ -1,13 +1,20 @@ -'use strict'; +(function () { + 'use strict'; -// Setting up route -angular.module('users.admin.routes').config(['$stateProvider', - function ($stateProvider) { + // Setting up route + angular + .module('users.admin.routes') + .config(routeConfig); + + routeConfig.$inject = ['$stateProvider']; + + function routeConfig($stateProvider) { $stateProvider .state('admin.users', { url: '/users', templateUrl: 'modules/users/client/views/admin/list-users.client.view.html', controller: 'UserListController', + controllerAs: 'vm', data: { pageTitle: 'Users List' } @@ -16,12 +23,9 @@ angular.module('users.admin.routes').config(['$stateProvider', url: '/users/:userId', templateUrl: 'modules/users/client/views/admin/view-user.client.view.html', controller: 'UserController', + controllerAs: 'vm', resolve: { - userResolve: ['$stateParams', 'Admin', function ($stateParams, Admin) { - return Admin.get({ - userId: $stateParams.userId - }); - }] + userResolve: getUser }, data: { pageTitle: 'Edit {{ userResolve.displayName }}' @@ -31,16 +35,21 @@ angular.module('users.admin.routes').config(['$stateProvider', url: '/users/:userId/edit', templateUrl: 'modules/users/client/views/admin/edit-user.client.view.html', controller: 'UserController', + controllerAs: 'vm', resolve: { - userResolve: ['$stateParams', 'Admin', function ($stateParams, Admin) { - return Admin.get({ - userId: $stateParams.userId - }); - }] + userResolve: getUser }, data: { pageTitle: 'Edit User {{ userResolve.displayName }}' } }); + + getUser.$inject = ['$stateParams', 'AdminService']; + + function getUser($stateParams, AdminService) { + return AdminService.get({ + userId: $stateParams.userId + }).$promise; + } } -]); +})(); diff --git a/modules/users/client/config/users.client.routes.js b/modules/users/client/config/users.client.routes.js index 8fb3bafbe3..a246a3cf77 100644 --- a/modules/users/client/config/users.client.routes.js +++ b/modules/users/client/config/users.client.routes.js @@ -1,14 +1,22 @@ -'use strict'; +(function () { + 'use strict'; -// Setting up route -angular.module('users').config(['$stateProvider', - function ($stateProvider) { + // Setting up route + angular + .module('users.routes') + .config(routeConfig); + + routeConfig.$inject = ['$stateProvider']; + + function routeConfig($stateProvider) { // Users state routing $stateProvider .state('settings', { abstract: true, url: '/settings', templateUrl: 'modules/users/client/views/settings/settings.client.view.html', + controller: 'SettingsController', + controllerAs: 'vm', data: { roles: ['user', 'admin'] } @@ -16,6 +24,8 @@ angular.module('users').config(['$stateProvider', .state('settings.profile', { url: '/profile', templateUrl: 'modules/users/client/views/settings/edit-profile.client.view.html', + controller: 'EditProfileController', + controllerAs: 'vm', data: { pageTitle: 'Settings' } @@ -23,6 +33,8 @@ angular.module('users').config(['$stateProvider', .state('settings.password', { url: '/password', templateUrl: 'modules/users/client/views/settings/change-password.client.view.html', + controller: 'ChangePasswordController', + controllerAs: 'vm', data: { pageTitle: 'Settings password' } @@ -30,6 +42,8 @@ angular.module('users').config(['$stateProvider', .state('settings.accounts', { url: '/accounts', templateUrl: 'modules/users/client/views/settings/manage-social-accounts.client.view.html', + controller: 'SocialAccountsController', + controllerAs: 'vm', data: { pageTitle: 'Settings accounts' } @@ -37,6 +51,8 @@ angular.module('users').config(['$stateProvider', .state('settings.picture', { url: '/picture', templateUrl: 'modules/users/client/views/settings/change-profile-picture.client.view.html', + controller: 'ChangeProfilePictureController', + controllerAs: 'vm', data: { pageTitle: 'Settings picture' } @@ -44,11 +60,15 @@ angular.module('users').config(['$stateProvider', .state('authentication', { abstract: true, url: '/authentication', - templateUrl: 'modules/users/client/views/authentication/authentication.client.view.html' + templateUrl: 'modules/users/client/views/authentication/authentication.client.view.html', + controller: 'AuthenticationController', + controllerAs: 'vm' }) .state('authentication.signup', { url: '/signup', templateUrl: 'modules/users/client/views/authentication/signup.client.view.html', + controller: 'AuthenticationController', + controllerAs: 'vm', data: { pageTitle: 'Signup' } @@ -56,6 +76,8 @@ angular.module('users').config(['$stateProvider', .state('authentication.signin', { url: '/signin?err', templateUrl: 'modules/users/client/views/authentication/signin.client.view.html', + controller: 'AuthenticationController', + controllerAs: 'vm', data: { pageTitle: 'Signin' } @@ -68,6 +90,8 @@ angular.module('users').config(['$stateProvider', .state('password.forgot', { url: '/forgot', templateUrl: 'modules/users/client/views/password/forgot-password.client.view.html', + controller: 'PasswordController', + controllerAs: 'vm', data: { pageTitle: 'Password forgot' } @@ -94,9 +118,11 @@ angular.module('users').config(['$stateProvider', .state('password.reset.form', { url: '/:token', templateUrl: 'modules/users/client/views/password/reset-password.client.view.html', + controller: 'PasswordController', + controllerAs: 'vm', data: { pageTitle: 'Password reset form' } }); } -]); +})(); diff --git a/modules/users/client/controllers/admin/list-users.client.controller.js b/modules/users/client/controllers/admin/list-users.client.controller.js index 0e0114947c..cd0fa74df6 100644 --- a/modules/users/client/controllers/admin/list-users.client.controller.js +++ b/modules/users/client/controllers/admin/list-users.client.controller.js @@ -1,31 +1,42 @@ -'use strict'; +(function () { + 'use strict'; -angular.module('users.admin').controller('UserListController', ['$scope', '$filter', 'Admin', - function ($scope, $filter, Admin) { - Admin.query(function (data) { - $scope.users = data; - $scope.buildPager(); + angular + .module('users.admin') + .controller('UserListController', UserListController); + + UserListController.$inject = ['$scope', '$filter', 'AdminService']; + + function UserListController($scope, $filter, AdminService) { + var vm = this; + vm.buildPager = buildPager; + vm.figureOutItemsToDisplay = figureOutItemsToDisplay; + vm.pageChanged = pageChanged; + + AdminService.query(function (data) { + vm.users = data; + vm.buildPager(); }); - $scope.buildPager = function () { - $scope.pagedItems = []; - $scope.itemsPerPage = 15; - $scope.currentPage = 1; - $scope.figureOutItemsToDisplay(); - }; + function buildPager() { + vm.pagedItems = []; + vm.itemsPerPage = 15; + vm.currentPage = 1; + vm.figureOutItemsToDisplay(); + } - $scope.figureOutItemsToDisplay = function () { - $scope.filteredItems = $filter('filter')($scope.users, { - $: $scope.search + function figureOutItemsToDisplay() { + vm.filteredItems = $filter('filter')(vm.users, { + $: vm.search }); - $scope.filterLength = $scope.filteredItems.length; - var begin = (($scope.currentPage - 1) * $scope.itemsPerPage); - var end = begin + $scope.itemsPerPage; - $scope.pagedItems = $scope.filteredItems.slice(begin, end); - }; + vm.filterLength = vm.filteredItems.length; + var begin = ((vm.currentPage - 1) * vm.itemsPerPage); + var end = begin + vm.itemsPerPage; + vm.pagedItems = vm.filteredItems.slice(begin, end); + } - $scope.pageChanged = function () { - $scope.figureOutItemsToDisplay(); - }; + function pageChanged() { + vm.figureOutItemsToDisplay(); + } } -]); +})(); diff --git a/modules/users/client/controllers/admin/user.client.controller.js b/modules/users/client/controllers/admin/user.client.controller.js index 7a017598d5..95a5c7c7b9 100644 --- a/modules/users/client/controllers/admin/user.client.controller.js +++ b/modules/users/client/controllers/admin/user.client.controller.js @@ -1,40 +1,50 @@ -'use strict'; +(function () { + 'use strict'; -angular.module('users.admin').controller('UserController', ['$scope', '$state', 'Authentication', 'userResolve', - function ($scope, $state, Authentication, userResolve) { - $scope.authentication = Authentication; - $scope.user = userResolve; + angular + .module('users.admin') + .controller('UserController', UserController); - $scope.remove = function (user) { + UserController.$inject = ['$scope', '$state', 'Authentication', 'userResolve']; + + function UserController($scope, $state, Authentication, user) { + var vm = this; + + vm.authentication = Authentication; + vm.user = user; + vm.remove = remove; + vm.update = update; + + function remove(user) { if (confirm('Are you sure you want to delete this user?')) { if (user) { user.$remove(); - $scope.users.splice($scope.users.indexOf(user), 1); + vm.users.splice(vm.users.indexOf(user), 1); } else { - $scope.user.$remove(function () { + vm.user.$remove(function () { $state.go('admin.users'); }); } } - }; + } - $scope.update = function (isValid) { + function update(isValid) { if (!isValid) { - $scope.$broadcast('show-errors-check-validity', 'userForm'); + $scope.$broadcast('show-errors-check-validity', 'vm.userForm'); return false; } - var user = $scope.user; + var user = vm.user; user.$update(function () { $state.go('admin.user', { userId: user._id }); }, function (errorResponse) { - $scope.error = errorResponse.data.message; + vm.error = errorResponse.data.message; }); - }; + } } -]); +})(); diff --git a/modules/users/client/controllers/authentication.client.controller.js b/modules/users/client/controllers/authentication.client.controller.js index 47dd234491..ac13c46fda 100644 --- a/modules/users/client/controllers/authentication.client.controller.js +++ b/modules/users/client/controllers/authentication.client.controller.js @@ -1,66 +1,77 @@ -'use strict'; +(function () { + 'use strict'; -angular.module('users').controller('AuthenticationController', ['$scope', '$state', '$http', '$location', '$window', 'Authentication', 'PasswordValidator', - function ($scope, $state, $http, $location, $window, Authentication, PasswordValidator) { - $scope.authentication = Authentication; - $scope.popoverMsg = PasswordValidator.getPopoverMsg(); + angular + .module('users') + .controller('AuthenticationController', AuthenticationController); + + AuthenticationController.$inject = ['$scope', '$state', '$http', '$location', '$window', 'Authentication', 'PasswordValidator']; + + function AuthenticationController($scope, $state, $http, $location, $window, Authentication, PasswordValidator) { + var vm = this; + + vm.authentication = Authentication; + vm.getPopoverMsg = PasswordValidator.getPopoverMsg; + vm.signup = signup; + vm.signin = signin; + vm.callOauthProvider = callOauthProvider; // Get an eventual error defined in the URL query string: - $scope.error = $location.search().err; + vm.error = $location.search().err; // If user is signed in then redirect back home - if ($scope.authentication.user) { + if (vm.authentication.user) { $location.path('/'); } - $scope.signup = function (isValid) { - $scope.error = null; + function signup(isValid) { + vm.error = null; if (!isValid) { - $scope.$broadcast('show-errors-check-validity', 'userForm'); + $scope.$broadcast('show-errors-check-validity', 'vm.userForm'); return false; } - $http.post('/api/auth/signup', $scope.credentials).success(function (response) { + $http.post('/api/auth/signup', vm.credentials).success(function (response) { // If successful we assign the response to the global user model - $scope.authentication.user = response; + vm.authentication.user = response; // And redirect to the previous or home page $state.go($state.previous.state.name || 'home', $state.previous.params); }).error(function (response) { - $scope.error = response.message; + vm.error = response.message; }); - }; + } - $scope.signin = function (isValid) { - $scope.error = null; + function signin(isValid) { + vm.error = null; if (!isValid) { - $scope.$broadcast('show-errors-check-validity', 'userForm'); + $scope.$broadcast('show-errors-check-validity', 'vm.userForm'); return false; } - $http.post('/api/auth/signin', $scope.credentials).success(function (response) { + $http.post('/api/auth/signin', vm.credentials).success(function (response) { // If successful we assign the response to the global user model - $scope.authentication.user = response; + vm.authentication.user = response; // And redirect to the previous or home page $state.go($state.previous.state.name || 'home', $state.previous.params); }).error(function (response) { - $scope.error = response.message; + vm.error = response.message; }); - }; + } // OAuth provider request - $scope.callOauthProvider = function (url) { + function callOauthProvider(url) { if ($state.previous && $state.previous.href) { url += '?redirect_to=' + encodeURIComponent($state.previous.href); } // Effectively call OAuth authentication route: $window.location.href = url; - }; + } } -]); +})(); diff --git a/modules/users/client/controllers/password.client.controller.js b/modules/users/client/controllers/password.client.controller.js index 572a5f5237..3656a4d063 100644 --- a/modules/users/client/controllers/password.client.controller.js +++ b/modules/users/client/controllers/password.client.controller.js @@ -1,50 +1,60 @@ -'use strict'; +(function () { + 'use strict'; -angular.module('users').controller('PasswordController', ['$scope', '$stateParams', '$http', '$location', 'Authentication', 'PasswordValidator', - function ($scope, $stateParams, $http, $location, Authentication, PasswordValidator) { - $scope.authentication = Authentication; - $scope.popoverMsg = PasswordValidator.getPopoverMsg(); + angular + .module('users') + .controller('PasswordController', PasswordController); + + PasswordController.$inject = ['$scope', '$stateParams', '$http', '$location', 'Authentication', 'PasswordValidator']; + + function PasswordController($scope, $stateParams, $http, $location, Authentication, PasswordValidator) { + var vm = this; + + vm.resetUserPassword = resetUserPassword; + vm.askForPasswordReset = askForPasswordReset; + vm.authentication = Authentication; + vm.getPopoverMsg = PasswordValidator.getPopoverMsg; // If user is signed in then redirect back home - if ($scope.authentication.user) { + if (vm.authentication.user) { $location.path('/'); } // Submit forgotten password account id - $scope.askForPasswordReset = function (isValid) { - $scope.success = $scope.error = null; + function askForPasswordReset(isValid) { + vm.success = vm.error = null; if (!isValid) { - $scope.$broadcast('show-errors-check-validity', 'forgotPasswordForm'); + $scope.$broadcast('show-errors-check-validity', 'vm.forgotPasswordForm'); return false; } - $http.post('/api/auth/forgot', $scope.credentials).success(function (response) { + $http.post('/api/auth/forgot', vm.credentials).success(function (response) { // Show user success message and clear form - $scope.credentials = null; - $scope.success = response.message; + vm.credentials = null; + vm.success = response.message; }).error(function (response) { // Show user error message and clear form - $scope.credentials = null; - $scope.error = response.message; + vm.credentials = null; + vm.error = response.message; }); - }; + } // Change user password - $scope.resetUserPassword = function (isValid) { - $scope.success = $scope.error = null; + function resetUserPassword(isValid) { + vm.success = vm.error = null; if (!isValid) { - $scope.$broadcast('show-errors-check-validity', 'resetPasswordForm'); + $scope.$broadcast('show-errors-check-validity', 'vm.resetPasswordForm'); return false; } - $http.post('/api/auth/reset/' + $stateParams.token, $scope.passwordDetails).success(function (response) { + $http.post('/api/auth/reset/' + $stateParams.token, vm.passwordDetails).success(function (response) { // If successful show success message and clear form - $scope.passwordDetails = null; + vm.passwordDetails = null; // Attach user profile Authentication.user = response; @@ -52,8 +62,8 @@ angular.module('users').controller('PasswordController', ['$scope', '$stateParam // And redirect to the index page $location.path('/password/reset/success'); }).error(function (response) { - $scope.error = response.message; + vm.error = response.message; }); - }; + } } -]); +})(); diff --git a/modules/users/client/controllers/settings/change-password.client.controller.js b/modules/users/client/controllers/settings/change-password.client.controller.js index ff8c4179b1..d1cabc03fc 100644 --- a/modules/users/client/controllers/settings/change-password.client.controller.js +++ b/modules/users/client/controllers/settings/change-password.client.controller.js @@ -1,28 +1,37 @@ -'use strict'; +(function () { + 'use strict'; -angular.module('users').controller('ChangePasswordController', ['$scope', '$http', 'Authentication', 'PasswordValidator', - function ($scope, $http, Authentication, PasswordValidator) { - $scope.user = Authentication.user; - $scope.popoverMsg = PasswordValidator.getPopoverMsg(); + angular + .module('users') + .controller('ChangePasswordController', ChangePasswordController); + + ChangePasswordController.$inject = ['$scope', '$http', 'Authentication', 'PasswordValidator']; + + function ChangePasswordController($scope, $http, Authentication, PasswordValidator) { + var vm = this; + + vm.user = Authentication.user; + vm.changeUserPassword = changeUserPassword; + vm.getPopoverMsg = PasswordValidator.getPopoverMsg; // Change user password - $scope.changeUserPassword = function (isValid) { - $scope.success = $scope.error = null; + function changeUserPassword(isValid) { + vm.success = vm.error = null; if (!isValid) { - $scope.$broadcast('show-errors-check-validity', 'passwordForm'); + $scope.$broadcast('show-errors-check-validity', 'vm.passwordForm'); return false; } - $http.post('/api/users/password', $scope.passwordDetails).success(function (response) { + $http.post('/api/users/password', vm.passwordDetails).success(function (response) { // If successful show success message and clear form - $scope.$broadcast('show-errors-reset', 'passwordForm'); - $scope.success = true; - $scope.passwordDetails = null; + $scope.$broadcast('show-errors-reset', 'vm.passwordForm'); + vm.success = true; + vm.passwordDetails = null; }).error(function (response) { - $scope.error = response.message; + vm.error = response.message; }); - }; + } } -]); +})(); diff --git a/modules/users/client/controllers/settings/change-profile-picture.client.controller.js b/modules/users/client/controllers/settings/change-profile-picture.client.controller.js index 545186dca9..6c5f75432d 100644 --- a/modules/users/client/controllers/settings/change-profile-picture.client.controller.js +++ b/modules/users/client/controllers/settings/change-profile-picture.client.controller.js @@ -1,18 +1,31 @@ -'use strict'; +(function () { + 'use strict'; -angular.module('users').controller('ChangeProfilePictureController', ['$scope', '$timeout', '$window', 'Authentication', 'FileUploader', - function ($scope, $timeout, $window, Authentication, FileUploader) { - $scope.user = Authentication.user; - $scope.imageURL = $scope.user.profileImageURL; + angular + .module('users') + .controller('ChangeProfilePictureController', ChangeProfilePictureController); + ChangeProfilePictureController.$inject = ['$scope', '$timeout', '$window', 'Authentication', 'FileUploader']; + + function ChangeProfilePictureController($scope, $timeout, $window, Authentication, FileUploader) { + var vm = this; + + vm.user = Authentication.user; + vm.imageURL = vm.user.profileImageURL; + vm.uploadProfilePicture = uploadProfilePicture; + + vm.cancelUpload = cancelUpload; // Create file uploader instance - $scope.uploader = new FileUploader({ + vm.uploader = new FileUploader({ url: 'api/users/picture', - alias: 'newProfilePicture' + alias: 'newProfilePicture', + onAfterAddingFile: onAfterAddingFile, + onSuccessItem: onSuccessItem, + onErrorItem: onErrorItem }); // Set file uploader image filter - $scope.uploader.filters.push({ + vm.uploader.filters.push({ name: 'imageFilter', fn: function (item, options) { var type = '|' + item.type.slice(item.type.lastIndexOf('/') + 1) + '|'; @@ -21,53 +34,53 @@ angular.module('users').controller('ChangeProfilePictureController', ['$scope', }); // Called after the user selected a new picture file - $scope.uploader.onAfterAddingFile = function (fileItem) { + function onAfterAddingFile(fileItem) { if ($window.FileReader) { var fileReader = new FileReader(); fileReader.readAsDataURL(fileItem._file); fileReader.onload = function (fileReaderEvent) { $timeout(function () { - $scope.imageURL = fileReaderEvent.target.result; + vm.imageURL = fileReaderEvent.target.result; }, 0); }; } - }; + } // Called after the user has successfully uploaded a new picture - $scope.uploader.onSuccessItem = function (fileItem, response, status, headers) { + function onSuccessItem(fileItem, response, status, headers) { // Show success message - $scope.success = true; + vm.success = true; // Populate user object - $scope.user = Authentication.user = response; + vm.user = Authentication.user = response; // Clear upload buttons - $scope.cancelUpload(); - }; + cancelUpload(); + } // Called after the user has failed to uploaded a new picture - $scope.uploader.onErrorItem = function (fileItem, response, status, headers) { + function onErrorItem(fileItem, response, status, headers) { // Clear upload buttons - $scope.cancelUpload(); + cancelUpload(); // Show error message - $scope.error = response.message; - }; + vm.error = response.message; + } // Change user profile picture - $scope.uploadProfilePicture = function () { + function uploadProfilePicture() { // Clear messages - $scope.success = $scope.error = null; + vm.success = vm.error = null; // Start upload - $scope.uploader.uploadAll(); - }; + vm.uploader.uploadAll(); + } // Cancel the upload process - $scope.cancelUpload = function () { - $scope.uploader.clearQueue(); - $scope.imageURL = $scope.user.profileImageURL; - }; + function cancelUpload() { + vm.uploader.clearQueue(); + vm.imageURL = vm.user.profileImageURL; + } } -]); +})(); diff --git a/modules/users/client/controllers/settings/edit-profile.client.controller.js b/modules/users/client/controllers/settings/edit-profile.client.controller.js index edade73f11..0d6b2d7c1d 100644 --- a/modules/users/client/controllers/settings/edit-profile.client.controller.js +++ b/modules/users/client/controllers/settings/edit-profile.client.controller.js @@ -1,29 +1,38 @@ -'use strict'; +(function () { + 'use strict'; -angular.module('users').controller('EditProfileController', ['$scope', '$http', '$location', 'Users', 'Authentication', - function ($scope, $http, $location, Users, Authentication) { - $scope.user = Authentication.user; + angular + .module('users') + .controller('EditProfileController', EditProfileController); + + EditProfileController.$inject = ['$scope', '$http', '$location', 'Users', 'Authentication']; + + function EditProfileController($scope, $http, $location, Users, Authentication) { + var vm = this; + + vm.user = Authentication.user; + vm.updateUserProfile = updateUserProfile; // Update a user profile - $scope.updateUserProfile = function (isValid) { - $scope.success = $scope.error = null; + function updateUserProfile(isValid) { + vm.success = vm.error = null; if (!isValid) { - $scope.$broadcast('show-errors-check-validity', 'userForm'); + $scope.$broadcast('show-errors-check-validity', 'vm.userForm'); return false; } - var user = new Users($scope.user); + var user = new Users(vm.user); user.$update(function (response) { - $scope.$broadcast('show-errors-reset', 'userForm'); + $scope.$broadcast('show-errors-reset', 'vm.userForm'); - $scope.success = true; + vm.success = true; Authentication.user = response; }, function (response) { - $scope.error = response.data.message; + vm.error = response.data.message; }); - }; + } } -]); +})(); diff --git a/modules/users/client/controllers/settings/manage-social-accounts.client.controller.js b/modules/users/client/controllers/settings/manage-social-accounts.client.controller.js index 0cb16aea04..5e5e3f2e06 100644 --- a/modules/users/client/controllers/settings/manage-social-accounts.client.controller.js +++ b/modules/users/client/controllers/settings/manage-social-accounts.client.controller.js @@ -1,26 +1,37 @@ -'use strict'; +(function () { + 'use strict'; -angular.module('users').controller('SocialAccountsController', ['$scope', '$http', 'Authentication', - function ($scope, $http, Authentication) { - $scope.user = Authentication.user; + angular + .module('users') + .controller('SocialAccountsController', SocialAccountsController); + + SocialAccountsController.$inject = ['$scope', '$http', 'Authentication']; + + function SocialAccountsController($scope, $http, Authentication) { + var vm = this; + + vm.user = Authentication.user; + vm.hasConnectedAdditionalSocialAccounts = hasConnectedAdditionalSocialAccounts; + vm.isConnectedSocialAccount = isConnectedSocialAccount; + vm.removeUserSocialAccount = removeUserSocialAccount; // Check if there are additional accounts - $scope.hasConnectedAdditionalSocialAccounts = function (provider) { - for (var i in $scope.user.additionalProvidersData) { + function hasConnectedAdditionalSocialAccounts(provider) { + for (var i in vm.user.additionalProvidersData) { return true; } return false; - }; + } // 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]); - }; + function isConnectedSocialAccount(provider) { + return vm.user.provider === provider || (vm.user.additionalProvidersData && vm.user.additionalProvidersData[provider]); + } // Remove a user social account - $scope.removeUserSocialAccount = function (provider) { - $scope.success = $scope.error = null; + function removeUserSocialAccount(provider) { + vm.success = vm.error = null; $http.delete('/api/users/accounts', { params: { @@ -28,11 +39,11 @@ angular.module('users').controller('SocialAccountsController', ['$scope', '$http } }).success(function (response) { // If successful show success message and clear form - $scope.success = true; - $scope.user = Authentication.user = response; + vm.success = true; + vm.user = Authentication.user = response; }).error(function (response) { - $scope.error = response.message; + vm.error = response.message; }); - }; + } } -]); +})(); diff --git a/modules/users/client/controllers/settings/settings.client.controller.js b/modules/users/client/controllers/settings/settings.client.controller.js index 475a6b057c..7f637e1ff2 100644 --- a/modules/users/client/controllers/settings/settings.client.controller.js +++ b/modules/users/client/controllers/settings/settings.client.controller.js @@ -1,7 +1,15 @@ -'use strict'; +(function () { + 'use strict'; -angular.module('users').controller('SettingsController', ['$scope', 'Authentication', - function ($scope, Authentication) { - $scope.user = Authentication.user; + angular + .module('users') + .controller('SettingsController', SettingsController); + + SettingsController.$inject = ['$scope', 'Authentication']; + + function SettingsController($scope, Authentication) { + var vm = this; + + vm.user = Authentication.user; } -]); +})(); diff --git a/modules/users/client/directives/password-validator.client.directive.js b/modules/users/client/directives/password-validator.client.directive.js index ceb56e16c9..1825311e89 100644 --- a/modules/users/client/directives/password-validator.client.directive.js +++ b/modules/users/client/directives/password-validator.client.directive.js @@ -1,44 +1,64 @@ -'use strict'; +(function () { + 'use strict'; -angular.module('users') - .directive('passwordValidator', ['PasswordValidator', function(PasswordValidator) { - return { + angular + .module('users') + .directive('passwordValidator', passwordValidator); + + passwordValidator.$inject = ['PasswordValidator']; + + function passwordValidator(PasswordValidator) { + var directive = { require: 'ngModel', - link: function(scope, element, attrs, ngModel) { - ngModel.$validators.requirements = function (password) { - var status = true; - if (password) { - var result = PasswordValidator.getResult(password); - var requirementsIdx = 0; - - // Requirements Meter - visual indicator for users - var requirementsMeter = [ - { color: 'danger', progress: '20' }, - { color: 'warning', progress: '40' }, - { color: 'info', progress: '60' }, - { color: 'primary', progress: '80' }, - { color: 'success', progress: '100' } - ]; - - if (result.errors.length < requirementsMeter.length) { - requirementsIdx = requirementsMeter.length - result.errors.length - 1; - } - - scope.requirementsColor = requirementsMeter[requirementsIdx].color; - scope.requirementsProgress = requirementsMeter[requirementsIdx].progress; - - if (result.errors.length) { - scope.popoverMsg = PasswordValidator.getPopoverMsg(); - scope.passwordErrors = result.errors; - status = false; - } else { - scope.popoverMsg = ''; - scope.passwordErrors = []; - status = true; - } - } - return status; - }; - } + link: link }; - }]); + + return directive; + + function link(scope, element, attrs, ngModel) { + ngModel.$validators.requirements = function (password) { + var status = true; + if (password) { + var result = PasswordValidator.getResult(password); + var requirementsIdx = 0; + + // Requirements Meter - visual indicator for users + var requirementsMeter = [{ + color: 'danger', + progress: '20' + }, { + color: 'warning', + progress: '40' + }, { + color: 'info', + progress: '60' + }, { + color: 'primary', + progress: '80' + }, { + color: 'success', + progress: '100' + }]; + + if (result.errors.length < requirementsMeter.length) { + requirementsIdx = requirementsMeter.length - result.errors.length - 1; + } + + scope.requirementsColor = requirementsMeter[requirementsIdx].color; + scope.requirementsProgress = requirementsMeter[requirementsIdx].progress; + + if (result.errors.length) { + scope.getPopoverMsg = PasswordValidator.getPopoverMsg(); + scope.passwordErrors = result.errors; + status = false; + } else { + scope.getPopoverMsg = ''; + scope.passwordErrors = []; + status = true; + } + } + return status; + }; + } + } +})(); diff --git a/modules/users/client/directives/password-verify.client.directive.js b/modules/users/client/directives/password-verify.client.directive.js index 178209eb66..ae594a71f6 100644 --- a/modules/users/client/directives/password-verify.client.directive.js +++ b/modules/users/client/directives/password-verify.client.directive.js @@ -1,28 +1,37 @@ -'use strict'; +(function () { + 'use strict'; -angular.module('users') - .directive('passwordVerify', [function() { - return { + angular + .module('users') + .directive('passwordVerify', passwordVerify); + + function passwordVerify() { + var directive = { require: 'ngModel', scope: { passwordVerify: '=' }, - link: function(scope, element, attrs, ngModel) { - var status = true; - scope.$watch(function() { - var combined; - if (scope.passwordVerify || ngModel) { - combined = scope.passwordVerify + '_' + ngModel; - } - return combined; - }, function(value) { - if (value) { - ngModel.$validators.passwordVerify = function (password) { - var origin = scope.passwordVerify; - return (origin !== password) ? false : true; - }; - } - }); - } + link: link }; - }]); + + return directive; + + function link(scope, element, attrs, ngModel) { + var status = true; + scope.$watch(function () { + var combined; + if (scope.passwordVerify || ngModel) { + combined = scope.passwordVerify + '_' + ngModel; + } + return combined; + }, function (value) { + if (value) { + ngModel.$validators.passwordVerify = function (password) { + var origin = scope.passwordVerify; + return (origin !== password) ? false : true; + }; + } + }); + } + } +})(); diff --git a/modules/users/client/directives/users.client.directive.js b/modules/users/client/directives/users.client.directive.js index cca4eb81ce..a48202e56f 100644 --- a/modules/users/client/directives/users.client.directive.js +++ b/modules/users/client/directives/users.client.directive.js @@ -1,14 +1,24 @@ -'use strict'; +(function () { + 'use strict'; -// Users directive used to force lowercase input -angular.module('users').directive('lowercase', function () { - return { - require: 'ngModel', - link: function (scope, element, attrs, modelCtrl) { + // Users directive used to force lowercase input + angular + .module('users') + .directive('lowercase', lowercase); + + function lowercase() { + var directive = { + require: 'ngModel', + link: link + }; + + return directive; + + function link(scope, element, attrs, modelCtrl) { modelCtrl.$parsers.push(function (input) { return input ? input.toLowerCase() : ''; }); element.css('text-transform', 'lowercase'); } - }; -}); + } +})(); diff --git a/modules/users/client/services/authentication.client.service.js b/modules/users/client/services/authentication.client.service.js index b535d46515..b36d5ef0ee 100644 --- a/modules/users/client/services/authentication.client.service.js +++ b/modules/users/client/services/authentication.client.service.js @@ -1,12 +1,19 @@ -'use strict'; +(function () { + 'use strict'; -// Authentication service for user variables -angular.module('users').factory('Authentication', ['$window', - function ($window) { + // Authentication service for user variables + + angular + .module('users.services') + .factory('Authentication', Authentication); + + Authentication.$inject = ['$window']; + + function Authentication($window) { var auth = { user: $window.user }; return auth; } -]); +})(); diff --git a/modules/users/client/services/password-validator.client.service.js b/modules/users/client/services/password-validator.client.service.js index f336259909..ac0f4bce8e 100644 --- a/modules/users/client/services/password-validator.client.service.js +++ b/modules/users/client/services/password-validator.client.service.js @@ -1,19 +1,33 @@ -'use strict'; +(function () { + 'use strict'; -// PasswordValidator service used for testing the password strength -angular.module('users').factory('PasswordValidator', ['$window', - function ($window) { + // PasswordValidator service used for testing the password strength + angular + .module('users.services') + .factory('PasswordValidator', PasswordValidator); + + PasswordValidator.$inject = ['$window']; + + function PasswordValidator($window) { var owaspPasswordStrengthTest = $window.owaspPasswordStrengthTest; - return { - getResult: function (password) { - var result = owaspPasswordStrengthTest.test(password); - return result; - }, - getPopoverMsg: function () { - var popoverMsg = 'Please enter a passphrase or password with 10 or more characters, numbers, lowercase, uppercase, and special characters.'; - return popoverMsg; - } + var service = { + getResult: getResult, + getPopoverMsg: getPopoverMsg }; + + return service; + + function getResult(password) { + var result = owaspPasswordStrengthTest.test(password); + return result; + } + + function getPopoverMsg() { + var popoverMsg = 'Please enter a passphrase or password with 10 or more characters, numbers, lowercase, uppercase, and special characters.'; + + return popoverMsg; + } } -]); + +})(); diff --git a/modules/users/client/services/users.client.service.js b/modules/users/client/services/users.client.service.js index aaac9c3591..17d1947dce 100644 --- a/modules/users/client/services/users.client.service.js +++ b/modules/users/client/services/users.client.service.js @@ -1,19 +1,30 @@ -'use strict'; +(function () { + 'use strict'; -// Users service used for communicating with the users REST endpoint -angular.module('users').factory('Users', ['$resource', - function ($resource) { + // Users service used for communicating with the users REST endpoint + angular + .module('users.services') + .factory('UsersService', UsersService); + + UsersService.$inject = ['$resource']; + + function UsersService($resource) { return $resource('api/users', {}, { update: { method: 'PUT' } }); } -]); -//TODO this should be Users service -angular.module('users.admin').factory('Admin', ['$resource', - function ($resource) { + + //TODO this should be Users service + angular + .module('users.admin.services') + .factory('AdminService', AdminService); + + AdminService.$inject = ['$resource']; + + function AdminService($resource) { return $resource('api/users/:userId', { userId: '@_id' }, { @@ -22,4 +33,4 @@ angular.module('users.admin').factory('Admin', ['$resource', } }); } -]); +})(); diff --git a/modules/users/client/users.client.module.js b/modules/users/client/users.client.module.js index 805261f885..e4a39a52ab 100644 --- a/modules/users/client/users.client.module.js +++ b/modules/users/client/users.client.module.js @@ -1,6 +1,10 @@ -'use strict'; +(function (app) { + 'use strict'; -// Use Application configuration module to register a new module -ApplicationConfiguration.registerModule('users', ['core']); -ApplicationConfiguration.registerModule('users.admin', ['core.admin']); -ApplicationConfiguration.registerModule('users.admin.routes', ['core.admin.routes']); + app.registerModule('users'); + app.registerModule('users.admin'); + app.registerModule('users.services'); + app.registerModule('users.admin.services'); + app.registerModule('users.routes', ['ui.router']); + app.registerModule('users.admin.routes', ['ui.router', 'users.admin.services']); +})(ApplicationConfiguration); diff --git a/modules/users/client/views/admin/edit-user.client.view.html b/modules/users/client/views/admin/edit-user.client.view.html index e7cc0d2b65..559af2812c 100644 --- a/modules/users/client/views/admin/edit-user.client.view.html +++ b/modules/users/client/views/admin/edit-user.client.view.html @@ -1,29 +1,29 @@
-
+
- -
+ +

First name is required.

- -
+ +

Last name is required.

- -
+ +

At least one role is required.

@@ -31,8 +31,8 @@

User

-
- +
+
diff --git a/modules/users/client/views/admin/list-users.client.view.html b/modules/users/client/views/admin/list-users.client.view.html index 3bae3509e5..826f19e7f5 100644 --- a/modules/users/client/views/admin/list-users.client.view.html +++ b/modules/users/client/views/admin/list-users.client.view.html @@ -5,17 +5,17 @@

Users

- +
- +

- +
diff --git a/modules/users/client/views/admin/view-user.client.view.html b/modules/users/client/views/admin/view-user.client.view.html index 491c5a0deb..2ab3272884 100644 --- a/modules/users/client/views/admin/view-user.client.view.html +++ b/modules/users/client/views/admin/view-user.client.view.html @@ -2,13 +2,13 @@