diff --git a/bower.json b/bower.json index 9738f46d4c..ab28fd9f5d 100644 --- a/bower.json +++ b/bower.json @@ -13,7 +13,7 @@ "angular-ui-router": "~0.2.18", "bootstrap": "~3.3.6", "ng-file-upload": "^12.1.0", - "ng-img-crop": "ngImgCrop#^0.3.2", + "ng-img-crop-full-extended": "ngImgCropFullExtended#~6.0.1", "owasp-password-strength-test": "~1.3.0" }, "overrides": { diff --git a/config/assets/default.js b/config/assets/default.js index 7d4fdca421..3cdad08b89 100644 --- a/config/assets/default.js +++ b/config/assets/default.js @@ -9,7 +9,7 @@ module.exports = { // bower:css 'public/lib/bootstrap/dist/css/bootstrap.css', 'public/lib/bootstrap/dist/css/bootstrap-theme.css', - 'public/lib/ng-img-crop/compile/unminified/ng-img-crop.css' + 'public/lib/ng-img-crop-full-extended/compile/minified/ng-img-crop.css' // endbower ], js: [ @@ -18,7 +18,7 @@ module.exports = { 'public/lib/angular-animate/angular-animate.js', 'public/lib/angular-bootstrap/ui-bootstrap-tpls.js', 'public/lib/ng-file-upload/ng-file-upload.js', - 'public/lib/ng-img-crop/compile/unminified/ng-img-crop.js', + 'public/lib/ng-img-crop-full-extended/compile/minified/ng-img-crop.js', 'public/lib/angular-messages/angular-messages.js', 'public/lib/angular-mocks/angular-mocks.js', 'public/lib/angular-resource/angular-resource.js', diff --git a/config/env/test.js b/config/env/test.js index d8b0e80a2a..598a4b581c 100644 --- a/config/env/test.js +++ b/config/env/test.js @@ -28,6 +28,14 @@ module.exports = { app: { title: defaultEnvConfig.app.title + ' - Test Environment' }, + uploads: { + profileUpload: { + dest: './modules/users/client/img/profile/uploads/', // Profile upload destination path + limits: { + fileSize: 100000 // Limit filesize (100kb) for testing purposes + } + } + }, facebook: { clientID: process.env.FACEBOOK_ID || 'APP_ID', clientSecret: process.env.FACEBOOK_SECRET || 'APP_SECRET', diff --git a/config/lib/multer.js b/config/lib/multer.js index 960ffcb443..81c4ca38f7 100644 --- a/config/lib/multer.js +++ b/config/lib/multer.js @@ -1,8 +1,10 @@ 'use strict'; -module.exports.profileUploadFileFilter = function (req, file, cb) { +module.exports.profileUploadFileFilter = function (req, file, callback) { if (file.mimetype !== 'image/png' && file.mimetype !== 'image/jpg' && file.mimetype !== 'image/jpeg' && file.mimetype !== 'image/gif') { - return cb(new Error('Only image files are allowed!'), false); + var err = new Error(); + err.code = 'UNSUPPORTED_MEDIA_TYPE'; + return callback(err, false); } - cb(null, true); + callback(null, true); }; diff --git a/modules/core/server/controllers/errors.server.controller.js b/modules/core/server/controllers/errors.server.controller.js index c584819dd7..0541b64b94 100644 --- a/modules/core/server/controllers/errors.server.controller.js +++ b/modules/core/server/controllers/errors.server.controller.js @@ -45,8 +45,11 @@ exports.getErrorMessage = function (err) { case 11001: message = getUniqueErrorMessage(err); break; + case 'UNSUPPORTED_MEDIA_TYPE': + message = 'Unsupported filetype'; + break; case 'LIMIT_FILE_SIZE': - message = 'Image too big. Please maximum ' + (config.uploads.profileUpload.limits.fileSize / (1024 * 1024)).toFixed(2) + ' Mb files.'; + message = 'Image too big. The maximum size allowed is ' + (config.uploads.profileUpload.limits.fileSize / (1024 * 1024)).toFixed(2) + ' Mb'; break; case 'LIMIT_UNEXPECTED_FILE': message = 'Missing `newProfilePicture` field'; 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..58be6e31b8 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 @@ -11,7 +11,6 @@ var vm = this; vm.user = Authentication.user; - vm.fileSelected = false; vm.upload = function (dataUrl, name) { vm.success = vm.error = null; @@ -32,6 +31,14 @@ }); }; + // Called after the user has selected any file and it's been cropped + vm.onFileSelection = function() { + vm.success = vm.error = vm.nowResizing = vm.pictureSelected = null; + + // proceed to crop if they didn't cancel and it's a valid image file + if (vm.picFile && !vm.userForm.$error.pattern) vm.pictureSelected = true; + }; + // Called after the user has successfully uploaded a new picture function onSuccessItem(response) { // Show success message @@ -41,13 +48,13 @@ vm.user = Authentication.user = response; // Reset form - vm.fileSelected = false; + vm.pictureSelected = false; vm.progress = 0; } // Called after the user has failed to uploaded a new picture function onErrorItem(response) { - vm.fileSelected = false; + vm.pictureSelected = false; // Show error message vm.error = response.message; diff --git a/modules/users/client/css/users.css b/modules/users/client/css/users.css index cd0141635b..a841183877 100644 --- a/modules/users/client/css/users.css +++ b/modules/users/client/css/users.css @@ -38,6 +38,7 @@ background: #E4E4E4; width: 300px; height: 300px; + margin: 0 auto; } .social { 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..7ee227bdf2 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 @@ -1,24 +1,30 @@
-
-