|
18 | 18 | use craft\errors\InvalidElementException; |
19 | 19 | use craft\errors\UploadFailedException; |
20 | 20 | use craft\errors\UserLockedException; |
| 21 | +use craft\errors\WrongEditionException; |
21 | 22 | use craft\events\DefineUserContentSummaryEvent; |
22 | 23 | use craft\events\FindLoginUserEvent; |
23 | 24 | use craft\events\InvalidUserTokenEvent; |
@@ -163,7 +164,6 @@ class UsersController extends Controller |
163 | 164 | 'logout' => self::ALLOW_ANONYMOUS_LIVE | self::ALLOW_ANONYMOUS_OFFLINE, |
164 | 165 | 'impersonate-with-token' => self::ALLOW_ANONYMOUS_LIVE | self::ALLOW_ANONYMOUS_OFFLINE, |
165 | 166 | 'save-user' => self::ALLOW_ANONYMOUS_LIVE, |
166 | | - 'send-activation-email' => self::ALLOW_ANONYMOUS_LIVE | self::ALLOW_ANONYMOUS_OFFLINE, |
167 | 167 | 'send-password-reset-email' => self::ALLOW_ANONYMOUS_LIVE | self::ALLOW_ANONYMOUS_OFFLINE, |
168 | 168 | 'set-password' => self::ALLOW_ANONYMOUS_LIVE | self::ALLOW_ANONYMOUS_OFFLINE, |
169 | 169 | 'verify-email' => self::ALLOW_ANONYMOUS_LIVE | self::ALLOW_ANONYMOUS_OFFLINE, |
@@ -294,7 +294,7 @@ private function _findLoginUser(string $loginName): ?User |
294 | 294 | */ |
295 | 295 | public function actionImpersonate(): ?Response |
296 | 296 | { |
297 | | - $this->requirePostRequest(); |
| 297 | + $this->userActionChecks(); |
298 | 298 |
|
299 | 299 | $userSession = Craft::$app->getUser(); |
300 | 300 | $userId = $this->request->getRequiredBodyParam('userId'); |
@@ -332,7 +332,7 @@ public function actionImpersonate(): ?Response |
332 | 332 | */ |
333 | 333 | public function actionGetImpersonationUrl(): Response |
334 | 334 | { |
335 | | - $this->requirePostRequest(); |
| 335 | + $this->userActionChecks(); |
336 | 336 |
|
337 | 337 | $userId = $this->request->getBodyParam('userId'); |
338 | 338 | $user = Craft::$app->getUsers()->getUserById($userId); |
@@ -607,6 +607,7 @@ public function actionSendPasswordResetEmail(): ?Response |
607 | 607 | */ |
608 | 608 | public function actionGetPasswordResetUrl(): Response |
609 | 609 | { |
| 610 | + $this->userActionChecks(); |
610 | 611 | $this->requirePermission('administrateUsers'); |
611 | 612 |
|
612 | 613 | if (!$this->_verifyElevatedSession()) { |
@@ -777,7 +778,7 @@ public function actionVerifyEmail(): Response |
777 | 778 | */ |
778 | 779 | public function actionEnableUser(): ?Response |
779 | 780 | { |
780 | | - $this->requirePostRequest(); |
| 781 | + $this->userActionChecks(); |
781 | 782 |
|
782 | 783 | $userId = $this->request->getRequiredBodyParam('userId'); |
783 | 784 | $user = Craft::$app->getUsers()->getUserById($userId); |
@@ -814,8 +815,8 @@ public function actionEnableUser(): ?Response |
814 | 815 | */ |
815 | 816 | public function actionActivateUser(): ?Response |
816 | 817 | { |
| 818 | + $this->userActionChecks(); |
817 | 819 | $this->requirePermission('administrateUsers'); |
818 | | - $this->requirePostRequest(); |
819 | 820 | $userVariable = $this->request->getValidatedBodyParam('userVariable') ?? 'user'; |
820 | 821 |
|
821 | 822 | $userId = $this->request->getRequiredBodyParam('userId'); |
@@ -1779,7 +1780,7 @@ public function actionDeleteUserPhoto(): Response |
1779 | 1780 | */ |
1780 | 1781 | public function actionSendActivationEmail(): ?Response |
1781 | 1782 | { |
1782 | | - $this->requirePostRequest(); |
| 1783 | + $this->userActionChecks(); |
1783 | 1784 |
|
1784 | 1785 | $userId = $this->request->getRequiredBodyParam('userId'); |
1785 | 1786 |
|
@@ -1833,7 +1834,7 @@ public function actionSendActivationEmail(): ?Response |
1833 | 1834 | */ |
1834 | 1835 | public function actionUnlockUser(): Response |
1835 | 1836 | { |
1836 | | - $this->requirePostRequest(); |
| 1837 | + $this->userActionChecks(); |
1837 | 1838 | $this->requirePermission('moderateUsers'); |
1838 | 1839 |
|
1839 | 1840 | $userId = $this->request->getRequiredBodyParam('userId'); |
@@ -1871,7 +1872,7 @@ public function actionUnlockUser(): Response |
1871 | 1872 | */ |
1872 | 1873 | public function actionSuspendUser(): ?Response |
1873 | 1874 | { |
1874 | | - $this->requirePostRequest(); |
| 1875 | + $this->userActionChecks(); |
1875 | 1876 | $this->requirePermission('moderateUsers'); |
1876 | 1877 |
|
1877 | 1878 | $userId = $this->request->getRequiredBodyParam('userId'); |
@@ -1952,7 +1953,7 @@ public function actionUserContentSummary(): Response |
1952 | 1953 | */ |
1953 | 1954 | public function actionDeactivateUser(): ?Response |
1954 | 1955 | { |
1955 | | - $this->requirePostRequest(); |
| 1956 | + $this->userActionChecks(); |
1956 | 1957 |
|
1957 | 1958 | $userId = $this->request->getRequiredBodyParam('userId'); |
1958 | 1959 | $user = Craft::$app->getUsers()->getUserById($userId); |
@@ -2046,7 +2047,7 @@ public function actionDeleteUser(): ?Response |
2046 | 2047 | */ |
2047 | 2048 | public function actionUnsuspendUser(): ?Response |
2048 | 2049 | { |
2049 | | - $this->requirePostRequest(); |
| 2050 | + $this->userActionChecks(); |
2050 | 2051 | $this->requirePermission('moderateUsers'); |
2051 | 2052 |
|
2052 | 2053 | $userId = $this->request->getRequiredBodyParam('userId'); |
@@ -2214,22 +2215,6 @@ public function actionSaveFieldLayout(): ?Response |
2214 | 2215 | return $this->redirectToPostedUrl(); |
2215 | 2216 | } |
2216 | 2217 |
|
2217 | | - /** |
2218 | | - * Verifies a password for a user. |
2219 | | - * |
2220 | | - * @return Response|null |
2221 | | - */ |
2222 | | - public function actionVerifyPassword(): ?Response |
2223 | | - { |
2224 | | - $this->requireAcceptsJson(); |
2225 | | - |
2226 | | - if ($this->_verifyExistingPassword()) { |
2227 | | - return $this->asSuccess(); |
2228 | | - } |
2229 | | - |
2230 | | - return $this->asFailure(Craft::t('app', 'Invalid password.')); |
2231 | | - } |
2232 | | - |
2233 | 2218 | /** |
2234 | 2219 | * Handles a failed login attempt. |
2235 | 2220 | * |
@@ -2819,4 +2804,17 @@ private function clearPassword(ModelInterface|Model $model): void |
2819 | 2804 | $model->currentPassword = null; |
2820 | 2805 | } |
2821 | 2806 | } |
| 2807 | + |
| 2808 | + /** |
| 2809 | + * @throws BadRequestHttpException |
| 2810 | + * @throws ForbiddenHttpException |
| 2811 | + * @throws WrongEditionException |
| 2812 | + */ |
| 2813 | + private function userActionChecks(): void |
| 2814 | + { |
| 2815 | + Craft::$app->requireEdition(Craft::Pro); |
| 2816 | + $this->requirePostRequest(); |
| 2817 | + $this->requireCpRequest(); |
| 2818 | + $this->requirePermission('editUsers'); |
| 2819 | + } |
2822 | 2820 | } |
0 commit comments