我的security.yml文件遇到一些麻烦:
# you can read more about security in the related section of the documentation
# http://symfony.com/doc/current/book/security.html
security:
# http://symfony.com/doc/current/book/security.html#encoding-the-user-s-password
encoders:
#Symfony\Component\Security\Core\User\User: plaintext
Login\Loginbundle\Entity\User: sha512
# http://symfony.com/doc/current/book/security.html#hierarchical-roles
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
# http://symfony.com/doc/current/book/security.html#where-do-users-come-from-user-providers
providers:
users:
entity: { class: LoginLoginBundle:User, property: username }
in_memory:
memory:
users:
user: { password: userpass, roles: [ 'ROLE_USER' ] }
admin: { password: adminpass, roles: [ 'ROLE_ADMIN' ] }
# the main part of the security, where you can set up firewalls
# for specific sections of your app
firewalls:
secured_area:
pattern: ^/
anonymous: ~
form_login:
provider: users
login_path: login
check_path: login_check
access_control:
- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
我有一个具有登录表单的网站。用户位于数据库中。
我可以使用用户名:user和密码:userpass登录,但是如何从数据库中使用它与用户一起使用?
我已经阅读了有关UserInterfaces的信息,并愚弄了它,但没有成功。
也许用户实体是有帮助的,在这里是:
<?php
namespace Login\LoginBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* User
*/
class User implements UserInterface, \Serializable
{
/**
* @var string
*/
private $username;
/**
* @var string
*/
private $email;
/**
* @var string
*/
private $password;
/**
* @var integer
*/
private $money;
/**
* @var integer
*/
private $userid;
/**
* @var \Login\LoginBundle\Entity\Team
*/
private $teamTeamid;
/**
* @inheritDoc
*/
public function getSalt()
{
// you *may* need a real salt depending on your encoder
// see section on salt below
return null;
}
/**
* @inheritDoc
*/
public function getRoles()
{
return array('ROLE_USER');
}
/**
* @inheritDoc
*/
public function eraseCredentials()
{
}
/**
* @see \Serializable::serialize()
*/
public function serialize()
{
return serialize(array(
$this->id,
$this->username,
$this->password,
// see section on salt below
// $this->salt,
));
}
/**
* @see \Serializable::unserialize()
*/
public function unserialize($serialized)
{
list (
$this->id,
$this->username,
$this->password,
// see section on salt below
// $this->salt
) = unserialize($serialized);
}
/**
* Set username
*
* @param string $username
* @return User
*/
public function setUsername($username)
{
$this->username = $username;
return $this;
}
/**
* Get username
*
* @return string
*/
public function getUsername()
{
return $this->username;
}
/**
* Set email
*
* @param string $email
* @return User
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* Get email
*
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* Set password
*
* @param string $password
* @return User
*/
public function setPassword($password)
{
$this->password = $password;
return $this;
}
/**
* Get password
*
* @return string
*/
public function getPassword()
{
return $this->password;
}
/**
* Set money
*
* @param integer $money
* @return User
*/
public function setMoney($money)
{
$this->money = $money;
return $this;
}
/**
* Get money
*
* @return integer
*/
public function getMoney()
{
return $this->money;
}
/**
* Get userid
*
* @return integer
*/
public function getUserid()
{
return $this->userid;
}
/**
* Set teamTeamid
*
* @param \Login\LoginBundle\Entity\Team $teamTeamid
* @return User
*/
public function setTeamTeamid(\Login\LoginBundle\Entity\Team $teamTeamid = null)
{
$this->teamTeamid = $teamTeamid;
return $this;
}
/**
* Get teamTeamid
*
* @return \Login\LoginBundle\Entity\Team
*/
public function getTeamTeamid()
{
return $this->teamTeamid;
}
}
编辑security.yml文件并访问数据库用户的正确方法是什么?
最佳答案
您是否正在尝试从数据库中用用户登录?
如果您尝试使用名称“ user”登录并传递“ userpass”,则此方法应该有效。
如果要与数据库中的用户一起使用,则应按以下方式编辑security.yml文件
providers:
user:
entity:
class: Login\LoginBundle\Entity\User
property: username
关于php - 什么是从数据库获取用户的适当的security.yml文件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26619011/