From 01a84ee4e2cff09347ca670f412c03e1f1e0fb99 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Sat, 22 Nov 2014 14:45:06 +0100 Subject: [PATCH] Changed account settings editing Account settings editing no longer encapsulates file content in base64. --- .../UserAccountSettingsPresenter.js | 56 ++++++++----------- src/FormData/UserEditFormData.php | 2 +- 2 files changed, 24 insertions(+), 34 deletions(-) diff --git a/public_html/js/Presenters/UserAccountSettingsPresenter.js b/public_html/js/Presenters/UserAccountSettingsPresenter.js index 50236d46..76fed7e0 100644 --- a/public_html/js/Presenters/UserAccountSettingsPresenter.js +++ b/public_html/js/Presenters/UserAccountSettingsPresenter.js @@ -77,11 +77,7 @@ App.Presenters.UserAccountSettingsPresenter = function( } function avatarContentChanged(files) { - if (files.length === 1) { - fileDropper.readAsDataURL(files[0], function(content) { - avatarContent = content; - }); - } + avatarContent = files[0]; } function accountSettingsFormSubmitted(e) { @@ -89,38 +85,42 @@ App.Presenters.UserAccountSettingsPresenter = function( var $el = jQuery(target); var $messages = jQuery(target).find('.messages'); messagePresenter.hideMessages($messages); - var formData = {}; + var formData = new FormData(); if (privileges.canChangeAvatarStyle) { - formData.avatarStyle = $el.find('[name=avatar-style]:checked').val(); + formData.append('avatarStyle', $el.find('[name=avatar-style]:checked').val()); if (avatarContent) { - formData.avatarContent = avatarContent; + formData.append('avatarContent', avatarContent); } } if (privileges.canChangeName) { - formData.userName = $el.find('[name=userName]').val(); + formData.append('userName', $el.find('[name=userName]').val()); } + if (privileges.canChangeEmailAddress) { - formData.email = $el.find('[name=email]').val(); + formData.append('email', $el.find('[name=email]').val()); } + if (privileges.canChangePassword) { - formData.password = $el.find('[name=password]').val(); - formData.passwordConfirmation = $el.find('[name=passwordConfirmation]').val(); + var password = $el.find('[name=password]').val(); + var passwordConfirmation = $el.find('[name=passwordConfirmation]').val(); + + if (password) { + if (password !== passwordConfirmation) { + messagePresenter.showError($messages, 'Passwords must be the same.'); + return; + } + + formData.append('password', password); + } } + if (privileges.canChangeAccessRank) { - formData.accessRank = $el.find('[name=access-rank]:checked').val(); + formData.append('accessRank', $el.find('[name=access-rank]:checked').val()); } + if (privileges.canBan) { - formData.banned = $el.find('[name=ban]').is(':checked') ? 1 : 0; - } - - if (!validateAccountSettingsFormData(formData)) { - return; - } - - if (!formData.password) { - delete formData.password; - delete formData.passwordConfirmation; + formData.append('banned', $el.find('[name=ban]').is(':checked') ? 1 : 0); } promise.wait(api.post('/users/' + user.name, formData)) @@ -153,16 +153,6 @@ App.Presenters.UserAccountSettingsPresenter = function( messagePresenter.showError($messages, apiResponse.json && apiResponse.json.error || apiResponse); } - function validateAccountSettingsFormData(formData) { - var $messages = jQuery(target).find('.messages'); - if (formData.password !== formData.passwordConfirmation) { - messagePresenter.showError($messages, 'Passwords must be the same.'); - return false; - } - - return true; - } - return { init: init, render: render, diff --git a/src/FormData/UserEditFormData.php b/src/FormData/UserEditFormData.php index 4f41492e..45549b67 100644 --- a/src/FormData/UserEditFormData.php +++ b/src/FormData/UserEditFormData.php @@ -27,7 +27,7 @@ class UserEditFormData implements IValidatable $this->accessRank = EnumHelper::accessRankFromString($inputReader->accessRank); if ($inputReader->avatarStyle !== null) $this->avatarStyle = EnumHelper::avatarStyleFromString($inputReader->avatarStyle); - $this->avatarContent = $inputReader->decodeBase64($inputReader->avatarContent); + $this->avatarContent = $inputReader->readFile('avatarContent'); $this->browsingSettings = json_decode($inputReader->browsingSettings); if ($inputReader->banned !== null) $this->banned = boolval($inputReader->banned);