shield-wall/simple-authenticator

简单的symfony身份验证器

v0.3.3 2022-08-26 15:38 UTC

This package is auto-updated.

Last update: 2024-09-26 20:30:02 UTC


README

这是一个简单的symfony身份验证器,让您只需使用电子邮件即可登录。

安装

composer req shield-w4ll/simple-authenticator

注意 我们强烈建议只在 开发环境 中使用此包。

配置

#config/packages/shield_wall.yaml
when@dev:
  simple_authenticator:
    route:
      redirect_success: 'profile_edit'
      redirect_failure: 'app_login'

  security:
    firewalls:
      main:
        custom_authenticators:
          - ShieldWall\SimpleAuthenticator\Security\EmailAuthenticator
#config/routes/shield_wall.yaml
simple_authenticator_login:
  prefix: ^/
  path: /simple_authenticator/login
#config/service.yaml
ShieldWall\SimpleAuthenticator\Security\EmailAuthenticator:
        arguments:
            - '@Symfony\Component\Routing\Generator\UrlGeneratorInterface'
            - '@App\Repository\UserRepository'
            - '%shield_wall.simple_authenticator.route.redirect_success%'
            - '%shield_wall.simple_authenticator.route.redirect_failure%'
//YourController.php
public function yourAction()
{
        $simpleAuthenticatorForm = $this->createForm(SimpleAuthenticatorType::class, null, [
            'action' => $this->generateUrl('simple_authenticator_login'),
        ]);
        $simpleAuthenticatorFromView = $simpleAuthenticatorForm->createView();

        return $this->render('your_template.html.twig', [
            'simpleAuthenticatorFrom' => $simpleAuthenticatorFromView,
        ]);
}

//your_file.html.twig
{{ form(simpleAuthenticatorFrom) }}

仓库

//src/Repository/UserRepository.php
class UserRepository extends ServiceEntityRepository implements EmailRepositoryInterface
{
    public function findOneByEmail(string $email): UserInterface
    {
        return $this->findOneBy(['email' => $email]);
    }
}

待办事项

  • 需要找到一种方法从控制器 simple_authenticator_login 获取路由名称
  • 导入路由作为资源
  • 服务应该自动声明。