使用第三个参数的自定义登录 [英] Custom Login using a Third Parameter

查看:31
本文介绍了使用第三个参数的自定义登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 Symfony2 开发一个相对简单的登录系统.

I am working on a relatively simple login system for Symfony2.

我已经掌握了基本知识并且工作得很好.

I have the basics down and working just fine.

让这有点特别的是我需要一种方法来提供第三个价值(生态系统价值).我的数据库中的用户名本身并不是唯一的,而是与生态系统价值形成唯一的配对.

What makes this a bit special is I need a way to provide a third value (an ecosystem value). The user names in my database are not unique on their own, but make unique pairs with an ecosystem value.

生态系统价值由他们登录的表单提供.

The ecosystem value is provided by the form that they log in from.

如何在登录时考虑使用这个生态系统价值?

How can I use this ecosystem value be taken into consideration when performing a login?

推荐答案

查看 如何从数据库(实体提供程序)加载安全用户 - 特别是关于 使用自定义实体提供程序验证某人.

Take a look at the Cookbook tutorial on How to load Security Users from the Database (the Entity Provider) - specifically the part about Authenticating Someone with a Custom Entity Provider.

这部分解释了如何更改/创建 UserProviderInterface 以允许通过电子邮件地址或用户名登录.显然,这不是您想要的,但是 - 修改代码以查询/验证您的第三个登录参数应该相对简单.

This part explains how to alter/create a UserProviderInterface to allow logging in via an e-mail address or username. Obviously, this isn't what you want, but - it should be relatively trivial to modify the code to also query/validate against your 3rd login parameter.

理想情况下,您可能希望创建自己的 UserProvider,幸运的是,有一个专门用于此的食谱教程:如何创建自定义用户提供程序.

Ideally, you will probabaly want to create your own UserProvider and luckily, there is a cookbook tutorial just for that: How to create a custom User Provider.

更新:要处理第三个登录选项并将其传递给您的自定义提供程序(在上面创建),您还需要创建一个自定义身份验证提供程序.看看(又一个)关于如何创建自定义身份验证提供程序.本文专门用于处理用于身份验证的额外请求标头参数,但使用此示例,您应该能够将请求标头换成请求 POST 值.

Update: To have the 3rd login option handled and passed to your custom providers (created above), you will also need to create a custom Authentication Provider. Take a look at (yet another) cookbook article on How to create a custom Authentication Provider. This article is tailored for handling extra request header parameters for authentication, but using this example you should be able to swap out request headers for request POST values.

使用说明书文章了解使用 Symfony2 进行身份验证的工作原理,但使用(并扩展)Symfony2 的用户名/密码功能并仅包含您的第三个参数.要查看的一些类:

Use the cookbook article to get an understanding of how authentication with Symfony2 works, but use (and extend) the username/password functionality of Symfony2 and just include your 3rd parameter. Some classes to look at:

这篇关于使用第三个参数的自定义登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆