- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 FOSUserBundle,但我想将旧数据库的角色字段列名称重命名为 user_roles,
引用
https://github.com/FriendsOfSymfony/FOSUserBundle/issues/338
和
我试图通过再次映射所有字段,用我的 AcmeDemoBundle:User 实体覆盖现有的 FOS\UserBundle\Model\User 。
这是我的类(class),
请注意,我直接从“FOS\UserBundle\Model\User”扩展实体
namespace Acme\SecurityBundle\Entity;
use FOS\UserBundle\Model\User as BaseUser;
use Acme\CommonBundle\Util\Url as Url;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @ORM\Entity
* @ORM\Table(name="users")
* @ORM\Entity(repositoryClass="Acme\SecurityBundle\Entity\UserRepository")
*/
Class User extends BaseUser
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string
* @ORM\Column(name="username", type="string", length=255)
*/
protected $username;
/**
* @var string
* @ORM\Column(name="username_canonical", type="string", length=255, unique=true)
*/
protected $usernameCanonical;
/**
* @var string
* @ORM\Column(name="email", type="string", length=255)
*/
protected $email;
/**
* @var string
* @ORM\Column(name="email_canonical", type="string", length=255, unique=true)
*/
protected $emailCanonical;
/**
* @var boolean
* @ORM\Column(name="enabled", type="boolean")
*/
protected $enabled;
/**
* The salt to use for hashing
*
* @var string
* @ORM\Column(name="salt", type="string")
*/
protected $salt;
/**
* Encrypted password. Must be persisted.
*
* @var string
* @ORM\Column(name="password", type="string")
*/
protected $password;
/**
* Plain password. Used for model validation. Must not be persisted.
*
* @var string
*/
protected $plainPassword;
/**
* @var \DateTime
* @ORM\Column(name="last_login", type="datetime", nullable=true)
*/
protected $lastLogin;
/**
* Random string sent to the user email address in order to verify it
*
* @var string
* @ORM\Column(name="confirmation_token", type="string", nullable=true)
*/
protected $confirmationToken;
/**
* @var \DateTime
* @ORM\Column(name="password_requested_at", type="datetime", nullable=true)
*/
protected $passwordRequestedAt;
/**
* @var Collection
*/
protected $groups;
/**
* @var boolean
* @ORM\Column(name="locked", type="boolean")
*/
protected $locked;
/**
* @var boolean
* @ORM\Column(name="expired", type="boolean")
*/
protected $expired;
/**
* @var \DateTime
* @ORM\Column(name="expires_at", type="datetime", nullable=true)
*/
protected $expiresAt;
/**
* @var array
* @ORM\Column(name="fos_roles", type="array", nullable=true)
*/
protected $roles;
/**
* @var boolean
* @ORM\Column(name="credentials_expired", type="boolean")
*/
protected $credentialsExpired;
/**
* @var \DateTime
* @ORM\Column(name="credentials_expire_at", type="datetime", nullable=true)
*/
protected $credentialsExpireAt;
public function __construct()
{
parent::__construct();
$this->salt = base_convert(sha1(uniqid(mt_rand(), true)), 16, 36);
$this->enabled = false;
$this->locked = false;
$this->expired = false;
$this->roles = array();
$this->credentialsExpired = false;
//$this->setEmailHash();
}
public function addRole($role)
{
$role = strtoupper($role);
if ($role === static::ROLE_DEFAULT) {
return $this;
}
if (!in_array($role, $this->roles, true)) {
$this->roles[] = $role;
}
return $this;
}
/**
* Serializes the user.
*
* The serialized data have to contain the fields used by the equals method and the username.
*
* @return string
*/
public function serialize()
{
return serialize(array(
$this->password,
$this->salt,
$this->usernameCanonical,
$this->username,
$this->expired,
$this->locked,
$this->credentialsExpired,
$this->enabled,
$this->id,
));
}
/**
* Unserializes the user.
*
* @param string $serialized
*/
public function unserialize($serialized)
{
$data = unserialize($serialized);
// add a few extra elements in the array to ensure that we have enough keys when unserializing
// older data which does not include all properties.
$data = array_merge($data, array_fill(0, 2, null));
list(
$this->password,
$this->salt,
$this->usernameCanonical,
$this->username,
$this->expired,
$this->locked,
$this->credentialsExpired,
$this->enabled,
$this->id
) = $data;
}
/**
* Removes sensitive data from the user.
*/
public function eraseCredentials()
{
$this->plainPassword = null;
}
/**
* Returns the user unique id.
*
* @return mixed
*/
public function getId()
{
return $this->id;
}
public function getUsername()
{
return $this->username;
}
public function getUsernameCanonical()
{
return $this->usernameCanonical;
}
public function getSalt()
{
return $this->salt;
}
public function getEmail()
{
return $this->email;
}
public function getEmailCanonical()
{
return $this->emailCanonical;
}
/**
* Gets the encrypted password.
*
* @return string
*/
public function getPassword()
{
return $this->password;
}
public function getPlainPassword()
{
return $this->plainPassword;
}
/**
* Gets the last login time.
*
* @return \DateTime
*/
public function getLastLogin()
{
return $this->lastLogin;
}
public function getConfirmationToken()
{
return $this->confirmationToken;
}
/**
* Returns the user roles
*
* @return array The roles
*/
public function getRoles()
{
$roles = $this->roles;
foreach ($this->getGroups() as $group) {
$roles = array_merge($roles, $group->getRoles());
}
// we need to make sure to have at least one role
$roles[] = static::ROLE_DEFAULT;
return array_unique($roles);
}
/**
* Never use this to check if this user has access to anything!
*
* Use the SecurityContext, or an implementation of AccessDecisionManager
* instead, e.g.
*
* $securityContext->isGranted('ROLE_USER');
*
* @param string $role
*
* @return boolean
*/
public function hasRole($role)
{
return in_array(strtoupper($role), $this->getRoles(), true);
}
public function isAccountNonExpired()
{
if (true === $this->expired) {
return false;
}
if (null !== $this->expiresAt && $this->expiresAt->getTimestamp() < time()) {
return false;
}
return true;
}
public function isAccountNonLocked()
{
return !$this->locked;
}
public function isCredentialsNonExpired()
{
if (true === $this->credentialsExpired) {
return false;
}
if (null !== $this->credentialsExpireAt && $this->credentialsExpireAt->getTimestamp() < time()) {
return false;
}
return true;
}
public function isCredentialsExpired()
{
return !$this->isCredentialsNonExpired();
}
public function isEnabled()
{
return $this->enabled;
}
public function isExpired()
{
return !$this->isAccountNonExpired();
}
public function isLocked()
{
return !$this->isAccountNonLocked();
}
public function isSuperAdmin()
{
return $this->hasRole(static::ROLE_SUPER_ADMIN);
}
public function isUser(\FOS\UserBundle\Model\UserInterface $user = null)
{
return null !== $user && $this->getId() === $user->getId();
}
public function removeRole($role)
{
if (false !== $key = array_search(strtoupper($role), $this->roles, true)) {
unset($this->roles[$key]);
$this->roles = array_values($this->roles);
}
return $this;
}
public function setUsername($username)
{
$this->username = $username;
return $this;
}
public function setUsernameCanonical($usernameCanonical)
{
$this->usernameCanonical = $usernameCanonical;
return $this;
}
/**
* @param \DateTime $date
*
* @return User
*/
public function setCredentialsExpireAt(\DateTime $date = null)
{
$this->credentialsExpireAt = $date;
return $this;
}
/**
* @param boolean $boolean
*
* @return User
*/
public function setCredentialsExpired($boolean)
{
$this->credentialsExpired = $boolean;
return $this;
}
public function setEmail($email)
{
$this->email = $email;
return $this;
}
public function setEmailCanonical($emailCanonical)
{
$this->emailCanonical = $emailCanonical;
return $this;
}
public function setEnabled($boolean)
{
$this->enabled = (Boolean) $boolean;
return $this;
}
/**
* Sets this user to expired.
*
* @param Boolean $boolean
*
* @return User
*/
public function setExpired($boolean)
{
$this->expired = (Boolean) $boolean;
return $this;
}
/**
* @param \DateTime $date
*
* @return User
*/
public function setExpiresAt(\DateTime $date = null)
{
$this->expiresAt = $date;
return $this;
}
public function setPassword($password)
{
$this->password = $password;
return $this;
}
public function setSuperAdmin($boolean)
{
if (true === $boolean) {
$this->addRole(static::ROLE_SUPER_ADMIN);
} else {
$this->removeRole(static::ROLE_SUPER_ADMIN);
}
return $this;
}
public function setPlainPassword($password)
{
$this->plainPassword = $password;
return $this;
}
public function setLastLogin(\DateTime $time = null)
{
$this->lastLogin = $time;
return $this;
}
public function setLocked($boolean)
{
$this->locked = $boolean;
return $this;
}
public function setConfirmationToken($confirmationToken)
{
$this->confirmationToken = $confirmationToken;
return $this;
}
public function setPasswordRequestedAt(\DateTime $date = null)
{
$this->passwordRequestedAt = $date;
return $this;
}
/**
* Gets the timestamp that the user requested a password reset.
*
* @return null|\DateTime
*/
public function getPasswordRequestedAt()
{
return $this->passwordRequestedAt;
}
public function isPasswordRequestNonExpired($ttl)
{
return $this->getPasswordRequestedAt() instanceof \DateTime &&
$this->getPasswordRequestedAt()->getTimestamp() + $ttl > time();
}
public function setRoles(array $roles)
{
$this->roles = array();
foreach ($roles as $role) {
$this->addRole($role);
}
return $this;
}
/**
* Gets the groups granted to the user.
*
* @return Collection
*/
public function getGroups()
{
return $this->groups ? : $this->groups = new ArrayCollection();
}
public function getGroupNames()
{
$names = array();
foreach ($this->getGroups() as $group) {
$names[] = $group->getName();
}
return $names;
}
public function hasGroup($name)
{
return in_array($name, $this->getGroupNames());
}
public function addGroup(\FOS\UserBundle\Model\GroupInterface $group)
{
if (!$this->getGroups()->contains($group)) {
$this->getGroups()->add($group);
}
return $this;
}
public function removeGroup(\FOS\UserBundle\Model\GroupInterface $group)
{
if ($this->getGroups()->contains($group)) {
$this->getGroups()->removeElement($group);
}
return $this;
}
public function __toString()
{
return (string) $this->getUsername();
}
}
如果我删除扩展 BaseUser (FOS\UserBundle\Model\User),它会给出错误“用户提供程序必须返回 UserInterface 对象。”
然后我尝试添加“implements UserInterface, GroupableInterface”,但它仍然给出“用户“Acme\SecurityBundle\Entity\User”没有用户提供程序。
最佳答案
https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Model/User.php
属性username
已在FOS\UserBundle\Model\User
中定义。它的元数据位于其资源配置中。因此,您基本上将该列定义了两次。
关于php - Doctrine\ORM\Mapping\MappingException 实体上列 'username' 的重复定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20683191/
这是我第一次使用 php 学习 session ,我正在尽可能地制作最简单的登录页面。 因此,只要用户永远不会关闭网页,理论上这是否可以让任何给定的字符串 $username 始终存储在 $_SESS
我已在Windows 10中更改了用户名,现在我需要自动将更改后的用户名作为Powershell脚本获取 但是我尝试的所有操作都返回了我的旧用户名,除了一些与AD相关的查询。 例子: $env
我的 html 页面上有这个链接,可以在特定用户上打开 Instagram 应用程序: Link to Instagram Profile 我一直在寻找自动运行 url 'instagram://us
此代码似乎不适用于 Windows 7/8? Public Function UserName() UserName = Environ$("UserName") End Function 有
Excel宏:如何编写此“如果用户名[示例代码:Environ(“用户名”)]等于此范围内的值之一[示例:我从工作簿创建的范围:范围(“Authorized_Users”)]然后。 ..“谢谢! 最佳
PowerShell的$env:username有什么区别和 [environment]::username和 为什么他们可能会返回不同的用户 ? (我知道还有其他方法可以获取当前用户) 一些背景:
与大多数网站的工作方式相同,我将“UsErNaMe”存储在数据库中,但让用户使用“用户名”登录。 这是一个相当明显且必要的功能,很多人似乎都问过它,但我不断遇到的解决方案似乎与 Devise 自己的文
在终端中输入 psql 后,用户通常会以 username=# 的形式出现在控制台中。但后来我注意到它说username-#,其中等号被连字符替换,但它似乎仍然以相同的方式执行。 我知道这是一个简单的
在终端中输入 psql 后,用户通常会以 username=# 的形式出现在控制台中。但后来我注意到它说username-#,其中等号被连字符替换,但它似乎仍然以相同的方式执行。 我知道这是一个简单的
这个问题已经有答案了: Reference - What does this error mean in PHP? (38 个回答) 已关闭 5 年前。 我是 PHP 的初学者,我一整天都在尝试修复这
我正在尝试从表 users 中取出 url 并将其插入到表 images 的 url> 来自当前登录的用户。此代码无法在 images 表中插入 url。 $uploaduser = $_SESSIO
我很难让 WebDriver 在 PayPal 网站的用户名框中键入内容。我已经尝试过 xpath、id、css,但这里一定有我遗漏的东西,因为它应该很简单。文本框是代码最底部的 input = "e
我正在使用 iOs 社交框架从某个用户那里检索 facebook 提要。为此,在进行身份验证后,我将执行以下操作: NSURL *requestURL = [NSURL URLWithString:@
我有一个 WCF web 服务托管在 IIS 中。这是相同的配置: 当我尝试在我的 WinForms 客户端中使用此特定服务(作为服务引用添加时)时,它会抛出此异常: The username is
def login_page(request): form = LoginForm(request.POST or None) context = { "form":
更新我想我很快就假设了 voodoo jquery 之谜。我注意到我确实使用了两次“用户名”ID,这就是问题所在。第二个用户名 id 是通过从 php 注入(inject)页面的 html 代码添加到
已结束。此问题正在寻求书籍、工具、软件库等的推荐。它不满足Stack Overflow guidelines 。目前不接受答案。 我们不允许提出寻求书籍、工具、软件库等推荐的问题。您可以编辑问题,以便
到目前为止,下面显示的第一个 $sql = “INSERT INTO MySQLtable 语句将插入一个包含静态文本的新行 VALUES ('statictext', 'statictext') 。
我几乎完成了我的大型项目的开发,但是如果我能做到而不是让用户配置文件页面位于:http://example.com/profile/username/USERNAME<,我会很高兴 (我目前正在使用
(注意我是 Scala 的新手,仍然在为集合操作的最常见操作而苦苦挣扎。) 我想将 List[Task] 转换为 Map。以下是一些详细信息: // assignee may be null case
我是一名优秀的程序员,十分优秀!