I am currently evaluating my options on changing the Bolt user provider and associated views to use some custom user/login services. So far, it seems i would have to modify some core elements of the Bolt source code, which obviously is a bad choice:
Users
service with custom class (Same interface)Backend
class as it is routing and rendering associated views itselfAny ideas on how to go at this with the smallest impact on the core source code?
Since the Bolt services architecture currently isnt as clean as needed to override certian core functionalities and since it's currently being rewritten for Symfony 5 Flex, since path is not really feasible right now.
BUT! Since a couple month, there is a new loginAsUser
method in Bolt's user service. You can now optionaly create your own user with Bolt's user reporistory and then login as this user.
Here are some sample code snipptes you can adapt and use inside an extension:
Note: This is incomplete sample code. Since modifying/bypassing the login system is riskay, be advised to fully read and understand Bolt's user and auth services. Also, this code is using internal methods that are not for use in extensions and might change. Do this at your own risk and use carefull error handling.
Create a user
/* @var Repository\UsersRepository $repository */
$repository = $this->app["storage"]->getRepository(Users::class);
$userEntity = new Users();
... set user attributes ...
$repository->save($userEntity);
Login as user
$event = new AccessControlEvent($request);
$this->login()->loginAsUser($user->getEmail(), $event);
$token = $this->session()->get('authentication');
$response = $this->setAuthenticationCookie($request, $response, (string) $token);