Make it possible to edit a user without necessarily updating the users password (closes #1942)

This commit is contained in:
Bernd Bestel
2022-08-27 14:54:52 +02:00
parent 7e2f30396f
commit 24c9247663
4 changed files with 67 additions and 19 deletions

View File

@@ -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 <https://lt.demo.grocy.info>)

View File

@@ -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');

View File

@@ -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,6 +43,18 @@ class UsersService extends BaseService
}
$user = $this->getDatabase()->users($userId);
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,
@@ -51,6 +63,7 @@ class UsersService extends BaseService
'picture_file_name' => $pictureFileName
]);
}
}
public function GetUserSetting($userId, $settingKey)
{

View File

@@ -66,13 +66,32 @@
</div>
@if(!defined('GROCY_EXTERNALLY_MANAGED_AUTHENTICATION'))
@if($mode == 'edit')
<div class="form-group mb-1">
<div class="custom-control custom-checkbox">
<input class="form-check-input custom-control-input"
type="checkbox"
id="change_password"
name="change_password"
value="1">
<label class="form-check-label custom-control-label"
for="change_password">{{ $__t('Change password') }}
</label>
</div>
</div>
@endif
<div class="form-group">
<label for="password">{{ $__t('Password') }}</label>
<input type="password"
class="form-control"
required
id="password"
name="password">
name="password"
@if($mode=='edit'
)
disabled
@endif>
</div>
<div class="form-group">
@@ -81,7 +100,11 @@
class="form-control"
required
id="password_confirm"
name="password_confirm">
name="password_confirm"
@if($mode=='edit'
)
disabled
@endif>
<div class="invalid-feedback">{{ $__t('Passwords do not match') }}</div>
</div>
@else