forked from fa/breadcrumb-the-shire
49 lines
1.3 KiB
PHP
49 lines
1.3 KiB
PHP
<?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];
|
|
}
|
|
}
|