instances added god may help
This commit is contained in:
48
lib/Service/User/UserPasswordService.php
Normal file
48
lib/Service/User/UserPasswordService.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace MintyPHP\Service\User;
|
||||
|
||||
use MintyPHP\Repository\User\UserWriteRepository;
|
||||
|
||||
class UserPasswordService
|
||||
{
|
||||
public function __construct(
|
||||
private readonly UserPasswordPolicyService $passwordPolicyService,
|
||||
private readonly UserWriteRepository $userWriteRepository
|
||||
) {
|
||||
}
|
||||
|
||||
public function validatePassword(
|
||||
string $password,
|
||||
string $password2,
|
||||
bool $required,
|
||||
?string $email
|
||||
): array {
|
||||
return $this->passwordPolicyService->validate($password, $password2, $required, $email);
|
||||
}
|
||||
|
||||
public function passwordHints(): array
|
||||
{
|
||||
return $this->passwordPolicyService->hints();
|
||||
}
|
||||
|
||||
public function passwordMinLength(): int
|
||||
{
|
||||
return $this->passwordPolicyService->minLength();
|
||||
}
|
||||
|
||||
public function resetPassword(int $userId, string $password, string $password2): array
|
||||
{
|
||||
$errors = $this->passwordPolicyService->validate($password, $password2, true, '');
|
||||
if ($errors) {
|
||||
return ['ok' => false, 'errors' => $errors];
|
||||
}
|
||||
|
||||
$updated = $this->userWriteRepository->setPassword($userId, $password);
|
||||
if (!$updated) {
|
||||
return ['ok' => false, 'errors' => [t('Password can not be updated')]];
|
||||
}
|
||||
|
||||
return ['ok' => true];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user