diff --git a/CHANGELOG.md b/CHANGELOG.md index fdf3d4d7146..361730366ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ - Fixed a bug where the “All” checkbox label was getting HTML-encoded when using `Craft.ui.createCheckboxSelect()`. - Fixed a bug where week day and month names were being translated based on the current formatting locale, rather than the current language. ([#7312](https://github.com/craftcms/cms/issues/7312)) - Fixed a bug where `craft\elements\Asset::getSrcset()` could return the wrong value if the asset had a named transform set on it. ([#7352](https://github.com/craftcms/cms/issues/7352)) +- Fixed a bug where user registration forms could get a “Username cannot be blank” error even if the `useEmailAsUsername` config setting was enabled. ([#7357](https://github.com/craftcms/cms/issues/7357)) ## 3.5.17.1 - 2020-12-17 diff --git a/src/elements/User.php b/src/elements/User.php index adcad91d2b5..28e19ef39d1 100644 --- a/src/elements/User.php +++ b/src/elements/User.php @@ -698,10 +698,14 @@ protected function defineRules(): array $rules[] = [['email', 'unverifiedEmail'], 'email', 'enableIDN' => $enableIdn]; $rules[] = [['email', 'password', 'unverifiedEmail'], 'string', 'max' => 255]; $rules[] = [['username', 'firstName', 'lastName', 'verificationCode'], 'string', 'max' => 100]; - $rules[] = [['username', 'email'], 'required']; - $rules[] = [['username'], UsernameValidator::class]; + $rules[] = [['email'], 'required']; $rules[] = [['lastLoginAttemptIp'], 'string', 'max' => 45]; + if (!Craft::$app->getConfig()->getGeneral()->useEmailAsUsername) { + $rules[] = [['username'], 'required']; + $rules[] = [['username'], UsernameValidator::class]; + } + if (Craft::$app->getIsInstalled()) { $rules[] = [ ['username', 'email'],