Validate if the user names are correct
authorJoshua Rüsweg <josh@bastelstu.be>
Sat, 15 Jul 2017 19:10:08 +0000 (21:10 +0200)
committerJoshua Rüsweg <josh@bastelstu.be>
Sat, 15 Jul 2017 19:10:08 +0000 (21:10 +0200)
See #2315

wcfsetup/install/files/acp/templates/userTrophyAdd.tpl
wcfsetup/install/files/lib/acp/form/UserTrophyAddForm.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index 335e7040bf7323c6552e7da8105838f3c708eef5..139d7a464dc325ab9abafbafbcf213e09eb5d3d3 100644 (file)
                                <input id="user" name="user" type="text" value="{$user}"{if $action == 'edit'} disabled{/if}>
                                {if $errorField == 'user'}
                                        <small class="innerError">
-                                               {if $errorType == 'empty'}
+                                               {if $errorType|is_array}
+                                                       {foreach from=$errorType item='errorData'}
+                                                               {lang}wcf.acp.trophy.userTrophy.user.error.{@$errorData.type}{/lang}
+                                                       {/foreach}
+                                               {elseif $errorType == 'empty'}
                                                        {lang}wcf.global.form.error.empty{/lang}
                                                {/if}
                                        </small>
index e9dfeb0f87f693b143a1e7a4a0de5d7017e1ccbd..1bffb568851f65e1bd2f0669570c7a7dc068eeff 100644 (file)
@@ -3,11 +3,12 @@ namespace wcf\acp\form;
 use wcf\data\trophy\category\TrophyCategoryCache;
 use wcf\data\trophy\Trophy;
 use wcf\data\user\trophy\UserTrophyAction;
-use wcf\data\user\UserList;
+use wcf\data\user\UserProfile;
 use wcf\system\exception\UserInputException;
 use wcf\system\language\I18nHandler;
 use wcf\system\language\I18nValue;
 use wcf\system\WCF;
+use wcf\util\ArrayUtil;
 use wcf\util\StringUtil;
 
 /**
@@ -93,16 +94,35 @@ class UserTrophyAddForm extends AbstractAcpForm {
                if (isset($_POST['useCustomDescription'])) $this->useCustomDescription = 1;
                
                $this->trophy = new Trophy($this->trophyID);
-               
+       }
+       
+       /**
+        * Validates the users. 
+        * 
+        * @throws UserInputException
+        */
+       protected function validateUser() {
                // read userIDs 
-               $userAsArray = explode(',', $this->user);
+               $userAsArray = ArrayUtil::trim(explode(',', $this->user));
+               
+               $userList = UserProfile::getUserProfilesByUsername($userAsArray);
                
-               $userList = new UserList();
-               $userList->getConditionBuilder()->add('user_table.username IN (?)', [$userAsArray]);
-               $userList->readObjects();
+               $error = []; 
                
-               foreach ($userList as $user) {
-                       $this->userIDs[] = $user->userID;
+               foreach ($userList as $username => $user) {
+                       if ($user === null) {
+                               $error[] = [
+                                       'type' => 'notFound', 
+                                       'username' => $username
+                               ];
+                       }
+                       else {
+                               $this->userIDs[] = $user->userID;
+                       }
+               }
+               
+               if (!empty($error)) {
+                       throw new UserInputException('user', $error);
                }
        }
        
@@ -118,6 +138,8 @@ class UserTrophyAddForm extends AbstractAcpForm {
                        }
                }
                
+               $this->validateUser();
+               
                if (empty($this->userIDs)) {
                        throw new UserInputException('user');
                }
index 98e936111adfcf81d91a0a31448fe574fb7d3035..c0f1ead99d92db59115ea04d9523b8a5147d02c5 100644 (file)
@@ -3639,6 +3639,7 @@ Die E-Mail-Adresse des neuen Benutzers lautet: {@$user->email}
                <item name="wcf.acp.trophy.delete.confirmMessage"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Willst du{else}Wollen Sie{/if} die Trophäe <span class="confirmationObject">{$trophy->getTitle()}</span> wirklich löschen?]]></item>
                <item name="wcf.acp.trophy.userTrophy.user"><![CDATA[Benutzer]]></item>
                <item name="wcf.acp.trophy.userTrophy.user.description"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Gebe{else}Geben Sie{/if} hier die Benutzer an, welche die Trophäe erhalten sollen.]]></item>
+               <item name="wcf.acp.trophy.userTrophy.user.error.notFound"><![CDATA[Der Benutzername „{$errorData[username]}“ konnte nicht gefunden werden.]]></item>
                <item name="wcf.acp.trophy.userTrophy.description"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Gebe{else}Geben Sie{/if} hier die Trophäe an, welche an die Benutzer vergeben werden soll. {if LANGUAGE_USE_INFORMAL_VARIANT}Du kannst{else}Sie können{/if} keine automatisch vergebene Trophäen manuell vergeben.]]></item>
                <item name="wcf.acp.trophy.userTrophy.useCustomDescription"><![CDATA[Benutzerdefinierte Trophäen-Beschreibung aktivieren]]></item>
                <item name="wcf.acp.trophy.userTrophy.delete.confirmMessage"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Willst du{else}Wollen Sie{/if} die Trophäe <span class="confirmationObject">{$userTrophy->getTrophy()->getTitle()}</span> von <span class="confirmationObject">{$userTrophy->getUserProfile()->username}</span> wirklich löschen?]]></item>
index 92e4bec057262e25b4255c64bd636bcfd9ac6344..5577dd038584467c50c712e685a1fdfb6cc6b2ec 100644 (file)
@@ -3626,6 +3626,7 @@ Open the link below to access the user profile:
                <item name="wcf.acp.trophy.delete.confirmMessage"><![CDATA[Do you really want to delete the trophy <span class="confirmationObject">{$trophy->getTitle()}</span>?]]></item>
                <item name="wcf.acp.trophy.userTrophy.user"><![CDATA[User]]></item>
                <item name="wcf.acp.trophy.userTrophy.user.description"><![CDATA[Enter the names of the users who should be awarded the trophy.]]></item>
+               <item name="wcf.acp.trophy.userTrophy.user.error.notFound"><![CDATA[The username “{$errorData[username]}” does not exist.]]></item>
                <item name="wcf.acp.trophy.userTrophy.description"><![CDATA[Select the trophy who should be awarded to the users. You cannot select automatically awarded trophies.]]></item>
                <item name="wcf.acp.trophy.userTrophy.useCustomDescription"><![CDATA[Use custom trophy description]]></item>
                <item name="wcf.acp.trophy.userTrophy.delete.confirmMessage"><![CDATA[Do you really want to delete the trophy <span class="confirmationObject">{$userTrophy->getTrophy()->getTitle()}</span> from <span class="confirmationObject">{$userTrophy->getUserProfile()->username}</span>?]]></item>