我正在使用Symfony 2安全系统.
当某些用户尝试登录时,我还要检查用户的字段"已激活"是否为真.如果没有,则会显示错误消息:"您必须先激活您的帐户".
我该如何实现此功能?
小智 14
如果您使用Doctrine作为用户提供程序,则可以实现AdvancedUserInterface.该接口(下面可见的定义)提供了isEnabled()与帐户激活状态方法相同的方法.如果此方法返回false,则用户将出现一条错误消息,例如您尝试登录时未启用该帐户.
我用它来提供订阅的电子邮件验证.
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Security\Core\User;
/**
* AdvancedUserInterface adds status flags to a regular account.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
interface AdvancedUserInterface extends UserInterface
{
/**
* Checks whether the user's account has expired.
*
* @return Boolean true if the user's account is non expired, false otherwise
*/
function isAccountNonExpired();
/**
* Checks whether the user is locked.
*
* @return Boolean true if the user is not locked, false otherwise
*/
function isAccountNonLocked();
/**
* Checks whether the user's credentials (password) has expired.
*
* @return Boolean true if the user's credentials are non expired, false otherwise
*/
function isCredentialsNonExpired();
/**
* Checks whether the user is enabled.
*
* @return Boolean true if the user is enabled, false otherwise
*/
function isEnabled();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5024 次 |
| 最近记录: |