update Kirby

This commit is contained in:
isUnknown 2025-04-22 16:01:57 +02:00
parent ecd997c895
commit 1b05e91943
47 changed files with 963 additions and 307 deletions

View file

@ -3,6 +3,7 @@
use Kirby\Cms\App;
use Kirby\Cms\Find;
use Kirby\Cms\UserRules;
use Kirby\Exception\Exception;
use Kirby\Exception\InvalidArgumentException;
use Kirby\Panel\Field;
use Kirby\Panel\Panel;
@ -42,7 +43,9 @@ return [
'link' => false,
'required' => true
]),
'password' => Field::password(),
'password' => Field::password([
'autocomplete' => 'new-password'
]),
'translation' => Field::translation([
'required' => true
]),
@ -180,17 +183,23 @@ return [
'user.changePassword' => [
'pattern' => 'users/(:any)/changePassword',
'load' => function (string $id) {
$user = Find::user($id);
Find::user($id);
return [
'component' => 'k-form-dialog',
'props' => [
'fields' => [
'fields' => [
'currentPassword' => Field::password([
'label' => I18n::translate('user.changePassword.current'),
'autocomplete' => 'current-password'
]),
'password' => Field::password([
'label' => I18n::translate('user.changePassword.new'),
'label' => I18n::translate('user.changePassword.new'),
'autocomplete' => 'new-password'
]),
'passwordConfirmation' => Field::password([
'label' => I18n::translate('user.changePassword.new.confirm'),
'label' => I18n::translate('user.changePassword.new.confirm'),
'autocomplete' => 'new-password'
])
],
'submitButton' => I18n::translate('change'),
@ -198,13 +207,26 @@ return [
];
},
'submit' => function (string $id) {
$request = App::instance()->request();
$kirby = App::instance();
$request = $kirby->request();
$user = Find::user($id);
$currentPassword = $request->get('currentPassword');
$password = $request->get('password');
$passwordConfirmation = $request->get('passwordConfirmation');
// validate the password
// validate the current password of the acting user
try {
$kirby->user()->validatePassword($currentPassword);
} catch (Exception) {
// catching and re-throwing exception to avoid automatic
// sign-out of current user from the Panel
throw new InvalidArgumentException([
'key' => 'user.password.wrong'
]);
}
// validate the new password
UserRules::validPassword($user, $password ?? '');
// compare passwords