gpt4 book ai didi

Symfony 2 安全 : account activation

转载 作者:行者123 更新时间:2023-12-02 15:10:51 25 4
gpt4 key购买 nike

我正在使用 Symfony 2 安全系统。

当某些用户尝试登录时,我想另外检查用户字段“activated”是否为true。如果没有,则会出现错误消息:“您必须先激活您的帐户”。

如何实现此功能?

最佳答案

如果您使用Doctrine as user provider您可以实现AdvancedUserInterface 。该接口(interface)(定义见下文)提供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();
}

关于Symfony 2 安全 : account activation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8976237/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com