简体   繁体   English

Symfony 3, Guard & Handlers

[英]Symfony 3, Guard & Handlers

Since the new component Guard from Symfony I've started playing a little with it to learn it better and see what things it changes.自从 Symfony 的新组件 Guard 开始,我就开始尝试使用它来更好地学习它并查看它发生了什么变化。 I've read the documentation from sf website to see what it brings and changes and i was wondering based on this example: Let's say we create a login attempt counter that at some point will disable the user until password reset.我已经阅读了 sf 网站上的文档,看看它带来了什么和改变,我想基于这个例子:假设我们创建了一个登录尝试计数器,在某个时候会禁用用户,直到密码重置。 Of course for this we would use the login failure handler.当然,为此我们将使用登录失败处理程序。 But since guard should make everything easier i was wondering if we still need that handler or we just put a bit of logic in the onAuthenticationFailure / onAuthenticationSuccess / checkCredentials to do certain tasks like saving some info into database about the failed login etc and how much code should go in there.但是由于守卫应该让一切变得更容易我想知道我们是否仍然需要该处理程序,或者我们只是在 onAuthenticationFailure / onAuthenticationSuccess / checkCredentials 中添加一些逻辑来执行某些任务,例如将一些有关登录失败的信息保存到数据库中以及多少代码应该进去。

The new Guard is aimed to ease the implementation of custom authentication patterns such as yours.新的Guard旨在简化自定义身份验证模式的实现,例如您的。

It is likely to be enough for most of the case even complex ones.对于大多数情况,即使是复杂的情况,这可能就足够了。

However, try to extract your custom processing, logging, etc. from your Guard and inject them to improve the maintainability of it.但是,尝试从您的Guard提取您的自定义处理、日志记录等并注入它们以提高它的可维护性。

Take a close look to GuardAuthenticatorInterface.php to find where and when in the process you have to set up your requirements.仔细查看GuardAuthenticatorInterface.php以了解您必须在流程中的何时何地设置您的要求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM