From 6be12f8a061a2f7228e254c314a46ad7a78966d1 Mon Sep 17 00:00:00 2001 From: Michael Leanos Date: Fri, 7 Oct 2016 22:03:31 -0700 Subject: [PATCH 01/11] fix(core): Add custom 400 and 404 error messages (#1547) * Added 400 and 404 custom error messages * nicer error message views * Sign Up & Sign In error responses Changed the error responses returned from the Sign Up & Sign In API calls to use 422 rather than 400. For insight into why this change was made: https://github.com/meanjs/mean/pull/1510#issuecomment-247435378 For reference on why to use 422 over 400: https://www.bennadel.com/blog/2434-http-status-codes-for-invalid-data-400-vs-422.htm --- .../core/client/config/core.client.routes.js | 18 ++++++++++++++++-- .../controllers/error.client.controller.js | 18 ++++++++++++++++++ .../auth-interceptor.client.service.js | 6 ++++++ modules/core/client/views/400.client.view.html | 7 +++++-- modules/core/client/views/403.client.view.html | 4 +++- modules/core/client/views/404.client.view.html | 7 +++++-- .../users.authentication.server.controller.js | 4 ++-- 7 files changed, 55 insertions(+), 9 deletions(-) create mode 100644 modules/core/client/controllers/error.client.controller.js diff --git a/modules/core/client/config/core.client.routes.js b/modules/core/client/config/core.client.routes.js index 6fc0d79fc0..9a89d6c326 100644 --- a/modules/core/client/config/core.client.routes.js +++ b/modules/core/client/config/core.client.routes.js @@ -36,17 +36,31 @@ .state('not-found', { url: '/not-found', templateUrl: 'modules/core/client/views/404.client.view.html', + controller: 'ErrorController', + controllerAs: 'vm', + params: { + message: function($stateParams) { + return $stateParams.message; + } + }, data: { ignoreState: true, - pageTitle: 'Not-Found' + pageTitle: 'Not Found' } }) .state('bad-request', { url: '/bad-request', templateUrl: 'modules/core/client/views/400.client.view.html', + controller: 'ErrorController', + controllerAs: 'vm', + params: { + message: function($stateParams) { + return $stateParams.message; + } + }, data: { ignoreState: true, - pageTitle: 'Bad-Request' + pageTitle: 'Bad Request' } }) .state('forbidden', { diff --git a/modules/core/client/controllers/error.client.controller.js b/modules/core/client/controllers/error.client.controller.js new file mode 100644 index 0000000000..5968f34315 --- /dev/null +++ b/modules/core/client/controllers/error.client.controller.js @@ -0,0 +1,18 @@ +(function () { + 'use strict'; + + angular + .module('core') + .controller('ErrorController', ErrorController); + + ErrorController.$inject = ['$stateParams']; + + function ErrorController($stateParams) { + var vm = this; + vm.errorMessage = null; + + // Display custom message if it was set + if ($stateParams.message) vm.errorMessage = $stateParams.message; + } +}()); + diff --git a/modules/core/client/services/interceptors/auth-interceptor.client.service.js b/modules/core/client/services/interceptors/auth-interceptor.client.service.js index 2929402804..97486209dd 100644 --- a/modules/core/client/services/interceptors/auth-interceptor.client.service.js +++ b/modules/core/client/services/interceptors/auth-interceptor.client.service.js @@ -17,6 +17,9 @@ function responseError(rejection) { if (!rejection.config.ignoreAuthModule) { switch (rejection.status) { + case 400: + $injector.get('$state').go('bad-request', { message: rejection.data.message }); + break; case 401: // Deauthenticate the global user Authentication.user = null; @@ -25,6 +28,9 @@ case 403: $injector.get('$state').transitionTo('forbidden'); break; + case 404: + $injector.get('$state').go('not-found', { message: rejection.data.message }); + break; } } // otherwise, default behaviour diff --git a/modules/core/client/views/400.client.view.html b/modules/core/client/views/400.client.view.html index efc28045ef..f1192d4915 100644 --- a/modules/core/client/views/400.client.view.html +++ b/modules/core/client/views/400.client.view.html @@ -1,6 +1,9 @@ -

Bad Request

+ diff --git a/modules/core/client/views/403.client.view.html b/modules/core/client/views/403.client.view.html index 151968d5e1..320980c931 100644 --- a/modules/core/client/views/403.client.view.html +++ b/modules/core/client/views/403.client.view.html @@ -1,4 +1,6 @@ -

Forbidden

+ diff --git a/modules/articles/tests/client/admin.articles.client.controller.tests.js b/modules/articles/tests/client/admin.articles.client.controller.tests.js index 2b99aa483e..52b206e43e 100644 --- a/modules/articles/tests/client/admin.articles.client.controller.tests.js +++ b/modules/articles/tests/client/admin.articles.client.controller.tests.js @@ -9,7 +9,8 @@ $state, Authentication, ArticlesService, - mockArticle; + mockArticle, + Notification; // The $resource service augments the response object with methods for updating and deleting the resource. // If we were to use the standard toEqual matcher, our tests would fail because the test values would not match @@ -36,7 +37,7 @@ // The injector ignores leading and trailing underscores here (i.e. _$httpBackend_). // This allows us to inject a service but then attach it to a variable // with the same name as the service. - beforeEach(inject(function ($controller, $rootScope, _$state_, _$httpBackend_, _Authentication_, _ArticlesService_) { + beforeEach(inject(function ($controller, $rootScope, _$state_, _$httpBackend_, _Authentication_, _ArticlesService_, _Notification_) { // Set a new global scope $scope = $rootScope.$new(); @@ -45,6 +46,7 @@ $state = _$state_; Authentication = _Authentication_; ArticlesService = _ArticlesService_; + Notification = _Notification_; // create mock article mockArticle = new ArticlesService({ @@ -66,6 +68,8 @@ // Spy on state go spyOn($state, 'go'); + spyOn(Notification, 'error'); + spyOn(Notification, 'success'); })); describe('vm.save() as create', function () { @@ -89,11 +93,13 @@ $scope.vm.save(true); $httpBackend.flush(); + // Test Notification success was called + expect(Notification.success).toHaveBeenCalledWith({ message: ' Article saved successfully!' }); // Test URL redirection after the article was created expect($state.go).toHaveBeenCalledWith('admin.articles.list'); })); - it('should set $scope.vm.error if error', function () { + it('should call Notification.error if error', function () { var errorMessage = 'this is an error message'; $httpBackend.expectPOST('api/articles', sampleArticlePostData).respond(400, { message: errorMessage @@ -102,7 +108,7 @@ $scope.vm.save(true); $httpBackend.flush(); - expect($scope.vm.error).toBe(errorMessage); + expect(Notification.error).toHaveBeenCalledWith({ message: errorMessage, title: ' Article save error!' }); }); }); @@ -120,11 +126,13 @@ $scope.vm.save(true); $httpBackend.flush(); + // Test Notification success was called + expect(Notification.success).toHaveBeenCalledWith({ message: ' Article saved successfully!' }); // Test URL location to new object expect($state.go).toHaveBeenCalledWith('admin.articles.list'); })); - it('should set $scope.vm.error if error', inject(function (ArticlesService) { + it('should call Notification.error if error', inject(function (ArticlesService) { var errorMessage = 'error'; $httpBackend.expectPUT(/api\/articles\/([0-9a-fA-F]{24})$/).respond(400, { message: errorMessage @@ -133,7 +141,7 @@ $scope.vm.save(true); $httpBackend.flush(); - expect($scope.vm.error).toBe(errorMessage); + expect(Notification.error).toHaveBeenCalledWith({ message: errorMessage, title: ' Article save error!' }); })); }); @@ -152,6 +160,7 @@ $scope.vm.remove(); $httpBackend.flush(); + expect(Notification.success).toHaveBeenCalledWith({ message: ' Article deleted successfully!' }); expect($state.go).toHaveBeenCalledWith('admin.articles.list'); }); diff --git a/modules/core/client/app/config.js b/modules/core/client/app/config.js index 754a6cbcd6..a8a093a5e0 100644 --- a/modules/core/client/app/config.js +++ b/modules/core/client/app/config.js @@ -6,7 +6,7 @@ var service = { applicationEnvironment: window.env, applicationModuleName: applicationModuleName, - applicationModuleVendorDependencies: ['ngResource', 'ngAnimate', 'ngMessages', 'ui.router', 'ui.bootstrap', 'ngFileUpload', 'ngImgCrop'], + applicationModuleVendorDependencies: ['ngResource', 'ngAnimate', 'ngMessages', 'ui.router', 'ui.bootstrap', 'ngFileUpload', 'ngImgCrop', 'ui-notification'], registerModule: registerModule }; @@ -20,4 +20,17 @@ // Add the module to the AngularJS configuration file angular.module(applicationModuleName).requires.push(moduleName); } + + // Angular-ui-notification configuration + angular.module('ui-notification').config(function(NotificationProvider) { + NotificationProvider.setOptions({ + delay: 2000, + startTop: 20, + startRight: 10, + verticalSpacing: 20, + horizontalSpacing: 20, + positionX: 'right', + positionY: 'bottom' + }); + }); }(window)); diff --git a/modules/users/client/controllers/admin/user.client.controller.js b/modules/users/client/controllers/admin/user.client.controller.js index 8c4a1bb04b..53ac51e726 100644 --- a/modules/users/client/controllers/admin/user.client.controller.js +++ b/modules/users/client/controllers/admin/user.client.controller.js @@ -5,9 +5,9 @@ .module('users.admin') .controller('UserController', UserController); - UserController.$inject = ['$scope', '$state', '$window', 'Authentication', 'userResolve']; + UserController.$inject = ['$scope', '$state', '$window', 'Authentication', 'userResolve', 'Notification']; - function UserController($scope, $state, $window, Authentication, user) { + function UserController($scope, $state, $window, Authentication, user, Notification) { var vm = this; vm.authentication = Authentication; @@ -22,9 +22,11 @@ user.$remove(); vm.users.splice(vm.users.indexOf(user), 1); + Notification.success('User deleted successfully!'); } else { vm.user.$remove(function () { $state.go('admin.users'); + Notification.success({ message: ' User deleted successfully!' }); }); } } @@ -43,8 +45,9 @@ $state.go('admin.user', { userId: user._id }); + Notification.success({ message: ' User saved successfully!' }); }, function (errorResponse) { - vm.error = errorResponse.data.message; + Notification.error({ message: errorResponse.data.message, title: ' User update error!' }); }); } diff --git a/modules/users/client/controllers/authentication.client.controller.js b/modules/users/client/controllers/authentication.client.controller.js index 96cca04f46..34ddeffd3f 100644 --- a/modules/users/client/controllers/authentication.client.controller.js +++ b/modules/users/client/controllers/authentication.client.controller.js @@ -5,9 +5,9 @@ .module('users') .controller('AuthenticationController', AuthenticationController); - AuthenticationController.$inject = ['$scope', '$state', 'UsersService', '$location', '$window', 'Authentication', 'PasswordValidator']; + AuthenticationController.$inject = ['$scope', '$state', 'UsersService', '$location', '$window', 'Authentication', 'PasswordValidator', 'Notification']; - function AuthenticationController($scope, $state, UsersService, $location, $window, Authentication, PasswordValidator) { + function AuthenticationController($scope, $state, UsersService, $location, $window, Authentication, PasswordValidator, Notification) { var vm = this; vm.authentication = Authentication; @@ -17,7 +17,9 @@ vm.callOauthProvider = callOauthProvider; // Get an eventual error defined in the URL query string: - vm.error = $location.search().err; + if ($location.search().err) { + Notification.error({ message: $location.search().err }); + } // If user is signed in then redirect back home if (vm.authentication.user) { @@ -25,7 +27,6 @@ } function signup(isValid) { - vm.error = null; if (!isValid) { $scope.$broadcast('show-errors-check-validity', 'vm.userForm'); @@ -39,7 +40,6 @@ } function signin(isValid) { - vm.error = null; if (!isValid) { $scope.$broadcast('show-errors-check-validity', 'vm.userForm'); @@ -67,25 +67,25 @@ function onUserSignupSuccess(response) { // If successful we assign the response to the global user model vm.authentication.user = response; - + Notification.success({ message: ' Signup successful!' }); // And redirect to the previous or home page $state.go($state.previous.state.name || 'home', $state.previous.params); } function onUserSignupError(response) { - vm.error = response.data.message; + Notification.error({ message: response.data.message, title: ' Signup Error!', delay: 6000 }); } function onUserSigninSuccess(response) { // If successful we assign the response to the global user model vm.authentication.user = response; - + Notification.info({ message: 'Welcome ' + response.firstName }); // And redirect to the previous or home page $state.go($state.previous.state.name || 'home', $state.previous.params); } function onUserSigninError(response) { - vm.error = response.data.message; + Notification.error({ message: response.data.message, title: ' Signin Error!', delay: 6000 }); } } }()); diff --git a/modules/users/client/controllers/password.client.controller.js b/modules/users/client/controllers/password.client.controller.js index fe015c7844..856d87f7ff 100644 --- a/modules/users/client/controllers/password.client.controller.js +++ b/modules/users/client/controllers/password.client.controller.js @@ -5,9 +5,9 @@ .module('users') .controller('PasswordController', PasswordController); - PasswordController.$inject = ['$scope', '$stateParams', 'UsersService', '$location', 'Authentication', 'PasswordValidator']; + PasswordController.$inject = ['$scope', '$stateParams', 'UsersService', '$location', 'Authentication', 'PasswordValidator', 'Notification']; - function PasswordController($scope, $stateParams, UsersService, $location, Authentication, PasswordValidator) { + function PasswordController($scope, $stateParams, UsersService, $location, Authentication, PasswordValidator, Notification) { var vm = this; vm.resetUserPassword = resetUserPassword; @@ -22,7 +22,6 @@ // Submit forgotten password account id function askForPasswordReset(isValid) { - vm.success = vm.error = null; if (!isValid) { $scope.$broadcast('show-errors-check-validity', 'vm.forgotPasswordForm'); @@ -37,7 +36,6 @@ // Change user password function resetUserPassword(isValid) { - vm.success = vm.error = null; if (!isValid) { $scope.$broadcast('show-errors-check-validity', 'vm.resetPasswordForm'); @@ -55,13 +53,13 @@ function onRequestPasswordResetSuccess(response) { // Show user success message and clear form vm.credentials = null; - vm.success = response.message; + Notification.success({ message: response.message, title: ' Password reset email sent successfully!' }); } function onRequestPasswordResetError(response) { // Show user error message and clear form vm.credentials = null; - vm.error = response.data.message; + Notification.error({ message: response.data.message, title: ' Failed to send password reset email!', delay: 4000 }); } function onResetPasswordSuccess(response) { @@ -70,12 +68,13 @@ // Attach user profile Authentication.user = response; + Notification.success({ message: ' Password reset successful!' }); // And redirect to the index page $location.path('/password/reset/success'); } function onResetPasswordError(response) { - vm.error = response.data.message; + Notification.error({ message: response.data.message, title: ' Password reset failed!', delay: 4000 }); } } }()); diff --git a/modules/users/client/controllers/settings/change-password.client.controller.js b/modules/users/client/controllers/settings/change-password.client.controller.js index a95b032b60..8602dfe8ef 100644 --- a/modules/users/client/controllers/settings/change-password.client.controller.js +++ b/modules/users/client/controllers/settings/change-password.client.controller.js @@ -5,9 +5,9 @@ .module('users') .controller('ChangePasswordController', ChangePasswordController); - ChangePasswordController.$inject = ['$scope', '$http', 'Authentication', 'UsersService', 'PasswordValidator']; + ChangePasswordController.$inject = ['$scope', '$http', 'Authentication', 'UsersService', 'PasswordValidator', 'Notification']; - function ChangePasswordController($scope, $http, Authentication, UsersService, PasswordValidator) { + function ChangePasswordController($scope, $http, Authentication, UsersService, PasswordValidator, Notification) { var vm = this; vm.user = Authentication.user; @@ -16,7 +16,6 @@ // Change user password function changeUserPassword(isValid) { - vm.success = vm.error = null; if (!isValid) { $scope.$broadcast('show-errors-check-validity', 'vm.passwordForm'); @@ -31,13 +30,12 @@ function onChangePasswordSuccess(response) { // If successful show success message and clear form - $scope.$broadcast('show-errors-reset', 'vm.passwordForm'); - vm.success = true; + Notification.success({ message: ' Password Changed Successfully' }); vm.passwordDetails = null; } function onChangePasswordError(response) { - vm.error = response.data.message; + Notification.error({ message: response.data.message, title: ' Password change failed!' }); } } }()); diff --git a/modules/users/client/controllers/settings/change-profile-picture.client.controller.js b/modules/users/client/controllers/settings/change-profile-picture.client.controller.js index 411b62a14e..ca378c78f5 100644 --- a/modules/users/client/controllers/settings/change-profile-picture.client.controller.js +++ b/modules/users/client/controllers/settings/change-profile-picture.client.controller.js @@ -5,16 +5,15 @@ .module('users') .controller('ChangeProfilePictureController', ChangeProfilePictureController); - ChangeProfilePictureController.$inject = ['$timeout', 'Authentication', 'Upload']; + ChangeProfilePictureController.$inject = ['$timeout', 'Authentication', 'Upload', 'Notification']; - function ChangeProfilePictureController($timeout, Authentication, Upload) { + function ChangeProfilePictureController($timeout, Authentication, Upload, Notification) { var vm = this; vm.user = Authentication.user; vm.fileSelected = false; vm.upload = function (dataUrl, name) { - vm.success = vm.error = null; Upload.upload({ url: 'api/users/picture', @@ -35,7 +34,7 @@ // Called after the user has successfully uploaded a new picture function onSuccessItem(response) { // Show success message - vm.success = true; + Notification.success({ message: ' Change profile picture successful!' }); // Populate user object vm.user = Authentication.user = response; @@ -50,7 +49,7 @@ vm.fileSelected = false; // Show error message - vm.error = response.message; + Notification.error({ message: response.message, title: ' Change profile picture failed!' }); } } }()); diff --git a/modules/users/client/controllers/settings/edit-profile.client.controller.js b/modules/users/client/controllers/settings/edit-profile.client.controller.js index 1a1d3ee43a..f6c5a2b405 100644 --- a/modules/users/client/controllers/settings/edit-profile.client.controller.js +++ b/modules/users/client/controllers/settings/edit-profile.client.controller.js @@ -5,9 +5,9 @@ .module('users') .controller('EditProfileController', EditProfileController); - EditProfileController.$inject = ['$scope', '$http', '$location', 'UsersService', 'Authentication']; + EditProfileController.$inject = ['$scope', '$http', '$location', 'UsersService', 'Authentication', 'Notification']; - function EditProfileController($scope, $http, $location, UsersService, Authentication) { + function EditProfileController($scope, $http, $location, UsersService, Authentication, Notification) { var vm = this; vm.user = Authentication.user; @@ -15,7 +15,6 @@ // Update a user profile function updateUserProfile(isValid) { - vm.success = vm.error = null; if (!isValid) { $scope.$broadcast('show-errors-check-validity', 'vm.userForm'); @@ -28,10 +27,10 @@ user.$update(function (response) { $scope.$broadcast('show-errors-reset', 'vm.userForm'); - vm.success = true; + Notification.success({ message: ' Edit profile successful!' }); Authentication.user = response; }, function (response) { - vm.error = response.data.message; + Notification.error({ message: response.data.message, title: ' Edit profile failed!' }); }); } } diff --git a/modules/users/client/controllers/settings/manage-social-accounts.client.controller.js b/modules/users/client/controllers/settings/manage-social-accounts.client.controller.js index 6ba564f97e..1551fce1c0 100644 --- a/modules/users/client/controllers/settings/manage-social-accounts.client.controller.js +++ b/modules/users/client/controllers/settings/manage-social-accounts.client.controller.js @@ -5,9 +5,9 @@ .module('users') .controller('SocialAccountsController', SocialAccountsController); - SocialAccountsController.$inject = ['$scope', 'UsersService', 'Authentication']; + SocialAccountsController.$inject = ['$scope', 'UsersService', 'Authentication', 'Notification']; - function SocialAccountsController($scope, UsersService, Authentication) { + function SocialAccountsController($scope, UsersService, Authentication, Notification) { var vm = this; vm.user = Authentication.user; @@ -27,7 +27,6 @@ // Remove a user social account function removeUserSocialAccount(provider) { - vm.success = vm.error = null; UsersService.removeSocialAccount(provider) .then(onRemoveSocialAccountSuccess) @@ -36,12 +35,12 @@ function onRemoveSocialAccountSuccess(response) { // If successful show success message and clear form - vm.success = true; + Notification.success({ message: ' Removed successfully!' }); vm.user = Authentication.user = response; } function onRemoveSocialAccountError(response) { - vm.error = response.message; + Notification.error({ message: response.message, title: ' Remove failed!' }); } } }()); diff --git a/modules/users/client/views/admin/edit-user.client.view.html b/modules/users/client/views/admin/edit-user.client.view.html index 559af2812c..3687a28095 100644 --- a/modules/users/client/views/admin/edit-user.client.view.html +++ b/modules/users/client/views/admin/edit-user.client.view.html @@ -31,9 +31,6 @@

User

-
- -
diff --git a/modules/users/client/views/authentication/signup.client.view.html b/modules/users/client/views/authentication/signup.client.view.html index edd6214e23..2c593322d9 100644 --- a/modules/users/client/views/authentication/signup.client.view.html +++ b/modules/users/client/views/authentication/signup.client.view.html @@ -51,9 +51,6 @@

Or sign up using your email

  or  Sign in -
- -
diff --git a/modules/users/client/views/password/forgot-password.client.view.html b/modules/users/client/views/password/forgot-password.client.view.html index 07fca823a4..b549ee70a6 100644 --- a/modules/users/client/views/password/forgot-password.client.view.html +++ b/modules/users/client/views/password/forgot-password.client.view.html @@ -13,12 +13,6 @@

Restore your password

-
- -
-
- -
diff --git a/modules/users/client/views/password/reset-password.client.view.html b/modules/users/client/views/password/reset-password.client.view.html index ca0763704d..be7f4e7cc8 100644 --- a/modules/users/client/views/password/reset-password.client.view.html +++ b/modules/users/client/views/password/reset-password.client.view.html @@ -28,12 +28,6 @@

Reset your password

-
- -
-
- -
diff --git a/modules/users/client/views/settings/change-password.client.view.html b/modules/users/client/views/settings/change-password.client.view.html index 8ab0045d50..f01dfd5aed 100644 --- a/modules/users/client/views/settings/change-password.client.view.html +++ b/modules/users/client/views/settings/change-password.client.view.html @@ -34,12 +34,6 @@
-
- Password Changed Successfully -
-
- -
diff --git a/modules/users/client/views/settings/change-profile-picture.client.view.html b/modules/users/client/views/settings/change-profile-picture.client.view.html index 721c34bb46..0e4fccc8a9 100644 --- a/modules/users/client/views/settings/change-profile-picture.client.view.html +++ b/modules/users/client/views/settings/change-profile-picture.client.view.html @@ -12,7 +12,7 @@ {{vm.user.displayName}}
- +
@@ -23,12 +23,6 @@ {{vm.progress}}% Complete
-
- Profile Picture Changed Successfully -
-
- -
diff --git a/modules/users/client/views/settings/edit-profile.client.view.html b/modules/users/client/views/settings/edit-profile.client.view.html index 62ab91984c..76b25bf8d5 100644 --- a/modules/users/client/views/settings/edit-profile.client.view.html +++ b/modules/users/client/views/settings/edit-profile.client.view.html @@ -34,12 +34,6 @@
-
- Profile Saved Successfully -
-
- -
diff --git a/modules/users/tests/client/authentication.client.controller.tests.js b/modules/users/tests/client/authentication.client.controller.tests.js index 0eafab51b1..dbbbd5b091 100644 --- a/modules/users/tests/client/authentication.client.controller.tests.js +++ b/modules/users/tests/client/authentication.client.controller.tests.js @@ -9,7 +9,8 @@ $httpBackend, $stateParams, $state, - $location; + $location, + Notification; beforeEach(function () { jasmine.addMatchers({ @@ -32,7 +33,7 @@ // The injector ignores leading and trailing underscores here (i.e. _$httpBackend_). // This allows us to inject a service but then attach it to a variable // with the same name as the service. - beforeEach(inject(function ($controller, $rootScope, _$location_, _$stateParams_, _$httpBackend_) { + beforeEach(inject(function ($controller, $rootScope, _$location_, _$stateParams_, _$httpBackend_, _Notification_) { // Set a new global scope scope = $rootScope.$new(); @@ -40,6 +41,11 @@ $stateParams = _$stateParams_; $httpBackend = _$httpBackend_; $location = _$location_; + Notification = _Notification_; + + // Spy on Notification + spyOn(Notification, 'error'); + spyOn(Notification, 'success'); // Initialize the Authentication controller AuthenticationController = $controller('AuthenticationController as vm', { @@ -107,8 +113,8 @@ scope.vm.signin(true); $httpBackend.flush(); - // Test scope value - expect(scope.vm.error).toEqual('Missing credentials'); + // Test Notification.error is called + expect(Notification.error).toHaveBeenCalledWith({ message: 'Missing credentials', title: ' Signin Error!', delay: 6000 }); }); it('should fail to log in with wrong credentials', function () { @@ -124,8 +130,8 @@ scope.vm.signin(true); $httpBackend.flush(); - // Test scope value - expect(scope.vm.error).toEqual('Unknown user'); + // Test Notification.error is called + expect(Notification.error).toHaveBeenCalledWith({ message: 'Unknown user', title: ' Signin Error!', delay: 6000 }); }); }); @@ -140,7 +146,7 @@ // test scope value expect(scope.vm.authentication.user.username).toBe('Fred'); - expect(scope.vm.error).toEqual(null); + expect(Notification.success).toHaveBeenCalledWith({ message: ' Signup successful!' }); expect($location.url()).toBe('/'); }); @@ -153,8 +159,8 @@ scope.vm.signup(true); $httpBackend.flush(); - // Test scope value - expect(scope.vm.error).toBe('Username already exists'); + // Test Notification.error is called + expect(Notification.error).toHaveBeenCalledWith({ message: 'Username already exists', title: ' Signup Error!', delay: 6000 }); }); }); }); diff --git a/modules/users/tests/client/edit-profile.client.controller.tests.js b/modules/users/tests/client/edit-profile.client.controller.tests.js index a8c6874acf..fcb73bafcc 100644 --- a/modules/users/tests/client/edit-profile.client.controller.tests.js +++ b/modules/users/tests/client/edit-profile.client.controller.tests.js @@ -8,7 +8,8 @@ $httpBackend, $location, Authentication, - UsersService; + UsersService, + Notification; // The $resource service augments the response object with methods for updating and deleting the resource. // If we were to use the standard toEqual matcher, our tests would fail because the test values would not match @@ -35,7 +36,7 @@ // The injector ignores leading and trailing underscores here (i.e. _$httpBackend_). // This allows us to inject a service but then attach it to a variable // with the same name as the service. - beforeEach(inject(function ($controller, $rootScope, _$location_, _$httpBackend_, _Authentication_, _UsersService_) { + beforeEach(inject(function ($controller, $rootScope, _$location_, _$httpBackend_, _Authentication_, _UsersService_, _Notification_) { // Set a new global scope $scope = $rootScope.$new(); @@ -44,6 +45,11 @@ $location = _$location_; Authentication = _Authentication_; UsersService = _UsersService_; + Notification = _Notification_; + + // Spy on Notification + spyOn(Notification, 'error'); + spyOn(Notification, 'success'); // Mock logged in user Authentication.user = { @@ -72,10 +78,10 @@ $scope.vm.updateUserProfile(true); $httpBackend.flush(); - expect($scope.vm.success).toBe(true); + expect(Notification.success).toHaveBeenCalledWith({ message: ' Edit profile successful!' }); })); - it('should set vm.error if error', inject(function (UsersService) { + it('should call Notification.error if error', inject(function (UsersService) { var errorMessage = 'error'; $httpBackend.expectPUT(/api\/users/).respond(400, { message: errorMessage @@ -84,7 +90,7 @@ $scope.vm.updateUserProfile(true); $httpBackend.flush(); - expect($scope.vm.error).toBe(errorMessage); + expect(Notification.error).toHaveBeenCalledWith({ message: errorMessage, title: ' Edit profile failed!' }); })); }); diff --git a/modules/users/tests/client/password.client.controller.tests.js b/modules/users/tests/client/password.client.controller.tests.js index cb486bc167..fc8637cd78 100644 --- a/modules/users/tests/client/password.client.controller.tests.js +++ b/modules/users/tests/client/password.client.controller.tests.js @@ -9,7 +9,8 @@ $httpBackend, $stateParams, $location, - $window; + $window, + Notification; beforeEach(function() { jasmine.addMatchers({ @@ -57,7 +58,7 @@ }); describe('Logged out user', function() { - beforeEach(inject(function($controller, $rootScope, _$window_, _$stateParams_, _$httpBackend_, _$location_) { + beforeEach(inject(function($controller, $rootScope, _$window_, _$stateParams_, _$httpBackend_, _$location_, _Notification_) { // Set a new global scope scope = $rootScope.$new(); @@ -68,6 +69,10 @@ $location.path = jasmine.createSpy().and.returnValue(true); $window = _$window_; $window.user = null; + Notification = _Notification_; + + spyOn(Notification, 'error'); + spyOn(Notification, 'success'); // Initialize the Authentication controller PasswordController = $controller('PasswordController as vm', { @@ -88,15 +93,6 @@ scope.vm.credentials = credentials; }); - it('should clear scope.success and scope.error', function() { - scope.vm.success = 'test'; - scope.vm.error = 'test'; - scope.vm.askForPasswordReset(true); - - expect(scope.vm.success).toBeNull(); - expect(scope.vm.error).toBeNull(); - }); - describe('POST error', function() { var errorMessage = 'No account with that username has been found'; beforeEach(function() { @@ -112,8 +108,8 @@ expect(scope.vm.credentials).toBe(null); }); - it('should set error to response message', function() { - expect(scope.vm.error).toBe(errorMessage); + it('should call Notification.error with response message', function() { + expect(Notification.error).toHaveBeenCalledWith({ message: errorMessage, title: ' Failed to send password reset email!', delay: 4000 }); }); }); @@ -132,8 +128,8 @@ expect(scope.vm.credentials).toBe(null); }); - it('should set success to response message', function() { - expect(scope.vm.success).toBe(successMessage); + it('should call Notification.success with response message', function() { + expect(Notification.success).toHaveBeenCalledWith({ message: successMessage, title: ' Password reset email sent successfully!' }); }); }); }); @@ -148,16 +144,7 @@ scope.vm.passwordDetails = passwordDetails; }); - it('should clear scope.success and scope.vm.error', function() { - scope.vm.success = 'test'; - scope.vm.error = 'test'; - scope.vm.resetUserPassword(true); - - expect(scope.vm.success).toBeNull(); - expect(scope.vm.error).toBeNull(); - }); - - it('POST error should set scope.error to response message', function() { + it('POST error should call Notification.error with response message', function() { var errorMessage = 'Passwords do not match'; $httpBackend.when('POST', 'api/auth/reset/' + token, passwordDetails).respond(400, { 'message': errorMessage @@ -166,7 +153,7 @@ scope.vm.resetUserPassword(true); $httpBackend.flush(); - expect(scope.vm.error).toBe(errorMessage); + expect(Notification.error).toHaveBeenCalledWith({ message: errorMessage, title: ' Password reset failed!', delay: 4000 }); }); describe('POST success', function() { @@ -188,7 +175,8 @@ expect(scope.vm.authentication.user.username).toEqual(user.username); }); - it('should redirect to password reset success view', function() { + it('should redirect to password reset success view with Notification.success', function() { + expect(Notification.success).toHaveBeenCalledWith({ message: ' Password reset successful!' }); expect($location.path).toHaveBeenCalledWith('/password/reset/success'); }); }); diff --git a/modules/users/tests/e2e/users.e2e.tests.js b/modules/users/tests/e2e/users.e2e.tests.js index 5e95d584c2..a6584bb8f3 100644 --- a/modules/users/tests/e2e/users.e2e.tests.js +++ b/modules/users/tests/e2e/users.e2e.tests.js @@ -272,7 +272,7 @@ describe('Users E2E Tests:', function () { // Click Submit button element(by.css('button[type=submit]')).click(); // Password Error - expect(element.all(by.css('strong')).get(0).getText()).toBe('Email already exists'); + expect(element.all(by.css('.message')).get(0).getText()).toBe('Email already exists'); }); it('Should report Username already exists', function () { @@ -291,7 +291,7 @@ describe('Users E2E Tests:', function () { // Click Submit button element(by.css('button[type=submit]')).click(); // Password Error - expect(element.all(by.css('strong')).get(0).getText()).toBe('Username already exists'); + expect(element.all(by.css('.message')).get(0).getText()).toBe('Username already exists'); }); }); @@ -436,7 +436,7 @@ describe('Users E2E Tests:', function () { // Click Submit button element(by.css('button[type=submit]')).click(); // Password Changed - expect(element.all(by.css('.text-success')).get(0).getText()).toBe('Password Changed Successfully'); + expect(element.all(by.css('.ui-notification')).get(0).getText()).toBe('Password Changed Successfully'); }); }); }); From 0ea8cec120864515bf7d9cd6a2dd9234efc79fc0 Mon Sep 17 00:00:00 2001 From: Michael Leanos Date: Mon, 10 Oct 2016 16:00:24 -0700 Subject: [PATCH 05/11] fix(express): Incorrest uses of 400 error codes (#1553) Fixes incorrest usage of 400 HTTP responses being returned from the server, in favor of using 422. Also, changed a few return codes to 401 where it was more appropriate. See this article for reasoning behind moving to 422, and why 400 isn't appropriate for these cases. For ref: https://github.com/meanjs/mean/commit/6be12f8a061a2f7228e254c314a46ad7a78966d1 Related: https://github.com/meanjs/mean/pull/1547 https://github.com/meanjs/mean/pull/1510 --- .../controllers/articles.server.controller.js | 8 +++---- .../admin.article.server.routes.tests.js | 2 +- .../controllers/admin.server.controller.js | 6 ++--- .../users.authentication.server.controller.js | 2 +- .../users/users.password.server.controller.js | 16 +++++++------- .../users/users.profile.server.controller.js | 10 ++++----- .../tests/server/user.server.routes.tests.js | 22 +++++++++---------- 7 files changed, 33 insertions(+), 33 deletions(-) diff --git a/modules/articles/server/controllers/articles.server.controller.js b/modules/articles/server/controllers/articles.server.controller.js index 18d6a3b959..ddba5fe192 100644 --- a/modules/articles/server/controllers/articles.server.controller.js +++ b/modules/articles/server/controllers/articles.server.controller.js @@ -17,7 +17,7 @@ exports.create = function (req, res) { article.save(function (err) { if (err) { - return res.status(400).send({ + return res.status(422).send({ message: errorHandler.getErrorMessage(err) }); } else { @@ -51,7 +51,7 @@ exports.update = function (req, res) { article.save(function (err) { if (err) { - return res.status(400).send({ + return res.status(422).send({ message: errorHandler.getErrorMessage(err) }); } else { @@ -68,7 +68,7 @@ exports.delete = function (req, res) { article.remove(function (err) { if (err) { - return res.status(400).send({ + return res.status(422).send({ message: errorHandler.getErrorMessage(err) }); } else { @@ -83,7 +83,7 @@ exports.delete = function (req, res) { exports.list = function (req, res) { Article.find().sort('-created').populate('user', 'displayName').exec(function (err, articles) { if (err) { - return res.status(400).send({ + return res.status(422).send({ message: errorHandler.getErrorMessage(err) }); } else { diff --git a/modules/articles/tests/server/admin.article.server.routes.tests.js b/modules/articles/tests/server/admin.article.server.routes.tests.js index e56119da9e..0322dd14bc 100644 --- a/modules/articles/tests/server/admin.article.server.routes.tests.js +++ b/modules/articles/tests/server/admin.article.server.routes.tests.js @@ -170,7 +170,7 @@ describe('Article Admin CRUD tests', function () { // Save a new article agent.post('/api/articles') .send(article) - .expect(400) + .expect(422) .end(function (articleSaveErr, articleSaveRes) { // Set message assertion (articleSaveRes.body.message).should.match('Title cannot be blank'); diff --git a/modules/users/server/controllers/admin.server.controller.js b/modules/users/server/controllers/admin.server.controller.js index 3747a06e68..20fc9c72cb 100644 --- a/modules/users/server/controllers/admin.server.controller.js +++ b/modules/users/server/controllers/admin.server.controller.js @@ -29,7 +29,7 @@ exports.update = function (req, res) { user.save(function (err) { if (err) { - return res.status(400).send({ + return res.status(422).send({ message: errorHandler.getErrorMessage(err) }); } @@ -46,7 +46,7 @@ exports.delete = function (req, res) { user.remove(function (err) { if (err) { - return res.status(400).send({ + return res.status(422).send({ message: errorHandler.getErrorMessage(err) }); } @@ -61,7 +61,7 @@ exports.delete = function (req, res) { exports.list = function (req, res) { User.find({}, '-salt -password -providerData').sort('-created').populate('user', 'displayName').exec(function (err, users) { if (err) { - return res.status(400).send({ + return res.status(422).send({ message: errorHandler.getErrorMessage(err) }); } diff --git a/modules/users/server/controllers/users/users.authentication.server.controller.js b/modules/users/server/controllers/users/users.authentication.server.controller.js index 2089385400..7d96002b08 100644 --- a/modules/users/server/controllers/users/users.authentication.server.controller.js +++ b/modules/users/server/controllers/users/users.authentication.server.controller.js @@ -231,7 +231,7 @@ exports.removeOAuthProvider = function (req, res, next) { user.save(function (err) { if (err) { - return res.status(400).send({ + return res.status(422).send({ message: errorHandler.getErrorMessage(err) }); } else { diff --git a/modules/users/server/controllers/users/users.password.server.controller.js b/modules/users/server/controllers/users/users.password.server.controller.js index 77a04dbd27..7f3153ba1f 100644 --- a/modules/users/server/controllers/users/users.password.server.controller.js +++ b/modules/users/server/controllers/users/users.password.server.controller.js @@ -50,7 +50,7 @@ exports.forgot = function (req, res, next) { } }); } else { - return res.status(400).send({ + return res.status(422).send({ message: 'Username field must not be blank' }); } @@ -141,7 +141,7 @@ exports.reset = function (req, res, next) { user.save(function (err) { if (err) { - return res.status(400).send({ + return res.status(422).send({ message: errorHandler.getErrorMessage(err) }); } else { @@ -161,7 +161,7 @@ exports.reset = function (req, res, next) { } }); } else { - return res.status(400).send({ + return res.status(422).send({ message: 'Passwords do not match' }); } @@ -217,7 +217,7 @@ exports.changePassword = function (req, res, next) { user.save(function (err) { if (err) { - return res.status(400).send({ + return res.status(422).send({ message: errorHandler.getErrorMessage(err) }); } else { @@ -233,12 +233,12 @@ exports.changePassword = function (req, res, next) { } }); } else { - res.status(400).send({ + res.status(422).send({ message: 'Passwords do not match' }); } } else { - res.status(400).send({ + res.status(422).send({ message: 'Current password is incorrect' }); } @@ -249,12 +249,12 @@ exports.changePassword = function (req, res, next) { } }); } else { - res.status(400).send({ + res.status(422).send({ message: 'Please provide a new password' }); } } else { - res.status(400).send({ + res.status(401).send({ message: 'User is not signed in' }); } diff --git a/modules/users/server/controllers/users/users.profile.server.controller.js b/modules/users/server/controllers/users/users.profile.server.controller.js index 99f8e7bc99..68e992d780 100644 --- a/modules/users/server/controllers/users/users.profile.server.controller.js +++ b/modules/users/server/controllers/users/users.profile.server.controller.js @@ -31,7 +31,7 @@ exports.update = function (req, res) { user.save(function (err) { if (err) { - return res.status(400).send({ + return res.status(422).send({ message: errorHandler.getErrorMessage(err) }); } else { @@ -45,7 +45,7 @@ exports.update = function (req, res) { } }); } else { - res.status(400).send({ + res.status(401).send({ message: 'User is not signed in' }); } @@ -73,10 +73,10 @@ exports.changeProfilePicture = function (req, res) { res.json(user); }) .catch(function (err) { - res.status(400).send(err); + res.status(422).send(err); }); } else { - res.status(400).send({ + res.status(401).send({ message: 'User is not signed in' }); } @@ -129,7 +129,7 @@ exports.changeProfilePicture = function (req, res) { return new Promise(function (resolve, reject) { req.login(user, function (err) { if (err) { - reject(err); + res.status(400).send(err); } else { resolve(); } diff --git a/modules/users/tests/server/user.server.routes.tests.js b/modules/users/tests/server/user.server.routes.tests.js index 8e6f075e58..9288a53488 100644 --- a/modules/users/tests/server/user.server.routes.tests.js +++ b/modules/users/tests/server/user.server.routes.tests.js @@ -328,7 +328,7 @@ describe('User CRUD tests', function () { .send({ username: '' }) - .expect(400) + .expect(422) .end(function (err, res) { // Handle error if (err) { @@ -507,7 +507,7 @@ describe('User CRUD tests', function () { verifyPassword: '1234567890-ABC-123-Aa$', currentPassword: credentials.password }) - .expect(400) + .expect(422) .end(function (err, res) { if (err) { return done(err); @@ -536,7 +536,7 @@ describe('User CRUD tests', function () { verifyPassword: '1234567890Aa$', currentPassword: 'some_wrong_passwordAa$' }) - .expect(400) + .expect(422) .end(function (err, res) { if (err) { return done(err); @@ -565,7 +565,7 @@ describe('User CRUD tests', function () { verifyPassword: '', currentPassword: credentials.password }) - .expect(400) + .expect(422) .end(function (err, res) { if (err) { return done(err); @@ -577,7 +577,7 @@ describe('User CRUD tests', function () { }); }); - it('should not be able to change user own password if no new password is at all given', function (done) { + it('should not be able to change user own password if not signed in', function (done) { // Change password agent.post('/api/users/password') @@ -586,7 +586,7 @@ describe('User CRUD tests', function () { verifyPassword: '1234567890Aa$', currentPassword: credentials.password }) - .expect(400) + .expect(401) .end(function (err, res) { if (err) { return done(err); @@ -759,7 +759,7 @@ describe('User CRUD tests', function () { agent.put('/api/users') .send(userUpdate) - .expect(400) + .expect(422) .end(function (userInfoErr, userInfoRes) { if (userInfoErr) { return done(userInfoErr); @@ -811,7 +811,7 @@ describe('User CRUD tests', function () { agent.put('/api/users') .send(userUpdate) - .expect(400) + .expect(422) .end(function (userInfoErr, userInfoRes) { if (userInfoErr) { return done(userInfoErr); @@ -888,7 +888,7 @@ describe('User CRUD tests', function () { agent.put('/api/users') .send(userUpdate) - .expect(400) + .expect(401) .end(function (userInfoErr, userInfoRes) { if (userInfoErr) { return done(userInfoErr); @@ -906,7 +906,7 @@ describe('User CRUD tests', function () { agent.post('/api/users/picture') .send({}) - .expect(400) + .expect(401) .end(function (userInfoErr, userInfoRes) { if (userInfoErr) { return done(userInfoErr); @@ -960,7 +960,7 @@ describe('User CRUD tests', function () { agent.post('/api/users/picture') .attach('fieldThatDoesntWork', './modules/users/client/img/profile/default.png') .send(credentials) - .expect(400) + .expect(422) .end(function (userInfoErr, userInfoRes) { done(userInfoErr); }); From aebaf2ff740aa6d09007cde66cb76e9afa429506 Mon Sep 17 00:00:00 2001 From: Cameron Behar <0x24a537r9@gmail.com> Date: Sun, 21 Feb 2016 02:13:16 -0800 Subject: [PATCH 06/11] fix(core): Remove the tag. --- .../client/config/articles.client.routes.js | 4 ++-- .../services/articles.client.service.js | 2 +- .../client/articles.client.routes.tests.js | 6 ++--- .../list-articles.client.controller.tests.js | 2 +- .../chat/client/config/chat.client.routes.js | 2 +- .../chat/client/views/chat.client.view.html | 2 +- modules/core/client/app/init.js | 5 +++- .../core/client/config/core.client.routes.js | 8 +++---- .../core/client/views/header.client.view.html | 2 +- .../core/client/views/home.client.view.html | 2 +- .../core/server/views/layout.server.view.html | 7 +++--- .../config/users-admin.client.routes.js | 6 ++--- .../client/config/users.client.routes.js | 24 +++++++++---------- ...hange-profile-picture.client.controller.js | 2 +- .../client/services/users.client.service.js | 4 ++-- 15 files changed, 40 insertions(+), 38 deletions(-) diff --git a/modules/articles/client/config/articles.client.routes.js b/modules/articles/client/config/articles.client.routes.js index a16926e520..4a94fa2e88 100644 --- a/modules/articles/client/config/articles.client.routes.js +++ b/modules/articles/client/config/articles.client.routes.js @@ -16,7 +16,7 @@ }) .state('articles.list', { url: '', - templateUrl: 'modules/articles/client/views/list-articles.client.view.html', + templateUrl: '/modules/articles/client/views/list-articles.client.view.html', controller: 'ArticlesListController', controllerAs: 'vm', data: { @@ -25,7 +25,7 @@ }) .state('articles.view', { url: '/:articleId', - templateUrl: 'modules/articles/client/views/view-article.client.view.html', + templateUrl: '/modules/articles/client/views/view-article.client.view.html', controller: 'ArticlesController', controllerAs: 'vm', resolve: { diff --git a/modules/articles/client/services/articles.client.service.js b/modules/articles/client/services/articles.client.service.js index 19b8015d5c..5e653ca4be 100644 --- a/modules/articles/client/services/articles.client.service.js +++ b/modules/articles/client/services/articles.client.service.js @@ -8,7 +8,7 @@ ArticlesService.$inject = ['$resource', '$log']; function ArticlesService($resource, $log) { - var Article = $resource('api/articles/:articleId', { + var Article = $resource('/api/articles/:articleId', { articleId: '@_id' }, { update: { diff --git a/modules/articles/tests/client/articles.client.routes.tests.js b/modules/articles/tests/client/articles.client.routes.tests.js index 650223d80c..4fa7cae1e2 100644 --- a/modules/articles/tests/client/articles.client.routes.tests.js +++ b/modules/articles/tests/client/articles.client.routes.tests.js @@ -64,7 +64,7 @@ beforeEach(inject(function ($controller, $state, $templateCache) { viewstate = $state.get('articles.view'); - $templateCache.put('modules/articles/client/views/view-article.client.view.html', ''); + $templateCache.put('/modules/articles/client/views/view-article.client.view.html', ''); // create mock article mockArticle = new ArticlesService({ @@ -104,7 +104,7 @@ }); it('Should have templateUrl', function () { - expect(viewstate.templateUrl).toBe('modules/articles/client/views/view-article.client.view.html'); + expect(viewstate.templateUrl).toBe('/modules/articles/client/views/view-article.client.view.html'); }); }); @@ -119,7 +119,7 @@ $rootScope.$digest(); expect($location.path()).toBe('/articles'); - expect($state.current.templateUrl).toBe('modules/articles/client/views/list-articles.client.view.html'); + expect($state.current.templateUrl).toBe('/modules/articles/client/views/list-articles.client.view.html'); })); }); }); diff --git a/modules/articles/tests/client/list-articles.client.controller.tests.js b/modules/articles/tests/client/list-articles.client.controller.tests.js index ee654f4707..248862298d 100644 --- a/modules/articles/tests/client/list-articles.client.controller.tests.js +++ b/modules/articles/tests/client/list-articles.client.controller.tests.js @@ -76,7 +76,7 @@ it('should send a GET request and return all articles', inject(function (ArticlesService) { // Set POST response - $httpBackend.expectGET('api/articles').respond(mockArticleList); + $httpBackend.expectGET('/api/articles').respond(mockArticleList); $httpBackend.flush(); diff --git a/modules/chat/client/config/chat.client.routes.js b/modules/chat/client/config/chat.client.routes.js index 4ec07d8bc9..f69aff6108 100644 --- a/modules/chat/client/config/chat.client.routes.js +++ b/modules/chat/client/config/chat.client.routes.js @@ -11,7 +11,7 @@ $stateProvider .state('chat', { url: '/chat', - templateUrl: 'modules/chat/client/views/chat.client.view.html', + templateUrl: '/modules/chat/client/views/chat.client.view.html', controller: 'ChatController', controllerAs: 'vm', data: { diff --git a/modules/chat/client/views/chat.client.view.html b/modules/chat/client/views/chat.client.view.html index 3b9174c6ed..ad45efa5cd 100644 --- a/modules/chat/client/views/chat.client.view.html +++ b/modules/chat/client/views/chat.client.view.html @@ -18,7 +18,7 @@

Chat Example

  • - {{message.username}} + {{message.username}}

    diff --git a/modules/core/client/app/init.js b/modules/core/client/app/init.js index 4b99c46d12..8ffaef33bc 100644 --- a/modules/core/client/app/init.js +++ b/modules/core/client/app/init.js @@ -13,7 +13,10 @@ bootstrapConfig.$inject = ['$compileProvider', '$locationProvider', '$httpProvider', '$logProvider']; function bootstrapConfig($compileProvider, $locationProvider, $httpProvider, $logProvider) { - $locationProvider.html5Mode(true).hashPrefix('!'); + $locationProvider.html5Mode({ + enabled: true, + requireBase: false + }).hashPrefix('!'); $httpProvider.interceptors.push('authInterceptor'); diff --git a/modules/core/client/config/core.client.routes.js b/modules/core/client/config/core.client.routes.js index 9a89d6c326..c00f8807e0 100644 --- a/modules/core/client/config/core.client.routes.js +++ b/modules/core/client/config/core.client.routes.js @@ -29,13 +29,13 @@ $stateProvider .state('home', { url: '/', - templateUrl: 'modules/core/client/views/home.client.view.html', + templateUrl: '/modules/core/client/views/home.client.view.html', controller: 'HomeController', controllerAs: 'vm' }) .state('not-found', { url: '/not-found', - templateUrl: 'modules/core/client/views/404.client.view.html', + templateUrl: '/modules/core/client/views/404.client.view.html', controller: 'ErrorController', controllerAs: 'vm', params: { @@ -50,7 +50,7 @@ }) .state('bad-request', { url: '/bad-request', - templateUrl: 'modules/core/client/views/400.client.view.html', + templateUrl: '/modules/core/client/views/400.client.view.html', controller: 'ErrorController', controllerAs: 'vm', params: { @@ -65,7 +65,7 @@ }) .state('forbidden', { url: '/forbidden', - templateUrl: 'modules/core/client/views/403.client.view.html', + templateUrl: '/modules/core/client/views/403.client.view.html', data: { ignoreState: true, pageTitle: 'Forbidden' diff --git a/modules/core/client/views/header.client.view.html b/modules/core/client/views/header.client.view.html index c09e9770a8..d35f961dc5 100644 --- a/modules/core/client/views/header.client.view.html +++ b/modules/core/client/views/header.client.view.html @@ -32,7 +32,7 @@