Witam
Zaczynam się uczyć Symwony2 i mam problem z autoryzacją użytkowników z bazy danych. Gdy użytkownicy są zapisani w pliku security.yml logowanie działa. Natomiast gdy przenoszę użytkowników do bazy danych i próbuje się zalogować, dostaję:
An exception occurred while executing 'SELECT t0.id AS id1, t0.username AS username2, t0.password AS password3, t0.email AS email4, t0.salt AS salt5 FROM user t0 WHERE t0.username = ? LIMIT 1' with params ["admin"]: SQLSTATE[42703]: Undefined column: 7 BŁĄD: kolumna t0.id nie istnieje LINE 1: SELECT t0.id AS id1, t0.username AS username2, t0.password A... ^
Poniżej kod pliku security.yml
Kod
security:
encoders:
#Symfony\Component\Security\Core\User\User:
Madan\AdminBundle\Entity\User:
algorithm: md5
iterations: 1
encode_as_base64: false
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
providers:
administrators:
entity: { class: Madan\AdminBundle\Entity\User, property: username }
in_memory:
memory:
users:
user: { password: 63e780c3f321d13109c71bf81805476e, roles: [ 'ROLE_USER' ] }
# userpass
admin: { password: 25e4ee4e9229397b6b17776bfceaf8e7, roles: [ 'ROLE_ADMIN' ] }
# adminpass
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
login:
pattern: ^/demo/secured/login$
security: false
secured_area:
pattern: ^/
form_login: ~
# check_path: login
# login_path: login_check
logout:
path: /logout
target: /login
anonymous: ~
http_basic:
realm: "Secured Demo Area"
access_control:
- { path: ^/admin, roles: ROLE_ADMIN }
#- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https }
routing:
Kod
login:
pattern: /login
defaults: { _controller: MadanAdminBundle:Security:login }
login_check:
pattern: /login_check
logout:
pattern: /logout
admin:
pattern: /admin
defaults: { _controller: MadanAdminBundle:Security:index }
Entity\User.php
<?php
namespace Madan\AdminBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Security\Core\User\UserInterface;
//use Symfony\Component\Security\Core\User\AdvancedUserInterface;
use Doctrine\ORM\Mapping as ORM;
/**
* User
*
* @ORM\Table(name="user")
* @ORM\Entity
*/
class User implements UserInterface
{
/**
* @ORM\ManyToMany(targetEntity="Role", inversedBy="users")
*
*/
private $roles;
public function __construct()
{
$this->roles = new ArrayCollection();
}
/**
* Returns an array of roles granted to the user
*
* @return type Role[]
*/
public function getRoles()
{
return $this->roles->toArray();
}
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="username", type="string", length=255)
*/
protected $username;
/**
* @var string
*
* @ORM\Column(name="password", type="string", length=50)
*/
private $password;
/**
* @var string
*
* @ORM\Column(name="email", type="string", length=127, unique=true)
*/
private $email;
/**
* @var string
*
* @ORM\Column(type="string", length=50)
*/
private $salt;
/**
* Returns the username used to authenticate the user.
*
* @return string
*/
public function getUsername()
{
return $this->username;
}
/**
* Returns the password used to authenticate the user.
*
* @return string
*/
public function getPassword()
{
return $this->password;
}
/**
* Returns the salt that was originally used to encode the password.
*
* @return string|null
*/
public function getSalt()
{
return $this->salt;
}
/**
* Removes sensitive data from the user.
*
*
*/
public function eraseCredentials()
{
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set username
*
* @param string $username
* @return User
*/
public function setUsername($username)
{
$this->username = $username;
return $this;
}
/**
* Set password
*
* @param string $password
* @return User
*/
public function setPassword($password)
{
$this->password = $password;
return $this;
}
/**
* 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 salt
*
* @param string $salt
* @return User
*/
public function setSalt($salt = null)
{
$this->salt = $salt;
return $this;
}
/**
* Add roles
*
* @param \Madan\AdminBundle\Entity\Role $roles
* @return User
*/
public function addRole(\Madan\AdminBundle\Entity\Role $roles)
{
$this->roles[] = $roles;
return $this;
}
/**
* Remove roles
*
* @param \Madan\AdminBundle\Entity\Role $roles
*/
public function removeRole(\Madan\AdminBundle\Entity\Role $roles)
{
$this->roles->removeElement($roles);
}
}
Entity\Role.php
<?php
namespace Madan\AdminBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Security\Core\Role\RoleInterface;
use Doctrine\ORM\Mapping as ORM;
/**
* User
*
* @ORM\Table(name="role")
* @ORM\Entity
*/
class Role implements RoleInterface
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=100)
*/
protected $name;
/**
* @var string
*
* @ORM\Column(name="role", type="string", length=100, unique=true)
*/
private $role;
/**
* @ORM\ManyToMany(targetEntity="User", mappedBy="roles")
*/
private $users;
public function __construct()
{
$this->users = new ArrayCollection();
}
/**
* @see RoleInterface
*/
public function getRole()
{
return $this->role;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
* @return Role
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set role
*
* @param string $role
* @return Role
*/
public function setRole($role)
{
$this->role = $role;
return $this;
}
/**
* Add users
*
* @param \Madan\AdminBundle\Entity\User $users
* @return Role
*/
public function addUser(\Madan\AdminBundle\Entity\User $users)
{
$this->users[] = $users;
return $this;
}
/**
* Remove users
*
* @param \Madan\AdminBundle\Entity\User $users
*/
public function removeUser(\Madan\AdminBundle\Entity\User $users)
{
$this->users->removeElement($users);
}
/**
* Get users
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getUsers()
{
return $this->users;
}
}
Pomożecie?