Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Symfony 2 authentication with Entity error
- security:
- firewalls:
- secured_area:
- pattern: ^/
- anonymous: ~
- form_login: true
- logout:
- path: /logout
- target: /login
- # access_control:
- # - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- # - { path: ^/admin, roles: ROLE_ADMIN }
- providers:
- in_memory:
- users:
- admin: { password: admin, roles: 'ROLE_ADMIN' }
- main:
- entity: { class: MyAppSafeDrivingBundle:Client, property: username }
- encoders:
- SymfonyComponentSecurityCoreUserUser: plaintext
- MyAppSafeDrivingBundleEntityClient: plaintext
- security:
- firewalls:
- secured_area:
- pattern: ^/
- anonymous: ~
- form_login: true
- logout:
- path: /logout
- target: /login
- access_control:
- - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- - { path: ^/admin, roles: ROLE_ADMIN }
- providers:
- in_memory:
- users:
- admin: { password: admin, roles: 'ROLE_ADMIN' }
- client: { password: client, roles: 'ROLE_CLIENT' }
- formateur: { password: formateur, roles: 'ROLE_FORMATEUR' }
- agence: { password: agence, roles: 'ROLE_AGENCE' }
- main:
- entity: { class: MyAppSafeDrivingBundle:Client, property: username }
- encoders:
- SymfonyComponentSecurityCoreUserUser: plaintext
- MyAppSafeDrivingBundleEntityClient: plaintext
- <?php
- namespace MyAppSafeDrivingBundleEntity;
- use DoctrineORMMapping as ORM;
- use SymfonyComponentValidatorConstraints as Assert;
- use SymfonyComponentSecurityCoreUserUserInterface;
- /**
- * @ORMEntity(repositoryClass="MyAppSafeDrivingBundleRepositoryUserRepository")
- */
- class Client implements UserInterface
- {
- /**
- * @ORMGeneratedValue
- * @ORMId
- * @ORMColumn(type="integer")
- */
- protected $id;
- /**
- * @ORMColumn(type="string", length="32", unique=true)
- */
- protected $username;
- /**
- * @ORMColumn(type="string", length="255")
- */
- protected $password;
- /**
- * @ORMColumn(type="string", length="255")
- * @AssertNotBlank()
- */
- private $mail;
- /**
- * @ORMColumn(type="string",length="255")
- * @AssertNotBlank()
- * @AssertMinLength(3)
- */
- private $nom;
- /**
- * @ORMColumn(type="string",length="255")
- * @AssertNotBlank()
- * @AssertMinLength(3)
- */
- private $prenom;
- /**
- * @ORMColumn(type="date")
- * @AssertNotBlank()
- */
- private $dateNaissance;
- /**
- * @ORMColumn(type="string", length="255")
- * @AssertNotBlank()
- */
- private $adresse;
- /**
- * @ORMColumn(type="string", length="255")
- * @AssertNotBlank()
- */
- private $telephone;
- /**
- * @ORMManyToOne(targetEntity="Agence")
- */
- private $agence;
- /**
- * @ORMManyToOne(targetEntity="Offre")
- */
- private $offre;
- /**
- * @ORMColumn(type="string",length="1")
- * @AssertNotBlank()
- * @AssertChoice(choices = {"M", "F"})
- */
- private $sexe;
- /**
- * @ORMColumn(type="string",length="255")
- * @AssertNotBlank()
- */
- private $nomCommercial;
- /**
- * Get id
- *
- * @return integer $id
- */
- public function getId()
- {
- return $this->id;
- }
- public function getUsername()
- {
- return $this->username;
- }
- public function setUsername($username)
- {
- $this->username = $username;
- }
- /**
- * Gets the user password.
- *
- * @return string The password.
- */
- public function getPassword()
- {
- return $this->password;
- }
- /**
- * Sets the user password.
- *
- * @param string $value The password.
- */
- public function setPassword($password)
- {
- $this->password = $password;
- }
- /**
- * Set nom
- *
- * @param string $nom
- */
- public function setNom($nom)
- {
- $this->nom = $nom;
- }
- /**
- * Get nom
- *
- * @return string $nom
- */
- public function getNom()
- {
- return $this->nom;
- }
- /**
- * Set prenom
- *
- * @param string $prenom
- */
- public function setPrenom($prenom)
- {
- $this->prenom = $prenom;
- }
- /**
- * Get prenom
- *
- * @return string $prenom
- */
- public function getPrenom()
- {
- return $this->prenom;
- }
- /**
- * Set dateNaissance
- *
- * @param date $dateNaissance
- */
- public function setDateNaissance($dateNaissance)
- {
- $this->dateNaissance = $dateNaissance;
- }
- /**
- * Get dateNaissance
- *
- * @return date $dateNaissance
- */
- public function getDateNaissance()
- {
- return $this->dateNaissance;
- }
- /**
- * Set sexe
- *
- * @param string $sexe
- */
- public function setSexe($sexe)
- {
- $this->sexe = $sexe;
- }
- /**
- * Get sexe
- *
- * @return string $sexe
- */
- public function getSexe()
- {
- return $this->sexe;
- }
- /**
- * Get mail
- *
- * @return string $mail
- */
- public function getMail()
- {
- return $this->mail;
- }
- /**
- * Set mail
- *
- * @param string $mail
- */
- public function setMail($mail)
- {
- $this->mail = $mail;
- }
- /**
- * Set adresse
- *
- * @param string $adresse
- */
- public function setAdresse($adresse)
- {
- $this->adresse = $adresse;
- }
- /**
- * Get adresse
- *
- * @return string $adresse
- */
- public function getAdresse()
- {
- return $this->adresse;
- }
- /**
- * Set telephone
- *
- * @param string $telephone
- */
- public function setTelephone($telephone)
- {
- $this->telephone = $telephone;
- }
- /**
- * Get telephone
- *
- * @return string $telephone
- */
- public function getTelephone()
- {
- return $this->telephone;
- }
- /**
- * Set agence
- *
- * @param MyAppSafeDrivingBundleEntityAgence $agence
- */
- public function setAgence(MyAppSafeDrivingBundleEntityAgence $agence)
- {
- $this->agence = $agence;
- }
- /**
- * Get agence
- *
- * @return MyAppSafeDrivingBundleEntityAgence $agence
- */
- public function getAgence()
- {
- return $this->agence;
- }
- /**
- * Set offre
- *
- * @param MyAppSafeDrivingBundleEntityOffre $offre
- */
- public function setOffre(MyAppSafeDrivingBundleEntityOffre $offre)
- {
- $this->offre = $offre;
- }
- /**
- * Get offre
- *
- * @return MyAppSafeDrivingBundleEntityOffre $offre
- */
- public function getOffre()
- {
- return $this->offre;
- }
- /**
- * Set nomCommercial
- *
- * @param string $nomCommercial
- */
- public function setNomCommercial($nomCommercial)
- {
- $this->nomCommercial = $nomCommercial;
- }
- /**
- * Get nomCommercial
- *
- * @return string $nomCommercial
- */
- public function getNomCommercial()
- {
- return $this->nomCommercial;
- }
- /**
- * Implementing the UserInterface interface
- */
- public function __toString()
- {
- return $this->getUsername();
- }
- public function getRoles()
- {
- return array('ROLE_CLIENT');
- }
- public function eraseCredentials()
- {
- return false;
- }
- public function getSalt()
- {
- return '';
- }
- /**
- * equals.
- *
- * @param UserInterface $account
- * @return bool
- */
- public function equals(UserInterface $account)
- {
- if ($account->getUsername() != $this->getUsername) {
- return false;
- }
- if ($account->getMail() != $this->getMail) {
- return false;
- }
- return true;
- }
- }
- <?php
- namespace MyAppSafeDrivingBundleRepository;
- use DoctrineORMEntityRepository;
- use SymfonyComponentSecurityCoreUserUserProviderInterface;
- use SymfonyComponentSecurityCoreUserUserInterface;
- class UserRepository extends EntityRepository implements UserProviderInterface
- {
- const CREATED = 0;
- const ACTIVE = 10;
- const INACTIVE = 20;
- /**
- * loadUserByUsername.
- *
- * @param string $username
- * @return MyAppSafeDrivingBundleEntityClient
- */
- public function loadUserByUsername($username)
- {
- return $this->findOneBy(array('username' => $username));
- }
- function loadUser(UserInterface $user)
- {
- return $user;
- }
- function loadUserByAccount(AccountInterface $account)
- {
- return $this->loadUserByUsername($account->getUsername());
- }
- public function supportsClass($class)
- {
- return true;
- }
- }
Add Comment
Please, Sign In to add comment