diff --git a/app/views/index.server.view.pug b/app/views/index.server.view.pug index 38052644..ba5f5d34 100644 --- a/app/views/index.server.view.pug +++ b/app/views/index.server.view.pug @@ -44,7 +44,7 @@ block content script(type='text/javascript', src='https://cdnjs.cloudflare.com/ajax/libs/angular-strap/2.3.8/angular-strap.min.js') - //script(src='http://textangular.com/dist/textAngular.min.js') + script(src='https://cdnjs.cloudflare.com/ajax/libs/ng-quill/3.5.1/ng-quill.min.js') //Application JavaScript Files each jsFile in jsFiles diff --git a/bower.json b/bower.json index 5d191560..c12eb2e5 100755 --- a/bower.json +++ b/bower.json @@ -16,13 +16,11 @@ "angular-mocks": "~1.4.7", "angular-bootstrap": "~0.14.3", "angular-ui-utils": "~3.0.0", - "angular-ui-router": "~0.2.11", "ng-file-upload": "^12.0.4", "angular-raven": "~0.5.11", "angular-ui-date": "~0.0.11", "lodash": "~3.10.0", "angular-ui-sortable": "~0.13.4", - "angular-permission": "~1.1.1", "file-saver.js": "~1.20150507.2", "angular-bootstrap-colorpicker": "~3.0.19", "angular-scroll": "^1.0.0", @@ -45,18 +43,20 @@ "angular-ui-select": "^0.19.8", "angular-bootstrap-switch": "^0.5.2", "jquery": "^3.2.1", - "ng-quill": "https://github.com/KillerCodeMonkey/ng-quill" + "ng-quill": "https://github.com/KillerCodeMonkey/ng-quill", + "angular-ui-router": "^1.0.11", + "angular-permission": "^5.3.2" }, "resolutions": { "angular-bootstrap": "^0.14.0", - "angular": "1.4.14", - "jspdf": "~1.0.178", "angular-sanitize": "1.4.14", "angular-ui-sortable": "^0.17.1", "angular-ui-date": "~0.0.11", "angular-input-stars-directive": "master", "angular-ui-select": "^0.19.8", - "jquery": "^3.2.1" + "jquery": "^3.2.1", + "angular-ui-router": "^1.0.11", + "angular-permission": "^5.3.2" }, "overrides": { "BOWER-PACKAGE": { diff --git a/public/form_modules/forms/base/directives/submit-form.client.directive.js b/public/form_modules/forms/base/directives/submit-form.client.directive.js index 4e9b2b1d..b026d5c7 100644 --- a/public/form_modules/forms/base/directives/submit-form.client.directive.js +++ b/public/form_modules/forms/base/directives/submit-form.client.directive.js @@ -320,12 +320,11 @@ angular.module('view-form').directive('submitFormDirective', ['$http', 'TimeCoun setTimeout(function () { $scope.submitPromise = $http.post('/forms/' + $scope.myform._id, form) - .success(function (data, status) { + .then(function (data, status) { $scope.myform.submitted = true; $scope.loading = false; SendVisitorData.send(form, getActiveField(), _timeElapsed); - }) - .error(function (error) { + }, function (error) { $scope.loading = false; console.error(error); $scope.error = error.message; diff --git a/public/modules/core/config/core.client.routes.js b/public/modules/core/config/core.client.routes.js index 4133bf0d..79c9dbc5 100755 --- a/public/modules/core/config/core.client.routes.js +++ b/public/modules/core/config/core.client.routes.js @@ -8,6 +8,9 @@ angular.module('core').config(['$stateProvider', '$urlRouterProvider', } ]); +var statesWithoutAuth = ['signin', 'resendVerifyEmail', 'verify', 'signup', 'signup-success', 'forgot', 'reset-invalid', 'reset', 'reset-success']; +var statesToIgnore = statesWithoutAuth.concat(['', 'home']); + angular.module(ApplicationConfiguration.applicationModuleName).run(['$rootScope', 'Auth', '$state', '$stateParams', function($rootScope, Auth, $state, $stateParams) { @@ -21,10 +24,8 @@ angular.module(ApplicationConfiguration.applicationModuleName).run(['$rootScope' params: fromParams } - 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(statesToIgnore.indexOf(toState.name) > -1){ if(Auth.isAuthenticated()){ event.preventDefault(); // stop current execution $state.go('listForms'); // go to listForms page @@ -43,23 +44,28 @@ angular.module(ApplicationConfiguration.applicationModuleName).run(['$rootScope' //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) { - console.log('$stateChangeStart'); - var authenticator, permissions, user; - permissions = next && next.data && next.data.permissions ? next.data.permissions : null; + $rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams) { + if(statesWithoutAuth.indexOf(toState.name) === -1){ + Auth.ensureHasCurrentUser(User).then( + function onSuccess(currentUser){ + if(currentUser){ + var authenticator = new Authorizer(user); + var permissions = toState && toState.data && toState.data.permissions ? toState.data.permissions : null; - Auth.ensureHasCurrentUser(User); - user = Auth.currentUser; - - if(user){ - authenticator = new Authorizer(user); - - if( (permissions !== null) ){ - if( !authenticator.canAccess(permissions) ){ + if( permissions !== null && !authenticator.canAccess(permissions) ){ + event.preventDefault(); + $state.go('access_denied'); + } + } + }, + function onError(error){ event.preventDefault(); $state.go('access_denied'); } - } + ); + } else { + event.preventDefault(); + $state.go('access_denied'); } }); - }]); + }]); \ No newline at end of file diff --git a/public/modules/core/controllers/header.client.controller.js b/public/modules/core/controllers/header.client.controller.js index 0281bd74..4e49a3d2 100755 --- a/public/modules/core/controllers/header.client.controller.js +++ b/public/modules/core/controllers/header.client.controller.js @@ -6,11 +6,8 @@ angular.module('core').controller('HeaderController', ['$rootScope', '$scope', ' $rootScope.signupDisabled = $window.signupDisabled; $scope.user = $rootScope.user = Auth.ensureHasCurrentUser(User); - $scope.authentication = $rootScope.authentication = Auth; - $rootScope.languages = $scope.languages = ['en', 'fr', 'es', 'it', 'de']; - //Set global app language $rootScope.language = $scope.user.language; $translate.use($scope.user.language); diff --git a/public/modules/forms/admin/controllers/list-forms.client.controller.js b/public/modules/forms/admin/controllers/list-forms.client.controller.js index 476a9a2a..b1ad8ac8 100644 --- a/public/modules/forms/admin/controllers/list-forms.client.controller.js +++ b/public/modules/forms/admin/controllers/list-forms.client.controller.js @@ -74,9 +74,9 @@ angular.module('forms').controller('ListFormsController', ['$rootScope', '$scope delete form._id; $http.post('/forms', {form: form}) - .success(function(data, status, headers){ + .then(function(data, status, headers){ $scope.myforms.splice(form_index+1, 0, data); - }).error(function(errorResponse){ + }, function(errorResponse){ console.error(errorResponse); if(errorResponse === null){ $scope.error = errorResponse.data.message; @@ -93,10 +93,10 @@ angular.module('forms').controller('ListFormsController', ['$rootScope', '$scope if($scope.forms.createForm.$valid && $scope.forms.createForm.$dirty){ $http.post('/forms', {form: form}) - .success(function(data, status, headers){ + .then(function(data, status, headers){ // Redirect after save $scope.goToWithId('viewForm.create', data._id+''); - }).error(function(errorResponse){ + }, function(errorResponse){ console.error(errorResponse); $scope.error = errorResponse.data.message; }); @@ -109,10 +109,10 @@ angular.module('forms').controller('ListFormsController', ['$rootScope', '$scope } $http.delete('/forms/'+$scope.myforms[form_index]._id) - .success(function(data, status, headers){ + .then(function(data, status, headers){ $scope.myforms.splice(form_index, 1); $scope.cancelDeleteModal(); - }).error(function(error){ + }, function(error){ console.error(error); }); }; diff --git a/public/modules/forms/admin/directives/edit-submissions-form.client.directive.js b/public/modules/forms/admin/directives/edit-submissions-form.client.directive.js index 314a2a77..63984893 100644 --- a/public/modules/forms/admin/directives/edit-submissions-form.client.directive.js +++ b/public/modules/forms/admin/directives/edit-submissions-form.client.directive.js @@ -172,14 +172,13 @@ angular.module('forms').directive('editSubmissionsFormDirective', ['$rootScope', method: 'DELETE', data: {deleted_submissions: delete_ids}, headers: {'Content-Type': 'application/json;charset=utf-8'} - }).success(function(data, status){ + }).then(function(data, status){ $scope.deletionInProgress = true; //Remove deleted ids from table $scope.table.rows = $scope.table.rows.filter(function(field){ return !field.selected; }); - }) - .error(function(err){ + }, function(err){ $scope.deletionInProgress = true; console.error(err); }); diff --git a/public/modules/forms/admin/services/form-fields.client.service.js b/public/modules/forms/admin/services/form-fields.client.service.js index 302603ae..5f86b2e5 100644 --- a/public/modules/forms/admin/services/form-fields.client.service.js +++ b/public/modules/forms/admin/services/form-fields.client.service.js @@ -4,7 +4,7 @@ angular.module('forms').service('FormFields', [ '$rootScope', '$translate', 'Auth', function($rootScope, $translate, Auth) { - var language = Auth.ensureHasCurrentUser().language; + var language = $rootScope.language; $translate.use(language); this.types = [ diff --git a/public/modules/forms/admin/views/adminTabs/configureTabs/respondent-notifications.html b/public/modules/forms/admin/views/adminTabs/configureTabs/respondent-notifications.html index 09b0915c..79eca037 100644 --- a/public/modules/forms/admin/views/adminTabs/configureTabs/respondent-notifications.html +++ b/public/modules/forms/admin/views/adminTabs/configureTabs/respondent-notifications.html @@ -74,11 +74,23 @@
+ + + +
+ + + + +
+
+
diff --git a/public/modules/forms/forms.client.module.js b/public/modules/forms/forms.client.module.js index d291bd6c..592fe2c9 100644 --- a/public/modules/forms/forms.client.module.js +++ b/public/modules/forms/forms.client.module.js @@ -4,5 +4,5 @@ ApplicationConfiguration.registerModule('forms', [ 'ngFileUpload', 'ui.date', 'ui.sortable', 'angular-input-stars', 'users', 'ngclipboard', 'textAngular', - 'frapontillo.bootstrap-switch' + 'frapontillo.bootstrap-switch', 'ngQuill' ]);//, 'colorpicker.module' @TODO reactivate this module diff --git a/public/modules/users/config/users.client.routes.js b/public/modules/users/config/users.client.routes.js index b51f4771..14ffe6b3 100755 --- a/public/modules/users/config/users.client.routes.js +++ b/public/modules/users/config/users.client.routes.js @@ -4,26 +4,26 @@ angular.module('users').config(['$stateProvider', function($stateProvider) { - var checkLoggedin = function($q, $timeout, $state, User, Auth) { - var deferred = $q.defer(); - - if (Auth.currentUser && Auth.currentUser.email) { - $timeout(deferred.resolve); - } - else { - Auth.currentUser = User.getCurrent( - function() { - Auth.login(); - $timeout(deferred.resolve()); - }, - function() { - Auth.logout(); - $timeout(deferred.reject()); - $state.go('signin', {reload: true}); - }); - } + var checkCurrentUser = function($q, $state, User, Auth) { + var deferred = $q.defer(); + + if (Auth.currentUser && Auth.currentUser.email) { + deferred.resolve(Auth.currentUser); + } else { + User.getCurrent().then( + function(user) { + console.log(user); + Auth.login(); + deferred.resolve(user); + }, + function() { + Auth.logout(); + deferred.reject(); + $state.go('signin', {reload: true}); + }); + } - return deferred.promise; + return deferred.promise; }; var checkSignupDisabled = function($window, $timeout, $q) { @@ -40,22 +40,24 @@ angular.module('users').config(['$stateProvider', $stateProvider. state('profile', { resolve: { - loggedin: checkLoggedin + currentUser: ['$q', '$state', 'User', 'Auth', checkCurrentUser] }, url: '/settings/profile', - templateUrl: 'modules/users/views/settings/edit-profile.client.view.html' + templateUrl: 'modules/users/views/settings/edit-profile.client.view.html', + controller: 'SettingsController' }). state('password', { resolve: { - loggedin: checkLoggedin - }, + currentUser: ['$q', '$state', 'User', 'Auth', checkCurrentUser] + }, url: '/settings/password', - templateUrl: 'modules/users/views/settings/change-password.client.view.html' + templateUrl: 'modules/users/views/settings/change-password.client.view.html', + controller: 'SettingsController' }). state('accounts', { resolve: { - loggedin: checkLoggedin - }, + currentUser: ['$q', '$state', 'User', 'Auth', checkCurrentUser] + }, url: '/settings/accounts', templateUrl: 'modules/users/views/settings/social-accounts.client.view.html' }). diff --git a/public/modules/users/controllers/settings.client.controller.js b/public/modules/users/controllers/settings.client.controller.js index fef50189..140d78bc 100755 --- a/public/modules/users/controllers/settings.client.controller.js +++ b/public/modules/users/controllers/settings.client.controller.js @@ -1,9 +1,9 @@ 'use strict'; -angular.module('users').controller('SettingsController', ['$scope', '$rootScope', '$http', '$state', 'Users', 'Auth', - function($scope, $rootScope, $http, $state, Users, Auth) { +angular.module('users').controller('SettingsController', ['$scope', '$rootScope', '$http', '$state', 'Users', 'Auth', 'currentUser', + function($scope, $rootScope, $http, $state, Users, Auth, currentUser) { - $scope.user = Auth.currentUser; + $scope.user = currentUser; // Check if there are additional accounts $scope.hasConnectedAdditionalSocialAccounts = function(provider) { @@ -30,12 +30,12 @@ angular.module('users').controller('SettingsController', ['$scope', '$rootScope' params: { provider: provider } - }).success(function(response) { + }).then(function(response) { // If successful show success message and clear form $scope.success = true; $scope.error = null; $scope.user = response; - }).error(function(response) { + }, function(response) { $scope.success = null; $scope.error = response.message; }); @@ -64,12 +64,12 @@ angular.module('users').controller('SettingsController', ['$scope', '$rootScope' $scope.changeUserPassword = function() { $scope.success = $scope.error = null; - $http.post('/users/password', $scope.passwordDetails).success(function(response) { + $http.post('/users/password', $scope.passwordDetails).then(function(response) { // If successful show success message and clear form $scope.success = true; $scope.error = null; $scope.passwordDetails = null; - }).error(function(response) { + }, function(response) { $scope.success = null; $scope.error = response.message; }); diff --git a/public/modules/users/services/auth.client.service.js b/public/modules/users/services/auth.client.service.js index 806db08f..1b0d6bf4 100644 --- a/public/modules/users/services/auth.client.service.js +++ b/public/modules/users/services/auth.client.service.js @@ -1,7 +1,7 @@ 'use strict'; -angular.module('users').factory('Auth', ['$window', - function($window) { +angular.module('users').factory('Auth', ['$window', '$q', + function($window, $q) { var userState = { isLoggedIn: false @@ -17,26 +17,30 @@ angular.module('users').factory('Auth', ['$window', // because that would create a circular dependency // Auth <- $http <- $resource <- LoopBackResource <- User <- Auth ensureHasCurrentUser: function(User) { + var deferred = $q.defer(); + if (service._currentUser && service._currentUser.username) { - return service._currentUser; + deferred.resolve(service._currentUser); } else if ($window.user){ service._currentUser = $window.user; - return service._currentUser; + deferred.resolve(service._currentUser) } else { User.getCurrent().then(function(user) { // success service._currentUser = user; userState.isLoggedIn = true; $window.user = service._currentUser; - return service._currentUser; + deferred.resolve(service._currentUser); }, function(response) { userState.isLoggedIn = false; service._currentUser = null; $window.user = null; - return null; + deferred.reject('User data could not be fetched from server'); }); } + + return deferred.promise; }, isAuthenticated: function() { diff --git a/public/modules/users/services/user.client.service.js b/public/modules/users/services/user.client.service.js index cf745fa7..2bec0664 100644 --- a/public/modules/users/services/user.client.service.js +++ b/public/modules/users/services/user.client.service.js @@ -6,19 +6,16 @@ angular.module('users').factory('User', ['$window', '$q', '$timeout', '$http', ' var userService = { getCurrent: function() { var deferred = $q.defer(); - $http.get('/users/me') - .success(function(response) { - deferred.resolve(response); - }) - .error(function() { + .then(function(response) { + deferred.resolve(response.data); + }, function() { deferred.reject('User\'s session has expired'); }); return deferred.promise; }, login: function(credentials) { - var deferred = $q.defer(); $http.post('/auth/signin', credentials).then(function(response) { deferred.resolve(response.data); @@ -29,7 +26,6 @@ angular.module('users').factory('User', ['$window', '$q', '$timeout', '$http', ' return deferred.promise; }, logout: function() { - var deferred = $q.defer(); $http.get('/auth/signout').then(function(response) { deferred.resolve(null); @@ -40,7 +36,6 @@ angular.module('users').factory('User', ['$window', '$q', '$timeout', '$http', ' return deferred.promise; }, signup: function(credentials) { - var deferred = $q.defer(); $http.post('/auth/signup', credentials).then(function(response) { // If successful we assign the response to the global user model @@ -53,7 +48,6 @@ angular.module('users').factory('User', ['$window', '$q', '$timeout', '$http', ' }, resendVerifyEmail: function(_email) { - var deferred = $q.defer(); $http.post('/auth/verify', {email: _email}).then(function(response) { deferred.resolve(response.data); @@ -65,7 +59,6 @@ angular.module('users').factory('User', ['$window', '$q', '$timeout', '$http', ' }, validateVerifyToken: function(token) { - //DAVID: TODO: The valid length of a token should somehow be linked to server config values //DAVID: TODO: SEMI-URGENT: Should we even be doing this? var validTokenRe = /^([A-Za-z0-9]{48})$/g; @@ -82,7 +75,6 @@ angular.module('users').factory('User', ['$window', '$q', '$timeout', '$http', ' }, resetPassword: function(passwordDetails, token) { - var deferred = $q.defer(); $http.post('/auth/reset/'+token, passwordDetails).then(function(response) { deferred.resolve(response); @@ -95,7 +87,6 @@ angular.module('users').factory('User', ['$window', '$q', '$timeout', '$http', ' // Submit forgotten password account id askForPasswordReset: function(credentials) { - var deferred = $q.defer(); $http.post('/auth/forgot', credentials).then(function(response) { // Show user success message and clear form diff --git a/public/modules/users/views/settings/change-password.client.view.html b/public/modules/users/views/settings/change-password.client.view.html index 3a8565fa..8d622f21 100755 --- a/public/modules/users/views/settings/change-password.client.view.html +++ b/public/modules/users/views/settings/change-password.client.view.html @@ -1,6 +1,6 @@
-
+

{{ 'CHANGE_PASSWORD' | translate }}