Guest User

Untitled

a guest
Aug 28th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.84 KB | None | 0 0
  1. Symfony 2 authentication with Entity error
  2. security:
  3. firewalls:
  4. secured_area:
  5. pattern: ^/
  6. anonymous: ~
  7. form_login: true
  8. logout:
  9. path: /logout
  10. target: /login
  11.  
  12. # access_control:
  13. # - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
  14. # - { path: ^/admin, roles: ROLE_ADMIN }
  15.  
  16. providers:
  17. in_memory:
  18. users:
  19. admin: { password: admin, roles: 'ROLE_ADMIN' }
  20.  
  21. main:
  22. entity: { class: MyAppSafeDrivingBundle:Client, property: username }
  23.  
  24. encoders:
  25. SymfonyComponentSecurityCoreUserUser: plaintext
  26. MyAppSafeDrivingBundleEntityClient: plaintext
  27.  
  28. security:
  29. firewalls:
  30. secured_area:
  31. pattern: ^/
  32. anonymous: ~
  33. form_login: true
  34. logout:
  35. path: /logout
  36. target: /login
  37.  
  38. access_control:
  39. - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
  40. - { path: ^/admin, roles: ROLE_ADMIN }
  41.  
  42. providers:
  43. in_memory:
  44. users:
  45. admin: { password: admin, roles: 'ROLE_ADMIN' }
  46. client: { password: client, roles: 'ROLE_CLIENT' }
  47. formateur: { password: formateur, roles: 'ROLE_FORMATEUR' }
  48. agence: { password: agence, roles: 'ROLE_AGENCE' }
  49.  
  50. main:
  51. entity: { class: MyAppSafeDrivingBundle:Client, property: username }
  52.  
  53. encoders:
  54. SymfonyComponentSecurityCoreUserUser: plaintext
  55. MyAppSafeDrivingBundleEntityClient: plaintext
  56.  
  57. <?php
  58.  
  59. namespace MyAppSafeDrivingBundleEntity;
  60. use DoctrineORMMapping as ORM;
  61. use SymfonyComponentValidatorConstraints as Assert;
  62. use SymfonyComponentSecurityCoreUserUserInterface;
  63.  
  64. /**
  65. * @ORMEntity(repositoryClass="MyAppSafeDrivingBundleRepositoryUserRepository")
  66. */
  67. class Client implements UserInterface
  68. {
  69. /**
  70. * @ORMGeneratedValue
  71. * @ORMId
  72. * @ORMColumn(type="integer")
  73. */
  74. protected $id;
  75.  
  76. /**
  77. * @ORMColumn(type="string", length="32", unique=true)
  78. */
  79. protected $username;
  80.  
  81. /**
  82. * @ORMColumn(type="string", length="255")
  83. */
  84. protected $password;
  85.  
  86.  
  87. /**
  88. * @ORMColumn(type="string", length="255")
  89. * @AssertNotBlank()
  90. */
  91. private $mail;
  92.  
  93. /**
  94. * @ORMColumn(type="string",length="255")
  95. * @AssertNotBlank()
  96. * @AssertMinLength(3)
  97. */
  98. private $nom;
  99.  
  100. /**
  101. * @ORMColumn(type="string",length="255")
  102. * @AssertNotBlank()
  103. * @AssertMinLength(3)
  104. */
  105. private $prenom;
  106.  
  107. /**
  108. * @ORMColumn(type="date")
  109. * @AssertNotBlank()
  110. */
  111. private $dateNaissance;
  112.  
  113. /**
  114. * @ORMColumn(type="string", length="255")
  115. * @AssertNotBlank()
  116. */
  117. private $adresse;
  118.  
  119. /**
  120. * @ORMColumn(type="string", length="255")
  121. * @AssertNotBlank()
  122. */
  123. private $telephone;
  124.  
  125. /**
  126. * @ORMManyToOne(targetEntity="Agence")
  127. */
  128. private $agence;
  129.  
  130. /**
  131. * @ORMManyToOne(targetEntity="Offre")
  132. */
  133. private $offre;
  134.  
  135.  
  136. /**
  137. * @ORMColumn(type="string",length="1")
  138. * @AssertNotBlank()
  139. * @AssertChoice(choices = {"M", "F"})
  140. */
  141. private $sexe;
  142.  
  143. /**
  144. * @ORMColumn(type="string",length="255")
  145. * @AssertNotBlank()
  146. */
  147. private $nomCommercial;
  148.  
  149. /**
  150. * Get id
  151. *
  152. * @return integer $id
  153. */
  154. public function getId()
  155. {
  156. return $this->id;
  157. }
  158.  
  159. public function getUsername()
  160. {
  161. return $this->username;
  162. }
  163.  
  164. public function setUsername($username)
  165. {
  166. $this->username = $username;
  167. }
  168.  
  169. /**
  170. * Gets the user password.
  171. *
  172. * @return string The password.
  173. */
  174. public function getPassword()
  175. {
  176. return $this->password;
  177. }
  178.  
  179. /**
  180. * Sets the user password.
  181. *
  182. * @param string $value The password.
  183. */
  184. public function setPassword($password)
  185. {
  186. $this->password = $password;
  187. }
  188.  
  189. /**
  190. * Set nom
  191. *
  192. * @param string $nom
  193. */
  194. public function setNom($nom)
  195. {
  196. $this->nom = $nom;
  197. }
  198.  
  199. /**
  200. * Get nom
  201. *
  202. * @return string $nom
  203. */
  204. public function getNom()
  205. {
  206. return $this->nom;
  207. }
  208.  
  209. /**
  210. * Set prenom
  211. *
  212. * @param string $prenom
  213. */
  214. public function setPrenom($prenom)
  215. {
  216. $this->prenom = $prenom;
  217. }
  218.  
  219. /**
  220. * Get prenom
  221. *
  222. * @return string $prenom
  223. */
  224. public function getPrenom()
  225. {
  226. return $this->prenom;
  227. }
  228.  
  229. /**
  230. * Set dateNaissance
  231. *
  232. * @param date $dateNaissance
  233. */
  234. public function setDateNaissance($dateNaissance)
  235. {
  236. $this->dateNaissance = $dateNaissance;
  237. }
  238.  
  239. /**
  240. * Get dateNaissance
  241. *
  242. * @return date $dateNaissance
  243. */
  244. public function getDateNaissance()
  245. {
  246. return $this->dateNaissance;
  247. }
  248.  
  249. /**
  250. * Set sexe
  251. *
  252. * @param string $sexe
  253. */
  254. public function setSexe($sexe)
  255. {
  256. $this->sexe = $sexe;
  257. }
  258.  
  259. /**
  260. * Get sexe
  261. *
  262. * @return string $sexe
  263. */
  264. public function getSexe()
  265. {
  266. return $this->sexe;
  267. }
  268.  
  269. /**
  270. * Get mail
  271. *
  272. * @return string $mail
  273. */
  274. public function getMail()
  275. {
  276. return $this->mail;
  277. }
  278.  
  279. /**
  280. * Set mail
  281. *
  282. * @param string $mail
  283. */
  284. public function setMail($mail)
  285. {
  286. $this->mail = $mail;
  287. }
  288.  
  289. /**
  290. * Set adresse
  291. *
  292. * @param string $adresse
  293. */
  294. public function setAdresse($adresse)
  295. {
  296. $this->adresse = $adresse;
  297. }
  298.  
  299. /**
  300. * Get adresse
  301. *
  302. * @return string $adresse
  303. */
  304. public function getAdresse()
  305. {
  306. return $this->adresse;
  307. }
  308.  
  309. /**
  310. * Set telephone
  311. *
  312. * @param string $telephone
  313. */
  314. public function setTelephone($telephone)
  315. {
  316. $this->telephone = $telephone;
  317. }
  318.  
  319. /**
  320. * Get telephone
  321. *
  322. * @return string $telephone
  323. */
  324. public function getTelephone()
  325. {
  326. return $this->telephone;
  327. }
  328.  
  329. /**
  330. * Set agence
  331. *
  332. * @param MyAppSafeDrivingBundleEntityAgence $agence
  333. */
  334. public function setAgence(MyAppSafeDrivingBundleEntityAgence $agence)
  335. {
  336. $this->agence = $agence;
  337. }
  338.  
  339. /**
  340. * Get agence
  341. *
  342. * @return MyAppSafeDrivingBundleEntityAgence $agence
  343. */
  344. public function getAgence()
  345. {
  346. return $this->agence;
  347. }
  348.  
  349. /**
  350. * Set offre
  351. *
  352. * @param MyAppSafeDrivingBundleEntityOffre $offre
  353. */
  354. public function setOffre(MyAppSafeDrivingBundleEntityOffre $offre)
  355. {
  356. $this->offre = $offre;
  357. }
  358.  
  359. /**
  360. * Get offre
  361. *
  362. * @return MyAppSafeDrivingBundleEntityOffre $offre
  363. */
  364. public function getOffre()
  365. {
  366. return $this->offre;
  367. }
  368.  
  369. /**
  370. * Set nomCommercial
  371. *
  372. * @param string $nomCommercial
  373. */
  374. public function setNomCommercial($nomCommercial)
  375. {
  376. $this->nomCommercial = $nomCommercial;
  377. }
  378.  
  379. /**
  380. * Get nomCommercial
  381. *
  382. * @return string $nomCommercial
  383. */
  384. public function getNomCommercial()
  385. {
  386. return $this->nomCommercial;
  387. }
  388.  
  389. /**
  390. * Implementing the UserInterface interface
  391. */
  392.  
  393. public function __toString()
  394. {
  395. return $this->getUsername();
  396. }
  397.  
  398. public function getRoles()
  399. {
  400. return array('ROLE_CLIENT');
  401. }
  402.  
  403. public function eraseCredentials()
  404. {
  405. return false;
  406. }
  407.  
  408. public function getSalt()
  409. {
  410. return '';
  411. }
  412.  
  413. /**
  414. * equals.
  415. *
  416. * @param UserInterface $account
  417. * @return bool
  418. */
  419. public function equals(UserInterface $account)
  420. {
  421. if ($account->getUsername() != $this->getUsername) {
  422. return false;
  423. }
  424. if ($account->getMail() != $this->getMail) {
  425. return false;
  426. }
  427. return true;
  428. }
  429. }
  430.  
  431. <?php
  432. namespace MyAppSafeDrivingBundleRepository;
  433. use DoctrineORMEntityRepository;
  434. use SymfonyComponentSecurityCoreUserUserProviderInterface;
  435. use SymfonyComponentSecurityCoreUserUserInterface;
  436.  
  437. class UserRepository extends EntityRepository implements UserProviderInterface
  438. {
  439. const CREATED = 0;
  440. const ACTIVE = 10;
  441. const INACTIVE = 20;
  442. /**
  443. * loadUserByUsername.
  444. *
  445. * @param string $username
  446. * @return MyAppSafeDrivingBundleEntityClient
  447. */
  448. public function loadUserByUsername($username)
  449. {
  450. return $this->findOneBy(array('username' => $username));
  451. }
  452. function loadUser(UserInterface $user)
  453. {
  454. return $user;
  455. }
  456. function loadUserByAccount(AccountInterface $account)
  457. {
  458. return $this->loadUserByUsername($account->getUsername());
  459. }
  460. public function supportsClass($class)
  461. {
  462. return true;
  463. }
  464. }
Add Comment
Please, Sign In to add comment