diff --git a/app/models/form_field.server.model.js b/app/models/form_field.server.model.js index b8f756e0..0487a49d 100644 --- a/app/models/form_field.server.model.js +++ b/app/models/form_field.server.model.js @@ -10,22 +10,22 @@ var mongoose = require('mongoose'), function validateFormFieldType(value) { if (!value || typeof myVar !== 'string' ) { return false; } - var validHTMLTypes = [ - 'textfield', - 'textarea', - 'statement' - 'email', - 'legal', - 'url', - 'number', - 'filefield', - 'radio', - 'checkbox', - 'date', - 'dropdown', - 'hidden', - 'password', - ]; + var validTypes = [ + 'textfield', + 'textarea', + 'statement', + 'email', + 'legal', + 'url', + 'number', + 'filefield', + 'radio', + 'checkbox', + 'date', + 'dropdown', + 'hidden', + 'password' + ]; if (validTypes.indexOf(value) > -1) { return true; diff --git a/public/config.js b/public/config.js index 920f8981..109385a5 100755 --- a/public/config.js +++ b/public/config.js @@ -4,7 +4,7 @@ var ApplicationConfiguration = (function() { // Init module configuration options var applicationModuleName = 'medform'; - var applicationModuleVendorDependencies = ['ngResource', 'ngAnimate', 'ui.router', 'ui.bootstrap', 'ui.utils', 'permission']; + var applicationModuleVendorDependencies = ['ngResource', 'ngAnimate', 'ui.router', 'ui.bootstrap', 'ui.utils']; // Add a new vertical module var registerModule = function(moduleName, dependencies) { diff --git a/public/modules/core/controllers/header.client.controller.js b/public/modules/core/controllers/header.client.controller.js index 4c0d76f7..9d90f5e4 100755 --- a/public/modules/core/controllers/header.client.controller.js +++ b/public/modules/core/controllers/header.client.controller.js @@ -7,17 +7,23 @@ angular.module('core').controller('HeaderController', ['$scope', 'Principal', 'M $scope.hideNav = false; $scope.menu = Menus.getMenu('topbar'); - // Principal.identity().then(function(user){ - // $scope.authentication.user = user; - // }).then(function(){ - $scope.authentication.user = Principal.identity(); + Principal.identity().then(function(user){ + $scope.authentication.user = user; + }).then(function(){ $scope.signout = function() { - var response_obj = Principal.signout(); + // $http.get('/auth/signout').success(function(response) { + // $state.go('home'); + // }).error(function(error) { + // $scope.error = (error.message || error); + // }); + + Principal.signout(); if( angular.isDefined(response_obj.error) ){ $scope.error = response_obj.error; } else{ $state.go('home'); } + }; $scope.toggleCollapsibleMenu = function() { @@ -35,7 +41,7 @@ angular.module('core').controller('HeaderController', ['$scope', 'Principal', 'M } } }); - // }); + }); } ]); \ No newline at end of file diff --git a/public/modules/core/controllers/home.client.controller.js b/public/modules/core/controllers/home.client.controller.js index ca686bee..9f251a9c 100755 --- a/public/modules/core/controllers/home.client.controller.js +++ b/public/modules/core/controllers/home.client.controller.js @@ -5,15 +5,14 @@ angular.module('core').controller('HomeController', ['$scope', 'Principal', function($scope, Principal) { // This provides Principal context. $scope.authentication = Principal; - $scope.authentication.user = Principal.identity(); console.log($scope.authentication.user); - // Principal.identity().then(function(user){ - // console.log(user); - // $scope.authentication.user = user; - // }, function(){ - // console.log('error'); - // }); + Principal.identity().then(function(user){ + console.log(user); + $scope.authentication.user = user; + }, function(){ + console.log('error'); + }); // console.log("user.displayName: "+Principal.user()._id); } diff --git a/public/modules/forms/controllers/submit-form.client.controller.js b/public/modules/forms/controllers/submit-form.client.controller.js index 699016fe..bdd0d0ef 100644 --- a/public/modules/forms/controllers/submit-form.client.controller.js +++ b/public/modules/forms/controllers/submit-form.client.controller.js @@ -1,8 +1,8 @@ 'use strict'; // Forms controller -angular.module('forms').controller('SubmitFormController', ['$scope', '$stateParams', '$state', 'Principal', 'Forms', 'CurrentForm','$http', - function($scope, $stateParams, $state, Principal, Forms, CurrentForm, $http) { +angular.module('forms').controller('SubmitFormController', ['$scope', '$stateParams', '$state', 'Principal', 'Forms', 'CurrentForm', + function($scope, $stateParams, $state, Principal, Forms, CurrentForm) { // Principal.identity().then(function(user){ // $scope.authentication.user = user; diff --git a/public/modules/forms/controllers/view-form.client.controller.js b/public/modules/forms/controllers/view-form.client.controller.js index 084292fa..9d27906f 100644 --- a/public/modules/forms/controllers/view-form.client.controller.js +++ b/public/modules/forms/controllers/view-form.client.controller.js @@ -1,8 +1,8 @@ 'use strict'; // Forms controller -angular.module('forms').controller('ViewFormController', ['$scope', '$stateParams', '$state', 'Principal', 'Forms', 'CurrentForm','$http', - function($scope, $stateParams, $state, Principal, Forms, CurrentForm, $http) { +angular.module('forms').controller('ViewFormController', ['$scope', '$stateParams', '$state', 'Forms', 'CurrentForm','$http', + function($scope, $stateParams, $state, Forms, CurrentForm, $http) { // Principal.identity().then(function(user){ // $scope.authentication.user = user; diff --git a/public/modules/users/config/users.client.config.js b/public/modules/users/config/users.client.config.js index dd9c46f6..42780ac3 100755 --- a/public/modules/users/config/users.client.config.js +++ b/public/modules/users/config/users.client.config.js @@ -1,4 +1,4 @@ -// 'use strict'; +'use strict'; // Config HTTP Error Handling angular.module('users').config(['$httpProvider', @@ -27,23 +27,4 @@ angular.module('users').config(['$httpProvider', } ]); } -]).run(function(Permission, Principal) { - var User = Principal.identity(); - Permission.defineRole('anonymous', function (stateParams) { - // If the returned value is *truthy* then the user has the role, otherwise they don't - if ( !User || !Principal.isInAnyRole() ) { - return true; // Is anonymous - } - return false; - }).defineRole('admin', function (stateParams) { - if (Principal.isInRole('admin')) { - return true; // Is admin - } - return false; - }).defineRole('user', function (stateParams) { - if (Principal.isInRole('user') && !Principal.isInRole('admin') ) { - return true; // Is user - } - return false; - }); - }); \ No newline at end of file +]); \ No newline at end of file diff --git a/public/modules/users/controllers/authentication.client.controller.js b/public/modules/users/controllers/authentication.client.controller.js index 6181cb50..377437f3 100755 --- a/public/modules/users/controllers/authentication.client.controller.js +++ b/public/modules/users/controllers/authentication.client.controller.js @@ -1,7 +1,7 @@ 'use strict'; -angular.module('users').controller('AuthenticationController', ['$scope', '$http', '$location', 'Principal', '$state', - function($scope, $http, $location, Principal, $state) { +angular.module('users').controller('AuthenticationController', ['$scope', '$location', 'Principal', '$state', + function($scope, $location, Principal, $state) { $scope.authentication = Principal; // $scope.authentication.user = Principal.getUser(); @@ -21,6 +21,7 @@ angular.module('users').controller('AuthenticationController', ['$scope', '$http // $http.post('/auth/signup', $scope.credentials).success(function(response) { // // If successful we assign the response to the global user model // $scope.authentication.user = response; + // Principal.authenticate(response); // // And redirect to the index page // $location.path('/'); @@ -50,10 +51,12 @@ angular.module('users').controller('AuthenticationController', ['$scope', '$http // $http.post('/auth/signin', $scope.credentials).success(function(response) { // // If successful we assign the response to the global user model // $scope.authentication.user = response; + // Principal.authenticate(response); // // And redirect to the index page // $location.path('/'); // }).error(function(response) { + // Principal.authenticate(null); // $scope.error = response.message; // }); }; diff --git a/public/modules/users/controllers/password.client.controller.js b/public/modules/users/controllers/password.client.controller.js index 3581b2a5..dbecdf36 100755 --- a/public/modules/users/controllers/password.client.controller.js +++ b/public/modules/users/controllers/password.client.controller.js @@ -10,36 +10,43 @@ angular.module('users').controller('PasswordController', ['$scope', '$stateParam // Submit forgotten password account id $scope.askForPasswordReset = function() { - $scope.success = $scope.error = null; - - $http.post('/auth/forgot', $scope.credentials).success(function(response) { - // Show user success message and clear form - $scope.credentials = null; - $scope.success = response.message; - - }).error(function(response) { - // Show user error message and clear form - $scope.credentials = null; - $scope.error = response.message; - }); + Principal.askForPasswordReset($scope.credentials).then( + function(response){ + $scope.success = response.message + $scope.credentials = null; + }, + function(error){ + $scope.error = error; + $scope.credentials = null; + } + ); }; // Change user password $scope.resetUserPassword = function() { - $scope.success = $scope.error = null; + Principal.askForPasswordReset($scope.credentials).then( + function(response){ + $scope.credentials = null; + }, + function(error){ + $scope.error = error; + $scope.credentials = null; + } + ); + // $scope.success = $scope.error = null; - $http.post('/auth/reset/' + $stateParams.token, $scope.passwordDetails).success(function(response) { - // If successful show success message and clear form - $scope.passwordDetails = null; + // $http.post('/auth/reset/' + $stateParams.token, $scope.passwordDetails).success(function(response) { + // // If successful show success message and clear form + // $scope.passwordDetails = null; - // Attach user profile - // Principal.user() = response; + // // Attach user profile + // // Principal.user() = response; - // And redirect to the index page - $state.go('reset-success'); - }).error(function(response) { - $scope.error = response.message; - }); + // // And redirect to the index page + // $state.go('reset-success'); + // }).error(function(response) { + // $scope.error = response.message; + // }); }; } ]); \ No newline at end of file diff --git a/public/modules/users/services/principal.client.service.js b/public/modules/users/services/principal.client.service.js index 8dcee53d..19de8fd3 100755 --- a/public/modules/users/services/principal.client.service.js +++ b/public/modules/users/services/principal.client.service.js @@ -1,13 +1,13 @@ 'use strict'; -angular.module('users').factory('Principal', ['$window', '$http', '$q', '$timeout', - function($window, $http, $q, $timeout) { +angular.module('users').factory('Principal', ['$window', '$q', '$timeout', + function($window, $q, $timeout) { var service = { _currentUser: null, isIdentityResolved: function() { - if(service._currentUser === null) return false + if(service._currentUser === null) return false; return true; }, isAuthenticated: function() { @@ -74,39 +74,75 @@ angular.module('users').factory('Principal', ['$window', '$http', '$q', '$timeou return deferred.promise; }, + + resetPassword: function(scope) { + var deferred = $q.defer(); + $http.get('/auth/password'+_currentUser._id, scope.passwordDetails).success(function(response) { + // If successful show success message and clear form + scope.passwordDetails = null; + + // Attach user profile + // Principal.user() = response; + + // And redirect to the index page + $state.go('reset-success'); + deferred.resolve(); + }).error(function(error) { + deferred.reject(error.message || error); + }); + + return deferred.promise; + }, + + // Submit forgotten password account id + askForPasswordReset: function(credentials) { + + $http.post('/auth/forgot', credentials).success(function(response) { + // Show user success message and clear form + + deferred.resolve(response); + + }).error(function(error) { + // Show user error message + deferred.reject(error.message || error); + }); + + return deferred.promise; + }, identity: function() { - if (service.isAuthenticated()) { - return service._currentUser; - } else if($window.user){ - service.authenticate($window.user); - return service._currentUser; - }else { - return $http.get('/user/me') - .success(function(response) { - service.authenticate(response.data.user); - return response.data.user; - }) - .error(function() { - service.authenticate(null); - // $state.go('signin'); - return null; - }); - } - - // var deferred = $q.defer(); - - // console.log($window.user); - // console.log(service.isAuthenticated()); - - // // check and see if we have retrieved the user data from the server. if we have, reuse it by immediately resolving - // if (service.isAuthenticated() === true ) { - // deferred.resolve(service.currentUser); - // }else if($window.user){ - + // if (service.isAuthenticated()) { + // return service._currentUser; + // } else if($window.user){ // service.authenticate($window.user); - // deferred.resolve(service._currentUser); + // return service._currentUser; // }else { + // return $http.get('/user/me') + // .success(function(response) { + // service.authenticate(response.data.user); + // return response.data.user; + // }) + // .error(function() { + // service.authenticate(null); + // // $state.go('signin'); + // return null; + // }); + // } + + var deferred = $q.defer(); + + console.log($window.user); + console.log(service.isAuthenticated()); + + // check and see if we have retrieved the user data from the server. if we have, reuse it by immediately resolving + if (service.isAuthenticated() === true ) { + deferred.resolve(service.currentUser); + }else if($window.user){ + + service.authenticate($window.user); + deferred.resolve(service._currentUser); + } + // else { // // otherwise, retrieve the user data from the server, update the user object, and then resolve. // $http.get('/users/me') @@ -120,7 +156,7 @@ angular.module('users').factory('Principal', ['$window', '$http', '$q', '$timeou // }); // } - // return deferred.promise; + return deferred.promise; } };