<file>lib/data/user/option/IUserOptionOutput.class.php</file>
<file>lib/data/user/option/UserOptionOutput.class.php</file>
<file>lib/form/AbstractSecureForm.class.php</file>
+ <file>lib/form/AvatarEditForm.class.php</file>
<file>lib/form/Form.class.php</file>
<file>lib/form/MailForm.class.php</file>
<file>lib/form/MultifactorAuthenticationAbortForm.class.php</file>
<template>__multiPageCondition</template>
<template>__multilineItemListFormField</template>
<template>email_notification_userRegistration</template>
+ <template>avatarEdit</template>
</delete>
</data>
+++ /dev/null
-{include file='userMenuSidebar'}
-
-{include file='header' __disableAds=true __sidebarLeftHasMenu=true}
-
-{if $__wcf->user->disableAvatar}
- <woltlab-core-notice type="error">{lang}wcf.user.avatar.error.disabled{/lang}</woltlab-core-notice>
-{/if}
-
-{include file='shared_formError'}
-
-{if $success|isset}
- <woltlab-core-notice type="success">{lang}wcf.global.success.edit{/lang}</woltlab-core-notice>
-{/if}
-
-<form method="post" action="{link controller='AvatarEdit'}{/link}" id="avatarForm">
- <div role="group" aria-label="{lang}wcf.user.avatar{/lang}" class="section avatarEdit">
- <dl class="avatarType">
- <dt></dt>
- <dd>
- <label><input type="radio" name="avatarType" value="none" {if $avatarType == 'none'}checked {/if}> {lang}wcf.user.avatar.type.none{/lang}</label>
- <small>{lang}wcf.user.avatar.type.none.description{/lang}</small>
- </dd>
- </dl>
-
- {if $__wcf->getSession()->getPermission('user.profile.avatar.canUploadAvatar')}
- <dl class="avatarType jsOnly{if $errorField == 'custom'} formError{/if}" id="avatarUpload">
- <dt>
- {if $avatarType == 'custom'}
- {@$__wcf->getUserProfileHandler()->getAvatar()->getImageTag(96)}
- {else}
- <img src="{@$__wcf->getPath()}images/avatars/avatar-default.svg" alt="" class="userAvatarImage" style="width: 96px; height: 96px">
- {/if}
- </dt>
- <dd>
- <label><input type="radio" name="avatarType" value="custom"{if $avatarType == 'custom'} checked{/if}> {lang}wcf.user.avatar.type.custom{/lang}</label>
- <small>{lang}wcf.user.avatar.type.custom.description{/lang}</small>
-
- {* placeholder for upload button: *}
- <div class="avatarUploadButtonContainer"></div>
-
- {if $errorField == 'custom'}
- <small class="innerError">
- {if $errorType == 'empty'}{lang}wcf.global.form.error.empty{/lang}{/if}
- </small>
- {/if}
- </dd>
- </dl>
- {/if}
-
- {event name='avatarFields'}
- </div>
-
- {event name='sections'}
-
- {if !$__wcf->user->disableAvatar}
- <div class="formSubmit">
- <input type="submit" value="{lang}wcf.global.button.submit{/lang}" accesskey="s">
- {csrfToken}
- </div>
- {/if}
-</form>
-
-{if $__wcf->getSession()->getPermission('user.profile.avatar.canUploadAvatar')}
- <script data-relocate="true">
- $(function() {
- WCF.Language.addObject({
- 'wcf.user.avatar.upload.error.invalidExtension': '{jslang}wcf.user.avatar.upload.error.invalidExtension{/jslang}',
- 'wcf.user.avatar.upload.error.tooSmall': '{jslang}wcf.user.avatar.upload.error.tooSmall{/jslang}',
- 'wcf.user.avatar.upload.error.tooLarge': '{jslang}wcf.user.avatar.upload.error.tooLarge{/jslang}',
- 'wcf.user.avatar.upload.error.uploadFailed': '{jslang}wcf.user.avatar.upload.error.uploadFailed{/jslang}',
- 'wcf.user.avatar.upload.error.badImage': '{jslang}wcf.user.avatar.upload.error.badImage{/jslang}',
- 'wcf.user.avatar.upload.success': '{jslang}wcf.user.avatar.upload.success{/jslang}'
- });
-
- {if !$__wcf->user->disableAvatar}
- new WCF.User.Avatar.Upload();
- {/if}
- });
- </script>
-{/if}
-
-{include file='footer'}
+++ /dev/null
-<?php
-
-namespace wcf\form;
-
-use wcf\data\user\avatar\UserAvatarAction;
-use wcf\data\user\UserAction;
-use wcf\system\exception\PermissionDeniedException;
-use wcf\system\exception\UserInputException;
-use wcf\system\menu\user\UserMenu;
-use wcf\system\user\group\assignment\UserGroupAssignmentHandler;
-use wcf\system\user\UserProfileHandler;
-use wcf\system\WCF;
-
-/**
- * Shows the avatar edit form.
- *
- * @author Marcel Werk
- * @copyright 2001-2019 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- */
-class AvatarEditForm extends AbstractForm
-{
- /**
- * @inheritDoc
- */
- public $loginRequired = true;
-
- /**
- * @inheritDoc
- */
- public $templateName = 'avatarEdit';
-
- /**
- * avatar type
- * @var string
- */
- public $avatarType = 'none';
-
- /**
- * @inheritDoc
- */
- public function readFormParameters()
- {
- parent::readFormParameters();
-
- if (isset($_POST['avatarType'])) {
- $this->avatarType = $_POST['avatarType'];
- }
- }
-
- /**
- * @inheritDoc
- */
- public function validate()
- {
- parent::validate();
-
- if (WCF::getUser()->disableAvatar) {
- throw new PermissionDeniedException();
- }
-
- if ($this->avatarType != 'custom') {
- $this->avatarType = 'none';
- }
-
- switch ($this->avatarType) {
- case 'custom':
- if (!WCF::getUser()->avatarID) {
- throw new UserInputException('custom');
- }
- break;
- }
- }
-
- /**
- * @inheritDoc
- */
- public function save()
- {
- parent::save();
-
- if ($this->avatarType != 'custom') {
- // delete custom avatar
- if (WCF::getUser()->avatarID) {
- $action = new UserAvatarAction([WCF::getUser()->avatarID], 'delete');
- $action->executeAction();
- }
- }
-
- // update user
- $data = [];
- if ($this->avatarType === 'none') {
- $data = [
- 'avatarID' => null,
- ];
- }
- $this->objectAction = new UserAction([WCF::getUser()], 'update', [
- 'data' => \array_merge($this->additionalFields, $data),
- ]);
- $this->objectAction->executeAction();
-
- // check if the user will be automatically added to new user groups
- // because of the changed avatar
- UserGroupAssignmentHandler::getInstance()->checkUsers([WCF::getUser()->userID]);
-
- UserProfileHandler::getInstance()->reloadUserProfile();
-
- $this->saved();
- WCF::getTPL()->assign('success', true);
- }
-
- /**
- * @inheritDoc
- */
- public function readData()
- {
- parent::readData();
-
- if (empty($_POST)) {
- if (WCF::getUser()->avatarID) {
- $this->avatarType = 'custom';
- }
- }
- }
-
- /**
- * @inheritDoc
- */
- public function assignVariables()
- {
- parent::assignVariables();
-
- WCF::getTPL()->assign([
- 'avatarType' => $this->avatarType,
- ]);
- }
-
- /**
- * @inheritDoc
- */
- public function show()
- {
- // set active tab
- UserMenu::getInstance()->setActiveMenuItem('wcf.user.menu.profile.avatar');
-
- parent::show();
- }
-}
use wcf\data\user\avatar\UserAvatarAction;
use wcf\data\user\User;
use wcf\data\user\UserEditor;
+use wcf\system\user\group\assignment\UserGroupAssignmentHandler;
use wcf\system\user\storage\UserStorageHandler;
+use wcf\system\user\UserProfileHandler;
+use wcf\system\WCF;
final class SetAvatar
{
]);
UserStorageHandler::getInstance()->reset([$this->user->userID], 'avatar');
+
+ // check if the user will be automatically added to new user groups
+ // because of the changed avatar
+ UserGroupAssignmentHandler::getInstance()->checkUsers([$this->user->userID]);
+
+ if ($this->user->userID === WCF::getUser()->userID) {
+ UserProfileHandler::getInstance()->reloadUserProfile();
+ }
}
}