fixed Principle -> dependency loop
This commit is contained in:
parent
f3f7d852fc
commit
4d2357b460
|
@ -10,10 +10,10 @@ var mongoose = require('mongoose'),
|
|||
function validateFormFieldType(value) {
|
||||
if (!value || typeof myVar !== 'string' ) { return false; }
|
||||
|
||||
var validHTMLTypes = [
|
||||
var validTypes = [
|
||||
'textfield',
|
||||
'textarea',
|
||||
'statement'
|
||||
'statement',
|
||||
'email',
|
||||
'legal',
|
||||
'url',
|
||||
|
@ -24,7 +24,7 @@ function validateFormFieldType(value) {
|
|||
'date',
|
||||
'dropdown',
|
||||
'hidden',
|
||||
'password',
|
||||
'password'
|
||||
];
|
||||
|
||||
if (validTypes.indexOf(value) > -1) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
|||
}
|
||||
}
|
||||
});
|
||||
// });
|
||||
});
|
||||
|
||||
}
|
||||
]);
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
});
|
||||
]);
|
|
@ -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;
|
||||
// });
|
||||
};
|
||||
|
|
|
@ -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
|
||||
Principal.askForPasswordReset($scope.credentials).then(
|
||||
function(response){
|
||||
$scope.success = response.message
|
||||
$scope.credentials = null;
|
||||
$scope.success = response.message;
|
||||
|
||||
}).error(function(response) {
|
||||
// Show user error message and clear form
|
||||
},
|
||||
function(error){
|
||||
$scope.error = error;
|
||||
$scope.credentials = null;
|
||||
$scope.error = response.message;
|
||||
});
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
// 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;
|
||||
// });
|
||||
};
|
||||
}
|
||||
]);
|
|
@ -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);
|
||||
// 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;
|
||||
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue