Skip to content

Commit

Permalink
Be defensive if the project config is missing its users key
Browse files Browse the repository at this point in the history
Resolves #4206
  • Loading branch information
brandonkelly committed May 2, 2019
1 parent 8585dd1 commit 30b4b1c
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
- Fixed a SQL error that would occur when deleting a site and transferring its content to another if you were using a database table prefix.
- Fixed an error that could occur when deleting a site.
- Fixed a PHP compile error that could occur when paginating a query. ([#4208](https://github.com/craftcms/cms/pull/4208))
- Fixed an error that could occur on the Settings → Users → Settings page if the project config was missing its `users` key. ([#4206](https://github.com/craftcms/cms/issues/4206))
- Fixed a bug where Craft wasn’t requiring email verification for new user accounts if the project config was missing its `users` key.

## 3.1.25 - 2019-04-30

Expand Down
2 changes: 1 addition & 1 deletion src/controllers/UserSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function actionSaveUserSettings()
$projectConfig = Craft::$app->getProjectConfig();
$settings = $projectConfig->get('users') ?? [];

$settings['photoVolumeUid'] = Craft::$app->getRequest()->getBodyParam('photoVolumeUid');
$settings['photoVolumeUid'] = Craft::$app->getRequest()->getBodyParam('photoVolumeUid') ?: null;
$settings['photoSubpath'] = Craft::$app->getRequest()->getBodyParam('photoSubpath');

if (Craft::$app->getEdition() === Craft::Pro) {
Expand Down
5 changes: 3 additions & 2 deletions src/controllers/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ public function actionSaveUser()
$request = Craft::$app->getRequest();
$userSession = Craft::$app->getUser();
$currentUser = $userSession->getIdentity();
$requireEmailVerification = Craft::$app->getProjectConfig()->get('users.requireEmailVerification');
$requireEmailVerification = Craft::$app->getProjectConfig()->get('users.requireEmailVerification') ?? true;

// Get the user being edited
// ---------------------------------------------------------------------
Expand Down Expand Up @@ -960,7 +960,8 @@ public function actionSaveUser()
$this->requirePermission('registerUsers');
} else {
// Make sure public registration is allowed
if (!Craft::$app->getProjectConfig()->get('users.allowPublicRegistration')) {
$allowPublicRegistration = Craft::$app->getProjectConfig()->get('users.allowPublicRegistration') ?? false;
if (!$allowPublicRegistration) {
throw new ForbiddenHttpException('Public registration is not allowed');
}

Expand Down
13 changes: 11 additions & 2 deletions src/templates/settings/users/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,18 @@


{% if settings is not defined %}
{% set settings = craft.app.projectConfig.get('users') %}
{% set settings = craft.app.projectConfig.get('users') ?? [] %}
{% endif %}

{# set defaults #}
{% set settings = {
photoVolumeUid: null,
photoSubpath: null,
requireEmailVerification: true,
allowPublicRegistration: false,
defaultGroup: null,
}|merge(settings) %}

{% set allVolumes = craft.app.volumes.getAllVolumes() %}
{% set volumeList = [] %}
{% for volume in allVolumes %}
Expand Down Expand Up @@ -51,7 +60,7 @@
first: true,
label: "User Photo Location"|t('app'),
instructions: "Where do you want to store user photos? Note that the subfolder path can contain variables like <code>{username}</code>."|t('app')
}, assetLocationInput(volumeList, settings.photoVolumeUid ?? null, settings.photoSubpath ?? null)) }}
}, assetLocationInput(volumeList, settings.photoVolumeUid, settings.photoSubpath)) }}
{% else %}
{{ forms.field({
first: true,
Expand Down
2 changes: 1 addition & 1 deletion src/templates/users/_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

{% do view.registerAssetBundle("craft\\web\\assets\\fileupload\\FileUploadAsset") %}

{% set requireEmailVerification = craft.app.projectConfig.get('users.requireEmailVerification') %}
{% set requireEmailVerification = craft.app.projectConfig.get('users.requireEmailVerification') ?? true %}

{% if craft.app.request.isPost %}
{% set currentGroupIds = craft.app.request.getBodyParam('groups') ?: [] %}
Expand Down
2 changes: 1 addition & 1 deletion src/templates/users/_photo.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% set volumeUid = craft.app.getSystemSettings.getSetting('users', 'photoVolumeUid') %}
{% set volumeUid = craft.app.projectConfig.get('users.photoVolumeUid') %}
{% if volumeUid %}
<div class="user-photo" data-user="{{ user.id }}">
<div id="current-photo">
Expand Down

0 comments on commit 30b4b1c

Please sign in to comment.