mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Catch groups that are in use.
This commit is contained in:
parent
fbf7578fb0
commit
6f8778d87f
@ -117,9 +117,24 @@ class UserEventHandler
|
|||||||
*/
|
*/
|
||||||
public function createGroupMembership(RegisteredUser $event): bool
|
public function createGroupMembership(RegisteredUser $event): bool
|
||||||
{
|
{
|
||||||
$user = $event->user;
|
$user = $event->user;
|
||||||
|
$groupExists = true;
|
||||||
|
$groupTitle = $user->email;
|
||||||
|
$index = 1;
|
||||||
|
|
||||||
// create a new group.
|
// create a new group.
|
||||||
$group = UserGroup::create(['title' => $user->email]);
|
while (true === $groupExists) {
|
||||||
|
$groupExists = UserGroup::where('title', $groupTitle)->count() > 0;
|
||||||
|
if(false === $groupExists) {
|
||||||
|
$group = UserGroup::create(['title' => $groupTitle]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$groupTitle = sprintf('%s-%d', $user->email, $index);
|
||||||
|
$index++;
|
||||||
|
if($index > 99) {
|
||||||
|
throw new FireflyException('Email address can no longer be used for registrations.');
|
||||||
|
}
|
||||||
|
}
|
||||||
$role = UserRole::where('title', UserRole::OWNER)->first();
|
$role = UserRole::where('title', UserRole::OWNER)->first();
|
||||||
if (null === $role) {
|
if (null === $role) {
|
||||||
throw new FireflyException('The user role is unexpectedly empty. Did you run all migrations?');
|
throw new FireflyException('The user role is unexpectedly empty. Did you run all migrations?');
|
||||||
|
Loading…
Reference in New Issue
Block a user