小编Stu*_*ent的帖子

Symfony 内存管理用户,具有电子邮件身份验证

我正在使用扩展 AbstractFormLoginAuthenticator 的类来验证我的应用程序。登录表单包含电子邮件和密码字段。我需要在内存中有一个硬编码的用户,并且能够通过该登录表单登录。我如何配置安全文件才能使其工作?

class LoginFormAuthenticator extends AbstractFormLoginAuthenticator

private $userRepository;
private $router;
private $passwordEncoder;

public function __construct(UserRepository $userRepository, RouterInterface $router, UserPasswordEncoderInterface $passwordEncoder)
{
    $this->userRepository = $userRepository;
    $this->router = $router;
    $this->passwordEncoder = $passwordEncoder;

}

public function supports(Request $request)
{
    return $request->attributes->get('_route') === 'app_login'
        && $request->isMethod('POST');
}

public function getCredentials(Request $request)
{
    $credentials = [
        'email' => $request->request->get('login_form')['email'],
        'password' => $request->request->get('login_form')['plainPassword'],
    ];

    $request->getSession()->set(
        Security::LAST_USERNAME,
        $credentials['email']
    );

    return $credentials;
}

public function getUser($credentials, UserProviderInterface $userProvider)
{
    return $this->userRepository->findOneBy(['email' => $credentials['email']]);
}

public function checkCredentials($credentials, …
Run Code Online (Sandbox Code Playgroud)

php authentication in-memory symfony

5
推荐指数
1
解决办法
2025
查看次数

标签 统计

authentication ×1

in-memory ×1

php ×1

symfony ×1