diff --git a/README.md b/README.md index 89620f1..5dbe3c5 100644 --- a/README.md +++ b/README.md @@ -12,4 +12,6 @@ Fixes/tweaks a few "issues" with the default UserFrosting installation, includin - Allow site-admins to view roles & permissions - Allow site-admins to edit basic role details (name, slug & description) - Added 'hasRole' twig function to check if a user has a role (if a role doesn't exist, always returns false) -- Added 'Auditer' role and split the activities permission away from site-admins (exclusive only) and everyone else \ No newline at end of file +- Added 'Auditer' role and split the activities permission away from site-admins (exclusive only) and everyone else +- Made the input elements on the account settings page more in line with the other inputs (including the "hidden" and "disabled" mechanisms) +- Update the "User" form to use the partial form elements for common styling with accounts page \ No newline at end of file diff --git a/routes/routes.php b/routes/routes.php new file mode 100644 index 0000000..687e00a --- /dev/null +++ b/routes/routes.php @@ -0,0 +1,15 @@ +group('/account', function () { + $this->get('/settings', 'UserFrosting\Sprinkle\UFTweaks\Controller\AccountController:pageSettings') + ->add('authGuard'); +})->add(new NoCache()); diff --git a/src/Controller/AccountController.php b/src/Controller/AccountController.php new file mode 100644 index 0000000..23330a1 --- /dev/null +++ b/src/Controller/AccountController.php @@ -0,0 +1,111 @@ +ci->config; + + /** @var \UserFrosting\Sprinkle\Account\Authorize\AuthorizationManager */ + $authorizer = $this->ci->authorizer; + + /** @var \UserFrosting\Sprinkle\Account\Database\Models\Interfaces\UserInterface $currentUser */ + $currentUser = $this->ci->currentUser; + + // Access-controlled page + if (!$authorizer->checkAccess($currentUser, 'uri_account_settings')) { + throw new ForbiddenException(); + } + + // Load validation rules + $schema = new RequestSchema('schema://requests/account-settings.yaml'); + $schema->set('password.validators.length.min', $config['site.password.length.min']); + $schema->set('password.validators.length.max', $config['site.password.length.max']); + $schema->set('passwordc.validators.length.min', $config['site.password.length.min']); + $schema->set('passwordc.validators.length.max', $config['site.password.length.max']); + $validatorAccountSettings = new JqueryValidationAdapter($schema, $this->ci->translator); + + $schema = new RequestSchema('schema://requests/profile-settings.yaml'); + $validatorProfileSettings = new JqueryValidationAdapter($schema, $this->ci->translator); + + // Get a list of all locales + $locales = $this->ci->locale->getAvailableOptions(); + + // Hide the locale field if there is only 1 locale available + $fields = [ + 'hidden' => [], + 'disabled' => [], + ]; + if (count($locales) <= 1) { + $fields['hidden'][] = 'locale'; + } + if (!$authorizer->checkAccess($currentUser, 'update_account_settings')) { + $fields['disabled'][] = 'name'; + $fields['disabled'][] = 'locale'; + $fields['disabled'][] = 'email'; + $fields['disabled'][] = 'copy'; + $fields['hidden'][] = 'password'; + $fields['hidden'][] = 'submit'; + } + + return $this->ci->view->render($response, 'pages/account-settings.html.twig', [ + 'user' => $currentUser, + 'locales' => $locales, + 'form' => [ + 'fields' => $fields, + ], + 'page' => [ + 'validators' => [ + 'account_settings' => $validatorAccountSettings->rules('json', false), + 'profile_settings' => $validatorProfileSettings->rules('json', false), + ] + ], + ]); + } +} diff --git a/templates/forms/partials/input-current_password.html.twig b/templates/forms/partials/input-current_password.html.twig new file mode 100644 index 0000000..788067d --- /dev/null +++ b/templates/forms/partials/input-current_password.html.twig @@ -0,0 +1,11 @@ +{% block input_current_password %} +{% if 'password' not in form.fields.hidden %} +
+ +
+ + +
+
+{% endif %} +{% endblock %} \ No newline at end of file diff --git a/templates/forms/partials/input-email.html.twig b/templates/forms/partials/input-email.html.twig new file mode 100644 index 0000000..9dd7454 --- /dev/null +++ b/templates/forms/partials/input-email.html.twig @@ -0,0 +1,18 @@ +{% block input_email %} +{% if 'email' not in form.fields.hidden %} +
+ +
+ + + {% if 'email' in form.fields.disabled %} + {% if 'copy' not in form.fields.disabled %} + + + + {% endif %} + {% endif %} +
+
+{% endif %} +{% endblock %} \ No newline at end of file diff --git a/templates/forms/partials/input-first_name.html.twig b/templates/forms/partials/input-first_name.html.twig new file mode 100644 index 0000000..552714c --- /dev/null +++ b/templates/forms/partials/input-first_name.html.twig @@ -0,0 +1,11 @@ +{% block input_first_name %} +{% if 'first_name' not in form.fields.hidden %} +
+ +
+ + +
+
+{% endif %} +{% endblock %} \ No newline at end of file diff --git a/templates/forms/partials/input-group.html.twig b/templates/forms/partials/input-group.html.twig new file mode 100644 index 0000000..18d3845 --- /dev/null +++ b/templates/forms/partials/input-group.html.twig @@ -0,0 +1,21 @@ +{% block input_group %} +{% if 'group' not in form.fields.hidden %} +
+ +
+ + {% if 'group' in form.fields.disabled %} + + {% else %} + + {% endif %} +
+
+{% endif %} +{% endblock %} \ No newline at end of file diff --git a/templates/forms/partials/input-last_name.html.twig b/templates/forms/partials/input-last_name.html.twig new file mode 100644 index 0000000..11dd6d5 --- /dev/null +++ b/templates/forms/partials/input-last_name.html.twig @@ -0,0 +1,11 @@ +{% block input_last_name %} +{% if 'last_name' not in form.fields.hidden %} +
+ +
+ + +
+
+{% endif %} +{% endblock %} \ No newline at end of file diff --git a/templates/forms/partials/input-locale.html.twig b/templates/forms/partials/input-locale.html.twig new file mode 100644 index 0000000..a768fba --- /dev/null +++ b/templates/forms/partials/input-locale.html.twig @@ -0,0 +1,19 @@ +{% block input_locale %} +{% if 'locale' not in form.fields.hidden %} +
+ +
+ + {% if 'locale' in form.fields.disabled %} + + {% else %} + + {% endif %} +
+
+{% endif %} +{% endblock %} \ No newline at end of file diff --git a/templates/forms/partials/input-new_password.html.twig b/templates/forms/partials/input-new_password.html.twig new file mode 100644 index 0000000..f002d86 --- /dev/null +++ b/templates/forms/partials/input-new_password.html.twig @@ -0,0 +1,18 @@ +{% block input_new_password %} +{% if 'password' not in form.fields.hidden %} +
+ +
+ + +
+
+
+ +
+ + +
+
+{% endif %} +{% endblock %} \ No newline at end of file diff --git a/templates/forms/partials/input-theme.html.twig b/templates/forms/partials/input-theme.html.twig new file mode 100644 index 0000000..d139b8a --- /dev/null +++ b/templates/forms/partials/input-theme.html.twig @@ -0,0 +1,19 @@ +{% block input_theme %} +{% if 'theme' not in form.fields.hidden %} +
+ +
+ + {% if 'theme' in form.fields.disabled %} + + {% else %} + + {% endif %} +
+
+{% endif %} +{% endblock %} \ No newline at end of file diff --git a/templates/forms/partials/input-user_name.html.twig b/templates/forms/partials/input-user_name.html.twig new file mode 100644 index 0000000..7b151f6 --- /dev/null +++ b/templates/forms/partials/input-user_name.html.twig @@ -0,0 +1,11 @@ +{% block input_user_name %} +{% if 'user_name' not in form.fields.hidden %} +
+ +
+ + +
+
+{% endif %} +{% endblock %} \ No newline at end of file diff --git a/templates/forms/settings-account.html.twig b/templates/forms/settings-account.html.twig new file mode 100644 index 0000000..535408a --- /dev/null +++ b/templates/forms/settings-account.html.twig @@ -0,0 +1,39 @@ +
+
+

{{translate("ACCOUNT.SETTINGS")}}

+
+
+ {% include "forms/csrf.html.twig" %} + + + + + {% block settings_account %} +
+
+ {% include "forms/partials/input-email.html.twig" %} +
+
+ +
+
+ {% include "forms/partials/input-new_password.html.twig" %} +
+
+ {% if 'password' not in form.fields.hidden %} +
+ {% endif %} +
+
+ {% include "forms/partials/input-current_password.html.twig" %} +
+
+ {% endblock %} +
+ {% if 'submit' not in form.fields.hidden %} + + {% endif %} +
diff --git a/templates/forms/settings-profile.html.twig b/templates/forms/settings-profile.html.twig new file mode 100644 index 0000000..46b485c --- /dev/null +++ b/templates/forms/settings-profile.html.twig @@ -0,0 +1,33 @@ +
+
+

{{translate("PROFILE.SETTINGS")}}

+
+
+ {% include "forms/csrf.html.twig" %} + + {% block settings_profile %} + {% if 'name' not in form.fields.hidden %} +
+
+ {% include "forms/partials/input-first_name.html.twig" %} +
+
+ {% include "forms/partials/input-last_name.html.twig" %} +
+
+ {% endif %} + +
+
+ {% include "forms/partials/input-locale.html.twig" %} +
+
+ {% endblock %} +
+ {% if 'submit' not in form.fields.hidden %} + + {% endif %} +
diff --git a/templates/forms/user.html.twig b/templates/forms/user.html.twig new file mode 100644 index 0000000..dd3ddf5 --- /dev/null +++ b/templates/forms/user.html.twig @@ -0,0 +1,46 @@ +{% extends "@admin/forms/user.html.twig" %} + +{% block user_form %} + {% if 'user_name' not in form.fields.hidden %} +
+ {% include "forms/partials/input-user_name.html.twig" %} +
+ {% endif %} + + {% if 'group' not in form.fields.hidden %} +
+ {% include "forms/partials/input-group.html.twig" %} +
+ {% endif %} + + {% if 'name' not in form.fields.hidden %} +
+ {% include "forms/partials/input-first_name.html.twig" %} +
+
+ {% include "forms/partials/input-last_name.html.twig" %} +
+ {% endif %} + + {% if 'email' not in form.fields.hidden %} +
+ {% include "forms/partials/input-email.html.twig" %} +
+ {% endif %} + + {% if 'theme' not in form.fields.hidden %} +
+ {% include "forms/partials/input-theme.html.twig" %} +
+ {% endif %} + + {% if 'locale' not in form.fields.hidden %} +
+ {% include "forms/partials/input-locale.html.twig" %} +
+ {% endif %} + + {% if 'password' not in form.fields.hidden %} + {% include "forms/partials/user-set-password.html.twig" %} + {% endif %} +{% endblock %} \ No newline at end of file