2015-06-29 22:51:29 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
// Setting up route
|
|
|
|
angular.module('core').config(['$stateProvider', '$urlRouterProvider',
|
|
|
|
function($stateProvider, $urlRouterProvider, Authorization) {
|
|
|
|
// Redirect to home view when route not found
|
2016-04-22 21:28:25 +00:00
|
|
|
$urlRouterProvider.otherwise('/forms');
|
2015-06-29 22:51:29 +00:00
|
|
|
}
|
2016-04-22 21:25:50 +00:00
|
|
|
]);
|
2016-06-09 03:32:33 +00:00
|
|
|
|
|
|
|
angular.module(ApplicationConfiguration.applicationModuleName).run(['$rootScope', 'Auth', '$state', '$stateParams',
|
|
|
|
function($rootScope, Auth, $state, $stateParams) {
|
|
|
|
|
|
|
|
$rootScope.$state = $state;
|
|
|
|
$rootScope.$stateParams = $stateParams;
|
|
|
|
|
|
|
|
// add previous state property
|
|
|
|
$rootScope.$on('$stateChangeSuccess', function (event, toState, toParams, fromState) {
|
|
|
|
$state.previous = fromState;
|
|
|
|
//console.log('toState: '+toState.name);
|
|
|
|
|
|
|
|
var statesToIgnore = ['home', 'signin', 'resendVerifyEmail', 'verify', 'signup', 'signup-success', 'forgot', 'reset-invalid', 'reset', 'reset-success'];
|
|
|
|
|
|
|
|
//Redirect to listForms if user is authenticated
|
|
|
|
if(statesToIgnore.indexOf(toState.name) > 0){
|
|
|
|
if(Auth.isAuthenticated()){
|
|
|
|
event.preventDefault(); // stop current execution
|
|
|
|
//console.log('go to forms');
|
|
|
|
$state.go('listForms'); // go to listForms page
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//Redirect to 'signup' route if user is not authenticated
|
|
|
|
else if(toState.name !== 'access_denied' && !Auth.isAuthenticated() && toState.name !== 'submitForm'){
|
|
|
|
console.log('go to signup');
|
|
|
|
event.preventDefault(); // stop current execution
|
|
|
|
$state.go('listForms'); // go to listForms page
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
//Page access/authorization logic
|
|
|
|
angular.module(ApplicationConfiguration.applicationModuleName).run(['$rootScope', 'Auth', 'User', 'Authorizer', '$state', '$stateParams',
|
|
|
|
function($rootScope, Auth, User, Authorizer, $state, $stateParams) {
|
|
|
|
$rootScope.$on('$stateChangeStart', function(event, next) {
|
|
|
|
var authenticator, permissions, user;
|
|
|
|
permissions = next && next.data && next.data.permissions ? next.data.permissions : null;
|
|
|
|
|
|
|
|
Auth.ensureHasCurrentUser(User);
|
|
|
|
user = Auth.currentUser;
|
|
|
|
|
|
|
|
if(user){
|
|
|
|
authenticator = new Authorizer(user);
|
|
|
|
//console.log('access denied: '+!authenticator.canAccess(permissions));
|
|
|
|
//console.log(permissions);
|
|
|
|
if( (permissions != null) ){
|
|
|
|
if( !authenticator.canAccess(permissions) ){
|
|
|
|
event.preventDefault();
|
|
|
|
//console.log('access denied');
|
|
|
|
$state.go('access_denied');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}]);
|