diff --git a/changelog/69_UNRELEASED_xxxx-xx-xx.md b/changelog/69_UNRELEASED_xxxx-xx-xx.md index 05c8f9b1..4ab5df5a 100644 --- a/changelog/69_UNRELEASED_xxxx-xx-xx.md +++ b/changelog/69_UNRELEASED_xxxx-xx-xx.md @@ -59,6 +59,7 @@ ### General +- It's now possible to edit a user without necessarily updating the users password - Fixed that when running label printer WebHooks client side (so when `LABEL_PRINTER_RUN_SERVER` = `false`), the setting `LABEL_PRINTER_HOOK_JSON` was ignored (the WebHook data was always sent as form data) - New translations: (thanks all the translators) - Lithuanian (demo available at ) diff --git a/public/viewjs/userform.js b/public/viewjs/userform.js index 39d334b6..2e0f8482 100644 --- a/public/viewjs/userform.js +++ b/public/viewjs/userform.js @@ -120,15 +120,6 @@ $('#user-form input').keydown(function(event) } }); -if (GetUriParam("changepw") === "true") -{ - $('#password').focus(); -} -else -{ - $('#username').focus(); -} - $("#user-picture").on("change", function(e) { $("#user-picture-label").removeClass("d-none"); @@ -148,5 +139,25 @@ $("#delete-current-user-picture-button").on("click", function(e) $("#user-picture-label-none").removeClass("d-none"); }); +$("#change_password").click(function() +{ + $("#password").attr("disabled", !this.checked); + $("#password_confirm").attr("disabled", !this.checked); + + setTimeout(function() + { + $("#password").focus(); + }, 200); +}); + +if (GetUriParam("changepw") === "true") +{ + $("#change_password").click(); +} +else +{ + $('#username').focus(); +} + Grocy.Components.UserfieldsForm.Load(); Grocy.FrontendHelpers.ValidateForm('user-form'); diff --git a/services/UsersService.php b/services/UsersService.php index 30edeff1..94b1912c 100644 --- a/services/UsersService.php +++ b/services/UsersService.php @@ -35,7 +35,7 @@ class UsersService extends BaseService $row->delete(); } - public function EditUser(int $userId, string $username, string $firstName, string $lastName, string $password, string $pictureFileName = null) + public function EditUser(int $userId, string $username, string $firstName, string $lastName, ?string $password, string $pictureFileName = null) { if (!$this->UserExists($userId)) { @@ -43,13 +43,26 @@ class UsersService extends BaseService } $user = $this->getDatabase()->users($userId); - $user->update([ - 'username' => $username, - 'first_name' => $firstName, - 'last_name' => $lastName, - 'password' => password_hash($password, PASSWORD_DEFAULT), - 'picture_file_name' => $pictureFileName - ]); + + if ($password == null || empty($password)) + { + $user->update([ + 'username' => $username, + 'first_name' => $firstName, + 'last_name' => $lastName, + 'picture_file_name' => $pictureFileName + ]); + } + else + { + $user->update([ + 'username' => $username, + 'first_name' => $firstName, + 'last_name' => $lastName, + 'password' => password_hash($password, PASSWORD_DEFAULT), + 'picture_file_name' => $pictureFileName + ]); + } } public function GetUserSetting($userId, $settingKey) diff --git a/views/userform.blade.php b/views/userform.blade.php index 3c363c4b..fe654e54 100644 --- a/views/userform.blade.php +++ b/views/userform.blade.php @@ -66,13 +66,32 @@ @if(!defined('GROCY_EXTERNALLY_MANAGED_AUTHENTICATION')) + @if($mode == 'edit') +
+
+ + +
+
+ @endif +
+ name="password" + @if($mode=='edit' + ) + disabled + @endif>
@@ -81,7 +100,11 @@ class="form-control" required id="password_confirm" - name="password_confirm"> + name="password_confirm" + @if($mode=='edit' + ) + disabled + @endif>
{{ $__t('Passwords do not match') }}
@else