fixed Principle -> dependency loop
This commit is contained in:
parent
f3f7d852fc
commit
4d2357b460
|
@ -10,22 +10,22 @@ var mongoose = require('mongoose'),
|
||||||
function validateFormFieldType(value) {
|
function validateFormFieldType(value) {
|
||||||
if (!value || typeof myVar !== 'string' ) { return false; }
|
if (!value || typeof myVar !== 'string' ) { return false; }
|
||||||
|
|
||||||
var validHTMLTypes = [
|
var validTypes = [
|
||||||
'textfield',
|
'textfield',
|
||||||
'textarea',
|
'textarea',
|
||||||
'statement'
|
'statement',
|
||||||
'email',
|
'email',
|
||||||
'legal',
|
'legal',
|
||||||
'url',
|
'url',
|
||||||
'number',
|
'number',
|
||||||
'filefield',
|
'filefield',
|
||||||
'radio',
|
'radio',
|
||||||
'checkbox',
|
'checkbox',
|
||||||
'date',
|
'date',
|
||||||
'dropdown',
|
'dropdown',
|
||||||
'hidden',
|
'hidden',
|
||||||
'password',
|
'password'
|
||||||
];
|
];
|
||||||
|
|
||||||
if (validTypes.indexOf(value) > -1) {
|
if (validTypes.indexOf(value) > -1) {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
var ApplicationConfiguration = (function() {
|
var ApplicationConfiguration = (function() {
|
||||||
// Init module configuration options
|
// Init module configuration options
|
||||||
var applicationModuleName = 'medform';
|
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
|
// Add a new vertical module
|
||||||
var registerModule = function(moduleName, dependencies) {
|
var registerModule = function(moduleName, dependencies) {
|
||||||
|
|
|
@ -7,17 +7,23 @@ angular.module('core').controller('HeaderController', ['$scope', 'Principal', 'M
|
||||||
$scope.hideNav = false;
|
$scope.hideNav = false;
|
||||||
$scope.menu = Menus.getMenu('topbar');
|
$scope.menu = Menus.getMenu('topbar');
|
||||||
|
|
||||||
// Principal.identity().then(function(user){
|
Principal.identity().then(function(user){
|
||||||
// $scope.authentication.user = user;
|
$scope.authentication.user = user;
|
||||||
// }).then(function(){
|
}).then(function(){
|
||||||
$scope.authentication.user = Principal.identity();
|
|
||||||
$scope.signout = 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) ){
|
if( angular.isDefined(response_obj.error) ){
|
||||||
$scope.error = response_obj.error;
|
$scope.error = response_obj.error;
|
||||||
} else{
|
} else{
|
||||||
$state.go('home');
|
$state.go('home');
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.toggleCollapsibleMenu = function() {
|
$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) {
|
function($scope, Principal) {
|
||||||
// This provides Principal context.
|
// This provides Principal context.
|
||||||
$scope.authentication = Principal;
|
$scope.authentication = Principal;
|
||||||
$scope.authentication.user = Principal.identity();
|
|
||||||
|
|
||||||
console.log($scope.authentication.user);
|
console.log($scope.authentication.user);
|
||||||
// Principal.identity().then(function(user){
|
Principal.identity().then(function(user){
|
||||||
// console.log(user);
|
console.log(user);
|
||||||
// $scope.authentication.user = user;
|
$scope.authentication.user = user;
|
||||||
// }, function(){
|
}, function(){
|
||||||
// console.log('error');
|
console.log('error');
|
||||||
// });
|
});
|
||||||
// console.log("user.displayName: "+Principal.user()._id);
|
// console.log("user.displayName: "+Principal.user()._id);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
// Forms controller
|
// Forms controller
|
||||||
angular.module('forms').controller('SubmitFormController', ['$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, $http) {
|
function($scope, $stateParams, $state, Principal, Forms, CurrentForm) {
|
||||||
|
|
||||||
// Principal.identity().then(function(user){
|
// Principal.identity().then(function(user){
|
||||||
// $scope.authentication.user = user;
|
// $scope.authentication.user = user;
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
// Forms controller
|
// Forms controller
|
||||||
angular.module('forms').controller('ViewFormController', ['$scope', '$stateParams', '$state', 'Principal', 'Forms', 'CurrentForm','$http',
|
angular.module('forms').controller('ViewFormController', ['$scope', '$stateParams', '$state', 'Forms', 'CurrentForm','$http',
|
||||||
function($scope, $stateParams, $state, Principal, Forms, CurrentForm, $http) {
|
function($scope, $stateParams, $state, Forms, CurrentForm, $http) {
|
||||||
|
|
||||||
// Principal.identity().then(function(user){
|
// Principal.identity().then(function(user){
|
||||||
// $scope.authentication.user = user;
|
// $scope.authentication.user = user;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// 'use strict';
|
'use strict';
|
||||||
|
|
||||||
// Config HTTP Error Handling
|
// Config HTTP Error Handling
|
||||||
angular.module('users').config(['$httpProvider',
|
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';
|
'use strict';
|
||||||
|
|
||||||
angular.module('users').controller('AuthenticationController', ['$scope', '$http', '$location', 'Principal', '$state',
|
angular.module('users').controller('AuthenticationController', ['$scope', '$location', 'Principal', '$state',
|
||||||
function($scope, $http, $location, Principal, $state) {
|
function($scope, $location, Principal, $state) {
|
||||||
|
|
||||||
$scope.authentication = Principal;
|
$scope.authentication = Principal;
|
||||||
// $scope.authentication.user = Principal.getUser();
|
// $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) {
|
// $http.post('/auth/signup', $scope.credentials).success(function(response) {
|
||||||
// // If successful we assign the response to the global user model
|
// // If successful we assign the response to the global user model
|
||||||
// $scope.authentication.user = response;
|
// $scope.authentication.user = response;
|
||||||
|
// Principal.authenticate(response);
|
||||||
|
|
||||||
// // And redirect to the index page
|
// // And redirect to the index page
|
||||||
// $location.path('/');
|
// $location.path('/');
|
||||||
|
@ -50,10 +51,12 @@ angular.module('users').controller('AuthenticationController', ['$scope', '$http
|
||||||
// $http.post('/auth/signin', $scope.credentials).success(function(response) {
|
// $http.post('/auth/signin', $scope.credentials).success(function(response) {
|
||||||
// // If successful we assign the response to the global user model
|
// // If successful we assign the response to the global user model
|
||||||
// $scope.authentication.user = response;
|
// $scope.authentication.user = response;
|
||||||
|
// Principal.authenticate(response);
|
||||||
|
|
||||||
// // And redirect to the index page
|
// // And redirect to the index page
|
||||||
// $location.path('/');
|
// $location.path('/');
|
||||||
// }).error(function(response) {
|
// }).error(function(response) {
|
||||||
|
// Principal.authenticate(null);
|
||||||
// $scope.error = response.message;
|
// $scope.error = response.message;
|
||||||
// });
|
// });
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,36 +10,43 @@ angular.module('users').controller('PasswordController', ['$scope', '$stateParam
|
||||||
|
|
||||||
// Submit forgotten password account id
|
// Submit forgotten password account id
|
||||||
$scope.askForPasswordReset = function() {
|
$scope.askForPasswordReset = function() {
|
||||||
$scope.success = $scope.error = null;
|
Principal.askForPasswordReset($scope.credentials).then(
|
||||||
|
function(response){
|
||||||
$http.post('/auth/forgot', $scope.credentials).success(function(response) {
|
$scope.success = response.message
|
||||||
// Show user success message and clear form
|
$scope.credentials = null;
|
||||||
$scope.credentials = null;
|
},
|
||||||
$scope.success = response.message;
|
function(error){
|
||||||
|
$scope.error = error;
|
||||||
}).error(function(response) {
|
$scope.credentials = null;
|
||||||
// Show user error message and clear form
|
}
|
||||||
$scope.credentials = null;
|
);
|
||||||
$scope.error = response.message;
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Change user password
|
// Change user password
|
||||||
$scope.resetUserPassword = function() {
|
$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) {
|
// $http.post('/auth/reset/' + $stateParams.token, $scope.passwordDetails).success(function(response) {
|
||||||
// If successful show success message and clear form
|
// // If successful show success message and clear form
|
||||||
$scope.passwordDetails = null;
|
// $scope.passwordDetails = null;
|
||||||
|
|
||||||
// Attach user profile
|
// // Attach user profile
|
||||||
// Principal.user() = response;
|
// // Principal.user() = response;
|
||||||
|
|
||||||
// And redirect to the index page
|
// // And redirect to the index page
|
||||||
$state.go('reset-success');
|
// $state.go('reset-success');
|
||||||
}).error(function(response) {
|
// }).error(function(response) {
|
||||||
$scope.error = response.message;
|
// $scope.error = response.message;
|
||||||
});
|
// });
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
]);
|
]);
|
|
@ -1,13 +1,13 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('users').factory('Principal', ['$window', '$http', '$q', '$timeout',
|
angular.module('users').factory('Principal', ['$window', '$q', '$timeout',
|
||||||
function($window, $http, $q, $timeout) {
|
function($window, $q, $timeout) {
|
||||||
|
|
||||||
var service = {
|
var service = {
|
||||||
_currentUser: null,
|
_currentUser: null,
|
||||||
|
|
||||||
isIdentityResolved: function() {
|
isIdentityResolved: function() {
|
||||||
if(service._currentUser === null) return false
|
if(service._currentUser === null) return false;
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
isAuthenticated: function() {
|
isAuthenticated: function() {
|
||||||
|
@ -74,39 +74,75 @@ angular.module('users').factory('Principal', ['$window', '$http', '$q', '$timeou
|
||||||
|
|
||||||
return deferred.promise;
|
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() {
|
identity: function() {
|
||||||
|
|
||||||
if (service.isAuthenticated()) {
|
// if (service.isAuthenticated()) {
|
||||||
return service._currentUser;
|
// return service._currentUser;
|
||||||
} else if($window.user){
|
// } 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){
|
|
||||||
|
|
||||||
// service.authenticate($window.user);
|
// service.authenticate($window.user);
|
||||||
// deferred.resolve(service._currentUser);
|
// return service._currentUser;
|
||||||
// }else {
|
// }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.
|
// // otherwise, retrieve the user data from the server, update the user object, and then resolve.
|
||||||
// $http.get('/users/me')
|
// $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