You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the proposed solution
You create yourself an account. You fill in a big form. Now you get redirected to your email to confirm it. You close the app, go to your email, find the mail, open it, click the link, and you are redirected to a login form with a flash message that you can now safely login.
But you have to input again the username, the password. Cognitive load++.
Same for reset password: you go to the website, it asks you to login. You input your email and a password you remember, it's wrong. Try a couple of variants, end up with the same error - wrong password.
You decide to reset it. Then you go to reset password. Enter your email, sends you back to login with a flash message to check your email. Again: You close the app, go to your email, find the mail, open it, click the link, and you are redirected to a form where you can set the new password. You write it, twice and hit submit.
Back to login, with a flash message. Now you have to insert the username, again, and then the new password. Again. Cognitive load++. Rage++.
Solution
<?php
namespace App\EventSubscriber;
use Sylius\Bundle\UserBundle\Security\UserLoginInterface;
use Sylius\Bundle\UserBundle\UserEvents;
use Sylius\Component\User\Repository\UserRepositoryInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
use Webmozart\Assert\Assert;
class AutologinSubscriber implements EventSubscriberInterface
{
/**
* @var \App\Repository\UserRepository
*/
private $userRepository;
/**
* @var \Sylius\Bundle\UserBundle\Security\UserLoginInterface
*/
private $userLogin;
/**
* @var string
*/
private $firewallContextName;
public function __construct(
UserRepositoryInterface $userRepository,
UserLoginInterface $userLogin,
string $firewallContextName
) {
$this->userRepository = $userRepository;
$this->userLogin = $userLogin;
$this->firewallContextName = $firewallContextName;
}
/**
* @return array|string[]
*/
public static function getSubscribedEvents(): array
{
return [
UserEvents::POST_PASSWORD_RESET => 'autoLogin',
];
}
public function autoLogin(GenericEvent $event)
{
$user = $event->getSubject();
Assert::notNull($user);
$user->setEnabled(true);
$this->userRepository->add($user);
$this->userLogin->login($user, $this->firewallContextName);
}
}
The solution above is a PoC I implemented for my needs. It works for me. If you are interested, I can submit it in a PR to be included in Monofony by default and, maybe, why not, in Sylius as well.
The text was updated successfully, but these errors were encountered:
Describe the proposed solution
You create yourself an account. You fill in a big form. Now you get redirected to your email to confirm it. You close the app, go to your email, find the mail, open it, click the link, and you are redirected to a login form with a flash message that you can now safely login.
But you have to input again the username, the password. Cognitive load++.
Same for reset password: you go to the website, it asks you to login. You input your email and a password you remember, it's wrong. Try a couple of variants, end up with the same error - wrong password.
You decide to reset it. Then you go to reset password. Enter your email, sends you back to login with a flash message to check your email. Again: You close the app, go to your email, find the mail, open it, click the link, and you are redirected to a form where you can set the new password. You write it, twice and hit submit.
Back to login, with a flash message. Now you have to insert the username, again, and then the new password. Again. Cognitive load++. Rage++.
Solution
The solution above is a PoC I implemented for my needs. It works for me. If you are interested, I can submit it in a PR to be included in Monofony by default and, maybe, why not, in Sylius as well.
The text was updated successfully, but these errors were encountered: