Skip to content

Commit 84580f9

Browse files
committed
Admin: User: add user_auth_source registry for user when user added to URL from dashboard - refs BT23449
1 parent ae88eeb commit 84580f9

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

src/CoreBundle/Controller/SessionController.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use BuyCoursesPlugin;
1010
use Chamilo\CoreBundle\Component\Essence\SafeEssenceHttpClient;
1111
use Chamilo\CoreBundle\Entity\AccessUrlRelUser;
12+
use Chamilo\CoreBundle\Entity\UserAuthSource;
1213
use Chamilo\CoreBundle\Entity\ExtraField;
1314
use Chamilo\CoreBundle\Entity\SequenceResource;
1415
use Chamilo\CoreBundle\Entity\Session;
@@ -318,6 +319,23 @@ public function sendCourseNotification(
318319
$rel->setUrl($accessUrl);
319320

320321
$em->persist($rel);
322+
323+
// Copy the user's first auth source to the new URL so they can log in on it,
324+
// mirroring the behaviour of access_url_edit_users_to_url.php.
325+
$alreadyHasAuthSource = $user->getAuthSourcesByUrl($accessUrl)->count() > 0;
326+
if (!$alreadyHasAuthSource) {
327+
$firstAuthSource = $user->getAuthSources()->first();
328+
$authentication = $firstAuthSource
329+
? $firstAuthSource->getAuthentication()
330+
: UserAuthSource::PLATFORM;
331+
332+
$userAuthSource = new UserAuthSource();
333+
$userAuthSource->setUser($user);
334+
$userAuthSource->setUrl($accessUrl);
335+
$userAuthSource->setAuthentication($authentication);
336+
337+
$em->persist($userAuthSource);
338+
}
321339
}
322340
}
323341

0 commit comments

Comments
 (0)