add user join event #4

This commit is contained in:
ghost 2023-10-11 16:38:01 +03:00
parent 0339ee9f23
commit 28f21d09c6
5 changed files with 388 additions and 94 deletions

View file

@ -23,20 +23,18 @@ class UserService
$this->parameterBagInterface = $parameterBagInterface;
}
public function init(string $address): User
public function addUser(
string $address,
string $added,
string $locale,
array $locales,
string $theme,
bool $sensitive = true,
bool $approved = false,
bool $moderator = false,
bool $status = true
): ?User
{
// Return existing user
if ($result = $this->entityManagerInterface
->getRepository(User::class)
->findOneBy(
[
'address' => $address
]
))
{
return $result;
}
// Create new user
$user = new User();
@ -45,38 +43,39 @@ class UserService
);
$user->setAdded(
time()
$added
);
$user->setApproved(
false
$approved
);
$user->setModerator(
false
$moderator
);
$user->setStatus(
true
$status
);
$user->setLocale(
$this->parameterBagInterface->get('app.locale')
$locale
);
$user->setLocales(
explode('|', $this->parameterBagInterface->get('app.locales'))
$locales
);
$user->setTheme(
$this->parameterBagInterface->get('app.theme')
$theme
);
$user->setSensitive(
$this->parameterBagInterface->get('app.sensitive')
$sensitive
);
$this->save($user);
$this->entityManagerInterface->persist($user);
$this->entityManagerInterface->flush();
// Set initial user as approved & moderator
if (1 === $user->getId())
@ -85,7 +84,8 @@ class UserService
$user->setModerator(true);
$user->setSensitive(false);
$this->save($user);
$this->entityManagerInterface->persist($user);
$this->entityManagerInterface->flush();
}
// Return user data
@ -99,6 +99,17 @@ class UserService
->find($userId);
}
public function findUserByAddress(string $address): ?User
{
return $this->entityManagerInterface
->getRepository(User::class)
->findOneBy(
[
'address' => $address
]
);
}
public function identicon(
mixed $value,
int $size = 16,