Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust to the latest atk4/ui #105

Merged
merged 5 commits into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},
"require-release": {
"php": ">=7.4 <8.3",
"atk4/ui": "~4.0.0"
"atk4/ui": "~5.0.0"
},
"require-dev": {
"behat/mink-extension": "^2.3.1",
Expand Down
2 changes: 1 addition & 1 deletion src/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ public function setPreferencePage(VirtualPage $page): void
$f->onSubmit(function (Form $f) {
$f->model->save();

return $f->success('User preferences saved.');
return $f->jsSuccess('User preferences saved.');
});
}

Expand Down
8 changes: 6 additions & 2 deletions src/Feature/PasswordManagementTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ public function resetPassword(int $length = 8): string
* - len: 0 (minimum length)
* - upper: 0 (minimum upper characters)
*
* @param array<string, mixed> $settings
*
* @return string|null
*/
public function checkPasswordStrength(string $password, array $settings = ['strength' => 3])
Expand Down Expand Up @@ -246,7 +248,9 @@ private function calculatePasswordStrength(string $pw): int
* For example if $charLocs is [0, 2, 3], then only $src[2:3] is a possible
* substring with sequential chars.
*
* @return array [[c, c, c, c], [a, a, a], ...]
* @param list<int> $charLocs
*
* @return list<list<non-empty-string>> [[c, c, c, c], [a, a, a], ...]
*/
private function findSequence(array $charLocs, string $src): array
{
Expand All @@ -260,7 +264,7 @@ private function findSequence(array $charLocs, string $src): array
$distance = $next - $here;
$charDistance = ord($charNext) - ord($charHere);
if ($distance === 1 && $charDistance === 1) {
// We find a pair of sequential chars!
// we find a pair of sequential chars
if ($sequence === []) {
$sequence = [$charHere, $charNext];
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/Form/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected function init(): void
return $this->getApp()->jsRedirect($linkSuccess);
}

return $form->error('password', 'Email or password is incorrect');
return $form->jsError('password', 'Email or password is incorrect');
});
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Form/Register.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,18 @@ public function setModel(Model $user, array $fields = null): void
$model = $this->model->getModel();
$entity = $model->tryLoadBy($this->auth->fieldLogin, $form->model->get($this->auth->fieldLogin));
if ($entity !== null) {
return $form->error($this->auth->fieldLogin, 'User with this email already exist');
return $form->jsError($this->auth->fieldLogin, 'User with this email already exist');
}

// check if passwords match
if (!PasswordField::assertInstanceOf($form->model->getField('password'))->verifyPassword($form->model, $form->model->get('password2'))) {
return $form->error('password2', 'Passwords does not match');
return $form->jsError('password2', 'Passwords does not match');
}

// save user
$form->model->save();

return $form->success('Account has been created');
return $form->jsSuccess('Account has been created');
});
}
}
5 changes: 3 additions & 2 deletions src/UserAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Atk4\Data\Model;
use Atk4\Ui\Crud;
use Atk4\Ui\Form;
use Atk4\Ui\Js\JsBlock;
use Atk4\Ui\Js\JsToast;
use Atk4\Ui\Table;
use Atk4\Ui\View;
Expand Down Expand Up @@ -61,13 +62,13 @@ public function setModel(Model $user): void
->setPassword($userEntity, $form->model->get('visible_password'));
$userEntity->save();

return [
return new JsBlock([
$v->getOwner()->jsHide(),
new JsToast([
'message' => 'Password for ' . $userEntity->get($userEntity->titleField) . ' is changed!',
'class' => 'success',
]),
];
]);
});
});

Expand Down
3 changes: 3 additions & 0 deletions tests/AclTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ protected function createAuthAndLogin(string $user): Auth
return $auth;
}

/**
* @param \Closure(): void $fx
*/
protected function invokeAndAssertAclException(\Closure $fx): void
{
$e = null;
Expand Down