Users - Auto-login after registered?
Created 7 years ago by emergingdznsI have two clients that both want to have it so that when the user registers, they are automatically and immediately logged in. Is this possible at all with the system already or am I going to have to hijack the registration process and custom build it myself?
Hello,
edit app/streams.php > singletons with: '\Anomaly\UsersModule\User\Register\RegisterFormBuilder' => '\App\Extensions\User\RegisterFormBuilder', content like so:
<?php
namespace App\Extensions\User;
use Anomaly\UsersModule\User\Register\RegisterFormBuilder as BaseRegisterFormBuilder;
class RegisterFormBuilder extends BaseRegisterFormBuilder
{
protected $handler = RegisterFormHandler::class;
}
And the RegisterFormHandler.php:
<?php
namespace App\Extensions\User;
use Anomaly\CustomersModule\Customer\CustomerModel;
use Anomaly\Streams\Platform\Traits\Transmitter;
use Anomaly\UsersModule\User\Contract\UserInterface;
use Anomaly\UsersModule\User\Notification\UserHasRegistered;
use Anomaly\UsersModule\User\Register\Command\HandleEmailRegistration;
use Anomaly\UsersModule\User\Register\Command\HandleManualRegistration;
use Anomaly\UsersModule\User\UserActivator;
use Illuminate\Contracts\Config\Repository;
use Illuminate\Foundation\Bus\DispatchesJobs;
class RegisterFormHandler
{
use Transmitter;
use DispatchesJobs;
public function handle(Repository $config, RegisterFormBuilder $builder, UserActivator $activator)
{
if (! $builder->canSave()) {
return;
}
auth()->login($user);
}
}
// maybe you will need to copy of some login from Default Handler... but you should get the idea 😄
This was actually pushed and done this last weekend. Already like that now 😊
Thanks @ryanthompson. I just ran composer update
and tested this but it still didn't log the user in after registering. I've got the Activation Mode set to "Automatically activate the user after they register."
Is there something I'm doing wrong?
No let me double check that mode. Write up a quick issue cause Ima be AFK for a while.
Done. Thanks bro.
I can see that it was added to the event handler for the user activation, which is done when the user gets an email to activate. https://github.com/anomalylabs/users-module/blob/2.2/src/User/Register/Command/HandleActivateRequest.php#L44
But when the activation is automatic, it's not there: Unless I'm missing something, we need to add the UserAuthenticator to the function and then add the login line correct?
This one should have done it: https://github.com/anomalylabs/users-module/commit/2c46c5c428aa0bd531d9aff7bb2b4f7f8f28a2d8
Thank you sir!
This one should have done it: https://github.com/anomalylabs/users-module/commit/2c46c5c428aa0bd531d9aff7bb2b4f7f8f28a2d8